occ_compatible.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*******************************************************************************
  2. ³ÌÐò˵Ã÷
  3. ½â¾öOCC7.5Óë7.8¼æÈÝÐÔ
  4. *******************************************************************************/
  5. #ifndef OCC_COMPATIBLE_H
  6. #define OCC_COMPATIBLE_H
  7. #include <vector>
  8. #include <Standard_Version.hxx>
  9. using namespace std;
  10. namespace occ_compatible
  11. {
  12. //
  13. //#define OCCT_VERSION_LESS_THAN_7_8 \
  14. // ((OCC_VERSION_MAJOR < 7) || \
  15. // ((OCC_VERSION_MAJOR == 7) && (OCC_VERSION_MINOR < 8)))
  16. #define OCC_VERSION_OPTION_7_5 ((OCC_VERSION_MAJOR == 7) && (OCC_VERSION_MINOR == 5))
  17. #define OCC_VERSION_OPTION_7_8 ((OCC_VERSION_MAJOR == 7) && (OCC_VERSION_MINOR == 8))
  18. #if OCC_VERSION_OPTION_7_5
  19. vector<double> GetNormals(opencascade::handle<Poly_Triangulation> theTris)
  20. {
  21. vector<double> res;
  22. for (int i = 1; i <= theTris->Normals().Size(); i++)
  23. {
  24. res.push_back(theTris->Normals().Value(i));
  25. }
  26. return res;
  27. }
  28. #define POLY_TRIGULATION_TRIANGLES(triFace) triFace->Triangles()
  29. #define POLY_TRIGULATION_NODES(triFace) triFace->Nodes()
  30. #define POLY_TRIGULATION_NORMALS(triFace) occ_compatible::GetNormals(triFace)
  31. #define POLY_TRIGULATION_UVNODES(triFace) triFace->UVNodes()
  32. #elif OCC_VERSION_OPTION_7_8
  33. #include <gp_Vec3f.hxx>
  34. TColgp_Array1OfPnt GetNodes(opencascade::handle<Poly_Triangulation> theTris)
  35. {
  36. const Poly_ArrayOfNodes &aNodes = theTris->InternalNodes();
  37. TColgp_Array1OfPnt aPnt(1, aNodes.Size());
  38. for (int i = 1; i <= aNodes.Size(); i++)
  39. {
  40. gp_Pnt pt = aNodes.Value(i - 1);
  41. aPnt[i] = pt;
  42. }
  43. return aPnt;
  44. }
  45. vector<double> GetNormals(opencascade::handle<Poly_Triangulation> theTris)
  46. {
  47. vector<double> res;
  48. NCollection_Array1<gp_Vec3f> aNormals = theTris->InternalNormals();
  49. for (int i = 1; i <= aNormals.Size(); i++)
  50. {
  51. res.push_back(aNormals.Value(i - 1).x());
  52. res.push_back(aNormals.Value(i - 1).y());
  53. res.push_back(aNormals.Value(i - 1).z());
  54. }
  55. return res;
  56. }
  57. TColgp_Array1OfPnt2d GetUVNodes(opencascade::handle<Poly_Triangulation> theTris)
  58. {
  59. const Poly_ArrayOfUVNodes &aNodes = theTris->InternalUVNodes();
  60. cout << "aNodes Size: " << aNodes.Size() << endl;
  61. TColgp_Array1OfPnt2d aPnt(1, aNodes.Size());
  62. for (int i = 1; i <= aNodes.Size(); i++)
  63. {
  64. aPnt[i] = aNodes.Value(i - 1);
  65. }
  66. return aPnt;
  67. }
  68. #define POLY_TRIGULATION_TRIANGLES(triFace) triFace->InternalTriangles()
  69. #define POLY_TRIGULATION_NODES(triFace) occ_compatible::GetNodes(triFace)
  70. #define POLY_TRIGULATION_NORMALS(triFace) occ_compatible::GetNormals(triFace)
  71. #define POLY_TRIGULATION_UVNODES(triFace) occ_compatible::GetUVNodes(triFace)
  72. #endif
  73. };
  74. #endif