31 m_polygonMesh(nullptr),
32 m_contourPolyline(nullptr),
33 m_contourVertices(nullptr),
34 m_originPoints(nullptr),
38 m_maxEdgeLength(maxEdgeLength) {
52 m_polygonMesh(nullptr),
53 m_contourPolyline(nullptr),
54 m_contourVertices(nullptr),
55 m_originPoints(nullptr),
76 if (!facet || this->
IsEmpty()) {
90 QString(
"[ccFacet::clone][%1] Failed to clone countour!")
117 QString(
"[ccFacet::clone][%1] Failed to clone polygon!")
149 facet->
m_arrow = std::shared_ptr<ccMesh>();
150 facet->
m_arrow->CreateInternalCloud();
169 bool transferOwnership ,
174 if (!cloud || cloud->
size() < 3) {
176 "[ccFacet::Create] Need at least 3 points to create a valid "
183 if (!facet->createInternalRepresentation(cloud, planeEquation)) {
200 if (transferOwnership) {
212 bool ccFacet::createInternalRepresentation(
216 if (!
points)
return false;
217 unsigned ptsCount =
points->size();
218 if (ptsCount < 3)
return false;
223 if (!planeEquation) {
224 planeEquation = Yk.getLSPlane();
225 if (!planeEquation) {
227 "[ccFacet::createInternalRepresentation] Failed to compute "
228 "the LS plane passing through the input points!");
235 std::vector<cloudViewer::PointProjectionTools::IndexedCCVector2> points2D;
240 if (!Yk.projectPointsOn2DPlane<
244 "[ccFacet::createInternalRepresentation] Not enough memory!");
255 for (
unsigned i = 0; i < ptsCount; ++i) {
256 points2D[i].index = i;
263 std::list<cloudViewer::PointProjectionTools::IndexedCCVector2*>
268 "[ccFacet::createInternalRepresentation] Failed to compute "
269 "the convex hull of the input points!");
272 unsigned hullPtsCount =
static_cast<unsigned>(hullPoints.size());
281 "[ccFacet::createInternalRepresentation] Not enough "
288 IndexedCCVector2*>::const_iterator it =
290 it != hullPoints.end(); ++it) {
316 "[ccFacet::createInternalRepresentation] Not enough "
317 "memory to create the contour polyline!");
322 std::vector<CCVector2> hullPointsVector;
324 hullPointsVector.reserve(hullPoints.size());
326 IndexedCCVector2*>::const_iterator it =
328 it != hullPoints.end(); ++it) {
329 hullPointsVector.push_back(**it);
333 "[ccFacet::createInternalRepresentation] Not enough memory "
334 "to create the contour mesh!");
341 if (!hullPointsVector.empty() &&
345 std::string errorStr;
349 if (removePointsOutsideHull)
351 unsigned triCount = dm.
size();
352 assert(triCount != 0);
357 for (
unsigned i = 0; i < triCount; ++i) {
369 normsTable->reserve(1);
374 for (
unsigned i = 0; i < triCount; ++i)
386 "[ccFacet::createInternalRepresentation] Not "
387 "enough memory to create the polygon mesh's "
398 "[ccFacet::createInternalRepresentation] Not "
399 "enough memory to create the polygon mesh!");
403 " Failed to create the polygon mesh "
404 "(third party lib. said '%1'")
405 .arg(QString::fromStdString(errorStr)));
444 Eigen::Matrix4d transformation;
448 m_arrow->Transform(transformation);
450 transformation = Eigen::Matrix4d::Identity();
452 m_arrow->Transform(transformation);
483 assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
484 if (dataVersion < 32) {
496 uint32_t originPointsUniqueID =
498 if (out.write((
const char*)&originPointsUniqueID, 4) < 0)
507 uint32_t contourPointsUniqueID =
510 if (out.write((
const char*)&contourPointsUniqueID, 4) < 0)
519 uint32_t contourPolyUniqueID =
522 if (out.write((
const char*)&contourPolyUniqueID, 4) < 0)
530 uint32_t polygonMeshUniqueID =
532 if (out.write((
const char*)&polygonMeshUniqueID, 4) < 0)
546 if (out.write((
const char*)&
m_rms,
sizeof(
double)) < 0)
return WriteError();
549 if (out.write((
const char*)&
m_surface,
sizeof(
double)) < 0)
561 return std::max(
static_cast<short>(32),
572 if (dataVersion < 32)
return false;
578 uint32_t origPointsUniqueID = 0;
579 if (in.read((
char*)&origPointsUniqueID, 4) < 0)
return ReadError();
589 uint32_t contourPointsUniqueID = 0;
590 if (in.read((
char*)&contourPointsUniqueID, 4) < 0)
return ReadError();
600 uint32_t contourPolyUniqueID = 0;
601 if (in.read((
char*)&contourPolyUniqueID, 4) < 0)
return ReadError();
611 uint32_t polygonMeshUniqueID = 0;
612 if (in.read((
char*)&polygonMeshUniqueID, 4) < 0)
return ReadError();
627 if (in.read((
char*)&
m_rms,
sizeof(double)) < 0)
return ReadError();
654 for (
int i = 0; i < 4; ++i) {
668 return Eigen::Vector3d();
676 return Eigen::Vector3d();
684 return Eigen::Vector3d();
732 const Eigen::Vector3d& center) {
747 if (facet.
IsEmpty())
return (*
this);
748 if (
this == &facet) {
constexpr PointCoordinateType PC_ONE
'1' as a PointCoordinateType value
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
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.
Array of compressed 3D normals (single index)
Type dot(const Vector3Tpl &v) const
Dot product.
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
void addElement(const Type &value)
virtual bool isVisible() const
Returns whether entity is visible or not.
virtual bool isVisibilityLocked() const
Returns whether visibility is locked or not.
virtual void lockVisibility(bool state)
Locks/unlocks visibility.
virtual void setVisible(bool state)
Sets entity visibility.
virtual void setTempColor(const ecvColor::Rgb &col, bool autoActivate=true)
Sets current temporary (unique)
virtual bool isRedraw() const
Returns whether entity is to be redraw.
virtual void showColors(bool state)
Sets colors visibility.
virtual void setOpacity(float opacity)
Set opacity activation state.
ccMesh * getPolygon()
Returns polygon mesh (if any)
short minimumFileVersion_MeOnly() const override
std::shared_ptr< ccMesh > getNormalVectorMesh(bool update=false)
Gets normal vector mesh.
virtual ccFacet & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
ccFacet operator+(const ccFacet &polyline) const
ccPolyline * getContour()
Returns contour polyline (if any)
virtual ~ccFacet() override
Destructor.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
double m_rms
RMS (relatively to m_associatedPoints)
ccFacet & operator+=(const ccFacet &polyline)
ccFacet(PointCoordinateType maxEdgeLength=0, QString name=QString("Facet"))
Default constructor.
ccMesh * m_polygonMesh
Facet.
ccFacet * clone() const
Clones this facet.
double m_surface
Surface (m_polygon)
ccFacet & operator=(const ccFacet &polyline)
virtual ccFacet & Scale(const double s, const Eigen::Vector3d ¢er) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
ccPointCloud * m_originPoints
Origin points.
CCVector3 getNormal() const override
Returns the entity normal.
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
PointCoordinateType m_maxEdgeLength
Max length.
void invertNormal()
Inverts the facet normal.
virtual ccFacet & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d ¢er) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
ccPolyline * m_contourPolyline
Facet contour.
virtual bool IsEmpty() const override
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
void setColor(const ecvColor::Rgb &rgb)
Sets the facet unique color.
std::shared_ptr< ccMesh > m_arrow
for python interface use
virtual ccFacet & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
virtual void applyGLTransformation(const ccGLMatrix &trans) override
Applies a GL transformation to the entity.
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
CCVector3 m_center
Facet centroid.
const CCVector3 & getCenter() const
Returns the facet center.
static ccFacet * Create(cloudViewer::GenericIndexedCloudPersist *cloud, PointCoordinateType maxEdgeLength=0, bool transferOwnership=false, const PointCoordinateType *planeEquation=nullptr)
Creates a facet from a set of points.
virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
PointCoordinateType m_planeEquation[4]
Plane equation - as usual in CC plane equation is ax + by + cz = d.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
ccPointCloud * m_contourVertices
Shared vertices (between polygon and contour)
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
void setOriginPoints(ccPointCloud *cloud)
Sets origin points.
void applyRotation(Vector3Tpl< float > &vec) const
Applies rotation only to a 3D vector (in place) - float version.
static ccGLMatrixTpl< float > FromToRotation(const Vector3Tpl< float > &from, const Vector3Tpl< float > &to)
Creates a transformation matrix that rotates a vector to another.
void apply(float vec[3]) const
Applies transformation to a 3D vector (in place) - float version.
static Eigen::Matrix< double, 4, 4 > ToEigenMatrix4(const ccGLMatrixTpl< float > &mat)
Float version of ccGLMatrixTpl.
void showNormals(bool state) override
Sets normals visibility.
void enableStippling(bool state)
Enables polygon stippling.
Hierarchical CLOUDVIEWER Object.
virtual short minimumFileVersion_MeOnly() const
virtual bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap)
Loads own object data.
void detachChild(ccHObject *child)
Detaches a specific child.
virtual bool toFile_MeOnly(QFile &out, short dataVersion) const
Save own object data.
virtual void applyGLTransformation(const ccGLMatrix &trans)
Applies a GL transformation to the entity.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
ccMesh * cloneMesh(ccGenericPointCloud *vertices=nullptr, ccMaterialSet *clonedMaterials=nullptr, NormsIndexesTableType *clonedNormsTable=nullptr, TextureCoordsContainer *cloneTexCoords=nullptr)
Clones this entity.
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
virtual ccMesh & Scale(const double s, const Eigen::Vector3d ¢er) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
virtual unsigned size() const override
Returns the number of triangles.
void setTriNormsTable(NormsIndexesTableType *triNormsTable, bool autoReleaseOldTable=true)
Sets per-triangle normals array (may be shared)
bool reserve(std::size_t n)
Reserves the memory to store the vertex indexes (3 per triangle)
void addTriangle(unsigned i1, unsigned i2, unsigned i3)
Adds a triangle to the mesh.
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
bool reservePerTriangleNormalIndexes()
Reserves memory to store per-triangle triplets of normal indexes.
void addTriangleNormalIndexes(int i1, int i2, int i3)
Adds a triplet of normal indexes for next triangle.
static std::shared_ptr< ccMesh > CreateArrow(double cylinder_radius=1.0, double cone_radius=1.5, double cylinder_height=5.0, double cone_height=4.0, int resolution=20, int cylinder_split=4, int cone_split=1)
virtual ccMesh & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
virtual ccMesh & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d ¢er) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
virtual ccMesh & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
static CompressedNormType GetNormIndex(const PointCoordinateType N[])
Returns the compressed index corresponding to a normal vector.
virtual void setLocked(bool state)
Sets the "enabled" property.
virtual bool isLocked() const
Returns whether the object is locked or not.
virtual QString getName() const
Returns object name.
virtual unsigned getUniqueID() const
Returns object unique ID.
virtual void setName(const QString &name)
Sets object name.
virtual void setEnabled(bool state)
Sets the "enabled" property.
virtual bool isEnabled() const
Returns whether the object is enabled or not.
QString m_name
Object name.
Interface for a planar entity.
void glDrawNormal(CC_DRAW_CONTEXT &context, const CCVector3 &pos, float scale, const ecvColor::Rgb *color=0)
Draws a normal vector (OpenGL)
bool normalVectorIsShown() const
Whether normal vector is shown or not.
bool m_showNormalVector
Whether the facet normal vector should be displayed or not.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
bool setRGBColor(ColorCompType r, ColorCompType g, ColorCompType b)
Set a unique color for the whole cloud (shortcut)
ccGenericPointCloud * clone(ccGenericPointCloud *destCloud=nullptr, bool ignoreChildren=false) override
Clones this entity.
PointCoordinateType computeLength() const
Computes the polyline length.
const ecvColor::Rgb & getColor() const
Returns the polyline color.
void setColor(const ecvColor::Rgb &col)
Sets the polyline color.
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'.
A class to compute and handle a Delaunay 2D mesh on a subset of points.
VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) override
Returns the indexes of the vertices of a given triangle.
virtual unsigned size() const override
Returns the number of triangles.
static bool Available()
Returns whether 2D Delaunay triangulation is supported or not.
virtual bool removeOuterTriangles(const std::vector< CCVector2 > &vertices2D, const std::vector< CCVector2 > &polygon2D, bool removeOutside=true)
Removes the triangles falling outside of a given (2D) polygon.
virtual bool buildMesh(const std::vector< CCVector2 > &points2D, std::size_t pointCountToUse, std::string &outputErrorStr)
Build the Delaunay mesh on top a set of 2D points.
static constexpr int USE_ALL_POINTS
virtual unsigned size() const =0
Returns the number of points.
A generic 3D point cloud with index-based and presistent access to points.
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
void setClosed(bool state)
Sets whether the polyline is closed or not.
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 bool reserve(unsigned n)
Reserves some memory for hosting the point references.
#define MACRO_Draw3D(context)
static const char DEFAULT_ORIGIN_POINTS_NAME[]
static const char DEFAULT_CONTOUR_POINTS_NAME[]
static const char DEFAULT_CONTOUR_NAME[]
static const char DEFAULT_POLYGON_MESH_NAME[]
constexpr Rgb darkGrey(MAX/2, MAX/2, MAX/2)
constexpr Rgb green(0, MAX, 0)
Triangle described by the indexes of its 3 vertices.