-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeoSphere.cpp
More file actions
98 lines (70 loc) · 2.52 KB
/
GeoSphere.cpp
File metadata and controls
98 lines (70 loc) · 2.52 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
/*
* File: GeoSphere.cpp
* Author: zoizoi
*
* Created on 17 December 2010, 23:17
*/
#include "GeoSphere.h"
GeoSphere::GeoSphere() {
}
GeoSphere::GeoSphere(const GeoSphere& orig) {
}
GeoSphere::~GeoSphere() {
}
bool GeoSphere::loadGeoSphereFile(string filename){
cout<<"loading sphere file "<<filename<<endl;
ifstream inf;
inf.open(filename.c_str());
if(!inf.is_open()){
cout<<"cant load file "<<filename<<endl;
return false;
}
inf >> this->n_vertices >> this->n_faces >> this->n_edges;
vertices = new float[n_vertices * 3];
faces = new int[n_faces * 3];
for (int i = 0; i < n_vertices; i++) {
inf >> vertices[3 * i] >> vertices[3 * i + 1] >> vertices[3 * i + 2];
}
for (int i = 0; i < n_faces; i++) {
inf >> faces[3 * i] >> faces[3 * i + 1] >> faces[3 * i + 2];
}
views = new GeoPoint*[n_vertices];
GeoPoint** extdNbrs = new GeoPoint*[n_vertices];
//extend to second-order neighbours
//for each vertex
for (int i = 0; i < n_vertices; i++) {
views[i] = new GeoPoint(i,vertices[3 * i],vertices[3 * i+1],vertices[3 * i+2]);
extdNbrs[i] = new GeoPoint(i,vertices[3 * i],vertices[3 * i+1],vertices[3 * i+2]);
//TD convert to use vtk cells?
//and for each face add neighbours to geopoint for that vertex
for (int j = 0; j < n_faces - 1; j++) {
if (faces[3 * j] == i) {
views[i]->addNeighbour(faces[3 * j + 1]);
views[i]->addNeighbour(faces[3 * j + 2]);
}
if (faces[3 * j + 1] == i) {
views[i]->addNeighbour(faces[3 * j]);
views[i]->addNeighbour(faces[3 * j + 2]);
}
if (faces[3 * j + 2] == i) {
views[i]->addNeighbour(faces[3 * j]);
views[i]->addNeighbour(faces[3 * j + 1]);
}
}
}
for (int i = 0; i < n_vertices; i++) {
for (int i2 = 0; i2 < views[i]->neighbourCount; i2++) {
extdNbrs[i]->addNeighbour(views[i]->neighbours[i2]);
int neib1 = views[i]->neighbours[i2];
for (int i3 = 0; i3 < views[neib1]->neighbourCount; i3++) {
extdNbrs[i]->addNeighbour(views[neib1]->neighbours[i3]);
}
}
}
//delete []views;
views = extdNbrs;
cout<<"created Geophere with nv:"<<n_vertices<<endl;
}
void GeoSphere::outputInfo(){
cout<<"Info "<<n_vertices<<" "<<n_edges<<" "<<n_faces<<endl;
}