Skip to content

Commit

Permalink
Update DgmOctree syntax (#100)
Browse files Browse the repository at this point in the history
* Improve the syntax of ScalarFieldTools::computeCellGaussianFilter

* Syntax fix

* Restore the definition of DgmOctree::MultiThreadingWrapper in the header to avoid issues when linking CCCoreLib statically on Windows
  • Loading branch information
dgirardeau authored Apr 10, 2024
1 parent a8ce427 commit cac3533
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 301 deletions.
54 changes: 42 additions & 12 deletions include/DgmOctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace CCCoreLib
class GenericIndexedCloudPersist;
class GenericProgressCallback;
class NormalizedProgress;
struct MultiThreadingWrapper;

//! The octree structure used throughout the library
/** Implements the GenericOctree interface.
Expand Down Expand Up @@ -349,7 +348,7 @@ namespace CCCoreLib
- (NormalizedProgress*) optional (normalized) progress callback
- return success
**/
using octreeCellFunc = bool (*)(const octreeCell &, void **, NormalizedProgress *);
using octreeCellFunc = bool (*)(const octreeCell&, void**, NormalizedProgress*);

/******************************/
/** METHODS **/
Expand All @@ -361,7 +360,7 @@ namespace CCCoreLib
explicit DgmOctree(GenericIndexedCloudPersist* cloud);

//! DgmOctree destructor
~DgmOctree() override;
~DgmOctree() override = default;

//! Clears the octree
virtual void clear();
Expand Down Expand Up @@ -1114,7 +1113,7 @@ namespace CCCoreLib

//! Computes statistics about cells for a given level of subdivision
/** This method requires some computation, therefore it shouldn't be
called too often.
called too often.
\param level the level of subdivision
**/
void computeCellsStatistics(unsigned char level);
Expand All @@ -1128,19 +1127,19 @@ namespace CCCoreLib
\param level the level of subdivision
**/
void getNeighborCellsAround(const Tuple3i& cellPos,
cellIndexesContainer &neighborCellsIndexes,
int neighbourhoodLength,
unsigned char level) const;
cellIndexesContainer &neighborCellsIndexes,
int neighbourhoodLength,
unsigned char level) const;

//! Gets point in the neighbourhing cells of a specific cell
/** \warning May throw a std::bad_alloc exception if memory is insufficient.
\param nNSS NN search parameters (from which are used: cellPos, pointsInNeighbourCells and level)
\param neighbourhoodLength the new distance (in terms of cells) at which to look for neighbour cells
\param getOnlyPointsWithValidScalar whether to ignore points having an invalid associated scalar value
**/
void getPointsInNeighbourCellsAround(NearestNeighboursSearchStruct &nNSS,
int neighbourhoodLength,
bool getOnlyPointsWithValidScalar = false) const;
void getPointsInNeighbourCellsAround( NearestNeighboursSearchStruct &nNSS,
int neighbourhoodLength,
bool getOnlyPointsWithValidScalar = false) const;

//! Returns the index of a given cell represented by its code
/** Same algorithm as the other "getCellIndex" method, but in an optimized form.
Expand Down Expand Up @@ -1215,8 +1214,39 @@ namespace CCCoreLib
//! Std. dev. of cell population per level of subdivision
double m_stdDevCellPopulation[MAX_OCTREE_LEVEL + 1];

//! Multithreading wrapper
MultiThreadingWrapper* m_MT_wrapper;
//! Octree cell description helper struct
struct octreeCellDesc
{
DgmOctree::CellCode truncatedCode;
unsigned i1, i2;
unsigned char level;
};

//! Structure containing objects needed to run octree operations in parallel
struct MultiThreadingWrapper
{
octreeCellFunc cellFunc = nullptr;
bool cellFuncSuccess = true;
DgmOctree* octree = nullptr;
GenericProgressCallback* progressCb = nullptr;
NormalizedProgress* normProgressCb = nullptr;
void** userParams = nullptr;

void reset()
{
cellFunc = nullptr;
cellFuncSuccess = true;
octree = nullptr;
normProgressCb = nullptr;
progressCb = nullptr;
userParams = nullptr;
}

void launchOctreeCellFunc(const octreeCellDesc& desc);
};

//! Multi-threading wrapper structure
MultiThreadingWrapper m_MT_wrapper;

//! Whether the octree build is in progress
std::atomic<bool> m_buildInProgress;
Expand Down
15 changes: 7 additions & 8 deletions include/ScalarFieldTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ namespace CCCoreLib
DgmOctree* theOctree = nullptr);

//! Computes a spatial gaussian filter on a scalar field associated to a point cloud
/** The "amplitutde" of the gaussian filter must be precised (sigma).
As 99% of the gaussian distribution is between -3*sigma and +3*sigma
around the mean value, this filter will only look for neighbouring
points (around each point) in a sphere of radius 3*sigma.
It also permits to use the filter as a bilateral filter. Where the wights are computed also considering the
distance of the neighbor's scalar value from the current point scalar value. (weighted with gaussian as distances are)
Warning: this method assumes the input scalar field is different from output.
/** The "amplitutde" of the Gaussian filter must be specified (sigma).
As 99% of the Gaussian distribution is between -3*sigma and +3*sigma around the mean value,
this filter will only look for neighbors within a sphere of radius 3*sigma.
One can also use the filter as a Bilateral filter. In this case the weights are computed considering the
difference of the neighbors SF values with the current point SF value (also following a Gaussian distribution).
Warning: this method assumes the input scalar field is different from the output one.
\param sigma filter variance
\param theCloud a point cloud (associated to scalar values)
\param sigmaSF the sigma for the bilateral filter. when different than -1 turns the gaussian filter into a bilateral filter
\param sigmaSF if strictly positive, the variance for the Bilateral filter
\param progressCb the client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback)
\param theOctree the octree, if it has already been computed
\return success
Expand Down
Loading

0 comments on commit cac3533

Please sign in to comment.