33 : GenericIndexedMesh(),
35 m_triNormsShown(false),
36 m_materialsShown(false),
50 static const GLubyte
s_byte0 = 1 | 4 | 16 | 64;
51 static const GLubyte
s_byte1 = 2 | 8 | 32 | 128;
96 *_vertWireIndexes++ = i;
97 *_vertWireIndexes++ = (((i + 1) % 3) == 0 ? i - 2 : i + 1);
140 if (!vertices)
return;
149 unsigned triNum =
size();
150 if (triNum == 0)
return;
154 (triNum >
context.minLODTriangleCount &&
157 (lodEnabled ?
static_cast<unsigned>(
158 ceil(
static_cast<double>(triNum * 3) /
161 unsigned displayedTriNum = triNum / decimStep;
172 bool visFiltering = (verticesVisibility.size() == vertices->
size());
173 context.visFiltering = visFiltering;
201 if (entityPickingMode) {
209 showTriNormals =
false;
210 applyMaterials =
false;
211 showTextures =
false;
216 bool greyForNanScalarValues =
true;
227 if (greyForNanScalarValues && entityPickingMode) {
254 assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
255 if (dataVersion < 29) {
263 if (out.write(
reinterpret_cast<const char*
>(&
m_showWired),
sizeof(
bool)) <
282 if (out.write(
reinterpret_cast<const char*
>(&
m_stippling),
sizeof(
bool)) <
290 return std::max(
static_cast<short>(29),
302 if (in.read(
reinterpret_cast<char*
>(&
m_showWired),
sizeof(
bool)) < 0)
310 if (dataVersion >= 29) {
321 if (in.read(
reinterpret_cast<char*
>(&
m_stippling),
sizeof(
bool)) < 0)
330 double samplingParameter,
335 if (samplingParameter <= 0) {
340 bool withFeatures = (withNormals || withRGB || withTexture);
342 QScopedPointer<std::vector<unsigned>> triIndices;
344 triIndices.reset(
new std::vector<unsigned>);
350 this, samplingParameter, pDlg, triIndices.data());
353 this,
static_cast<unsigned>(samplingParameter), pDlg,
361 if (sampledCloud->
size() == 0) {
363 "[ccGenericMesh::samplePoints] No point was generated "
364 "(sampling density is too low?)");
369 "[ccGenericMesh::samplePoints] Not enough memory!");
374 sampledCloud =
nullptr;
376 CVLog::Warning(
"[ccGenericMesh::samplePoints] Not enough memory!");
383 if (withFeatures && triIndices && triIndices->size() >= cloud->
size()) {
387 for (
unsigned i = 0; i < cloud->
size(); ++i) {
388 unsigned triIndex = triIndices->at(i);
399 "[ccGenericMesh::samplePoints] Failed to interpolate "
400 "normals (not enough memory?)");
407 for (
unsigned i = 0; i < cloud->
size(); ++i) {
408 unsigned triIndex = triIndices->at(i);
419 "[ccGenericMesh::samplePoints] Failed to export "
420 "texture colors (not enough memory?)");
424 for (
unsigned i = 0; i < cloud->
size(); ++i) {
425 unsigned triIndex = triIndices->at(i);
436 "[ccGenericMesh::samplePoints] Failed to interpolate "
437 "colors (not enough memory?)");
486 weights.
x = ((P - *B).cross(*C - *B)).normd() ;
487 weights.
y = ((P - *C).cross(*A - *C)).normd() ;
488 weights.
z = ((P - *A).cross(*B - *A)).normd() ;
491 double sum = weights.
x + weights.
y + weights.
z;
504 assert(triIndex <
size());
514 bool inFrustum =
true;
520 bool insideA = camera.
project(A3D, A2D, &inFrustum);
521 bool insideB = camera.
project(B3D, B2D, &inFrustum);
522 bool insideC = camera.
project(C3D, C2D, &inFrustum);
523 if (!insideA && !insideB && !insideC) {
534 bool insideA = camera.
project(A3Dp, A2D, &inFrustum);
535 bool insideB = camera.
project(B3Dp, B2D, &inFrustum);
536 bool insideC = camera.
project(C3Dp, C2D, &inFrustum);
537 if (!insideA && !insideB && !insideC) {
543 GLdouble detT = (B2D.
y - C2D.
y) * (A2D.
x - C2D.
x) +
544 (C2D.
x - B2D.
x) * (A2D.
y - C2D.
y);
548 GLdouble l1 = ((B2D.
y - C2D.
y) * (clickPos.
x - C2D.
x) +
549 (C2D.
x - B2D.
x) * (clickPos.
y - C2D.
y)) /
551 GLdouble l2 = ((C2D.
y - A2D.
y) * (clickPos.
x - C2D.
x) +
552 (A2D.
x - C2D.
x) * (clickPos.
y - C2D.
y)) /
556 if (l1 >= 0 && l1 <= 1.0 && l2 >= 0.0 && l2 <= 1.0) {
557 double l1l2 = l1 + l2;
558 assert(l1l2 >= -1.0e-12);
564 GLdouble l3 = 1.0 - l1 - l2;
565 assert(l3 >= -1.0e-12);
569 l1 * A3D.
y + l2 * B3D.
y + l3 * C3D.
y,
570 l1 * A3D.
z + l2 * B3D.
z + l3 * C3D.
z);
572 if (barycentricCoords) {
585 int& nearestTriIndex,
586 double& nearestSquareDist,
599 nearestTriIndex = -1;
600 nearestSquareDist = -1.0;
602 if (barycentricCoords) *barycentricCoords =
CCVector3d(0, 0, 0);
610 #if defined(_OPENMP) && !defined(_DEBUG)
611 #pragma omp parallel for
613 for (
int i = 0; i < static_cast<int>(
size()); ++i) {
617 P, barycentricCoords ? &BC :
nullptr))
620 double squareDist = (
X - P).norm2d();
621 if (nearestTriIndex < 0 || squareDist < nearestSquareDist) {
622 nearestSquareDist = squareDist;
623 nearestTriIndex =
static_cast<int>(i);
625 if (barycentricCoords) *barycentricCoords = BC;
629 return (nearestTriIndex >= 0);
638 if (triIndex >=
size()) {
652 return trianglePicking(triIndex, clickPos, trans, noGLTrans, *vertices,
653 camera, point, barycentricCoords);
660 bool warningIfOutside )
const {
661 if (triIndex >=
size()) {
672 double z = 1.0 -
uv.x -
uv.y;
673 if (warningIfOutside && ((
z < -1.0e-6) || (
z > 1.0 + 1.0e-6))) {
721 std::vector<std::string> texture_files = {texture_file};
726 const std::vector<std::string>& texture_files) {
727 if (texture_files.empty()) {
734 if (applyMaterials || showTextures) {
736 bool has_materials =
true;
738 has_materials =
false;
744 for (std::size_t ti = 0; ti < texture_files.size(); ++ti) {
745 QString textureFileName =
746 QFileInfo(texture_files[ti].c_str()).fileName();
747 QString textureFilePath = texture_files[ti].c_str();
748 if (ti >= materials->size()) {
750 if (material->loadAndSetTexture(textureFilePath)) {
751 const QImage& texture = material->getTexture();
753 "texture '%1' (%2x%3 pixels)")
754 .arg(textureFileName)
755 .arg(texture.width())
756 .arg(texture.height()));
760 materials->push_back(material);
764 .arg(textureFilePath));
768 const_cast<ccMaterial*
>(materials->at(ti).get());
772 const QImage& texture = material->
getTexture();
774 "texture '%1' (%2x%3 pixels)")
775 .arg(textureFileName)
776 .arg(texture.width())
777 .arg(texture.height()));
781 .arg(textureFilePath));
786 if (!has_materials) {
788 if (childIndex < 0)
addChild(materials);
Vector3Tpl< double > CCVector3d
Double 3D Vector.
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 Print(const char *format,...)
Prints out a formatted message in console.
QSharedPointer< ccColorScale > Shared
Shared pointer type.
virtual bool isVisible() const
Returns whether entity is visible or not.
virtual bool hasColors() const
Returns whether colors are enabled or not.
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 bool hasNormals() const
Returns whether normals are enabled or not.
virtual bool isColorOverridden() const
virtual void showNormals(bool state)
Sets normals visibility.
virtual void showColors(bool state)
Sets colors visibility.
bool m_normalsDisplayed
Specifies whether normals should be displayed.
virtual void getDrawingParameters(glDrawParams ¶ms) const
Returns main OpenGL parameters for this entity.
ecvColor::Rgb m_tempColor
Temporary (unique) color.
Float version of ccGLMatrixTpl.
virtual void showPoints(bool state)
bool updateTextures(const std::string &texture_file)
virtual bool materialsShown() const
Sets whether textures/material should be displayed or not.
void showNormals(bool state) override
Sets normals visibility.
virtual bool hasTextures() const =0
Returns whether textures are available for this mesh.
void importParametersFrom(const ccGenericMesh *mesh)
Imports the parameters from another mesh.
virtual void showWired(bool state)
Sets whether mesh should be displayed as a wire or with plain facets.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
virtual bool triNormsShown() const
Returns whether per-triangle normals are shown or not.
static CCVector3 * GetNormalsBuffer()
bool m_triNormsShown
Per-triangle normals display flag.
static ecvColor::Rgb * GetColorsBuffer()
virtual bool isShownAsWire() const
Returns whether the mesh is displayed as wired or with plain facets.
virtual const ccMaterialSet * getMaterialSet() const =0
bool m_stippling
Polygon stippling state.
virtual bool hasTriNormals() const =0
Returns whether the mesh has per-triangle normals.
const CCVector3d & getGlobalShift() const override
Returns the shift applied to original coordinates.
virtual void computeInterpolationWeights(unsigned triIndex, const CCVector3 &P, CCVector3d &weights) const
Returns the (barycentric) interpolation weights for a given triangle.
bool m_showWired
Wireframe display mode.
short minimumFileVersion_MeOnly() const override
ccPointCloud * samplePoints(bool densityBased, double samplingParameter, bool withNormals, bool withRGB, bool withTexture, cloudViewer::GenericProgressCallback *pDlg=nullptr)
Samples points on a mesh.
virtual ccGenericPointCloud * getAssociatedCloud() const =0
Returns the vertices cloud.
double getGlobalScale() const override
Returns the scale applied to original coordinates.
virtual bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C)=0
Interpolates RGB colors inside a given triangle.
static bool IsCloudVerticesOfMesh(ccGenericPointCloud *cloud, ccGenericMesh **mesh=nullptr)
Helper to determine if the input cloud acts as vertices of a mesh.
void enableStippling(bool state)
Enables polygon stippling.
virtual bool trianglePicking(const CCVector2d &clickPos, const ccGLCameraParameters &camera, int &nearestTriIndex, double &nearestSquareDist, CCVector3d &nearestPoint, CCVector3d *barycentricCoords=nullptr) const
Brute force triangle picking.
void setGlobalShift(const CCVector3d &shift) override
Sets shift applied to original coordinates (information storage only)
bool m_materialsShown
Texture/material display flag.
bool computePointPosition(unsigned triIndex, const CCVector2d &uv, CCVector3 &P, bool warningIfOutside=true) const
static unsigned * GetWireVertexIndexes()
Returns a pre-initialized array of vertex indexes for wired display.
static CCVector3 * GetVertexBuffer()
virtual bool isShownAsPoints() const
Returns whether the mesh is displayed as wired or with plain facets.
void handleColorRamp(CC_DRAW_CONTEXT &context)
Handles the color ramp display.
ccGenericMesh(QString name=QString())
Default constructor.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
void drawMeOnly(CC_DRAW_CONTEXT &context) override
Enables (OpenGL) stipple mask.
virtual bool getColorFromMaterial(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C, bool interpolateColorIfNoTexture)=0
void setGlobalScale(double scale) override
virtual bool stipplingEnabled() const
Returns whether polygon stippling is enabled or not.
virtual bool hasMaterials() const =0
virtual void showTriNorms(bool state)
Sets whether to show or not per-triangle normals.
A 3D cloud interface with associated features (color, normals, octree, etc.)
virtual VisibilityTableType & getTheVisibilityArray()
Returns associated visibility array.
std::vector< unsigned char > VisibilityTableType
Array of "visibility" information for each point.
static ccGenericMesh * ToGenericMesh(ccHObject *obj)
Converts current object to ccGenericMesh (if possible)
Hierarchical CLOUDVIEWER Object.
virtual const ccGLMatrix & getGLTransformationHistory() const
Returns the transformation 'history' matrix.
bool getAbsoluteGLTransformation(ccGLMatrix &trans) const
virtual short minimumFileVersion_MeOnly() const
int getChildIndex(const ccHObject *aChild) const
Returns child index.
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.
QString getViewId() const
unsigned getChildrenNumber() const
Returns the number of children.
virtual void setGLTransformationHistory(const ccGLMatrix &mat)
Sets the transformation 'history' matrix (handle with care!)
ccHObject * getParent() const
Returns parent object.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
Mesh (triangle) material.
Mesh (triangle) material.
QSharedPointer< ccMaterial > Shared
Shared type.
const QImage & getTexture() const
Returns the texture (if any)
bool loadAndSetTexture(const QString &absoluteFilename)
Loads texture from file (and set it if successful)
const QVariantMap & metaData() const
Returns meta-data map (const only)
virtual QString getName() const
Returns object name.
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
bool isA(CV_CLASS_ENUM type) const
virtual void setName(const QString &name)
Sets object name.
virtual bool isEnabled() const
Returns whether the object is enabled or not.
bool isKindOf(CV_CLASS_ENUM type) const
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void addColorRampInfo(CC_DRAW_CONTEXT &context)
Adds associated SF color ramp info to current GL context.
bool sfColorScaleShown() const
Returns whether color scale should be displayed or not.
void addNorm(const CCVector3 &N)
Pushes a normal vector on stack (shortcut)
ccScalarField * getCurrentDisplayedScalarField() const
Returns the currently displayed scalar (or 0 if none)
static ccPointCloud * From(const cloudViewer::GenericIndexedCloud *cloud, const ccGenericPointCloud *sourceCloud=nullptr)
Creates a new point cloud object from a GenericIndexedCloud.
bool reserveTheNormsTable()
Reserves memory to store the compressed normals.
bool reserveTheRGBTable()
Reserves memory to store the RGB colors.
void addRGBColor(const ecvColor::Rgb &C)
Pushes an RGB color on stack.
A scalar field associated to display-related parameters.
bool areNaNValuesShownInGrey() const
Returns whether NaN values are displayed in gray or hidden.
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'.
Shifted entity interface.
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.
void copyGlobalShiftAndScale(const ccShiftedObject &s)
Copies the Global Shift and Scale from another entity.
virtual unsigned size() const =0
Returns the number of points.
virtual bool interpolateNormals(unsigned triIndex, const CCVector3 &P, CCVector3 &N)
Interpolates normal(s) inside a given triangle.
virtual GenericTriangle * _getTriangle(unsigned triangleIndex)=0
Returns the ith triangle.
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const =0
Returns the vertices of a given triangle.
virtual unsigned size() const =0
Returns the number of triangles.
A generic triangle interface.
virtual const CCVector3 * _getA() const =0
Returns the first vertex (A)
virtual const CCVector3 * _getC() const =0
Returns the third vertex (C)
virtual const CCVector3 * _getB() const =0
Returns the second vertex (B)
unsigned size() const override
const CCVector3 * getPoint(unsigned index) const override
#define MACRO_Draw2D(context)
#define MACRO_Draw3D(context)
#define MACRO_LightIsEnabled(context)
#define MACRO_Foreground(context)
#define MACRO_FastEntityPicking(context)
#define MACRO_EntityPicking(context)
#define MACRO_LODActivated(context)
static const GLubyte s_byte1
static const GLubyte s_stippleMask[4 *32]
static const GLubyte s_byte0
static bool s_vertIndexesInitialized
static unsigned s_vertWireIndexes[ccChunk::SIZE *6]
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
bool LessThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).
constexpr Rgbaf light(0.66f, 0.66f, 0.66f, 1.00f)
constexpr Rgbaf bright(1.00f, 1.00f, 1.00f, 1.00f)
constexpr Rgb lightGrey(static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8))
constexpr Rgbaf darker(0.17f, 0.17f, 0.17f, 1.00f)
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)
Display parameters of a 3D entity.
bool showColors
Display colors.
bool showNorms
Display normals.
bool showSF
Display scalar field (prioritary on colors)