Skip to content

Commit

Permalink
Minor updates (#65)
Browse files Browse the repository at this point in the history
* Update SimpleMesh so that it can be used with the new ICP option (with normal orientation taken into account)

* Attempt to reduce level 4 warnings (and potential bug fix in the SquareMatrix::svd method)
  • Loading branch information
dgirardeau committed May 31, 2021
1 parent 4b036e0 commit d6ef2b0
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 68 deletions.
8 changes: 4 additions & 4 deletions include/Jacobi.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,19 @@ namespace CCCoreLib
{
for (unsigned iq = ip + 1; iq < n; iq++)
{
Scalar g = std::abs(matrix.m_values[ip][iq]) * 100;
Scalar pq = std::abs(matrix.m_values[ip][iq]) * 100;
//After four sweeps, skip the rotation if the off-diagonal element is small.
if (i > 4
&& static_cast<float>(std::abs(d[ip]) + g) == static_cast<float>(std::abs(d[ip]))
&& static_cast<float>(std::abs(d[iq]) + g) == static_cast<float>(std::abs(d[iq])))
&& static_cast<float>(std::abs(d[ip]) + pq) == static_cast<float>(std::abs(d[ip]))
&& static_cast<float>(std::abs(d[iq]) + pq) == static_cast<float>(std::abs(d[iq])))
{
matrix.m_values[ip][iq] = 0;
}
else if (std::abs(matrix.m_values[ip][iq]) > tresh)
{
Scalar h = d[iq] - d[ip];
Scalar t = 0;
if (static_cast<float>(std::abs(h) + g) == static_cast<float>(std::abs(h)))
if (static_cast<float>(std::abs(h) + pq) == static_cast<float>(std::abs(h)))
{
t = matrix.m_values[ip][iq] / h;
}
Expand Down
12 changes: 8 additions & 4 deletions include/SimpleMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ namespace CCCoreLib
GenericTriangle* _getTriangle(unsigned triangleIndex) override; //temporary
VerticesIndexes* getNextTriangleVertIndexes() override;
VerticesIndexes* getTriangleVertIndexes(unsigned triangleIndex) override;
unsigned size() const override { return static_cast<unsigned>(m_triIndexes.size()); }
unsigned size() const override { return static_cast<unsigned>(triIndexes.size()); }
void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override;
void getTriangleVertices(unsigned triangleIndex, CCVector3& A, CCVector3& B, CCVector3& C) const override;

public: //specific methods

//! Returns the mesh capacity
inline unsigned capacity() const { return static_cast<unsigned>(m_triIndexes.capacity()); }
inline unsigned capacity() const { return static_cast<unsigned>(triIndexes.capacity()); }

//! Returns the vertices
inline const GenericIndexedCloud* vertices() const { return theVertices; }

//! Clears the mesh
inline void clear() { m_triIndexes.resize(0); }
inline void clear() { triIndexes.resize(0); }

//! Adds a triangle to the mesh
/** Vertex indexes are expresesed relatively to the vertex cloud.
Expand All @@ -77,12 +77,16 @@ namespace CCCoreLib
**/
virtual bool resize(unsigned n);

//inherited from GenericIndexedMesh
bool normalsAvailable() const override;
bool interpolateNormals(unsigned triIndex, const CCVector3& P, CCVector3& N) override;

protected:

//! A triangle vertices indexes container
using TriangleIndexesContainer = std::vector<VerticesIndexes>;
//! The triangles indexes
TriangleIndexesContainer m_triIndexes;
TriangleIndexesContainer triIndexes;

//! Iterator on the list of triangles
unsigned globalIterator;
Expand Down
8 changes: 3 additions & 5 deletions include/SquareMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,6 @@ namespace CCCoreLib
if (m_matrixSize < 0)
return false;

unsigned sqMatrixSize = m_matrixSize * m_matrixSize;

// S : copy of the current matrix
SquareMatrixTpl S_(*this);

Expand Down Expand Up @@ -1066,9 +1064,9 @@ namespace CCCoreLib
}
else
{
Scalar b = (C[0][0] - C[1][1]) / 2;
Scalar c = -C[0][1] * C[1][0];
if (b*b - c > 0)
b = (C[0][0] - C[1][1]) / 2;
c = -C[0][1] * C[1][0];
if (b * b - c > 0)
d = sqrt(b*b - c);
}

Expand Down
30 changes: 15 additions & 15 deletions src/AutoSegmentationTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,22 @@ bool AutoSegmentationTools::frontPropagationBasedSegmentation( GenericIndexedClo

//on va faire la propagation avec le FastMarching();
FastMarchingForPropagation* fm = new FastMarchingForPropagation();

fm->setJumpCoef(50.0);
fm->setDetectionThreshold(alpha);

int result = fm->init(theCloud, theOctree, octreeLevel);
int octreeLength = DgmOctree::OCTREE_LENGTH(octreeLevel) - 1;

if (result < 0)
{
if (!inputOctree)
fm->setJumpCoef(50.0);
fm->setDetectionThreshold(alpha);

int result = fm->init(theCloud, theOctree, octreeLevel);
if (result < 0)
{
delete theOctree;
if (!inputOctree)
{
delete theOctree;
}
delete fm;
return false;
}
delete fm;
return false;
}
int octreeLength = DgmOctree::OCTREE_LENGTH(octreeLevel) - 1;

if (progressCb)
{
Expand Down Expand Up @@ -243,7 +243,7 @@ bool AutoSegmentationTools::frontPropagationBasedSegmentation( GenericIndexedClo
}

//on finit la recherche du max
for (unsigned i = begin; i<numberOfPoints; ++i)
for (unsigned i = begin; i < numberOfPoints; ++i)
{
const CCVector3 *thePoint = theCloud->getPoint(i);
const ScalarType& theDistance = theDists->at(i);
Expand All @@ -268,10 +268,10 @@ bool AutoSegmentationTools::frontPropagationBasedSegmentation( GenericIndexedClo
++seedPoints;
}

int result = fm->propagate();
int resultFM = fm->propagate();

//if the propagation was successful
if (result >= 0)
if (resultFM >= 0)
{
//we extract the corresponding points
ReferenceCloud* newCloud = new ReferenceCloud(theCloud);
Expand Down
12 changes: 6 additions & 6 deletions src/DgmOctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,10 +2015,10 @@ unsigned char DgmOctree::findBestLevelForAGivenNeighbourhoodSizeExtraction(Point
static const PointCoordinateType c_neighbourhoodSizeExtractionFactor = static_cast<PointCoordinateType>(2.5);
PointCoordinateType aim = std::max<PointCoordinateType>(0, radius / c_neighbourhoodSizeExtractionFactor);

int level = 1;
unsigned char level = 1;
PointCoordinateType minValue = getCellSize(1) - aim;
minValue *= minValue;
for (int i = 2; i <= MAX_OCTREE_LEVEL; ++i)
for (unsigned char i = 2; i <= static_cast<unsigned char>(MAX_OCTREE_LEVEL); ++i)
{
//we need two points per cell ideally
if (m_averageCellPopulation[i] < 1.5)
Expand All @@ -2035,7 +2035,7 @@ unsigned char DgmOctree::findBestLevelForAGivenNeighbourhoodSizeExtraction(Point
}
}

return static_cast<unsigned char>(level);
return level;
}

unsigned char DgmOctree::findBestLevelForComparisonWithOctree(const DgmOctree* theOtherOctree) const
Expand All @@ -2045,15 +2045,15 @@ unsigned char DgmOctree::findBestLevelForComparisonWithOctree(const DgmOctree* t

unsigned char maxOctreeLevel = MAX_OCTREE_LEVEL;

if (std::min(ptsA,ptsB) < 16)
if (std::min(ptsA, ptsB) < 16)
maxOctreeLevel = std::min(maxOctreeLevel, static_cast<unsigned char>(5)); //very small clouds
else if (std::max(ptsA,ptsB) < 2000000)
else if (std::max(ptsA, ptsB) < 2000000)
maxOctreeLevel = std::min(maxOctreeLevel, static_cast<unsigned char>(10)); //average size clouds

double estimatedTime[MAX_OCTREE_LEVEL]{};
unsigned char bestLevel = 1;

for (int i=1; i<maxOctreeLevel; ++i) //warning: i >= 1
for (unsigned char i = 1; i < maxOctreeLevel; ++i) //warning: i >= 1
{
int diffA = 0;
int diffB = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/DistanceComputationTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,11 @@ int DistanceComputationTools::intersectMeshWithOctree( OctreeAndMeshIntersection
(currentCellPos.y >= intersection->minFillIndexes.y && currentCellPos.y <= intersection->maxFillIndexes.y) &&
(currentCellPos.z >= intersection->minFillIndexes.z && currentCellPos.z <= intersection->maxFillIndexes.z) )
{
Tuple3i cellPos = currentCellPos - intersection->minFillIndexes;
Tuple3i candidateCellPos = currentCellPos - intersection->minFillIndexes;

if (intersection->perCellTriangleList.isInitialized())
{
TriangleList*& triList = intersection->perCellTriangleList.getValue(cellPos);
TriangleList*& triList = intersection->perCellTriangleList.getValue(candidateCellPos);
if (!triList)
{
triList = new TriangleList();
Expand All @@ -904,7 +904,7 @@ int DistanceComputationTools::intersectMeshWithOctree( OctreeAndMeshIntersection

if (intersection->distanceTransform)
{
intersection->distanceTransform->setValue(cellPos, 1);
intersection->distanceTransform->setValue(candidateCellPos, 1);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/GeometricalAnalysisTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,11 @@ CCVector3 GeometricalAnalysisTools::ComputeGravityCenter(GenericCloud* cloud)
CCVector3d sum(0, 0, 0);

cloud->placeIteratorAtBeginning();
const CCVector3 *P = nullptr;
while ((P = cloud->getNextPoint()))
const CCVector3* P = cloud->getNextPoint();
while (P)
{
sum += *P;
P = cloud->getNextPoint();
}

sum /= static_cast<double>(count);
Expand Down
36 changes: 19 additions & 17 deletions src/PointProjectionTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,22 @@ PointCloud* PointProjectionTools::developCloudOnCylinder( GenericCloud* cloud,
progressCb->start();
}

const CCVector3* Q = nullptr;
cloud->placeIteratorAtBeginning();
while ((Q = cloud->getNextPoint()))
const CCVector3* Q = cloud->getNextPoint();
while (Q)
{
CCVector3 P = *Q-*center;
CCVector3 P = *Q - *center;
PointCoordinateType u = sqrt(P.u[dim1] * P.u[dim1] + P.u[dim2] * P.u[dim2]);
PointCoordinateType lon = atan2(P.u[dim1],P.u[dim2]);
PointCoordinateType lon = atan2(P.u[dim1], P.u[dim2]);

newCloud->addPoint(CCVector3(lon*radius,P.u[dim],u-radius));
newCloud->addPoint(CCVector3(lon*radius, P.u[dim], u - radius));

if (progressCb && !nprogress.oneStep())
{
break;
}


Q = cloud->getNextPoint();
}

if (progressCb)
Expand Down Expand Up @@ -191,9 +192,8 @@ PointCloud* PointProjectionTools::applyTransformation(GenericCloud* cloud, Trans
}

cloud->placeIteratorAtBeginning();
const CCVector3* P;

while ((P = cloud->getNextPoint()))
const CCVector3* P = cloud->getNextPoint();
while (P)
{
//P' = s*R.P+T
CCVector3 newP = trans.apply(*P);
Expand All @@ -204,6 +204,8 @@ PointCloud* PointProjectionTools::applyTransformation(GenericCloud* cloud, Trans
{
break;
}

P = cloud->getNextPoint();
}

if (progressCb)
Expand Down Expand Up @@ -820,7 +822,7 @@ bool PointProjectionTools::extractConcaveHull2D(std::vector<IndexedCCVector2>& p
}

//update the removed edges info and put them back in the main list
for (std::size_t i=0; i<removed.size(); ++i)
for (std::size_t i = 0; i < removed.size(); ++i)
{
VertexIterator itC = removed[i];
VertexIterator itD = itC; ++itD;
Expand All @@ -839,14 +841,14 @@ bool PointProjectionTools::extractConcaveHull2D(std::vector<IndexedCCVector2>& p

if (minSquareDist >= 0)
{
Edge e(itC,nearestPointIndex,minSquareDist);
edges.insert(e);
Edge newEdge(itC, nearestPointIndex, minSquareDist);
edges.insert(newEdge);
}
}
}

//we'll inspect the two new segments later (if necessary)
if ((P-**itA).norm2() > maxSquareEdgeLength)
if ((P - **itA).norm2() > maxSquareEdgeLength)
{
unsigned nearestPointIndex = 0;
PointCoordinateType minSquareDist = FindNearestCandidate(
Expand All @@ -860,8 +862,8 @@ bool PointProjectionTools::extractConcaveHull2D(std::vector<IndexedCCVector2>& p

if (minSquareDist >= 0)
{
Edge e(itA,nearestPointIndex,minSquareDist);
edges.insert(e);
Edge newEdge(itA, nearestPointIndex, minSquareDist);
edges.insert(newEdge);
}
}

Expand All @@ -879,8 +881,8 @@ bool PointProjectionTools::extractConcaveHull2D(std::vector<IndexedCCVector2>& p

if (minSquareDist >= 0)
{
Edge e(itP,nearestPointIndex,minSquareDist);
edges.insert(e);
Edge newEdge(itP, nearestPointIndex, minSquareDist);
edges.insert(newEdge);
}
}
}
Expand Down
Loading

0 comments on commit d6ef2b0

Please sign in to comment.