OTB  9.0.0
Orfeo Toolbox
otbDEMHandler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbDEMHandler_h
22 #define otbDEMHandler_h
23 
24 #include "otbImage.h"
25 #include "otbGDALDatasetWrapper.h"
26 #include <string>
27 #include <list>
28 #include <vector>
29 #include <memory>
30 
31 namespace otb
32 {
33 
40 {
41 public:
42  virtual void Update() = 0;
43 protected:
44  DEMObserverInterface() = default;
45  ~DEMObserverInterface() = default;
48 };
49 
56 {
57 public:
58  virtual void AttachObserver(DEMObserverInterface *observer) = 0;
59  virtual void DetachObserver(DEMObserverInterface *observer) = 0;
60  virtual void Notify() const = 0;
61 protected:
62  DEMSubjectInterface() = default;
63  ~DEMSubjectInterface() = default;
66 };
67 
68 // Forward declaration of the class at this point. No need to expose the
69 // full class definition.
70 class DEMHandlerTLS;
71 
114 {
115 public:
116  using Self = DEMHandler;
117  using PointType = itk::Point<double, 2>;
118 
120  static DEMHandler & GetInstance();
121 
125  void OpenDEMDirectory(std::string DEMDirectory);
126 
130  void OpenDEMFile(std::string path);
131 
135  bool IsValidDEMDirectory(const std::string& DEMDirectory) const;
136 
140  bool OpenGeoidFile(std::string geoidFile);
141 
151  double GetHeightAboveEllipsoid(double lon, double lat) const;
152 
153  double GetHeightAboveEllipsoid(const PointType& geoPoint) const;
154 
164  double GetHeightAboveMSL(double lon, double lat) const;
165  double GetHeightAboveMSL(const PointType& geoPoint) const;
167 
173  double GetGeoidHeight(double lon, double lat) const;
174  double GetGeoidHeight(const PointType& geoPoint) const;
176 
178  std::size_t GetDEMCount() const noexcept;
179 
180  double GetDefaultHeightAboveEllipsoid() const noexcept;
181 
182  void SetDefaultHeightAboveEllipsoid(double height);
183 
189  std::string const& GetDEMDirectory(std::size_t idx = 0) const;
190 
191  std::size_t GetNumberOfDEMDirectories() const noexcept
192  { return m_DEMDirectories.size(); }
193 
195  std::string const& GetGeoidFile() const noexcept;
196 
201 
206  void AttachObserver(DEMObserverInterface *observer) override {m_ObserverList.push_back(observer);};
207 
209  void DetachObserver(DEMObserverInterface *observer) override {m_ObserverList.remove(observer);};
210 
212  void Notify() const override;
213 
215  static constexpr char const* DEM_DATASET_PATH = "/vsimem/otb_dem_dataset.vrt";
216  static constexpr char const* DEM_WARPED_DATASET_PATH = "/vsimem/otb_dem_warped_dataset.vrt";
217  static constexpr char const* DEM_SHIFTED_DATASET_PATH = "/vsimem/otb_dem_shifted_dataset.vrt";
218 
238  DEMHandlerTLS const& GetHandlerForCurrentThread() const;
239 
240 protected:
245  DEMHandler();
246 
252  ~DEMHandler();
253 
254 private:
255 
259  std::shared_ptr<DEMHandlerTLS> DoFetchOrCreateHandler() const;
260 
270  void RegisterConfigurationInHandler(DEMHandlerTLS & handler) const;
271 
272  DEMHandler(const Self&) = delete;
273  void operator=(const Self&) = delete;
274 
277 
279  std::vector<std::string> m_DEMDirectories;
280 
282  std::vector<otb::GDALDatasetWrapper::Pointer> m_DatasetList;
283 
285  std::string m_GeoidFilename;
286 
288  std::list<DEMObserverInterface *> m_ObserverList;
289 
291  mutable std::vector<std::shared_ptr<DEMHandlerTLS>> m_tlses;
292 };
293 
294 
307 double GetHeightAboveEllipsoid(DEMHandlerTLS const&, double lon, double lat);
309 double GetHeightAboveMSL (DEMHandlerTLS const&, double lon, double lat);
310 double GetGeoidHeight (DEMHandlerTLS const&, double lon, double lat);
311 double GetHeightAboveEllipsoid(DEMHandlerTLS const&, itk::Point<double, 2> geoPoint);
312 double GetHeightAboveMSL (DEMHandlerTLS const&, itk::Point<double, 2> geoPoint);
313 double GetGeoidHeight (DEMHandlerTLS const&, itk::Point<double, 2> geoPoint);
315 
316 
317 }
318 #endif
otb::DEMHandler::DetachObserver
void DetachObserver(DEMObserverInterface *observer) override
Definition: otbDEMHandler.h:209
otb::DEMHandler::ClearElevationParameters
void ClearElevationParameters()
otb::DEMObserverInterface
Observer design pattern to keep track of DEM configuration changes.
Definition: otbDEMHandler.h:39
otb::DEMHandler::GetInstance
static DEMHandler & GetInstance()
otb::GetHeightAboveMSL
double GetHeightAboveMSL(DEMHandlerTLS const &, double lon, double lat)
otb::DEMHandler::RegisterConfigurationInHandler
void RegisterConfigurationInHandler(DEMHandlerTLS &handler) const
otb::DEMHandler::SetDefaultHeightAboveEllipsoid
void SetDefaultHeightAboveEllipsoid(double height)
otbGDALDatasetWrapper.h
otb::DEMSubjectInterface::operator=
DEMSubjectInterface & operator=(DEMSubjectInterface const &)=delete
otb::DEMHandler::GetDEMDirectory
std::string const & GetDEMDirectory(std::vcl_size_t idx=0) const
otb::DEMHandler::GetHandlerForCurrentThread
DEMHandlerTLS const & GetHandlerForCurrentThread() const
otb::DEMHandler::OpenDEMFile
void OpenDEMFile(std::string path)
otb::DEMObserverInterface::operator=
DEMObserverInterface & operator=(DEMObserverInterface const &)=delete
otbImage.h
otb::DEMHandler::DoFetchOrCreateHandler
std::shared_ptr< DEMHandlerTLS > DoFetchOrCreateHandler() const
otb::DEMHandler::GetHeightAboveMSL
double GetHeightAboveMSL(double lon, double lat) const
otb::DEMSubjectInterface::DEMSubjectInterface
DEMSubjectInterface()=default
otb::GetGeoidHeight
double GetGeoidHeight(DEMHandlerTLS const &, double lon, double lat)
otb::DEMHandler::GetNumberOfDEMDirectories
std::vcl_size_t GetNumberOfDEMDirectories() const noexcept
Definition: otbDEMHandler.h:191
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::DEMHandler
Single access point for DEM data retrieval.
Definition: otbDEMHandler.h:113
otb::DEMSubjectInterface::~DEMSubjectInterface
~DEMSubjectInterface()=default
otb::DEMObserverInterface::DEMObserverInterface
DEMObserverInterface()=default
otb::DEMSubjectInterface::DetachObserver
virtual void DetachObserver(DEMObserverInterface *observer)=0
otb::DEMHandler::m_DatasetList
std::vector< otb::GDALDatasetWrapper::Pointer > m_DatasetList
Definition: otbDEMHandler.h:282
otb::DEMHandler::OpenGeoidFile
bool OpenGeoidFile(std::string geoidFile)
otb::DEMHandler::operator=
void operator=(const Self &)=delete
otb::DEMHandler::m_GeoidFilename
std::string m_GeoidFilename
Definition: otbDEMHandler.h:285
otb::DEMSubjectInterface::Notify
virtual void Notify() const =0
otb::DEMHandler::DEM_SHIFTED_DATASET_PATH
static constexpr char const * DEM_SHIFTED_DATASET_PATH
Definition: otbDEMHandler.h:217
otb::DEMHandler::DEM_DATASET_PATH
static constexpr char const * DEM_DATASET_PATH
Definition: otbDEMHandler.h:215
otb::DEMSubjectInterface::AttachObserver
virtual void AttachObserver(DEMObserverInterface *observer)=0
otb::DEMObserverInterface::~DEMObserverInterface
~DEMObserverInterface()=default
otb::DEMHandler::GetDEMCount
std::vcl_size_t GetDEMCount() const noexcept
otb::DEMHandler::GetGeoidFile
std::string const & GetGeoidFile() const noexcept
otb::DEMHandler::m_DefaultHeightAboveEllipsoid
double m_DefaultHeightAboveEllipsoid
Definition: otbDEMHandler.h:276
otb::DEMHandler::~DEMHandler
~DEMHandler()
otb::DEMHandler::DEMHandler
DEMHandler()
otb::DEMHandler::PointType
itk::Point< double, 2 > PointType
Definition: otbDEMHandler.h:117
otb::DEMHandler::GetDefaultHeightAboveEllipsoid
double GetDefaultHeightAboveEllipsoid() const noexcept
otb::GetHeightAboveEllipsoid
double GetHeightAboveEllipsoid(DEMHandlerTLS const &, double lon, double lat)
otb::DEMSubjectInterface
Observer design pattern to keep track of DEM configuration changes.
Definition: otbDEMHandler.h:55
otb::DEMHandler::m_tlses
std::vector< std::shared_ptr< DEMHandlerTLS > > m_tlses
Definition: otbDEMHandler.h:291
otb::DEMObserverInterface::Update
virtual void Update()=0
otb::DEMHandler::IsValidDEMDirectory
bool IsValidDEMDirectory(const std::string &DEMDirectory) const
otb::DEMHandler::AttachObserver
void AttachObserver(DEMObserverInterface *observer) override
Definition: otbDEMHandler.h:206
otb::DEMHandler::DEM_WARPED_DATASET_PATH
static constexpr char const * DEM_WARPED_DATASET_PATH
Definition: otbDEMHandler.h:216
otb::DEMHandler::m_ObserverList
std::list< DEMObserverInterface * > m_ObserverList
Definition: otbDEMHandler.h:288
otb::DEMHandler::Notify
void Notify() const override
otb::DEMHandler::GetGeoidHeight
double GetGeoidHeight(double lon, double lat) const
otb::DEMHandler::m_DEMDirectories
std::vector< std::string > m_DEMDirectories
Definition: otbDEMHandler.h:279
otb::DEMHandler::OpenDEMDirectory
void OpenDEMDirectory(std::string DEMDirectory)
otb::DEMHandler::GetHeightAboveEllipsoid
double GetHeightAboveEllipsoid(double lon, double lat) const