OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfRsmModel.cpp
Go to the documentation of this file.
1 //---
2 // File: ossimNitfRsmModel.cpp
3 //
4 // RP
5 // LIMITATIONS - This is supporting only the RSM features that have been
6 // observed in current data samples and does not attempt to support the entire
7 // RSM specification.
8 // Examples of currently unsupported items include ->
9 // 1. multiple RSMPC tags for different polynomials for separate image sections
10 // 2. Error Covariance (this may gain priority as we have access to RSMECA data)
11 // 3. Illumination model
12 // 4. Rectangular coodinate system conversion (RSDIDA GRNDD = "R")
13 //---
14 
17 #include <ossim/base/ossimTrace.h>
25 
26 
27 RTTI_DEF1(ossimNitfRsmModel, "ossimNitfRsmModel", ossimRsmModel);
28 
29 //---
30 // Define Trace flags for use within this file:
31 //---
32 
33 static ossimTrace traceExec ("ossimNitfRsmModel:exec");
34 static ossimTrace traceDebug ("ossimNitfRsmModel:debug");
35 
36 
37 
39  : ossimRsmModel()
40 {
41 }
42 
44  : ossimRsmModel(obj)
45 {
46 }
47 
49 {
50  if (this != &rhs)
51  {
53  }
54  return *this;
55 }
56 
58 {
59 }
60 
62  ossim_uint32 entryIndex )
63 {
64  bool status = false;
65 
66  if ( nitfFile.exists() )
67  {
69  if( file->parseFile(nitfFile) )
70  {
72  if ( ih.valid() )
73  {
74  status = parseImageHeader( ih.get() );
75  }
76  }
77  }
78 
79  if( !status )
80  {
82  }
83 
84  return status;
85 }
86 
88 {
89  static const char MODULE[] = "ossimNitfRsmModel::getRsmData";
90  if (traceExec())
91  {
92  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entering..." << std::endl;
93  }
94 
95  bool status = false;
96 
97  if ( getRsmData(ih) )
98  {
99 
100  theImageID = m_pca[0].m_iid; // tmp drb...
102 
103  ossimIrect imageRect = ih->getImageRect();
104 
105  // Fetch Image Size:
106  theImageSize.line = static_cast<ossim_int32>(imageRect.height());
107  theImageSize.samp = static_cast<ossim_int32>(imageRect.width());
108 
109  // Assign other data members:
112 
113  // Assign the bounding image space rectangle:
115 
116  ossimGpt v0, v1, v2, v3;
117  ossimDpt ip0 (0.0, 0.0);
118  lineSampleHeightToWorld(ip0, m_pca[0].m_znrmo, v0);
119  ossimDpt ip1 (theImageSize.samp-1.0, 0.0);
120  lineSampleHeightToWorld(ip1, m_pca[0].m_znrmo, v1);
121  ossimDpt ip2 (theImageSize.samp-1.0, theImageSize.line-1.0);
122  lineSampleHeightToWorld(ip2, m_pca[0].m_znrmo, v2);
123  ossimDpt ip3 (0.0, theImageSize.line-1.0);
124  lineSampleHeightToWorld(ip3, m_pca[0].m_znrmo, v3);
125 
127 
128  updateModel();
129 
130  // Set the ground reference point.
132 
133  // Height could have nan if elevation is not set so check lat, lon individually.
134  if ( ( theRefGndPt.isLatNan() == false ) && ( theRefGndPt.isLonNan() == false ) )
135  {
136  //---
137  // This will set theGSD and theMeanGSD. This model doesn't need these but
138  // others do.
139  //---
140  try
141  {
142  computeGsd();
143 
144  // Set return status.
145  status = true;
146  }
147  catch (const ossimException& e)
148  {
149  if (traceDebug())
150  {
152  << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:\n"
153  << e.what() << std::endl;
154  }
155  setErrorStatus();
156  }
157  }
158  else
159  {
160  if (traceDebug())
161  {
163  << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:"
164  << "\nGround Reference Point not valid(has nans)."
165  << " Aborting with error..."
166  << std::endl;
167  }
168  setErrorStatus();
169  }
170  }
171  else
172  {
173  if (traceDebug())
174  {
176  << "ossimNitfRpcModel::parseFile DEBUG:"
177  << "\nError parsing rsm tags. Aborting with error."
178  << std::endl;
179  }
180  setErrorStatus();
181  }
182 
183  if (traceExec())
184  {
186  << MODULE << " exit status: " << ( status ? "true" : "false" ) << "\n";
187  }
188 
189  return status;
190 
191 } // End: ossimNitfRsmModel::parseImageHeader(const ossimNitfImageHeader* ih)
192 
194 {
195  static const char MODULE[] = "ossimNitfRsmModel::getRsmData";
196  if (traceExec())
197  {
198  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entering..." << std::endl;
199  }
200 
201  bool status = false;
202 
203  if ( ih )
204  {
206 
207  // RSMECA:
208  const ossimString RSMECA_TAG = "RSMECA";
209  tag = ih->getTagData(RSMECA_TAG);
210  if (tag.valid())
211  {
213  dynamic_cast<ossimNitfRsmecaTag*>(tag.get());
214  if ( rsmecaTag.valid() )
215  {
216  if ( initializeModel( rsmecaTag.get() ) )
217  {
218  // RSMIDA:
219  ossimString RSMIDA_TAG = "RSMIDA";
220  tag = ih->getTagData(RSMIDA_TAG);
221  if (tag.valid())
222  {
224  dynamic_cast<ossimNitfRsmidaTag*>( tag.get() );
225  if ( rsmidaTag.valid() )
226  {
227  if ( m_ida.initialize( rsmidaTag.get() ) )
228  {
229  // RSMPIA:
230  const ossimString RSMPIA_TAG = "RSMPIA";
231  tag = ih->getTagData(RSMPIA_TAG);
232  if (tag.valid())
233  {
235  dynamic_cast<ossimNitfRsmpiaTag*>( tag.get() );
236  if ( rsmpiaTag.valid() )
237  {
238  if ( m_pia.initialize( rsmpiaTag.get() ) )
239  {
240  //---
241  // RSMPCA:
242  // Multiple tags if image is sectioned.
243  //---
244  const ossimString RSMPCA_TAG = "RSMPCA";
245  std::vector< const ossimNitfRegisteredTag* > tags;
246  ih->getTagData( RSMPCA_TAG, tags );
247 
248  if ( tags.size() == m_pia.m_tnis )
249  {
250  for ( ossim_uint32 tagIndex = 0;
251  tagIndex < m_pia.m_tnis;
252  ++tagIndex )
253  {
254  const ossimNitfRsmpcaTag* rsmpcaTag =
255  dynamic_cast<const ossimNitfRsmpcaTag*>( tags[tagIndex] );
256  if ( rsmpcaTag )
257  {
258  ossimRsmpca pca;
259  if ( pca.initialize( rsmpcaTag ) )
260  {
261  m_pca.push_back( pca );
262  }
263  else if (traceDebug())
264  {
266  << "WARNING! RSMPCA[" << tagIndex << "] intitialization failed!"
267  << std::endl;
268  }
269  }
270  }
271 
272  // Call base ossimRsmModel::validate() for sanity check:
273  status = validate();
274  }
275 
276  } // Matches: if ( m_pia.initialize( rsmpiaTag ) )
277  }
278  }
279  else if (traceDebug())
280  {
282  << "\nCould not find RSM tag: " << RSMPIA_TAG
283  << "\nAborting with error..."
284  << std::endl;
285  }
286  }
287  }
288  }
289  else if (traceDebug())
290  {
292  << "\nCould not find RSM tag: " << RSMIDA_TAG
293  << "\nAborting with error..." << std::endl;
294  }
295  }
296  }
297  }
298  else if (traceDebug())
299  {
301  << "ossimNitfRsmModel::getRsmData WARNING!"
302  << "\nCould not find RSM tag: " << RSMECA_TAG
303  << "\nAborting with error..." << std::endl;
304  }
305  }
306 
307  if (traceExec())
308  {
310  << MODULE << " exit status: " << ( status ? "true" : "false" ) << "\n";
311  }
312 
313  return status;
314 
315 } // End: ossimNitfRsmModel::getRsmData(const ossimNitfImageHeader* ih)
316 
317 
319 {
320  bool status = false;
321 
322  if ( rsmecaTag )
323  {
324  // TODO:
325  status = true;
326  }
327 
328  return status;
329 
330 } // End: ossimNitfRsmModel::initializeModel( rsmecaTag )
331 
333 {
334  return new ossimNitfRsmModel(*this);
335 }
336 
338  const char* prefix) const
339 {
340 
341  static const char MODULE[] = "ossimNitfRsmModel::saveState";
342  if (traceExec())
343  {
344  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
345  }
346 
347  //---
348  // Hand off to base class for common stuff:
349  //
350  // Note: Class type "ossimKeywordNames::TYPE_KW" is saved in
351  // ossimOject::saveState.
352  //---
353  bool status = ossimRsmModel::saveState(kwl, prefix);
354 
355  if (traceExec())
356  {
357  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exited...\n";
358  }
359 
360  return status;
361 }
362 
364  const char* prefix )
365 {
366  static const char MODULE[] = "ossimNitfRsmModel::loadState";
367  if (traceExec())
368  {
369  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
370  }
371 
372  bool status = false;
373 
374  // Check for type match before preceeding:
375  std::string myPrefix = ( prefix ? prefix : "" );
376  std::string type = kwl.findKey( myPrefix, std::string(ossimKeywordNames::TYPE_KW) );
377 
378  if ( type == "ossimNitfRsmModel" )
379  {
380  // Pass on to the base-class for parsing first:
381  status = ossimRsmModel::loadState(kwl, prefix);
382  }
383 
384  if (traceExec())
385  {
387  << MODULE << " exit status = " << (status?"true":"false") << "\n";
388  }
389 
390  return status;
391 }
virtual void lineSampleHeightToWorld(const ossimDpt &image_point, const double &heightEllipsoid, ossimGpt &worldPoint) const
lineSampleHeightToWorld() Overrides base class pure virtual.
virtual void updateModel()
bool initialize(const ossimNitfRsmidaTag *rsmidaTag)
initialize Initializes from nitf rsmida tag.
ossimNitfImageHeader * getNewImageHeader(ossim_uint32 imageNumber) const
bool validate() const
Performs sanity check on key/required rsm data.
Represents serializable keyword/value map.
ossimNitfRsmModel()
default constructor
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
bool isLonNan() const
Definition: ossimGpt.h:140
bool valid() const
Definition: ossimRefPtr.h:75
ossimString theImageID
double samp
Definition: ossimDpt.h:164
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
loadState Fulfills ossimObject base-class pure virtuals.
const ossimRsmModel & operator=(const ossimRsmModel &rhs)
assignment operator
ossim_uint32 height() const
Definition: ossimIrect.h:487
ossim_uint32 m_tnis
Definition: ossimRsmpia.h:92
bool initializeModel(const ossimNitfRsmecaTag *rsmecaTag)
Initializes model from RSMECA tag.
virtual bool parseFile(const ossimFilename &nitfFile, ossim_uint32 entryIndex=0)
RSM Identification: Id&#39;s, time-of-image model, optional illumination model, footprint information...
virtual ossimObject * dup() const
dup() Returns pointer to a new instance, copy of this.
bool isLatNan() const
Definition: ossimGpt.h:139
static const char * TYPE_KW
void computeGsd()
This method computes the ground sample distance(gsd) and sets class attributes theGSD and theMeanGSD ...
double line
Definition: ossimDpt.h:165
std::vector< ossimRsmpca > m_pca
bool exists() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saveState Fulfills ossimObject base-class pure virtuals.
virtual const char * what() const
Returns the error message.
virtual ossimIrect getImageRect() const =0
bool initialize(const ossimNitfRsmpcaTag *rsmpcaTag)
initialize Initializes from nitf rsmpia tag.
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
ossimPolygon theBoundGndPolygon
virtual ~ossimNitfRsmModel()
virtual destructor
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimRsmpia m_pia
return status
ossimDrect theImageClipRect
const ossimNitfRsmModel & operator=(const ossimNitfRsmModel &rhs)
assignment operator
RTTI_DEF1(ossimNitfRsmModel, "ossimNitfRsmModel", ossimRsmModel)
ossim_int32 samp
Definition: ossimIpt.h:141
RSM Polynomial Coefficients: Polynomials coefficients for a section.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
loadState Fulfills ossimObject base-class pure virtuals.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saveState Fulfills ossimObject base-class pure virtuals.
ossimRefPtr< ossimNitfRegisteredTag > getTagData(const ossimString &tagName)
bool getRsmData(const ossimNitfImageHeader *ih)
ossim_int32 line
Definition: ossimIpt.h:142
bool parseFile(const ossimFilename &file)
ossimRsmida m_ida
bool initialize(const ossimNitfRsmpiaTag *rsmpiaTag)
initialize Initializes from nitf rsmpia tag.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32
virtual bool parseImageHeader(const ossimNitfImageHeader *ih)