OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeneralRasterInfo.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: David Burken
9 //
10 // Description:
11 // Contains class definition for ossimGeneralRasterInfo
12 //*******************************************************************
13 // $Id: ossimGeneralRasterInfo.cpp 23645 2015-12-04 13:17:34Z gpotts $
14 
18 #include <ossim/base/ossimNotify.h>
21 #include <ossim/base/ossimString.h>
22 #include <ossim/base/ossimTrace.h>
26 
27 #include <iostream>
28 #include <iomanip>
29 
30 static const ossimKeyword
31 NUMBER_LINES("number_lines",
32  "Number of lines in the raster image.");
33 
34 static const ossimKeyword
35 NUMBER_SAMPLES("number_samples",
36  "Number of samples in the raster image.");
37 
38 static const ossimKeyword
39 VALID_START_LINE("valid_start_line",
40  "First valid line of raster image(zero based).");
41 
42 static const ossimKeyword
43 VALID_STOP_LINE("valid_stop_line",
44  "Last valid line of raster image(zero based).");
45 
46 static const ossimKeyword
47 VALID_START_SAMPLE("valid_start_sample",
48  "First valid sample of raster image(zero based).");
49 
50 static const ossimKeyword
51 VALID_STOP_SAMPLE("valid_stop_sample",
52  "Last valid sample of raster image(zero based).");
53 
54 static const ossimKeyword
55 SUB_IMAGE_OFFSET_LINE(
56  "sub_image_offset_line",
57  "Pixel line offset of sub-image in the full-image pixel space.");
58 
59 static const ossimKeyword
60 SUB_IMAGE_OFFSET_SAMP(
61  "sub_image_offset_samp",
62  "Pixel sample offset of sub-image in the full-image pixel space.");
63 
64 static const ossimKeyword
65 HEADER_SIZE("header_size",
66  "Header size in bytes.");
67 
68 static const ossimKeyword
69 SET_NULLS("set_fill_to_nulls_mode",
70  "0 = do nothing to pixels,\n1 = all zeroes to min values,\
71 \n2 = zeroes to null on edges only.");
72 
73 static const ossimKeyword
74 PIXELS_TO_CHOP("pixels_to_chop",
75  "Ammount of pixels to chop from edge.");
76 
77 static const ossimInterleaveTypeLut INTERLEAVE_TYPE_LUT;
78 
79 static ossimTrace traceDebug("ossimGeneralRasterInfo:debug");
80 
82  :
83  theMetaData(),
84  theImageFileList(),
85  theInterleaveType(OSSIM_BIL),
86  theRawImageRect(),
87  theValidImageRect(),
88  theImageRect(),
89  theSubImageOffset(0,0),
90  theHeaderSize(0),
91  theSetNullsMode(NONE),
92  thePixelsToChop(0),
93  theImageDataByteOrder(OSSIM_LITTLE_ENDIAN)
94 {
98 }
99 
100 ossimGeneralRasterInfo::ossimGeneralRasterInfo(const std::vector<ossimFilename>& imageFileList,
101  ossimScalarType pixelType,
102  ossimInterleaveType il_type,
103  ossim_int32 numberOfBands,
104  ossim_int32 lines,
105  ossim_int32 samples,
106  ossim_int32 headerSize,
107  ossimFillMode nullsMode,
108  ossim_int32 pixelsToChop)
109  :
110  theMetaData(pixelType, numberOfBands),
111  theImageFileList(imageFileList),
112  theInterleaveType(il_type),
113  theRawImageRect(0,0,0,0),
114  theValidImageRect(0,0,0,0),
115  theImageRect(0,0,0,0),
116  theSubImageOffset(0,0),
117  theHeaderSize(headerSize),
118  theSetNullsMode(nullsMode),
119  thePixelsToChop(pixelsToChop),
120  theImageDataByteOrder(OSSIM_LITTLE_ENDIAN)
121 {
122  theRawImageRect.set_lry(lines - 1);
123  theRawImageRect.set_lrx(samples - 1);
126 }
127 
129  const char* prefix)
130  :
131  theImageFileList(),
132  theInterleaveType(OSSIM_BIL),
133  theRawImageRect(0,0,0,0),
134  theValidImageRect(0,0,0,0),
135  theImageRect(0,0,0,0),
136  theSubImageOffset(0,0),
137  theHeaderSize(0),
138  theSetNullsMode(NONE),
139  thePixelsToChop(0),
140  theImageDataByteOrder(OSSIM_LITTLE_ENDIAN)
141 {
145 
146  loadState(kwl, prefix);
147 }
148 
150  :
151  theMetaData ( obj.theMetaData ),
152  theImageFileList ( obj.theImageFileList ),
153  theInterleaveType ( obj.theInterleaveType ),
154  theRawImageRect ( obj.theRawImageRect ),
155  theValidImageRect ( obj.theValidImageRect ),
156  theImageRect ( obj.theImageRect ),
157  theSubImageOffset ( obj.theSubImageOffset ),
158  theHeaderSize ( obj.theHeaderSize ),
159  theSetNullsMode ( obj.theSetNullsMode ),
160  thePixelsToChop ( obj.thePixelsToChop ),
161  theImageDataByteOrder ( obj.theImageDataByteOrder )
162 {
163 }
164 
166  const ossimGeneralRasterInfo& rhs )
167 {
168  if ( this != &rhs )
169  {
170  theMetaData = rhs.theMetaData;
181  }
182  return *this;
183 }
184 
186 {
187 }
188 
190 {
191  theMetaData.clear();
192  theImageFileList.clear();
197  theSubImageOffset.x = 0;
198  theSubImageOffset.y = 0;
199  theHeaderSize = 0;
201  thePixelsToChop = 0;
203 }
204 
206 {
207  return theImageRect;
208 }
209 
211 {
212  return theValidImageRect;
213 }
214 
216 {
217  return theRawImageRect;
218 }
219 
221 {
222  return theSubImageOffset;
223 }
224 
226 {
227  return theHeaderSize;
228 }
229 
231 {
232  return theSetNullsMode;
233 }
234 
236 {
237  //---
238  // This will print in a keyword format that can be read by the constructor.
239  // that takes a keyword list.
240  //---
241  ossimKeywordlist kwl;
242  saveState( kwl, 0 );
243  out << kwl << std::endl;
244  return out;
245 }
246 
248 {
249  static const char MODULE[] = "ossimGeneralRasterInfo::setFillToNullMode";
250  if(mode < 3)
251  {
253  }
254  else
255  {
257  << MODULE << " ERROR:"
258  << "\nmode out of bounds(0 - 2): " << mode << std::endl
259  << "\nmode has not been changed." << std::endl;
260  }
261 }
262 
264 {
265  return thePixelsToChop;
266 }
267 
269 {
270  return theInterleaveType;
271 }
272 
273 const std::vector<ossimFilename>& ossimGeneralRasterInfo::getImageFileList() const
274 {
275  return theImageFileList;
276 }
277 
278 void ossimGeneralRasterInfo::setImageFileList(const std::vector<ossimFilename>& list)
279 {
280  theImageFileList = list;
281 }
282 
284 {
285  theImageFileList.clear();
286  theImageFileList.push_back( file );
287 }
288 
290 {
292 }
293 
295 {
297 }
298 
300 {
301  theInterleaveType = il_type;
302 }
303 
305 {
307 }
308 
310 {
312 }
313 
315 {
317 }
318 
320 {
321  theSubImageOffset = d;
322 }
323 
325 {
326  return theImageDataByteOrder;
327 }
328 
330  const char* prefix) const
331 {
332  for (ossim_uint32 i=0; i<theImageFileList.size(); ++i)
333  {
335  kw += ossimString::toString(i+1);
336  kwl.add(prefix, theImageFileList[i].c_str());
337  }
338 
339  theMetaData.saveState(kwl, prefix);
340 
341  kwl.add(prefix,
342  NUMBER_LINES,
343  ossimString::toString( rawLines() ), true);
344  kwl.add(prefix,
345  NUMBER_SAMPLES,
347  true);
348  kwl.add(prefix,
349  HEADER_SIZE,
351  true);
352  kwl.add(prefix,
353  SUB_IMAGE_OFFSET_LINE,
355  true);
356  kwl.add(prefix,
357  SUB_IMAGE_OFFSET_SAMP,
359  true);
360  kwl.add(prefix,
361  VALID_START_LINE,
363  true);
364  kwl.add(prefix,
365  VALID_STOP_LINE,
367  true);
368  kwl.add(prefix,
369  VALID_START_SAMPLE,
371  true);
372  kwl.add(prefix,
373  VALID_STOP_SAMPLE,
375  true);
376  kwl.add(prefix,
378  INTERLEAVE_TYPE_LUT.getEntryString(theInterleaveType),
379  true);
380 
381  kwl.add(prefix,
382  PIXELS_TO_CHOP,
384  true);
385 
386  kwl.add(prefix,
387  SET_NULLS,
389  true);
390 
391 
392  if (bytesPerPixel() > 1)
393  {
394  kwl.add(prefix,
396  (theImageDataByteOrder == OSSIM_LITTLE_ENDIAN ? "little_endian" :
397  "big_endian"),
398  true);
399  }
400 
401  return true;
402 }
403 
404 bool ossimGeneralRasterInfo::loadState(const ossimKeywordlist& kwl, const char* prefix)
405 {
406  static const char MODULE[] = "ossimGeneralRasterInfo::loadState";
407  if ( traceDebug() )
408  {
409  CLOG << "DEBUG: entered..."
410  << "\nprefix: " << (prefix ? prefix : "")
411  << "\nInput keyword list:\n"
412  << kwl
413  << std::endl;
414  }
415 
416  bool result = false;
417 
418  //---
419  // Look for required and option keyword. Break from loop if required
420  // keyword is not found.
421  //---
422  while( 1 )
423  {
424  // Check for errors in the ossimKeywordlist.
426  {
427  if(traceDebug())
428  {
430  << MODULE << " ERROR:\n"
431  << "Detected an error in the keywordlist: " << kwl
432  << std::endl;
433  }
434  break;
435  }
436 
437  std::string key;
438  ossimString value; // Use for keyword list lookups.
439  ossim_int32 lines = 0;
440  ossim_int32 samples = 0;
441 
442  // Lines (required):
443  key = NUMBER_LINES;
444  value.string() = kwl.findKey( key ); // Required to have this.
445  if ( value.size() )
446  {
447  lines = value.toInt32();
448  if ( !lines )
449  {
450  if (traceDebug())
451  {
453  << " ERROR:\n"
454  << "Required number of lines is 0!" << std::endl;
455  }
456  break;
457  }
458  }
459  else
460  {
461  if (traceDebug())
462  {
464  << " ERROR:\n"
465  << "Required keyword not found: " << key << std::endl;
466  }
467  break;
468  }
469 
470  // Samples (required):
471  key = NUMBER_SAMPLES;
472  value.string() = kwl.findKey( key ); // Required to have this.
473  if ( value.size() )
474  {
475  samples = value.toInt32();
476  if ( !samples )
477  {
478  if (traceDebug())
479  {
481  << " ERROR:\n"
482  << "Required number of samples is 0!" << std::endl;
483  }
484  break;
485  }
486  }
487  else
488  {
489  if (traceDebug())
490  {
492  << " ERROR:\n"
493  << "Required keyword not found: " << key << std::endl;
494  }
495  break;
496  }
497 
498  // Bands ossimImageMetaData::loadState checks for required bands:
499  if(!theMetaData.loadState(kwl, prefix))
500  {
501  if (traceDebug())
502  {
504  << " Error loading meta data!\n" << std::endl;
505  }
506  break;
507  }
508 
509  // If we get here assign the rectangles:
510  theRawImageRect = ossimIrect( 0, 0, samples - 1, lines - 1 );
513 
514  int tmp = INTERLEAVE_TYPE_LUT.getEntryNumber(kwl);
515  if (tmp == ossimLookUpTable::NOT_FOUND)
516  {
518  }
519  else
520  {
521  theInterleaveType = static_cast<ossimInterleaveType>(tmp);
522  }
523 
524  // Get the image files.
526  {
527  // Look for "filename" first, then deprecated "image_file".
529  value.string() = kwl.findKey( key );
530  if ( value.empty() )
531  {
532  // deprecated keyword...
534  value.string() = kwl.findKey( key );
535  }
536 
537  if ( value.size() )
538  {
539  //---
540  // omd (ossim metadata) files can have just the base filename, e.g. image.ras,
541  // in which case open will fail if not in the image dir. So only put it in
542  // the list if it doesn't exits.
543  //---
544  ossimFilename f = value;
545  if ( f.exists() )
546  {
547  theImageFileList.clear();
548  theImageFileList.push_back(ossimFilename(value));
549  }
550  }
551 
552  if ( theImageFileList.empty() )
553  {
554  if (traceDebug())
555  {
557  << "ERROR:\n"
558  << "Required keyword not found: "
559  << ossimKeywordNames::FILENAME_KW << std::endl;
560  }
561  break;
562  }
563  }
564  else
565  {
566  // multiple file names.
567  ossim_int32 count = 0;
568 
569  // look for image file key word with no number.
570  // Required to have this.
572  value.string() = kwl.findKey( key );
573  if ( value.empty() )
574  {
575  // deprecated keyword...
577  value.string() = kwl.findKey( key );
578  }
579 
580  if ( value.size() )
581  {
582  theImageFileList.push_back(ossimFilename(value));
583  ++count;
584  }
585 
586  ossim_int32 i = 0;
587  while ( (count < numberOfBands()) && (i < 1000) )
588  {
590  key += ossimString::toString(i).string();
591  value.string() = kwl.findKey( key );
592  if ( value.empty() )
593  {
594  // Lookup for deprecated keyword.
596  key += ossimString::toString(i).string();
597  value.string() = kwl.findKey( key );
598  }
599 
600  if ( value.size() )
601  {
602  theImageFileList.push_back(ossimFilename(value));
603  ++count;
604  }
605  ++i;
606  }
607 
608  if (count != numberOfBands()) // Error, count should equal bands!
609  {
610  if (traceDebug())
611  {
613  << " ERROR:\n"
614  << "Required keyword not found: "
616  << "\nInterleave type is multi file; however,"
617  << " not enough were pick up!" << std::endl;
618  }
619  break;
620  }
621  }
622 
623  key = VALID_START_LINE;
624  value.string() = kwl.findKey( key ); // Default is zero.
625  if ( value.size() )
626  {
627  theValidImageRect.set_uly( value.toInt32() );
628  }
629 
630  key = VALID_STOP_LINE;
631  value.string() = kwl.findKey( key ); // Default is last line.
632  if ( value.size() )
633  {
634  theValidImageRect.set_lry( value.toInt32() );
635  }
636 
638  {
640  << " ERROR:"
641  << "\nValid stop line < start line."
642  << "\nValid start line: " << theValidImageRect.ul().y
643  << "\nValid stop line: " << theValidImageRect.lr().y
644  << "\nError status has been set. Returning." << std::endl;
645  break;
646  }
647 
648  key = VALID_START_SAMPLE;
649  value.string() = kwl.findKey( key ); // Default is zero.
650  if ( value.size() )
651  {
652  theValidImageRect.set_ulx( value.toInt32() );
653  }
654 
655  key = VALID_STOP_SAMPLE;
656  value.string() = kwl.findKey( key ); // Default is last sample.
657  if ( value.size() )
658  {
659  theValidImageRect.set_lrx( value.toInt32() );
660  }
661 
663  {
665  << " ERROR:"
666  << "\nValid stop samp < start samp."
667  << "\nValid start samp: " << theValidImageRect.ul().x
668  << "\nValid stop samp: " << theValidImageRect.lr().x
669  << "\nError status has been set. Returning." << std::endl;
670  break;
671  }
672 
677 
678  key = SUB_IMAGE_OFFSET_LINE;
679  value.string() = kwl.findKey( key ); // Default is zero.
680  if ( value.size() )
681  {
682  theSubImageOffset.line = value.toInt32();
683  }
684 
685  key = SUB_IMAGE_OFFSET_SAMP;
686  value.string() = kwl.findKey( key ); // Default is zero.
687  if ( value.size() )
688  {
689  theSubImageOffset.samp = atoi(value);
690  }
691 
692  key = HEADER_SIZE;
693  value.string() = kwl.findKey( key ); // Default is zero.
694  if ( value.size() )
695  {
696  theHeaderSize = value.toInt32();
697  }
698 
699  key = SET_NULLS;
700  value.string() = kwl.findKey( key ); // Default is 2.
701  if ( value.size() )
702  {
703  int tmp;
704  tmp = atoi(value);
705  if ((tmp < 3) && (tmp > -1))
706  {
708  }
709  else
710  {
713  << " WARNING:"
714  << "\nset_fill_to_nulls_mode value out of range."
715  << "\nDefaulted to 2" << std::endl;
716  }
717  }
718 
719  key = PIXELS_TO_CHOP;
720  value.string() = kwl.findKey( key ); // Default is zero.
721  if ( value.size() )
722  {
723  thePixelsToChop = value.toInt32();
724  }
725 
726  if (bytesPerPixel() > 1)
727  {
728  // get the byte order of the data.
730  value.string() = kwl.findKey( key );
731  if ( value.size() )
732  {
733  ossimString s(value);
734  if (s.trim() != "") // Check for empty string.
735  {
736  s.downcase();
737  if (s.contains("big"))
738  {
740  }
741  else if(s.contains("little"))
742  {
744  }
745  }
746  }
747  }
748 
749  // End of while forever loop.
750  result = true;
751  break;
752 
753  } // Matches: while (1)
754 
755  if ( traceDebug() )
756  {
758  << MODULE << " Exit status: " << (result?"true":"false") << std::endl;
759  }
760 
761  return result;
762 
763 } // End: bool ossimGeneralRasterInfo::loadState
764 
766 {
767  static const char MODULE[] = "ossimGeneralRasterInfo::open";
768  if ( traceDebug() )
769  {
771  << MODULE << " entered..." << "\nimageFile: " << imageFile << std::endl;
772  }
773 
774  bool result = false;
775 
776  // Wipe any previous state slick.
777  clear();
778 
779  ossimFilename copyFile = imageFile;
780  if ( !imageFile.exists() )
781  {
782  copyFile = imageFile.expand();
783  }
784 
785  // Look for the headrer of omd file as they are written out by img2rr.
786  ossimFilename hdr = copyFile;
787  hdr.setExtension("hdr"); // image.hdr
788  if ( !hdr.exists() )
789  {
790  hdr = imageFile;
791  hdr.string() += ".hdr"; // image.ras.hdr
792  if ( ! hdr.exists() )
793  {
794  hdr = imageFile;
795  hdr.setExtension("xml"); // image.xml
796  }
797  }
798 
799  if ( hdr.exists() )
800  {
801  if ( traceDebug() )
802  {
803  ossimNotify(ossimNotifyLevel_DEBUG) << "header file: " << hdr << std::endl;
804  }
805 
806  ossimString ext = hdr.ext().downcase();
807 
808  if ( ext == "hdr" )
809  {
810  if ( ossimEnviHeader::isEnviHeader( hdr ) )
811  {
812  result = initializeFromEnviHdr( hdr );
813  }
814  else
815  {
816  result = initializeFromHdr( imageFile, hdr );
817  }
818 
819  if ( !result )
820  {
821  // Could be an ossim meta data file:
822  ossimKeywordlist kwl( hdr );
823  result = loadState( kwl, 0 );
824  }
825  }
826  else if ( ext == "xml" )
827  {
828  result = initializeFromXml( imageFile, hdr );
829  }
830  }
831 
832  //---
833  // Set the file name. Needed for ossimGeneralRasterTileSource::open.
834  // Note set here above loadState call to stop loadState from returning
835  // false if no image file found.
836  //---
837  if ( theImageFileList.empty() )
838  {
839  setImageFile( imageFile );
840  }
841 
842  ossimFilename omd = imageFile;
843  omd.setExtension("omd"); // image.omd
844  if ( !omd.exists() )
845  {
846  omd.setExtension("kwl"); // image.kwl
847  }
848 
849  if ( omd.exists() )
850  {
851  if ( traceDebug() )
852  {
853  ossimNotify(ossimNotifyLevel_DEBUG) << "omd file: " << omd << std::endl;
854  }
855 
856  ossimKeywordlist kwl( omd );
857 
858  if ( result && theMetaData.getNumberOfBands() )
859  {
860  //---
861  // Just update the band info in case it has min/max values from
862  // a compute min/max scan.
863  //---
864  theMetaData.updateMetaData( kwl, std::string("") );
865  }
866  else
867  {
868  // We're not initialized yet so do a loadState:
869  result = loadState( kwl, 0 );
870  }
871  }
872 
873  if ( traceDebug() )
874  {
876  << MODULE << " Exit status: " << (result?"true":"false") << std::endl;
877  }
878 
879  return result;
880 }
881 
883  const ossimFilename& headerFile )
884 {
885  bool result = false;
886 
887  ossimKeywordlist kwl;
888  char delimeter = ' ';
889  kwl.change_delimiter(delimeter);
890 
891  if ( kwl.addFile(headerFile) )
892  {
893  kwl.downcaseKeywords();
894  ossimString value;
895 
896  while( 1 )
897  {
898  //---
899  // Go through the data members in order.
900  // If a required item is not found break from loop.
901  //--
902  theMetaData.clear();
903 
904  // scalar ( default ) - adjusted below :
906 
907  // Image file name:
908  theImageFileList.clear();
909  theImageFileList.push_back( imageFile );
910 
911  // interleave ( not required - default=BIL)
913  value.string() = kwl.findKey( std::string("layout") );
914  if ( value.size() )
915  {
917  ossim_int32 intrlv = lut.getEntryNumber( value.string().c_str(), true );
918  if ( intrlv != ossimLookUpTable::NOT_FOUND )
919  {
920  theInterleaveType = static_cast<ossimInterleaveType>(intrlv);
921  }
922  }
923 
924  // bands ( required ):
925  ossim_uint32 bands = 0;
926  value.string() = kwl.findKey( std::string("nbands") );
927  if ( value.size() )
928  {
929  bands = value.toUInt32();
930  }
931  if ( !bands )
932  {
933  break;
934  }
935  theMetaData.setNumberOfBands( bands );
936 
937  // lines ( required ):
938  ossim_int32 lines = 0;
939  value.string() = kwl.findKey( std::string("nrows") );
940  if ( value.size() )
941  {
942  lines = value.toInt32();
943  }
944  if ( !lines )
945  {
946  break;
947  }
948 
949  // samples ( required ):
950  ossim_int32 samples = 0;
951  value.string() = kwl.findKey( std::string("ncols") );
952  if ( value.size() )
953  {
954  samples = value.toInt32();
955  }
956  if ( !samples )
957  {
958  break;
959  }
960 
961  // nodata or null value ( not required )
962  value.string() = kwl.findKey( std::string("nodata") );
963  if ( value.empty() )
964  {
965  value.string() = kwl.findKey( std::string("nodata_value") );
966  }
967  if ( value.size() )
968  {
969  ossim_float64 nullValue = value.toUInt32();
970  for ( ossim_uint32 band = 0; band < theMetaData.getNumberOfBands(); ++band )
971  {
972  theMetaData.setNullPix( band, nullValue );
973  }
975  }
976 
977  // Set the rectangles:
978  theRawImageRect = ossimIrect( 0, 0, samples - 1, lines - 1 );
981 
982  // sample start ( not required ):
983  theSubImageOffset.x = 0;
984 
985  // line start ( not required ):
986  theSubImageOffset.y = 0;
987 
988  // header offset ( not required ):
989  theHeaderSize = 0;
990 
991  // null mode:
993 
994  // pixels to chop:
995  thePixelsToChop = 0;
996 
997  // Byte order, ( not required - defaulted to system if not found.
999  value.string() = kwl.findKey( std::string("byteorder") );
1000  if ( value.size() )
1001  {
1002  ossim_uint32 i = value.toUInt32();
1003  if ( i == 0 )
1004  {
1006  }
1007  else
1008  {
1010  }
1011  }
1012 
1013  // Pixel type used for scalar below:
1014  std::string pixelType = "N"; // not defined
1015  value.string() = kwl.findKey( std::string("pixeltype") );
1016  if ( value.size() )
1017  {
1018  pixelType = value.string();
1019  }
1020 
1021  ossim_int32 nbits = -1;
1022  value.string() = kwl.findKey( std::string("nbits") );
1023  if ( value.size() )
1024  {
1025  nbits = value.toInt32();
1026  }
1027  else
1028  {
1029  nbits = getBitsPerPixel( imageFile );
1030  }
1031 
1032  switch( nbits )
1033  {
1034  case 8:
1035  {
1037  break;
1038  }
1039  case 16:
1040  {
1041  if (pixelType == "S")
1042  {
1044  }
1045  else
1046  {
1048  }
1049  break;
1050  }
1051  case 32:
1052  {
1053  if( pixelType == "S")
1054  {
1056  }
1057  else if( pixelType == "F")
1058  {
1060  }
1061  else
1062  {
1064  }
1065  break;
1066  }
1067  default:
1068  {
1069  if( (nbits < 8) && (nbits >= 1 ) )
1070  {
1072  }
1073  break;
1074  }
1075  }
1076 
1077  result = true;
1078  break; // Trailing break to get out.
1079  }
1080  }
1081 
1082  return result;
1083 
1084 } // End: ossimGeneralRasterInfo::initializeFromHdr
1085 
1086 
1088 {
1089  bool result = false;
1090  ossimEnviHeader hdr;
1091  if( hdr.open( headerFile ) )
1092  {
1093  result = initializeFromEnviHdr( hdr );
1094  }
1095  return result;
1096 }
1097 
1099 {
1100  bool result = false;
1101 
1102  while( 1 )
1103  {
1104  //---
1105  // Go through the data members in order.
1106  // If a required item is not found break from loop.
1107  //--
1108  theMetaData.clear();
1109 
1110  // scalar ( required ) :
1111  if( enviHdr.getOssimScalarType() != OSSIM_SCALAR_UNKNOWN )
1112  {
1114  }
1115  else
1116  {
1117  break;
1118  }
1119 
1120  theImageFileList.clear();
1121 
1122  // interleave ( required ):
1125  {
1126  break;
1127  }
1128 
1129  // bands ( required ):
1130  if ( !enviHdr.getBands() )
1131  {
1132  break;
1133  }
1134  theMetaData.setNumberOfBands( enviHdr.getBands() );
1135 
1136  // lines ( required ):
1137  ossim_uint32 lines = enviHdr.getLines();
1138  if ( !lines )
1139  {
1140  break;
1141  }
1142 
1143  // samples ( required ):
1144  ossim_uint32 samples = enviHdr.getSamples();
1145  if ( !samples )
1146  {
1147  break;
1148  }
1149 
1150  // Set the rectangles:
1151  theRawImageRect = ossimIrect( 0, 0, samples - 1, lines - 1 );
1154 
1155  // sample start ( not required ):
1156  theSubImageOffset.x = enviHdr.getXStart();
1157 
1158  // line start ( not required ):
1159  theSubImageOffset.y = enviHdr.getYStart();
1160 
1161  // header offset ( not required ):
1162  theHeaderSize = enviHdr.getHeaderOffset();
1163 
1164  // null mode:
1166 
1167  // pixels to chop:
1168  thePixelsToChop = 0;
1169 
1170  // Byte order, this will be system if not found.
1171  theImageDataByteOrder = enviHdr.getByteOrder();
1172 
1173  result = true;
1174  break; // Trailing break to get out.
1175  }
1176  return result;
1177 
1178 } // End: ossimGeneralRasterInfo::initializeFromEnviHdr( const ossimEnviHeader& )
1179 
1181  const ossimFilename& headerFile )
1182 {
1183  bool result = false;
1184 
1185  ossimFgdcXmlDoc file;
1186  if (file.open( headerFile ))
1187  {
1188  while( 1 )
1189  {
1190  //---
1191  // Go through the data members in order.
1192  // If a required item is not found break from loop.
1193  //--
1194  theMetaData.clear();
1195 
1196  // scalar ( default ) - adjusted below :
1198 
1199  // Image file name:
1200  theImageFileList.clear();
1201  theImageFileList.push_back( imageFile );
1202 
1203  // interleave ( defaulted ):
1205 
1206  // bands ( required ):
1207  if ( !file.getNumberOfBands() )
1208  {
1209  break;
1210  }
1212 
1213  ossimIpt size;
1214  if ( file.getImageSize(size) ) // Lines, samples not image file size.
1215  {
1216  // lines, samples ( required ):
1217  if ( !size.x || !size.y )
1218  {
1219  break;
1220  }
1221  }
1222  else
1223  {
1224  break;
1225  }
1226 
1227  // Set the rectangles:
1228  theRawImageRect = ossimIrect( 0, 0, size.x - 1, size.y - 1 );
1231 
1232  // sample start ( not required ):
1233  theSubImageOffset.x = 0;
1234 
1235  // line start ( not required ):
1236  theSubImageOffset.y = 0;
1237 
1238  // header offset ( not required ):
1239  theHeaderSize = 0;
1240 
1241  // null mode:
1243 
1244  // pixels to chop:
1245  thePixelsToChop = 0;
1246 
1247  // Byte order *** need this ***, defaulting to system for now:
1249 
1250  // Adjust scalar if needed, note defaulted to 8 bit above:
1251  ossimString eainfo;
1252  file.getPath("/metadata/eainfo/detailed/enttyp/enttypd", eainfo);
1253  ossim_int32 numBits = 0;
1254  ossim_int64 fileSize = imageFile.fileSize(); // Image file size.
1255  ossim_int32 numBytes = fileSize / size.x / size.y / numberOfBands();
1256  if( numBytes > 0 && numBytes != 3 )
1257  {
1258  numBits = numBytes*8;
1259  }
1260  if( numBits == 16 )
1261  {
1263  }
1264  else if( numBits == 32 )
1265  {
1266  if(eainfo.contains("float"))
1267  {
1269  }
1270  else
1271  {
1273  }
1274  }
1275 
1276  result = true;
1277  break; // Trailing break to get out.
1278  }
1279  }
1280 
1281  return result;
1282 
1283 } // End: ossimGeneralRasterInfo::initializeFromXml
1284 
1286 {
1287  // Note currently does not consider header size.
1288  ossim_int32 result = 0;
1289 
1290  ossim_int64 fileSize = imageFile.size();
1291  ossimIpt rectSize = theRawImageRect.size();
1292  if ( fileSize && rectSize.x && rectSize.y && numberOfBands() )
1293  {
1294  result = ( fileSize / rectSize.x / rectSize.y / numberOfBands() ) * 8;
1295  }
1296  return result;
1297 }
1298 
void set_uly(ossim_int32 y)
Definition: ossimIrect.h:666
void setScalarType(ossimScalarType aType)
static const char * BYTE_ORDER_KW
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossimScalarType getOssimScalarType() const
ossim_int32 bytesPerPixel() const
Bytes per pixel.
ossim_int32 theHeaderSize
Size of header in bytes.
ossimInterleaveType getOssimInterleaveType() const
ossim_uint32 getHeaderOffset() const
ossimIrect theValidImageRect
The rectangle representing where the valid part of the image lies within "theRawImageRect".
#define CLOG
Definition: ossimTrace.h:23
16 bit unsigned integer
ossim_int32 headerSize() const
Returns the size of header in bytes.
ossim_int32 thePixelsToChop
Amount of pixels to chop for each line edge.
void setImageFileList(const std::vector< ossimFilename > &list)
const ossimIrect & validImageRect() const
Returns the rectangle of where the image is within the raster file.
Represents serializable keyword/value map.
bool addFile(const char *file)
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
ossimByteOrder theImageDataByteOrder
The byte order the image data is stored in.
void setNullValuesValid(bool flag)
ossimInterleaveType interleaveType() const
Enumerated in InterleaveTypeLUT.
ossim_int64 fileSize() const
ossimFilename expand() const
Method to do file name expansion.
virtual ossimString getEntryString(ossim_int32 entry_number) const
ossim_uint32 getNumberOfBands()
Get Bands.
ossimKeywordlist & downcaseKeywords()
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
static bool isEnviHeader(const ossimFilename &file)
Global method to test first line of file for "ENVI".
bool contains(char aChar) const
Definition: ossimString.h:58
ossimImageMetaData theMetaData
static ossimString toString(bool aValue)
Numeric to string methods.
bool getPath(const ossimString &path, ossimString &s) const
Gets path from doc and initializes string.
std::vector< ossimFilename > theImageFileList
16 bit signed integer
const ossimIpt & ul() const
Definition: ossimIrect.h:274
void change_delimiter(char del)
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
static const ossimErrorCode OSSIM_ERROR
ossim_uint32 toUInt32() const
32 bit floating point
32 bit unsigned integer
ossimIpt size() const
Definition: ossimIrect.h:510
ossim_uint32 getNumberOfBands() const
bool initializeFromHdr(const ossimFilename &imageFile, const ossimFilename &headerFile)
Initialize from header file.
ossimByteOrder getImageDataByteOrder() const
void clear()
Clears data members.
virtual std::ostream & print(std::ostream &out) const
Generic print method.
virtual ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
ossim_int32 toInt32() const
void setNumberOfBands(ossim_uint32 numberOfBands)
bool open(const ossimFilename &file)
Opens an envi header.
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossim_uint32 getLines() const
const std::vector< ossimFilename > & getImageFileList() const
const ossimIrect & rawImageRect() const
Zero based rectangle of the raw image.
const ossimIpt & subImageOffset() const
Returns the offset of this image&#39;s origin to a full-image&#39;s origin, in the case where this image is a...
bool open(const ossimFilename &imageFile)
Takes image file and attempts to derive/find header file to parse for general raster data...
yy_size_t size
bool exists() const
void setSubImageOffset(const ossimIpt &d)
ossimInterleaveType theInterleaveType
std::string::size_type size() const
Definition: ossimString.h:405
32 bit signed integer
void setRawImageRect(const ossimIrect &imageRect)
ossim_uint32 getBands() const
void setFillToNullsMode(ossim_uint32 mode)
Sets theSetNullsMode.
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
ossim_int32 rawLines() const
Returns the number of lines within "theRawImageRect".
ossim_int32 getXStart() const
Class for FGDC XML doc parsing.
ossimFillMode theSetNullsMode
Mode of how to handle pixels on import.
ossim_int32 rawSamples() const
Returns the number of samples within "theRawImageRect".
void setImageFile(const ossimFilename &file)
Sets the image file list to file.
ossim_int32 getBitsPerPixel(const ossimFilename &imageFile) const
Private method to get bits per pixel from file size, lines, samples and bands.
bool getImageSize(ossimIpt &size) const
ossimByteOrder
const ossimIpt & lr() const
Definition: ossimIrect.h:276
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void setValidImageRect(const ossimIrect &imageRect)
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossimInterleaveType
bool initializeFromXml(const ossimFilename &imageFile, const ossimFilename &headerFile)
Initialize from omd file.
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
const ossimGeneralRasterInfo & operator=(const ossimGeneralRasterInfo &rhs)
Assignment operator=.
ossim_uint32 getSamples() const
const ossimIpt & ur() const
Definition: ossimIrect.h:275
ossimScalarType
ossimIrect theImageRect
The valid image rectangle normalized to be zero based.
void set_lrx(ossim_int32 x)
Definition: ossimIrect.h:693
ossimIpt theSubImageOffset
The offset from the full-image origin to this image&#39;s origin.
void setInterleaveType(ossimInterleaveType il_type)
static const char * INTERLEAVE_TYPE_KW
ossim_int32 samp
Definition: ossimIpt.h:141
virtual ossimErrorCode getErrorStatus() const
void set_lry(ossim_int32 y)
Definition: ossimIrect.h:702
bool initializeFromEnviHdr(const ossimEnviHeader &enviHdr)
Initialize from envi header file.
ossim_int32 y
Definition: ossimIpt.h:142
ossimIrect theRawImageRect
The zero based rectangle of the entire image not including any header.
void makeNan()
Definition: ossimIrect.h:329
ossim_int32 getYStart() const
Class for reading and writing an ENVI (The Environment for Visualizing Images) header file...
ossim_uint32 fillToNullsMode() const
Returns the fill mode.
long long ossim_int64
ossim_int32 pixelsToChop() const
Returns the number of pixels from the edge of a line to set to the fill value.
bool empty() const
Definition: ossimString.h:411
const ossimIrect & imageRect() const
Zero based rectangle of the valid image.
ossim_int32 line
Definition: ossimIpt.h:142
ossimString ext() const
bool open(const ossimFilename &xmlFileName)
Open method.
void setImageDataByteOrder(ossimByteOrder byteOrder)
ossim_int32 x
Definition: ossimIpt.h:141
8 bit unsigned integer
static const char * IMAGE_FILE_KW
ossimByteOrder getByteOrder() const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
void setHeaderSize(ossim_int32 headerSize)
static const char * FILENAME_KW
ossim_int32 numberOfBands() const
Number of bands.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void updateMetaData(const ossimKeywordlist &kwl, const std::string &prefix)
Method to update band values.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
void setNullPix(ossim_uint32 band, double pix)
int ossim_int32
void set_ulx(ossim_int32 x)
Definition: ossimIrect.h:657
const std::string & string() const
Definition: ossimString.h:414
void setImageRect(const ossimIrect &imageRect)