CurveAdaptiveDiscrete.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*******************************************************************************
  2. 程序说明
  3. 曲线离散程序,对Curve数据进行离散,用于后续的显示;
  4. *******************************************************************************/
  5. #ifndef CURVEADAPTIVEDISCRETE_H
  6. #define CURVEADAPTIVEDISCRETE_H
  7. #include <vector>
  8. #include <BRepAdaptor_Curve.hxx>
  9. #include <GCPnts_QuasiUniformDeflection.hxx>
  10. #include <GCPnts_TangentialDeflection.hxx>
  11. #include <GCPnts_UniformDeflection.hxx>
  12. using namespace std;
  13. enum CurveDiscreteMethod {
  14. TangentialDeflection = 0,
  15. QuasiUniformDeflection = 1,
  16. UniformDeflection = 2
  17. };
  18. void CurveAdaptiveDiscrete(const BRepAdaptor_Curve &adaptorCurve,
  19. vector<double> &points, vector<int> &lines,
  20. CurveDiscreteMethod discreteMethod) {
  21. points.clear();
  22. lines.clear();
  23. Standard_Integer pointsLength = 0;
  24. double edgeLength = CPnts_AbscissaPoint::Length(adaptorCurve, 1e-7);
  25. // double adaptingDeflection = 0.1 * edgeLength;
  26. switch (discreteMethod) {
  27. case TangentialDeflection: {
  28. double adaptingDeflection = 0.005 * edgeLength;
  29. GCPnts_TangentialDeflection thePointsOnCurve;
  30. Standard_Real AngularDeflection = 0.3;
  31. Standard_Real CurvatureDeflection = adaptingDeflection;
  32. thePointsOnCurve.Initialize(adaptorCurve, AngularDeflection,
  33. CurvatureDeflection);
  34. pointsLength = thePointsOnCurve.NbPoints();
  35. for (Standard_Integer i = 1; i <= pointsLength; ++i) {
  36. gp_Pnt pt;
  37. pt = adaptorCurve.Value(thePointsOnCurve.Parameter(i));
  38. points.push_back(pt.X());
  39. points.push_back(pt.Y());
  40. points.push_back(pt.Z());
  41. if (i != pointsLength) {
  42. lines.push_back(i - 1);
  43. lines.push_back(i);
  44. }
  45. }
  46. } break;
  47. case QuasiUniformDeflection: {
  48. double adaptingDeflection = 0.007 * edgeLength;
  49. GCPnts_QuasiUniformDeflection thePointsOnCurve;
  50. thePointsOnCurve.Initialize(adaptorCurve, adaptingDeflection);
  51. pointsLength = thePointsOnCurve.NbPoints();
  52. for (Standard_Integer i = 1; i <= pointsLength; ++i) {
  53. gp_Pnt pt;
  54. pt = adaptorCurve.Value(thePointsOnCurve.Parameter(i));
  55. points.push_back(pt.X());
  56. points.push_back(pt.Y());
  57. points.push_back(pt.Z());
  58. if (i != pointsLength) {
  59. lines.push_back(i - 1);
  60. lines.push_back(i);
  61. }
  62. }
  63. } break;
  64. default: {
  65. // cout << "UniformDeflection" << endl;
  66. GCPnts_UniformDeflection thePointsOnCurve;
  67. double adaptingDeflection = 0.007 * edgeLength;
  68. thePointsOnCurve.Initialize(adaptorCurve, adaptingDeflection);
  69. pointsLength = thePointsOnCurve.NbPoints();
  70. for (Standard_Integer i = 1; i <= pointsLength; ++i) {
  71. gp_Pnt pt;
  72. pt = adaptorCurve.Value(thePointsOnCurve.Parameter(i));
  73. points.push_back(pt.X());
  74. points.push_back(pt.Y());
  75. points.push_back(pt.Z());
  76. if (i != pointsLength) {
  77. lines.push_back(i - 1);
  78. lines.push_back(i);
  79. }
  80. }
  81. } break;
  82. }
  83. }
  84. #endif