1 #ifndef ProcessByBrick_h 2 #define ProcessByBrick_h 26 #include <QtConcurrentMap> 105 enum IOCubes{InPlace,
109 enum ProcessingDirection {
116 int requirements = 0);
120 int requirements = 0);
122 virtual void SetBricks(IOCubes cn);
144 void SetOutputRequirements(
int outputRequirements);
153 virtual void StartProcess(
void funct(std::vector<Buffer *> &in,
154 std::vector<Buffer *> &out));
180 const Functor & functor,
bool threaded =
true) {
185 bool writeOutput = (!haveInput) || (cube->
isReadWrite());
188 cube, brick, haveInput, writeOutput, functor);
216 template <
typename Functor>
void ProcessCube(
const Functor & functor,
217 bool threaded =
true) {
218 Brick *inputCubeData = NULL;
219 Brick *outputCubeData = NULL;
226 RunProcess(wrapperFunctor, numBricks, threaded);
228 delete inputCubeData;
229 delete outputCubeData;
256 bool threaded =
true) {
257 std::vector<Brick *> inputCubeData;
258 std::vector<Brick *> outputCubeData;
260 std::vector<Buffer *> inputCubeDataParents;
261 std::vector<Buffer *> outputCubeDataParents;
264 inputCubeDataParents, outputCubeDataParents,
265 inputCubeData, outputCubeData);
270 RunProcess(wrapperFunctor, numBricks, threaded);
272 for(
unsigned int i = 0; i < inputCubeData.size(); i++) {
273 delete inputCubeData[i];
276 for(
unsigned int i = 0; i < outputCubeData.size(); i++) {
277 delete outputCubeData[i];
295 template <
typename Functor>
297 int numSteps,
bool threaded) {
304 int threadCount = QThreadPool::globalInstance()->maxThreadCount();
305 if (threaded && threadCount > 1) {
306 QFuture<void> result = QtConcurrent::mapped(begin, end,
311 while (begin != end) {
312 wrapperFunctor(*begin);
334 template <
typename T>
336 public std::unary_function<const int &, void *> {
354 const Brick *templateBrick,
355 bool readInput,
bool writeOutput,
356 const T &processingFunctor) :
396 cubeData.
setpos(brickPosition);
458 template <
typename T>
460 public std::unary_function<const int &, void *> {
478 const Brick *inputTemplateBrick,
480 const Brick *outputTemplateBrick,
481 const T &processingFunctor) :
523 inputCubeData.
setpos(brickPosition);
524 outputCubeData.
setpos(brickPosition);
585 template <
typename T>
587 public std::unary_function<const int &, void *> {
609 std::vector<Brick *> &inputTemplateBricks,
610 std::vector<Cube *> &outputCubes,
611 std::vector<Brick *> &outputTemplateBricks,
613 const T &processingFunctor) :
656 functorBricks.first.push_back(inputBrick);
659 inputBrick->
setpos(brickPosition % inputBrick->
Bricks());
662 inputBrick->
setpos(brickPosition);
666 functorBricks.first.size() &&
667 inputBrick->
Band() != functorBricks.first[0]->Band() &&
669 inputBrick->
SetBaseBand(functorBricks.first[0]->Band());
677 functorBricks.second.push_back(outputBrick);
678 outputBrick->
setpos(brickPosition);
685 for (
int i = 0; i < (int)functorBricks.second.size(); i++) {
687 delete functorBricks.second[i];
690 for (
int i = 0; i < (int)functorBricks.first.size(); i++) {
691 delete functorBricks.first[i];
749 std::vector<Buffer *> & obufs,
750 std::vector<Brick *> & imgrs,
751 std::vector<Brick *> & omgrs);
764 std::forward_iterator_tag, int> {
789 return !(*
this == rhs);
839 int p_outputRequirements;
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
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.
int Band(const int index=0) const
Returns the band position associated with a shape buffer index.
This class is designed to iterate over all brick positions in a cube.
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...
std::vector< Brick * > & m_outputTemplateBricks
Template bricks for writing output data.
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 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.
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.
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 * operator()(const int &brickPosition) const
Do the work for one position in a cube.
Cube * SetInputCube(const QString ¶meter, int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
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.
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).
bool isReadWrite() const
Test if the opened cube is read-write, that is read and write operations should succeed if this is tr...
int operator*() const
Convert this iterator into a position.
virtual ~ProcessCubeFunctor()
Destructor.
void SetBaseBand(const int start_band)
This method is used to set the base band position of the shape buffer.
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...
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.
void read(Blob &blob) const
This method will read data from the specified Blob object.
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.
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.
Namespace for ISIS/Bullet specific routines.
virtual ~ProcessIterator()
Destructor.
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...
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
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.