Isis 3 Programmer Reference
ImageExporter.cpp
1 #include "ImageExporter.h"
2 
3 #include "Buffer.h"
4 #include "Cube.h"
5 #include "CubeAttribute.h"
6 #include "ExportDescription.h"
7 #include "FileName.h"
8 #include "JP2Exporter.h"
9 #include "PixelType.h"
10 #include "ProcessExport.h"
11 #include "QtExporter.h"
12 #include "TiffExporter.h"
13 
14 using namespace Isis;
15 using namespace std;
16 
17 
18 namespace Isis {
23  m_process = NULL;
24  m_process = new ProcessExport;
25 
26  m_writeMethod = NULL;
27 
28  m_exportDescription = NULL;
29  m_exportDescription = new ExportDescription();
30 
31  m_extension = "";
32  m_worldExtension = "";
33 
34  m_samples = 0;
35  m_lines = 0;
36  m_bands = 0;
37 
38  m_outputPixelMinimum = 0.0;
39  m_outputPixelMaximum = 0.0;
40  }
41 
42 
53  setExportDescription(desc);
54  initializeProcess();
55  }
56 
61  delete m_process;
62  m_process = NULL;
63  delete m_exportDescription;
64  m_exportDescription = NULL;
65  }
66 
67 
78  void ImageExporter::operator()(vector<Buffer *> &in) const {
79  (this->*m_writeMethod)(in);
80  }
81 
82 
95  void ImageExporter::write(FileName outputName, int quality,
96  QString compression) {
97  ProcessExport &p = process();
98  if (!p.HasInputRange()) p.SetInputRange();
99  p.ProcessCubes(*this);
100 
101  outputName = outputName.addExtension(m_extension);
102 
103  createWorldFile(outputName);
104  }
105 
106 
113  return m_samples;
114  }
115 
116 
122  int ImageExporter::lines() const {
123  return m_lines;
124  }
125 
126 
132  int ImageExporter::bands() const {
133  return m_bands;
134  }
135 
136 
145  double ImageExporter::inputMinimum(int channel) const {
146  return m_process->GetInputMinimum(channel);
147  }
148 
149 
158  double ImageExporter::inputMaximum(int channel) const {
159  return m_process->GetInputMaximum(channel);
160  }
161 
162 
175  void ImageExporter::setOutputPixelRange(double outputPixelMinimum, double outputPixelMaximum) {
176  m_outputPixelMinimum = outputPixelMinimum;
177  m_outputPixelMaximum = outputPixelMaximum;
178  }
179 
180 
187  void ImageExporter::setExtension(QString extension) {
188  m_extension = extension;
189 
190  // World file extension is the first and last characters of the extension
191  // with an added 'w' at the end
192  int last = extension.length() - 1;
193  m_worldExtension = extension.mid(0, 1) + extension.mid(last) + "w";
194  }
195 
196 
202  QString ImageExporter::extension() const {
203  return m_extension;
204  }
205 
212  *m_exportDescription = desc;
213  }
214 
221  return *m_exportDescription;
222  }
223 
224 
241  switch (m_exportDescription->channelCount()) {
242  case 1:
243  m_writeMethod = &ImageExporter::writeGrayscale;
244  break;
245  case 3:
246  m_writeMethod = &ImageExporter::writeRgb;
247  break;
248  case 4:
249  m_writeMethod = &ImageExporter::writeRgba;
250  break;
251  default:
253  "Cannot export an image with [" + QString(m_exportDescription->channelCount()) +
254  "] channels",
255  _FILEINFO_);
256  }
257 
258  ProcessExport &p = process();
259  Cube *cube = addChannel(0);
260  m_samples = cube->sampleCount();
261  m_lines = cube->lineCount();
262  m_bands = m_exportDescription->channelCount();
263 
264  for (int i = 1; i < m_exportDescription->channelCount(); i++) addChannel(i);
265 
266  p.setFormat(ProcessExport::BIL);// why BIL and not default to BSQ??? Doesn't appear to make a
267  // difference in output images
268 
269  // set up the output pixel type, special pixels and valid output range for
270  // the stretch that will be performed by ProcessExport
271  p.SetOutputType(exportDescription().pixelType());
272  p.SetOutputRange(m_exportDescription->outputPixelValidMin(),
273  m_exportDescription->outputPixelValidMax());
274 
275  // the dafault value for the null
276  p.SetOutputNull(m_exportDescription->outputPixelNull());
277 
278  // set the absolute min/max values for all pixels (including specials) in the output image
279  setOutputPixelRange(m_exportDescription->outputPixelAbsoluteMin(),
280  m_exportDescription->outputPixelAbsoluteMax());
281  return cube;
282  }
283 
284 
292  return *m_process;
293  }
294 
295 
302  if (m_exportDescription) {
303  return m_exportDescription->pixelType();
304  }
305  else {
306  return Isis::None;
307  }
308  }
309 
310 
319  int ImageExporter::outputPixelValue(double dn) const {
320  if (dn < m_outputPixelMinimum) {
321  return m_outputPixelMinimum;
322  }
323  else if (dn > m_outputPixelMaximum) {
324  return m_outputPixelMaximum;
325  }
326  else {
327  return dn;
328  }
329  }
330 
331 
341  ProcessExport &p = process();
342 
343  const ExportDescription::ChannelDescription &channel = m_exportDescription->channel(i);
344  Cube *cube = p.SetInputCube(channel.filename().expanded(), channel.attributes(), Isis::OneBand);
345 
346  if (channel.hasCustomRange())
347  p.SetInputRange(channel.inputMinimum(), channel.inputMaximum(), i);
348 
349  return cube;
350  }
351 
352 
359  outputName = outputName.removeExtension();
360  outputName = outputName.addExtension(m_worldExtension);
361 
362  ProcessExport &p = process();
363  p.CreateWorldFile(outputName.expanded());
364  p.EndProcess();
365  }
366 
367 
385  ImageExporter *exporter = NULL;
386 
387  format = format.toLower();
388  if (TiffExporter::canWriteFormat(format)) {
389  exporter = new TiffExporter();
390  }
391  else if (JP2Exporter::canWriteFormat(format)) {
392  exporter = new JP2Exporter();
393  }
394  else if (QtExporter::canWriteFormat(format)) {
395  exporter = new QtExporter(format);
396  }
397  else {
399  "Cannot export image as format [" + format + "]",
400  _FILEINFO_);
401  }
402 
403  return exporter;
404  }
405 };
406 
double inputMaximum() const
Returns the input maximum for this channel.
static bool canWriteFormat(QString format)
Returns true if the format is "tiff".
QString extension() const
Gets the extension for the output image.
File name manipulation and expansion.
Definition: FileName.h:116
int bands() const
Number of bands (channels) in the output image.
Cube * initializeProcess()
Sets up the export process with the parameters described within the given description.
Process class for exporting cubes.
static ImageExporter * fromFormat(QString format)
A static (factory) method for constructing an ImageExporter instance from an output format...
Exports cubes into JPEG 2000 images.
Definition: JP2Exporter.h:50
Export Isis cubes into standard formats.
Definition: ImageExporter.h:70
ImageExporter()
Construct the exporter.
void SetOutputNull(const double value)
Set output special pixel value for NULL.
int sampleCount() const
Definition: Cube.cpp:1452
Exports cubes into TIFF images.
Definition: TiffExporter.h:57
FileName addExtension(const QString &extension) const
Adds a new extension to the file name.
Definition: FileName.cpp:241
int samples() const
Number of samples (columns) in the output image.
virtual int outputPixelValue(double dn) const
Return the output clamped integer pixel value from the input double-precision DN. ...
double inputMinimum() const
Returns the input minimum for this channel.
Namespace for the standard library.
PixelType pixelType() const
Returns the pixel type.
double inputMinimum(int channel) const
Returns the input minimum for the given channel.
ExportDescription & exportDescription() const
Gets the description for the output image.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
void setExtension(QString extension)
Sets the extension for the output image and generates the extension for the world file from it...
virtual void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Definition: Process.cpp:483
ProcessExport & process() const
Get a reference to the process object, useful for subclasses to access and manipulate the process...
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:43
void CreateWorldFile(const QString &worldFile)
Create a standard world file for the input cube.
void SetOutputRange(const double minimum, const double maximum)
Set output pixel range in Buffer.
void SetOutputType(Isis::PixelType pixelIn)
Set output pixel bit type in Buffer.
void setExportDescription(ExportDescription &desc)
Sets the description for the output image.
void SetInputRange()
Set input pixel range from user.
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:243
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
void setFormat(ExportFormat format)
Sets the storage order of the output file.
virtual void writeRgba(vector< Buffer *> &in) const =0
Pure virtual method for writing a line of RGBA data to the output image.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
static bool canWriteFormat(QString format)
Returns true if the format is supported by QImageWriter.
Definition: QtExporter.cpp:240
Describes how a series of cubes should be exported.
int lines() const
Number of lines (rows) in the output image.
virtual void initialize(ExportDescription &desc)=0
Generic initialization with the export description.
Describes how a cube as a single color channel to be exported.
void setOutputPixelRange(double outputPixelMinimum, double outputPixelMaximum)
Set the DN floor and ceiling for the exported image.
FileName filename() const
Returns a copy of the filename associated with this channel.
virtual void writeGrayscale(vector< Buffer *> &in) const =0
Pure virtual method for writing a line of grayscale data to the output image.
void operator()(vector< Buffer *> &in) const
The method for writing a line of input image data (with potentially several bands representing color ...
static bool canWriteFormat(QString format)
Returns true if the format is "jp2".
int lineCount() const
Definition: Cube.cpp:1379
virtual void write(FileName outputName, int quality=100, QString compression="none")
Export the Isis cube channels to the given standard image.
Isis exception class.
Definition: IException.h:107
Band interleaved by line.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double inputMaximum(int channel) const
Returns the input maximum for the given channel.
virtual ~ImageExporter()
Destruct the exporter.
virtual void writeRgb(vector< Buffer *> &in) const =0
Pure virtual method for writing a line of RGB data to the output image.
Cube * addChannel(int i)
Add a channel of input data to the process from the export description at the given index...
bool hasCustomRange() const
Returns true if the user of this instance has set a custom input range for this channel.
void createWorldFile(FileName outputName)
Creates a world file is the input has a map projection.
CubeAttributeInput attributes() const
Returns a copy of the input attributes associated with this channel.
Exports cubes into one of several formats with Qt facilities.
Definition: QtExporter.h:63
FileName removeExtension() const
Removes all extensions in the file name.
Definition: FileName.cpp:262
IO Handler for Isis Cubes.
Definition: Cube.h:170