22 :
in(sfIn),
out(sfOut) {}
28 void** additionalParameters,
35 std::vector<SFPair>* scalarFields =
36 reinterpret_cast<std::vector<SFPair>*
>(additionalParameters[2]);
39 additionalParameters[3]);
41 bool normalDistWeighting =
false;
42 double interpSigma2x2 = 0;
44 interpSigma2x2 = 2 * params->
sigma * params->sigma;
45 normalDistWeighting = (interpSigma2x2 > 0);
49 bool useKNN = (params->method ==
63 std::vector<double> sumValues;
64 size_t sfCount = scalarFields->size();
66 sumValues.resize(sfCount);
71 for (
unsigned i = 0; i < pointCount; i++) {
79 unsigned neighborCount = 0;
84 neighborCount = std::min(neighborCount, params->knn);
87 nNSS, params->radius,
false);
93 std::vector<ScalarType> values;
94 values.resize(neighborCount);
95 unsigned medianIndex = std::max(neighborCount / 2, 1u) - 1;
97 for (
unsigned j = 0; j < sfCount; ++j) {
99 for (
unsigned k = 0; k < neighborCount; ++k) {
104 std::sort(values.begin(), values.end());
106 ScalarType median = values[medianIndex];
107 scalarFields->at(j).out->setValue(outPointIndex, median);
112 std::fill(sumValues.begin(), sumValues.end(), 0);
113 for (
unsigned k = 0; k < neighborCount; ++k) {
117 if (normalDistWeighting) {
121 for (
unsigned j = 0; j < sfCount; ++j) {
122 sumValues[j] += w * scalarFields->at(j).in->getValue(
128 for (
unsigned j = 0; j < sfCount; ++j) {
130 static_cast<ScalarType
>(sumValues[j] / sumW);
131 scalarFields->at(j).out->setValue(outPointIndex, s);
154 const std::vector<int>& inSFIndexes,
158 if (!destCloud || !srcCloud || srcCloud->
size() == 0 ||
161 "[InterpolateScalarFieldsFrom] Invalid/empty input cloud(s)!");
171 if (fabs(dist.
x) > dimSum.
x / 2 || fabs(dist.
y) > dimSum.
y / 2 ||
172 fabs(dist.
z) > dimSum.
z / 2) {
174 "[InterpolateScalarFieldsFrom] Clouds are too far from each "
175 "other! Can't proceed.");
180 bool overwrite =
false;
181 std::vector<SFPair> scalarFields;
183 scalarFields.reserve(inSFIndexes.size());
184 }
catch (
const std::bad_alloc&) {
188 for (
size_t i = 0; i < inSFIndexes.size(); ++i) {
189 int inSFIndex = inSFIndexes[i];
194 CVLog::Warning(QString(
"[InterpolateScalarFieldsFrom] Source cloud "
195 "has no scalar field with index #%1")
203 if (outSFIndex < 0) {
205 if (outSFIndex < 0) {
215 scalarFields.push_back(
SFPair(inSF, outSF));
224 QSharedPointer<cloudViewer::ReferenceCloud> CPSet =
230 unsigned CPSetSize = CPSet->size();
231 assert(CPSetSize == destCloud->
size());
234 for (
SFPair& sfPair : scalarFields) {
235 for (
unsigned i = 0; i < CPSetSize; ++i) {
236 unsigned pointIndex = CPSet->getPointGlobalIndex(i);
237 sfPair.out->setValue(i, sfPair.in->getValue(pointIndex));
250 assert(srcCloud && destCloud);
256 srcCloud, destCloud, _srcOctree, _destOctree,
259 QScopedPointer<cloudViewer::DgmOctree> srcOctree(_srcOctree),
260 destOctree(_destOctree);
265 "[InterpolateScalarFieldsFrom] Failed to build the "
274 srcOctree->findBestLevelForAGivenPopulationPerCell(
279 ->findBestLevelForAGivenNeighbourhoodSizeExtraction(
286 void* additionalParameters[] = {
287 reinterpret_cast<void*
>(srcCloud),
288 reinterpret_cast<void*
>(srcOctree.data()),
289 reinterpret_cast<void*
>(&scalarFields), (
void*)(¶ms)};
291 if (destOctree->executeFunctionForAllCellsAtLevel(
293 true, progressCb,
"Scalar field interpolation",
297 "[InterpolateScalarFieldsFrom] Failed to perform the "
301 }
catch (
const std::bad_alloc&) {
303 CVLog::Warning(
"[InterpolateScalarFieldsFrom] Not enough memory");
309 for (
SFPair& sfPair : scalarFields) {
310 sfPair.out->computeMinAndMax();
315 "[InterpolateScalarFieldsFrom] Some scalar fields with the "
316 "same names have been overwritten");
constexpr ScalarType NAN_VALUE
NaN as a ScalarType value.
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.
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
static bool InterpolateScalarFieldsFrom(ccPointCloud *destCloud, ccPointCloud *srccloud, const std::vector< int > &sfIndexes, const Parameters ¶ms, cloudViewer::GenericProgressCallback *progressCb=0, unsigned char octreeLevel=0)
Interpolate scalar fields from another cloud.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
int addScalarField(const char *uniqueName) override
Creates a new scalar field and registers it.
QSharedPointer< cloudViewer::ReferenceCloud > computeCPSet(ccGenericPointCloud &otherCloud, cloudViewer::GenericProgressCallback *progressCb=nullptr, unsigned char octreeLevel=0)
Computes the closest point of this cloud relatively to another cloud.
Vector3Tpl< T > getDiagVec() const
Returns diagonal vector.
Vector3Tpl< T > getCenter() const
Returns center.
The octree structure used throughout the library.
void getCellPos(CellCode code, unsigned char level, Tuple3i &cellPos, bool isCodeTruncated) const
unsigned findNearestNeighborsStartingFromCell(NearestNeighboursSearchStruct &nNSS, bool getOnlyPointsWithValidScalar=false) const
int findNeighborsInASphereStartingFromCell(NearestNeighboursSearchStruct &nNSS, double radius, bool sortValues=true) const
Advanced form of the nearest neighbours search algorithm (in a sphere)
void computeCellCenter(CellCode code, unsigned char level, CCVector3 ¢er, bool isCodeTruncated=false) const
bool oneStep()
Increments total progress value of a single unit.
int getScalarFieldIndexByName(const char *name) const
Returns the index of a scalar field represented by its name.
ScalarField * getScalarField(int index) const
Returns a pointer to a specific scalar field.
unsigned getNumberOfScalarFields() const
Returns the number of associated (and active) scalar fields.
unsigned size() const override
const char * getScalarFieldName(int index) const
Returns the name of a specific scalar field.
unsigned size() const override
Returns the number of points.
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
A simple scalar field (to be associated to a point cloud)
void fill(ScalarType fillValue=0)
Fills the array with a particular value.
ScalarType & getValue(std::size_t index)
bool cellSFInterpolator(const cloudViewer::DgmOctree::octreeCell &cell, void **additionalParameters, cloudViewer::NormalizedProgress *nProgress)
const cloudViewer::ScalarField * in
SFPair(const cloudViewer::ScalarField *sfIn=0, cloudViewer::ScalarField *sfOut=0)
cloudViewer::ScalarField * out
Generic interpolation parameters.
Structure used during nearest neighbour search.
double squareDistd
Point associated distance value.
unsigned pointIndex
Point index.
ReferenceCloud * points
Set of points lying inside this cell.
const DgmOctree * parentOctree
Octree to which the cell belongs.
unsigned char level
Cell level of subdivision.
CellCode truncatedCode
Truncated cell code.