OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPleiadesModel.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2012 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 : Mickael Savinaud (mickael.savinaud@c-s.fr)
19 //
20 // Description:
21 //
22 // Contains definition of class ossimPleiadesModel
23 //
24 //*****************************************************************************
25 
26 #include "ossimPleiadesModel.h"
27 
28 #include <cmath>
29 #include <cstdio>
30 
31 #include <ossimPleiadesModel.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 ("ossimPleiadesModel:exec");
53  static ossimTrace traceDebug ("ossimPleiadesModel:debug");
54 
55 
56  RTTI_DEF1(ossimPleiadesModel, "ossimPleiadesModel", 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: ~ossimPleiadesModel(): entering..." << std::endl;
89 
90  theSupportData = 0;
91 
92  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG DESTRUCTOR: ~ossimPleiadesModel(): returning..." << std::endl;
93  }
94 //*************************************************************************************************
95 // Infamous DUP
96 //*************************************************************************************************
98  {
99  return new ossimPleiadesModel(*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 ossimPleiadesModel 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[] = "ossimPleiadesModel::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 
215  // DIMAPv1
216  ossimFilename DIMv1xmlFileTmp = file;
217  DIMv1xmlFileTmp.setFile("PHRDIMAP");
218  DIMv1xmlFileTmp.setExtension("XML");
219 
220  if (DIMv1xmlFileTmp.exists())
221  {
222  DIMxmlFile = DIMv1xmlFileTmp;
223  RPCxmlFile = DIMv1xmlFileTmp;
224  }
225  else
226  {
227  //---
228  // DIMAPv2
229  // Example file names:
230  // DIM_PHR1A_P_201202250025329_SEN_PRG_FC_5110-001.XML
231  // IMG_PHR1A_P_201202250025329_SEN_PRG_FC_5110-001_R1C1.tif
232  // RPC_PHR1A_P_201202250025329_SEN_PRG_FC_5110-001.XML
233  //---
234  DIMxmlFile = file.path();
235  RPCxmlFile = file.path();
236  ossimFilename DIMxmlFileTmp = file.file();
237  ossimFilename RPCxmlFileTmp;
238 
239  DIMxmlFileTmp = DIMxmlFileTmp.file().replaceStrThatMatch("^IMG_", "DIM_");
240 
241  //---
242  // Below substitution failing on lower case "tif" extension.
243  // Replacee with sustitute + setExtension call. (drb 17 Feb. 2016)
244  // DIMxmlFileTmp =
245  // DIMxmlFileTmp.replaceStrThatMatch("_R[0-9]+C[0-9]+\\.(JP2|TIF)$", ".XML");
246  //---
247  DIMxmlFileTmp = DIMxmlFileTmp.replaceStrThatMatch("_R[0-9]+C[0-9]", "");
248  DIMxmlFileTmp.setExtension("XML");
249 
250  RPCxmlFileTmp = DIMxmlFileTmp.file().replaceStrThatMatch("^DIM_", "RPC_");
251 
252  DIMxmlFile = DIMxmlFile.dirCat(DIMxmlFileTmp);
253  RPCxmlFile = RPCxmlFile.dirCat(RPCxmlFileTmp);
254  }
255 
256  if (!DIMxmlFile.exists())
257  {
258  if (traceDebug())
259  {
261  << "PHR main DIMAP file " << DIMxmlFile << " doesn't exist ...\n";
262  }
263  return false;
264  }
265  }
266 
267  if (traceDebug())
268  {
269  ossimNotify(ossimNotifyLevel_DEBUG) << "Metadata xml file: " << DIMxmlFile << "\n";
270  ossimNotify(ossimNotifyLevel_DEBUG) << "RPC xml file: " << RPCxmlFile << "\n";
271  }
272 
273  ossimString processingLevel;
274  // Parse the metadata xml file
275  if ( !theSupportData.valid() )
277 
278  if(!theSupportData->parseXmlFile(DIMxmlFile))
279  {
280  theSupportData = 0; // ossimRefPtr
281  if (traceDebug())
282  {
284  << "ossimPleiadesModel::open DEBUG:"
285  << "\nCould not open correctly DIMAP file" << std::endl;
286  }
287  return false;
288  }
289 
290  theSensorID = theSupportData->getSensorID();
291  theImageID = theSupportData->getImageID();
292  // Get the processing level (ORTHO or SENSOR or perhaps MOSAIC ?)
293  processingLevel = theSupportData->getProcessingLevel();
294 
295  // Parse the RPC xml file if necessary
296  if (RPCxmlFile.exists() && processingLevel == "SENSOR")
297  {
298  if (!theSupportData->parseXmlFile(RPCxmlFile))
299  {
300  theSupportData = 0; // ossimRefPtr
302  << "ossimPleiadesModel::open WARNING:"
303  << "\nCould not open correctly RPC file" << std::endl;
304  return false;
305  }
306 
307  thePolyType = B;
308 
309  for (unsigned int i = 0 ; i < 20; i++ )
310  {
311  theLineNumCoef[i] = theSupportData->getLineNumCoeff()[i];
312  theLineDenCoef[i] = theSupportData->getLineDenCoeff()[i];
313  theSampNumCoef[i] = theSupportData->getSampNumCoeff()[i];
314  theSampDenCoef[i] = theSupportData->getSampDenCoeff()[i];
315  }
316 
317  theLineScale = theSupportData->getLineScale();
318  theSampScale = theSupportData->getSampScale();
319  theLatScale = theSupportData->getLatScale();
320  theLonScale = theSupportData->getLonScale();
321  theHgtScale = theSupportData->getHeightScale();
322  theLineOffset = theSupportData->getLineOffset();
323  theSampOffset = theSupportData->getSampOffset();
324  theLatOffset = theSupportData->getLatOffset();
325  theLonOffset = theSupportData->getLonOffset();
326  theHgtOffset = theSupportData->getHeightOffset();
327  }
328 
329  // TODO MSD Check if this part is necessary
330  _productXmlFile = DIMxmlFile;
332 
333  // TODO MSD WARNING File with multi tiles are not well managed
334  theSupportData->getImageRect(theImageClipRect);
335  theSupportData->getImageSize(theImageSize);
336 
339 
340  result = true;
341  if (traceDebug())
342  {
343  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status = " << (result ? "true" : "false\n") << std::endl;
344  }
345 
346  /*std::cout << "---------------------------" << std::endl;
347  print(std::cout);
348  std::cout << "---------------------------" << std::endl;*/
349  return result;
350  }
351 
352 //*************************************************************************************************
354 //*************************************************************************************************
356  {
364 
365  //---
366  // NOTE: We must call "updateModel()" to set parameter used by base
367  // ossimRpcModel prior to calling lineSampleHeightToWorld or all
368  // the world points will be same.
369  //---
370  updateModel();
371 
372  ossimGpt v0, v1, v2, v3;
377 
379 
380  // Set the ground reference point using the model.
382 
383  if( theGSD.hasNans() )
384  {
385  try
386  {
387  // This will set theGSD and theMeanGSD. Method throws ossimException.
388  computeGsd();
389  }
390  catch (const ossimException& e)
391  {
393  << "ossimPleiadesModel::finishConstruction -- caught exception:\n"
394  << e.what() << std::endl;
395  }
396  }
397  }
398 
399 }
400 
double theSampOffset
ossimString theSensorID
PolynomialType thePolyType
double theSampNumCoef[20]
ossimRefPtr< ossimPleiadesDimapSupportData > theSupportData
ossim_float64 width() const
Definition: ossimDrect.h:522
ossimPleiadesModel()
default constructor
ossimFilename & setFile(const ossimString &f)
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 void updateModel()
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
double theLonScale
double theLineScale
virtual ~ossimPleiadesModel()
Destructor.
void finishConstruction()
Collects common code among all parsers.
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.
bool open(const ossimFilename &file)
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
virtual std::ostream & print(std::ostream &out) const
virtual ossimObject * dup() const
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 bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
loadState Fulfills ossimObject base-class pure virtuals.
ossimDrect theImageClipRect
ossim_int32 samp
Definition: ossimIpt.h:141
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
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]
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
double theLineOffset
const ossimDpt & lr() const
Definition: ossimDrect.h:341
double theHgtScale
ossimFilename path() const
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