2016-03-08 85 views
0

我目前正在使用CGAL进行树生成应用,这是我第一次。CGAL Lib拉伸多边形

这将是最容易和/或最好的方式做面部挤压?新点的计算已经完成。

CGAL是一个巨大的库,所以可能有更好更强大的方法。

请看看当前代码(考虑注释):

void TreeGenerator::extrude(Face_handle face, float value) 
{ 
    CGAL_precondition(m_mesh.is_valid()); 

    //calculate face normal vector direction 
    Halfedge_handle halfEdge1 = face->halfedge(); 
    Halfedge_handle halfEdge2 = halfEdge1->next(); 
    Halfedge_handle halfEdge3 = halfEdge2->next(); 
    Halfedge_handle halfEdge4 = halfEdge3->next(); 

    //vectors from v1 to v2 and from v2 to v3 -> vectors lying on the face 
    Vector3 v1(halfEdge1->vertex()->point(), halfEdge2->vertex()->point()); 
    Vector3 v2(halfEdge2->vertex()->point(), halfEdge3->vertex()->point()); 

    Vector3 normal_vector = cross_product(v1, v2); 

    //HINT: This can be cpu time consuming -> can we remove the sqrt() ? 
    normal_vector = (normal_vector/sqrt(normal_vector.squared_length())) * value; 

    std::cout << "Normal Vector: " << normal_vector << std::endl; 

    Point point1 = halfEdge1->vertex()->point() + normal_vector; 
    Point point2 = halfEdge2->vertex()->point() + normal_vector; 
    Point point3 = halfEdge3->vertex()->point() + normal_vector; 
    Point point4 = halfEdge4->vertex()->point() + normal_vector; 

    std::cout << "Point1: " << point1 << std::endl; 
    std::cout << "Point2: " << point2 << std::endl; 
    std::cout << "Point3: " << point3 << std::endl; 
    std::cout << "Point4: " << point4 << std::endl; 

    //test space -> try to use a Polyhedron_incremnt_builder_3 
    //http://doc.cgal.org/latest/Polyhedron/classCGAL_1_1Polyhedron__incremental__builder__3.html 

    //I want to do the extrude code here but what would be the best way? 

    CGAL_postcondition(m_mesh.is_valid()); 
} 

这将是真棒如果有人能指点正确的方法或者给我一个想法。

THX和再见 达里安

回答

0

我差点忘了回答我的问题。

我通过生成一个新的多维数据集来解决这个问题。 将顶点移动到正确位置,并使用cgal方法join_loop()将新立方体连接到当前网格。

代码:

Face_handle TreeGenerator::extrude(Face_handle face, float value) 
{ 

CGAL_precondition(m_mesh.is_valid()); 

//calculate face normal vector direction 
Halfedge_handle halfEdge1 = face->halfedge(); 
Halfedge_handle halfEdge2 = halfEdge1->next(); 
Halfedge_handle halfEdge3 = halfEdge2->next(); 
Halfedge_handle halfEdge4 = halfEdge3->next(); 

Vector3 normal_vector = getNormalVector(face, value); 

std::cout << "Normal Vector: " << normal_vector << std::endl; 

Point point1 = halfEdge1->vertex()->point() + normal_vector; 
Point point2 = halfEdge2->vertex()->point() + normal_vector; 
Point point3 = halfEdge3->vertex()->point() + normal_vector; 
Point point4 = halfEdge4->vertex()->point() + normal_vector; 

Face_handle newCubeFace = make_cube_3(m_mesh, 1.0f); 
Face_handle newOppositeFace = newCubeFace->halfedge()->opposite()->next()->next()->opposite()->face(); 

//edges to the top points 
Halfedge_handle newHalfEdge1 = newCubeFace->halfedge(); 
Halfedge_handle newHalfEdge2 = newHalfEdge1->next(); 
Halfedge_handle newHalfEdge3 = newHalfEdge2->next(); 
Halfedge_handle newHalfEdge4 = newHalfEdge3->next(); 

//edges to the bottom points 
Halfedge_handle newHalfEdgeBottom1 = newHalfEdge2->opposite()->next(); 
Halfedge_handle newHalfEdgeBottom2 = newHalfEdge3->opposite()->next(); 
Halfedge_handle newHalfEdgeBottom3 = newHalfEdge4->opposite()->next(); 
Halfedge_handle newHalfEdgeBottom4 = newHalfEdge1->opposite()->next(); 

//set new positions 
newHalfEdge1->vertex()->point() = point1; 
newHalfEdge2->vertex()->point() = point2; 
newHalfEdge3->vertex()->point() = point3; 
newHalfEdge4->vertex()->point() = point4; 

newHalfEdgeBottom1->vertex()->point() = halfEdge1->vertex()->point(); 
newHalfEdgeBottom2->vertex()->point() = halfEdge2->vertex()->point(); 
newHalfEdgeBottom3->vertex()->point() = halfEdge3->vertex()->point(); 
newHalfEdgeBottom4->vertex()->point() = halfEdge4->vertex()->point(); 

m_mesh.join_loop(halfEdge1, newOppositeFace->halfedge()); 

CGAL_postcondition(m_mesh.is_valid()); 

return newCubeFace; 
} 

也许它可以帮助别人。

Thx and bye Darian