38 #ifndef GEOTESSGRID_OBJECT_H
39 #define GEOTESSGRID_OBJECT_H
247 vertices(NULL), nVertices(0),
248 triangles(NULL), nTriangles(0),
249 levels(NULL), nLevels(0),
250 tessellations(NULL), nTessellations(0),
251 descendants(NULL), gridID(gid),
252 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
253 gridGenerationDate(
""), refCount(0)
285 vector<vector<Edge*> > edgeList;
299 mutable vector<vector<Edge*> > spokeList;
307 mutable vector<double*> circumCenters;
322 string gridInputFile;
327 string gridOutputFile;
332 string gridSoftwareVersion;
338 string gridGenerationDate;
349 vector< vector< vector<int> > > vtxTriangles;
356 mutable vector< set<int> > connectedVertices;
361 GeoTessGrid* loadGridAscii(
const string& inputFile);
372 GeoTessGrid* loadGridBinary(
const string& inputFile);
379 static void loadGridAsciiFront(
IFStreamAscii& input,
int& gridFileFormat,
380 string& gridSWVersion,
string& fileCreationDate,
381 string& gridid,
const string& grdInptFile);
383 static void loadGridBinaryFront(
IFStreamBinary& ifs,
int& gridFileFormat,
384 string& gridSWVersion,
string& fileCreationDate,
385 string& gridid,
const string& grdInptFile);
401 const set<int>& getVertexIndices(
const int& level);
403 void computeSpokeLists(
const int& level)
const;
413 vertices(NULL), nVertices(0),
414 triangles(NULL), nTriangles(0),
415 levels(NULL), nLevels(0),
416 tessellations(NULL), nTessellations(0),
417 descendants(NULL), gridID(
""),
418 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
419 gridGenerationDate(
""), refCount(0)
426 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
427 descendants(NULL), gridID(
""),
428 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
429 gridGenerationDate(
""), refCount(0)
430 { loadGridAscii(input); }
436 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
437 descendants(NULL), gridID(
""),
438 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
439 gridGenerationDate(
""), refCount(0)
440 { loadGridBinary(input); }
464 memory += nVertices * (
LONG_INT)
sizeof(
double*) + nVertices * 3 * (
LONG_INT)
sizeof(
double);
467 memory += nTriangles * (
LONG_INT)
sizeof(
int*) + nTriangles * 3 * (
LONG_INT)
sizeof(
int);
470 memory += nLevels * (
LONG_INT)
sizeof(
int*) + nLevels * 2 * (
LONG_INT)
sizeof(
int);
473 memory += nTessellations * (
LONG_INT)
sizeof(
int*) + nTessellations * 2 * (
LONG_INT)
sizeof(
int);
476 memory += nTriangles * (
LONG_INT)
sizeof(
int);
479 memory += (
LONG_INT) (edgeList.capacity() *
sizeof(vector<Edge*>)
480 + edgeList.size() * 3 * (
sizeof(
Edge*) +
sizeof(
Edge)));
483 memory += (
LONG_INT) (spokeList.capacity() *
sizeof(vector<Edge*>)
484 + spokeList.size() * 3 *
sizeof(
Edge*));
487 memory += (
LONG_INT) (circumCenters.capacity() *
sizeof(
double*));
488 for (
int i=0; i<(int)circumCenters.size(); ++i)
489 if (circumCenters[i]) memory += 3 * (
LONG_INT)
sizeof(
double);
494 memory += (
LONG_INT) (vtxTriangles.capacity() *
sizeof(vector< vector<int> >));
495 for (
int i=0; i<(int)vtxTriangles.size(); ++i)
497 memory += (
LONG_INT) (vtxTriangles[i].capacity() *
sizeof(vector<int>));
498 for (
int j=0; j<(int)vtxTriangles[i].size(); ++j)
499 memory += (
LONG_INT) (vtxTriangles[i][j].capacity() *
sizeof(int));
506 memory += (
LONG_INT) (connectedVertices.capacity() *
sizeof(set<int>));
507 for (
int i=0; i<(int)connectedVertices.size(); ++i)
508 memory += (
LONG_INT) (connectedVertices[i].size() *
sizeof(int));
511 memory += (
LONG_INT) (gridID.length() + gridInputFile.length() + gridOutputFile.length()
512 + gridSoftwareVersion.length() + gridGenerationDate.length());
546 {
return (gridID == g.gridID); }
554 {
return !(*
this == g); }
634 return vertices[vertex];
647 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), unit_vector)];
650 double dot = GeoTessUtils::dot(unit_vector, vertices[t[0]]);
652 double doti = GeoTessUtils::dot(unit_vector, vertices[t[1]]);
659 doti = GeoTessUtils::dot(unit_vector, vertices[t[2]]);
678 {
return triangles[triangle][corner]; }
697 return triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner];
708 for (
int i=nTessellations-1; i>=0; --i)
710 int vid = getVertexIndex(u, i);
727 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), u)];
729 if (GeoTessUtils::dot(u, vertices[t[0]]) > cos(1e-7))
731 if (GeoTessUtils::dot(u, vertices[t[1]]) > cos(1e-7))
733 if (GeoTessUtils::dot(u, vertices[t[2]]) > cos(1e-7))
749 double*
getVertex(
int tessId,
int level,
int triangle,
int corner)
751 return vertices[triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner]];
775 getVertices(tessellation, getNLevels(tessellation)-1, vectors);
787 void getVertices(
const int& tessellation,
const int& level, set<const double*>& vectors);
802 {
return getVertexIndices(getLevel(tessId, level)); }
816 {
return getVertexIndices(tessellations[tessId][1] - 1); }
838 {
return tessellations[tessellation][1] - tessellations[tessellation][0]; }
849 {
return tessellations[tessellation][0] + i; }
867 {
return tessellations[tessellation][1] - 1; }
884 {
return tessellations[tessellation][1] - tessellations[tessellation][0] - 1; }
897 return levels[tessellations[tessellation][0] + level][1]
898 - levels[tessellations[tessellation][0] + level][0];
913 {
return levels[tessellations[tessellation][0] + level][0] + i; }
925 {
return levels[tessellations[tessellation][0] + level][0]; }
937 {
return levels[tessellations[tessellation][0] + level][1]-1; }
962 {
return triangles[triangleIndex]; }
976 {
return triangles[triangleIndex][cornerIndex]; }
990 {
return vertices[triangles[triangleIndex][cornerIndex]]; }
1003 int* corners = triangles[triangle];
1004 triVrt[0][0] = vertices[corners[0]][0];
1005 triVrt[0][1] = vertices[corners[0]][1];
1006 triVrt[0][2] = vertices[corners[0]][2];
1007 triVrt[1][0] = vertices[corners[1]][0];
1008 triVrt[1][1] = vertices[corners[1]][1];
1009 triVrt[1][2] = vertices[corners[1]][2];
1010 triVrt[2][0] = vertices[corners[2]][0];
1011 triVrt[2][1] = vertices[corners[2]][1];
1012 triVrt[2][2] = vertices[corners[2]][2];
1021 if (circumCenters.empty()) circumCenters.resize(nTriangles, NULL);
1023 for (
int triangle=0; triangle<nTriangles; ++triangle)
1024 if (circumCenters[triangle] == NULL)
1026 int* corners = triangles[triangle];
1027 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
1028 vertices[corners[1]], vertices[corners[2]]);
1038 if (circumCenters.empty()) circumCenters.resize(nTriangles);
1040 if (circumCenters[levels[level][0]] == NULL)
1042 for (
int triangle=levels[level][0]; triangle<levels[level][1]; ++triangle)
1044 int* corners = triangles[triangle];
1045 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
1046 vertices[corners[1]], vertices[corners[2]]);
1066 const double*
getCircumCenter(
const int& triangle)
const {
return circumCenters[triangle]; }
1086 { cc[0]=circumCenters[triangle][0]; cc[1]=circumCenters[triangle][1]; cc[2]=circumCenters[triangle][2]; }
1102 int getNeighbor(
const int& triangleIndex,
const int& neighborIndex)
const
1103 {
return neighborIndex == 3 ? descendants[triangleIndex] : edgeList[triangleIndex][neighborIndex]->tLeft; }
1129 int getNeighbor(
const int& tessellation,
const int& level,
const int& triangle,
const int& side)
1130 {
return getNeighbor(getTriangle(tessellation, level, triangle), side); }
1149 vector<Edge*> edges = edgeList[triangleIndex];
1150 neighbors.push_back(edges[0]->tLeft);
1151 neighbors.push_back(edges[1]->tLeft);
1152 neighbors.push_back(edges[2]->tLeft);
1153 neighbors.push_back(descendants[triangleIndex]);
1178 void getNeighbors(
const int& tessellation,
const int& level,
const int& triangle, vector<int>& neighbors)
1179 { getNeighbors(getTriangle(tessellation, level, triangle), neighbors); }
1196 if (edgeList[tid][0]->tLeft == nid)
1198 if (edgeList[tid][1]->tLeft == nid)
1200 if (edgeList[tid][2]->tLeft == nid)
1209 int getDescendant(
const int& tessId,
const int& level,
const int& triangle)
const
1210 {
return descendants[getTriangle(tessId, level, triangle)]; }
1248 {
return vtxTriangles[tessellations[tessId][0] + level][vertex]; }
1264 {
return getVertexTriangles(tessId, getNLevels(tessId)-1, vertex); }
1297 { getVertexNeighbors(tessId, level, vertex, 1, nbrs); }
1317 const int& order, set<int>& nbrs);
1331 vertices(NULL), nVertices(0),
1332 triangles(NULL), nTriangles(0),
1333 levels(NULL), nLevels(0),
1334 tessellations(NULL), nTessellations(0),
1335 descendants(NULL), gridID(
""),
1336 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1337 gridGenerationDate(
""), refCount(0)
1345 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1346 descendants(NULL), gridID(
""),
1347 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1348 gridGenerationDate(
""), refCount(0)
1349 { loadGridAscii(input); }
1355 GeoTessGrid(IFStreamBinary& input,
const GeoTessOptimizationType* opttype) :
1356 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1357 descendants(NULL), gridID(
""),
1358 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1359 gridGenerationDate(
""), refCount(0)
1360 { loadGridBinary(input); }
1366 GeoTessGrid(
double** _vertices,
int& _nVertices,
1367 int** _triangles,
int& _nTriangles,
1368 int** _levels,
int& _nLevels,
1369 int** _tessellations,
int& _nTessellations,
1371 string& _gridInputFile,
1372 string& _gridOutputFile,
1373 string& _gridSoftwareVersion,
1374 string& _gridGenerationDate) :
1375 vertices(_vertices), nVertices(_nVertices),
1376 triangles(_triangles), nTriangles(_nTriangles),
1377 levels(_levels), nLevels(_nLevels),
1378 tessellations(_tessellations), nTessellations(_nTessellations),
1381 gridInputFile(_gridInputFile),
1382 gridOutputFile(_gridOutputFile),
1383 gridSoftwareVersion(_gridSoftwareVersion),
1384 gridGenerationDate(_gridGenerationDate),
1391 virtual ~GeoTessGrid();
1396 int getReferenceCount() {
return refCount; }
1401 void addReference() { ++refCount; }
1406 void removeReference()
1408 if (isNotReferenced())
1411 os << endl <<
"ERROR in GeoTessGrid::removeReference" << endl
1412 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1413 throw GeoTessException(os, __FILE__, __LINE__, 2001);
1422 bool isNotReferenced() {
return (refCount == 0); }
1429 void writeGrid(
const string& fileName);
1434 void writeGridAscii(
const string& fileName);
1439 void writeGridAscii(IFStreamAscii& output);
1444 void writeGridBinary(
const string& fileName);
1449 void writeGridBinary(IFStreamBinary& output);
1456 bool isSupportedFormatVersion(
int frmtVrsn)
1457 {
return (frmtVrsn == 2); }
1460 const GeoTessOptimizationType& getOptimizationType()
const {
return GeoTessOptimizationType::SPEED; }
1520 { computeSpokeLists(level);
return spokeList[level]; }
1522 const vector<vector<Edge*> >&
getEdgeList()
const {
return edgeList; }
1524 const vector<Edge*>&
getEdgeList(
const int& triangle)
const {
return edgeList[triangle]; }
1534 vector<double*> corners;
1535 corners.push_back(vertices[triangles[triangle][0]]);
1536 corners.push_back(vertices[triangles[triangle][1]]);
1537 corners.push_back(vertices[triangles[triangle][2]]);
1538 GeoTessUtils::center(corners, center);
1553 #endif // GEOTESSGRID_OBJECT_H