16 #include <QApplication>
20 -1, -1, -1, -1, -1, 0, -1, -1, 1, -1, 0, -1, -1, 0, 0, -1,
21 0, 1, -1, 1, -1, -1, 1, 0, -1, 1, 1, 0, -1, -1, 0, -1,
22 0, 0, -1, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 0, 1, 0,
23 0, 1, 1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 0, -1, 1,
24 0, 0, 1, 0, 1, 1, 1, -1, 1, 1, 0, 1, 1, 1};
28 m_currentFacetPoints(nullptr),
29 m_currentFacetError(0),
31 m_errorMeasure(
cloudViewer::DistanceComputationTools::RMS),
32 m_useRetroProjectionError(false),
33 m_propagateProgressCb(nullptr),
34 m_propagateProgress(0) {}
50 if (!subset || subset->
size() == 0)
return false;
76 bool useRetroProjectionError,
85 progressCb->
setInfo(qPrintable(QString(
"Level: %1").arg(level)));
97 size_t cellCount = cellCodes.size();
100 static_cast<unsigned>(cellCount));
102 progressCb->
setInfo(qPrintable(
103 QString(
"Level: %1\nCells: %2").arg(level).arg(cellCount)));
107 while (!cellCodes.empty()) {
111 theOctree->
getCellPos(cellCodes.back(), level, cellPos,
true);
132 cellCodes.pop_back();
155 if (minTCellIndex == 0)
return 0;
193 const float& t_old = nCell->
T;
196 if (t_new < t_old) nCell->
T = t_new;
231 float orientationConfidence = 0;
237 static_cast<float>(AB.
dot(oCell->
N)));
239 static_cast<float>(AB.
dot(dCell->
N)));
240 orientationConfidence =
241 (psOri + psDest) / 2;
247 theLSQPlaneEquation[0] = oCell->
N.
x;
248 theLSQPlaneEquation[1] = oCell->
N.
y;
249 theLSQPlaneEquation[2] = oCell->
N.
z;
250 theLSQPlaneEquation[3] = oCell->
C.
dot(oCell->
N);
258 if (reprojError >= 0)
259 return (1.0f - orientationConfidence) *
260 static_cast<float>(reprojError);
264 return (1.0f - orientationConfidence) ;
286 std::vector<unsigned char>& flags,
287 unsigned facetIndex) {
291 for (
unsigned k = 0; k < pointCount; ++k) {
296 static_cast<ScalarType
>(facetIndex));
319 for (
unsigned k = 0; k < Yk.
size(); ++k) {
321 assert(flags[index] == 1);
363 if (!cell)
return -1;
385 assert(seedCount <= 1);
391 assert(seedCell !=
nullptr);
392 assert(seedCell->
T == 0);
405 nCell->
T = seedCell->
T +
418 bool useRetroProjectionError ,
423 unsigned numberOfPoints = theCloud->
size();
424 if (numberOfPoints == 0)
return -1;
433 QApplication::processEvents();
438 QScopedPointer<cloudViewer::DgmOctree> tempOctree;
441 tempOctree.reset(theOctree);
442 if (theOctree->
build(progressCb) < 1) {
449 progressCb->
setMethodTitle(
"Fast Marching for facets extraction");
450 progressCb->
setInfo(
"Initializing...");
453 QApplication::processEvents();
457 "[FastMarchingForFacetExtraction] Couldn't enable scalar "
458 "field! Not enough memory?");
464 for (
unsigned i = 0; i != theCloud->
size(); ++i)
469 std::vector<unsigned char> flags;
471 flags.resize(numberOfPoints, 0);
472 }
catch (
const std::bad_alloc&) {
473 CVLog::Warning(
"[FastMarchingForFacetExtraction] Not enough memory!");
481 errorMeasure, useRetroProjectionError, progressCb);
484 "[FastMarchingForFacetExtraction] Something went wrong during "
485 "initialization...");
495 qPrintable(QString(
"Octree level: %1\nPoints: %2")
497 .arg(numberOfPoints)));
500 QApplication::processEvents();
511 unsigned resolvedPoints = 0;
512 int lastProcessedPoint = -1;
513 unsigned facetIndex = 0;
517 ++lastProcessedPoint;
518 }
while (lastProcessedPoint <
static_cast<int>(numberOfPoints) &&
519 flags[lastProcessedPoint] != 0);
522 if (lastProcessedPoint ==
static_cast<int>(numberOfPoints)) {
548 if (propagationResult < 0) {
558 resolvedPoints +=
count;
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
void normalize()
Sets vector norm to unity.
Type dot(const Vector3Tpl &v) const
Dot product.
Type norm2() const
Returns vector square norm.
A 3D cloud interface with associated features (color, normals, octree, etc.)
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
The octree structure used throughout the library.
GenericIndexedCloudPersist * associatedCloud() const
Returns the associated cloud.
void getCellPos(CellCode code, unsigned char level, Tuple3i &cellPos, bool isCodeTruncated) const
static const int MAX_OCTREE_LEVEL
Max octree subdivision level.
bool getPointsInCell(CellCode cellCode, unsigned char level, ReferenceCloud *subset, bool isCodeTruncated=false, bool clearOutputCloud=true) const
Returns the points lying in a specific cell.
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos) const
std::vector< CellCode > cellCodesContainer
Octree cell codes container.
int build(GenericProgressCallback *progressCb=nullptr)
Builds the structure.
bool getCellCodes(unsigned char level, cellCodesContainer &vec, bool truncatedCodes=false) const
A generic Fast Marching grid cell.
static float T_INF()
Returns infinite time value.
float T
Front arrival time.
virtual void addActiveCell(unsigned index)
Add a cell to the ACTIVE cells list.
unsigned pos2index(const Tuple3i &pos) const
Cell ** m_theGrid
Grid used to process Fast Marching.
virtual float computeT(unsigned index)
Computes the front arrival time at a given cell.
DgmOctree * m_octree
Associated octree.
std::vector< unsigned > m_activeCells
ACTIVE cells list.
unsigned char m_gridLevel
Equivalent octree subdivision level.
bool m_initialized
Specifiies whether structure is initialized or not.
virtual void addTrialCell(unsigned index)
Add a cell to the TRIAL cells list.
float m_neighboursDistance[26]
Neighbours distance weight.
virtual int initGridWithOctree(DgmOctree *octree, unsigned char gridLevel)
virtual bool setSeedCell(const Tuple3i &pos)
Sets a given cell as "seed".
unsigned m_numberOfNeighbours
Current number of neighbours (6 or 26)
virtual void addIgnoredCell(unsigned index)
Add a cell to the IGNORED cells list.
virtual unsigned getNearestTrialCell()
Returns the TRIAL cell with the smallest front arrival time.
int m_neighboursIndexShift[26]
Neighbours coordinates shifts in grid.
virtual void cleanLastPropagation()
virtual unsigned size() const =0
Returns the number of points.
virtual void setPointScalarValue(unsigned pointIndex, ScalarType value)=0
Sets the ith point associated scalar value.
virtual void stop()=0
Notifies the fact that the process has ended.
virtual void setInfo(const char *infoStr)=0
Notifies some information about the ongoing process.
virtual void setMethodTitle(const char *methodTitle)=0
Notifies the algorithm title.
virtual bool textCanBeEdited() const
Returns whether the dialog title and info can be updated or not.
virtual void update(float percent)=0
Notifies the algorithm progress.
virtual bool isCancelRequested()=0
Checks if the process should be canceled.
const PointCoordinateType * getLSPlane()
Returns best interpolating plane equation (Least-square)
const CCVector3 * getGravityCenter()
Returns gravity center.
bool oneStep()
Increments total progress value of a single unit.
ScalarField * getCurrentOutScalarField() const
Returns the scalar field currently associated to the cloud output.
void setPointScalarValue(unsigned pointIndex, ScalarType value) override
unsigned size() const override
const CCVector3 * getPoint(unsigned index) const override
bool enableScalarField() override
A very simple point cloud (no point duplication)
virtual GenericIndexedCloudPersist * getAssociatedCloud()
Returns the associated (source) cloud.
unsigned size() const override
Returns the number of points.
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
virtual bool resize(unsigned n)
Presets the size of the vector used to store point references.
virtual void clear(bool releaseMemory=false)
Clears the cloud.
bool add(const ReferenceCloud &cloud)
Add another reference cloud.
__host__ __device__ float2 fabs(float2 v)
static void error(char *msg)
Generic file read and write utility for python interface.