43 if (selection->
size() == 0) {
46 QString(
"[Crop] No point of the cloud '%1' falls %2side "
48 .arg(cloud->
getName(), (inside ?
"in" :
"out")));
64 params.generateOutsideMesh = !inside;
74 if (!rotatedVertices) {
82 cropVertices = rotatedVertices;
86 mesh, cropVertices,
params)) {
92 if (cropVertices != origVertices) {
95 cropVertices = origVertices;
107 if (croppedVertices) {
114 croppedMesh =
new ccMesh(tempMesh, croppedVertices);
115 croppedMesh->
addChild(croppedVertices);
117 if (croppedMesh->
size() == 0) {
120 "'%1' falls %2side the input box!")
122 (inside ?
"in" :
"out")));
126 assert(origVertices);
134 bool success =
false;
142 "[Crop] Failed to compute normals on the "
143 "output mesh (not enough memory)");
150 if (
params.trackOrigIndexes) {
151 const std::vector<unsigned>& origTriIndexes =
152 inside ?
params.origTriIndexesMapInside
153 :
params.origTriIndexesMapOutside;
161 std::vector<bool> vertProcessed(
162 croppedVertices->
size(),
false);
165 bool importColors =
false;
172 "[Crop] Failed to transfer RGB "
173 "colors on the output mesh "
174 "(not enough memory)");
178 std::vector<ccScalarField*> importedSFs;
195 for (
unsigned i = 0; i < sfCount; ++i) {
210 if (origVertices_pc) {
223 importedSFs.push_back(sf);
226 "[Crop] Failed to transfer "
227 "one or several scalar "
228 "fields on the output mesh "
229 "(not enough memory)");
241 ->getNumberOfScalarFields()) -
244 ->getCurrentDisplayedScalarFieldIndex()));
250 bool importSFs = !importedSFs.empty();
252 if (importColors || importSFs) {
255 i < croppedMesh->
size(); ++i) {
257 unsigned origTriIndex =
271 for (
unsigned j = 0; j < 3; ++j) {
272 unsigned vertIndex = tsic->
i[j];
274 if (vertProcessed[vertIndex]) {
301 origTriIndex, *Vcj, w);
306 static_cast<unsigned>(
312 if (origVertices_pc) {
339 ScalarType sVal =
static_cast<
343 importedSFs[s]->setValue(
349 vertProcessed[vertIndex] =
true;
353 for (
size_t s = 0; s < importedSFs.size();
355 importedSFs[s]->computeMinAndMax();
367 croppedMesh->
showSF(importSFs &&
376 assert(origMaterialSet);
378 if (origMaterialSet &&
379 !origMaterialSet->empty() &&
382 std::vector<int> materialUsed(
383 origMaterialSet->size(), -1);
387 i < croppedMesh->
size(); ++i) {
389 unsigned origTriIndex =
398 materialUsed[mtlIndex] = 1;
402 size_t materialUsedCount = 0;
405 i < materialUsed.size(); ++i)
406 if (materialUsed[i] == 1)
409 if (materialUsedCount ==
410 materialUsed.size()) {
414 origMaterialSet->
clone());
426 i < materialUsed.size();
428 if (materialUsed[i] >= 0) {
446 i < croppedMesh->
size(); ++i) {
468 "[Crop] Failed to transfer "
469 "materials on the output mesh (not "
477 ->reservePerTriangleTexCoordIndexes() &&
479 croppedMesh->
size() * 3)) {
482 i < croppedMesh->
size(); ++i) {
484 unsigned origTriIndex =
490 origTriIndex, tx1, tx2,
499 int texIndexes[3] = {-1, -1, -1};
500 for (
unsigned j = 0; j < 3; ++j) {
501 unsigned vertIndex = tsic->
i[j];
508 origTriIndex, *Vcj, w);
523 (tx1 ? tx1->
tx * w.
u[0]
525 (tx2 ? tx2->
tx * w.
u[1]
527 (tx3 ? tx3->
tx * w.
u[2]
530 (tx1 ? tx1->
ty * w.
u[0]
532 (tx2 ? tx2->
ty * w.
u[1]
534 (tx3 ? tx3->
ty * w.
u[2]
555 "[Crop] Failed to transfer "
556 "texture coordinates on the "
557 "output mesh (not enough "
564 }
catch (
const std::bad_alloc&) {
566 "[Crop] Failed to transfer per-vertex "
567 "features (color, SF values, etc.) on the "
568 "output mesh (not enough memory)");
576 "[Crop] Failed to create output mesh vertices (not "
587 delete params.outsideMesh;
constexpr ScalarType NAN_VALUE
NaN as a ScalarType value.
cmdLineReadable * params[]
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Array of 2D texture coordinates.
Type dot(const Vector3Tpl &v) const
Dot product.
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
bool reserveSafe(size_t count)
Reserves memory (no exception thrown)
unsigned currentSize() const
void addElement(const Type &value)
virtual bool colorsShown() const
Returns whether colors are shown or not.
virtual bool hasColors() const
Returns whether colors are enabled or not.
virtual bool sfShown() const
Returns whether active scalar field is visible.
virtual bool normalsShown() const
Returns whether normals are shown or not.
virtual bool hasNormals() const
Returns whether normals are enabled or not.
virtual void showColors(bool state)
Sets colors visibility.
virtual void showSF(bool state)
Sets active scalarfield visibility.
virtual bool hasScalarFields() const
Returns whether one or more scalar fields are instantiated.
virtual void setGLTransformation(const ccGLMatrix &trans)
Associates entity with a GL transformation (rotation + translation)
ccGLMatrixTpl< T > inverse() const
Returns inverse transformation.
Float version of ccGLMatrixTpl.
virtual bool materialsShown() const
Sets whether textures/material should be displayed or not.
void showNormals(bool state) override
Sets normals visibility.
void importParametersFrom(const ccGenericMesh *mesh)
Imports the parameters from another mesh.
virtual bool hasPerTriangleTexCoordIndexes() const =0
Returns whether this mesh as per-triangle triplets of tex coords indexes.
virtual const ccMaterialSet * getMaterialSet() const =0
virtual bool hasTriNormals() const =0
Returns whether the mesh has per-triangle normals.
virtual int getTriangleMtlIndex(unsigned triangleIndex) const =0
Returns a given triangle material indexes.
virtual ccGenericPointCloud * getAssociatedCloud() const =0
Returns the vertices cloud.
virtual bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C)=0
Interpolates RGB colors inside a given triangle.
virtual void computeInterpolationWeights(unsigned triIndex, const CCVector3 &P, CCVector3d &weights) const
Returns the (barycentric) interpolation weights for a given triangle.
virtual void getTriangleTexCoordinates(unsigned triIndex, TexCoords2D *&tx1, TexCoords2D *&tx2, TexCoords2D *&tx3) const =0
Returns per-triangle texture coordinates (pointer to)
virtual void showMaterials(bool state)
Sets whether textures should be displayed or not.
virtual bool hasMaterials() const =0
A 3D cloud interface with associated features (color, normals, octree, etc.)
void importParametersFrom(const ccGenericPointCloud *cloud)
Imports the parameters from another cloud.
Hierarchical CLOUDVIEWER Object.
void applyGLTransformation_recursive(const ccGLMatrix *trans=nullptr)
Applies the active OpenGL transformation to the entity (recursive)
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
Mesh (triangle) material.
ccMaterialSet * clone() const
Clones materials set.
Mesh (triangle) material.
QSharedPointer< ccMaterial > Shared
Shared type.
cloudViewer::VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) override
Returns the indexes of the vertices of a given triangle.
bool reservePerTriangleMtlIndexes()
Reserves memory to store per-triangle material index.
void addTriangleMtlIndex(int mtlIndex)
Adds triangle material index for next triangle.
void setTriangleMtlIndex(unsigned triangleIndex, int mtlIndex)
Sets triangle material indexes.
bool computePerTriangleNormals()
Computes per-triangle normals.
void setMaterialSet(ccMaterialSet *materialSet, bool autoReleaseOldMaterialSet=true)
Sets associated material set (may be shared)
void addTriangleTexCoordIndexes(int i1, int i2, int i3)
Adds a triplet of tex coords indexes for next triangle.
void setTexCoordinatesTable(TextureCoordsContainer *texCoordsTable, bool autoReleaseOldTable=true)
Sets per-triangle texture coordinates array (may be shared)
bool computePerVertexNormals()
Computes per-vertex normals.
virtual unsigned size() const override
Returns the number of triangles.
int getTriangleMtlIndex(unsigned triangleIndex) const override
Returns a given triangle material indexes.
virtual QString getName() const
Returns object name.
bool isA(CV_CLASS_ENUM type) const
virtual void setEnabled(bool state)
Sets the "enabled" property.
bool isKindOf(CV_CLASS_ENUM type) const
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void setCurrentDisplayedScalarField(int index)
Sets the currently displayed scalar field.
void unallocateColors()
Erases the cloud colors.
void deleteAllScalarFields() override
Deletes all scalar fields associated to this cloud.
int addScalarField(const char *uniqueName) override
Creates a new scalar field and registers it.
bool resizeTheRGBTable(bool fillWithWhite=false)
Resizes the RGB colors array.
cloudViewer::ReferenceCloud * crop(const ccBBox &box, bool inside=true) override
Crops the cloud inside (or outside) a bounding box.
static ccPointCloud * From(const cloudViewer::GenericIndexedCloud *cloud, const ccGenericPointCloud *sourceCloud=nullptr)
Creates a new point cloud object from a GenericIndexedCloud.
void setPointColor(size_t pointIndex, const ecvColor::Rgb &col)
Sets a particular point color.
ccPointCloud * partialClone(const cloudViewer::ReferenceCloud *selection, int *warnings=nullptr, bool withChildEntities=true) const
Creates a new point cloud object from a ReferenceCloud (selection)
A scalar field associated to display-related parameters.
void importParametersFrom(const ccScalarField *sf)
Imports the parameters from another scalar field.
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
virtual ScalarType getPointScalarValue(unsigned pointIndex) const =0
Returns the ith point associated scalar value.
virtual VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex)=0
Returns the indexes of the vertices of a given triangle.
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 CCVector3 * getPoint(unsigned index) const override
A very simple point cloud (no point duplication)
unsigned size() const override
Returns the number of points.
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)
A simple mesh structure, with index-based vertex access.
const GenericIndexedCloud * vertices() const
Returns the vertices.
Generic file read and write utility for python interface.
bool LessThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).
Triangle described by the indexes of its 3 vertices.