44 unsigned n = subset->
size();
45 for (
unsigned i = 0; i < n; ++i) {
65 unsigned char level) {
75 while (!cellCodes.empty()) {
83 theOctree->
getCellPos(cellCodes.back(), level, cellPos,
true);
117 static_cast<float>(AB.
dot(originCell->
N)));
119 fabs(
static_cast<float>(AB.
dot(destCell->
N)));
120 float oriConfidence = (psOri + psDest) / 2;
122 return 1.0f - oriConfidence;
131 bool inverseNormal =
false;
134 #ifndef USE_BEST_NEIGHBOR_ONLY
146 #ifdef USE_BEST_NEIGHBOR_ONLY
147 if (confidence > bestConf) {
148 bestConf = confidence;
149 float ps =
static_cast<float>(nCell->
N.
dot(N));
150 inverseNormal = (ps < 0);
154 float ps =
static_cast<float>(nCell->
N.
dot(N));
157 confNeg += confidence;
160 confPos += confidence;
166 #ifndef USE_BEST_NEIGHBOR_ONLY
167 inverseNormal = (nNeg == nPos ? confNeg > confPos : nNeg > nPos);
168 bestConf = inverseNormal ? confNeg : confPos;
182 static unsigned s_cellIndex = 0;
189 if (minTCellIndex == 0)
return 0;
196 if (s_cellIndex == 0) {
200 ->scalar =
static_cast<float>(0);
204 static_cast<float>(s_cellIndex++);
225 const float& t_old = nCell->
T;
228 if (t_new < t_old) nCell->
T = t_new;
264 std::vector<unsigned char>& resolved,
281 for (
unsigned k = 0; k < Yk.
size(); ++k) {
289 if (N.
dot(aCell->
N) < 0) {
309 assert(seedCount <= 1);
311 if (seedCount == 1) {
315 assert(seedCell !=
nullptr);
316 assert(seedCell->
T == 0);
331 nCell->
T = seedCell->
T +
343 if (!cloud || !cloud->
normals()) {
344 const QString
name((cloud ==
nullptr) ? QStringLiteral(
"[unnamed]")
347 CVLog::Warning(QString(
"[orientNormalsWithFM] Cloud '%1' is invalid "
348 "(or cloud has no normals)")
355 unsigned numberOfPoints = cloud->
size();
356 if (numberOfPoints == 0)
return -1;
362 "octree on cloud '%1'")
372 bool sfWasDisplayed = cloud->
sfShown();
381 "[orientNormalsWithFM] Couldn't create temporary scalar field! "
382 "Not enough memory?");
388 "[orientNormalsWithFM] Couldn't enable temporary scalar field! "
389 "Not enough memory?");
396 std::vector<unsigned char> resolved;
398 resolved.resize(numberOfPoints, 0);
399 }
catch (
const std::bad_alloc&) {
412 "[orientNormalsWithFM] Something went wrong during "
413 "initialization...");
424 qPrintable(QString(
"Octree level: %1\nPoints: %2")
426 .arg(numberOfPoints)));
438 unsigned resolvedPoints = 0;
439 int lastProcessedPoint = -1;
444 ++lastProcessedPoint;
445 }
while (lastProcessedPoint <
static_cast<int>(numberOfPoints) &&
446 resolved[lastProcessedPoint] != 0);
449 if (lastProcessedPoint ==
static_cast<int>(numberOfPoints))
break;
459 cellPos.
x = std::min(octreeWidth, cellPos.
x);
460 cellPos.
y = std::min(octreeWidth, cellPos.
y);
461 cellPos.
z = std::min(octreeWidth, cellPos.
z);
470 if (propagationResult >= 0) {
475 resolvedPoints +=
count;
477 progressCb->
update(resolvedPoints /
478 (numberOfPoints * 100.0f));
484 "An error occurred during front propagation! Process "
490 if (progressCb) progressCb->
stop();
500 cloud->
showSF(sfWasDisplayed);
503 return (success ? 1 : 0);
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.
Array of compressed 3D normals (single index)
void normalize()
Sets vector norm to unity.
Type dot(const Vector3Tpl &v) const
Dot product.
Type & getValue(size_t index)
void setValue(size_t index, const Type &value)
virtual bool sfShown() const
Returns whether active scalar field is visible.
virtual bool hasNormals() const
Returns whether normals are enabled or not.
virtual void showNormals(bool state)
Sets normals visibility.
virtual void showSF(bool state)
Sets active scalarfield visibility.
A Fast Marching grid cell for normals direction resolution.
cloudViewer::DgmOctree::CellCode cellCode
the code of the equivalent cell in the octree
CCVector3 N
The local cell normal.
float signConfidence
Confidence value.
CCVector3 C
The local cell center.
Fast Marching algorithm for normals direction resolution.
float computePropagationConfidence(DirectionCell *originCell, DirectionCell *destCell) const
Computes relative 'confidence' between two cells (orientations)
int step() override
Propagates the front (one step)
ccFastMarchingForNormsDirection()
Default constructor.
void resolveCellOrientation(unsigned index)
Resolves the direction of a given cell (once and for all)
float computeTCoefApprox(cloudViewer::FastMarching::Cell *currentCell, cloudViewer::FastMarching::Cell *neighbourCell) const override
Computes the front acceleration between two cells.
static int OrientNormals(ccPointCloud *theCloud, unsigned char octreeLevel, ecvProgressDialog *progressCb=nullptr)
Static entry point (helper)
int propagate() override
Propagates the front.
void initTrialCells() override
Initializes the TRIAL cells list.
unsigned updateResolvedTable(ccGenericPointCloud *theCloud, std::vector< unsigned char > &resolved, NormsIndexesTableType *theNorms)
Updates a list of point flags, indicating the points already processed.
int init(ccGenericPointCloud *cloud, NormsIndexesTableType *theNorms, ccOctree *theOctree, unsigned char gridLevel)
Initializes the grid with a point cloud (and ist corresponding octree)
A 3D cloud interface with associated features (color, normals, octree, etc.)
virtual const CCVector3 & getPointNormal(unsigned pointIndex) const =0
Returns normal corresponding to a given point.
virtual ccOctree::Shared computeOctree(cloudViewer::GenericProgressCallback *progressCb=nullptr, bool autoAddChild=true)
Computes the cloud octree.
virtual ccOctree::Shared getOctree() const
Returns the associated octree (if any)
static const CCVector3 & GetNormal(unsigned normIndex)
Static access to ccNormalVectors::getNormal.
static CompressedNormType GetNormIndex(const PointCoordinateType N[])
Returns the compressed index corresponding to a normal vector.
virtual QString getName() const
Returns object name.
QSharedPointer< ccOctree > Shared
Shared pointer.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void setCurrentDisplayedScalarField(int index)
Sets the currently displayed scalar field.
NormsIndexesTableType * normals() const
Returns pointer on compressed normals indexes table.
ccScalarField * getCurrentDisplayedScalarField() const
Returns the currently displayed scalar (or 0 if none)
int addScalarField(const char *uniqueName) override
Creates a new scalar field and registers it.
int getCurrentDisplayedScalarFieldIndex() const
Returns the currently displayed scalar field index (or -1 if none)
void deleteScalarField(int index) override
Deletes a specific scalar field.
void computeMinAndMax() override
Determines the min and max values.
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.
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 void setPointScalarValue(unsigned pointIndex, ScalarType value)=0
Sets the ith point associated scalar value.
A generic 3D point cloud with index-based point access.
virtual bool textCanBeEdited() const
Returns whether the dialog title and info can be updated or not.
const CCVector3 * getGravityCenter()
Returns gravity center.
int getScalarFieldIndexByName(const char *name) const
Returns the index of a scalar field represented by its name.
void setCurrentScalarField(int index)
Sets both the INPUT & OUTPUT scalar field.
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
Graphical progress indicator (thread-safe)
virtual void stop() override
Notifies the fact that the process has ended.
virtual void update(float percent) override
Notifies the algorithm progress.
virtual void setInfo(const char *infoStr) override
Notifies some information about the ongoing process.
virtual void start() override
virtual void setMethodTitle(const char *methodTitle) override
Notifies the algorithm title.
unsigned int CompressedNormType
Compressed normals type.
static CCVector3 ComputeRobustAverageNorm(cloudViewer::ReferenceCloud *subset, ccGenericPointCloud *sourceCloud)
Generic file read and write utility for python interface.