9 #include <tbb/parallel_for.h>
36 m_pointsVisibility(cloud.m_pointsVisibility),
37 m_pointSize(cloud.m_pointSize) {}
50 }
catch (
const std::bad_alloc&) {
99 if (proxy !=
nullptr) {
107 bool autoAddChild ) {
126 bool autoAddChild ) {
151 assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
152 if (dataVersion < 33) {
164 if (out.write((
const char*)&hasVisibilityArray,
sizeof(
bool)) < 0)
166 if (hasVisibilityArray) {
180 return std::max(
static_cast<short>(33),
193 if (dataVersion < 33) {
205 bool hasVisibilityArray =
false;
206 if (in.read((
char*)&hasVisibilityArray,
sizeof(
bool)) < 0)
208 if (hasVisibilityArray) {
219 if (dataVersion >= 24) {
255 int& nearestPointIndex,
256 double& nearestSquareDist,
259 bool autoComputeOctree ) {
261 if (pickWidth == pickHeight) {
263 if (!
octree && autoComputeOctree) {
290 if (
octree->pointPicking(clickPos, camera, point, pickWidth)) {
308 "[Point picking] Failed to use the octree. We'll fall "
309 "back to the slow process...");
315 nearestPointIndex = -1;
316 nearestSquareDist = -1.0;
351 0,
static_cast<int>(
size()),
355 #pragma omp parallel
for
357 for (
int i = 0; i < static_cast<int>(
size()); ++i)
375 if (fabs(Q2D.
x - clickPos.
x) <= pickWidth &&
376 fabs(Q2D.
y - clickPos.
y) <= pickHeight) {
377 const double squareDist =
381 if (nearestPointIndex < 0 ||
382 squareDist < nearestSquareDist) {
383 nearestSquareDist = squareDist;
384 nearestPointIndex = i;
394 return (nearestPointIndex >= 0);
397 std::tuple<Eigen::Vector3d, Eigen::Matrix3d>
405 covaMatrix.
toArray(cov.data());
425 if (!visTable || visTable->size() !=
count) {
428 "[ccGenericPointCloud::getTheVisiblePoints] Invalid visibility "
434 unsigned pointCount = 0;
436 for (
unsigned i = 0; i <
count; ++i) {
447 selection->
size() == 0);
457 for (
unsigned i = 0; i <
count; ++i) {
464 "[ccGenericPointCloud::getTheVisiblePoints] Not enough "
469 }
else if (!silent) {
471 "[ccGenericPointCloud::getTheVisiblePoints] No point in "
constexpr unsigned char POINT_VISIBLE
constexpr unsigned char POINT_HIDDEN
Vector3Tpl< double > CCVector3d
Double 3D Vector.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
double norm2d() const
Returns vector square norm (forces double precision output)
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
virtual void lockVisibility(bool state)
Locks/unlocks visibility.
virtual void setVisible(bool state)
Sets entity visibility.
virtual bool sfShown() const
Returns whether active scalar field is visible.
virtual void enableTempColor(bool state)
Set temporary color activation state.
virtual void showSF(bool state)
Sets active scalarfield visibility.
void apply(float vec[3]) const
Applies transformation to a 3D vector (in place) - float version.
Float version of ccGLMatrixTpl.
A 3D cloud interface with associated features (color, normals, octree, etc.)
virtual void invertVisibilityArray()
Inverts the visibility array.
ccGenericPointCloud(QString name=QString())
Default constructor.
virtual void deleteOctree()
Erases the octree.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
VisibilityTableType m_pointsVisibility
Per-point visibility table.
unsigned char getPointSize() const
Returns current point size.
virtual ccOctree::Shared computeOctree(cloudViewer::GenericProgressCallback *progressCb=nullptr, bool autoAddChild=true)
Computes the cloud octree.
virtual cloudViewer::ReferenceCloud * getTheVisiblePoints(const VisibilityTableType *visTable=nullptr, bool silent=false, cloudViewer::ReferenceCloud *selection=nullptr) const
Returns a ReferenceCloud equivalent to the visibility array.
unsigned char m_pointSize
Point size (won't be applied if 0)
virtual ccOctreeProxy * getOctreeProxy() const
Returns the associated octree proxy (if any)
virtual bool isVisibilityTableInstantiated() const
Returns whether the visibility array is allocated or not.
short minimumFileVersion_MeOnly() const override
void setPointSize(unsigned size=0)
Sets point size.
virtual void clear()
Clears the entity from all its points and features.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
~ccGenericPointCloud() override
Default destructor.
virtual void setOctree(ccOctree::Shared octree, bool autoAddChild=true)
Sets the associated octree.
virtual ccOctree::Shared getOctree() const
Returns the associated octree (if any)
virtual VisibilityTableType & getTheVisibilityArray()
Returns associated visibility array.
bool pointPicking(const CCVector2d &clickPos, const ccGLCameraParameters &camera, int &nearestPointIndex, double &nearestSquareDist, double pickWidth=2.0, double pickHeight=2.0, bool autoComputeOctree=false)
Point picking (brute force or octree-driven)
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
virtual bool resetVisibilityArray()
Resets the associated visibility array.
std::tuple< Eigen::Vector3d, Eigen::Matrix3d > computeMeanAndCovariance() const
std::vector< unsigned char > VisibilityTableType
Array of "visibility" information for each point.
void importParametersFrom(const ccGenericPointCloud *cloud)
Imports the parameters from another cloud.
cloudViewer::SquareMatrixd computeCovariance() const
virtual void unallocateVisibilityArray()
Erases the points visibility information.
virtual const ccGLMatrix & getGLTransformationHistory() const
Returns the transformation 'history' matrix.
bool getAbsoluteGLTransformation(ccGLMatrix &trans) const
virtual short minimumFileVersion_MeOnly() const
virtual bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap)
Loads own object data.
virtual bool toFile_MeOnly(QFile &out, short dataVersion) const
Save own object data.
virtual void setGLTransformationHistory(const ccGLMatrix &mat)
Sets the transformation 'history' matrix (handle with care!)
void removeChild(ccHObject *child)
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
Container m_children
Children.
CV_CLASS_ENUM getClassID() const override
Returns class ID.
const QVariantMap & metaData() const
Returns meta-data map (const only)
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
bool isA(CV_CLASS_ENUM type) const
virtual void setEnabled(bool state)
Sets the "enabled" property.
ccOctree::Shared getOctree() const
Returns the associated octree.
QSharedPointer< ccOctree > Shared
Shared pointer.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void setCurrentDisplayedScalarField(int index)
Sets the currently displayed scalar field.
ccScalarField * getCurrentDisplayedScalarField() const
Returns the currently displayed scalar (or 0 if none)
int addScalarField(const char *uniqueName) override
Creates a new scalar field and registers it.
A scalar field associated to display-related parameters.
const ccColorScale::Shared & getColorScale() const
Returns associated color scale.
const ecvColor::Rgb * getColor(ScalarType value) const
bool mayHaveHiddenValues() const
static bool CorruptError()
Sends a custom error message (corrupted file) and returns 'false'.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
static bool ReadError()
Sends a custom error message (read error) and returns 'false'.
static bool WriteError()
Sends a custom error message (write error) and returns 'false'.
static bool GenericArrayFromFile(std::vector< Type > &data, QFile &in, short dataVersion, const QString &verboseDescription)
Helper: loads a vector structure from file.
static bool GenericArrayToFile(const std::vector< Type > &data, QFile &out)
Helper: saves a vector to file.
Shifted entity interface.
double m_globalScale
Global scale (typically applied at loading time)
CCVector3d m_globalShift
Global shift (typically applied at loading time)
bool loadShiftInfoFromFile(QFile &in)
Serialization helper (input)
virtual void setGlobalShift(double x, double y, double z)
Sets shift applied to original coordinates (information storage only)
virtual const CCVector3d & getGlobalShift() const
Returns the shift applied to original coordinates.
virtual void setGlobalScale(double scale)
virtual double getGlobalScale() const
Returns the scale applied to original coordinates.
bool saveShiftInfoToFile(QFile &out) const
Serialization helper (output)
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
void setValidity(bool state)
Sets bonding box validity.
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
virtual void clear()
Clears the octree.
unsigned getNumberOfProjectedPoints() const
Returns the number of points projected into the octree.
int build(GenericProgressCallback *progressCb=nullptr)
Builds the structure.
virtual void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax)=0
Returns the cloud bounding box.
virtual unsigned size() const =0
Returns the number of points.
virtual const CCVector3 * getPoint(unsigned index) const =0
Returns the ith point.
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.
void setCurrentScalarField(int index)
Sets both the INPUT & OUTPUT scalar field.
A very simple point cloud (no point duplication)
virtual bool addPointIndex(unsigned globalIndex)
Point global index insertion mechanism.
virtual GenericIndexedCloudPersist * getAssociatedCloud()
Returns the associated (source) cloud.
unsigned size() const override
Returns the number of points.
virtual void clear(bool releaseMemory=false)
Clears the cloud.
virtual bool reserve(unsigned n)
Reserves some memory for hosting the point references.
A simple scalar field (to be associated to a point cloud)
virtual void computeMinAndMax()
Determines the min and max values.
ScalarType & getValue(std::size_t index)
void toArray(Scalar data[])
Graphical progress indicator (thread-safe)
OpenGL camera parameters.
bool unproject(const CCVector3d &input2D, CCVector3d &output3D) const
Unprojects a 2D point (+ normalized 'z' coordinate) in 3D.
bool project(const CCVector3d &input3D, CCVector3d &output2D, bool *inFrustum=nullptr) const
Projects a 3D point in 2D (+ normalized 'z' coordinate)
Structure used during nearest neighbour search.
const CCVector3 * point
Point.
double squareDistd
Point associated distance value.
unsigned pointIndex
Point index.