36 #ifndef GEOTESSGRID_OBJECT_H
37 #define GEOTESSGRID_OBJECT_H
208 mutable double** circumCenters;
223 string gridInputFile;
228 string gridOutputFile;
233 string gridSoftwareVersion;
239 string gridGenerationDate;
250 mutable vector< vector< vector<int> > > vtxTriangles;
257 mutable vector< set<int> > connectedVertices;
274 GeoTessGrid* loadGridAscii(
const string& inputFile);
285 GeoTessGrid* loadGridBinary(
const string& inputFile);
319 int** findNeighbors();
325 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
326 neighbors(NULL), edges(NULL), circumCenters(NULL), gridID(gid),
327 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
328 gridGenerationDate(
""), refCount(0), optimization(opttype)
332 static void loadGridAsciiFront(
IFStreamAscii& input,
int& gridFileFormat,
333 string& gridSWVersion,
string& fileCreationDate,
334 string& gridid,
const string& grdInptFile);
336 static void loadGridBinaryFront(
IFStreamBinary& ifs,
int& gridFileFormat,
337 string& gridSWVersion,
string& fileCreationDate,
338 string& gridid,
const string& grdInptFile);
354 const set<int>& getVertexIndices(
const int& level);
363 void clearVertexTriangles(
const int& level);
375 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
376 neighbors(NULL), edges(NULL), circumCenters(NULL), gridID(
""),
377 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
387 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
388 neighbors(NULL), edges(NULL), circumCenters(NULL), gridID(
""),
389 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
390 gridGenerationDate(
""), refCount(0), optimization(opttype)
420 static string getGridID(
const string& fileName);
428 static bool isGeoTessGrid(
const string& inputFile);
436 {
return (gridID == g.gridID); }
444 {
return !(*
this == g); }
456 const string& getGridID()
const
528 const double* getVertex(
int vertex)
const
530 return vertices[vertex];
541 int findClosestVertex(
double* unit_vector,
int tessId)
543 int* t = triangles[getTriangle(getFirstTriangle(tessId, 0), unit_vector)];
546 double dot = GeoTessUtils::dot(unit_vector, vertices[t[0]]);
548 double doti = GeoTessUtils::dot(unit_vector, vertices[t[1]]);
555 doti = GeoTessUtils::dot(unit_vector, vertices[t[2]]);
580 int getVertexIndex(
int tessId,
int level,
int triangle,
int corner)
const
582 return triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner];
596 double* getVertex(
int tessId,
int level,
int triangle,
int corner)
598 return vertices[triangles[levels[tessellations[tessId][0] + level][0] + triangle][corner]];
620 void getVerticesTopLevel(
const int& tessellation, set<const double*>& vectors)
622 getVertices(tessellation, getNLevels(tessellation)-1, vectors);
634 void getVertices(
const int& tessellation,
const int& level, set<const double*>& vectors);
648 const set<int>& getVertexIndices(
const int& tessId,
const int& level)
662 const set<int>& getVertexIndicesTopLevel(
const int& tessId)
663 {
return getVertexIndices(tessellations[tessId][1] - 1); }
694 int getNLevels(
int tessellation)
const
695 {
return tessellations[tessellation][1] - tessellations[tessellation][0]; }
706 int getLevel(
int tessellation,
int i)
const
707 {
return tessellations[tessellation][0] + i; }
715 int getLastLevel(
int tessellation)
const
716 {
return tessellations[tessellation][1] - 1; }
727 int getNTriangles(
int tessellation,
int level)
const
729 return levels[tessellations[tessellation][0] + level][1]
730 - levels[tessellations[tessellation][0] + level][0];
744 int getTriangle(
int tessellation,
int level,
int i)
const
745 {
return levels[tessellations[tessellation][0] + level][0] + i; }
756 int getFirstTriangle(
int tessellation,
int level)
const
757 {
return levels[tessellations[tessellation][0] + level][0]; }
768 int getLastTriangle(
int tessellation,
int level)
const
769 {
return levels[tessellations[tessellation][0] + level][1]-1; }
793 const int* getTriangleVertexIndexes(
int triangleIndex)
const
794 {
return triangles[triangleIndex]; }
807 int getTriangleVertexIndex(
int triangleIndex,
int cornerIndex)
const
808 {
return triangles[triangleIndex][cornerIndex]; }
821 const double* getTriangleVertex(
int triangleIndex,
int cornerIndex)
const
822 {
return vertices[triangles[triangleIndex][cornerIndex]]; }
833 void getTriangleVertices(
int triangle,
double** triVrt)
835 int* corners = triangles[triangle];
836 triVrt[0][0] = vertices[corners[0]][0];
837 triVrt[0][1] = vertices[corners[0]][1];
838 triVrt[0][2] = vertices[corners[0]][2];
839 triVrt[1][0] = vertices[corners[1]][0];
840 triVrt[1][1] = vertices[corners[1]][1];
841 triVrt[1][2] = vertices[corners[1]][2];
842 triVrt[2][0] = vertices[corners[2]][0];
843 triVrt[2][1] = vertices[corners[2]][1];
844 triVrt[2][2] = vertices[corners[2]][2];
861 const double* getCircumCenter(
int triangle,
double*
const pA)
const
868 int* corners = triangles[triangle];
869 GeoTessUtils::circumCenter(vertices[corners[0]], vertices[corners[1]],
870 vertices[corners[2]], pA);
877 if (circumCenters == NULL)
879 circumCenters = CPPUtils::new2DArray<double>(nTriangles, 3);
880 CPPUtils::resetArray<double>(nTriangles*3, circumCenters[0], -2.0);
885 if (circumCenters[triangle][0] == -2.0)
887 int* corners = triangles[triangle];
888 GeoTessUtils::circumCenter(vertices[corners[0]], vertices[corners[1]],
889 vertices[corners[2]], circumCenters[triangle]);
891 return circumCenters[triangle];
908 int getNeighbor(
int triangleIndex,
int neighborIndex)
const
909 {
return neighbors[triangleIndex][neighborIndex]; }
924 const int* getNeighbors(
int triangleIndex)
const
925 {
return neighbors[triangleIndex]; }
949 const int* getNeighbors(
const int& tessellation,
const int& level,
const int& triangle)
950 {
return neighbors[getTriangle(tessellation, level, triangle)]; }
976 int getNeighbor(
const int& tessellation,
const int& level,
const int& triangle,
const int& side)
977 {
return neighbors[getTriangle(tessellation, level, triangle)][side]; }
998 int getNeighborIndex(
const int& tid,
const int& nid)
1000 if (neighbors[tid][0] == nid)
1002 if (neighbors[tid][1] == nid)
1004 if (neighbors[tid][2] == nid)
1021 int getTriangle(
int triangleIndex,
double* vector);
1035 const vector<int>& getVertexTriangles(
const int& tessId,
const int& level,
const int& vertex)
const;
1050 const vector<int>& getVertexTriangles(
int tessId,
int vertex)
const
1059 void clearVertexTriangles();
1070 void getVertexNeighborsOrdered(
const int& tessId,
const int& level,
const int& vertex, vector<int>& v);
1083 void getVertexNeighbors(
const int& tessId,
const int& level,
const int& vertex, set<int>& nbrs)
1103 void getVertexNeighbors(
const int& tessId,
const int& level,
const int& vertex,
1104 const int& order, set<int>& nbrs);
1116 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1117 neighbors(NULL), edges(NULL), circumCenters(NULL), gridID(
""),
1118 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1119 gridGenerationDate(
""), refCount(0), optimization(opttype)
1120 { loadGridAscii(input); }
1125 GeoTessGrid(IFStreamBinary& input,
const OptimizationType* opttype) :
1126 vertices(NULL), triangles(NULL), levels(NULL), tessellations(NULL),
1127 neighbors(NULL), edges(NULL), circumCenters(NULL), gridID(
""),
1128 gridInputFile(
"null"), gridOutputFile(
"null"), gridSoftwareVersion(
""),
1129 gridGenerationDate(
""), refCount(0), optimization(opttype)
1130 { loadGridBinary(input); }
1135 virtual ~GeoTessGrid();
1140 int getReferenceCount() {
return refCount; }
1145 void addReference() { ++refCount; }
1150 void removeReference()
1152 if (isNotReferenced())
1155 os << endl <<
"ERROR in GeoTessGrid::removeReference" << endl
1156 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1157 throw GeoTessException(os, __FILE__, __LINE__, 2001);
1166 bool isNotReferenced() {
return (refCount == 0); }
1173 void writeGrid(
const string& fileName);
1178 void writeGridAscii(
const string& fileName);
1183 void writeGridAscii(IFStreamAscii& output);
1188 void writeGridBinary(
const string& fileName);
1193 void writeGridBinary(IFStreamBinary& output);
1212 double const*
const*
const* getEdges()
const {
return edges; }
1234 void getEdgeList(
const int& tessId,
const int& level,
const int& vertex, ArrayReuse<int>& store,
1236 {
return getEdgeList(tessId, level, vertex, -1, store, e); }
1241 void getEdgeList(
const int& tessId,
const int& level,
const int& vertex,
const int& firstNeighborVertex,
1242 ArrayReuse<int>& store, list<int*>& e)
const;
1249 bool isSupportedFormatVersion(
int frmtVrsn)
1250 {
return (frmtVrsn == 2); }
1269 #endif // GEOTESSGRID_OBJECT_H