| 1 |
//########################################################################## |
| 2 |
//# # |
| 3 |
//# CLOUDCOMPARE PLUGIN: qCANUPO # |
| 4 |
//# # |
| 5 |
//# This program is free software; you can redistribute it and/or modify # |
| 6 |
//# it under the terms of the GNU General Public License as published by # |
| 7 |
//# the Free Software Foundation; version 2 or later of the License. # |
| 8 |
//# # |
| 9 |
//# This program is distributed in the hope that it will be useful, # |
| 10 |
//# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 11 |
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 12 |
//# GNU General Public License for more details. # |
| 13 |
//# # |
| 14 |
//# COPYRIGHT: UEB (UNIVERSITE EUROPEENNE DE BRETAGNE) / CNRS # |
| 15 |
//# # |
| 16 |
//########################################################################## |
| 17 |
|
| 18 |
#ifndef CC_POINT_DESCRIPTOR_HEADER |
| 19 |
#define CC_POINT_DESCRIPTOR_HEADER |
| 20 |
|
| 21 |
//Qt |
| 22 |
#include <QByteArray> |
| 23 |
#include <QString> |
| 24 |
|
| 25 |
//CCCoreLib |
| 26 |
#include <ReferenceCloud.h> |
| 27 |
|
| 28 |
//system |
| 29 |
#include <vector> |
| 30 |
#include <math.h> |
| 31 |
|
| 32 |
// Descriptors' ID must be declared here and then implemented in 'ccPointDescriptor.cpp'. |
| 33 |
// |
| 34 |
// WARNING: the ID must be unique and must not be changed once set! |
| 35 |
// |
| 36 |
// Once declared (and implemented) in ccPointDescriptor.cpp, the descriptor must be added |
| 37 |
// to the static 'vault' (see ScaleParamsComputerVault's constructor). |
| 38 |
|
| 39 |
static const unsigned DESC_INVALID = 0; // Unknown descritpr |
| 40 |
static const unsigned DESC_DIMENSIONALITY = 1; // Original CANUPO's "Dimensionality" descriptor |
| 41 |
static const unsigned DESC_DIMENSIONALITY_SF = 2; // "Dimensionality" + scalar field descriptor |
| 42 |
static const unsigned DESC_CURVATURE = 3; // Test: Gaussian curvature descriptor |
| 43 |
//static const unsigned DESC_CUSTOM = ?; // Example of custom descriptor (to be reimplemented) |
| 44 |
|
| 45 |
//! Generic parameters 'computer' class (at a given scale) |
| 46 |
/** Must be inherited by any custom computer. |
| 47 |
**/ |
| 48 |
class ScaleParamsComputer |
| 49 |
{ |
| 50 |
public: |
| 51 |
|
| 52 |
//! Vault: returns the computer corresponding to the given ID |
| 53 |
static ScaleParamsComputer* GetByID(unsigned descID); |
| 54 |
|
| 55 |
public: |
| 56 |
|
| 57 |
//! Returns the number of available 'descriptors' |
| 58 |
static unsigned AvailableCount(); |
| 59 |
|
| 60 |
//! Vault: returns the ith computer |
| 61 |
static ScaleParamsComputer* GetByIndex(unsigned index); |
| 62 |
|
| 63 |
public: |
| 64 |
virtual ~ScaleParamsComputer() = default; |
| 65 |
|
| 66 |
//! Returns the associated descriptor ID |
| 67 |
virtual unsigned getID() const = 0; |
| 68 |
|
| 69 |
//! Returns the associated descriptor name |
| 70 |
virtual QString getName() const = 0; |
| 71 |
|
| 72 |
//! Returns the number of dimensions per scale for this descriptor |
| 73 |
virtual unsigned dimPerScale() const = 0; |
| 74 |
|
| 75 |
//! Returns whether the computer requires a scalar field or not |
| 76 |
virtual bool needSF() const { return false; } |
| 77 |
|
| 78 |
//! Called once before computing parameters at first scale |
| 79 |
virtual void reset() = 0; |
| 80 |
|
| 81 |
//! Computes the parameters at a given scale |
| 82 |
/** Scales are always called in decreasing order. |
| 83 |
\param[in] neighbors the set of neighbors at the current scale |
| 84 |
\param[in] radius current radius (half scale) value |
| 85 |
\param[out] params the computed parameters |
| 86 |
\param[out] invalidScale whether this scale is 'invalid' (i.e. parameters couldn't be computed, default one have been returned instead) |
| 87 |
**/ |
| 88 |
virtual void computeScaleParams(CCCoreLib::ReferenceCloud& neighbors, double radius, float params[], bool& invalidScale) = 0; |
| 89 |
|
| 90 |
protected: |
| 91 |
}; |
| 92 |
|
| 93 |
//! Set of descriptors |
| 94 |
/** Typically computed on (core) points |
| 95 |
**/ |
| 96 |
struct CorePointDesc |
| 97 |
{ |
| 98 |
//! Parameters array (its size should be 'number of scales' * 'dimensions per scale') |
| 99 |
std::vector<float> params; |
| 100 |
}; |
| 101 |
|
| 102 |
class ccPointCloud; |
| 103 |
|
| 104 |
//! Set of (core) point descriptors |
| 105 |
class CorePointDescSet : public std::vector<CorePointDesc> |
| 106 |
{ |
| 107 |
public: |
| 108 |
|
| 109 |
CorePointDescSet() : m_descriptorID(0), m_dimPerScale(0) {} |
| 110 |
CorePointDescSet(size_t sz) : std::vector<CorePointDesc>(sz), m_descriptorID(0), m_dimPerScale(0) {} |
| 111 |
CorePointDescSet(size_t sz, const CorePointDesc& defaultVal) : std::vector<CorePointDesc>(sz,defaultVal), m_descriptorID(0), m_dimPerScale(0) {} |
| 112 |
CorePointDescSet(const CorePointDescSet& descSet) : std::vector<CorePointDesc>(descSet), m_descriptorID(descSet.m_descriptorID), m_dimPerScale(descSet.m_dimPerScale) {} |
| 113 |
|
| 114 |
//! Converts structure to a byte array |
| 115 |
QByteArray toByteArray() const; |
| 116 |
//! Inits structure from a byte array |
| 117 |
bool fromByteArray(const QByteArray& data); |
| 118 |
|
| 119 |
//! Loads structure of descriptors from an ".msc" file (see Brodu's version) |
| 120 |
bool loadFromMSC(QString filename, QString& error, ccPointCloud* corePoints = nullptr); |
| 121 |
|
| 122 |
//! Returns associated scales |
| 123 |
inline const std::vector<float>& scales() const { return m_scales; } |
| 124 |
|
| 125 |
//! Sets associated scales |
| 126 |
/** \warning Automatically resize the descriptors 'params' vector |
| 127 |
\warning Call this AFTER having resized the vector! |
| 128 |
\return success |
| 129 |
**/ |
| 130 |
bool setScales(const std::vector<float>& scales); |
| 131 |
|
| 132 |
//! Returns associated descriptor ID |
| 133 |
inline const unsigned descriptorID() const { return m_descriptorID; } |
| 134 |
//! Sets associated descriptor ID |
| 135 |
inline void setDescriptorID(unsigned ID) { m_descriptorID = ID; } |
| 136 |
|
| 137 |
//! Returns the number of dimensions per scale |
| 138 |
inline const unsigned dimPerScale() const { return m_dimPerScale; } |
| 139 |
//! Sets associated descriptor ID |
| 140 |
inline void setDimPerScale(unsigned dim) { m_dimPerScale = dim; } |
| 141 |
|
| 142 |
protected: |
| 143 |
|
| 144 |
//! Associated scales |
| 145 |
std::vector<float> m_scales; |
| 146 |
|
| 147 |
//! Associated descriptor ID |
| 148 |
unsigned m_descriptorID; |
| 149 |
|
| 150 |
//! Dimensions per scale |
| 151 |
unsigned m_dimPerScale; |
| 152 |
}; |
| 153 |
|
| 154 |
#endif |