GeoTessCPP  2.0.0
Software to facilitate storage and retrieval of 3D information about the Earth.
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
include/Polygon3D.h
Go to the documentation of this file.
00001 //- ****************************************************************************
00002 //- 
00003 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
00004 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00005 //- retains certain rights in this software.
00006 //- 
00007 //- BSD Open Source License.
00008 //- All rights reserved.
00009 //- 
00010 //- Redistribution and use in source and binary forms, with or without
00011 //- modification, are permitted provided that the following conditions are met:
00012 //- 
00013 //-    * Redistributions of source code must retain the above copyright notice,
00014 //-      this list of conditions and the following disclaimer.
00015 //-    * Redistributions in binary form must reproduce the above copyright
00016 //-      notice, this list of conditions and the following disclaimer in the
00017 //-      documentation and/or other materials provided with the distribution.
00018 //-    * Neither the name of Sandia National Laboratories nor the names of its
00019 //-      contributors may be used to endorse or promote products derived from
00020 //-      this software without specific prior written permission.
00021 //- 
00022 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00026 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00027 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00028 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00029 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00030 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00031 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 //- POSSIBILITY OF SUCH DAMAGE.
00033 //-
00034 //- ****************************************************************************
00035 
00036 #ifndef POLYGON3D_H_
00037 #define POLYGON3D_H_
00038 
00039 // **** _SYSTEM INCLUDES_ ******************************************************
00040 
00041 #include <cstdio>
00042 #include <iostream>
00043 #include <iomanip>
00044 #include <vector>
00045 
00046 // use standard library objects
00047 using namespace std;
00048 
00049 // **** _LOCAL INCLUDES_ *******************************************************
00050 
00051 #include "CPPUtils.h"
00052 #include "GeoTessUtils.h"
00053 #include "GreatCircle.h"
00054 #include "IFStreamAscii.h"
00055 #include "Polygon.h"
00056 #include "Horizon.h"
00057 
00058 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
00059 
00060 namespace geotess {
00061 
00062 // **** _FORWARD REFERENCES_ ***************************************************
00063 
00064 class GeoTessPosition;
00065 
00066 // **** _CLASS DEFINITION_ *****************************************************
00067 
00114 class GEOTESS_EXP_IMP Polygon3D : public Polygon
00115 {
00116   private:
00117 
00118         Horizon* bottom;
00119 
00120         Horizon* top;
00121 
00122   public:
00123 
00124         ~Polygon3D();
00125 
00126         Polygon3D() : Polygon(), bottom(NULL), top(NULL)
00127         {};
00128 
00139         Polygon3D(vector<double*> points, Horizon* h_bottom, Horizon* h_top)
00140         : Polygon(points), bottom(h_bottom), top(h_top)
00141         {}
00142 
00154         Polygon3D(double* center, double radius, int nEdges, Horizon* h_bottom, Horizon* h_top)
00155         : Polygon(center, radius, nEdges), bottom(h_bottom), top(h_top)
00156         {}
00157 
00166         Polygon3D(string filename);
00167 
00171         virtual string class_name() { return "Polygon3D"; };
00172 
00176         Horizon* getTop()
00177         {
00178                 return top;
00179         }
00180 
00184         Horizon* getBottom()
00185         {
00186                 return bottom;
00187         }
00188 
00202         bool contains(const double* x, const double& radius, const int& layer, Profile** profiles)
00203                 {
00204                 return (bottom->getLayerIndex() < 0 || layer >= bottom->getLayerIndex())
00205                                 && (top->getLayerIndex() < 0 || layer <= top->getLayerIndex())
00206                                 && radius > bottom->getRadius(x, profiles) - 1e-4
00207                                 && radius < top->getRadius(x, profiles) + 1e-4
00208                                 && Polygon::contains(x);
00209         }
00210 
00218         bool contains(const double* x, const int& layer)
00219         {
00220                 return ( bottom->getLayerIndex() < 0 || layer >= bottom->getLayerIndex())
00221                                 && ( top->getLayerIndex() < 0 || layer <= top->getLayerIndex())
00222                                 && Polygon::contains(x);
00223         }
00224 
00231         bool contains(GeoTessPosition& position);
00232 
00244         bool containsAll(vector<double*>& points, vector<double>& radii, vector<int>& layers, vector<Profile**>& profiles)
00245         {
00246                 for (int i=0; i<(int)points.size(); ++i)
00247                         if (!contains(points[i], radii[i], layers[i], profiles[i]))
00248                                 return false;
00249                 return true;
00250         }
00251 
00263         bool containsAny(vector<double*>& points, vector<double>& radii, vector<int>& layers, vector<Profile**>& profiles)
00264         {
00265                 for (int i=0; i<(int)points.size(); ++i)
00266                         if (contains(points[i], radii[i], layers[i], profiles[i]))
00267                                 return true;
00268                 return false;
00269         }
00270 
00271         virtual void write(const string& outputFileName);
00272 
00274 
00275         virtual void loadAscii(vector<string>& records);
00276 
00278 
00279 }; // end class Polygon
00280 
00281 } // end namespace geotess
00282 
00283 #endif /* POLYGON3D_H_ */