ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvBox.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "ecvBox.h"
9 
10 // CV_DB_LIB
11 #include "ecvPlane.h"
12 #include "ecvPointCloud.h"
13 
14 ccBox::ccBox(const CCVector3& dims,
15  const ccGLMatrix* transMat /*= 0*/,
16  QString name /*=QString("Box")*/)
17  : ccGenericPrimitive(name, transMat), m_dims(dims) {
19 }
20 
21 ccBox::ccBox(QString name /*=QString("Box")*/)
22  : ccGenericPrimitive(name), m_dims(0, 0, 0) {}
23 
25  // clear triangles indexes
26  if (m_triVertIndexes) {
28  }
29  // clear per triangle normals
31  if (m_triNormals) {
33  }
34  // clear vertices
35  ccPointCloud* verts = vertices();
36  if (verts) {
37  verts->clear();
38  }
39 
40  // upper plane
41  ccGLMatrix upperMat;
42  upperMat.getTranslation()[2] = m_dims.z / 2;
43  *this += ccPlane(m_dims.x, m_dims.y, &upperMat);
44  // lower plane
45  ccGLMatrix lowerMat;
46  lowerMat.initFromParameters(-static_cast<PointCoordinateType>(M_PI),
47  CCVector3(1, 0, 0),
48  CCVector3(0, 0, -m_dims.z / 2));
49  *this += ccPlane(m_dims.x, m_dims.y, &lowerMat);
50  // left plane
51  ccGLMatrix leftMat;
52  leftMat.initFromParameters(-static_cast<PointCoordinateType>(M_PI / 2),
53  CCVector3(0, 1, 0),
54  CCVector3(-m_dims.x / 2, 0, 0));
55  *this += ccPlane(m_dims.z, m_dims.y, &leftMat);
56  // right plane
57  ccGLMatrix rightMat;
58  rightMat.initFromParameters(static_cast<PointCoordinateType>(M_PI / 2),
59  CCVector3(0, 1, 0),
60  CCVector3(m_dims.x / 2, 0, 0));
61  *this += ccPlane(m_dims.z, m_dims.y, &rightMat);
62  // front plane
63  ccGLMatrix frontMat;
64  frontMat.initFromParameters(static_cast<PointCoordinateType>(M_PI / 2),
65  CCVector3(1, 0, 0),
66  CCVector3(0, -m_dims.y / 2, 0));
67  *this += ccPlane(m_dims.x, m_dims.z, &frontMat);
68  // back plane
69  ccGLMatrix backMat;
70  backMat.initFromParameters(-static_cast<PointCoordinateType>(M_PI / 2),
71  CCVector3(1, 0, 0),
72  CCVector3(0, m_dims.y / 2, 0));
73  *this += ccPlane(m_dims.x, m_dims.z, &backMat);
74 
75  return (vertices() && vertices()->size() == 24 && this->size() == 12);
76 }
77 
80 }
81 
82 bool ccBox::toFile_MeOnly(QFile& out, short dataVersion) const {
83  assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
84  if (dataVersion < 21) {
85  assert(false);
86  return false;
87  }
88 
89  if (!ccGenericPrimitive::toFile_MeOnly(out, dataVersion)) return false;
90 
91  // parameters (dataVersion>=21)
92  QDataStream outStream(&out);
93  outStream << m_dims.x;
94  outStream << m_dims.y;
95  outStream << m_dims.z;
96 
97  return true;
98 }
99 
101  return std::max(static_cast<short>(21),
103 }
104 
105 bool ccBox::fromFile_MeOnly(QFile& in,
106  short dataVersion,
107  int flags,
108  LoadedIDMap& oldToNewIDMap) {
109  if (!ccGenericPrimitive::fromFile_MeOnly(in, dataVersion, flags,
110  oldToNewIDMap))
111  return false;
112 
113  // parameters (dataVersion>=21)
114  QDataStream inStream(&in);
116 
117  return true;
118 }
constexpr double M_PI
Pi.
Definition: CVConst.h:19
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
Definition: CVGeom.h:798
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
std::string name
Type y
Definition: CVGeom.h:137
Type u[3]
Definition: CVGeom.h:139
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
void clear(bool releaseMemory=false)
Definition: ecvArray.h:115
ccBox(const CCVector3 &dims, const ccGLMatrix *transMat=nullptr, QString name=QString("Box"))
Default constructor.
Definition: ecvBox.cpp:14
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
Definition: ecvBox.cpp:105
CCVector3 m_dims
Box dimensions.
Definition: ecvBox.h:60
short minimumFileVersion_MeOnly() const override
Definition: ecvBox.cpp:100
virtual bool buildUp() override
Builds primitive.
Definition: ecvBox.cpp:24
virtual ccGenericPrimitive * clone() const override
Clones primitive.
Definition: ecvBox.cpp:78
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
Definition: ecvBox.cpp:82
T * getTranslation()
Retruns a pointer to internal translation.
void initFromParameters(T alpha_rad, const Vector3Tpl< T > &axis3D, const Vector3Tpl< T > &t3D)
Inits transformation from a rotation axis, an angle and a translation.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Generic primitive interface.
virtual bool updateRepresentation()
Updates internal representation (as a mesh)
ccGenericPrimitive * finishCloneJob(ccGenericPrimitive *primitive) const
Finished 'clone' job (vertices color, etc.)
ccPointCloud * vertices()
Returns vertices.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
ccGLMatrix m_transformation
Associated transformation (applied to vertices)
short minimumFileVersion_MeOnly() const override
void removePerTriangleNormalIndexes()
Removes any per-triangle triplets of normal indexes.
Definition: ecvMesh.cpp:3323
virtual unsigned size() const override
Returns the number of triangles.
Definition: ecvMesh.cpp:2143
NormsIndexesTableType * m_triNormals
Per-triangle normals.
Definition: ecvMesh.h:1493
triangleIndexesContainer * m_triVertIndexes
Triangles' vertices indexes (3 per triangle)
Definition: ecvMesh.h:1502
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
Plane (primitive)
Definition: ecvPlane.h:18
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void clear() override
Clears the entity from all its points and features.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
static void CoordsFromDataStream(QDataStream &stream, int flags, PointCoordinateType *out, unsigned count=1)