-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjeto.cpp
More file actions
239 lines (192 loc) · 5.02 KB
/
Copy pathObjeto.cpp
File metadata and controls
239 lines (192 loc) · 5.02 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "Objeto.h"
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
Objeto::Objeto(int indice, string nombre, vector<Punto *> vertices, vector<Linea *> aristas, vector<Plano *> caras, Grafo <Punto* > grafo){
this->indice=indice;
this->nombre=nombre;
this->vertices=vertices;
this->aristas=aristas;
this->caras=caras;
this->arbolPuntos = nullptr;
this->envolvente=NULL;
this->grafo= grafo;
}
Objeto::~Objeto(){
Plano* plano_temporal;
for(int i=0; i< caras.size(); i++){
plano_temporal=caras[i];
delete plano_temporal;
}
caras.clear();
Linea* linea_temporal;
for(int i=0; i<aristas.size(); i++){
linea_temporal=aristas[i];
delete linea_temporal;
}
aristas.clear();
Punto* punto_temporal;
for(int i=0; i<vertices.size(); i++){
punto_temporal=vertices[i];
delete punto_temporal;
}
vertices.clear();
delete arbolPuntos;
}
int Objeto::get_indice(){
return indice;
}
string Objeto::get_nombre(){
return nombre;
}
vector<Punto *> Objeto::get_vertices(){
return vertices;
}
Punto* Objeto::get_vertices(int indice){
return vertices[indice];
}
vector<Linea *> Objeto::get_aristas(){
return aristas;
}
Linea* Objeto::get_aristas(int indice){
return aristas[indice];
}
vector<Plano *> Objeto::get_caras(){
return caras;
}
Plano* Objeto::get_caras(int indice){
return caras[indice];
}
ArbolKD3d<Punto*> *Objeto::get_arbolPuntos(){
return this->arbolPuntos;
}
void Objeto::set_arbolPuntos(ArbolKD3d<Punto*> *arbol){
this->arbolPuntos=arbol;
}
Objeto* Objeto::get_envolvente(){
return envolvente;
}
void Objeto::set_envolvente(Objeto* envolvente){
this->envolvente=envolvente;
}
Grafo<Punto *> Objeto::get_grafo(){
return grafo;
}
void Objeto::set_grafo(Grafo <Punto *> grafo){
this->grafo=grafo;
}
void Objeto::anadir_vertice(Punto * vertice){
vertices.push_back(vertice);
grafo.insertarVertice(vertice);
arbolPuntos->insertar(vertice);
}
void Objeto::anadir_arista(Punto * v1, Punto * v2 ){
Linea* arista = new Linea(aristas.size(), v1, v2);
aristas.push_back(arista);
grafo.insAristaNoDir(v1, v2, arista->get_distancia());
}
double Objeto::calcular_minimo(char coordenada){
double minimo=0;
switch (coordenada)
{
case 'x':
minimo= vertices[0]->get_x();
for(int i=1; i<vertices.size(); i++){
if(vertices[i]->get_x()<minimo)
minimo=vertices[i]->get_x();
}
break;
case 'y':
minimo= vertices[0]->get_y();
for(int i=1; i<vertices.size(); i++){
if(vertices[i]->get_y()<minimo)
minimo=vertices[i]->get_y();
}
break;
case 'z':
minimo= vertices[0]->get_z();
for(int i=1; i<vertices.size(); i++){
if(vertices[i]->get_z()<minimo)
minimo=vertices[i]->get_z();
}
break;
default:
break;
}
return minimo;
}
double Objeto::calcular_maximo(char coordenada){
double maximo=0;
switch (coordenada)
{
case 'x':
maximo= vertices[0]->get_x();
for(int i=1; i<vertices.size(); i++){
if(vertices[i]->get_x()>maximo)
maximo=vertices[i]->get_x();
}
break;
case 'y':
maximo= vertices[0]->get_y();
for(int i=1; i<vertices.size(); i++){
if(vertices[i]->get_y()>maximo)
maximo=vertices[i]->get_y();
}
break;
case 'z':
maximo= vertices[0]->get_z();
for(int i=1; i<vertices.size(); i++){
if(vertices[i]->get_z()>maximo)
maximo=vertices[i]->get_z();
}
break;
default:
break;
}
return maximo;
}
double Objeto::calcula_centroide(char coordenada){
double centroide=0;
switch (coordenada)
{
case 'x':
for(int i=0; i<vertices.size(); i++){
centroide += vertices[i]->get_x();
}
break;
case 'y':
for(int i=0; i<vertices.size(); i++){
centroide += vertices[i]->get_y();
}
break;
case 'z':
for(int i=0; i<vertices.size(); i++){
centroide += vertices[i]->get_z();
}
break;
default:
break;
}
return centroide/vertices.size();
}
Punto* Objeto::vertice_cercano(double px, double py, double pz){
Punto* verticeCercano;
Punto* dato= new Punto(-1,-1, px,py,pz);
verticeCercano= this->arbolPuntos->buscarNodoInsercion(dato);
delete dato;
return verticeCercano;
}
string Objeto::to_string(){
string cadena="";
cadena+= nombre + " contiene:\t "+ std::to_string(vertices.size()) + " vertices, " + std::to_string(aristas.size()) + " aristas, " +
std::to_string(caras.size()) + " caras.\n";
return cadena;
}
bool Objeto::equals(Objeto objeto){
bool respuesta=false;
if(this->indice==objeto.indice)
respuesta=true;
return true;
}