Isis 3 Programmer Reference
ProcessByBoxcar.cpp
Go to the documentation of this file.
1 
23 #include "BoxcarCachingAlgorithm.h"
24 #include "BoxcarManager.h"
25 #include "Buffer.h"
26 #include "LineManager.h"
27 #include "Process.h"
28 #include "ProcessByBoxcar.h"
29 
30 using namespace std;
31 namespace Isis {
32 
40  void ProcessByBoxcar::SetBoxcarSize(const int ns, const int nl) {
41 
42  p_boxSamples = ns;
43  p_boxLines = nl;
44  p_boxsizeSet = true;
45  }
46 
58  void ProcessByBoxcar::StartProcess(void funct(Isis::Buffer &in, double &out)) {
59  // Error checks ... there must be one input and output
60  if(InputCubes.size() != 1) {
61  string m = "You must specify exactly one input cube";
62  throw IException(IException::Programmer, m, _FILEINFO_);
63  }
64  else if(OutputCubes.size() != 1) {
65  string m = "You must specify exactly one output cube";
66  throw IException(IException::Programmer, m, _FILEINFO_);
67  }
68 
69  // The lines in the input and output must match
70  if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) {
71  string m = "The number of lines in the input and output cubes ";
72  m += "must match";
73  throw IException(IException::Programmer, m, _FILEINFO_);
74  }
75 
76  // The samples in the input and output must match
77  if(InputCubes[0]->sampleCount() != OutputCubes[0]->sampleCount()) {
78  string m = "The number of samples in the input and output cubes ";
79  m += "must match";
80  throw IException(IException::Programmer, m, _FILEINFO_);
81  }
82 
83  // The bands in the input and output must match
84  if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) {
85  string m = "The number of bands in the input and output cubes ";
86  m += "must match";
87  throw IException(IException::Programmer, m, _FILEINFO_);
88  }
89 
90  // Make sure the boxcar size has been set
91  if(!p_boxsizeSet) {
92  string m = "Use the SetBoxcarSize method to set the boxcar size";
93  throw IException(IException::Programmer, m, _FILEINFO_);
94  }
95 
96  // Construct boxcar buffer and line buffer managers
97  Isis::BoxcarManager box(*InputCubes[0], p_boxSamples, p_boxLines);
98  Isis::LineManager line(*OutputCubes[0]);
99  double out;
100 
101  InputCubes[0]->addCachingAlgorithm(new BoxcarCachingAlgorithm());
102  OutputCubes[0]->addCachingAlgorithm(new BoxcarCachingAlgorithm());
103 
104  // Loop and let the app programmer use the boxcar to change output pixel
105  p_progress->SetMaximumSteps(InputCubes[0]->lineCount()*InputCubes[0]->bandCount());
106  p_progress->CheckStatus();
107 
108  box.begin();
109  for(line.begin(); !line.end(); line.next()) {
110  for(int i = 0; i < line.size(); i++) {
111  InputCubes[0]->read(box);
112  funct(box, out);
113  line[i] = out;
114  box++;
115  }
116  OutputCubes[0]->write(line);
117  p_progress->CheckStatus();
118  }
119 
120  }
121 
128  void ProcessByBoxcar::EndProcess() {
129 
130  p_boxsizeSet = false;
132 
133  }
134 
139  void ProcessByBoxcar::Finalize() {
140 
141  p_boxsizeSet = false;
143 
144  }
145 } // end namespace isis
Buffer for reading and writing cube data.
Definition: Buffer.h:69
Namespace for the standard library.
Buffer manager, for moving through a cube by boxcar.
Definition: BoxcarManager.h:63
virtual void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Definition: Process.cpp:483
int size() const
Returns the total number of pixels in the shape buffer.
Definition: Buffer.h:113
bool begin()
Moves the shape buffer to the first position.
This algorithm is designed for applications that jump around between a couple of spots in the cube wi...
Buffer manager, for moving through a cube in lines.
Definition: LineManager.h:55
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
bool next()
Moves the shape buffer to the next position.
bool end() const
Returns true if the shape buffer has accessed the end of the cube.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual void Finalize()
Cleans up by closing cubes and freeing memory for owned cubes.
Definition: Process.cpp:491