| 1 |
//########################################################################## |
| 2 |
//# # |
| 3 |
//# CLOUDCOMPARE PLUGIN: qFacets # |
| 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: Thomas Dewez, BRGM # |
| 15 |
//# # |
| 16 |
//########################################################################## |
| 17 |
|
| 18 |
#ifndef QFACET_FAST_MARCHING_FOR_FACET_EXTRACTION_HEADER |
| 19 |
#define QFACET_FAST_MARCHING_FOR_FACET_EXTRACTION_HEADER |
| 20 |
|
| 21 |
//CCCoreLib |
| 22 |
#include <FastMarching.h> |
| 23 |
#include <GenericProgressCallback.h> |
| 24 |
#include <DistanceComputationTools.h> |
| 25 |
|
| 26 |
//qCC_db |
| 27 |
#include <ccAdvancedTypes.h> |
| 28 |
|
| 29 |
class ccGenericPointCloud; |
| 30 |
class ccPointCloud; |
| 31 |
|
| 32 |
//! Fast Marching algorithm for planar facets extraction (qFacets plugin) |
| 33 |
/** Extends the FastMarching class. |
| 34 |
**/ |
| 35 |
class FastMarchingForFacetExtraction : public CCCoreLib::FastMarching |
| 36 |
{ |
| 37 |
public: |
| 38 |
|
| 39 |
//! Static entry point (helper) |
| 40 |
static int ExtractPlanarFacets( ccPointCloud* theCloud, |
| 41 |
unsigned char octreeLevel, |
| 42 |
ScalarType maxError, |
| 43 |
CCCoreLib::DistanceComputationTools::ERROR_MEASURES errorMeasure, |
| 44 |
bool useRetroProjectionError = true, |
| 45 |
CCCoreLib::GenericProgressCallback* progressCb = nullptr, |
| 46 |
CCCoreLib::DgmOctree* _theOctree = nullptr); |
| 47 |
|
| 48 |
//! Default constructor |
| 49 |
FastMarchingForFacetExtraction(); |
| 50 |
|
| 51 |
//! Destructor |
| 52 |
virtual ~FastMarchingForFacetExtraction(); |
| 53 |
|
| 54 |
//! Initializes the grid with a point cloud (and ist corresponding octree) |
| 55 |
/** The points should be associated to an (active) scalar field. |
| 56 |
The Fast Marching grid will have the same dimensions as |
| 57 |
the input octree considered at a given level of subdivision. |
| 58 |
\param theOctree an octree, associated to a point cloud |
| 59 |
\param gridLevel the level of subdivision |
| 60 |
\param maxError maximum error allowed by 'propagated' facet |
| 61 |
\param errorMeasure error measure |
| 62 |
\param useRetroProjectionError whether to use retro-projection error in propagation |
| 63 |
\param progressCb progeress callback |
| 64 |
\return a negative value if something went wrong |
| 65 |
**/ |
| 66 |
int init( CCCoreLib::DgmOctree* theOctree, |
| 67 |
unsigned char gridLevel, |
| 68 |
ScalarType maxError, |
| 69 |
CCCoreLib::DistanceComputationTools::ERROR_MEASURES errorMeasure, |
| 70 |
bool useRetroProjectionError, |
| 71 |
CCCoreLib::GenericProgressCallback* progressCb = nullptr); |
| 72 |
|
| 73 |
//! Updates a list of point flags, indicating the points alreay processed |
| 74 |
/** \return the number of newly flagged points |
| 75 |
**/ |
| 76 |
unsigned updateFlagsTable( ccGenericPointCloud* theCloud, |
| 77 |
std::vector<unsigned char>& flags, |
| 78 |
unsigned facetIndex); |
| 79 |
|
| 80 |
//! Sets the propagation progress callback |
| 81 |
void setPropagateCallback(CCCoreLib::GenericProgressCallback* propagateProgressCb) { m_propagateProgressCb = propagateProgressCb; m_propagateProgress = 0; } |
| 82 |
|
| 83 |
//inherited methods (see FastMarchingAlgorithm) |
| 84 |
virtual int propagate() override; |
| 85 |
virtual bool setSeedCell(const Tuple3i& pos) override; |
| 86 |
|
| 87 |
protected: |
| 88 |
|
| 89 |
//! A Fast Marching grid cell for planar facets extraction |
| 90 |
class PlanarCell : public CCCoreLib::FastMarching::Cell |
| 91 |
{ |
| 92 |
public: |
| 93 |
//! Default constructor |
| 94 |
PlanarCell() |
| 95 |
: Cell() |
| 96 |
, N(0, 0, 0) |
| 97 |
, C(0, 0, 0) |
| 98 |
, cellCode(0) |
| 99 |
, planarError(0) |
| 100 |
{} |
| 101 |
|
| 102 |
///! Destructor |
| 103 |
virtual ~PlanarCell() {} |
| 104 |
|
| 105 |
//! The local cell normal |
| 106 |
CCVector3 N; |
| 107 |
//! The local cell center |
| 108 |
CCVector3 C; |
| 109 |
//! the code of the equivalent cell in the octree |
| 110 |
CCCoreLib::DgmOctree::CellCode cellCode; |
| 111 |
//! Cell planarity error |
| 112 |
ScalarType planarError; |
| 113 |
}; |
| 114 |
|
| 115 |
//inherited methods (see FastMarchingAlgorithm) |
| 116 |
virtual float computeTCoefApprox(CCCoreLib::FastMarching::Cell* currentCell, CCCoreLib::FastMarching::Cell* neighbourCell) const override; |
| 117 |
virtual int step() override; |
| 118 |
virtual void initTrialCells() override; |
| 119 |
virtual bool instantiateGrid(unsigned size) override { return instantiateGridTpl<PlanarCell*>(size); } |
| 120 |
|
| 121 |
//! Adds a given cell's points to the current facet and returns the resulting RMS |
| 122 |
ScalarType addCellToCurrentFacet(unsigned index); |
| 123 |
|
| 124 |
//! Current facet points |
| 125 |
CCCoreLib::ReferenceCloud* m_currentFacetPoints; |
| 126 |
|
| 127 |
//! Current facet error |
| 128 |
ScalarType m_currentFacetError; |
| 129 |
|
| 130 |
//! Max facet error |
| 131 |
ScalarType m_maxError; |
| 132 |
|
| 133 |
//! Error measrue |
| 134 |
CCCoreLib::DistanceComputationTools::ERROR_MEASURES m_errorMeasure; |
| 135 |
|
| 136 |
//! Whether to use retro-projection error in propagation |
| 137 |
bool m_useRetroProjectionError; |
| 138 |
|
| 139 |
//! Propagation progress callback |
| 140 |
CCCoreLib::GenericProgressCallback* m_propagateProgressCb; |
| 141 |
//! Propagation progress |
| 142 |
unsigned m_propagateProgress; |
| 143 |
}; |
| 144 |
|
| 145 |
#endif //QFACET_FAST_MARCHING_FOR_FACET_EXTRACTION_HEADER |