
Mon, 04/24/2017 - 17:41
Hi,
I am trying to triangulate a face. The triangulation works for the face which is in single plane. For non-planar surface (curved surface, for e.g. cylinder) the triangulation crashes. I am passing the outline points of the face. Some thing like this:
std::vector<gp_Pnt> occPointList;
BRepBuilderAPI_MakePolygon aMakePolygon;
for(int j = 0; j < numPoints; j++)
{
vtkIdType id = list->GetId(j);
double* point = points->GetPoint(id);
occPointList.push_back(gp_Pnt(point[0], point[1], point[2]));
}
for(int j = 0; j < numPoints; j++)
{
aMakePolygon.Add(occPointList[j]);
}
aMakePolygon.Close();
BRepBuilderAPI_MakeFace aMakeFace (aMakePolygon.Wire(), Standard_True /*CreateOnlyPlane*/);
TopoDS_Face aFace = aMakeFace.Face();
double const deflection = 0.001;
double const angulardeflection = 0.001;
BRepMesh_IncrementalMesh discr(aFace, deflection, false, angulardeflection);
discr.Perform();
TopoDS_Face meshFace = TopoDS::Face(discr.Shape());
TopLoc_Location loc;
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(meshFace, loc);
I observed that for curved surface, the meshFace shows orientation as EXTERNAL and for planar surfaces, it shows, FORWARD or REVERSED. What is that is causing a crash and how can I overcome this problem?
Thanks
Tue, 04/25/2017 - 07:15
Hello,
I have several remarks:
1) TopoDS_Face meshFace = TopoDS::Face(discr.Shape());
Incremental mesh stores resulting mesh in the original shape. There is no need to create additional shape.
2) BRepBuilderAPI_MakeFace aMakeFace (aMakePolygon.Wire(), Standard_True /*CreateOnlyPlane*/);
The instance of the face maker returns planar face or nothing (according to your second parameter). So, there is the contradiction between your input data (cylinder) and expected result (planar face). I think it is the root cause of the problem.
qa qa
Tue, 04/25/2017 - 09:53
Hi,
I changed it to Standard_False. Still it is crashing. The points forming polygon are unique points. No duplicate points. Any other suggestions?
Thanks
Tue, 04/25/2017 - 10:04
Well, it seems that polygon conversion is still broken. From my point of view, you should triangulate native OCCT shape. Your polygon has arbitrary structure and algorithm fails calculation of the face underlying surface.
qa qa
Tue, 04/25/2017 - 10:26
Hi,
Here is a sample geometry list.
std::vector<gp_Pnt> gpList;
gpList.push_back(gp_Pnt( 4.39116, -2.39117, 4.5));
gpList.push_back(gp_Pnt( 4.39116, -2.39117, 3));
gpList.push_back(gp_Pnt( 4.39116, -2.39117, 1.5));
gpList.push_back(gp_Pnt( 4.39116, -2.39117, 0));
gpList.push_back(gp_Pnt( 4.08748, -2.87967, 0));
gpList.push_back(gp_Pnt( 3.05391, -3.95899, 0));
gpList.push_back(gp_Pnt( 1.74755, -4.68466, 0));
gpList.push_back(gp_Pnt( 0.28509, -4.99187, 0));
gpList.push_back(gp_Pnt( -1.20284, -4.85316, 0));
gpList.push_back(gp_Pnt( -2.58332, -4.28094, 0));
gpList.push_back(gp_Pnt( -3.73305, -3.32631, 0));
gpList.push_back(gp_Pnt( -4.54931, -2.07456, 0));
gpList.push_back(gp_Pnt( -4.95919, -0.637487, 0));
gpList.push_back(gp_Pnt( -4.92609, 0.856528, 0));
gpList.push_back(gp_Pnt( -4.45295, 2.27403, 0));
gpList.push_back(gp_Pnt( -3.58205, 3.4884, 0));
gpList.push_back(gp_Pnt( -2.39117, 4.39116, 0));
gpList.push_back(gp_Pnt( -2.39117, 4.39116, 1.5));
gpList.push_back(gp_Pnt( -2.39117, 4.39116, 3));
gpList.push_back(gp_Pnt( -2.39117, 4.39116, 4.5));
gpList.push_back(gp_Pnt( -2.39117, 4.39116, 6));
gpList.push_back(gp_Pnt( -3.58205, 3.4884, 6));
gpList.push_back(gp_Pnt( -4.45295, 2.27403, 6));
gpList.push_back(gp_Pnt( -4.92609, 0.856528, 6));
gpList.push_back(gp_Pnt(-4.95919, -0.637487, 6));
gpList.push_back(gp_Pnt(-4.54931, -2.07456, 6));
gpList.push_back(gp_Pnt(-3.73305, -3.32631, 6));
gpList.push_back(gp_Pnt(-2.58332, -4.28094, 6));
gpList.push_back(gp_Pnt(-1.20284, -4.85316, 6));
gpList.push_back(gp_Pnt(0.28509, -4.99187, 6));
gpList.push_back(gp_Pnt(1.74755, -4.68466, 6));
gpList.push_back(gp_Pnt(3.05391, -3.95899, 6));
gpList.push_back(gp_Pnt(4.08748, -2.87967, 6));
gpList.push_back(gp_Pnt(4.39116, -2.39117, 6));
BRepBuilderAPI_MakePolygon aMakePolygon;
for(int j = 0; j < gpList.size(); j--)
{
aMakePolygon.Add(gpList[j]);
}
aMakePolygon.Close(); //to close the polygon
BRepBuilderAPI_MakeFace aMakeFace (aMakePolygon.Wire(), Standard_False /*CreateOnlyPlane*/);
TopoDS_Face aFace = aMakeFace.Face();
double const deflection = 0.001;
double const angulardeflection = 0.001;
BRepMesh_IncrementalMesh discr(aFace, deflection, false, angulardeflection);
discr.Perform();
const TopoDS_Face& meshFace = TopoDS::Face(discr.Shape());
TopLoc_Location loc;
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(meshFace, loc);
This polygon loop is basically a section of a side of the cylinder. What is wrong in this polygon? How do I check that polygon is valid structure or not? How do I make it correct oriented if at all it is wrong?
Thanks
Tue, 04/25/2017 - 10:41
The polygon seems to be correct. The problem is inside of conversion polygon -> face. Face maker does not know about underlying surface and tries to calculate it. Such calculation fails. So, I see only two alternatives:
1) Use face maker with correct underlying surface which should be created beforehand
2) Write polygon tessellation from scratch. In the academic literature, this problem is called "polygon triangulation". Simple "ear slicing" algorithm can be implemented in 2 or 3 days.
qa qa
Tue, 04/25/2017 - 10:54
Wrong post. Sorry.
Sat, 05/13/2017 - 18:04
Hi qa qa,
Is there any example which I can refer to the point number 1?
1) Use face maker with correct underlying surface which should be created beforehand
It would be helpful if some material is available.
Thanks