OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfWriterBase.cpp
Go to the documentation of this file.
1 //---
2 //
3 // License: MIT
4 //
5 // Author: David Burken
6 //
7 // Description: OSSIM nitf writer base class to hold methods common to
8 // all nitf writers.
9 //
10 //---
11 // $Id$
12 
16 #include <ossim/base/ossimIrect.h>
19 #include <ossim/base/ossimRefPtr.h>
20 #include <ossim/base/ossimString.h>
21 #include <ossim/base/ossimTrace.h>
37 
38 static const char ENABLE_BLOCKA_KW[] = "enable_blocka_tag";
39 static const char ENABLE_RPCB_KW[] = "enable_rpcb_tag";
40 static const char ENABLE_GEOLOB_KW[] = "enable_geolob_tag";
41 
42 RTTI_DEF1(ossimNitfWriterBase, "ossimNitfWriterBase", ossimImageFileWriter)
43 
44 static ossimTrace traceDebug(ossimString("ossimNitfWriterBase:debug"));
45 
48  theEnableRpcbTagFlag(false),
49  theEnableBlockaTagFlag(true),
50  theEnableGeolobTagFlag(true)
51 {
52 }
53 
55  ossimImageSource* inputSource)
56  : ossimImageFileWriter(filename, inputSource, 0),
57  theEnableRpcbTagFlag(false),
58  theEnableBlockaTagFlag(true),
59  theEnableGeolobTagFlag(true)
60 {
61 }
62 
64 {
65 }
66 
68 {
69  if(property.valid())
70  {
71  ossimString name = property->getName();
72 
73  if (name == ENABLE_RPCB_KW)
74  {
75  theEnableRpcbTagFlag = property->valueToString().toBool();
76  }
77  else if (name == ENABLE_BLOCKA_KW)
78  {
79  theEnableBlockaTagFlag = property->valueToString().toBool();
80  }
81  else if (name == ENABLE_GEOLOB_KW)
82  {
83  theEnableGeolobTagFlag = property->valueToString().toBool();
84  }
85  else
86  {
88  }
89  }
90 }
91 
93  const ossimString& name)const
94 {
95  ossimRefPtr<ossimProperty> result = 0;
96 
97  if(name == ENABLE_BLOCKA_KW)
98  {
99  result = new ossimBooleanProperty(name, theEnableBlockaTagFlag);
100  }
101  else if (name == ENABLE_GEOLOB_KW)
102  {
103  result = new ossimBooleanProperty(name, theEnableGeolobTagFlag);
104  }
105  else if(name == ENABLE_RPCB_KW)
106  {
107  result = new ossimBooleanProperty(name, theEnableRpcbTagFlag);
108  }
109  else
110  {
111  result = ossimImageFileWriter::getProperty(name);
112  }
113 
114  return result;
115 }
116 
118  std::vector<ossimString>& propertyNames)const
119 {
121 
122  propertyNames.push_back(ENABLE_BLOCKA_KW);
123  propertyNames.push_back(ENABLE_GEOLOB_KW);
124  propertyNames.push_back(ENABLE_RPCB_KW);
125 }
126 
127 
129  const char* prefix) const
130 {
131  kwl.add(prefix, ENABLE_BLOCKA_KW, theEnableBlockaTagFlag, true);
132  kwl.add(prefix, ENABLE_GEOLOB_KW, theEnableGeolobTagFlag, true);
133  kwl.add(prefix, ENABLE_RPCB_KW, theEnableRpcbTagFlag, true);
134 
135  return ossimImageFileWriter::saveState(kwl, prefix);
136 }
137 
139  const char* prefix)
140 {
141  // Look for the rpcb enable flag keyword.
142 
143 
144  // Look for the blocka enable flag keyword.
145  const char* lookup = kwl.find(prefix, ENABLE_BLOCKA_KW);
146  if(lookup)
147  {
148  ossimString os = lookup;
150  }
151 
152  // Look for the geolob enable flag keyword.
153  lookup = kwl.find(prefix, ENABLE_GEOLOB_KW);
154  if(lookup)
155  {
156  ossimString os = lookup;
158  }
159 
160  lookup = kwl.find(prefix, ENABLE_RPCB_KW);
161  if(lookup)
162  {
163  ossimString os = lookup;
165  }
166 
167  return ossimImageFileWriter::loadState(kwl, prefix);
168 }
169 
172 {
173  if (hdr && seq)
174  {
176  ossimKeywordlist kwl;
177 
178  if (geom.valid()&&geom->hasProjection())
179  {
180  // Get the requested bounding rectangles.
181  ossimIrect rect = seq->getBoundingRect();
182 
183  // See if it's a map projection; else, a sensor model.
184  ossimMapProjection* mapProj =
186  if (mapProj)
187  {
188  // Use map info to get the corners.
189  ossimMapProjectionInfo mapInfo(mapProj, rect);
191 
192  // See if it's utm.
194  mapProj);
195  if(utmProj)
196  {
197  ossimDpt ul = mapInfo.ulEastingNorthingPt();
198  ossimDpt ur = mapInfo.urEastingNorthingPt();
199  ossimDpt lr = mapInfo.lrEastingNorthingPt();
200  ossimDpt ll = mapInfo.llEastingNorthingPt();
201 
202  if(utmProj->getHemisphere() == 'N')
203  {
204  hdr->setUtmNorth(utmProj->getZone(), ul, ur, lr, ll);
205  }
206  else
207  {
208  hdr->setUtmSouth(utmProj->getZone(), ul, ur, lr, ll);
209  }
210  }
211  else
212  {
213  ossimGpt ul = mapInfo.ulGroundPt();
214  ossimGpt ur = mapInfo.urGroundPt();
215  ossimGpt lr = mapInfo.lrGroundPt();
216  ossimGpt ll = mapInfo.llGroundPt();
217  hdr->setGeographicLocationDms(ul, ur, lr, ll);
218  }
219 
221  {
222  addBlockaTag(mapInfo, hdr);
223  }
224 
226  {
227  addGeolobTag( mapProj, hdr );
228  }
229  }
230  else
231  {
232  ossimGpt ul, ur, lr, ll;
233  bool status = geom->getCornerGpts(ul, ur, lr, ll);
234  if (status)
235  {
236  hdr->setGeographicLocationDms(ul, ur, lr, ll);
237  }
238  }
239 
241  {
242  addRpcbTag(rect, geom->getProjection(), hdr);
243  }
244 
245  } // matches: if (proj.valid())
246 
247  } // matches: if (hdr && seq)
248 }
249 
252 {
253  if (hdr)
254  {
255  // Capture the current pixel type.
256  ossimPixelType originalPixelType = mapInfo.getPixelType();
257 
258  // This tag wants corners as area:
260 
261  // Stuff the blocka tag which has six digit precision.
263 
264  // Set the block number.
265  blockaTag->setBlockInstance(1);
266 
267  // Set the number of lines.
268  blockaTag->setLLines(mapInfo.linesPerImage());
269 
270  // Set first row, first column.
271  blockaTag->setFrfcLoc(ossimDpt(mapInfo.ulGroundPt()));
272 
273  // Set first row, last column.
274  blockaTag->setFrlcLoc(ossimDpt(mapInfo.urGroundPt()));
275 
276  // Set last row, last column.
277  blockaTag->setLrlcLoc(ossimDpt(mapInfo.lrGroundPt()));
278 
279  // Set last row, first column.
280  blockaTag->setLrfcLoc(ossimDpt(mapInfo.llGroundPt()));
281 
282  if (traceDebug())
283  {
285  << "ossimNitfWriterBase::addBlockaTag DEBUG:"
286  << "\nBLOCKA Tag:" << *((ossimObject*)(blockaTag.get()))
287  << std::endl;
288  }
289 
290  // Add the tag to the header.
291  ossimRefPtr<ossimNitfRegisteredTag> blockaTagRp = blockaTag.get();
292  ossimNitfTagInformation blockaTagInfo(blockaTagRp);
293  hdr->addTag(blockaTagInfo);
294 
295  // Reset the pixel type to original value
296  mapInfo.setPixelType(originalPixelType);
297 
298  } // matches: if (hdr)
299 }
300 
303 {
304  if (hdr && mapProj)
305  {
306  if ( mapProj->isGeographic() == true )
307  {
309 
310  // Get the scale:
311  ossimDpt gsd = mapProj->getDecimalDegreesPerPixel();
312  if ( (gsd.hasNans() == false) && (gsd.x > 0.0) && (gsd.y > 0.0) )
313  {
314  ossimGpt tie = mapProj->getUlGpt();
315  if ( tie.hasNans() == false )
316  {
317  // Shift the tie to edge of pixel:
318  tie.lat = tie.lat + gsd.y*0.5;
319  tie.lon = tie.lon - gsd.x*0.5;
320  if ( (tie.lat <= 90.0) && (tie.lon >= -180.0) )
321  {
323  geolobTag->setDegreesPerPixelLon( gsd.x );
324  geolobTag->setDegreesPerPixelLat( gsd.y );
325  geolobTag->setLso( tie.lon ); // Origin Longitude
326  geolobTag->setPso( tie.lat ); // Origin Latitude
327 
328  // Add the tag to the header.
329  ossimRefPtr<ossimNitfRegisteredTag> geolobTagRp = geolobTag.get();
330  ossimNitfTagInformation geolobTagInfo(geolobTagRp);
331  hdr->addTag(geolobTagInfo);
332 
333  if (traceDebug())
334  {
336  << "ossimNitfWriterBase::addGeolobTag DEBUG:"
337  << "\nAdded GEOLOB Tag:\n" << *(geolobTag.get())
338  << "\n";
339  }
340  }
341  }
342  }
343  }
344  }
345 }
346 
348  ossimProjection* proj,
350 {
351  if (proj && hdr)
352  {
353  bool useElevation = false;
354 
355  if (PTR_CAST(ossimMapProjection, proj))
356  {
357  // If we're already map projected turn the elevation off.
358  useElevation = false;
359  }
360 
361  // Make an rpc solver.
362  ossimRefPtr<ossimRpcSolver> rs = new ossimRpcSolver(useElevation);
363 
364  // Compute the coefficients.
365  rs->solveCoefficients(ossimDrect(rect), proj, 64, 64);
366 
367  // Add the tag.
369  ossimNitfTagInformation tagInfo(tag);
370  hdr->addTag(tagInfo);
371 
372  if (traceDebug())
373  {
375  << "ossimNitfWriterBase::addRpcbTag DEBUG:"
376  << "\nRPCB Tag:" << *((ossimObject*)(tag.get()))
377  << "\nProjection:\n";
378 
380 
382  << "\nRect: " << rect << std::endl;
383  }
384 
385  } // matches: if (proj && hdr)
386 }
387 
388 void ossimNitfWriterBase::setComplexityLevel(std::streamoff endPosition,
390 {
391  if (hdr)
392  {
393  //---
394  // See MIL-STD-2500C, Table A-10:
395  //
396  // Lots of rules here, but for now we will key off of file size.
397  //---
398  const std::streamoff MB = 1024 * 1024;
399  const std::streamoff MB50 = 50 * MB;
400  const std::streamoff GIG = 1000 * MB;
401  const std::streamoff GIG2 = 2 * GIG;
402 
403  ossimString complexity = "03"; // Less than 50 mb.
404 
405  if ( (endPosition >= MB50) && (endPosition < GIG) )
406  {
407  complexity = "05";
408  }
409  else if ( (endPosition >= GIG) && (endPosition < GIG2) )
410  {
411  complexity = "06";
412  }
413  else if (endPosition >= GIG2)
414  {
415  complexity = "07";
416  }
417 
418  hdr->setComplexityLevel(complexity);
419  }
420 }
421 
422 // Alternate calculation option for complexity. This seems to match more test data.
424 {
425  if (hdr)
426  {
427  ossim_uint64 max = (width > height) ? width : height;
428  ossimString complexity = "03";
429  if (max > 65536) complexity = "07";
430  else if (max > 8192) complexity = "06";
431  else if (max > 2048) complexity = "05";
432 
433  hdr->setComplexityLevel(complexity);
434  }
435 }
436 
438 {
439  return ossimString("ntf");
440 }
441 
443 {
444 }
445 
447 {
448 }
449 
450 void ossimNitfWriterBase::addRegisteredTag(ossimRefPtr<ossimNitfRegisteredTag> /* registeredTag */, bool /* unique */, const ossim_uint32& /* ownerIndex */, const ossimString& /* tagType */)
451 {
452 }
453 
455 {
456 }
457 
459 {
460 }
461 
463  ossimNitfImageHeaderV2_X* imgHdr )
464 {
465  // Look in prefs for site configuration file:
466  const char* lookup = ossimPreferences::instance()->
467  findPreference("nitf_writer.site_configuration_file");
468  if ( lookup && fileHdr && imgHdr )
469  {
470  ossimKeywordlist kwl;
471  if ( kwl.addFile( lookup ) )
472  {
473  fileHdr->loadState( kwl, "nitf.file." );
474  imgHdr->loadState( kwl, "nitf.image." );
475  }
476  }
477 }
478 
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Set the properties.
bool theEnableGeolobTagFlag
If true user wants to set GEOLOG tag.
virtual const ossimDpt & getDecimalDegreesPerPixel() const
Returns decimal degrees per pixel as an ossimDpt with "x" representing longitude and "y" representing...
void setFrlcLoc(const ossimDpt &pt)
Convert latitude and logitude to theFrlcLoc string.
ossimGpt urGroundPt() const
Returns the upper right ground point.
virtual void setFileHeaderV2_1(ossimRefPtr< ossimNitfFileHeaderV2_1 >, bool preferSource=false)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
ossim_int32 linesPerImage() const
void setLrfcLoc(const ossimDpt &pt)
Convert latitude and logitude to theLrfcLoc string.
ossimRefPtr< ossimNitfRegisteredTag > getNitfRpcBTag() const
Represents serializable keyword/value map.
bool addFile(const char *file)
ossimNitfWriterBase()
default constructor
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to set fields from a keyword list.
bool theEnableBlockaTagFlag
If true user wants to set BLOCKA tag.
const char * find(const char *key) const
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
virtual void setUtmNorth(ossim_uint32 zone, const ossimDpt &ul, const ossimDpt &ur, const ossimDpt &lr, const ossimDpt &ll)
void setLrlcLoc(const ossimDpt &pt)
Convert latitude and logitude to theLrlcLoc string.
void setBlockInstance(ossim_uint32 block)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
double y
Definition: ossimDpt.h:165
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void addTag(const ossimNitfTagInformation &tag, bool unique=true)
virtual bool isGeographic() const
void setPixelType(ossimPixelType type)
Sets the data member "thePixelType".
bool getCornerGpts(ossimGpt &ul, ossimGpt &ur, ossimGpt &lr, ossimGpt &ll) const
Assigns the ossimGpts with the ground coordinates of the four corresponding image corner points...
Pure virtual base class for image file writers.
ossimDpt lrEastingNorthingPt() const
Returns the lower right easting and northing as a ossimDpt.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
void solveCoefficients(const ossimDrect &imageBounds, ossimProjection *imageProj, ossim_uint32 xSamples=8, ossim_uint32 ySamples=8)
This will convert any projector to an RPC model.
ossimPixelType getPixelType() const
Returns data member "thePixelType".
void addBlockaTag(ossimMapProjectionInfo &mapInfo, ossimNitfImageHeaderV2_X *hdr)
Adds the BLOCKA tag.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
void setFrfcLoc(const ossimDpt &pt)
Convert latitude and logitude to theFrfcLoc string.
void setDegreesPerPixelLon(const ossim_float64 &deltaLon)
Sets the ARV field from decimal degrees per pixel longitude.
ossim_float64 lon
Definition: ossimGpt.h:266
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
void addRpcbTag(const ossimIrect &rect, ossimProjection *proj, ossimNitfImageHeaderV2_X *hdr)
Adds the RPC00B tag.
ossimGpt lrGroundPt() const
Returns the lower right ground point.
bool toBool() const
String to numeric methods.
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
unsigned long long ossim_uint64
unsigned int ossim_uint32
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
OSSIM nitf writer base class to hold methods common to all nitf writers.
ossimGpt ulGroundPt() const
Returns the upper left ground point.
ossimDpt urEastingNorthingPt() const
Returns the upper right easting and northing as a ossimDpt.
void setLso(const ossim_float64 &lso)
Sets the LSO field(Longitude Origin).
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
bool hasNans() const
Definition: ossimDpt.h:67
virtual const ossimGpt & getUlGpt() const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
static ossimPreferences * instance()
ossimDpt llEastingNorthingPt() const
Returns the lower left easting and northing as a ossimDpt.
void setLLines(ossim_uint32 lines)
virtual void setImageHeaderV2_1(ossimRefPtr< ossimNitfImageHeaderV2_1 >, bool preferSource=false)
void addGeolobTag(const ossimMapProjection *mapProj, ossimNitfImageHeaderV2_X *hdr)
Adds the GEOLOB tag.
return status
ossimDpt ulEastingNorthingPt() const
Returns the upper left easting and northing as a ossimDpt.
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
ossimPixelType
virtual void initializeDefaultsFromConfigFile(ossimNitfFileHeaderV2_X *fileHdr, ossimNitfImageHeaderV2_X *imgHdr)
Sets file header and image header defaults from config file if found in preferences.
virtual void setUtmSouth(ossim_uint32 zone, const ossimDpt &ul, const ossimDpt &ur, const ossimDpt &lr, const ossimDpt &ll)
void setComplexityLevel(const ossimString &level)
virtual void setProperty(ossimRefPtr< ossimProperty > property)
void writeGeometry(ossimNitfImageHeaderV2_X *hdr, ossimImageSourceSequencer *seq)
Populates tags with geometry info from projection.
bool hasNans() const
Definition: ossimGpt.h:135
#define max(a, b)
Definition: auxiliary.h:76
void setPso(const ossim_float64 &pso)
Sets the PSO field(Latitude Origin).
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Initializes the state of the writer from kwl with prefix then calls base class ossimImageFileWriter::...
void setComplexityLevel(std::streamoff, ossimNitfFileHeaderV2_X *hdr)
Sets the complexity level of theFileHeader.
double x
Definition: ossimDpt.h:164
virtual void addRegisteredTag(ossimRefPtr< ossimNitfRegisteredTag > registeredTag)
This currently only support Rational poilynomial B format.
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
ossim_int32 getZone() const
bool hasProjection() const
Returns TRUE if valid projection defined.
void setDegreesPerPixelLat(const ossim_float64 &deltaLat)
Sets the BRV field from decimal degrees per pixel latitude.
ossim_float64 lat
Definition: ossimGpt.h:265
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
Gets a property.
virtual void setGeographicLocationDms(const ossimDpt &ul, const ossimDpt &ur, const ossimDpt &lr, const ossimDpt &ll)
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
bool theEnableRpcbTagFlag
If true user wants to set RPC00B tag.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Saves the state of the writer to kwl with prefix then calls base class ossimImageFileWriter::saveStat...
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to set fields from a keyword list.
ossimGpt llGroundPt() const
Returns the lower left ground point.