DAVID4 SDK  1.8.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ShapeFusionD4Lib.h
1 //=============================================================================
2 // See License in Related Pages
3 //=============================================================================
4 
5 #pragma once
6 
7 #ifndef DAVID_SDK_SHAPE_FUSION_D4LIB_H
8 #define DAVID_SDK_SHAPE_FUSION_D4LIB_H
9 
10 #include "davidSDK/IShapeFusion.h"
11 #include "davidSDK/d4lib_helpers.h"
12 #include <limits>
13 #include <map>
14 #include <mutex>
15 
16 namespace david {
17 
18 
19 //=============================================================================
20 // ShapeFusionD4Lib
21 //=============================================================================
22 
23 /// Implements interface functions of IShapeFusion using DAVID Low Level Library.
25 {
26 public:
27  //-------------------------------------------------------------------------
28  /// @name (De-)Construction
29  /// @{
30  //-------------------------------------------------------------------------
31 
32  /// Constructor.
34 
35  /// Destructor.
36  virtual ~ShapeFusionD4Lib();
37 
38  /// @}
39 
40  //-------------------------------------------------------------------------
41  /// @name Interface functions from IShapeFusion
42  /// @{
43  //-------------------------------------------------------------------------
44 
45  // See IShapeFusion
46  virtual void ExportMesh(int meshID, const std::string& filename);
47 
48  // See IShapeFusion
49  virtual int ImportMesh(const std::string& filename);
50 
51  // See IShapeFusion
52  virtual int NewMesh();
53 
54  // See IShapeFusion
55  virtual int DuplicateMesh(int sourceMeshID);
56 
57  // See IShapeFusion
58  virtual void DeleteAllMeshes();
59 
60  // See IShapeFusion
61  virtual void DeleteMesh(int meshID);
62 
63  // See IShapeFusion
64  virtual void GetVertexPositions(std::vector<float>& positions, int meshID, enum CoordinateSystem coordinateSystem = WorldCoordinates);
65 
66  // See IShapeFusion
67  virtual void GetVertexQualities(std::vector<float>& qualities, int meshID);
68 
69  // See IShapeFusion
70  virtual void GetVertexNormals(std::vector<float>& normals, int meshID, enum CoordinateSystem coordinateSystem = WorldCoordinates);
71 
72  // See IShapeFusion
73  virtual void GetVertexTexCoords(std::vector<float>& texCoords, int meshID);
74 
75  // See IShapeFusion
76  virtual void GetTriangles(std::vector<int>& triangles, int meshID);
77 
78  // See IShapeFusion
79  virtual void GetTextureImageData(void* data, size_t dataSizeInBytes, int meshID, int submeshIndex = 0);
80 
81  // See IShapeFusion
82  virtual bool GetTextureImageFormat(int& width, int& height, enum PixelFormat& pixelFormat, int meshID, int submeshIndex = 0);
83 
84  // See IShapeFusion
85  virtual void SetTexture(const void* data, size_t dataSizeInBytes, int width, int height, enum PixelFormat pixelFormat, int meshID, int submeshIndex = 0);
86 
87  // See IShapeFusion
88  virtual void GetPose(double world_T_local[16], int meshID);
89 
90  // See IShapeFusion
91  virtual void SetPose(const double world_T_local[16], int meshID);
92 
93  // See IShapeFusion
94  virtual void Rotate(int meshID, enum TransformType transformType, double degrees);
95 
96  // See IShapeFusion
97  virtual void Translate(int meshID, enum TransformType transformType, double amount);
98 
99  // See IShapeFusion
100  virtual void ReduceMeshDensity(int meshID, float factor);
101 
102  // See IShapeFusion
103  virtual void RemoveVerticesByVirtualCamMask(const std::vector<bool>& mask, int width, int height, double f, const double world_T_cam[16]);
104 
105  // See IShapeFusion
106  virtual void RemoveSelectedVertices(const std::vector<SubmeshVertexIndex>& selectedVertices, int meshID);
107 
108  // See IShapeFusion
109  virtual void InvertTriangleOrientation(int meshID);
110 
111  // See IShapeFusion
112  virtual double AlignPairCoarse(int meshID1, int meshID2, const CoarseAlignParams &params);
113 
114  // See IShapeFusion
115  virtual void AlignPairFine(int meshID1, int meshID2, const FineAlignParams &params);
116 
117  // See IShapeFusion
118  virtual void AlignGlobalFine(const GlobalFineAlignParams &params);
119 
120  // See IShapeFusion
121  virtual int Fuse(int resolution, float holeSizeThresRel=1.f, int sharpness=1);
122 
123  // See IShapeFusion
124  virtual int GetFuseResolution(double metricResolution, int maxResolution);
125 
126  // See IShapeFusion
127  virtual int CombineMeshes(const std::vector<int> &meshIDs);
128 
129  // See IShapeFusion
130  virtual std::vector<int> UncombineMeshes(int meshIDgroup);
131 
132  // See IShapeFusion
133  virtual int GetSubmeshCount(int meshID);
134 
135  // See IShapeFusion
136  virtual void SetSubmeshCount(int count, int meshID);
137 
138  // See IShapeFusion
139  virtual void GetSubmeshBuffer(void* data, size_t size, enum SubmeshBufferType bufferType, int meshID, int submeshIndex);
140 
141  // See IShapeFusion
142  virtual void SetSubmeshBuffer(const void* data, size_t size, enum SubmeshBufferType bufferType, int meshID, int submeshIndex);
143 
144  // See IShapeFusion
145  virtual bool HasSubmeshBuffer(enum SubmeshBufferType bufferType, int meshID, int submeshIndex);
146 
147  // See IShapeFusion
148  virtual size_t GetSubmeshBufferSize(enum SubmeshBufferType bufferType, int meshID, int submeshIndex);
149 
150  // See IShapeFusion
151  virtual int GetSubmeshVertexCount(int meshID, int submeshIndex);
152 
153  // See IShapeFusion
154  virtual void SetSubmeshVertexCount(int vertexCount, int meshID, int submeshIndex);
155 
156  // See IShapeFusion
157  virtual int GetSubmeshTriangleCount(int meshID, int submeshIndex);
158 
159  // See IShapeFusion
160  virtual void SetSubmeshTriangleCount(int triangleCount, int meshID, int submeshIndex);
161 
162  /// @}
163 
164  //-------------------------------------------------------------------------
165  /// @name Special functions
166  /// @{
167  //-------------------------------------------------------------------------
168 
169  /// Add a new mesh to the list of scans.
170  /// @param[in,out] mesh Valid handle to mesh. The mesh is stored directly, no copy.
171  /// @return ID of the mesh.
172  int AddToList(std::shared_ptr<d4mesh> mesh);
173 
174  /// Translate (move) mesh into direction (dx, dy, dz) with respect to choosen coordinate system.
175  /// @param[in] meshID Valid mesh ID.
176  /// @param[in] dx Amount of translation in x direction.
177  /// @param[in] dy Amount of translation in y direction.
178  /// @param[in] dz Amount of translation in z direction.
179  /// @param[in] coordinateSystem See #CoordinateSystem.
180  void Translate(int meshID, double dx, double dy, double dz, enum CoordinateSystem coordinateSystem);
181 
182  /// @}
183 
184 protected:
185  //-------------------------------------------------------------------------
186  // Typedefs
187  //-------------------------------------------------------------------------
188 
189  /// Used mutex.
190  typedef std::recursive_mutex Mutex;
191 
192  /// Guard for automatic unlocking.
193  typedef std::lock_guard<std::recursive_mutex> Guard;
194 
195  //-------------------------------------------------------------------------
196  // Private helper functions
197  //-------------------------------------------------------------------------
198 
199  /// Check mesh ID.
200  /// @param[in] meshID ID of the mesh.
201  /// @return #d4ok, #d4error_InvalidMeshId
202  int CheckMeshID(int meshID);
203 
204  /// Get mesh by 'meshID'.
205  /// @param[in] meshID Valid ID of the mesh. Use 0 for fusion result.
206  /// @return Reference to mesh pointer.
207  std::shared_ptr<d4mesh>& GetMesh(int meshID);
208 
209  /// Helper function which converts vertex indices
210  /// from "indices per submesh" (SubmeshVertexIndex)
211  /// to "total indices" over all submeshes
212  void Helper_AlignPairCoarse_ConvertContactVertices(std::vector<int> &contactVertices, int meshID, const std::vector<SubmeshVertexIndex> &svi);
213 
214  //-------------------------------------------------------------------------
215  // Private member variables
216  //-------------------------------------------------------------------------
217 
218  /// Scans are stored with an associated ID.
219  typedef std::map<int, std::shared_ptr<d4mesh> > Scanlist;
220 
221  Scanlist m_scanlist; ///< List of scans.
222  std::shared_ptr<d4mesh> m_fusionResult; ///< Mesh for fusion result.
223  Mutex m_mutex; ///< Used for synchronization
224 };
225 
226 
227 } // namespace
228 
229 #endif // DAVID_SDK_SHAPE_FUSION_D4LIB_H