36 #ifndef GEOTESSGRID_OBJECT_H
37 #define GEOTESSGRID_OBJECT_H
242 vertices(NULL), nVertices(0),
243 triangles(NULL), nTriangles(0),
244 levels(NULL), nLevels(0),
245 tessellations(NULL), nTessellations(0),
246 descendants(NULL), gridID(gid),
247 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
248 gridGenerationDate(
""), refCount(0)
280 vector<vector<Edge*> > edgeList;
294 mutable vector<vector<Edge*> > spokeList;
302 mutable vector<double*> circumCenters;
317 string gridInputFile;
322 string gridOutputFile;
327 string gridSoftwareVersion;
333 string gridGenerationDate;
344 vector< vector< vector<int> > > vtxTriangles;
351 mutable vector< set<int> > connectedVertices;
356 GeoTessGrid* loadGridAscii(
const string& inputFile);
367 GeoTessGrid* loadGridBinary(
const string& inputFile);
374 static void loadGridAsciiFront(
IFStreamAscii& input,
int& gridFileFormat,
375 string& gridSWVersion,
string& fileCreationDate,
376 string& gridid,
const string& grdInptFile);
378 static void loadGridBinaryFront(
IFStreamBinary& ifs,
int& gridFileFormat,
379 string& gridSWVersion,
string& fileCreationDate,
380 string& gridid,
const string& grdInptFile);
396 const set<int>& getVertexIndices(
const int& level);
398 void computeSpokeLists(
const int& level)
const;
408 vertices(NULL), nVertices(0),
409 triangles(NULL), nTriangles(0),
410 levels(NULL), nLevels(0),
411 tessellations(NULL), nTessellations(0),
412 descendants(NULL), gridID(
""),
413 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
414 gridGenerationDate(
""), refCount(0)
421 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
422 descendants(NULL), gridID(
""),
423 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
424 gridGenerationDate(
""), refCount(0)
425 { loadGridAscii(input); }
431 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
432 descendants(NULL), gridID(
""),
433 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
434 gridGenerationDate(
""), refCount(0)
435 { loadGridBinary(input); }
459 memory += nVertices * (
LONG_INT)
sizeof(
double*) + nVertices * 3 * (
LONG_INT)
sizeof(
double);
462 memory += nTriangles * (
LONG_INT)
sizeof(
int*) + nTriangles * 3 * (
LONG_INT)
sizeof(
int);
465 memory += nLevels * (
LONG_INT)
sizeof(
int*) + nLevels * 2 * (
LONG_INT)
sizeof(
int);
468 memory += nTessellations * (
LONG_INT)
sizeof(
int*) + nTessellations * 2 * (
LONG_INT)
sizeof(
int);
471 memory += nTriangles * (
LONG_INT)
sizeof(
int);
474 memory += (
LONG_INT) (edgeList.capacity() *
sizeof(vector<Edge*>)
475 + edgeList.size() * 3 * (
sizeof(
Edge*) +
sizeof(
Edge)));
478 memory += (
LONG_INT) (spokeList.capacity() *
sizeof(vector<Edge*>)
479 + spokeList.size() * 3 *
sizeof(
Edge*));
482 memory += (
LONG_INT) (circumCenters.capacity() *
sizeof(
double*));
483 for (
int i=0; i<(int)circumCenters.size(); ++i)
484 if (circumCenters[i]) memory += 3 * (
LONG_INT)
sizeof(
double);
489 memory += (
LONG_INT) (vtxTriangles.capacity() *
sizeof(vector< vector<int> >));
490 for (
int i=0; i<(int)vtxTriangles.size(); ++i)
492 memory += (
LONG_INT) (vtxTriangles[i].capacity() *
sizeof(vector<int>));
493 for (
int j=0; j<(int)vtxTriangles[i].size(); ++j)
494 memory += (
LONG_INT) (vtxTriangles[i][j].capacity() *
sizeof(int));
501 memory += (
LONG_INT) (connectedVertices.capacity() *
sizeof(set<int>));
502 for (
int i=0; i<(int)connectedVertices.size(); ++i)
503 memory += (
LONG_INT) (connectedVertices[i].size() *
sizeof(int));
506 memory += (
LONG_INT) (gridID.length() + gridInputFile.length() + gridOutputFile.length()
507 + gridSoftwareVersion.length() + gridGenerationDate.length());
525 static string getGridID(
const string& fileName);
533 static bool isGeoTessGrid(
const string& inputFile);
541 {
return (gridID == g.gridID); }
549 {
return !(*
this == g); }
561 const string& getGridID()
const
627 const double* getVertex(
int vertex)
const
629 return vertices[vertex];
640 int findClosestVertex(
double* unit_vector,
int tessId)
642 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), unit_vector)];
645 double dot = GeoTessUtils::dot(unit_vector, vertices[t[0]]);
647 double doti = GeoTessUtils::dot(unit_vector, vertices[t[1]]);
654 doti = GeoTessUtils::dot(unit_vector, vertices[t[2]]);
672 int getVertexIndex(
int triangle,
int corner)
const
673 {
return triangles[triangle][corner]; }
690 int getVertexIndex(
int tessId,
int level,
int triangle,
int corner)
const
692 return triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner];
701 int getVertexIndex(
const double* u)
703 for (
int i=nTessellations-1; i>=0; --i)
705 int vid = getVertexIndex(u, i);
720 int getVertexIndex(
const double* u,
int tessId)
722 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), u)];
724 if (GeoTessUtils::dot(u, vertices[t[0]]) > cos(1e-7))
726 if (GeoTessUtils::dot(u, vertices[t[1]]) > cos(1e-7))
728 if (GeoTessUtils::dot(u, vertices[t[2]]) > cos(1e-7))
744 double* getVertex(
int tessId,
int level,
int triangle,
int corner)
746 return vertices[triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner]];
768 void getVerticesTopLevel(
const int& tessellation, set<const double*>& vectors)
770 getVertices(tessellation, getNLevels(tessellation)-1, vectors);
782 void getVertices(
const int& tessellation,
const int& level, set<const double*>& vectors);
796 const set<int>& getVertexIndices(
const int& tessId,
const int& level)
810 const set<int>& getVertexIndicesTopLevel(
const int& tessId)
811 {
return getVertexIndices(tessellations[tessId][1] - 1); }
832 int getNLevels(
int tessellation)
const
833 {
return tessellations[tessellation][1] - tessellations[tessellation][0]; }
843 int getLevel(
int tessellation,
int i)
const
844 {
return tessellations[tessellation][0] + i; }
861 int getLastLevel(
int tessellation)
const
862 {
return tessellations[tessellation][1] - 1; }
878 int getTopLevel(
int tessellation)
const
879 {
return tessellations[tessellation][1] - tessellations[tessellation][0] - 1; }
890 int getNTriangles(
int tessellation,
int level)
const
892 return levels[tessellations[tessellation][0] + level][1]
893 - levels[tessellations[tessellation][0] + level][0];
907 int getTriangle(
int tessellation,
int level,
int i)
const
908 {
return levels[tessellations[tessellation][0] + level][0] + i; }
919 int getFirstTriangle(
int tessellation,
int level)
const
920 {
return levels[tessellations[tessellation][0] + level][0]; }
931 int getLastTriangle(
int tessellation,
int level)
const
932 {
return levels[tessellations[tessellation][0] + level][1]-1; }
956 const int* getTriangleVertexIndexes(
int triangleIndex)
const
957 {
return triangles[triangleIndex]; }
970 int getTriangleVertexIndex(
int triangleIndex,
int cornerIndex)
const
971 {
return triangles[triangleIndex][cornerIndex]; }
984 const double* getTriangleVertex(
int triangleIndex,
int cornerIndex)
const
985 {
return vertices[triangles[triangleIndex][cornerIndex]]; }
996 void getTriangleVertices(
int triangle,
double** triVrt)
998 int* corners = triangles[triangle];
999 triVrt[0][0] = vertices[corners[0]][0];
1000 triVrt[0][1] = vertices[corners[0]][1];
1001 triVrt[0][2] = vertices[corners[0]][2];
1002 triVrt[1][0] = vertices[corners[1]][0];
1003 triVrt[1][1] = vertices[corners[1]][1];
1004 triVrt[1][2] = vertices[corners[1]][2];
1005 triVrt[2][0] = vertices[corners[2]][0];
1006 triVrt[2][1] = vertices[corners[2]][1];
1007 triVrt[2][2] = vertices[corners[2]][2];
1014 const void computeCircumCenters()
1016 if (circumCenters.empty()) circumCenters.resize(nTriangles, NULL);
1018 for (
int triangle=0; triangle<nTriangles; ++triangle)
1019 if (circumCenters[triangle] == NULL)
1021 int* corners = triangles[triangle];
1022 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
1023 vertices[corners[1]], vertices[corners[2]]);
1031 const void computeCircumCenters(
const int& level)
1033 if (circumCenters.empty()) circumCenters.resize(nTriangles);
1035 if (circumCenters[levels[level][0]] == NULL)
1037 for (
int triangle=levels[level][0]; triangle<levels[level][1]; ++triangle)
1039 int* corners = triangles[triangle];
1040 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
1041 vertices[corners[1]], vertices[corners[2]]);
1061 const double*
getCircumCenter(
const int& triangle)
const {
return circumCenters[triangle]; }
1080 void getCircumCenter(
const int& triangle,
double* cc)
const
1081 { cc[0]=circumCenters[triangle][0]; cc[1]=circumCenters[triangle][1]; cc[2]=circumCenters[triangle][2]; }
1097 int getNeighbor(
const int& triangleIndex,
const int& neighborIndex)
const
1098 {
return neighborIndex == 3 ? descendants[triangleIndex] : edgeList[triangleIndex][neighborIndex]->tLeft; }
1124 int getNeighbor(
const int& tessellation,
const int& level,
const int& triangle,
const int& side)
1125 {
return getNeighbor(getTriangle(tessellation, level, triangle), side); }
1141 void getNeighbors(
int triangleIndex, vector<int>& neighbors)
1144 vector<Edge*> edges = edgeList[triangleIndex];
1145 neighbors.push_back(edges[0]->tLeft);
1146 neighbors.push_back(edges[1]->tLeft);
1147 neighbors.push_back(edges[2]->tLeft);
1148 neighbors.push_back(descendants[triangleIndex]);
1173 void getNeighbors(
const int& tessellation,
const int& level,
const int& triangle, vector<int>& neighbors)
1174 {
getNeighbors(getTriangle(tessellation, level, triangle), neighbors); }
1189 int getNeighborIndex(
const int& tid,
const int& nid)
1191 if (edgeList[tid][0]->tLeft == nid)
1193 if (edgeList[tid][1]->tLeft == nid)
1195 if (edgeList[tid][2]->tLeft == nid)
1204 int getDescendant(
const int& tessId,
const int& level,
const int& triangle)
const
1205 {
return descendants[getTriangle(tessId, level, triangle)]; }
1219 int getTriangle(
int triangleIndex,
const double* vector);
1242 const vector<int>& getVertexTriangles(
const int& tessId,
const int& level,
const int& vertex)
const
1243 {
return vtxTriangles[tessellations[tessId][0] + level][vertex]; }
1258 const vector<int>& getVertexTriangles(
int tessId,
int vertex)
const
1278 void getVertexNeighborsOrdered(
const int& tessId,
const int& level,
const int& vertex, vector<int>& v);
1291 void getVertexNeighbors(
const int& tessId,
const int& level,
const int& vertex, set<int>& nbrs)
1311 void getVertexNeighbors(
const int& tessId,
const int& level,
const int& vertex,
1312 const int& order, set<int>& nbrs);
1326 vertices(NULL), nVertices(0),
1327 triangles(NULL), nTriangles(0),
1328 levels(NULL), nLevels(0),
1329 tessellations(NULL), nTessellations(0),
1330 descendants(NULL), gridID(
""),
1331 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1332 gridGenerationDate(
""), refCount(0)
1339 GeoTessGrid(IFStreamAscii& input,
const GeoTessOptimizationType* opttype) :
1340 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1341 descendants(NULL), gridID(
""),
1342 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1343 gridGenerationDate(
""), refCount(0)
1344 { loadGridAscii(input); }
1350 GeoTessGrid(IFStreamBinary& input,
const GeoTessOptimizationType* opttype) :
1351 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1352 descendants(NULL), gridID(
""),
1353 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1354 gridGenerationDate(
""), refCount(0)
1355 { loadGridBinary(input); }
1361 GeoTessGrid(
double** _vertices,
int& _nVertices,
1362 int** _triangles,
int& _nTriangles,
1363 int** _levels,
int& _nLevels,
1364 int** _tessellations,
int& _nTessellations,
1366 string& _gridInputFile,
1367 string& _gridOutputFile,
1368 string& _gridSoftwareVersion,
1369 string& _gridGenerationDate) :
1370 vertices(_vertices), nVertices(_nVertices),
1371 triangles(_triangles), nTriangles(_nTriangles),
1372 levels(_levels), nLevels(_nLevels),
1373 tessellations(_tessellations), nTessellations(_nTessellations),
1376 gridInputFile(_gridInputFile),
1377 gridOutputFile(_gridOutputFile),
1378 gridSoftwareVersion(_gridSoftwareVersion),
1379 gridGenerationDate(_gridGenerationDate),
1386 virtual ~GeoTessGrid();
1391 int getReferenceCount() {
return refCount; }
1396 void addReference() { ++refCount; }
1401 void removeReference()
1403 if (isNotReferenced())
1406 os << endl <<
"ERROR in GeoTessGrid::removeReference" << endl
1407 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1408 throw GeoTessException(os, __FILE__, __LINE__, 2001);
1417 bool isNotReferenced() {
return (refCount == 0); }
1424 void writeGrid(
const string& fileName);
1429 void writeGridAscii(
const string& fileName);
1434 void writeGridAscii(IFStreamAscii& output);
1439 void writeGridBinary(
const string& fileName);
1444 void writeGridBinary(IFStreamBinary& output);
1451 bool isSupportedFormatVersion(
int frmtVrsn)
1452 {
return (frmtVrsn == 2); }
1455 const GeoTessOptimizationType& getOptimizationType()
const {
return GeoTessOptimizationType::SPEED; }
1514 vector<Edge*>& getSpokeList(
const int& level)
const
1515 { computeSpokeLists(level);
return spokeList[level]; }
1517 const vector<vector<Edge*> >&
getEdgeList()
const {
return edgeList; }
1519 const vector<Edge*>&
getEdgeList(
const int& triangle)
const {
return edgeList[triangle]; }
1527 void getCenter(
const int& triangle,
double* center)
1529 vector<double*> corners;
1530 corners.push_back(vertices[triangles[triangle][0]]);
1531 corners.push_back(vertices[triangles[triangle][1]]);
1532 corners.push_back(vertices[triangles[triangle][2]]);
1533 GeoTessUtils::center(corners, center);
1548 #endif // GEOTESSGRID_OBJECT_H