ccFastMarchingForNormsDirection.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_FAST_MARCHING_DIRECTION_HEADER
  18. #define CC_FAST_MARCHING_DIRECTION_HEADER
  19. //CCCoreLib
  20. #include <DgmOctree.h>
  21. #include <FastMarching.h>
  22. //qCC_db
  23. #include "ccAdvancedTypes.h"
  24. //system
  25. #include <vector>
  26. class ccGenericPointCloud;
  27. class ccPointCloud;
  28. class ccOctree;
  29. class ccProgressDialog;
  30. //! Fast Marching algorithm for normals direction resolution
  31. /** Extends the FastMarching class.
  32. **/
  33. class ccFastMarchingForNormsDirection : public CCCoreLib::FastMarching
  34. {
  35. public:
  36. //! Static entry point (helper)
  37. static int OrientNormals( ccPointCloud* theCloud,
  38. unsigned char octreeLevel,
  39. ccProgressDialog* progressCb = nullptr);
  40. //! Default constructor
  41. ccFastMarchingForNormsDirection();
  42. //! Initializes the grid with a point cloud (and ist corresponding octree)
  43. /** The points should be associated to an (active) scalar field.
  44. The Fast Marching grid will have the same dimensions as
  45. the input octree considered at a given level of subdivision.
  46. \param cloud the point cloud
  47. \param theNorms the normals array
  48. \param theOctree the associated octree
  49. \param gridLevel the level of subdivision
  50. \return a negative value if something went wrong
  51. **/
  52. int init( ccGenericPointCloud* cloud,
  53. NormsIndexesTableType* theNorms,
  54. ccOctree* theOctree,
  55. unsigned char gridLevel);
  56. //! Updates a list of point flags, indicating the points already processed
  57. /** \return the number of resolved points
  58. **/
  59. unsigned updateResolvedTable( ccGenericPointCloud* theCloud,
  60. std::vector<unsigned char>& resolved,
  61. NormsIndexesTableType* theNorms);
  62. //inherited methods (see FastMarchingAlgorithm)
  63. int propagate() override;
  64. protected:
  65. //! A Fast Marching grid cell for normals direction resolution
  66. class DirectionCell : public CCCoreLib::FastMarching::Cell
  67. {
  68. public:
  69. //! Default constructor
  70. DirectionCell()
  71. : Cell()
  72. , N(0,0,0)
  73. , C(0,0,0)
  74. , cellCode(0)
  75. , signConfidence(1)
  76. #ifdef QT_DEBUG
  77. , scalar(0)
  78. #endif
  79. {}
  80. ///! Destructor
  81. ~DirectionCell() override = default;
  82. //! The local cell normal
  83. CCVector3 N;
  84. //! The local cell center
  85. CCVector3 C;
  86. //! the code of the equivalent cell in the octree
  87. CCCoreLib::DgmOctree::CellCode cellCode;
  88. //! Confidence value
  89. float signConfidence;
  90. #ifdef QT_DEBUG
  91. //! Undefined scalar for debug purposes
  92. float scalar;
  93. #endif
  94. };
  95. //inherited methods (see FastMarchingAlgorithm)
  96. float computeTCoefApprox(CCCoreLib::FastMarching::Cell* currentCell, CCCoreLib::FastMarching::Cell* neighbourCell) const override;
  97. int step() override;
  98. void initTrialCells() override;
  99. bool instantiateGrid(unsigned size) override { return instantiateGridTpl<DirectionCell*>(size); }
  100. //! Computes relative 'confidence' between two cells (orientations)
  101. /** \return confidence between 0 and 1
  102. **/
  103. float computePropagationConfidence(DirectionCell* originCell, DirectionCell* destCell) const;
  104. //! Resolves the direction of a given cell (once and for all)
  105. void resolveCellOrientation(unsigned index);
  106. };
  107. #endif