GeoTessCPP  2.6.1
Software to facilitate storage and retrieval of 3D information about the Earth.
All Classes Namespaces Files Functions Variables Typedefs Friends Macros
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 
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_ */
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
An abstract class that represents a single "surface" within a model.
virtual double getRadius(const double *position, GeoTessProfile **profiles)
virtual int getLayerIndex()
Extends Polygon by including information and constraints about the radial dimension.
bool containsAll(vector< double * > &points, vector< double > &radii, vector< int > &layers, vector< GeoTessProfile ** > &profiles)
GeoTessPolygon3D(vector< double * > points, GeoTessHorizon *h_bottom, GeoTessHorizon *h_top)
bool contains(const double *x, const double &radius, const int &layer, GeoTessProfile **profiles)
GeoTessHorizon * getTop()
GeoTessHorizon * getBottom()
bool contains(const double *x, const int &layer)
virtual void write(const string &outputFileName)
bool contains(GeoTessPosition &position)
GeoTessPolygon3D(string filename)
bool containsAny(vector< double * > &points, vector< double > &radii, vector< int > &layers, vector< GeoTessProfile ** > &profiles)
GeoTessPolygon3D(double *center, double radius, int nEdges, GeoTessHorizon *h_bottom, GeoTessHorizon *h_top)
An ordered list of points on the surface of a unit sphere that define a closed polygon.
Information about an interpolated point at an arbitrary position in a model.
Abstract class that manages the radii and data values that span a single layer associated with a sing...