36 #ifndef GEOTESSGRID_OBJECT_H
37 #define GEOTESSGRID_OBJECT_H
250 vertices(NULL), nVertices(0),
251 triangles(NULL), nTriangles(0),
252 levels(NULL), nLevels(0),
253 tessellations(NULL), nTessellations(0),
254 descendants(NULL), gridID(gid),
255 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
256 gridGenerationDate(
""), refCount(0)
288 vector<vector<Edge*> > edgeList;
302 mutable vector<vector<Edge*> > spokeList;
310 mutable vector<double*> circumCenters;
325 string gridInputFile;
330 string gridOutputFile;
335 string gridSoftwareVersion;
341 string gridGenerationDate;
352 vector< vector< vector<int> > > vtxTriangles;
359 mutable vector< set<int> > connectedVertices;
364 GeoTessGrid* loadGridAscii(
const string& inputFile);
375 GeoTessGrid* loadGridBinary(
const string& inputFile);
382 static void loadGridAsciiFront(
IFStreamAscii& input,
int& gridFileFormat,
383 string& gridSWVersion,
string& fileCreationDate,
384 string& gridid,
const string& grdInptFile);
386 static void loadGridBinaryFront(
IFStreamBinary& ifs,
int& gridFileFormat,
387 string& gridSWVersion,
string& fileCreationDate,
388 string& gridid,
const string& grdInptFile);
404 const set<int>& getVertexIndices(
const int& level);
406 void computeSpokeLists(
const int& level)
const;
416 vertices(NULL), nVertices(0),
417 triangles(NULL), nTriangles(0),
418 levels(NULL), nLevels(0),
419 tessellations(NULL), nTessellations(0),
420 descendants(NULL), gridID(
""),
421 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
422 gridGenerationDate(
""), refCount(0)
430 vertices(NULL), nVertices(0),
431 triangles(NULL), nTriangles(0),
432 levels(NULL), nLevels(0),
433 tessellations(NULL), nTessellations(0),
434 descendants(NULL), gridID(
""),
435 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
436 gridGenerationDate(
""), refCount(0)
465 static string getGridID(
const string& fileName);
473 static bool isGeoTessGrid(
const string& inputFile);
481 {
return (gridID == g.gridID); }
489 {
return !(*
this == g); }
501 const string& getGridID()
const
573 const double* getVertex(
int vertex)
const
575 return vertices[vertex];
586 int findClosestVertex(
double* unit_vector,
int tessId)
588 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), unit_vector)];
591 double dot = GeoTessUtils::dot(unit_vector, vertices[t[0]]);
593 double doti = GeoTessUtils::dot(unit_vector, vertices[t[1]]);
600 doti = GeoTessUtils::dot(unit_vector, vertices[t[2]]);
618 int getVertexIndex(
int triangle,
int corner)
const
619 {
return triangles[triangle][corner]; }
636 int getVertexIndex(
int tessId,
int level,
int triangle,
int corner)
const
638 return triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner];
647 int getVertexIndex(
const double* u)
649 for (
int i=nTessellations-1; i>=0; --i)
651 int vid = getVertexIndex(u, i);
666 int getVertexIndex(
const double* u,
int tessId)
668 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), u)];
670 if (GeoTessUtils::dot(u, vertices[t[0]]) > cos(1e-7))
672 if (GeoTessUtils::dot(u, vertices[t[1]]) > cos(1e-7))
674 if (GeoTessUtils::dot(u, vertices[t[2]]) > cos(1e-7))
690 double* getVertex(
int tessId,
int level,
int triangle,
int corner)
692 return vertices[triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner]];
714 void getVerticesTopLevel(
const int& tessellation, set<const double*>& vectors)
716 getVertices(tessellation, getNLevels(tessellation)-1, vectors);
728 void getVertices(
const int& tessellation,
const int& level, set<const double*>& vectors);
742 const set<int>& getVertexIndices(
const int& tessId,
const int& level)
756 const set<int>& getVertexIndicesTopLevel(
const int& tessId)
757 {
return getVertexIndices(tessellations[tessId][1] - 1); }
778 int getNLevels(
int tessellation)
const
779 {
return tessellations[tessellation][1] - tessellations[tessellation][0]; }
789 int getLevel(
int tessellation,
int i)
const
790 {
return tessellations[tessellation][0] + i; }
807 int getLastLevel(
int tessellation)
const
808 {
return tessellations[tessellation][1] - 1; }
824 int getTopLevel(
int tessellation)
const
825 {
return tessellations[tessellation][1] - tessellations[tessellation][0] - 1; }
836 int getNTriangles(
int tessellation,
int level)
const
838 return levels[tessellations[tessellation][0] + level][1]
839 - levels[tessellations[tessellation][0] + level][0];
853 int getTriangle(
int tessellation,
int level,
int i)
const
854 {
return levels[tessellations[tessellation][0] + level][0] + i; }
865 int getFirstTriangle(
int tessellation,
int level)
const
866 {
return levels[tessellations[tessellation][0] + level][0]; }
877 int getLastTriangle(
int tessellation,
int level)
const
878 {
return levels[tessellations[tessellation][0] + level][1]-1; }
902 const int* getTriangleVertexIndexes(
int triangleIndex)
const
903 {
return triangles[triangleIndex]; }
916 int getTriangleVertexIndex(
int triangleIndex,
int cornerIndex)
const
917 {
return triangles[triangleIndex][cornerIndex]; }
930 const double* getTriangleVertex(
int triangleIndex,
int cornerIndex)
const
931 {
return vertices[triangles[triangleIndex][cornerIndex]]; }
942 void getTriangleVertices(
int triangle,
double** triVrt)
944 int* corners = triangles[triangle];
945 triVrt[0][0] = vertices[corners[0]][0];
946 triVrt[0][1] = vertices[corners[0]][1];
947 triVrt[0][2] = vertices[corners[0]][2];
948 triVrt[1][0] = vertices[corners[1]][0];
949 triVrt[1][1] = vertices[corners[1]][1];
950 triVrt[1][2] = vertices[corners[1]][2];
951 triVrt[2][0] = vertices[corners[2]][0];
952 triVrt[2][1] = vertices[corners[2]][1];
953 triVrt[2][2] = vertices[corners[2]][2];
960 const void computeCircumCenters()
962 if (circumCenters.empty()) circumCenters.resize(nTriangles, NULL);
964 for (
int triangle=0; triangle<nTriangles; ++triangle)
965 if (circumCenters[triangle] == NULL)
967 int* corners = triangles[triangle];
968 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
969 vertices[corners[1]], vertices[corners[2]]);
977 const void computeCircumCenters(
const int& level)
979 if (circumCenters.empty()) circumCenters.resize(nTriangles);
981 if (circumCenters[levels[level][0]] == NULL)
983 for (
int triangle=levels[level][0]; triangle<levels[level][1]; ++triangle)
985 int* corners = triangles[triangle];
986 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
987 vertices[corners[1]], vertices[corners[2]]);
1007 const double*
getCircumCenter(
const int& triangle)
const {
return circumCenters[triangle]; }
1026 void getCircumCenter(
const int& triangle,
double* cc)
const
1027 { cc[0]=circumCenters[triangle][0]; cc[1]=circumCenters[triangle][1]; cc[2]=circumCenters[triangle][2]; }
1043 int getNeighbor(
const int& triangleIndex,
const int& neighborIndex)
const
1044 {
return neighborIndex == 3 ? descendants[triangleIndex] : edgeList[triangleIndex][neighborIndex]->tLeft; }
1070 int getNeighbor(
const int& tessellation,
const int& level,
const int& triangle,
const int& side)
1071 {
return getNeighbor(getTriangle(tessellation, level, triangle), side); }
1087 void getNeighbors(
int triangleIndex, vector<int>& neighbors)
1090 vector<Edge*> edges = edgeList[triangleIndex];
1091 neighbors.push_back(edges[0]->tLeft);
1092 neighbors.push_back(edges[1]->tLeft);
1093 neighbors.push_back(edges[2]->tLeft);
1094 neighbors.push_back(descendants[triangleIndex]);
1119 void getNeighbors(
const int& tessellation,
const int& level,
const int& triangle, vector<int>& neighbors)
1120 {
getNeighbors(getTriangle(tessellation, level, triangle), neighbors); }
1135 int getNeighborIndex(
const int& tid,
const int& nid)
1137 if (edgeList[tid][0]->tLeft == nid)
1139 if (edgeList[tid][1]->tLeft == nid)
1141 if (edgeList[tid][2]->tLeft == nid)
1150 int getDescendant(
const int& tessId,
const int& level,
const int& triangle)
const
1151 {
return descendants[getTriangle(tessId, level, triangle)]; }
1165 int getTriangle(
int triangleIndex,
const double* vector);
1188 const vector<int>& getVertexTriangles(
const int& tessId,
const int& level,
const int& vertex)
const
1189 {
return vtxTriangles[tessellations[tessId][0] + level][vertex]; }
1204 const vector<int>& getVertexTriangles(
int tessId,
int vertex)
const
1224 void getVertexNeighborsOrdered(
const int& tessId,
const int& level,
const int& vertex, vector<int>& v);
1237 void getVertexNeighbors(
const int& tessId,
const int& level,
const int& vertex, set<int>& nbrs)
1257 void getVertexNeighbors(
const int& tessId,
const int& level,
const int& vertex,
1258 const int& order, set<int>& nbrs);
1270 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1271 descendants(NULL), gridID(
""),
1272 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1273 gridGenerationDate(
""), refCount(0)
1274 { loadGridAscii(input); }
1279 GeoTessGrid(IFStreamBinary& input,
const GeoTessOptimizationType* opttype) :
1280 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1281 descendants(NULL), gridID(
""),
1282 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1283 gridGenerationDate(
""), refCount(0)
1284 { loadGridBinary(input); }
1289 GeoTessGrid(
double** _vertices,
int& _nVertices,
1290 int** _triangles,
int& _nTriangles,
1291 int** _levels,
int& _nLevels,
1292 int** _tessellations,
int& _nTessellations,
1294 string& _gridInputFile,
1295 string& _gridOutputFile,
1296 string& _gridSoftwareVersion,
1297 string& _gridGenerationDate,
1298 const GeoTessOptimizationType* _opttype) :
1299 vertices(_vertices), nVertices(_nVertices),
1300 triangles(_triangles), nTriangles(_nTriangles),
1301 levels(_levels), nLevels(_nLevels),
1302 tessellations(_tessellations), nTessellations(_nTessellations),
1305 gridInputFile(_gridInputFile),
1306 gridOutputFile(_gridOutputFile),
1307 gridSoftwareVersion(_gridSoftwareVersion),
1308 gridGenerationDate(_gridGenerationDate),
1315 virtual ~GeoTessGrid();
1320 int getReferenceCount() {
return refCount; }
1325 void addReference() { ++refCount; }
1330 void removeReference()
1332 if (isNotReferenced())
1335 os << endl <<
"ERROR in GeoTessGrid::removeReference" << endl
1336 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1337 throw GeoTessException(os, __FILE__, __LINE__, 2001);
1346 bool isNotReferenced() {
return (refCount == 0); }
1353 void writeGrid(
const string& fileName);
1358 void writeGridAscii(
const string& fileName);
1363 void writeGridAscii(IFStreamAscii& output);
1368 void writeGridBinary(
const string& fileName);
1373 void writeGridBinary(IFStreamBinary& output);
1380 bool isSupportedFormatVersion(
int frmtVrsn)
1381 {
return (frmtVrsn == 2); }
1440 vector<Edge*>& getSpokeList(
const int& level)
const
1441 { computeSpokeLists(level);
return spokeList[level]; }
1443 const vector<vector<Edge*> >&
getEdgeList()
const {
return edgeList; }
1445 const vector<Edge*>&
getEdgeList(
const int& triangle)
const {
return edgeList[triangle]; }
1453 void getCenter(
const int& triangle,
double* center)
1455 vector<double*> corners;
1456 corners.push_back(vertices[triangles[triangle][0]]);
1457 corners.push_back(vertices[triangles[triangle][1]]);
1458 corners.push_back(vertices[triangles[triangle][2]]);
1459 GeoTessUtils::center(corners, center);
1474 #endif // GEOTESSGRID_OBJECT_H