1 // Created on: 2016-07-04
2 // Copyright (c) 2016 OPEN CASCADE SAS
3 // Created by: Oleg AGASHIN
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepMesh_ModelPostProcessor.hxx>
17 #include <BRepMesh_ShapeTool.hxx>
18 #include <IMeshData_Model.hxx>
19 #include <IMeshData_Edge.hxx>
20 #include <IMeshData_PCurve.hxx>
21 #include <OSD_Parallel.hxx>
25 //! Commits 3D polygons and polygons on triangulations for corresponding edges.
26 class PolygonCommitter
30 PolygonCommitter(const Handle(IMeshData_Model)& theModel)
36 void operator()(const Standard_Integer theEdgeIndex) const
38 const IMeshData::IEdgeHandle& aDEdge = myModel->GetEdge(theEdgeIndex);
39 if (aDEdge->GetCurve()->ParametersNb() == 0)
44 if (!aDEdge->IsSet(IMeshData_Reused))
46 commitPolygon3D(aDEdge);
51 commitPolygons(aDEdge);
57 //! Commits 3d polygon to topological edge
58 void commitPolygon3D(const IMeshData::IEdgeHandle& theDEdge) const
60 const IMeshData::ICurveHandle& aCurve = theDEdge->GetCurve();
62 TColgp_Array1OfPnt aNodes (1, aCurve->ParametersNb());
63 TColStd_Array1OfReal aUVNodes(1, aCurve->ParametersNb());
64 for (Standard_Integer i = 1; i <= aCurve->ParametersNb(); ++i)
66 aNodes (i) = aCurve->GetPoint (i - 1);
67 aUVNodes(i) = aCurve->GetParameter(i - 1);
70 Handle(Poly_Polygon3D) aPoly3D = new Poly_Polygon3D(aNodes, aUVNodes);
71 aPoly3D->Deflection(theDEdge->GetDeflection());
73 BRepMesh_ShapeTool::UpdateEdge(theDEdge->GetEdge(), aPoly3D);
76 //! Commits all polygons on triangulations correspondent to the given edge.
77 void commitPolygons(const IMeshData::IEdgeHandle& theDEdge) const
79 // Collect pcurves associated with the given edge on the specific surface.
80 IMeshData::IDMapOfIFacePtrsListOfIPCurves aMapOfPCurves;
81 for (Standard_Integer aPCurveIt = 0; aPCurveIt < theDEdge->PCurvesNb(); ++aPCurveIt)
83 const IMeshData::IPCurveHandle& aPCurve = theDEdge->GetPCurve(aPCurveIt);
84 const IMeshData::IFacePtr& aDFacePtr = aPCurve->GetFace();
85 const IMeshData::IFaceHandle aDFace = aDFacePtr;
86 if (aDFace->IsSet(IMeshData_Failure) ||
87 aDFace->IsSet(IMeshData_Reused))
92 if (!aMapOfPCurves.Contains(aDFacePtr))
94 aMapOfPCurves.Add(aDFacePtr, IMeshData::ListOfIPCurves());
97 IMeshData::ListOfIPCurves& aPCurves = aMapOfPCurves.ChangeFromKey(aDFacePtr);
98 aPCurves.Append(aPCurve);
101 // Commit polygons related to separate face.
102 const TopoDS_Edge& aEdge = theDEdge->GetEdge();
103 IMeshData::IDMapOfIFacePtrsListOfIPCurves::Iterator aPolygonIt(aMapOfPCurves);
104 for (; aPolygonIt.More(); aPolygonIt.Next())
106 const TopoDS_Face& aFace = aPolygonIt.Key()->GetFace();
108 TopLoc_Location aLoc;
109 const Handle(Poly_Triangulation)& aTriangulation =
110 BRep_Tool::Triangulation(aFace, aLoc);
112 if (!aTriangulation.IsNull())
114 const IMeshData::ListOfIPCurves& aPCurves = aPolygonIt.Value();
115 if (aPCurves.Size() == 2)
117 BRepMesh_ShapeTool::UpdateEdge(
119 collectPolygon(aPCurves.First(), theDEdge->GetDeflection()),
120 collectPolygon(aPCurves.Last (), theDEdge->GetDeflection()),
121 aTriangulation, aLoc);
125 BRepMesh_ShapeTool::UpdateEdge(
127 collectPolygon(aPCurves.First(), theDEdge->GetDeflection()),
128 aTriangulation, aLoc);
134 //! Collects polygonal data for the given pcurve
135 Handle(Poly_PolygonOnTriangulation) collectPolygon(
136 const IMeshData::IPCurveHandle& thePCurve,
137 const Standard_Real theDeflection) const
139 TColStd_Array1OfInteger aNodes (1, thePCurve->ParametersNb());
140 TColStd_Array1OfReal aParams(1, thePCurve->ParametersNb());
141 for (Standard_Integer i = 1; i <= thePCurve->ParametersNb(); ++i)
143 aNodes (i) = thePCurve->GetIndex (i - 1);
144 aParams(i) = thePCurve->GetParameter(i - 1);
147 Handle(Poly_PolygonOnTriangulation) aPolygon =
148 new Poly_PolygonOnTriangulation(aNodes, aParams);
150 aPolygon->Deflection(theDeflection);
156 Handle(IMeshData_Model) myModel;
160 //=======================================================================
161 // Function: Constructor
163 //=======================================================================
164 BRepMesh_ModelPostProcessor::BRepMesh_ModelPostProcessor()
168 //=======================================================================
169 // Function: Destructor
171 //=======================================================================
172 BRepMesh_ModelPostProcessor::~BRepMesh_ModelPostProcessor()
176 //=======================================================================
179 //=======================================================================
180 Standard_Boolean BRepMesh_ModelPostProcessor::Perform(
181 const Handle(IMeshData_Model)& theModel,
182 const IMeshTools_Parameters& /*theParameters*/)
184 if (theModel.IsNull())
186 return Standard_False;
189 // TODO: Force single threaded solution due to data races on edges sharing the same TShape
190 OSD_Parallel::For(0, theModel->EdgesNb(), PolygonCommitter(theModel), Standard_True/*!theParameters.InParallel*/);
191 return Standard_True;