Part: add convenience functions to retrieve triangulation of a face or edge
This commit is contained in:
@@ -25,25 +25,31 @@
|
||||
# include <cassert>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <gp_Lin.hxx>
|
||||
# include <Adaptor3d_HCurveOnSurface.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <Geom_BSplineSurface.hxx>
|
||||
# include <Geom_Plane.hxx>
|
||||
# include <GeomAdaptor_HCurve.hxx>
|
||||
# include <GeomAPI_IntSS.hxx>
|
||||
# include <Geom_Line.hxx>
|
||||
# include <Geom_Point.hxx>
|
||||
# include <GeomAdaptor_Curve.hxx>
|
||||
# include <GeomPlate_BuildPlateSurface.hxx>
|
||||
# include <GeomPlate_CurveConstraint.hxx>
|
||||
# include <GeomPlate_MakeApprox.hxx>
|
||||
# include <GeomPlate_PlateG0Criterion.hxx>
|
||||
# include <GeomPlate_PointConstraint.hxx>
|
||||
# include <Poly_Triangulation.hxx>
|
||||
# include <Precision.hxx>
|
||||
# include <Standard_Mutex.hxx>
|
||||
# include <Standard_TypeMismatch.hxx>
|
||||
# include <Standard_Version.hxx>
|
||||
# include <TColStd_ListOfTransient.hxx>
|
||||
# include <TColStd_ListIteratorOfListOfTransient.hxx>
|
||||
# include <TColgp_SequenceOfXY.hxx>
|
||||
# include <TColgp_SequenceOfXYZ.hxx>
|
||||
# if OCC_VERSION_HEX < 0x070600
|
||||
# include <Adaptor3d_HCurveOnSurface.hxx>
|
||||
# include <GeomAdaptor_HCurve.hxx>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <Base/Vector3D.h>
|
||||
@@ -138,6 +144,20 @@ Part::Tools::makeSurface(const TColStd_ListOfTransient &theBoundaries,
|
||||
assert (0);
|
||||
Standard_ConstructionError::Raise ("Tools::makeSurface()");
|
||||
}
|
||||
#if OCC_VERSION_HEX >= 0x070600
|
||||
else if (aCur->IsKind (STANDARD_TYPE (Adaptor3d_CurveOnSurface))) {
|
||||
//G1 constraint
|
||||
Handle(Adaptor3d_CurveOnSurface) aHCOS (Handle(Adaptor3d_CurveOnSurface)::DownCast (aCur));
|
||||
Handle (GeomPlate_CurveConstraint) aConst = new GeomPlate_CurveConstraint (aHCOS, 1 /*GeomAbs_G1*/,aNbPnts, aTol3d, anAngTol, aCurvTol);
|
||||
aPlateBuilder.Add (aConst);
|
||||
}
|
||||
else if (aCur->IsKind (STANDARD_TYPE (GeomAdaptor_Curve))) {
|
||||
//G0 constraint
|
||||
Handle(GeomAdaptor_Curve) aHC (Handle(GeomAdaptor_Curve)::DownCast (aCur));
|
||||
Handle (GeomPlate_CurveConstraint) aConst = new GeomPlate_CurveConstraint (aHC, 0 /*GeomAbs_G0*/, aNbPnts, aTol3d);
|
||||
aPlateBuilder.Add (aConst);
|
||||
}
|
||||
#else
|
||||
else if (aCur->IsKind (STANDARD_TYPE (Adaptor3d_HCurveOnSurface))) {
|
||||
//G1 constraint
|
||||
Handle(Adaptor3d_HCurveOnSurface) aHCOS (Handle(Adaptor3d_HCurveOnSurface)::DownCast (aCur));
|
||||
@@ -150,6 +170,7 @@ Part::Tools::makeSurface(const TColStd_ListOfTransient &theBoundaries,
|
||||
Handle (GeomPlate_CurveConstraint) aConst = new GeomPlate_CurveConstraint (aHC, 0 /*GeomAbs_G0*/, aNbPnts, aTol3d);
|
||||
aPlateBuilder.Add (aConst);
|
||||
}
|
||||
#endif
|
||||
else if (aCur->IsKind (STANDARD_TYPE (Geom_Point))) {
|
||||
//Point constraint
|
||||
Handle(Geom_Point) aGP (Handle(Geom_Point)::DownCast (aCur));
|
||||
@@ -190,3 +211,148 @@ Part::Tools::makeSurface(const TColStd_ListOfTransient &theBoundaries,
|
||||
|
||||
return aRes;
|
||||
}
|
||||
|
||||
bool Part::Tools::getTriangulation(const TopoDS_Face& face, std::vector<gp_Pnt>& points, std::vector<Poly_Triangle>& facets)
|
||||
{
|
||||
TopLoc_Location loc;
|
||||
Handle(Poly_Triangulation) hTria = BRep_Tool::Triangulation(face, loc);
|
||||
if (hTria.IsNull())
|
||||
return false;
|
||||
|
||||
// getting the transformation of the face
|
||||
gp_Trsf transf;
|
||||
bool identity = true;
|
||||
if (!loc.IsIdentity()) {
|
||||
identity = false;
|
||||
transf = loc.Transformation();
|
||||
}
|
||||
|
||||
// check orientation
|
||||
TopAbs_Orientation orient = face.Orientation();
|
||||
|
||||
Standard_Integer nbNodes = hTria->NbNodes();
|
||||
Standard_Integer nbTriangles = hTria->NbTriangles();
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
const TColgp_Array1OfPnt& nodes = hTria->Nodes();
|
||||
const Poly_Array1OfTriangle& triangles = hTria->Triangles();
|
||||
#endif
|
||||
|
||||
points.reserve(nbNodes);
|
||||
facets.reserve(nbTriangles);
|
||||
|
||||
// cycling through the poly mesh
|
||||
//
|
||||
for (int i = 1; i <= nbNodes; i++) {
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
gp_Pnt p = nodes(i);
|
||||
#else
|
||||
gp_Pnt p = hTria->Node(i);
|
||||
#endif
|
||||
|
||||
// transform the vertices to the location of the face
|
||||
if (!identity) {
|
||||
p.Transform(transf);
|
||||
}
|
||||
|
||||
points.push_back(p);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= nbTriangles; i++) {
|
||||
// Get the triangle
|
||||
Standard_Integer n1,n2,n3;
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
triangles(i).Get(n1, n2, n3);
|
||||
#else
|
||||
hTria->Triangle(i).Get(n1, n2, n3);
|
||||
#endif
|
||||
--n1; --n2; --n3;
|
||||
|
||||
// change orientation of the triangles
|
||||
if (orient != TopAbs_FORWARD) {
|
||||
std::swap(n1, n2);
|
||||
}
|
||||
|
||||
facets.emplace_back(n1, n2, n3);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Part::Tools::getPolygonOnTriangulation(const TopoDS_Edge& edge, const TopoDS_Face& face, std::vector<gp_Pnt>& points)
|
||||
{
|
||||
TopLoc_Location loc;
|
||||
Handle(Poly_Triangulation) hTria = BRep_Tool::Triangulation(face, loc);
|
||||
if (hTria.IsNull())
|
||||
return false;
|
||||
|
||||
// this holds the indices of the edge's triangulation to the actual points
|
||||
Handle(Poly_PolygonOnTriangulation) hPoly = BRep_Tool::PolygonOnTriangulation(edge, hTria, loc);
|
||||
if (hPoly.IsNull())
|
||||
return false;
|
||||
|
||||
// getting the transformation of the edge
|
||||
gp_Trsf transf;
|
||||
bool identity = true;
|
||||
if (!loc.IsIdentity()) {
|
||||
identity = false;
|
||||
transf = loc.Transformation();
|
||||
}
|
||||
|
||||
// getting size and create the array
|
||||
Standard_Integer nbNodes = hPoly->NbNodes();
|
||||
points.reserve(nbNodes);
|
||||
const TColStd_Array1OfInteger& indices = hPoly->Nodes();
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
const TColgp_Array1OfPnt& Nodes = hTria->Nodes();
|
||||
#endif
|
||||
|
||||
// go through the index array
|
||||
for (Standard_Integer i = indices.Lower(); i <= indices.Upper(); i++) {
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
gp_Pnt p = Nodes(indices(i));
|
||||
#else
|
||||
gp_Pnt p = hTria->Node(indices(i));
|
||||
#endif
|
||||
if (!identity) {
|
||||
p.Transform(transf);
|
||||
}
|
||||
|
||||
points.push_back(p);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Part::Tools::getPolygon3D(const TopoDS_Edge& edge, std::vector<gp_Pnt>& points)
|
||||
{
|
||||
TopLoc_Location loc;
|
||||
Handle(Poly_Polygon3D) hPoly = BRep_Tool::Polygon3D(edge, loc);
|
||||
if (hPoly.IsNull())
|
||||
return false;
|
||||
|
||||
// getting the transformation of the edge
|
||||
gp_Trsf transf;
|
||||
bool identity = true;
|
||||
if (!loc.IsIdentity()) {
|
||||
identity = false;
|
||||
transf = loc.Transformation();
|
||||
}
|
||||
|
||||
// getting size and create the array
|
||||
Standard_Integer nbNodes = hPoly->NbNodes();
|
||||
points.reserve(nbNodes);
|
||||
const TColgp_Array1OfPnt& nodes = hPoly->Nodes();
|
||||
|
||||
for (int i = 1; i <= nbNodes; i++) {
|
||||
gp_Pnt p = nodes(i);
|
||||
|
||||
// transform the vertices to the location of the face
|
||||
if (!identity) {
|
||||
p.Transform(transf);
|
||||
}
|
||||
|
||||
points.push_back(p);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,11 @@
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_XYZ.hxx>
|
||||
#include <Geom_Surface.hxx>
|
||||
#include <Poly_Triangle.hxx>
|
||||
#include <TColStd_ListOfTransient.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <vector>
|
||||
|
||||
class gp_Lin;
|
||||
class gp_Pln;
|
||||
@@ -104,7 +108,32 @@ public:
|
||||
const Standard_Integer theNbPnts,
|
||||
const Standard_Integer theNbIter,
|
||||
const Standard_Integer theMaxDeg);
|
||||
|
||||
/*!
|
||||
* @brief getTriangulation
|
||||
* The indexes of the triangles are adjusted to the points vector.
|
||||
* @param face
|
||||
* @param points
|
||||
* @param facets
|
||||
* @return true if a triangulation exists or false otherwise
|
||||
*/
|
||||
static bool getTriangulation(const TopoDS_Face& face, std::vector<gp_Pnt>& points, std::vector<Poly_Triangle>& facets);
|
||||
/*!
|
||||
* \brief getPolygonOnTriangulation
|
||||
* Get the polygon of edge.
|
||||
* \note \a edge must belong to face.
|
||||
* \param edge
|
||||
* \param face
|
||||
* \param points
|
||||
* \return true if a triangulation exists or false otherwise
|
||||
*/
|
||||
static bool getPolygonOnTriangulation(const TopoDS_Edge& edge, const TopoDS_Face& face, std::vector<gp_Pnt>& points);
|
||||
/*!
|
||||
* \brief getPolygon3D
|
||||
* \param edge
|
||||
* \param points
|
||||
* \return true if a polygon exists or false otherwise
|
||||
*/
|
||||
static bool getPolygon3D(const TopoDS_Edge& edge, std::vector<gp_Pnt>& points);
|
||||
};
|
||||
|
||||
} //namespace Part
|
||||
|
||||
Reference in New Issue
Block a user