OpenLexocad  27.1
MeshTool.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Draw/OglMaterial.h>
4 #include <Draw/SurfaceStyle.h>
5 #include <Topo/Shape.h>
6 
7 
8 /*
9 @brief MeshTool
10 [1] Boundary edges are edges shared by only one face.
11 */
12 
13 class TopoDS_Shape;
14 
15 namespace Core
16 {
17 class CoreDocument;
18 
19 }
20 
21 namespace App
22 {
23 class Element;
24 }
25 
26 
27 namespace Topo
28 {
29 struct LX_TOPO_EXPORT LineItem
30 {
31  std::vector<Geom::Pnt> points;
32  Draw::OglMaterial material;
33 };
34 
41 class LX_TOPO_EXPORT MeshTool
42 {
43 public:
44  MeshTool(void);
45  virtual ~MeshTool(void);
46 
48  // //
49  // --------------------- BEGIN API --------------------- //
50  // //
51  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
52  // //
54 
56  static pMesh copy(pConstMesh mesh, bool deepCopy = false);
58  static bool isClosed(pConstMesh mesh);
60  static bool isPlanar(pConstMesh mesh);
63  static pMesh triangulationToMesh(pConstShape shape);
66  static pMesh triangulationToMesh(pConstShape shape, bool highQuality, std::vector<int>* newToOldFaceIdxMap = 0);
68  static pShape convertMesh2Shape(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
70  static pShape convertMesh2Solid(pConstMesh aMesh, bool prefer_stiching, bool onlyClosedSolid, bool mergePlanarFaces);
72  static pShape convertMesh2Polyhedral(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
74  static pShape convertMesh2Brep_by_Face_Stiching(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
76  static pShape convertMesh2Shell(pConstMesh mesh, std::vector<std::vector<Geom::Pnt>>& defectPolygons);
78  static pMesh makeMeshFromBrepData(pConstBrepData data);
80  static pMesh makeMesh(const std::vector<Geom::Pnt>& nodes,
81  const std::vector<int>& model,
82  const std::vector<Geom::Pnt2d>& textureCoords,
83  const std::vector<int>& textureCoordIndices,
84  const std::vector<Geom::Pnt>& normals);
86  static pMesh makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model);
87 
89  static pMesh makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model, const std::vector<Geom::Pnt>& normals);
91  static std::vector<App::Element*> getElementsFromOMFFile(Core::CoreDocument* doc,
92  const Base::String& fileName,
93  double scaleFactor = 1.,
94  bool terrain = false);
95 
96  static bool getMesh(pConstMesh mesh,
97  std::vector<Geom::Pnt>& nodes,
98  std::vector<int>& model,
99  std::vector<Draw::SurfaceStyle>& surfaceStyles,
100  std::vector<int>& faceIndices,
101  std::vector<int>& surfaceStyleIndices,
102  std::vector<Geom::Pnt2d>& textureCoords,
103  std::vector<int>& textureCoordIndices,
104  std::vector<Topo::LineItem>* lineItems = 0);
105 
106  static bool getCreaseAngle(pConstMesh mesh, float& angle);
107 
109  // //
110  // ---------------------- END API ---------------------- //
111  // //
113 
114 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
115 
118  static std::vector<App::Element*> getElementsFromOMFFile(Core::CoreDocument* doc,
119  const Base::String& fileName,
120  double scaleFactor,
121  bool terrain,
122  std::map<std::string, Core::Variant>* properties,
123  bool forceTerrainFrom2dr);
124 
125 #ifndef SWIG
126  static std::map<int, std::array<Core::Variant, 6>> getHorizontalPointsFromOMFFile(Core::CoreDocument* doc,
128  const Base::String& fileName,
129  std::map<std::string, Core::Variant>* properties,
130  const double& scaleFactor = 1.);
131  static std::map<int, std::array<Core::Variant, 4>> getVerticalPointsFromOMFFile(Core::CoreDocument* doc,
132  const Base::String& fileName,
133  std::map<std::string, Core::Variant>* properties,
134  const double& scaleFactor = 1.);
135 #endif
136 
137  static void getModel(pConstMesh mesh, std::vector<int>& model);
138  static void getPoints(pConstMesh mesh, std::vector<Geom::Pnt>& points);
139 
140 
142  static void __setDefaultMeshTool__(Topo::MeshTool* tool) { _defaultTool = tool; }
144  static bool writeOmfFile(const std::vector<App::Element*>& elems, const Base::String& fileName);
145 
146  static bool getInventorMeshColors(pConstMesh mesh, std::vector<Base::Color>& uniqueColors, std::vector<std::string>* colorNames = 0);
147 
148 protected:
149 #endif
150 
151 private:
152  virtual pMesh _copy(pConstMesh shape, bool deepCopy);
153  virtual bool _isClosed(pConstMesh mesh);
154  virtual pMesh _triangulationToMesh(pConstShape shape);
155  virtual pMesh _triangulationToMesh(pConstShape shape, bool highQuality, std::vector<int>* newToOldFaceIdxMap);
156  static Topo::MeshTool* _defaultTool;
157 
158  virtual void _getModel(pConstMesh mesh, std::vector<int>& model);
159  virtual void _getPoints(pConstMesh mesh, std::vector<Geom::Pnt>& points);
160  virtual pMesh _makeMeshFromBrepData(pConstBrepData data);
161  virtual std::vector<App::Element*> _getElementsFromOMFFile(Core::CoreDocument* doc,
162  const Base::String& fileName,
163  double scaleFactor,
164  bool terrain,
165  std::map<std::string, Core::Variant>* properties,
166  bool forceTerrainFrom2dr);
167  virtual std::map<int, std::array<Core::Variant, 6>> _getHorizontalPointsFromOMFFile(Core::CoreDocument* doc,
168  const Base::String& fileName,
169  std::map<std::string, Core::Variant>* properties,
170  const double& scaleFactor);
171  virtual std::map<int, std::array<Core::Variant, 4>> _getVerticalPointsFromOMFFile(Core::CoreDocument* doc,
172  const Base::String& fileName,
173  std::map<std::string, Core::Variant>* properties,
174  const double& scaleFactor);
175  virtual bool _writeOmfFile(const std::vector<App::Element*>& elems, const Base::String& fileName);
176  virtual bool _getInventorMeshColors(pConstMesh mesh, std::vector<Base::Color>& uniqueColors, std::vector<std::string>* colorNames);
177  virtual pMesh _makeMesh(const std::vector<Geom::Pnt>& nodes,
178  const std::vector<int>& model,
179  const std::vector<Geom::Pnt2d>& textureCoords,
180  const std::vector<int>& textureCoordIndices,
181  const std::vector<Geom::Pnt>& normals);
182  virtual pMesh _makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model);
183  virtual pMesh _makeMesh(const std::vector<Geom::Pnt>& nodes, const std::vector<int>& model, const std::vector<Geom::Pnt>& normals);
184 
185  virtual bool _getMesh(pConstMesh mesh,
186  std::vector<Geom::Pnt>& nodes,
187  std::vector<int>& model,
188  std::vector<Draw::SurfaceStyle>& surfaceStyles,
189  std::vector<int>& faceIndices,
190  std::vector<int>& surfaceStyleIndices,
191  std::vector<Geom::Pnt2d>& textureCoords,
192  std::vector<int>& textureCoordIndices,
193  std::vector<Topo::LineItem>* lineItems = 0);
194 
195  virtual bool _getCreaseAngle(pConstMesh mesh, float& angle);
196 
198 };
199 
200 } // namespace Topo
Tools for creating, manipulating and querying Meshes.
Definition: MeshTool.h:41
CoreDocument()
Definition: MeshTool.h:29
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:23
Definition: CoreDocument.h:210
std::shared_ptr< const Geom::BrepData > pConstBrepData
Definition: BrepData.h:31
Definition: Base.h:12
Draw::OglMaterial material
Definition: MeshTool.h:32
std::shared_ptr< Topo::MeshShape > pMesh
Definition: Shape.h:77
Definition: Variant.h:55
std::shared_ptr< Topo::Shape const > pConstShape
Definition: Variant.h:77
std::shared_ptr< Topo::MeshShape const > pConstMesh
Definition: Shape.h:92
Base::String fileName
Definition: CoreDocument.h:186
std::shared_ptr< Topo::Shape > pShape
Definition: Variant.h:76
std::vector< Geom::Pnt > points
Definition: MeshTool.h:31