1#ifndef ProcessByBrick_h 
    2#define ProcessByBrick_h 
   10#include <QtConcurrentMap> 
   95      enum ProcessingDirection {
 
  102                         int requirements = 0);
 
  106                         int requirements = 0);
 
  108      virtual void SetBricks(IOCubes cn);
 
  130      void SetOutputRequirements(
int outputRequirements);
 
  139      virtual void StartProcess(
void funct(std::vector<Buffer *> &in,
 
  140                                           std::vector<Buffer *> &out));
 
  141      virtual void StartProcess(std::function<
void(std::vector<Buffer *> &in,
 
  142                                                   std::vector<Buffer *> &out)> funct);
 
  168          const Functor & functor, 
bool threaded = 
true) {
 
  173        bool writeOutput = (!haveInput) || (cube->
isReadWrite());
 
  175        ProcessCubeInPlaceFunctor<Functor> wrapperFunctor(
 
  176            cube, brick, haveInput, writeOutput, functor);
 
  178        RunProcess(wrapperFunctor, brick->Bricks(), threaded);
 
 
  204      template <
typename Functor> 
void ProcessCube(
const Functor & functor,
 
  205                                                   bool threaded = 
true) {
 
  206        Brick *inputCubeData = NULL;
 
  207        Brick *outputCubeData = NULL;
 
  211        ProcessCubeFunctor<Functor> wrapperFunctor(
InputCubes[0], inputCubeData,
 
  214        RunProcess(wrapperFunctor, numBricks, threaded);
 
  216        delete inputCubeData;
 
  217        delete outputCubeData;
 
 
  244                                                    bool threaded = 
true) {
 
  245        std::vector<Brick *> inputCubeData;
 
  246        std::vector<Brick *> outputCubeData;
 
  248        std::vector<Buffer *> inputCubeDataParents;
 
  249        std::vector<Buffer *> outputCubeDataParents;
 
  252            inputCubeDataParents, outputCubeDataParents,
 
  253            inputCubeData, outputCubeData);
 
  255        ProcessCubesFunctor<Functor> wrapperFunctor(
InputCubes, inputCubeData,
 
  258        RunProcess(wrapperFunctor, numBricks, threaded);
 
  260        for(
unsigned int i = 0; i < inputCubeData.size(); i++) {
 
  261          delete inputCubeData[i];
 
  264        for(
unsigned int i = 0; i < outputCubeData.size(); i++) {
 
  265          delete outputCubeData[i];
 
 
  283      template <
typename Functor>
 
  285                      int numSteps, 
bool threaded) {
 
  292        int threadCount = QThreadPool::globalInstance()->maxThreadCount();
 
  293        if (threaded && threadCount > 1) {
 
  294          QFuture<void> result = QtConcurrent::mapped(begin, end,
 
  299          while (begin != end) {
 
  300            wrapperFunctor(*begin);
 
 
  322      template <
typename T>
 
  324          public std::function<void*(int)> {
 
  342                                    const Brick *templateBrick,
 
  343                                    bool readInput, 
bool writeOutput,
 
  344                                    const T &processingFunctor) :
 
 
  384            cubeData.setpos(brickPosition);
 
 
 
  446      template <
typename T>
 
  448          public std::function<void *(const int &)> {
 
  466                             const Brick *inputTemplateBrick,
 
  468                             const Brick *outputTemplateBrick,
 
  469                             const T &processingFunctor) :
 
 
  511            inputCubeData.setpos(brickPosition);
 
  512            outputCubeData.setpos(brickPosition);
 
 
 
  573      template <
typename T>
 
  575          public std::function<void *(const int &)> {
 
  597                              std::vector<Brick *> &inputTemplateBricks,
 
  598                              std::vector<Cube *> &outputCubes,
 
  599                              std::vector<Brick *> &outputTemplateBricks,
 
  601                              const T &processingFunctor) :
 
 
  640            QPair< std::vector<Buffer *>, std::vector<Buffer *> > functorBricks;
 
  644              functorBricks.first.push_back(inputBrick);
 
  647                inputBrick->setpos(brickPosition % inputBrick->Bricks());
 
  650                inputBrick->setpos(brickPosition);
 
  654                  functorBricks.first.size() &&
 
  655                  inputBrick->Band() != functorBricks.first[0]->Band() &&
 
  657                inputBrick->SetBaseBand(functorBricks.first[0]->Band());
 
  665              functorBricks.second.push_back(outputBrick);
 
  666              outputBrick->setpos(brickPosition);
 
  673            for (
int i = 0; i < (int)functorBricks.second.size(); i++) {
 
  675              delete functorBricks.second[i];
 
  678            for (
int i = 0; i < (int)functorBricks.first.size(); i++) {
 
  679              delete functorBricks.first[i];
 
 
 
  737                           std::vector<Buffer *> & obufs,
 
  738                           std::vector<Brick *> & imgrs,
 
  739                           std::vector<Brick *> & omgrs);
 
  752          std::forward_iterator_tag, int> {
 
  777            return !(*
this == rhs);
 
 
 
  827      int p_outputRequirements;
 
 
Buffer for containing a three dimensional section of an image.
 
Buffer for reading and writing cube data.
 
Manipulate and parse attributes of output cube filenames.
 
IO Handler for Isis Cubes.
 
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
 
void write(Blob &blob, bool overwrite=true)
This method will write a blob of data (e.g.
 
bool isReadWrite() const
Test if the opened cube is read-write, that is read and write operations should succeed if this is tr...
 
Create an output cube given one input cube.
 
Cube * m_inputCube
The cube to read from for the input brick data.
 
Cube * m_outputCube
The cube to write to with the output of m_processingFunctor.
 
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
 
ProcessCubeFunctor & operator=(const ProcessCubeFunctor &rhs)
Assignment of these objects is fully supported.
 
ProcessCubeFunctor(const ProcessCubeFunctor &other)
Copy construction of these objects is fully supported.
 
ProcessCubeFunctor(Cube *inputCube, const Brick *inputTemplateBrick, Cube *outputCube, const Brick *outputTemplateBrick, const T &processingFunctor)
Construct a ProcessCubeFunctor.
 
const Brick * m_inputTemplateBrick
An example brick for the input parameter to m_processingFunctor.
 
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
 
const Brick * m_outputTemplateBrick
An example brick for the output parameter to m_processingFunctor.
 
virtual ~ProcessCubeFunctor()
Destructor.
 
Process a cube in place (one input/zero output or zero input/one output or one cube that acts both as...
 
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
 
bool m_writeOutput
Should we write to the output cube after processing.
 
ProcessCubeInPlaceFunctor(Cube *cube, const Brick *templateBrick, bool readInput, bool writeOutput, const T &processingFunctor)
Construct a ProcessCubeInPlaceFunctor.
 
bool m_readInput
Should we read from the cube before processing.
 
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
 
ProcessCubeInPlaceFunctor & operator=(const ProcessCubeInPlaceFunctor &rhs)
Assignment of these objects is fully supported.
 
ProcessCubeInPlaceFunctor(const ProcessCubeInPlaceFunctor &other)
Copy construction of these objects is fully supported.
 
virtual ~ProcessCubeInPlaceFunctor()
Destructor.
 
Cube * m_cube
The cube we're I/O'ing on.
 
const Brick * m_templateBrick
A brick with the right dimensions, pixel type, etc. for processing.
 
Create an arbitrary number of output cubes given an arbitrary number of input cubes (these counts can...
 
void * operator()(const int &brickPosition) const
Do the work for one position in a cube.
 
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.
 
const T & m_processingFunctor
The functor which does the work/arbitrary calculations.
 
std::vector< Cube * > m_inputCubes
The input cubes for reading data from.
 
virtual ~ProcessCubesFunctor()
Destructor.
 
ProcessCubesFunctor(const ProcessCubesFunctor &other)
Copy construction of these objects is fully supported.
 
bool m_wraps
Wrap smaller cubes back to the beginning?
 
std::vector< Brick * > & m_inputTemplateBricks
Template bricks for reading input data.
 
ProcessCubesFunctor & operator=(const ProcessCubesFunctor &rhs)
Assignment of these objects is fully supported.
 
std::vector< Cube * > m_outputCubes
The output cubes for writing data to.
 
std::vector< Brick * > & m_outputTemplateBricks
Template bricks for writing output data.
 
This class is designed to iterate over all brick positions in a cube.
 
int operator*() const
Convert this iterator into a position.
 
bool operator==(const ProcessIterator &rhs)
Compare equality of two iterator positions.
 
ProcessIterator(int position)
Initialize a process iterator given a position.
 
ProcessIterator & operator=(const ProcessIterator &rhs)
Assignment of these iterators is fully supported.
 
int m_currentPosition
The current iterator's position/value.
 
void swap(ProcessIterator &other)
Exception-safe swap method.
 
bool operator!=(const ProcessIterator &rhs)
Compare inequality of two iterator positions.
 
virtual ~ProcessIterator()
Destructor.
 
ProcessIterator & operator++()
Increment the process iterator to the next position.
 
bool p_wrapOption
Indicates whether the brick manager will wrap.
 
std::vector< int > p_inputBrickBands
Number of bands in the input bricks.
 
void SetProcessingDirection(ProcessingDirection direction)
Set the direction the data will be read, either all lines in a single band proceeding to the next ban...
 
std::vector< int > p_outputBrickLines
Number of lines in the output bricks.
 
bool p_inputBrickSizeSet
Indicates whether the brick size has been set.
 
void Finalize()
Cleans up by closing cubes and freeing memory.
 
bool PrepProcessCubeInPlace(Cube **cube, Brick **bricks)
Prepare and check to run "function" parameter for StartProcess(void funct(Buffer &in)) and StartProce...
 
void ProcessCubeInPlace(const Functor &functor, bool threaded=true)
Operate over a single cube (either input or output).
 
bool p_reverse
Use the reverse option for constructing the Buffer objects when the Processing Direction is changed f...
 
ProcessByBrick()
Constructs a ProcessByBrick object.
 
void ProcessCubes(const Functor &functor, bool threaded=true)
Operate over an arbitrary number of input cubes given an arbitrary number of output cubes.
 
void SetOutputBrickSize(int ns, int nl, int nb)
Sets the size of all output bricks.
 
int PrepProcessCube(Brick **ibrick, Brick **obrick)
Prepare and check to run "function" parameter for StartProcess(void funct(Buffer &in,...
 
void VerifyCubes(IOCubes cn)
Verifies the dimensions of the input/output cubes.
 
void SetInputBrickSize(int ns, int nl, int nb)
Sets the size of all input bricks.
 
std::vector< int > p_inputBrickSamples
Number of samples in the input bricks.
 
virtual void StartProcess(void funct(Buffer &in))
Starts the systematic processing of the input cube by moving an arbitrarily-shaped brick through the ...
 
Cube * SetInputCube(const QString ¶meter, int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
 
void ProcessCube(const Functor &functor, bool threaded=true)
Operate over a single input cube creating a separate output cube.
 
std::vector< int > p_outputBrickBands
Number of bands in the output bricks.
 
void SetBrickSize(int ns, int nl, int nb)
Sets the input and output bricks sizes to the given number of samples, lines, and bands.
 
void SetWrap(bool wrap)
This wrapping option only applys when there are two or more input cubes.
 
bool Wraps()
Returns true if the wrapping option is enabled.
 
virtual ~ProcessByBrick()
Destroys the ProcessByBrick object.
 
void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
 
virtual Cube * SetOutputCube(const QString &fname, const CubeAttributeOutput &att)
Create the output file.
 
std::vector< int > p_inputBrickLines
Number of lines in the input bricks.
 
ProcessingDirection GetProcessingDirection()
Returns the direction the data will be read, either all lines in a single band proceeding to the next...
 
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 BlockingReportProgress(QFuture< void > &future)
This method blocks until the future reports that it is finished.
 
bool p_outputBrickSizeSet
Indicates whether the brick size has been set.
 
std::vector< int > p_outputBrickSamples
Number of samples in the output bricks.
 
void RunProcess(const Functor &wrapperFunctor, int numSteps, bool threaded)
This method runs the given wrapper functor numSteps times with or without threading,...
 
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...
 
Base class for all cube processing derivatives.
 
virtual void StartProcess(void funct())
In the base class, this method will invoked a user-specified function exactly one time.
 
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
 
Isis::Progress * p_progress
Pointer to a Progress object.
 
virtual Isis::Cube * SetOutputCube(const QString ¶meter)
Allocates a user-specified output cube whose size matches the first input cube.
 
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
 
virtual Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
 
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
 
void CheckStatus()
Checks and updates the status.
 
This is free and unencumbered software released into the public domain.