GeoTessCPP  2.0.0
Software to facilitate storage and retrieval of 3D information about the Earth.
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Polygon3D.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 "GreatCircle.h"
54 #include "IFStreamAscii.h"
55 #include "Polygon.h"
56 #include "Horizon.h"
57 
58 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
59 
60 namespace geotess {
61 
62 // **** _FORWARD REFERENCES_ ***************************************************
63 
64 // **** _CLASS DEFINITION_ *****************************************************
65 
122 {
123  private:
124 
125  Horizon* bottom;
126 
127  Horizon* top;
128 
129  public:
130 
131  ~Polygon3D();
132 
133  Polygon3D() : Polygon(), bottom(NULL), top(NULL)
134  {};
135 
146  Polygon3D(vector<double*> points, Horizon* h_bottom, Horizon* h_top)
147  : Polygon(points), bottom(h_bottom), top(h_top)
148  {}
149 
161  Polygon3D(double* center, double radius, int nEdges, Horizon* h_bottom, Horizon* h_top)
162  : Polygon(center, radius, nEdges), bottom(h_bottom), top(h_top)
163  {}
164 
173  Polygon3D(string filename);
174 
178  virtual string class_name() { return "Polygon3D"; };
179 
183  Horizon* getTop()
184  {
185  return top;
186  }
187 
191  Horizon* getBottom()
192  {
193  return bottom;
194  }
195 
196  bool contains(const double* x)
197  {
198  return Polygon::contains(x);
199  }
200 
201  bool contains(const double* x, const double& radius, const int& layer, Profile** profiles)
202  {
203  return (bottom->getLayerIndex() < 0 || layer >= bottom->getLayerIndex())
204  && (top->getLayerIndex() < 0 || layer <= top->getLayerIndex())
205  && radius > bottom->getRadius(x, profiles) - 1e-4
206  && radius < top->getRadius(x, profiles) + 1e-4
207  && Polygon::contains(x);
208  }
209 
210  bool contains(const double* x, const int& layer)
211  {
212  return ( bottom->getLayerIndex() < 0 || layer >= bottom->getLayerIndex())
213  && ( top->getLayerIndex() < 0 || layer <= top->getLayerIndex())
214  && Polygon::contains(x);
215  }
216 
228  bool containsAll(vector<double*>& points, vector<double>& radii, vector<int>& layers, vector<Profile**>& profiles)
229  {
230  for (int i=0; i<(int)points.size(); ++i)
231  if (!contains(points[i], radii[i], layers[i], profiles[i]))
232  return false;
233  return true;
234  }
235 
247  bool containsAny(vector<double*>& points, vector<double>& radii, vector<int>& layers, vector<Profile**>& profiles)
248  {
249  for (int i=0; i<(int)points.size(); ++i)
250  if (contains(points[i], radii[i], layers[i], profiles[i]))
251  return true;
252  return false;
253  }
254 
255  virtual void write(const string& outputFileName);
256 
258 
259  virtual void loadAscii(IFStreamAscii& input);
260 
262 
263 }; // end class Polygon
264 
265 } // end namespace geotess
266 
267 #endif /* POLYGON3D_H_ */