OpenLexocad  28.0
MeshTool.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Draw/OglMaterial.h>
4 #include <Geom/Pln.h>
5 #include <Topo/Types.h>
6 
7 
8 /*
9 @brief MeshTool
10 [1] Boundary edges are edges shared by only one face.
11 */
12 
13 namespace Core
14 {
15 class CoreDocument;
16 class Variant;
17 }
18 namespace Draw
19 {
20 class SurfaceStyle;
21 }
22 
23 namespace App
24 {
25 class Element;
26 }
27 
28 namespace Geom
29 {
30 class Pnt2d;
31 }
32 
33 
34 namespace Topo
35 {
36 struct LX_TOPO_EXPORT LineItem
37 {
38  std::vector<Geom::Pnt> points;
39  Draw::OglMaterial material;
40 };
41 
48 class LX_TOPO_EXPORT MeshTool
49 {
50 public:
51  MeshTool(void);
52  virtual ~MeshTool(void);
53 
55  // //
56  // --------------------- BEGIN API --------------------- //
57  // //
58  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
59  // //
61 
63  static pMesh copy(pConstMesh mesh, bool deepCopy = false);
65  static bool isClosed(pConstMesh mesh);
67  static bool isPlanar(pConstMesh mesh);
73  static pMesh triangulationToMesh(pConstShape shape, bool highQuality, std::vector<int>* newToOldFaceIdxMap = 0);
75  static pShape convertMesh2Shape(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
77  static pShape convertMesh2Solid(pConstMesh aMesh, bool prefer_stiching, bool onlyClosedSolid, bool mergePlanarFaces);
79  static pShape convertMesh2Polyhedral(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
81  static pShape convertMesh2Brep_by_Face_Stiching(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
83  static pShape convertMesh2Shell(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
87  static pMesh makeMesh(const std::vector<Geom::Pnt>& nodes,
88  const std::vector<int>& model,
89  const std::vector<Geom::Pnt2d>& textureCoords,
90  const std::vector<int>& textureCoordIndices,
91  const std::vector<Geom::Pnt>& normals);
93  static pMesh makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model);
94 
96  static pMesh makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model, const std::vector<Geom::Pnt>& normals);
98  static std::vector<App::Element*> getElementsFromOMFFile(Core::CoreDocument* doc,
99  const Base::String& fileName,
100  double scaleFactor = 1.,
101  bool terrain = false);
102 
103  static bool getMesh(pConstMesh mesh,
104  std::vector<Geom::Pnt>& nodes,
105  std::vector<int>& model,
106  std::vector<Draw::SurfaceStyle>& surfaceStyles,
107  std::vector<int>& faceIndices,
108  std::vector<int>& surfaceStyleIndices,
109  std::vector<Geom::Pnt2d>& textureCoords,
110  std::vector<int>& textureCoordIndices,
111  std::vector<Topo::LineItem>* lineItems = 0);
112 
113  static bool getCreaseAngle(pConstMesh mesh, float& angle);
114 
115 
116 
118  // //
119  // ---------------------- END API ---------------------- //
120  // //
122 
123 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
124 
127  static std::vector<App::Element*> getElementsFromOMFFile(Core::CoreDocument* doc,
128  const Base::String& fileName,
129  double scaleFactor,
130  bool terrain,
131  std::map<std::string, Core::Variant>* properties,
132  bool forceTerrainFrom2dr);
133 
134 #ifndef SWIG
135  static std::map<int, std::array<Core::Variant, 6>> getHorizontalPointsFromOMFFile(Core::CoreDocument* doc,
137  const Base::String& fileName,
138  std::map<std::string, Core::Variant>* properties,
139  const double& scaleFactor = 1.);
140  static std::map<int, std::array<Core::Variant, 4>> getVerticalPointsFromOMFFile(Core::CoreDocument* doc,
141  const Base::String& fileName,
142  std::map<std::string, Core::Variant>* properties,
143  const double& scaleFactor = 1.);
144 #endif
145 
146  static void getModel(pConstMesh mesh, std::vector<int>& model);
147  static void getPoints(pConstMesh mesh, std::vector<Geom::Pnt>& points);
148 
149 
151  static void __setDefaultMeshTool__(Topo::MeshTool* tool) { _defaultTool = tool; }
153  static bool writeOmfFile(const std::vector<App::Element*>& elems, const Base::String& fileName);
154 
155  static bool getInventorMeshColors(pConstMesh mesh, std::vector<Base::Color>& uniqueColors, std::vector<std::string>* colorNames = 0);
156 
157  static pMesh makePlateFast(const std::vector<Geom::Pnt>& points,
158  const std::vector<int>& model,
159  const Geom::Dir& extrudeDir,
160  double thickness,
161  bool askForHoles); // for mesh without overhangs
162 
163  static bool triangulateClosedPolyline(const std::vector<Geom::Pnt> inputPolyLine, std::vector<Geom::Pnt>& nodes, std::vector<int>& model);
164  static bool tryToCloseMesh(const pConstMesh& mesh,
165  pMesh& newMesh,
166  const std::vector<unsigned int>* mtlIds = nullptr,
167  std::vector<unsigned int>* newMtlIds = nullptr);
168 
170  static bool section(const pConstMesh& mesh, const Geom::Pln& pln, std::vector<pFace>& faces);
172  static pFace getCreaseAngleFace(const pConstMesh& mesh, double creaseAngle, int faceIndex);
174  static bool getCreaseAngleFaceMesh(const pConstMesh& mesh,
175  double creaseAngle,
176  int faceIndex,
177  std::vector<Geom::Pnt>* points,
178  std::vector<int>* linesModel,
179  std::vector<int>* trianglesModel,
180  double* area);
181 
182 protected:
183 #endif
184 
185 private:
186  virtual pMesh _copy(pConstMesh shape, bool deepCopy);
187  virtual bool _isClosed(pConstMesh mesh);
188  virtual pMesh _triangulationToMesh(pConstShape shape);
189  virtual pMesh _triangulationToMesh(pConstShape shape, bool highQuality, std::vector<int>* newToOldFaceIdxMap);
190  static Topo::MeshTool* _defaultTool;
191 
192  virtual void _getModel(pConstMesh mesh, std::vector<int>& model);
193  virtual void _getPoints(pConstMesh mesh, std::vector<Geom::Pnt>& points);
194  virtual pMesh _makeMeshFromBrepData(pConstBrepData data);
195  virtual std::vector<App::Element*> _getElementsFromOMFFile(Core::CoreDocument* doc,
196  const Base::String& fileName,
197  double scaleFactor,
198  bool terrain,
199  std::map<std::string, Core::Variant>* properties,
200  bool forceTerrainFrom2dr);
201  virtual std::map<int, std::array<Core::Variant, 6>> _getHorizontalPointsFromOMFFile(Core::CoreDocument* doc,
202  const Base::String& fileName,
203  std::map<std::string, Core::Variant>* properties,
204  const double& scaleFactor);
205  virtual std::map<int, std::array<Core::Variant, 4>> _getVerticalPointsFromOMFFile(Core::CoreDocument* doc,
206  const Base::String& fileName,
207  std::map<std::string, Core::Variant>* properties,
208  const double& scaleFactor);
209  virtual bool _writeOmfFile(const std::vector<App::Element*>& elems, const Base::String& fileName);
210  virtual bool _getInventorMeshColors(pConstMesh mesh, std::vector<Base::Color>& uniqueColors, std::vector<std::string>* colorNames);
211  virtual pMesh _makeMesh(const std::vector<Geom::Pnt>& nodes,
212  const std::vector<int>& model,
213  const std::vector<Geom::Pnt2d>& textureCoords,
214  const std::vector<int>& textureCoordIndices,
215  const std::vector<Geom::Pnt>& normals);
216  virtual pMesh _makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model);
217  virtual pMesh _makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model, const std::vector<Geom::Pnt>& normals);
218 
219  virtual bool _getMesh(pConstMesh mesh,
220  std::vector<Geom::Pnt>& nodes,
221  std::vector<int>& model,
222  std::vector<Draw::SurfaceStyle>& surfaceStyles,
223  std::vector<int>& faceIndices,
224  std::vector<int>& surfaceStyleIndices,
225  std::vector<Geom::Pnt2d>& textureCoords,
226  std::vector<int>& textureCoordIndices,
227  std::vector<Topo::LineItem>* lineItems = 0);
228 
229  virtual bool _getCreaseAngle(pConstMesh mesh, float& angle);
230 
231  virtual pMesh _makePlateFast(const std::vector<Geom::Pnt>& points,
232  const std::vector<int>& model,
233  const Geom::Dir& extrudeDir,
234  double thickness,
235  bool askForHoles);
236 
237  virtual bool _triangulateClosedPolyline( const std::vector<Geom::Pnt> inputPolyLine, std::vector<Geom::Pnt>& nodes, std::vector<int>& model );
238  virtual bool _tryToCloseMesh(const pConstMesh& mesh,
239  pMesh& newMesh,
240  const std::vector<unsigned int>* mtlIds,
241  std::vector<unsigned int>* newMtlIds);
242  virtual bool _section(const pConstMesh& mesh, const Geom::Pln& pln, std::vector<pFace>& faces);
243  virtual pFace _getCreaseAngleFace(const pConstMesh& mesh, double creaseAngle, int faceIndex);
244  virtual bool _getCreaseAngleFaceMesh(const pConstMesh& mesh,
245  double creaseAngle,
246  int faceIndex,
247  std::vector<Geom::Pnt>* points,
248  std::vector<int>* linesModel,
249  std::vector<int>* trianglesModel,
250  double* area);
251 
253 };
254 
255 } // namespace Topo
Topo::MeshTool::triangulationToMesh
static pMesh triangulationToMesh(pConstShape shape)
Topo::MeshTool::getElementsFromOMFFile
static std::vector< App::Element * > getElementsFromOMFFile(Core::CoreDocument *doc, const Base::String &fileName, double scaleFactor=1., bool terrain=false)
Reads in a OMF file and converts each OMF into an App::Element.
Draw
Definition: PropertyContainer.h:30
Core::CoreDocument
Definition: CoreDocument.h:269
Topo::MeshTool::getCreaseAngle
static bool getCreaseAngle(pConstMesh mesh, float &angle)
Topo::MeshTool::convertMesh2Shape
static pShape convertMesh2Shape(pConstMesh mesh, std::vector< std::vector< Geom::Pnt >> &defectPolygons)
Converts a mesh to a BREP shape (shell or solid)
Topo::MeshTool::makeMeshFromBrepData
static pMesh makeMeshFromBrepData(pConstBrepData data)
Makes a mesh from BrepData.
Topo::MeshTool::isClosed
static bool isClosed(pConstMesh mesh)
Checks if the mesh is closed ( = it has no boundary edges[1] ).
Topo::MeshTool::convertMesh2Solid
static pShape convertMesh2Solid(pConstMesh aMesh, bool prefer_stiching, bool onlyClosedSolid, bool mergePlanarFaces)
pFace
std::shared_ptr< Topo::Face > pFace
Definition: Types.h:53
Topo::LineItem::points
std::vector< Geom::Pnt > points
Definition: MeshTool.h:38
Topo::LineItem::material
Draw::OglMaterial material
Definition: MeshTool.h:39
pConstShape
std::shared_ptr< Topo::Shape const > pConstShape
Definition: Variant.h:65
Topo::MeshTool
Tools for creating, manipulating and querying Meshes.
Definition: MeshTool.h:49
Geom::Dir
Definition: Dir.h:45
Topo::MeshTool::isPlanar
static bool isPlanar(pConstMesh mesh)
Checks if the mesh is planar ( = all its points lay on the same plane ).
Topo::MeshTool::MeshTool
MeshTool(void)
pShape
std::shared_ptr< Topo::Shape > pShape
Definition: Variant.h:64
Geom::Pln
Definition: Pln.h:52
pMesh
std::shared_ptr< Topo::MeshShape > pMesh
Definition: Types.h:49
Topo::MeshTool::makeMesh
static pMesh makeMesh(const std::vector< Geom::Pnt > &nodes, const std::vector< int > &model, const std::vector< Geom::Pnt > &normals)
Makes a mesh from Nodes and normals.
Core
Definition: Base.h:5
Topo::MeshTool::makeMesh
static pMesh makeMesh(const std::vector< Geom::Pnt > &nodes, const std::vector< int > &model, const std::vector< Geom::Pnt2d > &textureCoords, const std::vector< int > &textureCoordIndices, const std::vector< Geom::Pnt > &normals)
Makes a mesh from Nodes and Texture-Coordinates.
Topo::MeshTool::convertMesh2Shell
static pShape convertMesh2Shell(pConstMesh mesh, std::vector< std::vector< Geom::Pnt >> &defectPolygons)
Converts a mesh to an open or closed shell.
Topo::MeshTool::triangulationToMesh
static pMesh triangulationToMesh(pConstShape shape, bool highQuality, std::vector< int > *newToOldFaceIdxMap=0)
pConstBrepData
std::shared_ptr< const Geom::BrepData > pConstBrepData
Definition: BrepData.h:31
pConstMesh
std::shared_ptr< Topo::MeshShape const > pConstMesh
Definition: Types.h:66
Topo::MeshTool::copy
static pMesh copy(pConstMesh mesh, bool deepCopy=false)
Makes a copy of the mesh.
Topo
Definition: DbgInfo.h:17
Types.h
Topo::MeshTool::convertMesh2Brep_by_Face_Stiching
static pShape convertMesh2Brep_by_Face_Stiching(pConstMesh mesh, std::vector< std::vector< Geom::Pnt >> &defectPolygons)
Converts a mesh to a BREP shape (shell or solid)
Topo::MeshTool::getMesh
static bool getMesh(pConstMesh mesh, std::vector< Geom::Pnt > &nodes, std::vector< int > &model, std::vector< Draw::SurfaceStyle > &surfaceStyles, std::vector< int > &faceIndices, std::vector< int > &surfaceStyleIndices, std::vector< Geom::Pnt2d > &textureCoords, std::vector< int > &textureCoordIndices, std::vector< Topo::LineItem > *lineItems=0)
Topo::MeshTool::makeMesh
static pMesh makeMesh(const std::vector< Geom::Pnt > &nodes, const std::vector< int > &model)
Makes a mesh from Nodes.
Pln.h
Topo::MeshTool::~MeshTool
virtual ~MeshTool(void)
Topo::LineItem
Definition: MeshTool.h:37
Base::String
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:18
Topo::MeshTool::convertMesh2Polyhedral
static pShape convertMesh2Polyhedral(pConstMesh mesh, std::vector< std::vector< Geom::Pnt >> &defectPolygons)
Converts a mesh to a Polyhedral (Acis)
Geom
Definition: PropertyContainer.h:33