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