1 #ifndef ProcessByBrick_h
2 #define ProcessByBrick_h
26 #include <QtConcurrentMap>
102 enum IOCubes{InPlace,
106 enum ProcessingDirection {
113 int requirements = 0);
117 int requirements = 0);
119 virtual void SetBricks(IOCubes cn);
141 void SetOutputRequirements(
int outputRequirements);
148 virtual void StartProcess(
void funct(std::vector<Buffer *> &in,
149 std::vector<Buffer *> &out));
175 const Functor & functor,
bool threaded =
true) {
180 bool writeOutput = (!haveInput) || (cube->
isReadWrite());
183 cube, brick, haveInput, writeOutput, functor);
211 template <
typename Functor>
void ProcessCube(
const Functor & functor,
212 bool threaded =
true) {
213 Brick *inputCubeData = NULL;
214 Brick *outputCubeData = NULL;
221 RunProcess(wrapperFunctor, numBricks, threaded);
223 delete inputCubeData;
224 delete outputCubeData;
251 bool threaded =
true) {
252 std::vector<Brick *> inputCubeData;
253 std::vector<Brick *> outputCubeData;
255 std::vector<Buffer *> inputCubeDataParents;
256 std::vector<Buffer *> outputCubeDataParents;
259 inputCubeDataParents, outputCubeDataParents,
260 inputCubeData, outputCubeData);
265 RunProcess(wrapperFunctor, numBricks, threaded);
267 for(
unsigned int i = 0; i < inputCubeData.size(); i++) {
268 delete inputCubeData[i];
271 for(
unsigned int i = 0; i < outputCubeData.size(); i++) {
272 delete outputCubeData[i];
290 template <
typename Functor>
292 int numSteps,
bool threaded) {
299 int threadCount = QThreadPool::globalInstance()->maxThreadCount();
300 if (threaded && threadCount > 1) {
301 QFuture<void> result = QtConcurrent::mapped(begin, end,
306 while (begin != end) {
307 wrapperFunctor(*begin);
329 template <
typename T>
331 public std::unary_function<const int &, void *> {
349 const Brick *templateBrick,
350 bool readInput,
bool writeOutput,
351 const T &processingFunctor) :
391 cubeData.
setpos(brickPosition);
453 template <
typename T>
455 public std::unary_function<const int &, void *> {
473 const Brick *inputTemplateBrick,
475 const Brick *outputTemplateBrick,
476 const T &processingFunctor) :
518 inputCubeData.
setpos(brickPosition);
519 outputCubeData.
setpos(brickPosition);
580 template <
typename T>
582 public std::unary_function<const int &, void *> {
604 std::vector<Brick *> &inputTemplateBricks,
605 std::vector<Cube *> &outputCubes,
606 std::vector<Brick *> &outputTemplateBricks,
608 const T &processingFunctor) :
651 functorBricks.first.push_back(inputBrick);
654 inputBrick->
setpos(brickPosition % inputBrick->
Bricks());
657 inputBrick->
setpos(brickPosition);
661 functorBricks.first.size() &&
662 inputBrick->
Band() != functorBricks.first[0]->Band() &&
664 inputBrick->
SetBaseBand(functorBricks.first[0]->Band());
672 functorBricks.second.push_back(outputBrick);
673 outputBrick->
setpos(brickPosition);
680 for (
int i = 0; i < (int)functorBricks.second.size(); i++) {
682 delete functorBricks.second[i];
685 for (
int i = 0; i < (int)functorBricks.first.size(); i++) {
686 delete functorBricks.first[i];
744 std::vector<Buffer *> & obufs,
745 std::vector<Brick *> & imgrs,
746 std::vector<Brick *> & omgrs);
759 std::forward_iterator_tag, int> {
784 return !(*
this == rhs);
834 int p_outputRequirements;
Buffer for reading and writing cube data.
void SetBrickSize(int ns, int nl, int nb)
Sets the input and output bricks sizes to the given number of samples, lines, and bands...
int m_currentPosition
The current iterator's position/value.
std::vector< int > p_outputBrickBands
Number of bands in the output bricks.
Cube * m_outputCube
The cube to write to with the output of m_processingFunctor.
void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Create an arbitrary number of output cubes given an arbitrary number of input cubes (these counts can...
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
This class is designed to iterate over all brick positions in a cube.
std::vector< Brick * > & m_outputTemplateBricks
Template bricks for writing output data.
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.
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
void BlockingReportProgress(QFuture< void > &future)
This method blocks until the future reports that it is finished.
ProcessCubeFunctor(const ProcessCubeFunctor &other)
Copy construction of these objects is fully supported.
ProcessCubeInPlaceFunctor(const ProcessCubeInPlaceFunctor &other)
Copy construction of these objects is fully supported.
void VerifyCubes(IOCubes cn)
Verifies the dimensions of the input/output cubes.
ProcessCubeInPlaceFunctor & operator=(const ProcessCubeInPlaceFunctor &rhs)
Assignment of these objects is fully supported.
virtual ~ProcessByBrick()
Destroys the ProcessByBrick object.
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
int operator*() const
Convert this iterator into a position.
int PrepProcessCube(Brick **ibrick, Brick **obrick)
Prepare and check to run "function" parameter for StartProcess(void funct(Buffer &in, Buffer &out)) and StartProcessIO(Functor funct)
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
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...
void swap(ProcessIterator &other)
Exception-safe swap method.
virtual Cube * SetOutputCube(const QString &fname, const CubeAttributeOutput &att)
Create the output file.
virtual void StartProcess(void funct(Buffer &in))
Starts the systematic processing of the input cube by moving an arbitrary shaped brick through the cu...
bool m_readInput
Should we read from the cube before processing.
Buffer for containing a three dimensional section of an image.
bool isReadWrite() const
Test if the opened cube is read-write, that is read and write operations should succeed if this is tr...
void ProcessCubes(const Functor &functor, bool threaded=true)
Operate over an arbitrary number of input cubes given an arbitrary number of output cubes...
void SetInputBrickSize(int ns, int nl, int nb)
Sets the size of all input bricks.
std::vector< int > p_outputBrickLines
Number of lines in the output bricks.
bool p_wrapOption
Indicates whether the brick manager will wrap.
void read(Blob &blob) const
This method will read data from the specified Blob object.
Cube * SetInputCube(const QString ¶meter, int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
ProcessIterator & operator++()
Increment the process iterator to the next position.
Cube * m_inputCube
The cube to read from for the input brick data.
ProcessCubeInPlaceFunctor(Cube *cube, const Brick *templateBrick, bool readInput, bool writeOutput, const T &processingFunctor)
Construct a ProcessCubeInPlaceFunctor.
std::vector< int > p_inputBrickLines
Number of lines in the input bricks.
void CheckStatus()
Checks and updates the status.
std::vector< Cube * > m_inputCubes
The input cubes for reading data from.
virtual ~ProcessCubesFunctor()
Destructor.
virtual ~ProcessCubeInPlaceFunctor()
Destructor.
bool p_reverse
Use the reverse option for constructing the Buffer objects when the Processing Direction is changed f...
virtual void StartProcess(void funct())
In the base class, this method will invoked a user-specified function exactly one time...
std::vector< int > p_inputBrickBands
Number of bands in the input bricks.
void ProcessCubeInPlace(const Functor &functor, bool threaded=true)
Operate over a single cube (either input or output).
virtual ~ProcessCubeFunctor()
Destructor.
void SetBaseBand(const int start_band)
This method is used to set the base band position of the shape buffer.
int Band(const int index=0) const
Returns the band position associated with a shape buffer index.
int Bricks()
Returns the number of Bricks in the cube.
Process a cube in place (one input/zero output or zero input/one output or one cube that acts both as...
virtual Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
Manipulate and parse attributes of output cube filenames.
void RunProcess(const Functor &wrapperFunctor, int numSteps, bool threaded)
This method runs the given wrapper functor numSteps times with or without threading, reporting progress in both cases.
std::vector< int > p_inputBrickSamples
Number of samples in the input bricks.
Create an output cube given one input cube.
bool setpos(BigInt map)
Sets the position of the shape in the cube.
virtual Isis::Cube * SetOutputCube(const QString ¶meter)
Allocates a user-specified output cube whose size matches the first input cube.
const Brick * m_templateBrick
A brick with the right dimensions, pixel type, etc. for processing.
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
bool operator==(const ProcessIterator &rhs)
Compare equality of two iterator positions.
void ProcessCube(const Functor &functor, bool threaded=true)
Operate over a single input cube creating a separate output cube.
bool m_wraps
Wrap smaller cubes back to the beginning?
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
Isis::Progress * p_progress
Pointer to a Progress object.
ProcessingDirection GetProcessingDirection()
Returns the direction the data will be read, either all lines in a single band proceeding to the next...
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
void write(Blob &blob)
This method will write a blob of data (e.g.
ProcessIterator(int position)
Initialize a process iterator given a position.
void SetProcessingDirection(ProcessingDirection direction)
Set the direction the data will be read, either all lines in a single band proceeding to the next ban...
ProcessCubeFunctor & operator=(const ProcessCubeFunctor &rhs)
Assignment of these objects is fully supported.
virtual ~ProcessIterator()
Destructor.
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...
bool p_outputBrickSizeSet
Indicates whether the brick size has been set.
bool PrepProcessCubeInPlace(Cube **cube, Brick **bricks)
Prepare and check to run "function" parameter for StartProcess(void funct(Buffer &in)) and StartProce...
const Brick * m_inputTemplateBrick
An example brick for the input parameter to m_processingFunctor.
bool m_writeOutput
Should we write to the output cube after processing.
ProcessIterator & operator=(const ProcessIterator &rhs)
Assignment of these iterators is fully supported.
ProcessByBrick()
Constructs a ProcessByBrick object.
ProcessCubesFunctor(const ProcessCubesFunctor &other)
Copy construction of these objects is fully supported.
Cube * m_cube
The cube we're I/O'ing on.
void SetWrap(bool wrap)
This wrapping option only applys when there are two or more input cubes.
void Finalize()
Cleans up by closing cubes and freeing memory.
bool p_inputBrickSizeSet
Indicates whether the brick size has been set.
Base class for all cube processing derivatives.
std::vector< Brick * > & m_inputTemplateBricks
Template bricks for reading input data.
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.
bool Wraps()
Returns true if the wrapping option is enabled.
ProcessCubesFunctor & operator=(const ProcessCubesFunctor &rhs)
Assignment of these objects is fully supported.
std::vector< int > p_outputBrickSamples
Number of samples in the output bricks.
const Brick * m_outputTemplateBrick
An example brick for the output parameter to m_processingFunctor.
void SetOutputBrickSize(int ns, int nl, int nb)
Sets the size of all output bricks.
bool operator!=(const ProcessIterator &rhs)
Compare inequality of two iterator positions.
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
IO Handler for Isis Cubes.