OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageFileWriter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Frank Warmerdam (warmerdam@pobox.com)
6 //
7 // Description:
8 //
9 // Contains class declaration for ossimImageFileWriter.
10 //*******************************************************************
11 // $Id: ossimImageFileWriter.cpp 23068 2015-01-07 23:08:29Z okramer $
12 
13 
14 #include <tiff.h> /* for tiff compression defines */
15 
16 #include <ossim/ossimConfig.h>
45 #include <ossim/base/ossimTrace.h>
49 
50 static ossimTrace traceDebug("ossimImageFileWriter:debug");
51 static const ossimString AUTO_CREATE_DIRECTORY_KW("auto_create_directory");
52 
53 #if OSSIM_ID_ENABLED
54 static const char OSSIM_ID[] = "$Id: ossimImageFileWriter.cpp 23068 2015-01-07 23:08:29Z okramer $";
55 #endif
56 
58  "ossimImageFileWriter",
62 
63 static const char SCALE_TO_EIGHT_BIT_KW[] = "scale_to_eight_bit";
64 
66  ossimImageSource* inputSource,
67  ossimObject* owner)
68  : ossimImageWriter(owner,
69  1,
70  0,
71  true,
72  false),
75  theViewController(NULL),
76  theProgressListener(NULL),
77  theFilename(file),
78  theOutputImageType(ossimImageTypeLut().getEntryString(OSSIM_IMAGE_TYPE_UNKNOWN)),
79  theWriteImageFlag(true),
80  theWriteOverviewFlag(false),
81  theWriteHistogramFlag(false),
82  theScaleToEightBitFlag(false),
83  theOverviewCompressType(COMPRESSION_NONE),
84  theOverviewJpegCompressQuality(75),
85  theWriteEnviHeaderFlag(false),
86  theWriteErsHeaderFlag(false),
87  theWriteExternalGeometryFlag(false),
88  theWriteFgdcFlag(false),
89  theWriteJpegWorldFileFlag(false),
90  theWriteReadmeFlag(false),
91  theWriteTiffWorldFileFlag(false),
92  theWriteWorldFileFlag(false),
93  theAutoCreateDirectoryFlag(true),
94  theLinearUnits(OSSIM_UNIT_UNKNOWN),
95  thePixelType(OSSIM_PIXEL_IS_POINT)
96 {
97  if (traceDebug())
98  {
100  << "ossimImageFileWriter::ossimImageFileWriter entered..."
101  << std::endl;
102 #ifdef OSSIM_ID_ENABLED
104  << "OSSIM_ID: " << OSSIM_ID << std::endl;
105 #endif
106  }
107 
109 
110  // now map the sequencer to the same input
111  connectMyInputTo(0, inputSource);
112  initialize();
113 
114  // make sure we listen to our input changes so we can change
115  // it for the sequencer as well.
117 
118  theInputConnection->connectMyInputTo(0, inputSource, false);
120 }
121 
123 {
124  theInputConnection = 0;
125  theProgressListener = NULL;
127 }
128 
130 {
132  {
134 
135  //---
136  // Area Of Interest(AOI):
137  // There are two AOIs to keep in sync.
138  // One owned by this base: ossimImageWriter::theAreaOfInterest
139  // One owned by the theInputConntion: ossimImageSourceSequencer::theAreaOfInterest
140  //---
141  if ( theAreaOfInterest.hasNans() == false )
142  {
143  //---
144  // ossimImageSourceSequencer::setAreaOfInterest does more than just set the
145  // variable, so only call if out of sync to avoid wasted cycles.
146  //---
148  {
150  }
151  }
152  else
153  {
154  // Set this AOI to bounding rect of input.
156  }
157  }
158 }
159 
161 {
162  if( sequencer )
163  {
164  theInputConnection = sequencer;
166  }
167 }
168 
170  const char* prefix)const
171 {
172  kwl.add(prefix,
174  getClassName(),
175  true);
176 
177  kwl.add(prefix,
179  theFilename.c_str(),
180  true);
181 
182  kwl.add(prefix,
183  "create_envi_hdr",
185  true);
186 
187  kwl.add(prefix,
188  "create_ers_hdr",
190  true);
191 
192  kwl.add(prefix,
195  true);
196 
197  kwl.add(prefix,
198  "create_fgdc",
200  true);
201 
202  kwl.add(prefix,
203  "create_jpeg_world_file",
205  true);
206 
207  kwl.add(prefix,
208  "create_readme",
210  true);
211 
212  kwl.add(prefix,
213  "create_tiff_world_file",
215  true);
216 
217  kwl.add(prefix,
218  "create_world_file",
220  true);
221 
222  kwl.add(prefix,
225  true);
226 
227  kwl.add(prefix,
230  true);
231 
232  kwl.add(prefix,
235  true);
236 
237  kwl.add(prefix,
238  SCALE_TO_EIGHT_BIT_KW,
240  true);
241  kwl.add(prefix,
242  AUTO_CREATE_DIRECTORY_KW,
244  true);
245  kwl.add(prefix,
248  true);
249 
250  kwl.add(prefix,
253  true);
254 
255  ossimImageTypeLut lut;
256  kwl.add(prefix,
259  true);
260 
261  //---
262  // When "theLinearUnits" == "unknown" that is a key to the writer to just
263  // use whatever units makes sense for the projection. Since "unknown"
264  // doesn't look good to the average user in a spec file, change to
265  // "default" if "unknown". When read back in by the lookup table since
266  // "default" is not a valid "string" theLinearUnits will remain "unknown".
267  // Kind of a hack but it works:) (drb)
268  //---
270  getEntryString(theLinearUnits);
271  if (os == "unknown")
272  {
273  os = "default"; // Avoid saving as unknown for user readability.
274  }
275  kwl.add(prefix, "linear_units", os, true);
276 
277  // Set the pixel type.
278  ossimString pixelType;
279  getPixelTypeString(pixelType);
280  kwl.add(prefix,
282  pixelType.c_str(),
283  true);
284 
285  return ossimSource::saveState(kwl, prefix);
286 }
287 
289  const char* prefix)
290 {
291  // Load the state of the base class.
292  bool result = ossimSource::loadState(kwl, prefix);
293 
294  // Get the filename...
295  const char* lookup = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
296  if(lookup)
297  {
298  ossimString filename = lookup;
299 
300  lookup = kwl.find(prefix, ossimKeywordNames::FILEPATH_KW);
301  if(lookup)
302  {
303  filename = ossimString(lookup) + filename;
304  }
305 
306  setFilename(filename);
307  }
308 
309  lookup = kwl.find(prefix, ossimKeywordNames::PIXEL_TYPE_KW);
310  if(lookup)
311  {
312  if(ossimString(lookup).downcase().contains("area"))
313  {
315  }
316  else
317  {
319  }
320  }
321 
322  lookup = kwl.find(prefix, "linear_units");
323  if(lookup)
324  {
326  getEntryNumber(lookup, true);
327  if ( (units == OSSIM_METERS) ||
328  (units == OSSIM_FEET) ||
329  (units == OSSIM_US_SURVEY_FEET) )
330  {
331  theLinearUnits = units;
332  }
333  }
334 
336  if(lookup)
337  {
338  ossimString s = lookup;
340  }
341 
342  lookup = kwl.find(prefix, "create_envi_hdr");
343  if(lookup)
344  {
345  ossimString s = lookup;
347  }
348 
349  lookup = kwl.find(prefix, "create_ers_hdr");
350  if(lookup)
351  {
352  ossimString s = lookup;
354  }
355 
356  lookup = kwl.find(prefix, "create_fgdc");
357  if(lookup)
358  {
359  ossimString s = lookup;
360  theWriteFgdcFlag = s.toBool();
361  }
362 
363  lookup = kwl.find(prefix, "create_jpeg_world_file");
364  if(lookup)
365  {
366  ossimString s = lookup;
368  }
369 
370  lookup = kwl.find(prefix, "create_readme");
371  if(lookup)
372  {
373  ossimString s = lookup;
375  }
376 
377  lookup = kwl.find(prefix, "create_tiff_world_file");
378  if(lookup)
379  {
380  ossimString s = lookup;
382  }
383 
384  lookup = kwl.find(prefix, "create_world_file");
385  if(lookup)
386  {
387  ossimString s = lookup;
389  }
390 
391  lookup = kwl.find(prefix, ossimKeywordNames::CREATE_IMAGE_KW);
392  if(lookup)
393  {
394  ossimString s = lookup;
396  }
397 
398  lookup = kwl.find(prefix, ossimKeywordNames::CREATE_OVERVIEW_KW);
399  if(lookup)
400  {
401  ossimString s = lookup;
403  }
404 
405  lookup = kwl.find(prefix, ossimKeywordNames::CREATE_HISTOGRAM_KW);
406  if(lookup)
407  {
408  ossimString s = lookup;
410  }
411 
412  lookup = kwl.find(prefix, SCALE_TO_EIGHT_BIT_KW);
413  if(lookup)
414  {
415  ossimString s = lookup;
417  }
418 
419  lookup = kwl.find(prefix, AUTO_CREATE_DIRECTORY_KW);
420  if(lookup)
421  {
423  }
425  if(lookup)
426  {
427  ossimString s = lookup;
428  theOverviewCompressType = static_cast<ossim_uint16>(s.toUInt32());
429  }
430 
432  if(lookup)
433  {
434  ossimString s = lookup;
436  }
437 
438  const char* outputImageType = kwl.find(prefix, ossimKeywordNames::IMAGE_TYPE_KW);
439  if(outputImageType)
440  {
441  theOutputImageType = outputImageType;
442  }
443 
444  if(theInputObjectList.size() != 2)
445  {
446  theInputObjectList.resize(2);
448  }
449 
450  theOutputListIsFixedFlag = false;
451 
452  return result;
453 }
454 
456  ossim_int32 jpeg_compress_quality,
457  bool includeR0)
458 {
459  if(theFilename == "") return false;
460 
461  // Get an image handler for the source file.
464 
465  if (ih.valid() == false)
466  {
467  // Set the error...
468  return false;
469  }
470 
472 
473  if ( ob->setInputSource(ih.get()) )
474  {
475  // Give the listener to the overview builder if set.
477  {
479  }
480 
481  // Build a new file name for the overview.
482  ossimFilename overview_file = theFilename;
483  overview_file.setExtension(ossimString("ovr"));
484  ob->setCompressionType(tiff_compress_type);
485  ob->setJpegCompressionQuality(jpeg_compress_quality);
486  ob->setOutputFile(overview_file);
487  ob->setCopyAllFlag(includeR0);
488  ob->execute();
489 
490  // Remove the listener from the overview builder.
492  {
494  }
495  }
496 
497  return true;
498 }
499 
501 {
502  if( (theFilename == "") || !theInputConnection ||
504  {
505  return false;
506  }
507 
508  // Make the file name.
509  ossimFilename outputFile = theFilename;
510  outputFile.setExtension(ossimString("hdr"));
511 
512  // Make the writer.
515 
516  // Set things up.
518  writer->initialize();
519  writer->setFilename(outputFile);
520  writer->setPixelType(thePixelType);
522 
523  // Write it to disk.
524  return writer->execute();
525 }
526 
528 {
529  if( (theFilename == "") || !theInputConnection ||
531  {
532  return false;
533  }
534 
535  // Make the file name.
536  ossimFilename outputFile = theFilename;
537  outputFile.setExtension(ossimString("ers"));
538 
539  // Make the writer.
541  new ossimERSFileWriter();
542 
543  // Set things up.
545  writer->initialize();
546  writer->setFilename(outputFile);
547  writer->setPixelType(thePixelType);
549 
550  // Write it to disk.
551  return writer->execute();
552 }
553 
555 {
556  if( (theFilename == "") || !theInputConnection ||
558  {
559  return false;
560  }
561 
562  // Make the file name.
563  ossimFilename geomFile = theFilename;
564  geomFile.setExtension(ossimString("geom"));
565 
566  // Make the writer.
568 
569  // Set things up.
570 // writer->connectMyInputTo(0, theInputConnection.get());
572  writer->setFilename(geomFile);
573  writer->initialize();
574  writer->setPixelType(thePixelType);
576 
577  // Write it to disk.
578  return writer->execute();
579 }
580 
582 {
583  if( (theFilename == "") || !theInputConnection ||
585  {
586  return false;
587  }
588 
589  // Make the file name.
590  ossimFilename outputFile = theFilename;
591  outputFile.setExtension(ossimString("xml"));
592 
593  // Make the writer.
595 
596  // Set things up.
598  writer->initialize();
599  writer->setFilename(outputFile);
600  writer->setPixelType(thePixelType);
602 
603  // Write it to disk.
604  return writer->execute();
605 }
606 
608 {
609  if(theFilename == "")
610  {
611  return false;
612  }
613 
614  // Make the file name.
615  ossimFilename file = theFilename;
616  file.setExtension(ossimString("jpw")); // jpw???
617 
618  return writeWorldFile(file);
619 }
620 
622 {
623  if( (theFilename == "") || !theInputConnection ||
625  {
626  return false;
627  }
628 
629  // Make the file name.
630  ossimFilename outputFile = theFilename.noExtension();
631 
632  outputFile += "_readme.txt";
633 
634  // Make the writer.
636  new ossimReadmeFileWriter();
637 
638  // Set things up.
640  writer->initialize();
641  writer->setFilename(outputFile);
642  writer->setPixelType(thePixelType);
644 
645  // Write it to disk.
646  return writer->execute();
647 }
648 
650 {
651  if(theFilename == "")
652  {
653  return false;
654  }
655 
656  // Make the file name.
657  ossimFilename file = theFilename;
658  file.setExtension(ossimString("tfw"));
659 
660  return writeWorldFile(file);
661 }
662 
664 {
665  bool status = true;
666 
668  {
669  if(writeEnviHeaderFile() == false)
670  {
671  status = false;
672 
674  << "Write of envi header file failed!" << endl;
675  }
676  }
677 
679  {
680  if(writeErsHeaderFile() == false)
681  {
682  status = false;
683 
685  << "Write of ers header file failed!" << endl;
686  }
687  }
688 
690  {
691  if( writeExternalGeometryFile() == false)
692  {
693  status = false;
694  if(traceDebug())
695  {
697  << "Write of geometry file failed!" << endl;
698  }
699  }
700  }
702  {
703  if(writeFgdcFile() == false)
704  {
705  status = false;
706  if(traceDebug())
707  {
709  << "Write of fgdc file failed!" << endl;
710  }
711  }
712  }
714  {
715  if(writeJpegWorldFile() == false)
716  {
717  status = false;
718  if(traceDebug())
719  {
721  << "Write of jpeg world file failed!" << endl;
722  }
723  }
724  }
726  {
727  if(writeReadmeFile() == false)
728  {
729  status = false;
730 
731  if(traceDebug())
732  {
734  << "Write of readme file failed!" << endl;
735  }
736  }
737  }
739  {
740  if(writeTiffWorldFile() == false)
741  {
742  status = false;
743  if(traceDebug())
744  {
746  << "Write of tiff world file failed!" << endl;
747  }
748  }
749  }
750 
752  {
753  if(writeWorldFile() == false)
754  {
755  status = false;
756  if(traceDebug())
757  {
759  << "Write of world file failed!" << endl;
760  }
761  }
762  }
763 
765  {
766  if (!writeHistogramFile())
767  {
768  status = false;
769  if(traceDebug())
770  {
772  << "Write of histogram file failed!" << endl;
773  }
774  }
775  }
776 
777  return status;
778 }
779 
781 {
782  if(needsAborting()) return false;
783  if(theFilename == "") return false;
784 
785  ossimFilename histogram_file = theFilename;
786  histogram_file.setExtension(ossimString("his"));
787 
789  open(theFilename);
790 
791  if (!handler)
792  {
793  return false;
794  }
795 
797 
799  histoSource->setMaxNumberOfRLevels(1); // Only compute for r0.
800  histoSource->connectMyInputTo(0, handler.get());
801  histoSource->enableSource();
802  writer->connectMyInputTo(0, histoSource.get());
803  writer->setFilename(histogram_file);
804  writer->addListener(&theStdOutProgress);
805  writer->execute();
806  writer->disconnect();
807  histoSource->disconnect();
808  handler->disconnect();
809  writer = 0; histoSource = 0; handler = 0;
810  return true;
811 }
812 
814 {
815  if(!getInput(0))
816  {
818  }
820 
821  initialize();
822 }
823 
825 {
827  getInput(0),
828  false);
830  initialize();
831 }
832 
834 {
835  initialize();
836 }
837 
839 {
840  theOutputImageType = type;
841 }
842 
844 {
845  ossimImageTypeLut lut;
847 }
848 
850 {
851  return theOutputImageType;
852 
853 }
854 
856 {
857  ossimImageTypeLut lut;
859 }
860 
861 
863 {
864  return theWriteImageFlag;
865 }
866 
868 {
869  return theWriteHistogramFlag;
870 }
871 
873 {
874  return theWriteOverviewFlag;
875 }
876 
878 {
879  return theScaleToEightBitFlag;
880 }
881 
883 {
884  return theWriteEnviHeaderFlag;
885 }
886 
888 {
889  return theWriteErsHeaderFlag;
890 }
891 
893 {
895 }
896 
898 {
899  return theWriteFgdcFlag;
900 }
901 
903 {
905 }
906 
908 {
909  return theWriteReadmeFlag;
910 }
911 
913 {
915 }
916 
918 {
919  return theWriteWorldFileFlag;
920 }
921 
923 {
924  theWriteOverviewFlag = flag;
925 }
926 
928 {
929  theWriteImageFlag = flag;
930 }
931 
933 {
934  theWriteHistogramFlag = flag;
935 }
936 
938 {
939  theScaleToEightBitFlag = flag;
940 }
941 
943 {
944  theWriteEnviHeaderFlag = flag;
945 }
946 
948 {
949  theWriteErsHeaderFlag = flag;
950 }
951 
953 {
955 }
956 
958 {
959  theWriteFgdcFlag = flag;
960 }
961 
963 {
965 }
966 
968 {
969  theWriteReadmeFlag = flag;
970 }
971 
973 {
975 }
976 
978 {
979  theWriteWorldFileFlag = flag;
980 }
981 
983 {
984  return this;
985 }
986 
988 {
989  return this;
990 }
991 
993 {
994  // This sets "theAreaOfInterest".
996 
997  if( theInputConnection.valid() )
998  {
999  //---
1000  // ossimImageSourceSequencer::setAreaOfInterest does more than just set the
1001  // variable, so only call if out of sync to avoid wasted cycles.
1002  //---
1004  {
1005  // Set the sequencer area of interest.
1007  }
1008  }
1009 }
1010 
1012 {
1013  return theInputConnection.get();
1014 }
1015 
1017 {
1018  static const char MODULE[] = "ossimImageFileWriter::execute";
1019 
1020  if (!theInputConnection) // Must have a sequencer...
1021  {
1022  if (traceDebug())
1023  {
1025  << MODULE << " DEBUG:\ntheInputConnection is NULL!" << endl;
1026  }
1027  return false;
1028  }
1029 
1030  if (theFilename == "") // Must have a filename...
1031  {
1032  if (traceDebug())
1033  {
1035  << MODULE << " DEBUG:\ntheFilename is empty!" << endl;
1036  }
1037  return false;
1038  }
1039 
1040 
1041  // make sure we have a region of interest
1043  {
1046  }
1047  else
1048  {
1050  }
1051 
1052  if(theAreaOfInterest.hasNans()) // Must have an area of interest...
1053  {
1054  if (traceDebug())
1055  {
1057  << MODULE << " ERROR: Area of interest has nans!"
1058  << "Area of interest: "
1060  << "\nReturning..." << endl;
1061  }
1062 
1063  return false;
1064  }
1065 
1066  if (traceDebug())
1067  {
1069  << MODULE << " DEBUG:\n"
1070  << "Area of interest: " << theAreaOfInterest << endl;
1071  }
1072 
1073  ossimRefPtr<ossimImageSource> savedInput;
1075  {
1077  {
1078  savedInput = new ossimScalarRemapper;
1079 
1080  savedInput->connectMyInputTo(0, theInputConnection->getInput(0));
1081  theInputConnection->connectMyInputTo(0, savedInput.get());
1083  }
1084  }
1085 
1086  ossimFilename path = theFilename.path();
1087  if (!path.empty() && !path.exists() )
1088  {
1089  path.createDirectory(true);
1090  }
1092  //setPercentComplete(0.0); let writeFile set the precent complete
1093  bool wroteFile = true;
1094  bool result = true;
1095  if (theWriteImageFlag)
1096  {
1097  wroteFile = writeFile();
1098  }
1099 
1100  /*
1101  if(needsAborting())
1102  {
1103  setProcessStatus(ossimProcessInterface::PROCESS_STATUS_ABORTED);
1104  }
1105  else
1106  {
1107  setProcessStatus(ossimProcessInterface::PROCESS_STATUS_NOT_EXECUTING);
1108  }
1109  */
1111  {
1112  // Writing overviews has been mpi'd so do on all processes.
1115  {
1116  if(traceDebug())
1117  {
1119  << "Write of overview file failed!" << endl;
1120  }
1121  }
1122  }
1123 
1124  if(!needsAborting())
1125  {
1126  // Do these only on the master process. Note left to right precedence!
1127  if (getSequencer() && getSequencer()->isMaster())
1128  {
1129  if (wroteFile)
1130  {
1131  if (writeMetaDataFiles() == false)
1132  {
1133  if(traceDebug())
1134  {
1136  << "Write of metadata file failed!" << endl;
1137  }
1138  result = false;
1139  }
1140  }
1141 
1142  } // End of "if (getSequencer() && getSequencer()->isMaster()))
1143  }
1144 
1145  if(savedInput.valid())
1146  {
1148  if(obj)
1149  {
1151  }
1152  }
1153  if(!needsAborting())
1154  {
1156  }
1157  else
1158  {
1160  }
1161 
1162  savedInput = 0;
1163  return result;
1164 }
1165 
1167 {
1168  //---
1169  // Not implemented in this class. Derived classed should implement if
1170  // they can write to a stream.
1171  //---
1172  return false;
1173 }
1174 
1176 {
1177  //---
1178  // Not implemented in this class. Derived classed should implement if
1179  // they can write to a stream.
1180  //---
1181  return ossimRefPtr<ossimOStream>();
1182 }
1183 
1185  ossimRefPtr<ossimOStream> /* stream */ )
1186 {
1187  //---
1188  // Not implemented in this class. Derived classed should implement if
1189  // they can write to a stream.
1190  //---
1191  return false;
1192 }
1193 
1195 {
1196  //---
1197  // Not implemented in this class. Derived classed should implement if
1198  // they can write to a stream.
1199  //---
1200  return false;
1201 }
1202 
1203 
1204 void ossimImageFileWriter::setPercentComplete(double percentComplete)
1205 {
1207  ossimProcessProgressEvent event(this, percentComplete);
1208  fireEvent(event);
1209 }
1210 
1212 {
1213  ossimImageWriter::setOutputName(outputName);
1214  setFilename(ossimFilename(outputName));
1215 }
1216 
1218 {
1219  theFilename = file;
1220 }
1221 
1223 {
1224  return theFilename;
1225 }
1226 
1228  const ossimConnectableObject* object)const
1229 {
1230  return (object&&
1231  ( (PTR_CAST(ossimImageSource, object)&&inputIndex == 0)||
1232  (PTR_CAST(ossimViewController, object)&&inputIndex == 1)) );
1233 }
1234 
1236 {
1237  return theOverviewCompressType;
1238 }
1239 
1241 {
1243 }
1244 
1246 {
1247  theOverviewCompressType = type;
1248 }
1249 
1251 {
1253 }
1254 
1256 {
1257  if(!property) return;
1258 
1259  if(property->getName() == ossimKeywordNames::FILENAME_KW)
1260  {
1261  theFilename = property->valueToString();
1262  }
1263  else if (property->getName() == "create_envi_hdr")
1264  {
1265  theWriteEnviHeaderFlag = property->valueToString().toBool();
1266  }
1267  else if (property->getName() == "create_ers_hdr")
1268  {
1269  theWriteErsHeaderFlag = property->valueToString().toBool();
1270  }
1271  else if (property->getName() ==
1273  {
1274  theWriteExternalGeometryFlag = property->valueToString().toBool();
1275  }
1276  else if (property->getName() == "create_fgdc")
1277  {
1278  theWriteFgdcFlag = property->valueToString().toBool();
1279  }
1280  else if (property->getName() == "create_jpeg_world_file")
1281  {
1282  theWriteJpegWorldFileFlag = property->valueToString().toBool();
1283  }
1284  else if (property->getName() == "create_readme")
1285  {
1286  theWriteReadmeFlag = property->valueToString().toBool();
1287  }
1288  else if (property->getName() == "create_tiff_world_file")
1289  {
1290  theWriteTiffWorldFileFlag = property->valueToString().toBool();
1291  }
1292  else if (property->getName() == "create_world_file")
1293  {
1294  theWriteWorldFileFlag = property->valueToString().toBool();
1295  }
1296  else if (property->getName() == ossimKeywordNames::CREATE_IMAGE_KW)
1297  {
1298  theWriteImageFlag = property->valueToString().toBool();
1299  }
1300  else if (property->getName() == ossimKeywordNames::CREATE_OVERVIEW_KW)
1301  {
1302  theWriteOverviewFlag = property->valueToString().toBool();
1303  }
1304  else if (property->getName() == ossimKeywordNames::CREATE_HISTOGRAM_KW)
1305  {
1306  theWriteHistogramFlag = property->valueToString().toBool();
1307  }
1308  else if (property->getName() == SCALE_TO_EIGHT_BIT_KW)
1309  {
1310  theScaleToEightBitFlag = property->valueToString().toBool();
1311  }
1312  else if(property->getName() == AUTO_CREATE_DIRECTORY_KW)
1313  {
1314  theAutoCreateDirectoryFlag = property->valueToString().toBool();
1315  }
1316  else if (property->getName() == "linear_units")
1317  {
1320  getEntryNumber(property->valueToString()));
1321  }
1322  else if(property->getName() == ossimKeywordNames::IMAGE_TYPE_KW)
1323  {
1324  setOutputImageType(property->valueToString());
1325  }
1326  else if(property->getName() == ossimKeywordNames::PIXEL_TYPE_KW)
1327  {
1329  property.get());
1330  if (stringProperty)
1331  {
1332  ossimString s;
1333  stringProperty->valueToString(s);
1334  setPixelType(s);
1335  }
1336  }
1337  else
1338  {
1340  }
1341 }
1342 
1344 {
1345  if(name == ossimKeywordNames::FILENAME_KW)
1346  {
1347  ossimFilenameProperty* filenameProp =
1349 
1351 
1352  return filenameProp;
1353  }
1354  else if(name == ossimKeywordNames::IMAGE_TYPE_KW)
1355  {
1357  std::vector<ossimString> typeList;
1358  getImageTypeList(typeList);
1359  if(typeList.size() > 1)
1360  {
1361  prop->setReadOnlyFlag(false);
1362  prop->setConstraints(typeList);
1364  }
1365  else
1366  {
1367  prop->setReadOnlyFlag(true);
1368  }
1369  return prop;
1370  }
1371  else if(name == AUTO_CREATE_DIRECTORY_KW)
1372  {
1374  }
1375  else if (name == "create_envi_hdr")
1376  {
1377  return new ossimBooleanProperty(name, theWriteEnviHeaderFlag);
1378  }
1379  else if (name == "create_ers_hdr")
1380  {
1381  return new ossimBooleanProperty(name, theWriteErsHeaderFlag);
1382  }
1384  {
1386  }
1387  else if (name == "create_fgdc")
1388  {
1389  return new ossimBooleanProperty(name, theWriteFgdcFlag);
1390  }
1391  else if (name == "create_jpeg_world_file")
1392  {
1394  }
1395  else if (name == "create_readme")
1396  {
1397  return new ossimBooleanProperty(name, theWriteReadmeFlag);
1398  }
1399  else if (name == "create_tiff_world_file")
1400  {
1402  }
1403  else if (name == "create_world_file")
1404  {
1405  return new ossimBooleanProperty(name, theWriteWorldFileFlag);
1406  }
1407  else if (name == ossimKeywordNames::CREATE_IMAGE_KW)
1408  {
1409  return new ossimBooleanProperty(name, theWriteImageFlag);
1410  }
1411  else if (name == ossimKeywordNames::CREATE_OVERVIEW_KW)
1412  {
1413  return new ossimBooleanProperty(name, theWriteOverviewFlag);
1414  }
1415  else if (name == ossimKeywordNames::CREATE_HISTOGRAM_KW)
1416  {
1417  return new ossimBooleanProperty(name, theWriteHistogramFlag);
1418  }
1419  else if (name == SCALE_TO_EIGHT_BIT_KW)
1420  {
1421  return new ossimBooleanProperty(name, theScaleToEightBitFlag);
1422  }
1423  else if (name == "linear_units")
1424  {
1425  // property value
1427  getEntryString(theLinearUnits);
1428 
1429  //---
1430  // theLinearUnits is set to unknown as a default. This keys the
1431  // writer to use whatever makes sense for the given output.
1432  // Since "unknown" is a bad name to present to users, we will
1433  // use "default" if theLinearUnits is == "unknown".
1434  //---
1435  if (value == "unknown")
1436  {
1437  value = "default";
1438  }
1439 
1440  // constraint list
1441  vector<ossimString> constraintList;
1442  constraintList.push_back(ossimString("default"));
1443  constraintList.push_back(ossimString("meters"));
1444  constraintList.push_back(ossimString("feet"));
1445  constraintList.push_back(ossimString("us_survey_feet"));
1446 
1447  return new ossimStringProperty(name,
1448  value,
1449  false, // not editable
1450  constraintList);
1451  }
1452  else if (name == ossimKeywordNames::PIXEL_TYPE_KW)
1453  {
1454  ossimString value;
1455  getPixelTypeString(value);
1456  ossimStringProperty* stringProp =
1457  new ossimStringProperty(name,
1458  value,
1459  false); // editable flag
1460  stringProp->addConstraint(ossimString("point"));
1461  stringProp->addConstraint(ossimString("area"));
1462  return stringProp;
1463  }
1464 
1465  return ossimImageWriter::getProperty(name);
1466 }
1467 
1468 void ossimImageFileWriter::getPropertyNames(std::vector<ossimString>& propertyNames)const
1469 {
1470  ossimImageWriter::getPropertyNames(propertyNames);
1471 
1472  propertyNames.push_back(ossimString(ossimKeywordNames::FILENAME_KW));
1473  propertyNames.push_back(ossimString("create_envi_hdr"));
1475  propertyNames.push_back(ossimString("create_fgdc"));
1476  propertyNames.push_back(ossimString("create_jpeg_world_file"));
1477  propertyNames.push_back(ossimString("create_readme"));
1478  propertyNames.push_back(ossimString("create_tiff_world_file"));
1479  propertyNames.push_back(ossimString("create_world_file"));
1480  propertyNames.push_back(ossimString(ossimKeywordNames::CREATE_IMAGE_KW));
1481  propertyNames.push_back(ossimString(ossimKeywordNames::CREATE_OVERVIEW_KW));
1482  propertyNames.push_back(ossimString(ossimKeywordNames::CREATE_HISTOGRAM_KW));
1483  propertyNames.push_back(ossimString(AUTO_CREATE_DIRECTORY_KW));
1484  propertyNames.push_back(ossimString(SCALE_TO_EIGHT_BIT_KW));
1485  propertyNames.push_back(ossimString("linear_units"));
1486  propertyNames.push_back(ossimString(ossimKeywordNames::PIXEL_TYPE_KW));
1487  propertyNames.push_back(ossimString(ossimKeywordNames::IMAGE_TYPE_KW));
1488 
1489 }
1490 
1492 {
1493  // default unknown file extension
1494  return ossimString("ext");
1495 }
1496 
1498 {
1499  // default value: don't assume internal overviews will
1500  // be generated by image writers.
1501  return false;
1502 }
1503 
1505 {
1506  std::vector<ossimString> imageTypeList;
1507  getImageTypeList(imageTypeList);
1508 
1509  std::vector<ossimString>::const_iterator i = imageTypeList.begin();
1510 
1511  while (i != imageTypeList.end())
1512  {
1513  if ( (*i) == imageType )
1514  {
1515  return true;
1516  }
1517  ++i;
1518  }
1519 
1520  return false; // not found...
1521 }
1522 
1524 {
1525  theProgressListener = listener;
1526  return ossimImageWriter::addListener(listener);
1527 }
1528 
1530 {
1531  if (listener == theProgressListener)
1532  {
1533  theProgressListener = NULL;
1534  }
1535  return ossimImageWriter::removeListener(listener);
1536 }
1537 
1539 {
1540  thePixelType = type;
1541 }
1542 
1544 {
1545  ossimString s = type;
1546  s.downcase();
1547  if (s == "point")
1548  {
1550  }
1551  else if (s == "area")
1552  {
1554  }
1555 }
1556 
1558 {
1559  return thePixelType;
1560 }
1561 
1563 {
1565  {
1566  type = "point";
1567  }
1568  else
1569  {
1570  type = "area";
1571  }
1572 }
1573 
1575 {
1576  if (theInputConnection.valid())
1577  {
1578  theInputConnection->setTileSize(tileSize);
1579  }
1580 }
1581 
1583 {
1584  bool result = false;
1585 
1586  if( theFilename.size() )
1587  {
1588  // Make the file name.
1589  ossimFilename file = theFilename;
1590  ossimString ext = file.ext().downcase();
1591 
1592  ossimString wfExt = ""; // World file extension.
1593 
1594  if ( ( ext == "tif" ) || ( ext == "tiff" ) )
1595  {
1596  wfExt = "tfw";
1597  }
1598  else if ( ( ext == "jpg" ) || ( ext == "jpeg" ) )
1599  {
1600  wfExt = "jpw";
1601  }
1602  else if ( ext == "png" )
1603  {
1604  wfExt = "pgw";
1605  }
1606  else if ( ext == "sid" )
1607  {
1608  wfExt = "sdw";
1609  }
1610 
1611  if ( ext.size() )
1612  {
1613  file.setExtension(wfExt);
1614 
1615  result = writeWorldFile(file);
1616  }
1617  else
1618  {
1620  << "Could not derive world file extension for: " << theFilename << "\n";
1621  }
1622  }
1623 
1624  if ( !result )
1625  {
1627  << "Write of world file failed!\n";
1628  }
1629 
1630  return result;
1631 }
1632 
1634 {
1636  {
1637  return false;
1638  }
1639 
1640  // Make the writer.
1642 
1643  // Set things up.
1644  writer->connectMyInputTo(0, theInputConnection.get());
1645  writer->initialize();
1646  writer->setFilename(file);
1648  writer->setLinearUnits(theLinearUnits);
1649  writer->setPixelType(thePixelType);
1650 
1651  // Write it to disk.
1652  return writer->execute();
1653 }
virtual bool writeHistogramFile()
Returns true on success, false on error.
virtual void valueToString(ossimString &valueResult) const =0
virtual ossimRefPtr< ossimConnectableObject > disconnectMyInput(ossim_int32 inputIndex, bool disconnectOutputFlag=true, bool createEventFlag=true)
Will disconnect the object at the given input index and generate a connection event.
virtual bool addListener(ossimListener *listener)
virtual void setOutputImageType(ossim_int32 type)
virtual ossim_uint16 getOverviewCompressType() const
virtual void setWriteImageFlag(bool flag)
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
Sets the area of interest to write the meta data for.
virtual ossimObject * getObject()
ossimFilename noExtension() const
virtual bool writeErsHeaderFile()
Will write an ER Mapper header file.
virtual bool writeWorldFile()
Will write a world file.
virtual void setWriteJpegWorldFile(bool flag)
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual bool execute()
Calls buildOverview.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
virtual void disconnect(ossimConnectableObject *object=0)
Will disconnect the object passed in.
static const char * CREATE_HISTOGRAM_KW
ossimUnitType
Represents serializable keyword/value map.
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Definition: ossimSource.cpp:55
virtual void setWriteErsHeaderFlag(bool flag)
virtual void setWriteTiffWorldFile(bool flag)
virtual void setScaleToEightBitFlag(bool flag)
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool getOutputHasInternalOverviews(void) const
Examples of writers that always generate internal overviews are ossim_kakadu_jp2 and ossim_kakadu_nit...
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Definition: ossimSource.cpp:66
ossimRefPtr< ossimViewController > theViewController
virtual void setPixelType(ossimPixelType type)
If "point" the coordinate tie points are relative to the center of the pixel.
const char * find(const char *key) const
virtual bool addListener(ossimListener *listener)
Overrides base "addListener" this will capture the pointer and then call the base class "addListener"...
virtual void setOverviewJpegCompressQuality(ossim_int32 quality)
ossimUnitType theLinearUnits
If not a geographic projection this allows the user to set the linear units of the output tag to be: ...
virtual ossimString getEntryString(ossim_int32 entry_number) const
virtual bool writeFile()=0
Write out the file.
virtual void disconnectInputEvent(ossimConnectionEvent &event)
static const char * OVERVIEW_COMPRESSION_TYPE_KW
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool writeReadmeFile()
Will write a readme file.
Class to write out meta data in a Federal Geographic Data Committe (FGDC) format. ...
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimIrect theAreaOfInterest
void setCopyAllFlag(bool flag)
Sets theCopyAllFlag.
void setChangeType(int type, bool on=true)
virtual bool getWriteTiffWorldFileFlag() const
ossimWorldFileWriter
virtual void setTileSize(const ossimIpt &tileSize)
Sets the output image tiling size if supported by the writer.
virtual void setPercentComplete(double percentComplete)
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
static const char * FILEPATH_KW
virtual bool getWriteErsHeaderFlag() const
ossim_uint32 toUInt32() const
virtual bool writeTiffWorldFile()
Will write a world file.
OSSIM_DLL ossimStdOutProgress theStdOutProgress
virtual void setReadOnlyFlag(bool flag)
void addConstraint(const ossimString &value)
Pure virtual base class for image file writers.
virtual bool canConnectMyInputTo(ossim_int32 inputIndex, const ossimConnectableObject *object) const
required to be overriden by derived classes
virtual void connectInputEvent(ossimConnectionEvent &event)
unsigned short ossim_uint16
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void setProcessStatus(ossimProcessStatus processStatus)
virtual void fireEvent(ossimEvent &event)
virtual bool setOutputStream(ossimRefPtr< ossimOStream > stream)
Sets the output stream to write to.
virtual bool getScaleToEightBitFlag() const
virtual ossimImageSourceSequencer * getSequencer()
static const char * TYPE_KW
virtual bool writeMetaDataFiles()
Convenience method that calls meta data write methods that are flagged to be called.
virtual ossim_int32 getOverviewJpegCompressQuality() const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
ossimImageFileWriter(const ossimFilename &filename=ossimFilename(), ossimImageSource *inputSource=0, ossimObject *owner=0)
The writer will own the sequencer.
virtual void setOutputName(const ossimString &outputName)
bool theWriteEnviHeaderFlag
External meta data writer flags.
virtual ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const =0
void getImageTypeList(std::vector<ossimString>& imageTypeList)const
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
ossim_int32 toInt32() const
virtual bool getWriteJpegWorldFileFlag() const
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
void setJpegCompressionQuality(ossim_int32 quality)
Sets the compression quality for use when using a compression type of COMPRESSION_JPEG.
virtual bool writeOverviewFile(ossim_uint16 tiff_compress_type=1, ossim_int32 jpeg_compress_quality=75, bool includeR0=false)
Write out an ossim overview file from the source_file.
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
Class for writing a "ERS" style header.
virtual void getPixelTypeString(ossimString &type) const
bool exists() const
virtual bool setInputSource(ossimImageHandler *imageSource)
Sets the input to the builder.
std::string::size_type size() const
Definition: ossimString.h:405
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
virtual bool getWriteEnviHeaderFlag() const
static const char * CREATE_OVERVIEW_KW
bool toBool() const
String to numeric methods.
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual bool writeStream()
Method to write the image to a stream.
unsigned int ossim_uint32
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
virtual void setWriteWorldFile(bool flag)
virtual void enableSource()
Definition: ossimSource.cpp:84
virtual bool getWriteWorldFileFlag() const
virtual ossimPixelType getPixelType() const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
void setCompressionType(ossim_uint16 compression_type)
Sets the compression type to use when building overviews.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void setWriteReadme(bool flag)
virtual void setAreaOfInterest(const ossimIrect &inputAreaOfInterest)
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void setOutputName(const ossimString &outputName)
virtual bool hasImageType(const ossimString &imageType) const
bool hasImageType(const ossimString& imageType) const
static const char * CREATE_EXTERNAL_GEOMETRY_KW
virtual bool getWriteHistogramFlag() const
virtual bool getWriteOverviewFlag() const
virtual bool getWriteFgdcFlag() const
virtual ossimString getOutputImageTypeString() const
ossimReadmeFileWriter
return status
virtual void setFilename(const ossimFilename &file)
ossimPixelType thePixelType
OSSIM_PIXEL_IS_POINT = 0, OSSIM_PIXEL_IS_AREA = 1.
virtual void setOutputFile(const ossimFilename &file)
Sets the output filename.
virtual void setWriteEnviHeaderFlag(bool flag)
virtual void setOverviewCompressType(ossim_uint16 type)
void setLinearUnits(ossimUnitType units)
Sets the linear units of the output file to either feet, us_survey_feet, or meters.
virtual bool writeFgdcFile()
Will write an fgdc file.
ossim_int32 theOverviewJpegCompressQuality
virtual bool writeExternalGeometryFile()
Will write an external geometry file.
ossimPixelType
virtual bool writeJpegWorldFile()
Will write a jpeg world file.
ConnectableObjectList theInputObjectList
Holds a list of input objects.
virtual const ossimFilename & getFilename() const
virtual void setPixelType(ossimPixelType pixelType)
Ossim uses a concept of "pixel is point" internally.
static const char * CREATE_IMAGE_KW
ossim_uint16 theOverviewCompressType
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void initialize()
Initialize method.
virtual void setWriteExternalGeometryFlag(bool flag)
virtual bool getWriteExternalGeometryFlag() const
virtual void setWriteFgdcFlag(bool flag)
void setIoType(ossimFilenamePropertyIoType ioType)
virtual bool open()=0
void makeNan()
Definition: ossimIrect.h:329
static const char * PIXEL_TYPE_KW
virtual void setAreaOfInterest(const ossimIrect &inputRect)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual bool writeEnviHeaderFile()
Will write an envi header file.
bool theInputListIsFixedFlag
Indicates whether the theInputObjectList is fixed.
bool empty() const
Definition: ossimString.h:411
virtual bool getWriteImageFlag() const
Control flags...
virtual ossimRefPtr< ossimOStream > getOutputStream() const
Method to return the stream attached to output.
virtual void setFilename(const ossimFilename &file)
virtual void changeSequencer(ossimImageSourceSequencer *sequencer)
Sets the sequencer and connects it to the input of this.
virtual bool getWriteReadmeFlag() const
bool hasNans() const
Definition: ossimIrect.h:337
virtual void setMaxNumberOfRLevels(ossim_uint32 number)
ossimString ext() const
const ossimIrect & getAreaOfInterest() const
static ossimImageHandlerRegistry * instance()
RTTI_DEF3(ossimImageFileWriter, "ossimImageFileWriter", ossimImageWriter, ossimProcessInterface, ossimConnectableObjectListener) static const char SCALE_TO_EIGHT_BIT_KW[]
8 bit unsigned integer
bool theOutputListIsFixedFlag
Indicates whether the theOutputObjectList is fixed.
static const char * IMAGE_TYPE_KW
static const char * OVERVIEW_COMPRESSION_QUALITY_KW
virtual void setPercentComplete(double percentComplete)
virtual void setWriteHistogramFlag(bool flag)
virtual ossim_int32 getOutputImageType() const
virtual void setFilename(const ossimFilename &filename)
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
virtual void setTileSize(const ossimIpt &tileSize)
virtual bool removeListener(ossimListener *listener)
Overrides base "removeListener".
bool createDirectory(bool recurseFlag=true, int perm=0775) const
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
virtual void propertyEvent(ossimPropertyEvent &event)
static const char * FILENAME_KW
ossimFilename path() const
virtual void setWriteOverviewFlag(bool flag)
Class for writing a "ENVI" style header.
ossimGeomFileWriter
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
void setConstraints(const std::vector< ossimString > &constraintList)
const ossimString & getName() const
ossimListener * theProgressListener
int ossim_int32
virtual void valueToString(ossimString &valueResult) const
virtual bool removeListener(ossimListener *listener)