All Classes Functions Variables Enumerations Pages
surfaceExtraction.h
1 #ifndef SURFACEEXTRACTION_H
2 #define SURFACEEXTRACTION_H
3 #include <myTraits.h>
4 #include <MeshManipulation/translateToCog.h>
5 #include <MeshManipulation/transformMesh.h>
6 #include <MeshAnalysis/faceArea.h>
7 
8 
9 
10 
11 namespace ilato {
12 
14 {
15 public:
16  // surfaceExtraction();
33  void createSurface(volume_parameters &settings, MyMesh &mesh, double threshold=7000, bool connected=false, bool mixedMode=true, bool extraPoints=false);
40  void setBorderOffset(double bOffset);
45  void clear4refresh();
50  bool existComplexEdges();
54  void setMediumMode();
59  bool getMediumMode();
63  void setSemiConnectedMode();
68  bool getSpecialMode();
72  void setSpecialMode();
78  void setModeDecided(bool decided);
83  void setSurfaceColor(int n);
84 
91  void setFeatureEdges(bool fEdges);
92 
98  void setDeleteZeroFaces(bool zerofaced);
99 
100  // surfaceExtraction_HELPER.CPP
101  // -> for surfaceExtraction_helper.cpp
102  /*
103  void createDensityData(int xEdgeL, int yEdgeL, int zEdgeL);
104  void createDensityData(ilato::volume_parameters& settings, int xEdgeL, int yEdgeL, int zEdgeL);
105  void createDensityData2(volume_parameters &settings);
106  void createDensityData3(volume_parameters &settings);
107  void changeDensityData(int testcase, std::vector<double> &densities);
108  void createMeshFromData(volume_parameters &settings, MyMesh &mesh, double threshold);
109  void createTestCycles(MyMesh &mesh);
110  void createTestcases(volume_parameters &settings, std::vector<MyMesh> &myMeshes);
111  void createPointcloud(volume_parameters &settings, MyMesh &mesh, double threshold); // -> for surfaceExtraction_helper.cpp
112  std::string clipVolume(MyMesh &mesh); // -> for surfaceExtraction_helper.cpp
113  void createSurfaceOld(volume_parameters &settings, MyMesh &mesh, double threshold, bool connected, bool mixedMode, bool extraPoints);
114  void setTestCounter(int testCounter); // -> for surfaceExtraction_helper.cpp
115  */
116  // ilato::volume_parameters loadDataFromMHD(std::string filename);
117  // void createSurface(MyMesh &mesh, bool connection = false, double threshold = 0.0);
118  // <- surfaceExtraction_helper.cpp
119 
120 private:
122  bool complexEdgeError = false;
124  bool mediumMode = false;
126  bool semiConnectedMode = false;
128  bool specialMode = false;
130  bool modeDecided = false;
132  bool drawPOAs = false;
134  double borderOffset = 0.0;
136  bool computeNormals = true;
138  bool deleteZeroFaces = true;
140  bool featureEdges = false;
142  double minSpacing = 0.000001; // = 1 nanometer
147  MyMesh::Color fcpColor = MyMesh::Color(0,0.9,0,0.9);
148 
150  enum start {north, east, south, west};
151 
154  int cube[7][4] = {{0,0,0,0}, //empty since ori=0 does not exist
155  {3,2,4,5}, {1,3,6,4}, {1,5,6,2},
156  {1,2,6,5}, {1,4,6,3}, {4,2,3,5}};
157 
159  start stdDirection[7][4] = {{north, north, north, north}, //nonsense since ori=0 does not exist
160  {east, east, east, east}, {south, north, south, south}, {east, north, west, south},
161  {west, north, east, south}, {north, north, north, south}, {west, west, west, west}};
162 
164  start altDirection[7][4] = {{north, north, north, north}, //nonsense since ori=0 does not exist
165  {west, west, west, west}, {north, north, north, south}, {east, north, west, south},
166  {west, north, east, south}, {south, north, south, south}, {east, east, east, east}};
167 
169  int offsetCube[7][4][3];
170 
172  int doffset[7];
173 
181  struct fcp {
182  int ori; // orientation of the face (=1,2,3,4,5,6)
183  int i; // position in xf,yf or zf
184  MyMesh::VertexHandle vertex;
185  // prev handle
186  // next handle
187  bool visitedNorth = false;
188  bool visitedEast = false;
189  bool visitedSouth = false;
190  bool visitedWest = false;
191  void visited(start dir) {
192  switch (dir) {
193  case north: visitedNorth=true; break;
194  case east: visitedEast=true; break;
195  case south: visitedSouth=true; break;
196  case west: visitedWest=true; break;
197  default: std::cerr << "wrong assignment in fcp.visited()" << std::endl;
198  }
199  }
200  };
201 
203  std::vector<fcp> allFCP;
204 
209  std::vector<int> xfIndex;
213  std::vector<int> yfIndex;
217  std::vector<int> zfIndex;
218 
221  std::vector<int> *(indexStd[7][2]) = {{&zfIndex, &xfIndex}, //nonsense since ori=0 does not exist
222  {&zfIndex, &xfIndex}, {&yfIndex, &zfIndex},{&yfIndex, &xfIndex},
223  {&yfIndex, &xfIndex}, {&yfIndex, &zfIndex},{&zfIndex, &xfIndex}};
224 
227  std::vector<int> *(indexAlt[7]) = {&yfIndex, //nonsense since ori=0 does not exist
228  &yfIndex, &xfIndex, &zfIndex, &zfIndex, &xfIndex, &yfIndex};
229 
230 
231  std::vector<int>* stdIndex(int ori, start dir);
232  std::vector<int>* altIndex(int ori);
235  surfaceExtraction::start stdDir(int ori, start dir, bool connec);
236  surfaceExtraction::start altDir(int ori, start dir, bool connec);
237  int offset(int orientation, start dir, int case012, bool connec);
238  int cubeSide(int orientation, start dir, bool connec);
239  int nextOri(int ori, start dir);
240 
250  int nextFCP(int inIndex, start& direction, bool connec);
251 
256  struct poa {
257  int fcp1;
258  int fcp2;
259  int fcp3;
260  int fcp4;
261  start dirFCP1;
262  start dirFCP2;
263  start dirFCP3;
264  start dirFCP4;
265  MyMesh::VertexHandle vertex;
266  };
268  std::vector<poa> allPOA;
269 
272  struct fcpPOA {
273  bool existsPOA = false;
274  bool northConnected = 0; // later implement this with only 1 byte = 8 bits
275  bool eastConnected = 0;
276  bool southConnected = 0;
277  bool westConnected = 0;
278  };
279 
281  std::vector<fcpPOA> allFCPpoa;
282 
283  int threeNeighboursFCPNew(int i, start direction, int& a, int& b, start& d1, start& d2, start& d3); // better implementation
284 
285  void setPOAconnected(int i, bool connected);
286  void setFCPconnected(int fcpIndex, start direction, bool connected);
287  // double poaDensity(int fcp1i, int fcp1ori, int fcp2i, std::vector<double> &densities);
288  double poaDensity(int fcp1i, int fcp1ori, int fcp2i, volume_parameters &settings);
289  // double fcpDensity(int fcpOri, int vd, std::vector<double> &densities);
290  double fcpDensity(int fcpOri, int vd, int xEdgeLength, int yEdgeLength, std::vector<double> &densities);
291 
302  void fillup(volume_parameters &settings, double isoValue, MyMesh &mesh);
303 
312  void createTriangles(int fcpCycle[], int lengthOfCycle, MyMesh &mesh, bool extraPoints);
313  int computeStartIndex(int &lengthOfCycle, int fcpCycle[], bool semicon);
325  bool drawTriangles(int startIndex, int fcpCycle[], int lengthOfCycle,std::vector<MyMesh::FaceHandle>* fHandles, MyMesh &mesh);
334  void computeExtraPoint(int &startIndex, int fcpCycle[], int &lengthOfCycle ,MyMesh &mesh);
335  bool isSameVoxel(int index1, int index2);
336 
337 
338  // surfaceExtraction_HELPER.CPP
339  // -> for surfaceExtraction_helper.cpp
340  /*
341  int calculateIndex(int ex, int ey, int ez); // calculate index from xEdgeLength, yEdgeLength
342  int calculateIndex(int ex, int ey, int ez, int xEdgeL, int yEdgeL);
343  // void calculateDcoordinates(int i, int& x, int&y, int&z);
344  int xEdgeLengthOld, yEdgeLengthOld, zEdgeLengthOld; // -> for surfaceExtraction_helper.cpp
345  int edge2Old, edge1Old; // -> for surfaceExtraction_helper.cpp
346  bool oldFunction; // -> for surfaceExtraction_helper.cpp
347  double isoValueOld; // -> for surfaceExtraction_helper.cpp
348  double xspaceOld, yspaceOld, zspaceOld; // -> for surfaceExtraction_helper.cpp
349  std::vector<fcp> xf, yf, zf; // for old algorithm // -> for surfaceExtraction_helper.cpp
350  fcp* nextFCP(fcp* in, start& direction); // old algorithm!
351  // fcp* originalFCP(fcp* in); // for old algorithm
352  // int nextFCP(int in, start& direction); // this function is more efficent!
353  int nextDisconnectedFCP(int inIndex, start& direction);
354  int nextConnectedFCP(int inIndex, start& direction); // connected mode
355  fcp* originalFCP(fcp* in); // for old algorithm
356  int neighbourFCP(int i, start direction);
357  int threeNeighboursFCP(int i, start direction, int& a, int& b, start& d1, start& d2, start& d3);
358  // void fillup_xf_yf_zf_allFCP(MyMesh &mesh); void fillup_xf_yf_zf_allFCP2(MyMesh &mesh);
359  void fillup_xf_yf_zf_allFCP(MyMesh &mesh, std::vector<double> &densities); void fillup_xf_yf_zf_allFCP2(MyMesh &mesh, std::vector<double> &densities);
360  void fillup_xfIndex_yfIndex_zfIndex_allFCP(MyMesh &mesh); // for the more efficent nextFCP function
361  void fillup_xfIndex_yfIndex_zfIndex_allFCP(std::vector<double> &densities, MyMesh &mesh);
362  // void fillupNew(std::vector<double> &densities, MyMesh &mesh);
363  bool isSameVoxel2(int index1, int index2); // -> for surfaceExtraction_helper.cpp
364  // void computeMpoint(std::vector<MyMesh::VertexHandle> &f4vertices);
365  void computeMpoint(std::vector<MyMesh::VertexHandle> &f4vertices, MyMesh &me);
366  std::vector<MyMesh::VertexHandle> compute7StartPoint(int initFCPIndex, start direction1, bool connec);
367  std::vector<MyMesh::VertexHandle> compute6StartPoint(int initFCPIndex, start direction1, bool connec);
368  std::vector<MyMesh::VertexHandle> compute7mStartPoint(int initFCPIndex, start direction1); // for mixed mode
369  std::vector<MyMesh::VertexHandle> compute6mStartPoint(int initFCPIndex, start direction1); // for mixed mode
370  int testValue;
371  */
372  // <- surfaceExtraction_helper.cpp
373 
374 };
375 } // end of namespace "ilato"
376 
377 #endif // surfaceExtraction_H
start stdDirection[7][4]
determines next movement direction if traveling from ori 1-6 in direction NESW (=0-3) around 90 or 27...
Definition: surfaceExtraction.h:159
std::vector< int > * indexAlt[7]
Definition: surfaceExtraction.h:227
bool deleteZeroFaces
If this variable is true, it will be checked whether faces of zero length were drawn, and these faces will be deleted.
Definition: surfaceExtraction.h:138
bool semiConnectedMode
True if 8 cycles are calculated in the low resolution mode in a secure way.
Definition: surfaceExtraction.h:126
std::vector< poa > allPOA
This vector contains all points of ambiguity (=POA) of the surface.
Definition: surfaceExtraction.h:268
int offset(int orientation, start dir, int case012, bool connec)
This helper function for the next FCP function determines the offset to the adjacent FCPs...
Definition: surfaceExtraction.cpp:630
std::vector< int > * altIndex(int ori)
This helper function for the next FCP function returns the xfIndex-, yfIndex- or zfIndex- vector depe...
Definition: surfaceExtraction.cpp:589
bool getSpecialMode()
This function reports whether the special mode is set.
Definition: surfaceExtraction.cpp:69
int cubeSide(int orientation, start dir, bool connec)
This helper function for the next FCP function returns the cube side of the first case in the crucial...
Definition: surfaceExtraction.cpp:643
int nextOri(int ori, start dir)
This function is not used. It returns a cube side if traveling from ori 1-6 in direction NESW (=0-3) ...
Definition: surfaceExtraction.cpp:565
bool featureEdges
True if feature edges should be drawn.
Definition: surfaceExtraction.h:140
double borderOffset
If this parameter is greater than zero, the surface protrude from the scalar field.
Definition: surfaceExtraction.h:134
Definition: Project.txt:1329
std::vector< int > * indexStd[7][2]
Definition: surfaceExtraction.h:221
int nextFCP(int inIndex, start &direction, bool connec)
That is the crucial function of the VESTA algorithm. Given a face center point (=FCP) and a direction...
Definition: surfaceExtraction.cpp:652
bool mediumMode
True if the medium mode is set.
Definition: surfaceExtraction.h:124
void setSurfaceColor(int n)
With this funtion, the color of the surface can be set.
Definition: surfaceExtraction.cpp:12
double poaDensity(int fcp1i, int fcp1ori, int fcp2i, volume_parameters &settings)
This function computes the density at a point of ambiguity (=between two FCPs)
Definition: surfaceExtraction.cpp:460
std::vector< fcp > allFCP
This vector contains all face center points (=FCP) of the surface.
Definition: surfaceExtraction.h:203
double minSpacing
the minimal distance between the center of a voxel and a FCP
Definition: surfaceExtraction.h:142
bool complexEdgeError
If an complex edge error occurs, this variable is set to true.
Definition: surfaceExtraction.h:122
bool isSameVoxel(int index1, int index2)
This function checks if two faces belong to the same density value/cube. This is needed for computing...
Definition: surfaceExtraction.cpp:1005
start altDirection[7][4]
determines next movement direction if traveling from ori 1-6 in direction NESW (=0-3) around 0 or 180...
Definition: surfaceExtraction.h:164
int offsetCube[7][4][3]
The offsets for the nextFCP function.
Definition: surfaceExtraction.h:169
void createTriangles(int fcpCycle[], int lengthOfCycle, MyMesh &mesh, bool extraPoints)
This function computes the triangulations (= 4-/5-/6-/7-/8-/9-/12-cycle decomposition), and draws the triangles, by calling drawTriangles.
Definition: surfaceExtraction.cpp:794
surfaceExtraction::start iterDir(start dir, int i)
This helper function for the nextFCP function returns the direction of the next VESTA segment in cloc...
Definition: surfaceExtraction.cpp:546
void setMediumMode()
This sets a mode that switches to the high resolution mode, if the cycle length is equal 8 or greater...
Definition: surfaceExtraction.cpp:53
The fcp struct determines on which side of an active voxel the face center point is located (= ori)...
Definition: surfaceExtraction.h:181
double fcpDensity(int fcpOri, int vd, int xEdgeLength, int yEdgeLength, std::vector< double > &densities)
This function computes the density at a FCP (=between two Voxels of the scalar field) ...
Definition: surfaceExtraction.cpp:492
std::vector< fcpPOA > allFCPpoa
This vector contains all the fcpPOAs. It is as large as the allFCP vector.
Definition: surfaceExtraction.h:281
std::vector< int > yfIndex
Definition: surfaceExtraction.h:213
std::vector< int > zfIndex
Definition: surfaceExtraction.h:217
int computeStartIndex(int &lengthOfCycle, int fcpCycle[], bool semicon)
This function computes the start index of the 8 cycle.
Definition: surfaceExtraction.cpp:691
void fillup(volume_parameters &settings, double isoValue, MyMesh &mesh)
This function computes the face center points and puts them all in the allFCP vector. Furthermore, it computes the cuboid which contains the pointers (=indices) pointing to the FCPs in the allFCP vector (this cuboid is represented by the vectors xfIndex, yfIndex and zfIndex). Finally, this function computes edge1 and edge2 (the offsets in y- and z-direction in the cuboid of pointers) and the derived member variables doffset and offsetCube.
Definition: surfaceExtraction.cpp:1019
bool drawPOAs
If this variable is true, points of ambiguities will be drawn.
Definition: surfaceExtraction.h:132
void setDeleteZeroFaces(bool zerofaced)
This setter determines whether defective zero faces should be deleted. This kind of faces is not gene...
Definition: surfaceExtraction.cpp:83
surfaceExtraction::start stdDir(int ori, start dir, bool connec)
This helper function for the next FCP function determines next movement direction if traveling from o...
Definition: surfaceExtraction.cpp:601
int cube[7][4]
Definition: surfaceExtraction.h:154
void setSpecialMode()
This sets a mode that switches to the high resolution mode, if complex edges occurs.
Definition: surfaceExtraction.cpp:73
int threeNeighboursFCPNew(int i, start direction, int &a, int &b, start &d1, start &d2, start &d3)
Given a FCP and a direction, this function find the three FCPs adjacent to a POA. ...
Definition: surfaceExtraction.cpp:524
bool specialMode
True if the special mode is set (low resolution mode and high resolution mode in case of complex edge...
Definition: surfaceExtraction.h:128
void setModeDecided(bool decided)
This function determines whether you will be asked if you want to switch to the special mode in the c...
Definition: surfaceExtraction.cpp:79
Definition: Project.txt:1393
void setPOAconnected(int i, bool connected)
This function specifies that 4 FCP cycles are connected or disconnected.
Definition: surfaceExtraction.cpp:422
bool existComplexEdges()
This function reports whether during the last calculation of the surface complex edges have occured...
Definition: surfaceExtraction.cpp:49
void setSemiConnectedMode()
This sets a mode that calculates 8 cycles in the low resolution mode in a secure way.
Definition: surfaceExtraction.cpp:63
void computeExtraPoint(int &startIndex, int fcpCycle[], int &lengthOfCycle, MyMesh &mesh)
This function computes the center of gravity and adds this point at the beginning and at the end of t...
Definition: surfaceExtraction.cpp:701
int doffset[7]
The offsets between two adjacent voxels depending on the side of the voxel.
Definition: surfaceExtraction.h:172
start
Defines the directions in which one can travel from the face center point of a cube side...
Definition: surfaceExtraction.h:150
bool drawTriangles(int startIndex, int fcpCycle[], int lengthOfCycle, std::vector< MyMesh::FaceHandle > *fHandles, MyMesh &mesh)
This function draws the triangles of a triangulation. If an error occurs (complex edge)...
Definition: surfaceExtraction.cpp:740
Definition: surfaceExtraction.h:272
void clear4refresh()
This function sets all the private member variables to 0. It is required if another surface is to be ...
Definition: surfaceExtraction.cpp:27
This struct determines the point of ambiguity (=POA) and his 4 adjacent FCPs. The start members indic...
Definition: surfaceExtraction.h:256
void setFCPconnected(int fcpIndex, start direction, bool connected)
This function specifies that a FCP is connected in a specific direction.
Definition: surfaceExtraction.cpp:436
Definition: surfaceExtraction.h:13
surfaceExtraction::start prevDir(start dir)
This helper function for the nextFCP function returns the direction of the next VESTA segment in coun...
Definition: surfaceExtraction.cpp:556
void setBorderOffset(double bOffset)
This setter determines whether the surface should protrude from the scalar field when it gets to the ...
Definition: surfaceExtraction.cpp:44
bool modeDecided
True if high resolution mode is selected in case of complex edges.
Definition: surfaceExtraction.h:130
surfaceExtraction::start altDir(int ori, start dir, bool connec)
This helper function for the next FCP function determines next movement direction if traveling from o...
Definition: surfaceExtraction.cpp:615
void createSurface(volume_parameters &settings, MyMesh &mesh, double threshold=7000, bool connected=false, bool mixedMode=true, bool extraPoints=false)
This function generates a surface from a 3-dimensional scalar field using the VESTA algorithm...
Definition: surfaceExtraction.cpp:89
bool computeNormals
True if face normals are to be calculated.
Definition: surfaceExtraction.h:136
MyMesh::Color fcpColor
This variable defines the color of the face center points and therefore it determines the color of th...
Definition: surfaceExtraction.h:147
std::vector< int > * stdIndex(int ori, start dir)
This helper function for the next FCP function returns the xfIndex-, yfIndex- or zfIndex- vector depe...
Definition: surfaceExtraction.cpp:577
bool getMediumMode()
This function reports whether the medium mode is set.
Definition: surfaceExtraction.cpp:59
std::vector< int > xfIndex
Definition: surfaceExtraction.h:209
void setFeatureEdges(bool fEdges)
This setter determines whether additional red edges are drawn for highlighting the cycles of the VEST...
Definition: surfaceExtraction.cpp:38