36 #ifndef GEOTESSGRID_OBJECT_H
37 #define GEOTESSGRID_OBJECT_H
245 vertices(NULL), nVertices(0),
246 triangles(NULL), nTriangles(0),
247 levels(NULL), nLevels(0),
248 tessellations(NULL), nTessellations(0),
249 descendants(NULL), gridID(gid),
250 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
251 gridGenerationDate(
""), refCount(0)
283 vector<vector<Edge*> > edgeList;
297 mutable vector<vector<Edge*> > spokeList;
305 mutable vector<double*> circumCenters;
320 string gridInputFile;
325 string gridOutputFile;
330 string gridSoftwareVersion;
336 string gridGenerationDate;
347 vector< vector< vector<int> > > vtxTriangles;
354 mutable vector< set<int> > connectedVertices;
359 GeoTessGrid* loadGridAscii(
const string& inputFile);
370 GeoTessGrid* loadGridBinary(
const string& inputFile);
377 static void loadGridAsciiFront(
IFStreamAscii& input,
int& gridFileFormat,
378 string& gridSWVersion,
string& fileCreationDate,
379 string& gridid,
const string& grdInptFile);
381 static void loadGridBinaryFront(
IFStreamBinary& ifs,
int& gridFileFormat,
382 string& gridSWVersion,
string& fileCreationDate,
383 string& gridid,
const string& grdInptFile);
399 const set<int>& getVertexIndices(
const int& level);
401 void computeSpokeLists(
const int& level)
const;
411 vertices(NULL), nVertices(0),
412 triangles(NULL), nTriangles(0),
413 levels(NULL), nLevels(0),
414 tessellations(NULL), nTessellations(0),
415 descendants(NULL), gridID(
""),
416 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
417 gridGenerationDate(
""), refCount(0)
424 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
425 descendants(NULL), gridID(
""),
426 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
427 gridGenerationDate(
""), refCount(0)
428 { loadGridAscii(input); }
434 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
435 descendants(NULL), gridID(
""),
436 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
437 gridGenerationDate(
""), refCount(0)
438 { loadGridBinary(input); }
462 memory += nVertices * (
LONG_INT)
sizeof(
double*) + nVertices * 3 * (
LONG_INT)
sizeof(
double);
465 memory += nTriangles * (
LONG_INT)
sizeof(
int*) + nTriangles * 3 * (
LONG_INT)
sizeof(
int);
468 memory += nLevels * (
LONG_INT)
sizeof(
int*) + nLevels * 2 * (
LONG_INT)
sizeof(
int);
471 memory += nTessellations * (
LONG_INT)
sizeof(
int*) + nTessellations * 2 * (
LONG_INT)
sizeof(
int);
474 memory += nTriangles * (
LONG_INT)
sizeof(
int);
477 memory += (
LONG_INT) (edgeList.capacity() *
sizeof(vector<Edge*>)
478 + edgeList.size() * 3 * (
sizeof(
Edge*) +
sizeof(
Edge)));
481 memory += (
LONG_INT) (spokeList.capacity() *
sizeof(vector<Edge*>)
482 + spokeList.size() * 3 *
sizeof(
Edge*));
485 memory += (
LONG_INT) (circumCenters.capacity() *
sizeof(
double*));
486 for (
int i=0; i<(int)circumCenters.size(); ++i)
487 if (circumCenters[i]) memory += 3 * (
LONG_INT)
sizeof(
double);
492 memory += (
LONG_INT) (vtxTriangles.capacity() *
sizeof(vector< vector<int> >));
493 for (
int i=0; i<(int)vtxTriangles.size(); ++i)
495 memory += (
LONG_INT) (vtxTriangles[i].capacity() *
sizeof(vector<int>));
496 for (
int j=0; j<(int)vtxTriangles[i].size(); ++j)
497 memory += (
LONG_INT) (vtxTriangles[i][j].capacity() *
sizeof(int));
504 memory += (
LONG_INT) (connectedVertices.capacity() *
sizeof(set<int>));
505 for (
int i=0; i<(int)connectedVertices.size(); ++i)
506 memory += (
LONG_INT) (connectedVertices[i].size() *
sizeof(int));
509 memory += (
LONG_INT) (gridID.length() + gridInputFile.length() + gridOutputFile.length()
510 + gridSoftwareVersion.length() + gridGenerationDate.length());
544 {
return (gridID == g.gridID); }
552 {
return !(*
this == g); }
632 return vertices[vertex];
645 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), unit_vector)];
648 double dot = GeoTessUtils::dot(unit_vector, vertices[t[0]]);
650 double doti = GeoTessUtils::dot(unit_vector, vertices[t[1]]);
657 doti = GeoTessUtils::dot(unit_vector, vertices[t[2]]);
676 {
return triangles[triangle][corner]; }
695 return triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner];
706 for (
int i=nTessellations-1; i>=0; --i)
708 int vid = getVertexIndex(u, i);
725 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), u)];
727 if (GeoTessUtils::dot(u, vertices[t[0]]) > cos(1e-7))
729 if (GeoTessUtils::dot(u, vertices[t[1]]) > cos(1e-7))
731 if (GeoTessUtils::dot(u, vertices[t[2]]) > cos(1e-7))
747 double*
getVertex(
int tessId,
int level,
int triangle,
int corner)
749 return vertices[triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner]];
773 getVertices(tessellation, getNLevels(tessellation)-1, vectors);
785 void getVertices(
const int& tessellation,
const int& level, set<const double*>& vectors);
800 {
return getVertexIndices(getLevel(tessId, level)); }
814 {
return getVertexIndices(tessellations[tessId][1] - 1); }
836 {
return tessellations[tessellation][1] - tessellations[tessellation][0]; }
847 {
return tessellations[tessellation][0] + i; }
865 {
return tessellations[tessellation][1] - 1; }
882 {
return tessellations[tessellation][1] - tessellations[tessellation][0] - 1; }
895 return levels[tessellations[tessellation][0] + level][1]
896 - levels[tessellations[tessellation][0] + level][0];
911 {
return levels[tessellations[tessellation][0] + level][0] + i; }
923 {
return levels[tessellations[tessellation][0] + level][0]; }
935 {
return levels[tessellations[tessellation][0] + level][1]-1; }
960 {
return triangles[triangleIndex]; }
974 {
return triangles[triangleIndex][cornerIndex]; }
988 {
return vertices[triangles[triangleIndex][cornerIndex]]; }
1001 int* corners = triangles[triangle];
1002 triVrt[0][0] = vertices[corners[0]][0];
1003 triVrt[0][1] = vertices[corners[0]][1];
1004 triVrt[0][2] = vertices[corners[0]][2];
1005 triVrt[1][0] = vertices[corners[1]][0];
1006 triVrt[1][1] = vertices[corners[1]][1];
1007 triVrt[1][2] = vertices[corners[1]][2];
1008 triVrt[2][0] = vertices[corners[2]][0];
1009 triVrt[2][1] = vertices[corners[2]][1];
1010 triVrt[2][2] = vertices[corners[2]][2];
1019 if (circumCenters.empty()) circumCenters.resize(nTriangles, NULL);
1021 for (
int triangle=0; triangle<nTriangles; ++triangle)
1022 if (circumCenters[triangle] == NULL)
1024 int* corners = triangles[triangle];
1025 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
1026 vertices[corners[1]], vertices[corners[2]]);
1036 if (circumCenters.empty()) circumCenters.resize(nTriangles);
1038 if (circumCenters[levels[level][0]] == NULL)
1040 for (
int triangle=levels[level][0]; triangle<levels[level][1]; ++triangle)
1042 int* corners = triangles[triangle];
1043 circumCenters[triangle] = GeoTessUtils::circumCenterPlus(vertices[corners[0]],
1044 vertices[corners[1]], vertices[corners[2]]);
1064 const double*
getCircumCenter(
const int& triangle)
const {
return circumCenters[triangle]; }
1084 { cc[0]=circumCenters[triangle][0]; cc[1]=circumCenters[triangle][1]; cc[2]=circumCenters[triangle][2]; }
1100 int getNeighbor(
const int& triangleIndex,
const int& neighborIndex)
const
1101 {
return neighborIndex == 3 ? descendants[triangleIndex] : edgeList[triangleIndex][neighborIndex]->tLeft; }
1127 int getNeighbor(
const int& tessellation,
const int& level,
const int& triangle,
const int& side)
1128 {
return getNeighbor(getTriangle(tessellation, level, triangle), side); }
1147 vector<Edge*> edges = edgeList[triangleIndex];
1148 neighbors.push_back(edges[0]->tLeft);
1149 neighbors.push_back(edges[1]->tLeft);
1150 neighbors.push_back(edges[2]->tLeft);
1151 neighbors.push_back(descendants[triangleIndex]);
1176 void getNeighbors(
const int& tessellation,
const int& level,
const int& triangle, vector<int>& neighbors)
1177 { getNeighbors(getTriangle(tessellation, level, triangle), neighbors); }
1194 if (edgeList[tid][0]->tLeft == nid)
1196 if (edgeList[tid][1]->tLeft == nid)
1198 if (edgeList[tid][2]->tLeft == nid)
1207 int getDescendant(
const int& tessId,
const int& level,
const int& triangle)
const
1208 {
return descendants[getTriangle(tessId, level, triangle)]; }
1246 {
return vtxTriangles[tessellations[tessId][0] + level][vertex]; }
1262 {
return getVertexTriangles(tessId, getNLevels(tessId)-1, vertex); }
1295 { getVertexNeighbors(tessId, level, vertex, 1, nbrs); }
1315 const int& order, set<int>& nbrs);
1329 vertices(NULL), nVertices(0),
1330 triangles(NULL), nTriangles(0),
1331 levels(NULL), nLevels(0),
1332 tessellations(NULL), nTessellations(0),
1333 descendants(NULL), gridID(
""),
1334 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1335 gridGenerationDate(
""), refCount(0)
1343 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1344 descendants(NULL), gridID(
""),
1345 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1346 gridGenerationDate(
""), refCount(0)
1347 { loadGridAscii(input); }
1353 GeoTessGrid(IFStreamBinary& input,
const GeoTessOptimizationType* opttype) :
1354 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1355 descendants(NULL), gridID(
""),
1356 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1357 gridGenerationDate(
""), refCount(0)
1358 { loadGridBinary(input); }
1364 GeoTessGrid(
double** _vertices,
int& _nVertices,
1365 int** _triangles,
int& _nTriangles,
1366 int** _levels,
int& _nLevels,
1367 int** _tessellations,
int& _nTessellations,
1369 string& _gridInputFile,
1370 string& _gridOutputFile,
1371 string& _gridSoftwareVersion,
1372 string& _gridGenerationDate) :
1373 vertices(_vertices), nVertices(_nVertices),
1374 triangles(_triangles), nTriangles(_nTriangles),
1375 levels(_levels), nLevels(_nLevels),
1376 tessellations(_tessellations), nTessellations(_nTessellations),
1379 gridInputFile(_gridInputFile),
1380 gridOutputFile(_gridOutputFile),
1381 gridSoftwareVersion(_gridSoftwareVersion),
1382 gridGenerationDate(_gridGenerationDate),
1389 virtual ~GeoTessGrid();
1394 int getReferenceCount() {
return refCount; }
1399 void addReference() { ++refCount; }
1404 void removeReference()
1406 if (isNotReferenced())
1409 os << endl <<
"ERROR in GeoTessGrid::removeReference" << endl
1410 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1411 throw GeoTessException(os, __FILE__, __LINE__, 2001);
1420 bool isNotReferenced() {
return (refCount == 0); }
1427 void writeGrid(
const string& fileName);
1432 void writeGridAscii(
const string& fileName);
1437 void writeGridAscii(IFStreamAscii& output);
1442 void writeGridBinary(
const string& fileName);
1447 void writeGridBinary(IFStreamBinary& output);
1454 bool isSupportedFormatVersion(
int frmtVrsn)
1455 {
return (frmtVrsn == 2); }
1458 const GeoTessOptimizationType& getOptimizationType()
const {
return GeoTessOptimizationType::SPEED; }
1518 { computeSpokeLists(level);
return spokeList[level]; }
1520 const vector<vector<Edge*> >&
getEdgeList()
const {
return edgeList; }
1522 const vector<Edge*>&
getEdgeList(
const int& triangle)
const {
return edgeList[triangle]; }
1532 vector<double*> corners;
1533 corners.push_back(vertices[triangles[triangle][0]]);
1534 corners.push_back(vertices[triangles[triangle][1]]);
1535 corners.push_back(vertices[triangles[triangle][2]]);
1536 GeoTessUtils::center(corners, center);
Manages the geometry and topology of one or more multi-level triangular tessellations of a unit spher...
const double * getVertex(int vertex) const
vector< Edge * > & getSpokeList(const int &level) const
const string & getGridOutputFile() const
int findClosestVertex(double *unit_vector, int tessId)
void getNeighbors(const int &tessellation, const int &level, const int &triangle, vector< int > &neighbors)
int getTriangle(int tessellation, int level, int i) const
void getVertices(const int &tessellation, const int &level, set< const double * > &vectors)
int getNTriangles(int tessellation, int level) const
int getLastLevel(int tessellation) const
int getDescendant(const int &tessId, const int &level, const int &triangle) const
GeoTessGrid(IFStreamBinary &input)
GeoTessGrid * loadGrid(const string &inputFile)
const vector< int > & getVertexTriangles(int tessId, int vertex) const
double const *const * getVertices() const
void getVertexNeighbors(const int &tessId, const int &level, const int &vertex, set< int > &nbrs)
const vector< Edge * > & getEdgeList(const int &triangle) const
int getNLevels(int tessellation) const
int getTriangleVertexIndex(int triangleIndex, int cornerIndex) const
const set< int > & getVertexIndicesTopLevel(const int &tessId)
double * getVertex(int tessId, int level, int triangle, int corner)
void setGridGenerationDate(const string &gridDate)
static bool isGeoTessGrid(const string &inputFile)
void setGridInputFile(const string &gridFile)
int getLastTriangle(int tessellation, int level) const
void getVertexNeighbors(const int &tessId, const int &level, const int &vertex, const int &order, set< int > &nbrs)
const string & getGridGenerationDate() const
int getNeighborIndex(const int &tid, const int &nid)
void getCenter(const int &triangle, double *center)
int getVertexIndex(int triangle, int corner) const
int getNeighbor(const int &tessellation, const int &level, const int &triangle, const int &side)
int getNeighbor(const int &triangleIndex, const int &neighborIndex) const
int const * getDescendants() const
int getVertexIndex(int tessId, int level, int triangle, int corner) const
void getTriangleVertices(int triangle, double **triVrt)
void getCircumCenter(const int &triangle, double *cc) const
const void computeCircumCenters(const int &level)
int getLevel(int tessellation, int i) const
GeoTessGrid(const string &gid)
void getVertexNeighborsOrdered(const int &tessId, const int &level, const int &vertex, vector< int > &v)
int getDescendant(const int &triangle) const
void getNeighbors(int triangleIndex, vector< int > &neighbors)
int getFirstTriangle(int tessellation, int level) const
int getVertexIndex(const double *u)
int getTopLevel(int tessellation) const
int getTriangle(int triangleIndex, const double *vector)
void setGridSoftwareVersion(const string &swVersion)
const string & getGridInputFile() const
const vector< vector< Edge * > > & getEdgeList() const
int getVertexIndex(const double *u, int tessId)
const void computeCircumCenters()
int getNTriangles() const
const vector< int > & getVertexTriangles(const int &tessId, const int &level, const int &vertex) const
const set< int > & getVertexIndices(const int &tessId, const int &level)
const double * getCircumCenter(const int &triangle) const
const double * getTriangleVertex(int triangleIndex, int cornerIndex) const
const vector< vector< int > > & getVertexTriangles(const int &level) const
const string & getGridID() const
static string getGridID(const string &fileName)
int const *const * getLevels() const
GeoTessGrid(IFStreamAscii &input)
int const *const * getTriangles() const
GeoTessGrid(GeoTessGrid &other)
const int * getTriangleVertexIndexes(int triangleIndex) const
const string & getGridSoftwareVersion() const
int getNTessellations() const
int const *const * getTessellations() const
void getVerticesTopLevel(const int &tessellation, set< const double * > &vectors)
Enumeration of the optimization strategies supported by GeoTess including OptimizationType::SPEED and...
Opens ascii file for read and write access.
Opens a file for binary read and write access.
Stores information about the connection between two adjacent vertices which separates two neighboring...