gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
PolygonMesh.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
35 #ifndef __PolygonMesh_h
36 #define __PolygonMesh_h
37 
38 
69 //******************************************************************************
70 // Include
71 //******************************************************************************
72 #ifndef __gVirtualXRayConfig_h
74 #endif
75 
76 #include <string>
77 #include <vector>
78 #include <map>
79 #include <memory>
80 
81 #ifndef __VBO_h
82 #include "gVirtualXRay/VBO.h"
83 #endif
84 
85 #ifndef __Types_h
86 #include "gVirtualXRay/Types.h"
87 #endif
88 
89 #ifndef __Units_h
90 #include "gVirtualXRay/Units.h"
91 #endif
92 
93 #ifndef __Material_h
94 #include "gVirtualXRay/Material.h"
95 #endif
96 
97 #ifndef __PhotonCrossSection_h
99 #endif
100 
101 
102 //******************************************************************************
103 // namespace
104 //******************************************************************************
105 namespace gVirtualXRay {
106 
107 
108 //==============================================================================
113 //==============================================================================
115 //------------------------------------------------------------------------------
116 {
117 //******************************************************************************
118 public:
119  //--------------------------------------------------------------------------
121  //--------------------------------------------------------------------------
122  PolygonMesh();
123 
124 
125  //--------------------------------------------------------------------------
127 
130  //--------------------------------------------------------------------------
131  PolygonMesh(const PolygonMesh& aPolygonMesh);
132 
133 
134  //--------------------------------------------------------------------------
136  //--------------------------------------------------------------------------
137  ~PolygonMesh();
138 
139 
140  //--------------------------------------------------------------------------
142  //--------------------------------------------------------------------------
143  void reset();
144 
145  //--------------------------------------------------------------------------
147 
150  //--------------------------------------------------------------------------
151  void setDisplayFlag(bool display);
152 
153 
154  //--------------------------------------------------------------------------
156 
159  //--------------------------------------------------------------------------
160  bool getDisplayFlag() const;
161 
162 
163  //--------------------------------------------------------------------------
165  //--------------------------------------------------------------------------
166  void display();
167 
168 
169  //--------------------------------------------------------------------------
171  //--------------------------------------------------------------------------
172  void displayWireFrame();
173 
174 
175  //--------------------------------------------------------------------------
177 
180  //--------------------------------------------------------------------------
181  void displayFaceNormal(RATIONAL_NUMBER aNormalSize = 0.5 * cm);
182 
183 
184  //--------------------------------------------------------------------------
186 
189  //--------------------------------------------------------------------------
190  void displayVertexNormal(RATIONAL_NUMBER aNormalSize = 0.5 * cm);
191 
192 
193  //--------------------------------------------------------------------------
195 
198  //--------------------------------------------------------------------------
199  void setFilename(const char* aFilename);
200 
201 
202  //--------------------------------------------------------------------------
204 
207  //--------------------------------------------------------------------------
208  void setFilename(const std::string& aFilename);
209 
210 
211  //--------------------------------------------------------------------------
213 
216  //--------------------------------------------------------------------------
217  void setFileName(const char* aFilename);
218 
219 
220  //--------------------------------------------------------------------------
222 
225  //--------------------------------------------------------------------------
226  void setFileName(const std::string& aFilename);
227 
228 
229  //--------------------------------------------------------------------------
231 
234  //--------------------------------------------------------------------------
235  const std::string& getFilename() const;
236 
237 
238  //------------------------------------------------------------------------------
240 
243  //------------------------------------------------------------------------------
244  const RATIONAL_NUMBER& getUnitOfLength() const;
245 
246 
247  //--------------------------------------------------------------------------
249 
263  //--------------------------------------------------------------------------
264  void loadSTLFile(bool aMoveToCentreFlag,
265  bool anAutoComputeNormalFlag,
266  bool aPrintDebugInfoFlag,
267  bool aCreateVBOFlag,
268  RATIONAL_NUMBER aScale,
269  int aBufferUsageHing);
270 
271 
272  //--------------------------------------------------------------------------
274  //--------------------------------------------------------------------------
275  void writeSTLFile();
276 
277 
278  //--------------------------------------------------------------------------
280  //--------------------------------------------------------------------------
281  void moveToCentre();
282 
283 
284  //--------------------------------------------------------------------------
286  //--------------------------------------------------------------------------
287  void moveToCenter();
288 
289 
290  //--------------------------------------------------------------------------
292  //--------------------------------------------------------------------------
293  void computeNormalVectors();
294 
295 
296  //--------------------------------------------------------------------------
298 
306  //--------------------------------------------------------------------------
307  bool useVBO(int aBufferUsageHing, int aTypeOfPrimitive);
308 
309 
310  void setHU(short HU);
311  void setHounsfieldUnit(short HU);
312  void setHounsfieldValue(short HU);
313  void setElement(unsigned short Z);
314  void setElement(const std::string& aName);
315  void setMixture(const Mixture& aMixture);
316  void setMixture(const std::map<int, double>& aMixture);
317  void setMixture(const std::map<std::string, double>& aMixture);
318  void setMixture(const std::string& aName);
319  void setCompound(const std::string& aName);
320  void setMassAttenuationCoefficient(double aCoefficient);
321  void setLinearAttenuationCoefficient(double aCoefficient);
322  void setDensity(double aDensity);
323  double getDensity();
324  const std::string& getMaterialLabel() const;
325 
326 
327  //------------------------------------------------------------------------------
329 
332  //------------------------------------------------------------------------------
333  std::string getCompound() const;
334 
335 
336  //------------------------------------------------------------------------------
338 
341  //------------------------------------------------------------------------------
342  std::vector<int> getMixtureElementSet() const;
343 
344 
345  //------------------------------------------------------------------------------
347 
350  //------------------------------------------------------------------------------
351  std::vector<double> getMixtureWeightSet() const;
352 
353 
355 
356 
357  //--------------------------------------------------------------------------
359 
362  //--------------------------------------------------------------------------
363  const VEC3& getLocalMinCorner() const;
364 
365 
366  //--------------------------------------------------------------------------
368 
371  //--------------------------------------------------------------------------
372  const VEC3& getLocalMaxCorner() const;
373 
374 
375  //--------------------------------------------------------------------------
378 
381  //--------------------------------------------------------------------------
382  void applyTranslation(const VEC3& aTranslationVector);
383 
384 
385  //--------------------------------------------------------------------------
388 
393  //--------------------------------------------------------------------------
395 
396 
397  //--------------------------------------------------------------------------
400 
404  //--------------------------------------------------------------------------
405  void applyRotation(const VEC3& aRotationAxis,
406  RATIONAL_NUMBER aRotationAngleInDegrees);
407 
408 
409  //--------------------------------------------------------------------------
412 
415  //--------------------------------------------------------------------------
416  void applyTransform(const MATRIX4& aTransformationMatrix);
417 
418 
419  //--------------------------------------------------------------------------
421 
424  //--------------------------------------------------------------------------
425  unsigned int getFaceNumber() const;
426 
427 
428  //--------------------------------------------------------------------------
430 
433  //--------------------------------------------------------------------------
434  unsigned int getTriangleNumber() const;
435 
436 
437  //--------------------------------------------------------------------------
439 
442  //--------------------------------------------------------------------------
443  unsigned int getFaceNormalNumber() const;
444 
445 
446  //--------------------------------------------------------------------------
448 
451  //--------------------------------------------------------------------------
452  unsigned int getVertexNormalNumber() const;
453 
454 
455  //--------------------------------------------------------------------------
457 
460  //--------------------------------------------------------------------------
461  unsigned int getVertexNumber() const;
462 
463 
464  //--------------------------------------------------------------------------
466 
469  //--------------------------------------------------------------------------
470  unsigned int getIndexNumber() const;
471 
472 
473  //--------------------------------------------------------------------------
476  //--------------------------------------------------------------------------
477  void mergeVertices(bool aPrintDebugInfoFlag = false);
478 
479 
480  //--------------------------------------------------------------------------
482  //--------------------------------------------------------------------------
483  void splitFaces(bool aPrintDebugInfoFlag = false);
484 
485 
486  //--------------------------------------------------------------------------
488 
492  //--------------------------------------------------------------------------
493  VEC3 getVertex(unsigned int anIndex) const;
494 
495 
496  //--------------------------------------------------------------------------
498 
502  //--------------------------------------------------------------------------
503  void setVertex(unsigned int anIndex, const VEC3& aVertex);
504  void setFaceNormal(unsigned int anIndex, const VEC3& aNormalVector);
505  void setVertexNormal(unsigned int anIndex, const VEC3& aNormalVector);
506 
507 
508  //--------------------------------------------------------------------------
510 
514  //--------------------------------------------------------------------------
515  int getIndex(unsigned int anIndex) const;
516 
517 
518  //--------------------------------------------------------------------------
520 
524  //--------------------------------------------------------------------------
525  void setIndex(unsigned int anIndex, unsigned int aValue);
526 
527 
528  //--------------------------------------------------------------------------
530 
534  //--------------------------------------------------------------------------
535  VEC3 getFaceNormal(unsigned int anIndex) const;
536 
537 
538  //--------------------------------------------------------------------------
540 
544  //--------------------------------------------------------------------------
545  VEC3 getVertexNormal(unsigned int anIndex) const;
546 
547 
548  //--------------------------------------------------------------------------
551 
569  //--------------------------------------------------------------------------
570  void setExternalData(int aTypeOfPrimitive,
571  const void* aVertexArray,
572  unsigned int aNumberOfVertices,
573  int aVertexDataType,
574  const void* anIndexArray,
575  unsigned int aNumberOfIndices,
576  int anIndexDataType,
577  bool aCreateVBOFlag,
578  int aTypeOfVBO);
579 
580 
581  //--------------------------------------------------------------------------
584 
594  //--------------------------------------------------------------------------
595  void setExternalData(int aTypeOfPrimitive,
596  const std::vector<float>* aVertexArray,
597  bool aCreateVBOFlag,
598  int aTypeOfVBO);
599 
600 
601  //--------------------------------------------------------------------------
604 
614  //--------------------------------------------------------------------------
615  void setExternalData(int aTypeOfPrimitive,
616  const std::vector<double>* aVertexArray,
617  bool aCreateVBOFlag,
618  int aTypeOfVBO);
619 
620 
621  //--------------------------------------------------------------------------
624 
635  //--------------------------------------------------------------------------
636  void setExternalData(int aTypeOfPrimitive,
637  const std::vector<float>* aVertexArray,
638  const std::vector<unsigned int>* anIndexArray,
639  bool aCreateVBOFlag,
640  int aTypeOfVBO);
641 
642 
643  //--------------------------------------------------------------------------
646 
657  //--------------------------------------------------------------------------
658  void setExternalData(int aTypeOfPrimitive,
659  const std::vector<double>* aVertexArray,
660  const std::vector<unsigned int>* anIndexArray,
661  bool aCreateVBOFlag,
662  int aTypeOfVBO);
663 
664 
665  //--------------------------------------------------------------------------
668 
679  //--------------------------------------------------------------------------
680  void setExternalData(int aTypeOfPrimitive,
681  const std::vector<float>* aVertexArray,
682  const std::vector<unsigned short>* anIndexArray,
683  bool aCreateVBOFlag,
684  int aTypeOfVBO);
685 
686 
687  //--------------------------------------------------------------------------
690 
701  //--------------------------------------------------------------------------
702  void setExternalData(int aTypeOfPrimitive,
703  const std::vector<double>* aVertexArray,
704  const std::vector<unsigned short>* anIndexArray,
705  bool aCreateVBOFlag,
706  int aTypeOfVBO);
707 
708 
709  //--------------------------------------------------------------------------
712 
723  //--------------------------------------------------------------------------
724  void setExternalData(int aTypeOfPrimitive,
725  const std::vector<float>* aVertexArray,
726  const std::vector<unsigned char>* anIndexArray,
727  bool aCreateVBOFlag,
728  int aTypeOfVBO);
729 
730 
731  //--------------------------------------------------------------------------
734 
745  //--------------------------------------------------------------------------
746  void setExternalData(int aTypeOfPrimitive,
747  const std::vector<double>* aVertexArray,
748  const std::vector<unsigned char>* anIndexArray,
749  bool aCreateVBOFlag,
750  int aTypeOfVBO);
751 
752 
753  //--------------------------------------------------------------------------
756 
771  //--------------------------------------------------------------------------
772  void setVBOData(
773  const void* aVertexArray,
774  unsigned int aNumberOfVertices,
775  unsigned int aVertexVBO,
776  unsigned int aNormalVBO,
777  unsigned int aTextureVBO,
778  unsigned int anIndexVBO,
779  unsigned int aNumberOfIndices,
780  int anIndexDataType,
781  const void* aIndexArray = NULL,
782  const void* aNormalArray = NULL
783  );
784 
785 
786  //--------------------------------------------------------------------------
789 
807  //--------------------------------------------------------------------------
808  void setInternalData(int aTypeOfPrimitive,
809  const void* aVertexArray,
810  unsigned int aNumberOfVertices,
811  int aVertexDataType,
812  const void* anIndexArray,
813  unsigned int aNumberOfIndices,
814  int anIndexDataType,
815  bool aCreateVBOFlag,
816  int aTypeOfVBO);
817 
818 
819  //--------------------------------------------------------------------------
822 
833  //--------------------------------------------------------------------------
834  void setInternalData(int aTypeOfPrimitive,
835  const std::vector<float>* aVertexArray,
836  const std::vector<float>* aNormalArray,
837  bool aCreateVBOFlag,
838  int aTypeOfVBO);
839 
840 
841  //--------------------------------------------------------------------------
844 
854  //--------------------------------------------------------------------------
855  void setInternalData(int aTypeOfPrimitive,
856  const std::vector<float>* aVertexArray,
857  bool aCreateVBOFlag,
858  int aTypeOfVBO);
859 
860 
861  //--------------------------------------------------------------------------
864 
875  //--------------------------------------------------------------------------
876  void setInternalData(int aTypeOfPrimitive,
877  const std::vector<double>* aVertexArray,
878  const std::vector<double>* aNormalArray,
879  bool aCreateVBOFlag,
880  int aTypeOfVBO);
881 
882 
883  //--------------------------------------------------------------------------
886 
896  //--------------------------------------------------------------------------
897  void setInternalData(int aTypeOfPrimitive,
898  const std::vector<double>* aVertexArray,
899  bool aCreateVBOFlag,
900  int aTypeOfVBO);
901 
902 
903  //--------------------------------------------------------------------------
906 
917  //--------------------------------------------------------------------------
918  void setInternalData(int aTypeOfPrimitive,
919  const std::vector<float>* aVertexArray,
920  const std::vector<unsigned int>* anIndexArray,
921  bool aCreateVBOFlag,
922  int aTypeOfVBO);
923 
924 
925  void setInternalData(int aTypeOfPrimitive,
926  const std::vector<float>* aVertexArray,
927  const std::vector<float>* aNormalArray,
928  const std::vector<unsigned int>* anIndexArray,
929  bool aCreateVBOFlag,
930  int aTypeOfVBO);
931 
932 
933  //--------------------------------------------------------------------------
936 
947  //--------------------------------------------------------------------------
948  void setInternalData(int aTypeOfPrimitive,
949  const std::vector<double>* aVertexArray,
950  const std::vector<unsigned int>* anIndexArray,
951  bool aCreateVBOFlag,
952  int aTypeOfVBO);
953 
954 
955  //--------------------------------------------------------------------------
958 
970  //--------------------------------------------------------------------------
971  void setInternalData(int aTypeOfPrimitive,
972  const std::vector<double>* aVertexArray,
973  const std::vector<float>* aNormalArray,
974  const std::vector<unsigned int>* anIndexArray,
975  bool aCreateVBOFlag,
976  int aTypeOfVBO);
977 
978 
979  //--------------------------------------------------------------------------
982 
993  //--------------------------------------------------------------------------
994  void setInternalData(int aTypeOfPrimitive,
995  const std::vector<float>* aVertexArray,
996  const std::vector<unsigned short>* anIndexArray,
997  bool aCreateVBOFlag,
998  int aTypeOfVBO);
999 
1000 
1001  //--------------------------------------------------------------------------
1004 
1016  //--------------------------------------------------------------------------
1017  void setInternalData(int aTypeOfPrimitive,
1018  const std::vector<float>* aVertexArray,
1019  const std::vector<float>* aNormalArray,
1020  const std::vector<unsigned short>* anIndexArray,
1021  bool aCreateVBOFlag,
1022  int aTypeOfVBO);
1023 
1024  //--------------------------------------------------------------------------
1027 
1038  //--------------------------------------------------------------------------
1039  void setInternalData(int aTypeOfPrimitive,
1040  const std::vector<double>* aVertexArray,
1041  const std::vector<unsigned short>* anIndexArray,
1042  bool aCreateVBOFlag,
1043  int aTypeOfVBO);
1044 
1045 
1046  //--------------------------------------------------------------------------
1049 
1061  //--------------------------------------------------------------------------
1062  void setInternalData(int aTypeOfPrimitive,
1063  const std::vector<double>* aVertexArray,
1064  const std::vector<float>* aNormalArray,
1065  const std::vector<unsigned short>* anIndexArray,
1066  bool aCreateVBOFlag,
1067  int aTypeOfVBO);
1068 
1069 
1070  //--------------------------------------------------------------------------
1073 
1084  //--------------------------------------------------------------------------
1085  void setInternalData(int aTypeOfPrimitive,
1086  const std::vector<float>* aVertexArray,
1087  const std::vector<unsigned char>* anIndexArray,
1088  bool aCreateVBOFlag,
1089  int aTypeOfVBO);
1090 
1091 
1092  //--------------------------------------------------------------------------
1095 
1107  //--------------------------------------------------------------------------
1108  void setInternalData(int aTypeOfPrimitive,
1109  const std::vector<float>* aVertexArray,
1110  const std::vector<float>* aNormalArray,
1111  const std::vector<unsigned char>* anIndexArray,
1112  bool aCreateVBOFlag,
1113  int aTypeOfVBO);
1114 
1115 
1116  //--------------------------------------------------------------------------
1119 
1130  //--------------------------------------------------------------------------
1131  void setInternalData(int aTypeOfPrimitive,
1132  const std::vector<double>* aVertexArray,
1133  const std::vector<unsigned char>* anIndexArray,
1134  bool aCreateVBOFlag,
1135  int aTypeOfVBO);
1136 
1137 
1138  //--------------------------------------------------------------------------
1141 
1153  //--------------------------------------------------------------------------
1154  void setInternalData(int aTypeOfPrimitive,
1155  const std::vector<double>* aVertexArray,
1156  const std::vector<float>* aNormalArray,
1157  const std::vector<unsigned char>* anIndexArray,
1158  bool aCreateVBOFlag,
1159  int aTypeOfVBO);
1160 
1161 
1162  //--------------------------------------------------------------------------
1165 
1177  //--------------------------------------------------------------------------
1178  void setInternalData(int aTypeOfPrimitive,
1179  const std::vector<double>* aVertexArray,
1180  const std::vector<double>* aNormalArray,
1181  const std::vector<unsigned char>* anIndexArray,
1182  bool aCreateVBOFlag,
1183  int aTypeOfVBO);
1184 
1185 
1186  //--------------------------------------------------------------------------
1189 
1201  //--------------------------------------------------------------------------
1202  void setInternalData(int aTypeOfPrimitive,
1203  const std::vector<double>* aVertexArray,
1204  const std::vector<double>* aNormalArray,
1205  const std::vector<unsigned short>* anIndexArray,
1206  bool aCreateVBOFlag,
1207  int aTypeOfVBO);
1208 
1209 
1210  //--------------------------------------------------------------------------
1213 
1225  //--------------------------------------------------------------------------
1226  void setInternalData(int aTypeOfPrimitive,
1227  const std::vector<double>* aVertexArray,
1228  const std::vector<double>* aNormalArray,
1229  const std::vector<unsigned int>* anIndexArray,
1230  bool aCreateVBOFlag,
1231  int aTypeOfVBO);
1232 
1233 
1234  //--------------------------------------------------------------------------
1237 
1240  //--------------------------------------------------------------------------
1241  void applyScale(const RATIONAL_NUMBER& aScale);
1242 
1243 
1244  //--------------------------------------------------------------------------
1247 
1252  //--------------------------------------------------------------------------
1253  void applyScale(const RATIONAL_NUMBER& aScaleX,
1254  const RATIONAL_NUMBER& aScaleY,
1255  const RATIONAL_NUMBER& aScaleZ);
1256 
1257 
1258  //--------------------------------------------------------------------------
1260  //--------------------------------------------------------------------------
1261  void invertNormalVectors();
1262 
1263 
1264  //--------------------------------------------------------------------------
1266 
1273  //--------------------------------------------------------------------------
1274  virtual void updateVBO(int aTypeOfVBO, int aTypeOfPrimitive);
1275 
1276 
1277  //--------------------------------------------------------------------------
1279 
1285  //--------------------------------------------------------------------------
1286  virtual void updateVBOs(unsigned int aVertexVBO,
1287  unsigned int aNormalVBO,
1288  unsigned int aTextureVBO,
1289  unsigned int anIndexVBO);
1290 
1291 
1292  //--------------------------------------------------------------------------
1294 
1297  //--------------------------------------------------------------------------
1298  const Material& getMaterial() const;
1299 
1300 
1301  //--------------------------------------------------------------------------
1303 
1306  //--------------------------------------------------------------------------
1307  Material& getMaterial();
1308 
1309 
1310  //--------------------------------------------------------------------------
1312 
1315  //--------------------------------------------------------------------------
1316  virtual void copyFrom(const PolygonMesh& aPolygonMesh);
1317 
1318 
1319  //--------------------------------------------------------------------------
1321 
1325  //--------------------------------------------------------------------------
1326  virtual PolygonMesh& operator=(const PolygonMesh& aPolygonMesh);
1327 
1328 
1329  //--------------------------------------------------------------------------
1331 
1335  //--------------------------------------------------------------------------
1336  virtual PolygonMesh operator+(const PolygonMesh& aPolygonMesh) const;
1337 
1338 
1339  //--------------------------------------------------------------------------
1341 
1345  //--------------------------------------------------------------------------
1346  virtual PolygonMesh operator-(const PolygonMesh& aPolygonMesh) const;
1347 
1348 
1349  //--------------------------------------------------------------------------
1351 
1355  //--------------------------------------------------------------------------
1356  virtual PolygonMesh& operator+=(const PolygonMesh& aPolygonMesh);
1357 
1358 
1359  //--------------------------------------------------------------------------
1361 
1365  //--------------------------------------------------------------------------
1366  virtual PolygonMesh& operator-=(const PolygonMesh& aPolygonMesh);
1367 
1368 
1369  //--------------------------------------------------------------------------
1371 
1375  //--------------------------------------------------------------------------
1376  virtual PolygonMesh operator+(const VEC3& aTranslationVector) const;
1377 
1378 
1379  //--------------------------------------------------------------------------
1381 
1385  //--------------------------------------------------------------------------
1386  virtual PolygonMesh operator-(const VEC3& aTranslationVector) const;
1387 
1388 
1389  //--------------------------------------------------------------------------
1391 
1395  //--------------------------------------------------------------------------
1396  virtual PolygonMesh& operator+=(const VEC3& aTranslationVector);
1397 
1398 
1399  //--------------------------------------------------------------------------
1401 
1405  //--------------------------------------------------------------------------
1406  virtual PolygonMesh& operator-=(const VEC3& aTranslationVector);
1407 
1408 
1409  std::map<RATIONAL_NUMBER, VEC3> rayIntersect(
1410  const VEC3& aRayOrigin,
1411  const VEC3& aRayDirection,
1412  const MATRIX4& aTransformationMatrix) const;
1413 
1414 
1415  void getTriangleVertices(VEC3& v0, VEC3& v1, VEC3& v2, unsigned int anIndex) const;
1416 
1417 
1418  //--------------------------------------------------------------------------
1420 
1423  //--------------------------------------------------------------------------
1424  bool hasNormalVectorsInverted() const;
1425 
1426 
1427 //******************************************************************************
1428 protected:
1429  //--------------------------------------------------------------------------
1431  //--------------------------------------------------------------------------
1432  void computeBoundingBox();
1433 
1434 
1435  //--------------------------------------------------------------------------
1437  //--------------------------------------------------------------------------
1438  void normaliseNormals();
1439 
1440 
1441  //--------------------------------------------------------------------------
1443  //--------------------------------------------------------------------------
1444  void destroyVertexData();
1445 
1446 
1447  //--------------------------------------------------------------------------
1449  //--------------------------------------------------------------------------
1450  void destroyIndexData();
1451 
1452 
1453  //--------------------------------------------------------------------------
1455  //--------------------------------------------------------------------------
1456  void removeIndex(bool aPrintDebugInfoFlag = false);
1457 
1458 
1459  //--------------------------------------------------------------------------
1461  //--------------------------------------------------------------------------
1462  void copyVertexSet(const void* apVertexSet);
1463 
1464 
1465  //--------------------------------------------------------------------------
1467  //--------------------------------------------------------------------------
1468  void copyIndexSet(const void* apIndexSet);
1469 
1470 
1471  //--------------------------------------------------------------------------
1473 
1487  //--------------------------------------------------------------------------
1488  void loadASCIISTLFile(bool aMoveToCentreFlag,
1489  bool anAutoComputeNormalFlag,
1490  bool aPrintDebugInfoFlag,
1491  bool aCreateVBOFlag,
1492  RATIONAL_NUMBER aScale,
1493  int aBufferUsageHing);
1494 
1495 
1496  //--------------------------------------------------------------------------
1498 
1512  //--------------------------------------------------------------------------
1513  void loadBinarySTLFile(bool aMoveToCentreFlag,
1514  bool anAutoComputeNormalFlag,
1515  bool aPrintDebugInfoFlag,
1516  bool aCreateVBOFlag,
1517  RATIONAL_NUMBER aScale,
1518  int aBufferUsageHing);
1519 
1520 
1521  //--------------------------------------------------------------------------
1523 
1538  //--------------------------------------------------------------------------
1539  void loadSTLDataFromBinaryStream(const char* apInputData,
1540  bool aMoveToCentreFlag,
1541  bool anAutoComputeNormalFlag,
1542  bool aPrintDebugInfoFlag,
1543  bool aCreateVBOFlag,
1544  RATIONAL_NUMBER aScale,
1545  int aBufferUsageHing);
1546 
1547 
1549  std::string m_filename;
1550 
1551 
1554 
1555 
1557 #if __cplusplus < 199711L
1558  std::auto_ptr<VBO> m_p_vbo;
1559  std::auto_ptr<PolygonMesh> m_p_face_normal_vbo;
1560  std::auto_ptr<PolygonMesh> m_p_vertex_normal_vbo;
1561 #else
1562  std::unique_ptr<VBO> m_p_vbo;
1563  std::unique_ptr<PolygonMesh> m_p_face_normal_vbo;
1564  std::unique_ptr<PolygonMesh> m_p_vertex_normal_vbo;
1565 #endif
1566 
1567 
1570 
1571 
1574 
1575 
1578 
1579 
1581  //std::vector<RATIONAL_NUMBER> m_p_face_normal_set;
1582 
1583 
1585  std::vector<RATIONAL_NUMBER> m_p_vertex_normal_set;
1586 
1587 
1590 
1591 
1594 
1595 
1597  unsigned int m_number_of_indices;
1598 
1599 
1601  unsigned int m_number_of_vertices;
1602 
1603 
1607 
1608 
1612 
1613 
1616 
1617 
1622 
1623 
1627 
1628 
1631 
1632 
1635 };
1636 
1637 
1638 } // namespace gVirtualXRay
1639 
1640 
1641 //******************************************************************************
1642 #include "PolygonMesh.inl"
1643 
1644 
1645 #endif // __PolygonMesh_h
void * m_p_vertex_set
Array containing the vertices.
Definition: PolygonMesh.h:1589
void applyTransform(const MATRIX4 &aTransformationMatrix)
void copyVertexSet(const void *apVertexSet)
Copy a vertex set.
bool hasNormalVectorsInverted() const
Check if the normal vectors have been inverted.
virtual void updateVBO(int aTypeOfVBO, int aTypeOfPrimitive)
Update the VBO.
void copyIndexSet(const void *apIndexSet)
Copy an index set.
void setLinearAttenuationCoefficient(double aCoefficient)
Type declarations.
void loadASCIISTLFile(bool aMoveToCentreFlag, bool anAutoComputeNormalFlag, bool aPrintDebugInfoFlag, bool aCreateVBOFlag, RATIONAL_NUMBER aScale, int aBufferUsageHing)
Set the name of the file that contains the polygon mesh.
VEC3 getVertex(unsigned int anIndex) const
Accessor on a given vertex.
void applyScaling(RATIONAL_NUMBER x, RATIONAL_NUMBER y, RATIONAL_NUMBER z)
void getTriangleVertices(VEC3 &v0, VEC3 &v1, VEC3 &v2, unsigned int anIndex) const
const std::string & getFilename() const
Accessor on the name of the file that contains the polygon mesh.
void loadBinarySTLFile(bool aMoveToCentreFlag, bool anAutoComputeNormalFlag, bool aPrintDebugInfoFlag, bool aCreateVBOFlag, RATIONAL_NUMBER aScale, int aBufferUsageHing)
Set the name of the file that contains the polygon mesh.
const PhotonCrossSection & getPhotonCrossSection() const
void setMassAttenuationCoefficient(double aCoefficient)
void display()
Display the triangular mesh using OpenGL.
virtual void updateVBOs(unsigned int aVertexVBO, unsigned int aNormalVBO, unsigned int aTextureVBO, unsigned int anIndexVBO)
Update the VBOs with VBO already created.
VEC3 m_local_max_corner
Upper corner of the bounding box.
Definition: PolygonMesh.h:1577
unsigned int m_number_of_indices
Number of indices.
Definition: PolygonMesh.h:1597
const Material & getMaterial() const
Accessor on the material of the polygon mesh.
void displayFaceNormal(RATIONAL_NUMBER aNormalSize=0.5 *cm)
Display the face normal vectors.
virtual PolygonMesh operator-(const PolygonMesh &aPolygonMesh) const
operator-.
void setVertex(unsigned int anIndex, const VEC3 &aVertex)
Change the value of a given vertex.
Class to handle vertex buffer objects (VBOs).
void setDisplayFlag(bool display)
Set if the mesh is displayed or not.
Definition: PolygonMesh.inl:91
std::auto_ptr< PolygonMesh > m_p_face_normal_vbo
Definition: PolygonMesh.h:1559
unsigned int m_number_of_vertices
Number of vertices.
Definition: PolygonMesh.h:1601
void loadSTLDataFromBinaryStream(const char *apInputData, bool aMoveToCentreFlag, bool anAutoComputeNormalFlag, bool aPrintDebugInfoFlag, bool aCreateVBOFlag, RATIONAL_NUMBER aScale, int aBufferUsageHing)
Set the name of the file that contains the polygon mesh.
const VEC3 & getLocalMaxCorner() const
Accessor on the bounding box upper corner.
void computeNormalVectors()
Compute the normal vectors using the cross product method.
void setElement(unsigned short Z)
void setFileName(const char *aFilename)
Set the name of the file that contains the polygon mesh.
unsigned int getIndexNumber() const
Accessor on the number of indices.
virtual PolygonMesh operator+(const PolygonMesh &aPolygonMesh) const
operator+.
void * m_p_index_set
Array containing the index.
Definition: PolygonMesh.h:1593
void setExternalData(int aTypeOfPrimitive, const void *aVertexArray, unsigned int aNumberOfVertices, int aVertexDataType, const void *anIndexArray, unsigned int aNumberOfIndices, int anIndexDataType, bool aCreateVBOFlag, int aTypeOfVBO)
void reset()
Reset the data.
const std::string & getMaterialLabel() const
virtual void copyFrom(const PolygonMesh &aPolygonMesh)
Copy.
virtual PolygonMesh & operator+=(const PolygonMesh &aPolygonMesh)
operator+=.
void moveToCenter()
Move the polygon to the center.
PolygonMesh()
Default constructor.
bool useVBO(int aBufferUsageHing, int aTypeOfPrimitive)
Use a vertex buffer object if possible.
virtual PolygonMesh & operator-=(const PolygonMesh &aPolygonMesh)
operator-=.
virtual PolygonMesh & operator=(const PolygonMesh &aPolygonMesh)
Copy operator.
int m_polygon_type
Polygon type; valid values are GL_TRIANGLES.
Definition: PolygonMesh.h:1615
PolygonMesh is a class to handle polygon (triangles) meshes.
Definition: PolygonMesh.h:114
VEC3 getVertexNormal(unsigned int anIndex) const
Accessor on a given vertex normal.
void moveToCentre()
Move the polygon to the centre.
void setHounsfieldValue(short HU)
float RATIONAL_NUMBER
Type of data used to store real numbers.
Definition: Types.h:107
void setIndex(unsigned int anIndex, unsigned int aValue)
Set the value of a given index.
void setDensity(double aDensity)
bool m_has_inverted_normal_vectors
A flag set to true if the normal vectors are inverted.
Definition: PolygonMesh.h:1634
Class to manage photon cross sections of elements, compounds and mixtures.
PhotonCrossSection is a class to manage photon cross sections of elements, compounds and mixtures...
VEC3 getFaceNormal(unsigned int anIndex) const
Accessor on a given face normal.
unsigned int getVertexNormalNumber() const
Accessor on the number of vertex normal vectors.
void applyTranslation(const VEC3 &aTranslationVector)
void destroyIndexData()
Release the memory held by the index data if needed.
void setVertexNormal(unsigned int anIndex, const VEC3 &aNormalVector)
unsigned int getVertexNumber() const
Accessor on the number of vertices.
Material m_material
Material of the object.
Definition: PolygonMesh.h:1630
void setHounsfieldUnit(short HU)
const double cm
centimeter
Definition: Units.h:106
const VEC3 & getLocalMinCorner() const
Accessor on the bounding box lower corner.
void applyRotation(const VEC3 &aRotationAxis, RATIONAL_NUMBER aRotationAngleInDegrees)
PhotonCrossSection m_photon_cross_section
Material properties, with respect to X-ray.
Definition: PolygonMesh.h:1569
void setVBOData(const void *aVertexArray, unsigned int aNumberOfVertices, unsigned int aVertexVBO, unsigned int aNormalVBO, unsigned int aTextureVBO, unsigned int anIndexVBO, unsigned int aNumberOfIndices, int anIndexDataType, const void *aIndexArray=NULL, const void *aNormalArray=NULL)
std::auto_ptr< VBO > m_p_vbo
Vertex buffer object.
Definition: PolygonMesh.h:1558
Units, such as meters, etc.
void writeSTLFile()
Write the STL file.
void displayWireFrame()
Display the triangular mesh in wireframe using OpenGL.
Material is a class to handle materials.
Definition: Material.h:86
void mergeVertices(bool aPrintDebugInfoFlag=false)
void computeBoundingBox()
Update the bounding box.
std::vector< RATIONAL_NUMBER > m_p_vertex_normal_set
Array containing the normal vectors (one per triangle)
Definition: PolygonMesh.h:1585
int getIndex(unsigned int anIndex) const
Accessor on a given index.
unsigned int getFaceNormalNumber() const
Accessor on the number of face normal vectors.
void destroyVertexData()
Release the memory held by the vertex data if needed.
~PolygonMesh()
Destructor.
Definition: PolygonMesh.inl:84
std::string m_filename
Name of the file that contains the polygon mesh.
Definition: PolygonMesh.h:1549
std::vector< double > getMixtureWeightSet() const
Accessor on the element weight set of the mixture of the polygon mesh.
void loadSTLFile(bool aMoveToCentreFlag, bool anAutoComputeNormalFlag, bool aPrintDebugInfoFlag, bool aCreateVBOFlag, RATIONAL_NUMBER aScale, int aBufferUsageHing)
Set the name of the file that contains the polygon mesh.
Mixture is a class to manage a mixture (e.g. Ti90Al6V4).
Definition: Mixture.h:101
std::string getCompound() const
Accessor on the compound description of the polygon mesh.
void setInternalData(int aTypeOfPrimitive, const void *aVertexArray, unsigned int aNumberOfVertices, int aVertexDataType, const void *anIndexArray, unsigned int aNumberOfIndices, int anIndexDataType, bool aCreateVBOFlag, int aTypeOfVBO)
bool getDisplayFlag() const
Accessor on the display flag of the polygon mesh.
Definition: PolygonMesh.inl:99
RATIONAL_NUMBER m_file_scale
Unit of length of the file that contains the polygon mesh (if negative, then unknown) ...
Definition: PolygonMesh.h:1553
std::auto_ptr< PolygonMesh > m_p_vertex_normal_vbo
Definition: PolygonMesh.h:1560
void applyScale(const RATIONAL_NUMBER &aScale)
void setMixture(const Mixture &aMixture)
void setCompound(const std::string &aName)
Class to handle polygon (triangles) meshes.
void displayVertexNormal(RATIONAL_NUMBER aNormalSize=0.5 *cm)
Display the vertex normal vectors.
void setFaceNormal(unsigned int anIndex, const VEC3 &aNormalVector)
unsigned int getFaceNumber() const
Accessor on the number of faces.
std::vector< int > getMixtureElementSet() const
Accessor on the element Z number set of the mixture of the polygon mesh.
void setFilename(const char *aFilename)
Set the name of the file that contains the polygon mesh.
void invertNormalVectors()
Inverse the normal vectors.
void normaliseNormals()
Normalise the normal vectors.
VEC3 m_local_min_corner
Lower corner of the bounding box.
Definition: PolygonMesh.h:1573
unsigned int getTriangleNumber() const
Accessor on the number of triangles.
const RATIONAL_NUMBER & getUnitOfLength() const
Accessor on the unit of length of the mesh.
Class to handle a material.
void splitFaces(bool aPrintDebugInfoFlag=false)
Split each face into four faces.
std::map< RATIONAL_NUMBER, VEC3 > rayIntersect(const VEC3 &aRayOrigin, const VEC3 &aRayDirection, const MATRIX4 &aTransformationMatrix) const
void removeIndex(bool aPrintDebugInfoFlag=false)
Remove the index.