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 PROFILECONSTANT_OBJECT_H 00037 #define PROFILECONSTANT_OBJECT_H 00038 00039 // **** _SYSTEM INCLUDES_ ****************************************************** 00040 00041 #include <iostream> 00042 #include <string> 00043 #include <fstream> 00044 00045 // use standard library objects 00046 using namespace std; 00047 00048 // **** _LOCAL INCLUDES_ ******************************************************* 00049 00050 #include "Data.h" 00051 #include "Profile.h" 00052 #include "ProfileType.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 00076 class GEOTESS_EXP_IMP ProfileConstant : virtual public Profile 00077 { 00078 private: 00079 00083 float radiusBottom; 00084 00088 float radiusTop; 00089 00093 Data* data; 00094 00098 int pointIndex; 00099 00103 ProfileConstant() : Profile(), radiusBottom(0.0), radiusTop(0.0), 00104 data(NULL), pointIndex(-1) {}; 00105 00106 public: 00107 00111 ProfileConstant(float radBot, float radTop, Data* dat) : 00112 Profile(), radiusBottom(radBot), radiusTop(radTop), 00113 data(dat), pointIndex(-1) {}; 00114 00118 static string class_name() { return "ProfileConstant"; }; 00119 00123 virtual int class_size() const 00124 { return (int) sizeof(ProfileConstant); }; 00125 00131 virtual const ProfileType& getType() const 00132 { return ProfileType::CONSTANT; }; 00133 00137 virtual bool operator == (const Profile& p) const 00138 { return (Profile::operator==(p) && 00139 (radiusBottom == p.getRadiusBottom()) && 00140 (radiusTop == p.getRadiusTop()) && 00141 (*data == p.getData(0))); 00142 } 00143 00148 virtual float getRadius(int i) const 00149 { return i == 0 ? radiusBottom : radiusTop; }; 00150 00154 virtual int getNRadii() const { return 2; }; 00155 00159 virtual int getNData() const { return 1; }; 00160 00164 virtual float* getRadii() 00165 { float* fa = new float [2]; fa[0] = radiusBottom; fa[1] = radiusTop; return fa; }; 00166 00170 virtual Data** getData() 00171 { Data** da = new Data* [1]; da[0] = data; return da; }; 00172 00176 virtual Data* getData(int i) { return data; }; 00177 00181 virtual const Data& getData(int i) const { return *data; }; 00182 00186 virtual void setData(const vector<Data*>& inData) 00187 { delete data; data = inData[0]; } 00188 00192 virtual void setData(int index, Data* inData) 00193 { delete data; data = inData; } 00194 00203 virtual double getValue(int attributeIndex, int nodeIndex) const 00204 { return nodeIndex <= 1 ? data->getDouble(attributeIndex) : NaN_DOUBLE; } 00205 00215 virtual double getValue(const InterpolatorType& rInterpType, 00216 int attributeIndex, double radius, bool allowRadiusOutOfRange) const 00217 { 00218 if (!allowRadiusOutOfRange && 00219 ((radius < getRadiusBottom()) || (radius > getRadiusTop()))) 00220 return NaN_DOUBLE; 00221 00222 // default behavior is to simply return the data value for the first 00223 // data object. This works for all the Profile classes that only support 00224 // a single Data object like ProfileConstant, ProfileSurface, and 00225 // ProfileThin. Profile classes for which the number of supported 00226 // Data objects is not equal to 1 must override this method. 00227 00228 return getValue(attributeIndex, 0); 00229 }; 00230 00237 virtual double getValueTop(int attributeIndex) const 00238 { return data->getDouble(attributeIndex); } 00239 00250 virtual bool isNaN(int nodeIndex, int attributeIndex) 00251 { 00252 return nodeIndex != 0 || data->isNaN(attributeIndex); 00253 } 00254 00258 virtual void setRadii(const vector<float>& newRadii) 00259 { radiusBottom = newRadii[0]; radiusTop = newRadii[1]; } 00260 00264 virtual float getRadiusTop() const { return radiusTop; }; 00265 00269 virtual const Data& getDataTop() const { return *data; }; 00270 00274 virtual Data* getDataTop() { return data; }; 00275 00279 virtual float getRadiusBottom() const { return radiusBottom; }; 00280 00284 virtual const Data& getDataBottom() const { return *data; }; 00285 00289 virtual Data* getDataBottom() { return data; }; 00290 00292 00296 ProfileConstant(IFStreamBinary& ifs, GeoTessMetaData& gtmd) : Profile() 00297 { radiusBottom = ifs.readFloat(); radiusTop = ifs.readFloat(); 00298 data = Data::getData(ifs, gtmd); }; 00299 00303 ProfileConstant(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : Profile() 00304 { radiusBottom = ifs.readFloat(); 00305 radiusTop = ifs.readFloat(); 00306 data = Data::getData(ifs, gtmd); }; 00307 00312 virtual ~ProfileConstant() { if (data != NULL) delete data; }; 00313 00317 virtual void write(IFStreamBinary& ofs) 00318 { 00319 ofs.writeByte((byte) ProfileType::CONSTANT.ordinal()); 00320 ofs.writeFloat(radiusBottom); 00321 ofs.writeFloat(radiusTop); 00322 data->write(ofs); 00323 }; 00324 00328 virtual void write(IFStreamAscii& ofs) 00329 { ofs.writeInt(ProfileType::CONSTANT.ordinal()); 00330 ofs.writeString(" "); 00331 ofs.writeFloat(radiusBottom); 00332 ofs.writeString(" "); 00333 ofs.writeFloat(radiusTop); 00334 data->write(ofs); 00335 ofs.writeNL(); 00336 }; 00337 00346 virtual int findClosestRadiusIndex(double radius) const 00347 { return abs(radiusTop - radius) < abs(radiusBottom - radius) ? 1 : 0; } 00348 00356 virtual void setPointIndex(int nodeIndex, int pntIndex) 00357 { pointIndex = pntIndex; } 00358 00366 virtual void resetPointIndices() { pointIndex = -1; } 00367 00375 virtual int getPointIndex(int nodeIndex) const 00376 { return pointIndex; } 00377 00381 virtual Profile* copy() 00382 { 00383 return new ProfileConstant(radiusBottom, radiusTop, data->copy()); 00384 } 00385 00387 00388 }; // end class ProfileConstant 00389 00390 } // end namespace geotess 00391 00392 #endif // PROFILECONSTANT_OBJECT_H