102 int requirements = 0);
106 int requirements = 0);
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) {
172 bool haveInput = PrepProcessCubeInPlace(&cube, &brick);
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;
209 int numBricks = PrepProcessCube(&inputCubeData, &outputCubeData);
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;
251 int numBricks = PrepProcessCubes(
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>
284 void RunProcess(
const Functor &wrapperFunctor,
285 int numSteps,
bool threaded) {
286 ProcessIterator begin(0);
287 ProcessIterator end(numSteps);
292 int threadCount = QThreadPool::globalInstance()->maxThreadCount();
293 if (threaded && threadCount > 1) {
294 QFuture<void> result = QtConcurrent::mapped(begin, end,
296 BlockingReportProgress(result);
299 while (begin != end) {
300 wrapperFunctor(*begin);
322 template <
typename T>
323 class ProcessCubeInPlaceFunctor :
324 public std::function<void*(int)> {
341 ProcessCubeInPlaceFunctor(Cube *cube,
342 const Brick *templateBrick,
343 bool readInput,
bool writeOutput,
344 const T &processingFunctor) :
346 m_templateBrick(templateBrick),
347 m_readInput(readInput),
348 m_writeOutput(writeOutput),
349 m_processingFunctor(processingFunctor) {
358 ProcessCubeInPlaceFunctor(
const ProcessCubeInPlaceFunctor &other) :
359 m_cube(other.m_cube),
360 m_templateBrick(other.m_templateBrick),
361 m_readInput(other.m_readInput),
362 m_writeOutput(other.m_writeOutput),
363 m_processingFunctor(other.m_processingFunctor) {
370 virtual ~ProcessCubeInPlaceFunctor() {
372 m_templateBrick = NULL;
382 void *operator()(
const int &brickPosition)
const {
383 Brick cubeData(*m_templateBrick);
384 cubeData.setpos(brickPosition);
387 m_cube->
read(cubeData);
389 m_processingFunctor(cubeData);
392 m_cube->
write(cubeData);
405 ProcessCubeInPlaceFunctor &operator=(
406 const ProcessCubeInPlaceFunctor &rhs) {
408 m_templateBrick = rhs.m_templateBrick;
410 m_readInput = rhs.m_readInput;
411 m_writeOutput = rhs.m_writeOutput;
413 m_processingFunctor = rhs.m_processingFunctor;
422 const Brick *m_templateBrick;
429 const T &m_processingFunctor;
446 template <
typename T>
447 class ProcessCubeFunctor :
448 public std::function<void *(const int &)> {
465 ProcessCubeFunctor(Cube *inputCube,
466 const Brick *inputTemplateBrick,
468 const Brick *outputTemplateBrick,
469 const T &processingFunctor) :
470 m_inputCube(inputCube),
471 m_inputTemplateBrick(inputTemplateBrick),
472 m_outputCube(outputCube),
473 m_outputTemplateBrick(outputTemplateBrick),
474 m_processingFunctor(processingFunctor) {
483 ProcessCubeFunctor(
const ProcessCubeFunctor &other) :
484 m_inputCube(other.m_inputCube),
485 m_inputTemplateBrick(other.m_inputTemplateBrick),
486 m_outputCube(other.m_outputCube),
487 m_outputTemplateBrick(other.m_outputTemplateBrick),
488 m_processingFunctor(other.m_processingFunctor) {
495 virtual ~ProcessCubeFunctor() {
496 m_inputTemplateBrick = NULL;
497 m_outputTemplateBrick = NULL;
507 void *operator()(
const int &brickPosition)
const {
508 Brick inputCubeData(*m_inputTemplateBrick);
509 Brick outputCubeData(*m_outputTemplateBrick);
511 inputCubeData.setpos(brickPosition);
512 outputCubeData.setpos(brickPosition);
514 m_inputCube->
read(inputCubeData);
516 m_processingFunctor(inputCubeData, outputCubeData);
518 m_outputCube->
write(outputCubeData);
531 ProcessCubeFunctor &operator=(
const ProcessCubeFunctor &rhs) {
532 m_inputCube = rhs.m_inputCube;
533 m_inputTemplateBrick = rhs.m_inputTemplateBrick;
535 m_outputCube = rhs.m_outputCube;
536 m_outputTemplateBrick = rhs.m_outputTemplateBrick;
538 m_processingFunctor = rhs.m_processingFunctor;
547 const Brick *m_inputTemplateBrick;
552 const Brick *m_outputTemplateBrick;
555 const T &m_processingFunctor;
573 template <
typename T>
574 class ProcessCubesFunctor :
575 public std::function<void *(const int &)> {
596 ProcessCubesFunctor(std::vector<Cube *> &inputCubes,
597 std::vector<Brick *> &inputTemplateBricks,
598 std::vector<Cube *> &outputCubes,
599 std::vector<Brick *> &outputTemplateBricks,
601 const T &processingFunctor) :
602 m_inputCubes(inputCubes),
603 m_inputTemplateBricks(inputTemplateBricks),
604 m_outputCubes(outputCubes),
605 m_outputTemplateBricks(outputTemplateBricks),
607 m_processingFunctor(processingFunctor) {
616 ProcessCubesFunctor(
const ProcessCubesFunctor &other) :
617 m_inputCubes(other.m_inputCubes),
618 m_inputTemplateBricks(other.m_inputTemplateBricks),
619 m_outputCubes(other.m_outputCubes),
620 m_outputTemplateBricks(other.m_outputTemplateBricks),
621 m_wraps(other.m_wraps),
622 m_processingFunctor(other.m_processingFunctor) {
629 virtual ~ProcessCubesFunctor() {
639 void *operator()(
const int &brickPosition)
const {
640 QPair< std::vector<Buffer *>, std::vector<Buffer *> > functorBricks;
642 for (
int i = 0; i < (int)m_inputTemplateBricks.size(); i++) {
643 Brick *inputBrick =
new Brick(*m_inputTemplateBricks[i]);
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() &&
656 m_inputCubes[i]->bandCount() != 1) {
657 inputBrick->SetBaseBand(functorBricks.first[0]->Band());
660 m_inputCubes[i]->read(*inputBrick);
663 for (
int i = 0; i < (int)m_outputTemplateBricks.size(); i++) {
664 Brick *outputBrick =
new Brick(*m_outputTemplateBricks[i]);
665 functorBricks.second.push_back(outputBrick);
666 outputBrick->setpos(brickPosition);
670 m_processingFunctor(functorBricks.first, functorBricks.second);
673 for (
int i = 0; i < (int)functorBricks.second.size(); i++) {
674 m_outputCubes[i]->write(*functorBricks.second[i]);
675 delete functorBricks.second[i];
678 for (
int i = 0; i < (int)functorBricks.first.size(); i++) {
679 delete functorBricks.first[i];
693 ProcessCubesFunctor &operator=(
const ProcessCubesFunctor &rhs) {
694 m_inputCubes = rhs.m_inputCubes;
695 m_inputTemplateBricks = rhs.m_inputTemplateBricks;
697 m_outputCubes = rhs.m_outputCubes;
698 m_outputTemplateBricks = rhs.m_outputTemplateBricks;
700 m_wraps = rhs.m_wraps;
702 m_processingFunctor = rhs.m_processingFunctor;
709 std::vector<Cube *> m_inputCubes;
714 std::vector<Brick *> &m_inputTemplateBricks;
717 std::vector<Cube *> m_outputCubes;
722 std::vector<Brick *> &m_outputTemplateBricks;
728 const T &m_processingFunctor;
732 void BlockingReportProgress(QFuture<void> &future);
733 std::vector<int> CalculateMaxDimensions(std::vector<Cube *> cubes)
const;
734 bool PrepProcessCubeInPlace(Cube **cube, Brick **bricks);
735 int PrepProcessCube(Brick **ibrick, Brick **obrick);
736 int PrepProcessCubes(std::vector<Buffer *> & ibufs,
737 std::vector<Buffer *> & obufs,
738 std::vector<Brick *> & imgrs,
739 std::vector<Brick *> & omgrs);
751 class ProcessIterator {
753 ProcessIterator(
int position);
754 ProcessIterator(
const ProcessIterator &other);
755 virtual ~ProcessIterator();
757 using value_type = int;
758 using iterator_category = std::forward_iterator_tag;
759 using difference_type = std::ptrdiff_t;
760 using pointer =
int*;
761 using reference =
int&;
763 ProcessIterator &operator++();
771 bool operator==(
const ProcessIterator &rhs) {
772 return (m_currentPosition == rhs.m_currentPosition);
781 bool operator!=(
const ProcessIterator &rhs) {
782 return !(*
this == rhs);
791 void swap(ProcessIterator &other) {
792 std::swap(m_currentPosition, other.m_currentPosition);
802 ProcessIterator &operator=(
const ProcessIterator &rhs) {
803 ProcessIterator copy(rhs);
813 int operator*()
const {
814 return m_currentPosition;
819 int m_currentPosition;
827 bool p_inputBrickSizeSet;
829 bool p_outputBrickSizeSet;
832 int p_outputRequirements;
835 std::vector<int> p_inputBrickSamples;
837 std::vector<int> p_inputBrickLines;
839 std::vector<int> p_inputBrickBands;
841 std::vector<int> p_outputBrickSamples;
843 std::vector<int> p_outputBrickLines;
845 std::vector<int> p_outputBrickBands;