GeoTessCPP
2.0.0
Software to facilitate storage and retrieval of 3D information about the Earth.
|
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 PROFILETHIN_OBJECT_H 00037 #define PROFILETHIN_OBJECT_H 00038 00039 // **** _SYSTEM INCLUDES_ ****************************************************** 00040 00041 #include <iostream> 00042 #include <fstream> 00043 #include <string> 00044 00045 // use standard library objects 00046 using namespace std; 00047 00048 // **** _LOCAL INCLUDES_ ******************************************************* 00049 00050 #include "GeoTessData.h" 00051 #include "GeoTessProfile.h" 00052 #include "GeoTessProfileType.h" 00053 #include "IFStreamAscii.h" 00054 #include "IFStreamBinary.h" 00055 00056 // **** _BEGIN GEOTESS NAMESPACE_ ********************************************** 00057 00058 namespace geotess { 00059 00060 // **** _FORWARD REFERENCES_ *************************************************** 00061 00062 class GeoTessMetaData; 00063 00064 // **** _CLASS DEFINITION_ ***************************************************** 00065 00073 class GEOTESS_EXP_IMP GeoTessProfileThin : virtual public GeoTessProfile 00074 { 00075 private: 00076 00080 float radius; 00081 00085 GeoTessData* data; 00086 00090 int pointIndex; 00091 00095 GeoTessProfileThin() : GeoTessProfile(), radius(0.0), data(NULL), 00096 pointIndex(-1) {}; 00097 00098 public: 00099 00103 GeoTessProfileThin(float rad, GeoTessData* dat) : 00104 GeoTessProfile(), radius(rad), data(dat), 00105 pointIndex(-1) {}; 00106 00110 static string class_name() { return "ProfileThin"; }; 00111 00115 virtual int class_size() const 00116 { return (int) sizeof(GeoTessProfileThin); }; 00117 00123 virtual const GeoTessProfileType& getType() const 00124 { return GeoTessProfileType::THIN; }; 00125 00129 virtual bool operator == (const GeoTessProfile& p) const 00130 { return (GeoTessProfile::operator==(p) && (radius == p.getRadius(0)) && (*data == p.getData(0))); } 00131 00140 virtual double getValue(int attributeIndex, int nodeIndex) const 00141 { return nodeIndex == 0 ? data->getDouble(attributeIndex) : NaN_DOUBLE; } 00142 00152 virtual double getValue(const GeoTessInterpolatorType& rInterpType, 00153 int attributeIndex, double r, bool allowRadiusOutOfRange) const 00154 { 00155 if (!allowRadiusOutOfRange && 00156 ((r < getRadiusBottom()) || (r > getRadiusTop()))) 00157 return NaN_DOUBLE; 00158 00159 // default behavior is to simply return the data value for the first 00160 // data object. This works for all the Profile classes that only support 00161 // a single Data object like ProfileConstant, ProfileSurface, and 00162 // ProfileThin. Profile classes for which the number of supported 00163 // Data objects is not equal to 1 must override this method. 00164 00165 return getValue(attributeIndex, 0); 00166 }; 00167 00174 virtual double getValueTop(int attributeIndex) const 00175 { return data->getDouble(attributeIndex); } 00176 00187 virtual bool isNaN(int nodeIndex, int attributeIndex) 00188 { 00189 return nodeIndex != 0 || data->isNaN(attributeIndex); 00190 } 00191 00196 virtual float getRadius(int i) const { return radius; }; 00197 00201 virtual int getNRadii() const { return 1; }; 00202 00206 virtual int getNData() const { return 1; }; 00207 00211 virtual float* getRadii() 00212 { float* fa = new float [1]; fa[0] = radius; return fa; }; 00213 00217 virtual GeoTessData** getData() 00218 { GeoTessData** da = new GeoTessData* [1]; da[0] = data; return da; }; 00219 00223 virtual GeoTessData* getData(int i) { return data; }; 00224 00228 virtual const GeoTessData& getData(int i) const { return *data; }; 00229 00233 virtual void setData(const vector<GeoTessData*>& inData) 00234 { delete data; data = inData[0]; } 00235 00239 virtual void setRadii(const vector<float>& newRadii) 00240 { radius = newRadii[0]; } 00241 00245 virtual void setData(int index, GeoTessData* inData) 00246 { delete data; data = inData; } 00247 00251 virtual float getRadiusTop() const { return radius; }; 00252 00256 virtual const GeoTessData& getDataTop() const { return *data; }; 00257 00261 virtual GeoTessData* getDataTop() { return data; }; 00262 00266 virtual float getRadiusBottom() const { return radius; }; 00267 00271 virtual const GeoTessData& getDataBottom() const { return *data; }; 00272 00276 virtual GeoTessData* getDataBottom() { return data; }; 00277 00279 00283 GeoTessProfileThin(IFStreamBinary& ifs, GeoTessMetaData& gtmd) : GeoTessProfile(), 00284 radius(-1.0), data(NULL), pointIndex(-1) 00285 { radius = ifs.readFloat(); data = GeoTessData::getData(ifs, gtmd); }; 00286 00290 GeoTessProfileThin(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : GeoTessProfile(), 00291 radius(-1.0), data(NULL), pointIndex(-1) 00292 { radius = ifs.readFloat(); data = GeoTessData::getData(ifs, gtmd); }; 00293 00298 virtual ~GeoTessProfileThin() { if (data != NULL) delete data; }; 00299 00303 virtual void write(IFStreamBinary& ofs) 00304 { ofs.writeByte((byte) GeoTessProfileType::THIN.ordinal()); 00305 ofs.writeFloat(radius); data->write(ofs); }; 00306 00310 virtual void write(IFStreamAscii& ofs) 00311 { ofs.writeInt(GeoTessProfileType::THIN.ordinal()); 00312 ofs.writeString(" "); 00313 ofs.writeFloat(radius); 00314 data->write(ofs); 00315 ofs.writeNL(); }; 00316 00325 virtual int findClosestRadiusIndex(double r) const 00326 { return 0; } 00327 00335 virtual void setPointIndex(int nodeIndex, int pntIndex) 00336 { pointIndex = pntIndex; } 00337 00345 virtual void resetPointIndices() { pointIndex = -1; } 00346 00354 virtual int getPointIndex(int nodeIndex) const 00355 { return pointIndex; } 00356 00360 virtual GeoTessProfile* copy() 00361 { 00362 return new GeoTessProfileThin(radius, data->copy()); 00363 } 00364 00366 00367 }; // end class ProfileThin 00368 00369 } // end namespace geotess 00370 00371 #endif // PROFILETHIN_OBJECT_H