|
Isis 3 Programmer Reference
|
1 #ifndef ProcessByBrick_h
2 #define ProcessByBrick_h
10 #include <QtConcurrentMap>
93 enum ProcessingDirection {
100 int requirements = 0);
104 int requirements = 0);
106 virtual void SetBricks(IOCubes cn);
128 void SetOutputRequirements(
int outputRequirements);
137 virtual void StartProcess(
void funct(std::vector<Buffer *> &in,
138 std::vector<Buffer *> &out));
164 const Functor & functor,
bool threaded =
true) {
169 bool writeOutput = (!haveInput) || (cube->
isReadWrite());
172 cube, brick, haveInput, writeOutput, functor);
200 template <
typename Functor>
void ProcessCube(
const Functor & functor,
201 bool threaded =
true) {
202 Brick *inputCubeData = NULL;
203 Brick *outputCubeData = NULL;
210 RunProcess(wrapperFunctor, numBricks, threaded);
212 delete inputCubeData;
213 delete outputCubeData;
240 bool threaded =
true) {
241 std::vector<Brick *> inputCubeData;
242 std::vector<Brick *> outputCubeData;
244 std::vector<Buffer *> inputCubeDataParents;
245 std::vector<Buffer *> outputCubeDataParents;
248 inputCubeDataParents, outputCubeDataParents,
249 inputCubeData, outputCubeData);
254 RunProcess(wrapperFunctor, numBricks, threaded);
256 for(
unsigned int i = 0; i < inputCubeData.size(); i++) {
257 delete inputCubeData[i];
260 for(
unsigned int i = 0; i < outputCubeData.size(); i++) {
261 delete outputCubeData[i];
279 template <
typename Functor>
281 int numSteps,
bool threaded) {
288 int threadCount = QThreadPool::globalInstance()->maxThreadCount();
289 if (threaded && threadCount > 1) {
290 QFuture<void> result = QtConcurrent::mapped(begin, end,
295 while (begin != end) {
296 wrapperFunctor(*begin);
318 template <
typename T>
320 public std::unary_function<const int &, void *> {
338 const Brick *templateBrick,
339 bool readInput,
bool writeOutput,
340 const T &processingFunctor) :
380 cubeData.
setpos(brickPosition);
442 template <
typename T>
444 public std::unary_function<const int &, void *> {
462 const Brick *inputTemplateBrick,
464 const Brick *outputTemplateBrick,
465 const T &processingFunctor) :
507 inputCubeData.
setpos(brickPosition);
508 outputCubeData.
setpos(brickPosition);
569 template <
typename T>
571 public std::unary_function<const int &, void *> {
593 std::vector<Brick *> &inputTemplateBricks,
594 std::vector<Cube *> &outputCubes,
595 std::vector<Brick *> &outputTemplateBricks,
597 const T &processingFunctor) :
640 functorBricks.first.push_back(inputBrick);
643 inputBrick->
setpos(brickPosition % inputBrick->
Bricks());
646 inputBrick->
setpos(brickPosition);
650 functorBricks.first.size() &&
651 inputBrick->
Band() != functorBricks.first[0]->Band() &&
653 inputBrick->
SetBaseBand(functorBricks.first[0]->Band());
661 functorBricks.second.push_back(outputBrick);
662 outputBrick->
setpos(brickPosition);
669 for (
int i = 0; i < (int)functorBricks.second.size(); i++) {
671 delete functorBricks.second[i];
674 for (
int i = 0; i < (int)functorBricks.first.size(); i++) {
675 delete functorBricks.first[i];
733 std::vector<Buffer *> & obufs,
734 std::vector<Brick *> & imgrs,
735 std::vector<Brick *> & omgrs);
748 std::forward_iterator_tag, int> {
773 return !(*
this == rhs);
823 int p_outputRequirements;
const Brick * m_outputTemplateBrick
An example brick for the output parameter to m_processingFunctor.
bool setpos(BigInt map)
Sets the position of the shape in the cube.
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
ProcessCubesFunctor & operator=(const ProcessCubesFunctor &rhs)
Assignment of these objects is fully supported.
void SetInputBrickSize(int ns, int nl, int nb)
Sets the size of all input bricks.
bool m_wraps
Wrap smaller cubes back to the beginning?
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
void CheckStatus()
Checks and updates the status.
Process a cube in place (one input/zero output or zero input/one output or one cube that acts both as...
void VerifyCubes(IOCubes cn)
Verifies the dimensions of the input/output cubes.
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
void swap(ProcessIterator &other)
Exception-safe swap method.
int m_currentPosition
The current iterator's position/value.
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
bool PrepProcessCubeInPlace(Cube **cube, Brick **bricks)
Prepare and check to run "function" parameter for StartProcess(void funct(Buffer &in)) and StartProce...
virtual ~ProcessCubeFunctor()
Destructor.
std::vector< Cube * > m_outputCubes
The output cubes for writing data to.
ProcessCubeFunctor(Cube *inputCube, const Brick *inputTemplateBrick, Cube *outputCube, const Brick *outputTemplateBrick, const T &processingFunctor)
Construct a ProcessCubeFunctor.
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
Base class for all cube processing derivatives.
virtual Cube * SetOutputCube(const QString &fname, const CubeAttributeOutput &att)
Create the output file.
virtual Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
Create an arbitrary number of output cubes given an arbitrary number of input cubes (these counts can...
Manipulate and parse attributes of output cube filenames.
ProcessCubeInPlaceFunctor(Cube *cube, const Brick *templateBrick, bool readInput, bool writeOutput, const T &processingFunctor)
Construct a ProcessCubeInPlaceFunctor.
bool p_wrapOption
Indicates whether the brick manager will wrap.
virtual ~ProcessByBrick()
Destroys the ProcessByBrick object.
int operator*() const
Convert this iterator into a position.
ProcessCubeInPlaceFunctor(const ProcessCubeInPlaceFunctor &other)
Copy construction of these objects is fully supported.
virtual ~ProcessCubesFunctor()
Destructor.
void RunProcess(const Functor &wrapperFunctor, int numSteps, bool threaded)
This method runs the given wrapper functor numSteps times with or without threading,...
bool m_readInput
Should we read from the cube before processing.
ProcessCubesFunctor(std::vector< Cube * > &inputCubes, std::vector< Brick * > &inputTemplateBricks, std::vector< Cube * > &outputCubes, std::vector< Brick * > &outputTemplateBricks, bool wraps, const T &processingFunctor)
Construct a ProcessCubesFunctor.
std::vector< int > p_inputBrickSamples
Number of samples in the input bricks.
virtual void StartProcess(void funct())
In the base class, this method will invoked a user-specified function exactly one time.
Buffer for containing a three dimensional section of an image.
ProcessIterator & operator++()
Increment the process iterator to the next position.
bool p_inputBrickSizeSet
Indicates whether the brick size has been set.
const Brick * m_templateBrick
A brick with the right dimensions, pixel type, etc. for processing.
ProcessCubeFunctor & operator=(const ProcessCubeFunctor &rhs)
Assignment of these objects is fully supported.
void ProcessCubeInPlace(const Functor &functor, bool threaded=true)
Operate over a single cube (either input or output).
void SetOutputBrickSize(int ns, int nl, int nb)
Sets the size of all output bricks.
int Bricks()
Returns the number of Bricks in the cube.
void SetBrickSize(int ns, int nl, int nb)
Sets the input and output bricks sizes to the given number of samples, lines, and bands.
Buffer for reading and writing cube data.
bool m_writeOutput
Should we write to the output cube after processing.
void SetWrap(bool wrap)
This wrapping option only applys when there are two or more input cubes.
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
std::vector< int > p_outputBrickLines
Number of lines in the output bricks.
int PrepProcessCube(Brick **ibrick, Brick **obrick)
Prepare and check to run "function" parameter for StartProcess(void funct(Buffer &in,...
std::vector< int > CalculateMaxDimensions(std::vector< Cube * > cubes) const
Calculates the maximum dimensions of all the cubes and returns them in a vector where position 0 is t...
void ProcessCube(const Functor &functor, bool threaded=true)
Operate over a single input cube creating a separate output cube.
std::vector< int > p_inputBrickLines
Number of lines in the input bricks.
bool isReadWrite() const
Test if the opened cube is read-write, that is read and write operations should succeed if this is tr...
virtual Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
bool p_reverse
Use the reverse option for constructing the Buffer objects when the Processing Direction is changed f...
ProcessIterator(int position)
Initialize a process iterator given a position.
void ProcessCubes(const Functor &functor, bool threaded=true)
Operate over an arbitrary number of input cubes given an arbitrary number of output cubes.
std::vector< Cube * > m_inputCubes
The input cubes for reading data from.
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
Cube * m_inputCube
The cube to read from for the input brick data.
IO Handler for Isis Cubes.
virtual void StartProcess(void funct(Buffer &in))
Starts the systematic processing of the input cube by moving an arbitrary shaped brick through the cu...
virtual ~ProcessIterator()
Destructor.
ProcessByBrick()
Constructs a ProcessByBrick object.
This class is designed to iterate over all brick positions in a cube.
std::vector< int > p_inputBrickBands
Number of bands in the input bricks.
virtual Isis::Cube * SetOutputCube(const QString ¶meter)
Allocates a user-specified output cube whose size matches the first input cube.
int Band(const int index=0) const
Returns the band position associated with a shape buffer index.
bool Wraps()
Returns true if the wrapping option is enabled.
void Finalize()
Cleans up by closing cubes and freeing memory.
ProcessCubesFunctor(const ProcessCubesFunctor &other)
Copy construction of these objects is fully supported.
std::vector< int > p_outputBrickSamples
Number of samples in the output bricks.
Cube * m_outputCube
The cube to write to with the output of m_processingFunctor.
std::vector< int > p_outputBrickBands
Number of bands in the output bricks.
This is free and unencumbered software released into the public domain.
ProcessIterator & operator=(const ProcessIterator &rhs)
Assignment of these iterators is fully supported.
bool operator!=(const ProcessIterator &rhs)
Compare inequality of two iterator positions.
bool operator==(const ProcessIterator &rhs)
Compare equality of two iterator positions.
virtual ~ProcessCubeInPlaceFunctor()
Destructor.
void write(Blob &blob, bool overwrite=true)
This method will write a blob of data (e.g.
void SetProcessingDirection(ProcessingDirection direction)
Set the direction the data will be read, either all lines in a single band proceeding to the next ban...
Create an output cube given one input cube.
Isis::Progress * p_progress
Pointer to a Progress object.
std::vector< Brick * > & m_inputTemplateBricks
Template bricks for reading input data.
void BlockingReportProgress(QFuture< void > &future)
This method blocks until the future reports that it is finished.
const Brick * m_inputTemplateBrick
An example brick for the input parameter to m_processingFunctor.
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
ProcessCubeInPlaceFunctor & operator=(const ProcessCubeInPlaceFunctor &rhs)
Assignment of these objects is fully supported.
void SetBaseBand(const int start_band)
This method is used to set the base band position of the shape buffer.
ProcessCubeFunctor(const ProcessCubeFunctor &other)
Copy construction of these objects is fully supported.
std::vector< Brick * > & m_outputTemplateBricks
Template bricks for writing output data.
void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
ProcessingDirection GetProcessingDirection()
Returns the direction the data will be read, either all lines in a single band proceeding to the next...
This is free and unencumbered software released into the public domain.
Cube * m_cube
The cube we're I/O'ing on.
int PrepProcessCubes(std::vector< Buffer * > &ibufs, std::vector< Buffer * > &obufs, std::vector< Brick * > &imgrs, std::vector< Brick * > &omgrs)
Prepare and check to run "function" parameter for StartProcess(void funct(vector<Buffer *> &in,...
bool p_outputBrickSizeSet
Indicates whether the brick size has been set.