OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimSpot6Model.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2014 Centre National Etudes Spatiales
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 3 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 //
18 // Author : Christophe Palmann (christophe.palmann@c-s.fr)
19 //
20 // Description:
21 //
22 // Contains definition of class ossimSpot6Model
23 //
24 //*****************************************************************************
25 
26 #include "ossimSpot6Model.h"
27 
28 #include <cmath>
29 #include <cstdio>
30 
31 #include <ossimSpot6Model.h>
33 
34 #include <ossimPluginCommon.h>
35 
36 #include <ossim/base/ossimCommon.h>
39 #include <ossim/base/ossimNotify.h>
40 #include <ossim/base/ossimRefPtr.h>
41 #include <ossim/base/ossimString.h>
42 #include <ossim/base/ossimTrace.h>
46 
47 
48 namespace ossimplugins
49 {
50 
51 // Define Trace flags for use within this file:
52  static ossimTrace traceExec ("ossimSpot6Model:exec");
53  static ossimTrace traceDebug ("ossimSpot6Model:debug");
54 
55 
56  RTTI_DEF1(ossimSpot6Model, "ossimSpot6Model", ossimRpcModel);
57 
58 //*************************************************************************************************
59 // Constructor
60 //*************************************************************************************************
62  :ossimRpcModel (),
63  theSupportData (0)
64  {
65  for (unsigned int i = 0; i < 20; i++)
66  {
67  theLineDenCoef[i] = 0.0;
68  theLineNumCoef[i] = 0.0;
69  theSampNumCoef[i] = 0.0;
70  theSampDenCoef[i] = 0.0;
71  }
72  }
73 
74 //*************************************************************************************************
75 // Constructor
76 //*************************************************************************************************
78  :ossimRpcModel (rhs),
79  theSupportData (0)
80  {
81  }
82 
83 //*************************************************************************************************
84 // Destructor
85 //*************************************************************************************************
87  {
88  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG DESTRUCTOR: ~ossimSpot6Model(): entering..." << std::endl;
89 
90  theSupportData = 0;
91 
92  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG DESTRUCTOR: ~ossimSpot6Model(): returning..." << std::endl;
93  }
94 //*************************************************************************************************
95 // Infamous DUP
96 //*************************************************************************************************
98  {
99  return new ossimSpot6Model(*this);
100  }
101 
102 //*************************************************************************************************
103 // Print
104 //*************************************************************************************************
106  {
107  // Capture stream flags since we are going to mess with them.
108  std::ios_base::fmtflags f = out.flags();
109 
110  out << "\nDump of ossimSpot6Model at address " << (hex) << this
111  << (dec)
112  << "\n------------------------------------------------"
113  << "\n theImageID = " << theImageID
114  << "\n theImageSize = " << theImageSize
115  << "\n theRefGndPt = " << theRefGndPt
116  << "\n theRefImgPt = " << theRefImgPt
117  << "\n theProcessingLevel = " << theSupportData->getProcessingLevel()
118  << "\n------------------------------------------------"
119  << "\n " << endl;
120 
121  // Set the flags back.
122  out.flags(f);
123 
124  if (theSupportData->getProcessingLevel() == "SENSOR")
125  return ossimRpcModel::print(out);
126  else
127  return out;
128  }
129 
130 //*************************************************************************************************
131 // Save State
132 //*************************************************************************************************
134  const char* prefix) const
135  {
136  if(theSupportData.valid())
137  {
138  ossimString supportPrefix = ossimString(prefix) + "support_data.";
139  theSupportData->saveState(kwl, supportPrefix);
140  }
141 
142  // If only it is a sensor product we save parameters from RPC model, its avoid to
143  // propagate a empty RPC model
144  if (theSupportData->getProcessingLevel() == "SENSOR")
145  {
146  ossimRpcModel::saveState(kwl, prefix);
147  return true;
148  }
149  else
150  {
151  kwl.add(prefix, "sensor", theSensorID, true);
152  return true;
153  }
154  }
155 
156 //*************************************************************************************************
157 // Load State
158 //*************************************************************************************************
160  const char* prefix)
161  {
162  if(!theSupportData)
163  {
165  }
166 
167  ossimString supportPrefix = ossimString(prefix) + "support_data.";
168  theSupportData->loadState(kwl, supportPrefix);
169 
170  // If only it is a sensor product we load parameters from RPC model only, its avoid to
171  // add a empty RPC model
172  if (theSupportData->getProcessingLevel() == "SENSOR")
173  {
174  ossimRpcModel::loadState(kwl, prefix);
175  return true;
176  }
177  else
178  {
179  return true;
180  }
181  }
182 
183 
184 
185  bool
187  {
188  static const char MODULE[] = "ossimSpot6Model::open";
189  //traceDebug.setTraceFlag(true);
190 
191  if (traceDebug())
192  {
193  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
194  }
195 
196  // Make the gsd nan so it gets computed.
197  theGSD.makeNan();
198 
199  bool result = false;
200 
201  // Filename used.
202  ossimFilename DIMxmlFile;
203  ossimFilename RPCxmlFile;
204 
205  // Generate metadata and rpc filename
206  if ( (file.ext().downcase() != "jp2" && file.ext().downcase() != "tif")
207  || !file.exists())
208  {
209  //not a valid file
210  return false;
211  }
212  else
213  {
214  // DIMAPv2
215  DIMxmlFile = file.path();
216  RPCxmlFile = file.path();
217  ossimFilename DIMxmlFileTmp = file.file();
218  ossimFilename RPCxmlFileTmp;
219 
220  DIMxmlFileTmp = DIMxmlFileTmp.file().replaceStrThatMatch("^IMG_", "DIM_");
221  DIMxmlFileTmp = DIMxmlFileTmp.replaceStrThatMatch("_R[0-9]+C[0-9]+\\.(JP2|TIF)$", ".XML");
222  // Check if it is an XML extension
223  if( DIMxmlFileTmp.ext() != "XML")
224  return false;
225 
226  RPCxmlFileTmp = DIMxmlFileTmp.file().replaceStrThatMatch("^DIM_", "RPC_");
227 
228  DIMxmlFile = DIMxmlFile.dirCat(DIMxmlFileTmp);
229  RPCxmlFile = RPCxmlFile.dirCat(RPCxmlFileTmp);
230 
231  if (!DIMxmlFile.exists())
232  {
233  if (traceDebug())
234  {
235  ossimNotify(ossimNotifyLevel_DEBUG) << "SPOT main DIMAP file " << DIMxmlFile << " doesn't exist ...\n";
236  }
237  return false;
238  }
239  }
240 
241  if (traceDebug())
242  {
243  ossimNotify(ossimNotifyLevel_DEBUG) << "Metadata xml file: " << DIMxmlFile << "\n";
244  ossimNotify(ossimNotifyLevel_DEBUG) << "RPC xml file: " << RPCxmlFile << "\n";
245  }
246 
247  ossimString processingLevel;
248  // Parse the metadata xml file
249  if ( !theSupportData.valid() )
251 
252  if(!theSupportData->parseXmlFile(DIMxmlFile))
253  {
254  theSupportData = 0; // ossimRefPtr
255  if (traceDebug())
256  {
257  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimSpot6Model::open DEBUG:"
258  << "\nCould not open correctly DIMAP file" << std::endl;
259  }
260  return false;
261  }
262 
263  theSensorID = theSupportData->getSensorID();
264  theImageID = theSupportData->getImageID();
265  // Get the processing level (ORTHO or SENSOR or perhaps MOSAIC ?)
266  processingLevel = theSupportData->getProcessingLevel();
267 
268  // Parse the RPC xml file if necessary
269  if (RPCxmlFile.exists() && processingLevel == "SENSOR")
270  {
271  if (!theSupportData->parseXmlFile(RPCxmlFile))
272  {
273  theSupportData = 0; // ossimRefPtr
274  ossimNotify(ossimNotifyLevel_WARN) << "ossimSpot6Model::open WARNING:"
275  << "\nCould not open correctly RPC file" << std::endl;
276  return false;
277  }
278 
279  thePolyType = B;
280 
281  for (unsigned int i = 0 ; i < 20; i++ )
282  {
283  theLineNumCoef[i] = theSupportData->getLineNumCoeff()[i];
284  theLineDenCoef[i] = theSupportData->getLineDenCoeff()[i];
285  theSampNumCoef[i] = theSupportData->getSampNumCoeff()[i];
286  theSampDenCoef[i] = theSupportData->getSampDenCoeff()[i];
287  }
288 
289  theLineScale = theSupportData->getLineScale();
290  theSampScale = theSupportData->getSampScale();
291  theLatScale = theSupportData->getLatScale();
292  theLonScale = theSupportData->getLonScale();
293  theHgtScale = theSupportData->getHeightScale();
294  theLineOffset = theSupportData->getLineOffset();
295  theSampOffset = theSupportData->getSampOffset();
296  theLatOffset = theSupportData->getLatOffset();
297  theLonOffset = theSupportData->getLonOffset();
298  theHgtOffset = theSupportData->getHeightOffset();
299  }
300 
301  // TODO MSD Check if this part is necessary
302  _productXmlFile = DIMxmlFile;
304 
305  // TODO MSD WARNING File with multi tiles are not well managed
306  theSupportData->getImageRect(theImageClipRect);
307  theSupportData->getImageSize(theImageSize);
308 
311 
312  result = true;
313  if (traceDebug())
314  {
315  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status = " << (result ? "true" : "false\n") << std::endl;
316  }
317 
318  /*std::cout << "---------------------------" << std::endl;
319  print(std::cout);
320  std::cout << "---------------------------" << std::endl;*/
321  return result;
322  }
323 
324 //*************************************************************************************************
326 //*************************************************************************************************
328  {
336 
337  //---
338  // NOTE: We must call "updateModel()" to set parameter used by base
339  // ossimRpcModel prior to calling lineSampleHeightToWorld or all
340  // the world points will be same.
341  //---
342  updateModel();
343 
344  ossimGpt v0, v1, v2, v3;
349 
351 
352  // Set the ground reference point using the model.
354 
355  if( theGSD.hasNans() )
356  {
357  try
358  {
359  // This will set theGSD and theMeanGSD. Method throws ossimException.
360  computeGsd();
361  }
362  catch (const ossimException& e)
363  {
365  << "ossimSpot6Model::finishConstruction -- caught exception:\n"
366  << e.what() << std::endl;
367  }
368  }
369  }
370 
371 }
372 
double theSampOffset
ossimString theSensorID
PolynomialType thePolyType
double theSampNumCoef[20]
ossimRefPtr< ossimSpot6DimapSupportData > theSupportData
ossim_float64 width() const
Definition: ossimDrect.h:522
RTTI_DEF1(ossimAlosPalsarModel, "ossimAlosPalsarModel", ossimGeometricSarSensorModel)
Represents serializable keyword/value map.
ossimString theImageID
double samp
Definition: ossimDpt.h:164
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
virtual ossimObject * dup() const
ossimSpot6Model()
default constructor
bool open(const ossimFilename &file)
virtual void updateModel()
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
double theLonScale
virtual std::ostream & print(std::ostream &out) const
double theLineScale
double theSampDenCoef[20]
double theLineNumCoef[20]
double theLatOffset
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual std::ostream & print(std::ostream &out) const
print() Extends base-class implementation.
void add(const ossimFilename &f)
Add support data filename to the list:
double theHgtOffset
double theLonOffset
void computeGsd()
This method computes the ground sample distance(gsd) and sets class attributes theGSD and theMeanGSD ...
double line
Definition: ossimDpt.h:165
bool exists() const
ossim_float64 lon
Definition: ossimGpt.h:266
double theLatScale
virtual const char * what() const
Returns the error message.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saveState Fulfills ossimObject base-class pure virtuals.
ossimPolygon theBoundGndPolygon
virtual void lineSampleHeightToWorld(const ossimDpt &image_point, const double &heightEllipsoid, ossimGpt &worldPoint) const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
bool hasNans() const
Definition: ossimDpt.h:67
ossim_float64 height() const
Definition: ossimDrect.h:517
ossimString replaceStrThatMatch(const char *regularExpressionPattern, const char *value="") const
virtual ~ossimSpot6Model()
Destructor.
ossimDrect theImageClipRect
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
ossim_int32 samp
Definition: ossimIpt.h:141
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
loadState Fulfills ossimObject base-class pure virtuals.
ossimDpt midPoint() const
Definition: ossimDrect.h:817
const ossimDpt & ur() const
Definition: ossimDrect.h:340
double x
Definition: ossimDpt.h:164
ossimFilename dirCat(const ossimFilename &file) const
double theSampScale
ossimFilename file() const
ossim_int32 line
Definition: ossimIpt.h:142
ossimString ext() const
const ossimDpt & ll() const
Definition: ossimDrect.h:342
ossim_float64 lat
Definition: ossimGpt.h:265
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
loadState Fulfills ossimObject base-class pure virtuals.
static ossimSupportFilesList * instance()
double theLineDenCoef[20]
double theLineOffset
const ossimDpt & lr() const
Definition: ossimDrect.h:341
double theHgtScale
ossimFilename path() const
void finishConstruction()
Collects common code among all parsers.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void makeNan()
Definition: ossimDpt.h:65
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23