File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
ImageExporter.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "ImageExporter.h"
8 
9 #include "Buffer.h"
10 #include "Cube.h"
11 #include "CubeAttribute.h"
12 #include "ExportDescription.h"
13 #include "FileName.h"
14 #include "JP2Exporter.h"
15 #include "PixelType.h"
16 #include "ProcessExport.h"
17 #include "QtExporter.h"
18 #include "TiffExporter.h"
19 
20 using namespace Isis;
21 using namespace std;
22 
23 
24 namespace Isis {
29  m_process = NULL;
30  m_process = new ProcessExport;
31 
32  m_writeMethod = NULL;
33 
34  m_exportDescription = NULL;
35  m_exportDescription = new ExportDescription();
36 
37  m_extension = "";
38  m_worldExtension = "";
39 
40  m_samples = 0;
41  m_lines = 0;
42  m_bands = 0;
43 
44  m_outputPixelMinimum = 0.0;
45  m_outputPixelMaximum = 0.0;
46  }
47 
48 
59  setExportDescription(desc);
60  initializeProcess();
61  }
62 
67  delete m_process;
68  m_process = NULL;
69  delete m_exportDescription;
70  m_exportDescription = NULL;
71  }
72 
73 
84  void ImageExporter::operator()(vector<Buffer *> &in) const {
85  (this->*m_writeMethod)(in);
86  }
87 
88 
101  void ImageExporter::write(FileName outputName, int quality,
102  QString compression) {
103  ProcessExport &p = process();
104  if (!p.HasInputRange()) p.SetInputRange();
105  p.ProcessCubes(*this);
106 
107  outputName = outputName.addExtension(m_extension);
108 
109  createWorldFile(outputName);
110  }
111 
112 
119  return m_samples;
120  }
121 
122 
128  int ImageExporter::lines() const {
129  return m_lines;
130  }
131 
132 
138  int ImageExporter::bands() const {
139  return m_bands;
140  }
141 
142 
151  double ImageExporter::inputMinimum(int channel) const {
152  return m_process->GetInputMinimum(channel);
153  }
154 
155 
164  double ImageExporter::inputMaximum(int channel) const {
165  return m_process->GetInputMaximum(channel);
166  }
167 
168 
181  void ImageExporter::setOutputPixelRange(double outputPixelMinimum, double outputPixelMaximum) {
182  m_outputPixelMinimum = outputPixelMinimum;
183  m_outputPixelMaximum = outputPixelMaximum;
184  }
185 
186 
193  void ImageExporter::setExtension(QString extension) {
194  m_extension = extension;
195 
196  // World file extension is the first and last characters of the extension
197  // with an added 'w' at the end
198  int last = extension.length() - 1;
199  m_worldExtension = extension.mid(0, 1) + extension.mid(last) + "w";
200  }
201 
202 
208  QString ImageExporter::extension() const {
209  return m_extension;
210  }
211 
218  *m_exportDescription = desc;
219  }
220 
227  return *m_exportDescription;
228  }
229 
230 
247  switch (m_exportDescription->channelCount()) {
248  case 1:
249  m_writeMethod = &ImageExporter::writeGrayscale;
250  break;
251  case 3:
252  m_writeMethod = &ImageExporter::writeRgb;
253  break;
254  case 4:
255  m_writeMethod = &ImageExporter::writeRgba;
256  break;
257  default:
259  "Cannot export an image with [" + QString(m_exportDescription->channelCount()) +
260  "] channels",
261  _FILEINFO_);
262  }
263 
264  ProcessExport &p = process();
265  Cube *cube = addChannel(0);
266  m_samples = cube->sampleCount();
267  m_lines = cube->lineCount();
268  m_bands = m_exportDescription->channelCount();
269 
270  for (int i = 1; i < m_exportDescription->channelCount(); i++) addChannel(i);
271 
272  p.setFormat(ProcessExport::BIL);// why BIL and not default to BSQ??? Doesn't appear to make a
273  // difference in output images
274 
275  // set up the output pixel type, special pixels and valid output range for
276  // the stretch that will be performed by ProcessExport
277  p.SetOutputType(exportDescription().pixelType());
278  p.SetOutputRange(m_exportDescription->outputPixelValidMin(),
279  m_exportDescription->outputPixelValidMax());
280 
281  // the dafault value for the null
282  p.SetOutputNull(m_exportDescription->outputPixelNull());
283 
284  // set the absolute min/max values for all pixels (including specials) in the output image
285  setOutputPixelRange(m_exportDescription->outputPixelAbsoluteMin(),
286  m_exportDescription->outputPixelAbsoluteMax());
287  return cube;
288  }
289 
290 
298  return *m_process;
299  }
300 
301 
308  if (m_exportDescription) {
309  return m_exportDescription->pixelType();
310  }
311  else {
312  return Isis::None;
313  }
314  }
315 
316 
325  int ImageExporter::outputPixelValue(double dn) const {
326  if (dn < m_outputPixelMinimum) {
327  return m_outputPixelMinimum;
328  }
329  else if (dn > m_outputPixelMaximum) {
330  return m_outputPixelMaximum;
331  }
332  else {
333  return dn;
334  }
335  }
336 
337 
347  ProcessExport &p = process();
348 
349  const ExportDescription::ChannelDescription &channel = m_exportDescription->channel(i);
350  Cube *cube = p.SetInputCube(channel.filename().expanded(), channel.attributes(), Isis::OneBand);
351 
352  if (channel.hasCustomRange())
353  p.SetInputRange(channel.inputMinimum(), channel.inputMaximum(), i);
354 
355  return cube;
356  }
357 
358 
365  outputName = outputName.removeExtension();
366  outputName = outputName.addExtension(m_worldExtension);
367 
368  ProcessExport &p = process();
369  p.CreateWorldFile(outputName.expanded());
370  p.EndProcess();
371  }
372 
373 
391  ImageExporter *exporter = NULL;
392 
393  format = format.toLower();
394  if (TiffExporter::canWriteFormat(format)) {
395  exporter = new TiffExporter();
396  }
397  else if (JP2Exporter::canWriteFormat(format)) {
398  exporter = new JP2Exporter();
399  }
400  else if (QtExporter::canWriteFormat(format)) {
401  exporter = new QtExporter(format);
402  }
403  else {
405  "Cannot export image as format [" + format + "]",
406  _FILEINFO_);
407  }
408 
409  return exporter;
410  }
411 };
412 
Isis::ImageExporter::process
ProcessExport & process() const
Get a reference to the process object, useful for subclasses to access and manipulate the process.
Definition: ImageExporter.cpp:297
Isis::ImageExporter::setOutputPixelRange
void setOutputPixelRange(double outputPixelMinimum, double outputPixelMaximum)
Set the DN floor and ceiling for the exported image.
Definition: ImageExporter.cpp:181
Isis::ImageExporter::inputMinimum
double inputMinimum(int channel) const
Returns the input minimum for the given channel.
Definition: ImageExporter.cpp:151
Isis::JP2Exporter
Exports cubes into JPEG 2000 images.
Definition: JP2Exporter.h:34
Isis::QtExporter
Exports cubes into one of several formats with Qt facilities.
Definition: QtExporter.h:47
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::ImageExporter::addChannel
Cube * addChannel(int i)
Add a channel of input data to the process from the export description at the given index.
Definition: ImageExporter.cpp:346
Isis::ProcessExport::SetInputRange
void SetInputRange()
Set input pixel range from user.
Definition: ProcessExport.cpp:359
Isis::ExportDescription::ChannelDescription
Describes how a cube as a single color channel to be exported.
Definition: ExportDescription.h:58
Isis::ExportDescription
Describes how a series of cubes should be exported.
Definition: ExportDescription.h:43
Isis::ImageExporter::exportDescription
ExportDescription & exportDescription() const
Gets the description for the output image.
Definition: ImageExporter.cpp:226
Isis::ProcessExport::CreateWorldFile
void CreateWorldFile(const QString &worldFile)
Create a standard world file for the input cube.
Definition: ProcessExport.cpp:1255
Isis::ProcessExport::setFormat
void setFormat(ExportFormat format)
Sets the storage order of the output file.
Definition: ProcessExport.h:170
Isis::ImageExporter::writeGrayscale
virtual void writeGrayscale(vector< Buffer * > &in) const =0
Pure virtual method for writing a line of grayscale data to the output image.
Isis::ExportDescription::ChannelDescription::filename
FileName filename() const
Returns a copy of the filename associated with this channel.
Definition: ExportDescription.cpp:286
Isis::ExportDescription::ChannelDescription::attributes
CubeAttributeInput attributes() const
Returns a copy of the input attributes associated with this channel.
Definition: ExportDescription.cpp:296
Isis::ProcessExport::SetOutputRange
void SetOutputRange(const double minimum, const double maximum)
Set output pixel range in Buffer.
Definition: ProcessExport.cpp:454
Isis::Process::EndProcess
virtual void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Definition: Process.cpp:455
Isis::ImageExporter::createWorldFile
void createWorldFile(FileName outputName)
Creates a world file is the input has a map projection.
Definition: ImageExporter.cpp:364
Isis::ProcessExport::SetOutputType
void SetOutputType(Isis::PixelType pixelIn)
Set output pixel bit type in Buffer.
Definition: ProcessExport.cpp:608
Isis::ImageExporter::writeRgba
virtual void writeRgba(vector< Buffer * > &in) const =0
Pure virtual method for writing a line of RGBA data to the output image.
Isis::ImageExporter::initializeProcess
Cube * initializeProcess()
Sets up the export process with the parameters described within the given description.
Definition: ImageExporter.cpp:246
Isis::ImageExporter::write
virtual void write(FileName outputName, int quality=100, QString compression="none")
Export the Isis cube channels to the given standard image.
Definition: ImageExporter.cpp:101
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::Cube::lineCount
int lineCount() const
Definition: Cube.cpp:1734
Isis::FileName::addExtension
FileName addExtension(const QString &extension) const
Adds a new extension to the file name.
Definition: FileName.cpp:225
Isis::ImageExporter::~ImageExporter
virtual ~ImageExporter()
Destruct the exporter.
Definition: ImageExporter.cpp:66
Isis::ImageExporter::fromFormat
static ImageExporter * fromFormat(QString format)
A static (factory) method for constructing an ImageExporter instance from an output format.
Definition: ImageExporter.cpp:390
Isis::ImageExporter::inputMaximum
double inputMaximum(int channel) const
Returns the input maximum for the given channel.
Definition: ImageExporter.cpp:164
Isis::ExportDescription::ChannelDescription::inputMinimum
double inputMinimum() const
Returns the input minimum for this channel.
Definition: ExportDescription.cpp:323
Isis::ExportDescription::ChannelDescription::hasCustomRange
bool hasCustomRange() const
Returns true if the user of this instance has set a custom input range for this channel.
Definition: ExportDescription.cpp:345
Isis::Process::SetInputCube
virtual Isis::Cube * SetInputCube(const QString &parameter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
Definition: Process.cpp:136
Isis::ImageExporter::operator()
void operator()(vector< Buffer * > &in) const
The method for writing a line of input image data (with potentially several bands representing color ...
Definition: ImageExporter.cpp:84
Isis::ImageExporter::writeRgb
virtual void writeRgb(vector< Buffer * > &in) const =0
Pure virtual method for writing a line of RGB data to the output image.
Isis::Cube::sampleCount
int sampleCount() const
Definition: Cube.cpp:1807
Isis::ProcessExport::BIL
@ BIL
Band interleaved by line.
Definition: ProcessExport.h:118
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::ImageExporter::outputPixelValue
virtual int outputPixelValue(double dn) const
Return the output clamped integer pixel value from the input double-precision DN.
Definition: ImageExporter.cpp:325
Isis::ImageExporter::extension
QString extension() const
Gets the extension for the output image.
Definition: ImageExporter.cpp:208
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::TiffExporter
Exports cubes into TIFF images.
Definition: TiffExporter.h:41
Isis::ImageExporter::ImageExporter
ImageExporter()
Construct the exporter.
Definition: ImageExporter.cpp:28
Isis::ImageExporter
Export Isis cubes into standard formats.
Definition: ImageExporter.h:54
Isis::FileName::removeExtension
FileName removeExtension() const
Removes all extensions in the file name.
Definition: FileName.cpp:246
Isis::PixelType
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:27
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::ImageExporter::lines
int lines() const
Number of lines (rows) in the output image.
Definition: ImageExporter.cpp:128
Isis::ExportDescription::ChannelDescription::inputMaximum
double inputMaximum() const
Returns the input maximum for this channel.
Definition: ExportDescription.cpp:334
Isis::ImageExporter::bands
int bands() const
Number of bands (channels) in the output image.
Definition: ImageExporter.cpp:138
Isis::JP2Exporter::canWriteFormat
static bool canWriteFormat(QString format)
Returns true if the format is "jp2".
Definition: JP2Exporter.cpp:126
Isis::ImageExporter::pixelType
PixelType pixelType() const
Returns the pixel type.
Definition: ImageExporter.cpp:307
Isis::ImageExporter::setExportDescription
void setExportDescription(ExportDescription &desc)
Sets the description for the output image.
Definition: ImageExporter.cpp:217
Isis::ImageExporter::samples
int samples() const
Number of samples (columns) in the output image.
Definition: ImageExporter.cpp:118
Isis::QtExporter::canWriteFormat
static bool canWriteFormat(QString format)
Returns true if the format is supported by QImageWriter.
Definition: QtExporter.cpp:246
Isis::TiffExporter::canWriteFormat
static bool canWriteFormat(QString format)
Returns true if the format is "tiff".
Definition: TiffExporter.cpp:169
Isis::ImageExporter::setExtension
void setExtension(QString extension)
Sets the extension for the output image and generates the extension for the world file from it.
Definition: ImageExporter.cpp:193
Isis::ProcessExport::SetOutputNull
void SetOutputNull(const double value)
Set output special pixel value for NULL.
Definition: ProcessExport.cpp:476
Isis::ImageExporter::initialize
virtual void initialize(ExportDescription &desc)=0
Generic initialization with the export description.
Definition: ImageExporter.cpp:58
Isis::ProcessExport
Process class for exporting cubes.
Definition: ProcessExport.h:111
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:37