OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
SceneCoord.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // "Copyright Centre National d'Etudes Spatiales"
4 //
5 // License: LGPL
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
12 #include <otb/SceneCoord.h>
13 #include <ossim/base/ossimDpt3d.h>
15 #include <ossim/base/ossimNotify.h>
16 #include <ossim/base/ossimString.h>
17 
18 
19 namespace ossimplugins
20 {
21 static const char SCENE_COORD[] = "sceneCoord";
22 static const char NUMBER_OF_SCENE_CORNER_COORD[] = "numberOfSceneCornerCoord";
23 static const char SCENE_CENTER_COORD[] = "sceneCenterCoord";
24 static const char SCENE_CORNER_COORD[] = "sceneCornerCoord";
25 
27  :
28  _numberOfSceneCoord(0),
29  _centerSceneCoord(),
30  _tabCornersSceneCoord()
31 {
32 }
33 
35 {
36 }
37 
39  :
40  _numberOfSceneCoord(rhs._numberOfSceneCoord),
41  _centerSceneCoord(rhs._centerSceneCoord),
42  _tabCornersSceneCoord(rhs._tabCornersSceneCoord)
43 {
44 }
45 
47 {
48  if ( this != &rhs )
49  {
53  }
54 
55  return *this;
56 }
57 
58 bool SceneCoord::saveState(ossimKeywordlist& kwl, const char* prefix) const
59 {
60  std::string pfx("");
61  std::string pfx2("");
62  if (prefix)
63  {
64  pfx = prefix;
65  }
66  pfx += SCENE_COORD;
67  pfx2 = pfx;
68  pfx2 += ".";
69 
70  kwl.add(pfx2.c_str(), NUMBER_OF_SCENE_CORNER_COORD, _numberOfSceneCoord);
71 
72  std::string s = pfx + "." + SCENE_CENTER_COORD;
73  _centerSceneCoord.saveState(kwl, s.c_str());
74 
75  std::string s2 =pfx + "." + SCENE_CORNER_COORD;
76  for (unsigned int i = 0; i < _tabCornersSceneCoord.size(); ++i)
77  {
78  std::string s3 = s2 + "[" + ossimString::toString(i).c_str() + "]";
79  _tabCornersSceneCoord[i].saveState(kwl, s3.c_str());
80  }
81  return true;
82 }
83 
84 bool SceneCoord::loadState(const ossimKeywordlist& kwl, const char* prefix)
85 {
86  static const char MODULE[] = "SceneCoord::loadState";
87 
88  bool result = true;
89 
90  ossimString s;
91  const char* lookup = 0;
92 
93  std::string pfx("");
94  if (prefix)
95  {
96  pfx = prefix;
97  }
98  pfx += SCENE_COORD;
99  pfx += ".";
100 
101 
102  lookup = kwl.find(pfx.c_str(), NUMBER_OF_SCENE_CORNER_COORD);
103 
104  if (lookup)
105  {
106  s = lookup;
108  }
109  else
110  {
112  << MODULE << " Keyword not found: " << NUMBER_OF_SCENE_CORNER_COORD << " in "<<pfx.c_str()<<" path.\n";
113  result = false;
114  }
115 
116  std::string s1 = pfx + SCENE_CENTER_COORD;
117 
118  result = _centerSceneCoord.loadState(kwl, s1.c_str());
119 
120  _tabCornersSceneCoord.clear();
121  std::string s2 = pfx + SCENE_CORNER_COORD;
122  for (unsigned int i = 0; i < _numberOfSceneCoord; ++i)
123  {
124  std::string s3 = s2 + "[" + ossimString::toString(i).c_str() + "]";
125  InfoSceneCoord isc;
126  result = isc.loadState(kwl, s3.c_str());
127  _tabCornersSceneCoord.push_back(isc);
128  }
130  {
132  << MODULE << " Keyword " << NUMBER_OF_SCENE_CORNER_COORD << " is different with the number of _tabCornersScenceCoord nodes \n";
133  }
134 
135  return result;
136 }
137 
138 
140 {
141  out << setprecision(15) << setiosflags(ios::fixed)
142  << "\n SceneCoord class data members:\n";
143 
144  const char* prefix = 0;
145  ossimKeywordlist kwl;
146  ossimString pfx;
147  pfx += SCENE_COORD;
148  ossimString s = pfx + "." + NUMBER_OF_SCENE_CORNER_COORD;
149  kwl.add(prefix, s.c_str(), _numberOfSceneCoord);
150 
151  ossimString s1 = pfx + "." + SCENE_CENTER_COORD;
152  _centerSceneCoord.saveState(kwl, s1.c_str());
153 
154  ossimString s2 =pfx + "." + SCENE_CORNER_COORD;
155  for (unsigned int i = 0; i < _tabCornersSceneCoord.size(); ++i)
156  {
157  ossimString s3 = s2 + "[" + ossimString::toString(i) + "]";
158  _tabCornersSceneCoord[i].saveState(kwl, s3.c_str());
159  }
160  out << kwl;
161 
162  return out;
163 }
164 
165 }
This class represents an InfoSceneCoord.
This class represents Scence coordinate.
Definition: SceneCoord.h:29
Represents serializable keyword/value map.
const char * find(const char *key) const
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ~SceneCoord()
Destructor.
Definition: SceneCoord.cpp:34
ossim_uint32 toUInt32() const
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
Definition: SceneCoord.cpp:58
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
SceneCoord()
Constructor.
Definition: SceneCoord.cpp:26
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
Definition: SceneCoord.cpp:84
SceneCoord & operator=(const SceneCoord &rhs)
Affectation operator.
Definition: SceneCoord.cpp:46
InfoSceneCoord _centerSceneCoord
Center scene coordinate.
Definition: SceneCoord.h:94
std::vector< InfoSceneCoord > _tabCornersSceneCoord
Corners InfoIncidenceAngle.
Definition: SceneCoord.h:98
ossim_uint32 _numberOfSceneCoord
Number of scene coordinate.
Definition: SceneCoord.h:90
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
virtual std::ostream & print(std::ostream &out) const
Definition: SceneCoord.cpp:139
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23