32 ProcessByBrick::ProcessByBrick() {
33 p_inputBrickSamples.clear();
34 p_inputBrickLines.clear();
35 p_inputBrickBands.clear();
37 p_outputBrickSamples.clear();
38 p_outputBrickLines.clear();
39 p_outputBrickBands.clear();
41 p_outputRequirements = 0;
42 p_inputBrickSizeSet =
false;
43 p_outputBrickSizeSet =
false;
51 ProcessByBrick::~ProcessByBrick() {
74 Cube *ProcessByBrick::SetInputCube(
const QString ¶meter,
76 int allRequirements = AllMatchOrOne;
77 allRequirements |= requirements;
78 return Process::SetInputCube(parameter, allRequirements);
102 Cube *ProcessByBrick::SetInputCube(
const QString &file,
105 int allRequirements = AllMatchOrOne;
106 allRequirements |= requirements;
107 return Process::SetInputCube(file, att, allRequirements);
111 void ProcessByBrick::SetOutputRequirements(
int outputRequirements) {
113 p_outputRequirements = outputRequirements;
118 void ProcessByBrick::SetBricks(IOCubes cn){
136 void ProcessByBrick::VerifyCubes(IOCubes cn){
143 if (InputCubes.size() +OutputCubes.size() > 1) {
144 string m =
"You can only specify exactly one input or output cube";
147 else if ( (InputCubes.size() + OutputCubes.size() == 0) ){
149 string m =
"You haven't specified an input or output cube";
158 if(InputCubes.size() != 1) {
159 string m =
"You must specify exactly one input cube";
162 else if(OutputCubes.size() != 1) {
163 string m =
"You must specify exactly one output cube";
168 if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) {
169 string m =
"The number of lines in the input and output cubes ";
174 if(InputCubes[0]->sampleCount() != OutputCubes[0]->sampleCount()) {
175 string m =
"The number of samples in the input and output cubes ";
186 if ( !(p_outputRequirements & Isis::SpatialMatch ) ) {
187 if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) {
188 string m =
"The number of bands in the input and output cubes ";
197 case InputOutputList:
200 if (InputCubes.size() + OutputCubes.size() < 1) {
201 string m =
"You have not specified any input or output cubes";
205 for (
unsigned int i = 0; i < OutputCubes.size(); i++) {
206 if (OutputCubes[i]->lineCount() != OutputCubes[0]->lineCount() ) {
207 string m =
"All output cubes must have the same number of lines ";
208 m +=
"as the first input cube or output cube";
213 if ( !(p_outputRequirements & Isis::SpatialMatch ) ) {
214 if (OutputCubes[i]->bandCount() != OutputCubes[0]->bandCount() ) {
215 string m =
"All output cubes must have the same number of bands ";
216 m +=
"as the first input cube or output cube";
241 void ProcessByBrick::SetBrickSize(
int ns,
int nl,
int nb) {
242 SetInputBrickSize(ns, nl, nb);
243 SetOutputBrickSize(ns, nl, nb);
257 void ProcessByBrick::SetInputBrickSize(
int ns,
int nl,
int nb) {
258 p_inputBrickSamples.clear();
259 p_inputBrickSamples.resize(InputCubes.size() + 1, ns);
260 p_inputBrickLines.clear();
261 p_inputBrickLines.resize(InputCubes.size() + 1, nl);
262 p_inputBrickBands.clear();
263 p_inputBrickBands.resize(InputCubes.size() + 1, nb);
265 p_inputBrickSizeSet =
true;
280 void ProcessByBrick::SetInputBrickSize(
int ns,
int nl,
int nb,
int cube) {
281 if (cube > (
int)InputCubes.size()) {
282 string m =
"The specified cube is out of range";
287 if (p_inputBrickSamples.size() > 0) {
288 p_inputBrickSamples.resize(InputCubes.size() + 1, p_inputBrickSamples[0]);
289 p_inputBrickLines.resize(InputCubes.size() + 1, p_inputBrickLines[0]);
290 p_inputBrickBands.resize(InputCubes.size() + 1, p_inputBrickBands[0]);
294 p_inputBrickSamples.resize(InputCubes.size() + 1, ns);
295 p_inputBrickLines.resize(InputCubes.size() + 1, nl);
296 p_inputBrickBands.resize(InputCubes.size() + 1, nb);
299 p_inputBrickSamples[cube] = ns;
300 p_inputBrickLines[cube] = nl;
301 p_inputBrickBands[cube] = nb;
303 p_inputBrickSizeSet =
true;
316 void ProcessByBrick::SetOutputBrickSize(
int ns,
int nl,
int nb) {
317 p_outputBrickSamples.clear();
318 p_outputBrickSamples.resize(OutputCubes.size() + 1, ns);
319 p_outputBrickLines.clear();
320 p_outputBrickLines.resize(OutputCubes.size() + 1, nl);
321 p_outputBrickBands.clear();
322 p_outputBrickBands.resize(OutputCubes.size() + 1, nb);
324 p_outputBrickSizeSet =
true;
339 void ProcessByBrick::SetOutputBrickSize(
int ns,
int nl,
int nb,
int cube) {
340 if(cube > (
int)OutputCubes.size()) {
341 string m =
"The specified cube is out of range";
346 if(p_outputBrickSamples.size() > 0) {
347 p_outputBrickSamples.resize(OutputCubes.size() + 1,
348 p_outputBrickSamples[0]);
349 p_outputBrickLines.resize(OutputCubes.size() + 1, p_outputBrickLines[0]);
350 p_outputBrickBands.resize(OutputCubes.size() + 1, p_outputBrickBands[0]);
354 p_outputBrickSamples.resize(OutputCubes.size() + 1, ns);
355 p_outputBrickLines.resize(OutputCubes.size() + 1, nl);
356 p_outputBrickBands.resize(OutputCubes.size() + 1, nb);
359 p_outputBrickSamples[cube] = ns;
360 p_outputBrickLines[cube] = nl;
361 p_outputBrickBands[cube] = nb;
363 p_outputBrickSizeSet =
true;
380 Isis::Cube *ProcessByBrick::SetOutputCube(
const QString &fname,
383 int ns = InputCubes[0]->sampleCount();
384 int nb = InputCubes[0]->bandCount();
385 return Process::SetOutputCube(fname, att, ns, nl, nb);
396 void ProcessByBrick::SetProcessingDirection(ProcessingDirection direction) {
397 p_reverse = direction == BandsFirst ? true :
false;
409 ProcessByBrick::ProcessingDirection ProcessByBrick::GetProcessingDirection() {
410 return p_reverse ? BandsFirst : LinesFirst;
425 void ProcessByBrick::SetWrap(
bool wrap) {
435 bool ProcessByBrick::Wraps() {
453 void ProcessByBrick::StartProcess(
void funct(
Buffer &in)) {
457 bool haveInput = PrepProcessCubeInPlace(&cube, &brick);
460 p_progress->SetMaximumSteps(brick->
Bricks());
461 p_progress->CheckStatus();
463 for (brick->
begin(); !brick->
end(); (*brick)++) {
474 p_progress->CheckStatus();
494 void ProcessByBrick::StartProcess(std::function<
void(
Buffer &in)> funct ) {
498 bool haveInput = PrepProcessCubeInPlace(&cube, &brick);
501 p_progress->SetMaximumSteps(brick->
Bricks());
502 p_progress->CheckStatus();
504 for (brick->
begin(); !brick->
end(); (*brick)++) {
515 p_progress->CheckStatus();
536 void ProcessByBrick::StartProcess(
void funct(
Buffer &in,
Buffer &out)) {
537 Brick *ibrick = NULL;
538 Brick *obrick = NULL;
540 int numBricks = PrepProcessCube(&ibrick, &obrick);
543 p_progress->SetMaximumSteps(numBricks);
544 p_progress->CheckStatus();
549 for (
int i = 0; i < numBricks; i++) {
550 InputCubes[0]->read(*ibrick);
551 funct(*ibrick, *obrick);
552 OutputCubes[0]->write(*obrick);
553 p_progress->CheckStatus();
577 void ProcessByBrick::StartProcess(std::function<
void(
Buffer &in,
Buffer &out)> funct ) {
578 Brick *ibrick = NULL;
579 Brick *obrick = NULL;
581 int numBricks = PrepProcessCube(&ibrick, &obrick);
584 p_progress->SetMaximumSteps(numBricks);
585 p_progress->CheckStatus();
590 for (
int i = 0; i < numBricks; i++) {
591 InputCubes[0]->read(*ibrick);
592 funct(*ibrick, *obrick);
593 OutputCubes[0]->write(*obrick);
594 p_progress->CheckStatus();
617 void ProcessByBrick::StartProcess(
void funct(std::vector<Buffer *> &in,
618 std::vector<Buffer *> &out)) {
621 vector<Brick *> imgrs;
622 vector<Buffer *> ibufs;
625 vector<Brick *> omgrs;
626 vector<Buffer *> obufs;
628 int numBricks = PrepProcessCubes(ibufs, obufs, imgrs, omgrs);
631 p_progress->SetMaximumSteps(numBricks);
632 p_progress->CheckStatus();
634 for(
int t = 0; t < numBricks; t++) {
636 for(
unsigned int i = 0; i < InputCubes.size(); i++) {
637 InputCubes[i]->read(*ibufs[i]);
644 for(
unsigned int i = 0; i < OutputCubes.size(); i++) {
645 OutputCubes[i]->write(*obufs[i]);
649 for(
unsigned int i = 0; i < InputCubes.size(); i++) {
654 if(Wraps() && imgrs[i]->end())
658 if(imgrs[i]->Band() != imgrs[0]->Band() &&
659 InputCubes[i]->bandCount() != 1) {
660 imgrs[i]->SetBaseBand(imgrs[0]->Band());
663 p_progress->CheckStatus();
666 for(
unsigned int i = 0; i < ibufs.size(); i++) {
672 for(
unsigned int i = 0; i < obufs.size(); i++) {
685 void ProcessByBrick::EndProcess() {
686 p_inputBrickSizeSet =
false;
687 p_outputBrickSizeSet =
false;
688 Process::EndProcess();
695 void ProcessByBrick::Finalize() {
707 void ProcessByBrick::BlockingReportProgress(QFuture<void> &future) {
708 int isisReportedProgress = 0;
709 int lastProgressValue = future.progressValue();
715 while (!future.isFinished()) {
716 sleeper.tryLock(100);
718 if (future.progressValue() != lastProgressValue) {
719 lastProgressValue = future.progressValue();
722 int isisProgressValue = lastProgressValue;
723 while (isisReportedProgress < isisProgressValue) {
724 p_progress->CheckStatus();
725 isisReportedProgress++;
730 while (isisReportedProgress < future.progressValue()) {
731 p_progress->CheckStatus();
732 isisReportedProgress++;
753 vector<int> ProcessByBrick::CalculateMaxDimensions(
754 vector<Cube *> cubes)
const {
759 for (
unsigned int i = 0; i < cubes.size(); i++) {
760 int sampleCount = cubes[i]->sampleCount();
761 int lineCount = cubes[i]->lineCount();
762 int bandCount = cubes[i]->bandCount();
764 if (sampleCount > maxSamples)
765 maxSamples = sampleCount;
766 if (lineCount > maxLines)
767 maxLines = lineCount;
768 if (bandCount > maxBands)
769 maxBands = bandCount;
772 vector<int> maxDimensions;
773 maxDimensions.push_back(maxSamples);
774 maxDimensions.push_back(maxLines);
775 maxDimensions.push_back(maxBands);
776 return maxDimensions;
795 bool ProcessByBrick::PrepProcessCubeInPlace(
Cube **cube,
Brick **bricks) {
797 if ((InputCubes.size() + OutputCubes.size()) != 1) {
798 string m =
"You can only specify exactly one input or output cube";
803 if (InputCubes.size() == 1) {
807 if (!p_inputBrickSizeSet) {
808 string m =
"Use the SetBrickSize() or SetInputBrickSize() method to set" 809 " the input brick size";
813 else if (p_inputBrickSamples.size() == 1) {
814 SetInputBrickSize(p_inputBrickSamples[0], p_inputBrickLines[0],
815 p_inputBrickBands[0], 1);
819 *cube = InputCubes[0];
820 *bricks =
new Brick(**cube, p_inputBrickSamples[1],
821 p_inputBrickLines[1], p_inputBrickBands[1], p_reverse);
826 if (!p_outputBrickSizeSet) {
827 string m =
"Use the SetBrickSize() or SetOutputBrickSize() method to " 828 "set the output brick size";
832 else if (p_outputBrickSamples.size() == 1) {
833 SetOutputBrickSize(p_outputBrickSamples[0], p_outputBrickLines[0],
834 p_outputBrickBands[0], 1);
838 *cube = OutputCubes[0];
839 *bricks =
new Brick(**cube, p_outputBrickSamples[1],
840 p_outputBrickLines[1], p_outputBrickBands[1], p_reverse);
862 int ProcessByBrick::PrepProcessCube(
Brick **ibrick,
Brick **obrick) {
864 if (InputCubes.size() != 1) {
865 string m =
"You must specify exactly one input cube";
868 else if (OutputCubes.size() != 1) {
869 string m =
"You must specify exactly one output cube";
872 SetBricks(InputOutput);
874 if (!p_inputBrickSizeSet || !p_outputBrickSizeSet) {
875 string m =
"Use the SetBrickSize(), SetInputBrickSize(), or " 876 "SetOutputBrickSize() method to set the brick sizes";
881 if (p_outputBrickSamples.size() == 1) {
882 SetOutputBrickSize(p_outputBrickSamples[0], p_outputBrickLines[0],
883 p_outputBrickBands[0], 1);
885 if (p_inputBrickSamples.size() == 1) {
886 SetInputBrickSize(p_inputBrickSamples[0], p_inputBrickLines[0],
887 p_inputBrickBands[0], 1);
894 *ibrick =
new Brick(*InputCubes[0], p_inputBrickSamples[1],
895 p_inputBrickLines[1], p_inputBrickBands[1], p_reverse);
896 *obrick =
new Brick(*OutputCubes[0], p_outputBrickSamples[1],
897 p_outputBrickLines[1], p_outputBrickBands[1], p_reverse);
904 vector<Cube *> allCubes;
905 allCubes.push_back(InputCubes[0]);
906 allCubes.push_back(OutputCubes[0]);
907 vector<int> maxDimensions = CalculateMaxDimensions(allCubes);
908 int maxSamples = maxDimensions[0];
909 int maxLines = maxDimensions[1];
910 int maxBands = maxDimensions[2];
912 *ibrick =
new Brick(maxSamples, maxLines, maxBands,
913 p_inputBrickSamples[1],
914 p_inputBrickLines[1],
915 p_inputBrickBands[1],
916 InputCubes[0]->pixelType(),
918 *obrick =
new Brick(maxSamples, maxLines, maxBands,
919 p_outputBrickSamples[1],
920 p_outputBrickLines[1],
921 p_outputBrickBands[1],
922 OutputCubes[0]->pixelType(),
927 if((*ibrick)->Bricks() > (*obrick)->Bricks()) {
928 numBricks = (*ibrick)->Bricks();
931 numBricks = (*obrick)->Bricks();
954 int ProcessByBrick::PrepProcessCubes(vector<Buffer *> & ibufs,
955 vector<Buffer *> & obufs,
956 vector<Brick *> & imgrs,
957 vector<Brick *> & omgrs) {
959 if(InputCubes.size() == 0 && OutputCubes.size() == 0) {
960 string m =
"You have not specified any input or output cubes";
964 SetBricks(InputOutputList);
967 if(!p_inputBrickSizeSet && InputCubes.size() > 0) {
968 string m =
"Use the SetBrickSize() or SetInputBrick() method to set the " 969 "input brick size(s)";
972 else if(p_inputBrickSizeSet && p_inputBrickSamples.size() == 1) {
973 SetInputBrickSize(p_inputBrickSamples[0], p_inputBrickLines[0],
974 p_inputBrickBands[0], InputCubes.size());
976 if(!p_outputBrickSizeSet && OutputCubes.size() > 0) {
977 string m =
"Use the SetBrickSize() or SetOutputBrick() method to set the " 978 "output brick size(s)";
981 else if(p_outputBrickSizeSet && p_outputBrickSamples.size() == 1) {
982 SetOutputBrickSize(p_outputBrickSamples[0], p_outputBrickLines[0],
983 p_outputBrickBands[0], OutputCubes.size());
998 vector<Cube *> allCubes(InputCubes);
999 for (
unsigned int i = 0; i < OutputCubes.size(); i++)
1000 allCubes.push_back(OutputCubes[i]);
1001 vector<int> maxDimensions = CalculateMaxDimensions(allCubes);
1002 maxSamples = maxDimensions[0];
1003 maxLines = maxDimensions[1];
1004 maxBands = maxDimensions[2];
1007 for (
unsigned int i = 1; i <= InputCubes.size(); i++) {
1008 Brick *ibrick = NULL;
1013 ibrick =
new Brick(*InputCubes[i-1],
1014 p_inputBrickSamples[i],
1015 p_inputBrickLines[i],
1016 p_inputBrickBands[i],
1020 ibrick =
new Brick(maxSamples, maxLines, maxBands,
1021 p_inputBrickSamples[i],
1022 p_inputBrickLines[i],
1023 p_inputBrickBands[i],
1024 InputCubes[i - 1]->pixelType(),
1028 ibufs.push_back(ibrick);
1029 imgrs.push_back(ibrick);
1030 if(numBricks < ibrick->Bricks()) {
1031 numBricks = ibrick->
Bricks();
1035 for (
unsigned int i = 1; i <= OutputCubes.size(); i++) {
1036 Brick *obrick = NULL;
1038 obrick =
new Brick(*OutputCubes[i-1],
1039 p_outputBrickSamples[i],
1040 p_outputBrickLines[i],
1041 p_outputBrickBands[i],
1045 obrick =
new Brick(maxSamples, maxLines, maxBands,
1046 p_outputBrickSamples[i],
1047 p_outputBrickLines[i],
1048 p_outputBrickBands[i],
1049 OutputCubes[i - 1]->pixelType(),
1053 obufs.push_back(obrick);
1054 omgrs.push_back(obrick);
1055 if(numBricks < obrick->Bricks()) {
1056 numBricks = obrick->
Bricks();
1069 ProcessByBrick::ProcessIterator::ProcessIterator(
int position) :
1070 m_currentPosition(position) {
1081 m_currentPosition(other.m_currentPosition) {
1089 m_currentPosition = -1;
1099 m_currentPosition++;
Buffer for reading and writing cube data.
This class is designed to iterate over all brick positions in a cube.
Buffer for containing a three dimensional section of an image.
Namespace for the standard library.
ProcessIterator & operator++()
Increment the process iterator to the next position.
bool begin()
Moves the shape buffer to the first position.
bool isReadWrite() const
Test if the opened cube is read-write, that is read and write operations should succeed if this is tr...
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 read(Blob &blob) const
This method will read data from the specified Blob object.
bool end() const
Returns true if the shape buffer has accessed the end of the cube.
void write(Blob &blob)
This method will write a blob of data (e.g.
ProcessIterator(int position)
Initialize a process iterator given a position.
Namespace for ISIS/Bullet specific routines.
virtual ~ProcessIterator()
Destructor.
IO Handler for Isis Cubes.