GeoTessCPP  2.2
Software to facilitate storage and retrieval of 3D information about the Earth.
GeoTessPolygon3D.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
4 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5 //- retains certain rights in this software.
6 //-
7 //- BSD Open Source License.
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- * Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //- * Redistributions in binary form must reproduce the above copyright
16 //- notice, this list of conditions and the following disclaimer in the
17 //- documentation and/or other materials provided with the distribution.
18 //- * Neither the name of Sandia National Laboratories nor the names of its
19 //- contributors may be used to endorse or promote products derived from
20 //- this software without specific prior written permission.
21 //-
22 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //- POSSIBILITY OF SUCH DAMAGE.
33 //-
34 //- ****************************************************************************
35 
36 #ifndef POLYGON3D_H_
37 #define POLYGON3D_H_
38 
39 // **** _SYSTEM INCLUDES_ ******************************************************
40 
41 #include <cstdio>
42 #include <iostream>
43 #include <iomanip>
44 #include <vector>
45 
46 // use standard library objects
47 using namespace std;
48 
49 // **** _LOCAL INCLUDES_ *******************************************************
50 
51 #include "CPPUtils.h"
52 #include "GeoTessUtils.h"
53 #include "GeoTessGreatCircle.h"
54 #include "IFStreamAscii.h"
55 #include "GeoTessPolygon.h"
56 #include "GeoTessHorizon.h"
57 
58 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
59 
60 namespace geotess {
61 
62 // **** _FORWARD REFERENCES_ ***************************************************
63 
64 class GeoTessPosition;
65 
66 // **** _CLASS DEFINITION_ *****************************************************
67 
115 {
116  private:
117 
118  GeoTessHorizon* bottom;
119 
120  GeoTessHorizon* top;
121 
122  public:
123 
124  ~GeoTessPolygon3D();
125 
126  GeoTessPolygon3D() : GeoTessPolygon(), bottom(NULL), top(NULL)
127  {};
128 
139  GeoTessPolygon3D(vector<double*> points, GeoTessHorizon* h_bottom, GeoTessHorizon* h_top)
140  : GeoTessPolygon(points), bottom(h_bottom), top(h_top)
141  {}
142 
154  GeoTessPolygon3D(double* center, double radius, int nEdges, GeoTessHorizon* h_bottom, GeoTessHorizon* h_top)
155  : GeoTessPolygon(center, radius, nEdges), bottom(h_bottom), top(h_top)
156  {}
157 
166  GeoTessPolygon3D(string filename);
167 
171  virtual string class_name() { return "Polygon3D"; };
172 
177  {
178  return top;
179  }
180 
185  {
186  return bottom;
187  }
188 
202  bool contains(const double* x, const double& radius, const int& layer, GeoTessProfile** profiles)
203  {
204  return (bottom->getLayerIndex() < 0 || layer >= bottom->getLayerIndex())
205  && (top->getLayerIndex() < 0 || layer <= top->getLayerIndex())
206  && radius > bottom->getRadius(x, profiles) - 1e-4
207  && radius < top->getRadius(x, profiles) + 1e-4
208  && GeoTessPolygon::contains(x);
209  }
210 
218  bool contains(const double* x, const int& layer)
219  {
220  return ( bottom->getLayerIndex() < 0 || layer >= bottom->getLayerIndex())
221  && ( top->getLayerIndex() < 0 || layer <= top->getLayerIndex())
222  && GeoTessPolygon::contains(x);
223  }
224 
231  bool contains(GeoTessPosition& position);
232 
244  bool containsAll(vector<double*>& points, vector<double>& radii, vector<int>& layers, vector<GeoTessProfile**>& profiles)
245  {
246  for (int i=0; i<(int)points.size(); ++i)
247  if (!contains(points[i], radii[i], layers[i], profiles[i]))
248  return false;
249  return true;
250  }
251 
263  bool containsAny(vector<double*>& points, vector<double>& radii, vector<int>& layers, vector<GeoTessProfile**>& profiles)
264  {
265  for (int i=0; i<(int)points.size(); ++i)
266  if (contains(points[i], radii[i], layers[i], profiles[i]))
267  return true;
268  return false;
269  }
270 
271  virtual void write(const string& outputFileName);
272 
274 
275  virtual void loadAscii(vector<string>& records);
276 
278 
279 }; // end class Polygon
280 
281 } // end namespace geotess
282 
283 #endif /* POLYGON3D_H_ */
virtual double getRadius(const double *position, GeoTessProfile **profiles)
Return the radius of the Horizon at the specified geographic position and constrained by the specifie...
An ordered list of points on the surface of a unit sphere that define a closed polygon.
Definition: GeoTessPolygon.h:111
Information about an interpolated point at an arbitrary position in a model.
Definition: GeoTessPosition.h:101
GeoTessPolygon3D(double *center, double radius, int nEdges, GeoTessHorizon *h_bottom, GeoTessHorizon *h_top)
Constructor that builds a circular polygon of a specified horizontal radius centered on position cent...
Definition: GeoTessPolygon3D.h:154
bool contains(const double *x, const double &radius, const int &layer, GeoTessProfile **profiles)
Returns true if this Polygon3D contains the specified position.
Definition: GeoTessPolygon3D.h:202
GeoTessPolygon3D(vector< double * > points, GeoTessHorizon *h_bottom, GeoTessHorizon *h_top)
Constructor that accepts a list of unit vectors that define the polygon.
Definition: GeoTessPolygon3D.h:139
Definition: ArrayReuse.h:55
An abstract class that represents a single "surface" within a model.
Definition: GeoTessHorizon.h:79
bool contains(const double *x, const int &layer)
Returns true if this Polygon3D contains the specified position.
Definition: GeoTessPolygon3D.h:218
GeoTessHorizon * getBottom()
Retrieve a reference to the Horizon that defines the bottom of the active region. ...
Definition: GeoTessPolygon3D.h:184
virtual string class_name()
Returns the class name.
Definition: GeoTessPolygon3D.h:171
Extends Polygon by including information and constraints about the radial dimension.
Definition: GeoTessPolygon3D.h:114
bool containsAny(vector< double * > &points, vector< double > &radii, vector< int > &layers, vector< GeoTessProfile ** > &profiles)
Returns true if this Polygon contains any of the supplied unit vectors.
Definition: GeoTessPolygon3D.h:263
GeoTessHorizon * getTop()
Retrieve a reference to the Horizon that defines the top of the active region.
Definition: GeoTessPolygon3D.h:176
bool containsAll(vector< double * > &points, vector< double > &radii, vector< int > &layers, vector< GeoTessProfile ** > &profiles)
Returns true if this Polygon contains all of the supplied unit vectors.
Definition: GeoTessPolygon3D.h:244
Abstract class that manages the radii and data values that span a single layer associated with a sing...
Definition: GeoTessProfile.h:96
GeoTessPolygon3D()
Definition: GeoTessPolygon3D.h:126
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
virtual int getLayerIndex()
Retrieve the index of the layer that was specified at construction.
Definition: GeoTessHorizon.h:146