Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/Delaunay2dMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ namespace CCCoreLib

//inherited methods (see GenericMesh)
unsigned size() const override { return m_numberOfTriangles; }
void forEach(genericTriangleAction action) override;
void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override;
void placeIteratorAtBeginning() override;
GenericTriangle* _getNextTriangle() override;
Expand Down
2 changes: 1 addition & 1 deletion include/DgmOctreeReferenceCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace CCCoreLib

//**** inherited form GenericCloud ****//
inline unsigned size() const override { return m_size; }
void forEach(genericPointAction action) override;
void setPointScalarValues(ScalarType value) override;
void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override;
//virtual unsigned char testVisibility(const CCVector3& P) const; //not supported
inline void placeIteratorAtBeginning() override { m_globalIterator = 0; }
Expand Down
19 changes: 10 additions & 9 deletions include/GenericCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,12 @@ namespace CCCoreLib
//! Default destructor
virtual ~GenericCloud() = default;

//! Generic function applied to a point (used by foreach)
using genericPointAction = std::function<void (const CCVector3 &, ScalarType &)>;

//! Returns the number of points
/** Virtual method to request the cloud size
\return the cloud size
**/
virtual unsigned size() const = 0;

//! Fast iteration mechanism
/** Virtual method to apply a function to the whole cloud
\param action the function to apply (see GenericCloud::genericPointAction)
**/
virtual void forEach(genericPointAction action) = 0;

//! Returns the cloud bounding box
/** Virtual method to request the cloud bounding box limits
\param bbMin lower bounding-box limits (Xmin,Ymin,Zmin)
Expand Down Expand Up @@ -88,10 +79,20 @@ namespace CCCoreLib
//! Returns true if the scalar field is enabled, false otherwise
virtual bool isScalarFieldEnabled() const = 0;

//! Resets all value of the currently enabled scalar field to the same value
/** \param value the value to for to all points
**/
virtual void setPointScalarValues(ScalarType value) = 0;

//! Sets the ith point associated scalar value
/** \param pointIndex the point index
\param value the value to set
**/
virtual void setPointScalarValue(unsigned pointIndex, ScalarType value) = 0;

//! Returns the ith point associated scalar value
/** \param pointIndex the point index
**/
virtual ScalarType getPointScalarValue(unsigned pointIndex) const = 0;
};

Expand Down
9 changes: 0 additions & 9 deletions include/GenericMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,12 @@ namespace CCCoreLib
//! Default destructor
virtual ~GenericMesh() = default;

//! Generic function to apply to a triangle (used by foreach)
using genericTriangleAction = std::function<void (GenericTriangle &)>;

//! Returns the number of triangles
/** Virtual method to request the mesh size
\return the mesh size
**/
virtual unsigned size() const = 0;

//! Fast iteration mechanism
/** Virtual method to apply a function to the whole mesh
\param action function to apply (see GenericMesh::genericTriangleAction)
**/
virtual void forEach(genericTriangleAction action) = 0;

//! Returns the mesh bounding-box
/** Virtual method to request the mesh bounding-box limits. It is equivalent to
the bounding-box of the cloud composed of the mesh vertexes.
Expand Down
29 changes: 4 additions & 25 deletions include/PointCloudTpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,39 +81,18 @@ namespace CCCoreLib

inline unsigned size() const override { return static_cast<unsigned>(m_points.size()); }

void forEach(GenericCloud::genericPointAction action) override
void setPointScalarValues(ScalarType value) override
{
//there's no point of calling forEach if there's no activated scalar field!
ScalarField* currentOutScalarFieldArray = getCurrentOutScalarField();
if (!currentOutScalarFieldArray)
{
//no activated scalar field!
assert(false);
return;
}

unsigned n = size();

if (0 != n)
{
double previousOffset = currentOutScalarFieldArray->getOffset();
if (n == currentOutScalarFieldArray->size())
{
// if we are going to change ALL the values, we can also apply the functor on the offset
double firstValue = currentOutScalarFieldArray->getValue(0);
action(m_points.front(), firstValue);
if (ScalarField::ValidValue(firstValue))
{
currentOutScalarFieldArray->setOffset(firstValue);
}
}

for (unsigned i = 0; i < n; ++i)
{
ScalarType value = previousOffset + currentOutScalarFieldArray->getLocalValue(i); // warning, the offset has been changed, we can't use getValue anymore
action(m_points[i], value);
currentOutScalarFieldArray->setValue(i, value);
}
}
currentOutScalarFieldArray->resetOffset();
currentOutScalarFieldArray->fill(value);
}

void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override
Expand Down
2 changes: 1 addition & 1 deletion include/ReferenceCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace CCCoreLib

//**** inherited form GenericCloud ****//
inline unsigned size() const override { return static_cast<unsigned>(m_theIndexes.size()); }
void forEach(genericPointAction action) override;
void setPointScalarValues(ScalarType value) override;
void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override;
inline unsigned char testVisibility(const CCVector3& P) const override { assert(m_theAssociatedCloud); return m_theAssociatedCloud->testVisibility(P); }
inline void placeIteratorAtBeginning() override { m_globalIterator = 0; }
Expand Down
34 changes: 23 additions & 11 deletions include/ScalarField.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace CCCoreLib
assert(std::isfinite(offset));

m_offsetHasBeenSet = true;
m_offset = offset;
m_offset = (std::abs(offset) < 100.0 ? 0.0 : offset); // don't use a too small offset, as it can cause numerical accuracy issues
}

//! Resets the offset
Expand Down Expand Up @@ -111,22 +111,18 @@ namespace CCCoreLib
inline ScalarType getMax() const { return m_offset + m_localMaxVal; }

//! Fills the array with a particular value
inline void fill(ScalarType fillValue = 0)
inline void fill(ScalarType fillValue = 0, bool autoResetOffset = true)
{
float fillValueF = 0.0f;
if (std::isfinite(fillValue))
{
if (m_offsetHasBeenSet)
{
fillValueF = static_cast<float>(fillValue - m_offset);
}
else
if (!m_offsetHasBeenSet || autoResetOffset)
{
// if the offset has not been set yet, we use the first finite value by default
setOffset(fillValue);

//fillValueF = 0.0f; // already set
}

fillValueF = static_cast<float>(fillValue - m_offset);
}
else
{
Expand All @@ -147,6 +143,22 @@ namespace CCCoreLib
}
}

//! Inverts all values
/** \warning The internal offset will be inverted as well
**/
inline void invert()
{
if (m_offsetHasBeenSet && std::isfinite(m_offset))
{
m_offset = -m_offset;
}

for (float& fValue : *this)
{
fValue = -fValue;
}
}

//! Reserves memory (no exception thrown)
CC_CORE_LIB_API bool reserveSafe(std::size_t count);
//! Resizes memory (no exception thrown)
Expand All @@ -171,7 +183,7 @@ namespace CCCoreLib
// if the offset has not been set yet, we use the
// first finite value as offset by default
setOffset(value);
(*this)[index] = 0.0f;
(*this)[index] = static_cast<float>(value - m_offset);
}
else
{
Expand All @@ -192,7 +204,7 @@ namespace CCCoreLib
// if the offset has not been set yet, we use the
// first finite value as offset by default
setOffset(value);
push_back(0.0f);
push_back(static_cast<float>(value - m_offset));
}
else
{
Expand Down
15 changes: 0 additions & 15 deletions include/ScalarFieldTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,6 @@ namespace CCCoreLib
KMeanClass kmcc[],
GenericProgressCallback* progressCb = nullptr);

//! Sets the distance value associated to a point
/** Generic function that can be used with the GenericCloud::foreach() method.
\param P a 3D point
\param scalarValue its associated scalar value
**/
static void SetScalarValueToNaN(const CCVector3& P, ScalarType& scalarValue);

//! Sets the distance value associated to a point to zero
/** Generic function that can be used with the GenericCloud::foreach() method.
\param P a 3D point
\param scalarValue its associated scalar value
**/
static void SetScalarValueToZero(const CCVector3 &P, ScalarType& scalarValue);

static void SetScalarValueInverted(const CCVector3 &P, ScalarType& scalarValue);
protected:

//! "Cellular" function to compute the gradient norms of points inside an octree cell
Expand Down
1 change: 0 additions & 1 deletion include/SimpleMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace CCCoreLib

public: //inherited methods

void forEach(genericTriangleAction action) override;
void placeIteratorAtBeginning() override;
GenericTriangle* _getNextTriangle() override; //temporary
GenericTriangle* _getTriangle(unsigned triangleIndex) override; //temporary
Expand Down
17 changes: 0 additions & 17 deletions src/Delaunay2dMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,23 +318,6 @@ bool Delaunay2dMesh::removeTrianglesWithEdgesLongerThan(PointCoordinateType maxE
return true;
}

void Delaunay2dMesh::forEach(genericTriangleAction action)
{
if (!m_associatedCloud)
return;

SimpleTriangle tri;

const int* _triIndexes = m_triIndexes.data();
for (unsigned i = 0; i < m_numberOfTriangles; ++i, _triIndexes += 3)
{
tri.A = *m_associatedCloud->getPoint(_triIndexes[0]);
tri.B = *m_associatedCloud->getPoint(_triIndexes[1]);
tri.C = *m_associatedCloud->getPoint(_triIndexes[2]);
action(tri);
}
}

void Delaunay2dMesh::placeIteratorAtBeginning()
{
m_globalIterator = m_triIndexes.data();
Expand Down
7 changes: 2 additions & 5 deletions src/DgmOctreeReferenceCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ void DgmOctreeReferenceCloud::getBoundingBox(CCVector3& bbMin, CCVector3& bbMax)
bbMax = m_bbMax;
}

void DgmOctreeReferenceCloud::forEach(genericPointAction action)
void DgmOctreeReferenceCloud::setPointScalarValues(ScalarType value)
{
unsigned count = size();
for (unsigned i = 0; i < count; ++i)
{
//we must change from double container to 'ScalarType' one!
ScalarType sqDist = static_cast<ScalarType>(m_set->at(i).squareDistd);
action(*m_set->at(i).point, sqDist);
m_set->at(i).squareDistd = static_cast<double>(sqDist);
m_set->at(i).squareDistd = value;
}
}
Loading
Loading