1 //----------------------------------------------------------------------------
2 //
3 // License:  see top level LICENSE.txt
4 //
5 // Author:  Garrett Potts
6 //
7 // Description:
8 //
9 //
10 //----------------------------------------------------------------------------
11 // $Id: ossimGeneralRasterElevHandler.h 23117 2015-01-29 22:33:13Z okramer $
12 #ifndef ossimGeneralRasterElevHandler_HEADER
13 #define ossimGeneralRasterElevHandler_HEADER
14 #include <list>
15 #include <ossim/base/ossimIoStream.h>
16 //#include <fstream>
17 
18 #include <ossim/base/ossimString.h>
19 #include <ossim/base/ossimDatum.h>
20 #include <ossim/elevation/ossimElevCellHandler.h>
21 #include <ossim/imaging/ossimGeneralRasterInfo.h>
22 #include <ossim/imaging/ossimImageHandlerRegistry.h>
23 #include <ossim/imaging/ossimImageHandler.h>
24 #include <ossim/imaging/ossimImageSource.h>
25 #include <ossim/imaging/ossimImageGeometry.h>
26 #include <ossim/projection/ossimProjectionFactoryRegistry.h>
27 #include <ossim/projection/ossimMapProjection.h>
28 #include <ossim/projection/ossimImageViewTransform.h>
29 #include <ossim/base/ossimKeywordlist.h>
30 #include <ossim/base/ossimDpt.h>
31 #include <ossim/base/ossimGpt.h>
32 #include <mutex>
33 class ossimProjection;
34 /**
35  * @class ossimGeneralRasterElevHandler Elevation source for an srtm file.
36  */
37 class  OSSIM_DLL ossimGeneralRasterElevHandler : public ossimElevCellHandler
38 {
39 public:
40    class GeneralRasterInfo
41       {
42       public:
GeneralRasterInfo()43          GeneralRasterInfo()
44          :theWidth(0),
45          theHeight(0),
46          theNullHeightValue(ossim::nan()),
47          theScalarType(OSSIM_SCALAR_UNKNOWN),
48          theBytesPerRawLine(0),
49          theDatum(0),
50          theGeometry(0)
51          {
52          }
GeneralRasterInfo(const ossimGeneralRasterElevHandler::GeneralRasterInfo & src)53          GeneralRasterInfo(const  ossimGeneralRasterElevHandler::GeneralRasterInfo& src)
54          :theFilename(src.theFilename),
55          theImageRect(src.theImageRect),
56          theUl(src.theUl),
57          theLr(src.theLr),
58          theWidth(src.theWidth),
59          theHeight(src.theHeight),
60          theWgs84GroundRect(src.theWgs84GroundRect),
61          theNullHeightValue(src.theNullHeightValue),
62          theByteOrder(src.theByteOrder),
63          theScalarType(src.theScalarType),
64          theBytesPerRawLine(src.theBytesPerRawLine),
65          theDatum(src.theDatum),
66          theGeometry(src.theGeometry)
67          {
68          }
69          ossimFilename     theFilename;
70          ossimIrect        theImageRect;
71          ossimIpt          theUl;
72          ossimIpt          theLr;
73          ossim_uint32      theWidth;
74          ossim_uint32      theHeight;
75          ossimDrect        theWgs84GroundRect;
76          ossim_float64     theNullHeightValue;
77          ossimByteOrder    theByteOrder;
78          ossimScalarType   theScalarType;
79          ossim_uint32      theBytesPerRawLine;
80          const ossimDatum* theDatum;
81          ossimRefPtr<ossimImageGeometry> theGeometry;  //add by simbla
82       };
83    ossimGeneralRasterElevHandler(const ossimFilename& file="");
84    ossimGeneralRasterElevHandler(const ossimGeneralRasterElevHandler::GeneralRasterInfo& generalRasterInfo);
85    ossimGeneralRasterElevHandler(const ossimGeneralRasterElevHandler& rhs);
86 
87    /** destructor */
88    virtual ~ossimGeneralRasterElevHandler();
89 
dup()90    virtual ossimObject* dup() const { return new ossimGeneralRasterElevHandler(this->theFilename); }
91 
92 
93    /**
94     * METHOD: getHeightAboveMSL
95     * Height access methods.
96     */
97    virtual double getHeightAboveMSL(const ossimGpt&);
98 
99    /**
100     *  METHOD:  getSizeOfElevCell
101     *  Returns the number of post in the cell.  Satisfies pure virtual.
102     *  Note:  x = longitude, y = latitude
103     */
104    virtual ossimIpt getSizeOfElevCell() const;
105 
106    /**
107     *  METHOD:  getPostValue
108     *  Returns the value at a given grid point as a double.
109     *  Satisfies pure virtual.
110     */
111    virtual double getPostValue(const ossimIpt& gridPt) const;
112 
113    virtual bool isOpen()const;
114 
115    /**
116     * Opens a stream to the srtm cell.
117     *
118     * @return Returns true on success, false on error.
119     */
120    bool open(const ossimFilename& file, bool memoryMapFlag=false);
121 
122    /**
123     * Closes the stream to the file.
124     */
125    virtual void close();
126 
127    /**
128     * This method does not really fit the handler since this handle a
129     * directory not a cell that could have holes in it.  So users looking for
130     * valid coverage should call "pointHasCoverage".
131     */
132    ossimDrect getBoundingRect()const;
133 
134    /**
135     * Loops through ossimGeneralRasterElevHandler::BoundingRectListType and
136     * checks for coverage.
137     *
138     * @param gpt Point to look for.
139     *
140     * @return true if coverage is found false if not.
141     */
142    virtual bool pointHasCoverage(const ossimGpt& gpt) const;
143 
144    const ossimGeneralRasterElevHandler::GeneralRasterInfo& generalRasterInfo()const;
145 
146 private:
147    template <class T>
148    double getHeightAboveMSLFileTemplate(T dummy,
149                                     const ossimGeneralRasterElevHandler::GeneralRasterInfo& info,
150                                     const ossimGpt& gpt);
151    template <class T>
152    double getHeightAboveMSLMemoryTemplate(T dummy,
153                                     const ossimGeneralRasterElevHandler::GeneralRasterInfo& info,
154                                     const ossimGpt& gpt);
155 
156    virtual bool setFilename(const ossimFilename& file);
157 
158    ossimGeneralRasterElevHandler::GeneralRasterInfo theGeneralRasterInfo;
159    mutable std::mutex m_inputStreamMutex;
160    std::ifstream m_inputStream;
161 
162    /** @brief true if stream is open. */
163    bool          m_streamOpen;
164 
165    std::vector<char> m_memoryMap;
166 TYPE_DATA
167 };
168 
169 #endif /* End of "#ifndef ossimGeneralRasterElevHandler_HEADER" */
170