RSTT: rstt/SLBM/include/GridGeoTess.h Source File

RSTT 3.1.0 Regional Seismic Travel Time

GridGeoTess.h
Go to the documentation of this file.
1 /*
2 * GridGeoTess.h
3 *
4 * Created on: Sep 25, 2012
5 * Author: sballar
6 */
7
8 #ifndef GRIDGEOTESS_H_
9 #define GRIDGEOTESS_H_
10
11 #include <map>
12
13 #include "Grid.h"
14 #include "GeoTessModelSLBM.h"
15 #include "GeoTessModelPathUnc.h"
16 #include "GeoTessPosition.h"
17 #include "GridProfileGeoTess.h"
18
19 using namespace std;
20 using namespace geotess;
21
22 namespace slbm {
23
24 class SLBM_EXP_IMP GridGeoTess: public Grid
25 {
26 public:
27
28 GridGeoTess();
29
33 virtual ~GridGeoTess();
34
38 static string class_name() { return "GridGeoTess"; };
39
40 GeoTessModelSLBM* loadModel(const string& filename, const string& relGridPath = "");
41
45 void clear();
46
52 void loadFromFile(const string& filename);
53
59 void loadFromDirectory(const string& dirName);
60
61 void loadFromDataBuffer(util::DataBuffer& buffer);
62
69 void saveVelocityModel(const string& filename, const int& format);
70
75 void saveVelocityModel(util::DataBuffer& buffer);
76
82 int getBufferSize() const { return model->getBufferSize(); };
83
90 double getAverageMantleVelocity(const int& waveType)
91 {return model->getAverageMantleVelocity(waveType); };
92
99 void setAverageMantleVelocity(const int& waveType, const double& velocity)
100 {model->setAverageMantleVelocity(waveType, velocity); };
101
121 virtual bool findProfile(Location& location,
122 vector<GridProfile*>& neighbors, vector<int>& nodeIds,
123 vector<double>& coefficients);
124
125 // //! \brief Specify the latitude, longitude range that will define
126 // //! which grid nodes are also active nodes.
127 // //!
128 // //! Specify the latitude, longitude range that will define
129 // //! which grid nodes are also active nodes. Active nodes are defined
130 // //! as follows: Each triangle in the tessellation is visited. If any
131 // //! one of the three nodes which define the triangle is located within
132 // //! the specified latitude, longitude range, then all three of the
133 // //! nodes are active nodes.
134 // void initializeActiveNodes(double activeNodeLatMin,
135 // double activeNodeLonMin,
136 // double activeNodeLatMax,
137 // double activeNodeLonMax);
138
144 void getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors);
145
151 void getNodeNeighbors(const int& nodeId, vector<int>& neighbors);
152
153 void getActiveNodeNeighbors(const int& nodeid, int neighbors[], int& nNeighbors);
154
155 void getActiveNodeNeighbors(const int& nodeid, vector<int>& neighbors);
156
164 void getNodeNeighborInfo(const int& nodeid, int neighbors[],
165 double distance[], double azimuth[], int& nNeighbors)
166 {
167 set<int> nbrs;
168 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
169 nodeid, nbrs);
170
171 nNeighbors = (int)nbrs.size();
172 int nid, i=0;
173 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
174 {
175 nid = profiles[*it]->getNodeId();
176
177 neighbors[i]=nid;
178
179 distance[i] = GeoTessUtils::angle(model->getGrid().getVertex(nodeid),
180 model->getGrid().getVertex(nid));
181
182 azimuth[i] = GeoTessUtils::azimuth(model->getGrid().getVertex(nodeid),
183 model->getGrid().getVertex(nid), NA_VALUE);
184
185 ++i;
186 }
187 }
188
189 void getNodeNeighborInfo(const int& nodeid, vector<int>& neighbors,
190 vector<double>& distance, vector<double>& azimuth)
191 {
192 set<int> nbrs;
193 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
194 nodeid, nbrs);
195
196 int nNeighbors = (int)nbrs.size();
197 neighbors.clear();
198 distance.clear();
199 azimuth.clear();
200 neighbors.reserve(nNeighbors);
201 distance.reserve(nNeighbors);
202 azimuth.reserve(nNeighbors);
203 int nid;
204 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
205 {
206 nid = profiles[*it]->getNodeId();
207
208 neighbors.push_back(nid);
209
210 distance.push_back(GeoTessUtils::angle(model->getGrid().getVertex(nodeid),
211 model->getGrid().getVertex(nid)));
212
213 azimuth.push_back(GeoTessUtils::azimuth(model->getGrid().getVertex(nodeid),
214 model->getGrid().getVertex(nid), NA_VALUE));
215 }
216 }
217
219 // grid nodes.
222 // grid nodes.
223 void getNodeSeparation(const int& node1, const int& node2, double& distance);
224
228 void getNodeAzimuth(const int& node1, const int& node2, double& azimuth);
229
230 size_t memSize();
231
232 string getTessId() { return model->getGrid().getGridID(); }
233
234 int addGeoStack(GeoStack* geoStack)
235 { return 0; };
236
237 GeoTessModelSLBM* getModel() { return model; }
238
239 string toString();
240
241 void setInterpolatorType(const string& interpolatorType);
242
243 string getInterpolatorType() { return position->getInterpolatorType().toString(); }
244
245 private:
246
247 GeoTessModelSLBM* model;
248
249 GeoTessPosition* position;
250
251 };
252
253 inline void GridGeoTess::setInterpolatorType(const string& interpolatorType)
254 {
255 string type = CPPUtils::uppercase_string(interpolatorType);
256 if (position->getInterpolatorType().toString() != type)
257 {
258 if (type == "LINEAR")
259 {
260 delete position;
261 position = model->getPosition(GeoTessInterpolatorType::LINEAR);
262 }
263 else if (type == "NATURAL_NEIGHBOR")
264 {
265 delete position;
266 position = model->getPosition(GeoTessInterpolatorType::NATURAL_NEIGHBOR);
267 }
268 else
269 {
270 ostringstream os;
271 os << endl << "ERROR in GridGeoTess::setInterpolatorType()" << endl
272 << interpolatorType << " is not a recognized interpolator type." << endl
273 << "Must be one of [ LINEAR | NATURAL_NEIGHBOR ]."
274 << "Version " << SlbmVersion << " File " << __FILE__ << " line " << __LINE__ << endl << endl;
275 throw SLBMException(os.str(),114);
276 }
277 }
278 }
279
280 inline void GridGeoTess::getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors)
281 {
282 set<int> nbrs;
283 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
284 nodeId, nbrs);
285 nNeighbors = (int)nbrs.size();
286 set<int>::iterator it;
287 int i=0;
288 for (it=nbrs.begin(); it != nbrs.end(); ++it)
289 neighbors[i++] = *it;
290 }
291
292 inline void GridGeoTess::getNodeNeighbors(const int& nodeId, vector<int>& neighbors)
293 {
294 set<int> nbrs;
295 const int level = model->getGrid().getLastLevel(0);
296 model->getGrid().getVertexNeighbors(0, level, nodeId, nbrs);
297 neighbors.resize(nbrs.size());
298 set<int>::iterator it;
299 int i=0;
300 for (it=nbrs.begin(); it != nbrs.end(); ++it)
301 neighbors[i++] = *it;
302 }
303
304 inline void GridGeoTess::getActiveNodeNeighbors(const int& activeNodeId, int neighbors[], int& nNeighbors)
305 {
306 int nodeId = getGridNodeId(activeNodeId);
307 if (nodeId < 0)
308 nNeighbors = 0;
309 else
310 {
311 set<int> nbrs;
312 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
313 nodeId, nbrs);
314 nNeighbors = 0;
315 int id;
316 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
317 {
318 id = getActiveNodeId(profiles[*it]->getNodeId());
319 if (id >= 0)
320 neighbors[nNeighbors++] = id;
321 }
322 }
323 }
324
325 inline void GridGeoTess::getActiveNodeNeighbors(const int& activeNodeId, vector<int>& neighbors)
326 {
327 neighbors.clear();
328
329 int nodeId = getGridNodeId(activeNodeId);
330 if (nodeId >= 0)
331 {
332 set<int> nbrs;
333 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
334 nodeId, nbrs);
335 int id;
336 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
337 {
338 id = getActiveNodeId(profiles[*it]->getNodeId());
339 if (id >= 0)
340 neighbors.push_back(id);
341 }
342 }
343 }
344
345 inline void GridGeoTess::getNodeSeparation(const int& node1, const int& node2, double& distance)
346 {
347 distance = GeoTessUtils::angle(model->getGrid().getVertex(node1),
348 model->getGrid().getVertex(node2));
349 }
350
351 inline void GridGeoTess::getNodeAzimuth(const int& node1, const int& node2, double& azimuth)
352 {
353 azimuth = GeoTessUtils::azimuth(model->getGrid().getVertex(node1),
354 model->getGrid().getVertex(node2), NaN_DOUBLE);
355 }
356
357 } /* namespace slbm */
358 #endif /* GRIDGEOTESS_H_ */
slbm::GeoStack
Manages all information related to a single node in a Grid object.
Definition: GeoStack.h:65
slbm::GridGeoTess::getModel
GeoTessModelSLBM * getModel()
Definition: GridGeoTess.h:237
slbm::GridGeoTess::setAverageMantleVelocity
void setAverageMantleVelocity(const int &waveType, const double &velocity)
Retreive the average P or S wave velocity of the mantle, in km/sec.
Definition: GridGeoTess.h:99
slbm::Location
The Location Class manages a single point in/on the Earth, which is described by the GRS80 ellipsoid.
Definition: Location.h:78
slbm::GridGeoTess::getInterpolatorType
string getInterpolatorType()
Definition: GridGeoTess.h:243
GeoTessModelPathUnc.h
Grid.h
slbm::GridGeoTess::loadFromDirectory
void loadFromDirectory(const string &dirName)
Load the depth, velocity and gradient information from binary files in specified directory.
slbm::GridGeoTess::getBufferSize
int getBufferSize() const
Returns the size of a DataBuffer object required to store this Grid objects model data.
Definition: GridGeoTess.h:82
slbm::GridGeoTess::addGeoStack
int addGeoStack(GeoStack *geoStack)
Definition: GridGeoTess.h:234
slbm::GridGeoTess::class_name
static string class_name()
Definition: GridGeoTess.h:38
slbm::GridGeoTess::loadFromDataBuffer
void loadFromDataBuffer(util::DataBuffer &buffer)
Load the depth, velocity and gradient information from DataBuffer.
GridProfileGeoTess.h
slbm::GridGeoTess::loadModel
GeoTessModelSLBM * loadModel(const string &filename, const string &relGridPath="")
slbm::GridGeoTess::getAverageMantleVelocity
double getAverageMantleVelocity(const int &waveType)
Retreive the average P or S wave velocity of the mantle, in km/sec.
Definition: GridGeoTess.h:90
slbm::Grid
A 2 dimensional, horizontal grid of GirdProfile objects.
Definition: Grid.h:90
slbm::GridGeoTess::getTessId
string getTessId()
Definition: GridGeoTess.h:232
slbm::GridGeoTess::saveVelocityModel
void saveVelocityModel(const string &filename, const int &format)
Save the Earth model currently in memory, to an ascii flat file.
slbm::GridGeoTess::loadFromFile
void loadFromFile(const string &filename)
Load the depth, velocity and gradient information from an ascii flat file.
slbm::GridGeoTess::getNodeNeighborInfo
void getNodeNeighborInfo(const int &nodeid, vector< int > &neighbors, vector< double > &distance, vector< double > &azimuth)
Retrieve the grid node id of the nodes that are direct neighbors of the specified grid node.
Definition: GridGeoTess.h:189
slbm::GridGeoTess::clear
void clear()
Clears and releases all memory held by this GridSLBM object.
slbm::GridGeoTess::GridGeoTess
GridGeoTess()
slbm::GridGeoTess::findProfile
virtual bool findProfile(Location &location, vector< GridProfile * > &neighbors, vector< int > &nodeIds, vector< double > &coefficients)
Find the neighboring GridProfile objects and associated interpolation coefficients at a specified Loc...
slbm::GridGeoTess::memSize
size_t memSize()
SLBM_EXP_IMP
#define SLBM_EXP_IMP
Definition: SLBMGlobals.h:180
slbm::GridGeoTess::getNodeNeighborInfo
void getNodeNeighborInfo(const int &nodeid, int neighbors[], double distance[], double azimuth[], int &nNeighbors)
Retrieve the grid node id of the nodes that are direct neighbors of the specified grid node.
Definition: GridGeoTess.h:164
slbm::GridGeoTess
Definition: GridGeoTess.h:25
slbm::GridGeoTess::saveVelocityModel
void saveVelocityModel(util::DataBuffer &buffer)
Save the Earth model currently in memory, to a DataBuffer.
slbm::GridGeoTess::toString
string toString()
slbm::SLBMException
An Exception class for Grid and related objects.
Definition: SLBMException.h:55
slbm::GridGeoTess::~GridGeoTess
virtual ~GridGeoTess()
Destructor.
GeoTessModelSLBM.h
slbm
Definition: CrustalProfile.h:59
util::DataBuffer
A byte array container used to hold binary data in the same manner as disk based file system.
Definition: DataBuffer.h:81
slbm::GeoTessModelSLBM
Definition: GeoTessModelSLBM.h:83