ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CorePoints.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "CorePoints.h"
9 
10 // qCC_db
11 #include <ecvPointCloud.h>
12 
13 // CCLib
14 #include <CloudSamplingTools.h>
15 
16 // system
17 #include <assert.h>
18 
19 using namespace masc;
20 
22  cloudViewer::GenericProgressCallback* progressCb /*=nullptr*/) {
23  if (!origin) {
24  assert(false);
25  return false;
26  }
27 
28  if (selection) {
29  // nothing to do
30  return true;
31  }
32 
33  // now we can compute the subsampled version
34  cloudViewer::ReferenceCloud* ref = nullptr;
35  switch (selectionMethod) {
36  case SPATIAL: {
37  // we'll need an octree
38  if (!origin->getOctree()) {
39  if (!origin->computeOctree(progressCb)) {
41  "[CorePoints::prepare] Failed to compute the "
42  "octree");
43  return false;
44  }
45  }
46 
48  modParams.enabled = false;
51  modParams, origin->getOctree().data(), progressCb);
52 
53  break;
54  }
55 
56  case RANDOM: {
57  if (selectionParam <= 0.0 || selectionParam >= 1.0) {
59  "[CorePoints::prepare] Random subsampling ration must "
60  "be between 0 and 1 (excluded)");
61  return false;
62  }
63  int targetCount = static_cast<int>(origin->size() * selectionParam);
65  origin, targetCount, progressCb);
66  break;
67  }
68 
69  case NONE:
70  // nothing to do
71  cloud = origin;
72  return true;
73 
74  default:
75  assert(false);
76  break;
77  }
78 
79  // store the references
80  if (!ref) {
82  "[CorePoints::prepare] Failed to subsampled the origin cloud");
83  return false;
84  }
85  selection.reset(ref);
86 
87  // and create the subsampled version of the cloud
88  cloud = origin->partialClone(ref);
89  if (!cloud) {
91  "[CorePoints::prepare] Failed to subsampled the origin cloud "
92  "(not enough memory)");
93  return false;
94  }
95 
96  return true;
97 }
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
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)
ccPointCloud * partialClone(const cloudViewer::ReferenceCloud *selection, int *warnings=nullptr, bool withChildEntities=true) const
Creates a new point cloud object from a ReferenceCloud (selection)
static ReferenceCloud * subsampleCloudRandomly(GenericIndexedCloudPersist *cloud, unsigned newNumberOfPoints, GenericProgressCallback *progressCb=nullptr)
Subsamples a point cloud (process based on random selections)
static ReferenceCloud * resampleCloudSpatially(GenericIndexedCloudPersist *cloud, PointCoordinateType minDistance, const SFModulationParams &modParams, DgmOctree *octree=nullptr, GenericProgressCallback *progressCb=nullptr)
Resamples a point cloud (process based on inter point distance)
unsigned size() const override
Definition: PointCloudTpl.h:38
A very simple point cloud (no point duplication)
3DMASC classifier
Parameters for the scalar-field based modulation of a parameter.
bool enabled
Whether the modulation is enabled or not.
bool prepare(cloudViewer::GenericProgressCallback *progressCb=nullptr)
Prepares the selection (must be called once)
Definition: CorePoints.cpp:21
double selectionParam
Definition: CorePoints.h:60
SubSamplingMethod selectionMethod
Definition: CorePoints.h:59
ccPointCloud * cloud
Core points cloud.
Definition: CorePoints.h:44
ccPointCloud * origin
Origin cloud.
Definition: CorePoints.h:41
QSharedPointer< cloudViewer::ReferenceCloud > selection
Definition: CorePoints.h:57