File: ccBox.cpp

package info (click to toggle)
cloudcompare 2.10.1-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 55,916 kB
  • sloc: cpp: 219,837; ansic: 29,944; makefile: 67; sh: 45
file content (116 lines) | stat: -rw-r--r-- 3,870 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//##########################################################################
//#                                                                        #
//#                              CLOUDCOMPARE                              #
//#                                                                        #
//#  This program is free software; you can redistribute it and/or modify  #
//#  it under the terms of the GNU General Public License as published by  #
//#  the Free Software Foundation; version 2 or later of the License.      #
//#                                                                        #
//#  This program is distributed in the hope that it will be useful,       #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
//#  GNU General Public License for more details.                          #
//#                                                                        #
//#          COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI)             #
//#                                                                        #
//##########################################################################

#include "ccBox.h"

//qCC_db
#include "ccPlane.h"
#include "ccPointCloud.h"

ccBox::ccBox(	const CCVector3& dims,
				const ccGLMatrix* transMat/*= 0*/,
				QString name/*=QString("Box")*/)
	: ccGenericPrimitive(name, transMat)
	, m_dims(dims)
{
	updateRepresentation();
}

ccBox::ccBox(QString name/*=QString("Box")*/)
	: ccGenericPrimitive(name)
	, m_dims(0, 0, 0)
{
}

bool ccBox::buildUp()
{
	//clear triangles indexes
	if (m_triVertIndexes)
	{
		m_triVertIndexes->clear();
	}
	//clear per triangle normals
	removePerTriangleNormalIndexes();
	if (m_triNormals)
	{
		m_triNormals->clear();
	}
	//clear vertices
	ccPointCloud* verts = vertices();
	if (verts)
	{
		verts->clear();
	}

	//upper plane
	ccGLMatrix upperMat;
	upperMat.getTranslation()[2] = m_dims.z / 2;
	*this += ccPlane(m_dims.x, m_dims.y, &upperMat);
	//lower plane
	ccGLMatrix lowerMat;
	lowerMat.initFromParameters(-static_cast<PointCoordinateType>(M_PI), CCVector3(1, 0, 0), CCVector3(0, 0, -m_dims.z / 2));
	*this += ccPlane(m_dims.x, m_dims.y, &lowerMat);
	//left plane
	ccGLMatrix leftMat;
	leftMat.initFromParameters(-static_cast<PointCoordinateType>(M_PI / 2), CCVector3(0, 1, 0), CCVector3(-m_dims.x / 2, 0, 0));
	*this += ccPlane(m_dims.z, m_dims.y, &leftMat);
	//right plane
	ccGLMatrix rightMat;
	rightMat.initFromParameters(static_cast<PointCoordinateType>(M_PI / 2), CCVector3(0, 1, 0), CCVector3(m_dims.x / 2, 0, 0));
	*this += ccPlane(m_dims.z, m_dims.y, &rightMat);
	//front plane
	ccGLMatrix frontMat;
	frontMat.initFromParameters(static_cast<PointCoordinateType>(M_PI / 2), CCVector3(1, 0, 0), CCVector3(0, -m_dims.y / 2, 0));
	*this += ccPlane(m_dims.x, m_dims.z, &frontMat);
	//back plane
	ccGLMatrix backMat;
	backMat.initFromParameters(-static_cast<PointCoordinateType>(M_PI / 2), CCVector3(1, 0, 0), CCVector3(0, m_dims.y / 2, 0));
	*this += ccPlane(m_dims.x, m_dims.z, &backMat);

	return (vertices() && vertices()->size() == 24 && this->size() == 12);
}

ccGenericPrimitive* ccBox::clone() const
{
	return finishCloneJob(new ccBox(m_dims, &m_transformation, getName()));
}

bool ccBox::toFile_MeOnly(QFile& out) const
{
	if (!ccGenericPrimitive::toFile_MeOnly(out))
		return false;

	//parameters (dataVersion>=21)
	QDataStream outStream(&out);
	outStream << m_dims.x;
	outStream << m_dims.y;
	outStream << m_dims.z;

	return true;
}

bool ccBox::fromFile_MeOnly(QFile& in, short dataVersion, int flags)
{
	if (!ccGenericPrimitive::fromFile_MeOnly(in, dataVersion, flags))
		return false;

	//parameters (dataVersion>=21)
	QDataStream inStream(&in);
	ccSerializationHelper::CoordsFromDataStream(inStream, flags, m_dims.u, 3);

	return true;
}