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#include "UserInterface.h"
20
21using namespace Isis;
22using namespace std;
23
24
25namespace Isis {
30 m_process = NULL;
32
33 m_writeMethod = NULL;
34
37
38 m_extension = "";
40
41 m_samples = 0;
42 m_lines = 0;
43 m_bands = 0;
44
47 }
48
49
63
68 delete m_process;
69 m_process = NULL;
72 }
73
74
85 void ImageExporter::operator()(vector<Buffer *> &in) const {
86 (this->*m_writeMethod)(in);
87 }
88
89
103 void ImageExporter::write(FileName outputName, int quality,
104 QString compression, UserInterface *ui) {
105 ProcessExport &p = process();
106 if (!p.HasInputRange()) {
107 if (ui) {
108 p.SetInputRange(*ui);
109 }
110 else {
111 p.SetInputRange();
112 }
113 }
114 p.ProcessCubes(*this);
115
116 outputName = outputName.addExtension(m_extension);
117
118 createWorldFile(outputName);
119 }
120
121
128 return m_samples;
129 }
130
131
138 return m_lines;
139 }
140
141
148 return m_bands;
149 }
150
151
160 double ImageExporter::inputMinimum(int channel) const {
161 return m_process->GetInputMinimum(channel);
162 }
163
164
173 double ImageExporter::inputMaximum(int channel) const {
174 return m_process->GetInputMaximum(channel);
175 }
176
177
190 void ImageExporter::setOutputPixelRange(double outputPixelMinimum, double outputPixelMaximum) {
191 m_outputPixelMinimum = outputPixelMinimum;
192 m_outputPixelMaximum = outputPixelMaximum;
193 }
194
195
202 void ImageExporter::setExtension(QString extension) {
204
205 // World file extension is the first and last characters of the extension
206 // with an added 'w' at the end
207 int last = extension.length() - 1;
208 m_worldExtension = extension.mid(0, 1) + extension.mid(last) + "w";
209 }
210
211
217 QString ImageExporter::extension() const {
218 return m_extension;
219 }
220
229
238
239
257 case 1:
259 break;
260 case 3:
262 break;
263 case 4:
265 break;
266 default:
268 "Cannot export an image with [" + QString(m_exportDescription->channelCount()) +
269 "] channels",
270 _FILEINFO_);
271 }
272
273 ProcessExport &p = process();
274 Cube *cube = addChannel(0);
275 m_samples = cube->sampleCount();
276 m_lines = cube->lineCount();
278
279 for (int i = 1; i < m_exportDescription->channelCount(); i++) addChannel(i);
280
281 p.setFormat(ProcessExport::BIL);// why BIL and not default to BSQ??? Doesn't appear to make a
282 // difference in output images
283
284 // set up the output pixel type, special pixels and valid output range for
285 // the stretch that will be performed by ProcessExport
286 p.SetOutputType(exportDescription().pixelType());
287 p.SetOutputRange(m_exportDescription->outputPixelValidMin(),
289
290 // the dafault value for the null
291 p.SetOutputNull(m_exportDescription->outputPixelNull());
292
293 // set the absolute min/max values for all pixels (including specials) in the output image
296 return cube;
297 }
298
299
307 return *m_process;
308 }
309
310
319 }
320 else {
321 return Isis::None;
322 }
323 }
324
325
334 int ImageExporter::outputPixelValue(double dn) const {
335 if (dn < m_outputPixelMinimum) {
337 }
338 else if (dn > m_outputPixelMaximum) {
340 }
341 else {
342 return dn;
343 }
344 }
345
346
356 ProcessExport &p = process();
357
359 Cube *cube = p.SetInputCube(channel.filename().expanded(), channel.attributes(), Isis::OneBand);
360
361 if (channel.hasCustomRange())
362 p.SetInputRange(channel.inputMinimum(), channel.inputMaximum(), i);
363
364 return cube;
365 }
366
367
374 outputName = outputName.removeExtension();
375 outputName = outputName.addExtension(m_worldExtension);
376
377 ProcessExport &p = process();
378 p.CreateWorldFile(outputName.expanded());
379 p.EndProcess();
380 }
381
382
400 ImageExporter *exporter = NULL;
401
402 format = format.toLower();
403 if (TiffExporter::canWriteFormat(format)) {
404 exporter = new TiffExporter();
405 }
406 else if (JP2Exporter::canWriteFormat(format)) {
407 exporter = new JP2Exporter();
408 }
409 else if (QtExporter::canWriteFormat(format)) {
410 exporter = new QtExporter(format);
411 }
412 else {
414 "Cannot export image as format [" + format + "]",
415 _FILEINFO_);
416 }
417
418 return exporter;
419 }
420};
421
IO Handler for Isis Cubes.
Definition Cube.h:168
void setFormat(Format format)
Used prior to the Create method, this will specify the format of the cube, either band,...
Definition Cube.cpp:1272
int lineCount() const
Definition Cube.cpp:1740
int sampleCount() const
Definition Cube.cpp:1813
Describes how a cube as a single color channel to be exported.
double inputMinimum() const
Returns the input minimum for this channel.
double inputMaximum() const
Returns the input maximum for this channel.
bool hasCustomRange() const
Returns true if the user of this instance has set a custom input range for this channel.
FileName filename() const
Returns a copy of the filename associated with this channel.
CubeAttributeInput attributes() const
Returns a copy of the input attributes associated with this channel.
Describes how a series of cubes should be exported.
const ChannelDescription & channel(int i) const
Return the channels description at the given index.
double outputPixelAbsoluteMax() const
Returns the absolute maximum value for output pixels.
double outputPixelValidMin() const
Returns the output pixel value for the valid minimum.
double outputPixelAbsoluteMin() const
Returns the absolute minimum value for output pixels.
PixelType pixelType() const
Returns the pixel type.
int channelCount() const
Count of the number of channels in the description.
double outputPixelNull() const
Returns the output pixel value for Null DNs.
double outputPixelValidMax() const
Returns the output pixel value for the valid maximum.
File name manipulation and expansion.
Definition FileName.h:100
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Export Isis cubes into standard formats.
int lines() const
Number of lines (rows) in the output image.
QString extension() const
Gets the extension for the output image.
int bands() const
Number of bands (channels) in the output image.
virtual void write(FileName outputName, int quality=100, QString compression="none", UserInterface *ui=nullptr)
Export the Isis cube channels to the given standard image.
virtual ~ImageExporter()
Destruct the exporter.
Cube * addChannel(int i)
Add a channel of input data to the process from the export description at the given index.
ExportDescription & exportDescription() const
Gets the description for the output image.
Cube * initializeProcess()
Sets up the export process with the parameters described within the given description.
double inputMinimum(int channel) const
Returns the input minimum for the given channel.
ExportDescription * m_exportDescription
! The description for the export.
void createWorldFile(FileName outputName)
Creates a world file is the input has a map projection.
int m_samples
Number of samples (columns) in the output image.
QString m_extension
Extension to append to the output image if not already provided.
static ImageExporter * fromFormat(QString format)
A static (factory) method for constructing an ImageExporter instance from an output format.
WriteChannels m_writeMethod
Method pointer to one of the pure virtual write methods.
int samples() const
Number of samples (columns) in the output image.
ImageExporter()
Construct the exporter.
PixelType pixelType() const
Returns the pixel type.
double m_outputPixelMaximum
! The absolute maximum value for the output pixels.
virtual void writeGrayscale(vector< Buffer * > &in) const =0
Pure virtual method for writing a line of grayscale data to the output image.
void setOutputPixelRange(double outputPixelMinimum, double outputPixelMaximum)
Set the DN floor and ceiling for the exported image.
void operator()(vector< Buffer * > &in) const
The method for writing a line of input image data (with potentially several bands representing color ...
QString m_worldExtension
Extension to append to the output world file.
int m_lines
Number of lines (rows) in the output image.
void setExportDescription(ExportDescription &desc)
Sets the description for the output image.
virtual void initialize(ExportDescription &desc)=0
Generic initialization with the export description.
void setExtension(QString extension)
Sets the extension for the output image and generates the extension for the world file from it.
ProcessExport & process() const
Get a reference to the process object, useful for subclasses to access and manipulate the process.
int m_bands
Number of bands (channels) in the output image.
virtual int outputPixelValue(double dn) const
Return the output clamped integer pixel value from the input double-precision DN.
ProcessExport * m_process
The object that feeds lines to this instance and handles stretching.
double m_outputPixelMinimum
! The absolute minimum value for the output pixels.
virtual void writeRgba(vector< Buffer * > &in) const =0
Pure virtual method for writing a line of RGBA data to the output image.
virtual void writeRgb(vector< Buffer * > &in) const =0
Pure virtual method for writing a line of RGB data to the output image.
double inputMaximum(int channel) const
Returns the input maximum for the given channel.
Exports cubes into JPEG 2000 images.
Definition JP2Exporter.h:34
static bool canWriteFormat(QString format)
Returns true if the format is "jp2".
Process class for exporting cubes.
double GetInputMinimum(unsigned int n=0) const
Get the valid minimum pixel value for the Nth input cube.
@ BIL
Band interleaved by line.
double GetInputMaximum(unsigned int n=0) const
Get the valid maximum pixel value for the Nth input cube.
Exports cubes into one of several formats with Qt facilities.
Definition QtExporter.h:47
static bool canWriteFormat(QString format)
Returns true if the format is supported by QImageWriter.
Exports cubes into TIFF images.
static bool canWriteFormat(QString format)
Returns true if the format is "tiff".
Command Line and Xml loader, validation, and access.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
PixelType
Enumerations for Isis Pixel Types.
Definition PixelType.h:27
Namespace for the standard library.