31 ProcessByBrick::ProcessByBrick() {
32 p_inputBrickSamples.clear();
33 p_inputBrickLines.clear();
34 p_inputBrickBands.clear();
36 p_outputBrickSamples.clear();
37 p_outputBrickLines.clear();
38 p_outputBrickBands.clear();
40 p_outputRequirements = 0;
41 p_inputBrickSizeSet =
false;
42 p_outputBrickSizeSet =
false;
50 ProcessByBrick::~ProcessByBrick() {
73 Cube *ProcessByBrick::SetInputCube(
const QString ¶meter,
75 int allRequirements = AllMatchOrOne;
76 allRequirements |= requirements;
77 return Process::SetInputCube(parameter, allRequirements);
101 Cube *ProcessByBrick::SetInputCube(
const QString &file,
104 int allRequirements = AllMatchOrOne;
105 allRequirements |= requirements;
106 return Process::SetInputCube(file, att, allRequirements);
110 void ProcessByBrick::SetOutputRequirements(
int outputRequirements) {
112 p_outputRequirements = outputRequirements;
117 void ProcessByBrick::SetBricks(IOCubes cn){
139 void ProcessByBrick::VerifyCubes(IOCubes cn){
147 if (InputCubes.size() +OutputCubes.size() > 1) {
148 string m =
"You can only specify exactly one input or output cube";
151 else if ( (InputCubes.size() + OutputCubes.size() == 0) ){
153 string m =
"You haven't specified an input or output cube";
163 if(InputCubes.size() != 1) {
164 string m =
"You must specify exactly one input cube";
167 else if(OutputCubes.size() != 1) {
168 string m =
"You must specify exactly one output cube";
175 if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) {
176 string m =
"The number of lines in the input and output cubes ";
181 if(InputCubes[0]->sampleCount() != OutputCubes[0]->sampleCount()) {
182 string m =
"The number of samples in the input and output cubes ";
193 if ( !(p_outputRequirements & Isis::SpatialMatch ) ) {
194 if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) {
195 string m =
"The number of bands in the input and output cubes ";
206 case InputOutputList:
209 if (InputCubes.size() + OutputCubes.size() < 1) {
210 string m =
"You have not specified any input or output cubes";
214 for (
unsigned int i = 0; i < OutputCubes.size(); i++) {
215 if (OutputCubes[i]->lineCount() != OutputCubes[0]->lineCount() ) {
216 string m =
"All output cubes must have the same number of lines ";
217 m +=
"as the first input cube or output cube";
222 if ( !(p_outputRequirements & Isis::SpatialMatch ) ) {
223 if (OutputCubes[i]->bandCount() != OutputCubes[0]->bandCount() ) {
224 string m =
"All output cubes must have the same number of bands ";
225 m +=
"as the first input cube or output cube";
252 void ProcessByBrick::SetBrickSize(
int ns,
int nl,
int nb) {
253 SetInputBrickSize(ns, nl, nb);
254 SetOutputBrickSize(ns, nl, nb);
268 void ProcessByBrick::SetInputBrickSize(
int ns,
int nl,
int nb) {
269 p_inputBrickSamples.clear();
270 p_inputBrickSamples.resize(InputCubes.size() + 1, ns);
271 p_inputBrickLines.clear();
272 p_inputBrickLines.resize(InputCubes.size() + 1, nl);
273 p_inputBrickBands.clear();
274 p_inputBrickBands.resize(InputCubes.size() + 1, nb);
276 p_inputBrickSizeSet =
true;
291 void ProcessByBrick::SetInputBrickSize(
int ns,
int nl,
int nb,
int cube) {
292 if (cube > (
int)InputCubes.size()) {
293 string m =
"The specified cube is out of range";
298 if (p_inputBrickSamples.size() > 0) {
299 p_inputBrickSamples.resize(InputCubes.size() + 1, p_inputBrickSamples[0]);
300 p_inputBrickLines.resize(InputCubes.size() + 1, p_inputBrickLines[0]);
301 p_inputBrickBands.resize(InputCubes.size() + 1, p_inputBrickBands[0]);
305 p_inputBrickSamples.resize(InputCubes.size() + 1, ns);
306 p_inputBrickLines.resize(InputCubes.size() + 1, nl);
307 p_inputBrickBands.resize(InputCubes.size() + 1, nb);
310 p_inputBrickSamples[cube] = ns;
311 p_inputBrickLines[cube] = nl;
312 p_inputBrickBands[cube] = nb;
314 p_inputBrickSizeSet =
true;
327 void ProcessByBrick::SetOutputBrickSize(
int ns,
int nl,
int nb) {
328 p_outputBrickSamples.clear();
329 p_outputBrickSamples.resize(OutputCubes.size() + 1, ns);
330 p_outputBrickLines.clear();
331 p_outputBrickLines.resize(OutputCubes.size() + 1, nl);
332 p_outputBrickBands.clear();
333 p_outputBrickBands.resize(OutputCubes.size() + 1, nb);
335 p_outputBrickSizeSet =
true;
350 void ProcessByBrick::SetOutputBrickSize(
int ns,
int nl,
int nb,
int cube) {
351 if(cube > (
int)OutputCubes.size()) {
352 string m =
"The specified cube is out of range";
357 if(p_outputBrickSamples.size() > 0) {
358 p_outputBrickSamples.resize(OutputCubes.size() + 1,
359 p_outputBrickSamples[0]);
360 p_outputBrickLines.resize(OutputCubes.size() + 1, p_outputBrickLines[0]);
361 p_outputBrickBands.resize(OutputCubes.size() + 1, p_outputBrickBands[0]);
365 p_outputBrickSamples.resize(OutputCubes.size() + 1, ns);
366 p_outputBrickLines.resize(OutputCubes.size() + 1, nl);
367 p_outputBrickBands.resize(OutputCubes.size() + 1, nb);
370 p_outputBrickSamples[cube] = ns;
371 p_outputBrickLines[cube] = nl;
372 p_outputBrickBands[cube] = nb;
374 p_outputBrickSizeSet =
true;
391 Isis::Cube *ProcessByBrick::SetOutputCube(
const QString &fname,
394 int ns = InputCubes[0]->sampleCount();
395 int nb = InputCubes[0]->bandCount();
396 return Process::SetOutputCube(fname, att, ns, nl, nb);
407 void ProcessByBrick::SetProcessingDirection(ProcessingDirection direction) {
408 p_reverse = direction == BandsFirst ?
true :
false;
420 ProcessByBrick::ProcessingDirection ProcessByBrick::GetProcessingDirection() {
421 return p_reverse ? BandsFirst : LinesFirst;
436 void ProcessByBrick::SetWrap(
bool wrap) {
446 bool ProcessByBrick::Wraps() {
464 void ProcessByBrick::StartProcess(
void funct(
Buffer &in)) {
468 bool haveInput = PrepProcessCubeInPlace(&cube, &brick);
471 p_progress->SetMaximumSteps(brick->
Bricks());
472 p_progress->CheckStatus();
474 for (brick->
begin(); !brick->
end(); (*brick)++) {
485 p_progress->CheckStatus();
506 void ProcessByBrick::StartProcess(
void funct(
Buffer &in,
Buffer &out)) {
507 Brick *ibrick = NULL;
508 Brick *obrick = NULL;
510 int numBricks = PrepProcessCube(&ibrick, &obrick);
513 p_progress->SetMaximumSteps(numBricks);
514 p_progress->CheckStatus();
519 for (
int i = 0; i < numBricks; i++) {
520 InputCubes[0]->read(*ibrick);
521 funct(*ibrick, *obrick);
522 OutputCubes[0]->write(*obrick);
523 p_progress->CheckStatus();
546 void ProcessByBrick::StartProcess(
void funct(std::vector<Buffer *> &in,
547 std::vector<Buffer *> &out)) {
550 vector<Brick *> imgrs;
551 vector<Buffer *> ibufs;
554 vector<Brick *> omgrs;
555 vector<Buffer *> obufs;
557 int numBricks = PrepProcessCubes(ibufs, obufs, imgrs, omgrs);
560 p_progress->SetMaximumSteps(numBricks);
561 p_progress->CheckStatus();
563 for(
int t = 0; t < numBricks; t++) {
565 for(
unsigned int i = 0; i < InputCubes.size(); i++) {
566 InputCubes[i]->read(*ibufs[i]);
573 for(
unsigned int i = 0; i < OutputCubes.size(); i++) {
574 OutputCubes[i]->write(*obufs[i]);
578 for(
unsigned int i = 0; i < InputCubes.size(); i++) {
583 if(Wraps() && imgrs[i]->end())
587 if(imgrs[i]->Band() != imgrs[0]->Band() &&
588 InputCubes[i]->bandCount() != 1) {
589 imgrs[i]->SetBaseBand(imgrs[0]->Band());
592 p_progress->CheckStatus();
595 for(
unsigned int i = 0; i < ibufs.size(); i++) {
601 for(
unsigned int i = 0; i < obufs.size(); i++) {
614 void ProcessByBrick::EndProcess() {
615 p_inputBrickSizeSet =
false;
616 p_outputBrickSizeSet =
false;
617 Process::EndProcess();
624 void ProcessByBrick::Finalize() {
636 void ProcessByBrick::BlockingReportProgress(QFuture<void> &future) {
637 int isisReportedProgress = 0;
638 int lastProgressValue = future.progressValue();
644 while (!future.isFinished()) {
645 sleeper.tryLock(100);
647 if (future.progressValue() != lastProgressValue) {
648 lastProgressValue = future.progressValue();
651 int isisProgressValue = lastProgressValue;
652 while (isisReportedProgress < isisProgressValue) {
653 p_progress->CheckStatus();
654 isisReportedProgress++;
659 while (isisReportedProgress < future.progressValue()) {
660 p_progress->CheckStatus();
661 isisReportedProgress++;
682 vector<int> ProcessByBrick::CalculateMaxDimensions(
683 vector<Cube *> cubes)
const {
688 for (
unsigned int i = 0; i < cubes.size(); i++) {
689 int sampleCount = cubes[i]->sampleCount();
690 int lineCount = cubes[i]->lineCount();
691 int bandCount = cubes[i]->bandCount();
693 if (sampleCount > maxSamples)
694 maxSamples = sampleCount;
695 if (lineCount > maxLines)
696 maxLines = lineCount;
697 if (bandCount > maxBands)
698 maxBands = bandCount;
701 vector<int> maxDimensions;
702 maxDimensions.push_back(maxSamples);
703 maxDimensions.push_back(maxLines);
704 maxDimensions.push_back(maxBands);
705 return maxDimensions;
724 bool ProcessByBrick::PrepProcessCubeInPlace(
Cube **cube,
Brick **bricks) {
726 if ((InputCubes.size() + OutputCubes.size()) != 1) {
727 string m =
"You can only specify exactly one input or output cube";
732 if (InputCubes.size() == 1) {
734 if (!p_inputBrickSizeSet) {
735 string m =
"Use the SetBrickSize() or SetInputBrickSize() method to set"
736 " the input brick size";
740 else if (p_inputBrickSamples.size() == 1) {
741 SetInputBrickSize(p_inputBrickSamples[0], p_inputBrickLines[0],
742 p_inputBrickBands[0], 1);
746 *cube = InputCubes[0];
747 *bricks =
new Brick(**cube, p_inputBrickSamples[1],
748 p_inputBrickLines[1], p_inputBrickBands[1], p_reverse);
752 if (!p_outputBrickSizeSet) {
753 string m =
"Use the SetBrickSize() or SetOutputBrickSize() method to "
754 "set the output brick size";
758 else if (p_outputBrickSamples.size() == 1) {
759 SetOutputBrickSize(p_outputBrickSamples[0], p_outputBrickLines[0],
760 p_outputBrickBands[0], 1);
764 *cube = OutputCubes[0];
765 *bricks =
new Brick(**cube, p_outputBrickSamples[1],
766 p_outputBrickLines[1], p_outputBrickBands[1], p_reverse);
788 int ProcessByBrick::PrepProcessCube(
Brick **ibrick,
Brick **obrick) {
790 if (InputCubes.size() != 1) {
791 string m =
"You must specify exactly one input cube";
794 else if (OutputCubes.size() != 1) {
795 string m =
"You must specify exactly one output cube";
800 if (!p_inputBrickSizeSet || !p_outputBrickSizeSet) {
801 string m =
"Use the SetBrickSize(), SetInputBrickSize(), or "
802 "SetOutputBrickSize() method to set the brick sizes";
807 if (p_outputBrickSamples.size() == 1) {
808 SetOutputBrickSize(p_outputBrickSamples[0], p_outputBrickLines[0],
809 p_outputBrickBands[0], 1);
811 if (p_inputBrickSamples.size() == 1) {
812 SetInputBrickSize(p_inputBrickSamples[0], p_inputBrickLines[0],
813 p_inputBrickBands[0], 1);
820 *ibrick =
new Brick(*InputCubes[0], p_inputBrickSamples[1],
821 p_inputBrickLines[1], p_inputBrickBands[1], p_reverse);
822 *obrick =
new Brick(*OutputCubes[0], p_outputBrickSamples[1],
823 p_outputBrickLines[1], p_outputBrickBands[1], p_reverse);
830 vector<Cube *> allCubes;
831 allCubes.push_back(InputCubes[0]);
832 allCubes.push_back(OutputCubes[0]);
833 vector<int> maxDimensions = CalculateMaxDimensions(allCubes);
834 int maxSamples = maxDimensions[0];
835 int maxLines = maxDimensions[1];
836 int maxBands = maxDimensions[2];
838 *ibrick =
new Brick(maxSamples, maxLines, maxBands,
839 p_inputBrickSamples[1],
840 p_inputBrickLines[1],
841 p_inputBrickBands[1],
842 InputCubes[0]->pixelType(),
844 *obrick =
new Brick(maxSamples, maxLines, maxBands,
845 p_outputBrickSamples[1],
846 p_outputBrickLines[1],
847 p_outputBrickBands[1],
848 OutputCubes[0]->pixelType(),
853 if((*ibrick)->Bricks() > (*obrick)->Bricks()) {
854 numBricks = (*ibrick)->Bricks();
857 numBricks = (*obrick)->Bricks();
880 int ProcessByBrick::PrepProcessCubes(vector<Buffer *> & ibufs,
881 vector<Buffer *> & obufs,
882 vector<Brick *> & imgrs,
883 vector<Brick *> & omgrs) {
885 if(InputCubes.size() == 0 && OutputCubes.size() == 0) {
886 string m =
"You have not specified any input or output cubes";
891 if(!p_inputBrickSizeSet && InputCubes.size() > 0) {
892 string m =
"Use the SetBrickSize() or SetInputBrick() method to set the "
893 "input brick size(s)";
896 else if(p_inputBrickSizeSet && p_inputBrickSamples.size() == 1) {
897 SetInputBrickSize(p_inputBrickSamples[0], p_inputBrickLines[0],
898 p_inputBrickBands[0], InputCubes.size());
900 if(!p_outputBrickSizeSet && OutputCubes.size() > 0) {
901 string m =
"Use the SetBrickSize() or SetOutputBrick() method to set the "
902 "output brick size(s)";
905 else if(p_outputBrickSizeSet && p_outputBrickSamples.size() == 1) {
906 SetOutputBrickSize(p_outputBrickSamples[0], p_outputBrickLines[0],
907 p_outputBrickBands[0], OutputCubes.size());
922 vector<Cube *> allCubes(InputCubes);
923 for (
unsigned int i = 0; i < OutputCubes.size(); i++)
924 allCubes.push_back(OutputCubes[i]);
925 vector<int> maxDimensions = CalculateMaxDimensions(allCubes);
926 maxSamples = maxDimensions[0];
927 maxLines = maxDimensions[1];
928 maxBands = maxDimensions[2];
931 for (
unsigned int i = 1; i <= InputCubes.size(); i++) {
932 Brick *ibrick = NULL;
937 ibrick =
new Brick(*InputCubes[i-1],
938 p_inputBrickSamples[i],
939 p_inputBrickLines[i],
940 p_inputBrickBands[i],
944 ibrick =
new Brick(maxSamples, maxLines, maxBands,
945 p_inputBrickSamples[i],
946 p_inputBrickLines[i],
947 p_inputBrickBands[i],
948 InputCubes[i - 1]->pixelType(),
952 ibufs.push_back(ibrick);
953 imgrs.push_back(ibrick);
954 if(numBricks < ibrick->Bricks()) {
955 numBricks = ibrick->
Bricks();
959 for (
unsigned int i = 1; i <= OutputCubes.size(); i++) {
960 Brick *obrick = NULL;
962 obrick =
new Brick(*OutputCubes[i-1],
963 p_outputBrickSamples[i],
964 p_outputBrickLines[i],
965 p_outputBrickBands[i],
969 obrick =
new Brick(maxSamples, maxLines, maxBands,
970 p_outputBrickSamples[i],
971 p_outputBrickLines[i],
972 p_outputBrickBands[i],
973 OutputCubes[i - 1]->pixelType(),
977 obufs.push_back(obrick);
978 omgrs.push_back(obrick);
979 if(numBricks < obrick->Bricks()) {
980 numBricks = obrick->
Bricks();
993 ProcessByBrick::ProcessIterator::ProcessIterator(
int position) :
994 m_currentPosition(position) {
1005 m_currentPosition(other.m_currentPosition) {
1013 m_currentPosition = -1;
1023 m_currentPosition++;
Buffer for reading and writing cube data.
This class is designed to iterate over all brick positions in a cube.
bool end() const
Returns true if the shape buffer has accessed the end of the cube.
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 read(Blob &blob) const
This method will read data from the specified Blob object.
ProcessIterator & operator++()
Increment the process iterator to the next position.
bool begin()
Moves the shape buffer to the first position.
int Bricks()
Returns the number of Bricks in the cube.
#define _FILEINFO_
Macro for the filename and line number.
Manipulate and parse attributes of output cube filenames.
void write(Blob &blob)
This method will write a blob of data (e.g.
ProcessIterator(int position)
Initialize a process iterator given a position.
virtual ~ProcessIterator()
Destructor.
IO Handler for Isis Cubes.