ccEnvelopeExtractor.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. //qCC_db
  19. #include <ccPolyline.h>
  20. //CCCoreLib
  21. #include <PointProjectionTools.h>
  22. //! Envelope extractor (with debug GUI)
  23. class ccEnvelopeExtractor
  24. {
  25. public:
  26. //! Envelope type
  27. enum EnvelopeType { LOWER, UPPER, FULL };
  28. //! Extracts a unique closed (2D) envelope polyline of a point cloud
  29. /** Projects the cloud on its best fitting LS plane first.
  30. \param points point cloud
  31. \param allowMultiPass whether to allow multi-pass process (with longer edges potentially generated so as 'disturb' the initial guess)
  32. \param maxEdgeLength max edge length (ignored if 0, in which case the envelope is the convex hull)
  33. \param preferredNormDim to specifiy a preferred (normal) direction for the polyline extraction
  34. \param preferredUpDir to specifiy a preferred up direction for the polyline extraction (preferredNormDim must be defined as well and must be normal to this 'up' direction)
  35. \param envelopeType to specify a type of envelope (you should define a 'up' direction to get proper lower and upper envelope)
  36. \param[out] originalPointIndexes to get the indexes (relatively to the input cloud) of the output polyline vertices
  37. \param enableVisualDebugMode whether to display a (debug) window to represent the algorithm process
  38. \param maxAngleDeg max angle between segments (angle between 0 and 180, in degrees)
  39. \return envelope polyline (or 0 if an error occurred)
  40. **/
  41. static ccPolyline* ExtractFlatEnvelope( CCCoreLib::GenericIndexedCloudPersist* points,
  42. bool allowMultiPass,
  43. PointCoordinateType maxEdgeLength = 0,
  44. const PointCoordinateType* preferredNormDim = nullptr,
  45. const PointCoordinateType* preferredUpDir = nullptr,
  46. EnvelopeType envelopeType = FULL,
  47. std::vector<unsigned>* originalPointIndexes = nullptr,
  48. bool enableVisualDebugMode = false,
  49. double maxAngleDeg = 0.0);
  50. //! Extracts one or several parts of the (2D) envelope polyline of a point cloud
  51. /** Projects the cloud on its best fitting LS plane first.
  52. \warning output polylines set (parts) may be empty if all the vertices are too far from each other!
  53. \param points point cloud
  54. \param allowMultiPass whether to allow multi-pass process (with longer edges potentially generated so as 'disturb' the initial guess)
  55. \param maxEdgeLength max edge length (ignored if 0, in which case the envelope is the convex hull)
  56. \param[out] parts output polyline parts
  57. \param envelopeType envelope type (FULL by default)
  58. \param allowSplitting whether the polyline can be split or not
  59. \param preferredNormDim to specifiy a preferred (normal) direction for the polyline extraction
  60. \param preferredUpDir to specifiy a preferred up direction for the polyline extraction (preferredNormDim must be defined as well and must be normal to this 'up' direction)
  61. \param enableVisualDebugMode whether to display a (debug) window to represent the algorithm process
  62. \return success
  63. **/
  64. static bool ExtractFlatEnvelope(CCCoreLib::GenericIndexedCloudPersist* points,
  65. bool allowMultiPass,
  66. PointCoordinateType maxEdgeLength,
  67. std::vector<ccPolyline*>& parts,
  68. EnvelopeType envelopeType = FULL,
  69. bool allowSplitting = true,
  70. const PointCoordinateType* preferredNormDim = nullptr,
  71. const PointCoordinateType* preferredUpDir = nullptr,
  72. bool enableVisualDebugMode = false);
  73. protected:
  74. //! Determines the 'concave' hull of a set of points
  75. /** Inspired from JIN-SEO PARK AND SE-JONG OH, "A New Concave Hull Algorithm
  76. and Concaveness Measure for n-dimensional Datasets", 2012
  77. Calls extractConvexHull2D (see associated warnings).
  78. \note Almost the same method as CCCoreLib::PointProjectionTools::ExtractConcaveHull2D
  79. but with partial envelope support and visual debug mode.
  80. \param points input set of points
  81. \param hullPoints output points (on the convex hull)
  82. \param envelopeType type of envelope (above / below / full)
  83. \param allowMultiPass whether to allow multi-pass process (with longer edges potentially generated so as 'disturb' the initial guess)
  84. \param maxSquareLength maximum square length (ignored if <= 0, in which case the method simply returns the convex hull!)
  85. \param enableVisualDebugMode whether to display a (debug) window to represent the algorithm process
  86. \param maxAngleDeg max angle between segments (angle between 0 and 180, in degrees)
  87. \return success
  88. **/
  89. static bool ExtractConcaveHull2D( std::vector<CCCoreLib::PointProjectionTools::IndexedCCVector2>& points,
  90. std::list<CCCoreLib::PointProjectionTools::IndexedCCVector2*>& hullPoints,
  91. EnvelopeType envelopeType,
  92. bool allowMultiPass,
  93. PointCoordinateType maxSquareLength = 0,
  94. bool enableVisualDebugMode = false,
  95. double maxAngleDeg = 90.0);
  96. };