USGS

Isis 3.0 Object Programmers' Reference

Home

ProcessByLine.cpp
Go to the documentation of this file.
1 
24 #include "ProcessByLine.h"
25 
26 #include "Buffer.h"
27 #include "Cube.h"
28 #include "IException.h"
29 #include "Process.h"
30 #include "ProcessByBrick.h"
31 
32 
33 using namespace std;
34 namespace Isis {
57  Isis::Cube *ProcessByLine::SetInputCube(const QString &parameter,
58  const int requirements) {
59  int allRequirements = Isis::SpatialMatch | Isis::BandMatchOrOne;
60  allRequirements |= requirements;
61  return Process::SetInputCube(parameter, allRequirements);
62  }
63 
79  Isis::Cube *ProcessByLine::SetInputCube(const QString &file,
81  const int requirements) {
82  int allRequirements = Isis::SpatialMatch | Isis::BandMatchOrOne;
83  allRequirements |= requirements;
84  return Process::SetInputCube(file, att, allRequirements);
85  }
86 
87 
96  void ProcessByLine::SetInputCube(Isis::Cube *inCube)
97  {
98  Process::SetInputCube(inCube);
99  }
100 
107  void ProcessByLine::VerifyCubeInPlace(void){
108  // Error checks
109  if((InputCubes.size() + OutputCubes.size()) > 1) {
110  string m = "You can only specify exactly one input or output cube";
111  throw IException(IException::Programmer, m, _FILEINFO_);
112  }
113  else if((InputCubes.size() + OutputCubes.size()) == 0) {
114  string m = "You haven't specified an input or output cube";
115  throw IException(IException::Programmer, m, _FILEINFO_);
116  }
117 
118  // Determine if we have an input or output
119  if(InputCubes.size() == 1) {
120  SetBrickSize(InputCubes[0]->sampleCount(), 1, 1);
121  }
122  else {
123  SetBrickSize(OutputCubes[0]->sampleCount(), 1, 1);
124  }
125  }
126 
146  void ProcessByLine::StartProcess(void funct(Isis::Buffer &inout)) {
147  // Error checks
148  VerifyCubeInPlace();
149  ProcessByBrick::StartProcess(funct);
150  }
151 
158  void ProcessByLine::VerifyCubeIO(void)
159  {
160  // Error checks ... there must be one input and output
161  if(InputCubes.size() != 1) {
162  string m = "You must specify exactly one input cube";
163  throw IException(IException::Programmer, m, _FILEINFO_);
164  }
165  else if(OutputCubes.size() != 1) {
166  string m = "You must specify exactly one output cube";
167  throw IException(IException::Programmer, m, _FILEINFO_);
168  }
169 
170  // The lines in the input and output must match
171  if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) {
172  string m = "The number of lines in the input and output cubes ";
173  m += "must match";
174  throw IException(IException::Programmer, m, _FILEINFO_);
175  }
176 
177  // The bands in the input and output must match
178  if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) {
179  string m = "The number of bands in the input and output cubes ";
180  m += "must match";
181  throw IException(IException::Programmer, m, _FILEINFO_);
182  }
183 
184  SetInputBrickSize(InputCubes[0]->sampleCount(), 1, 1);
185  SetOutputBrickSize(OutputCubes[0]->sampleCount(), 1, 1);
186  }
187 
200  void ProcessByLine::StartProcess(void
201  funct(Isis::Buffer &in, Isis::Buffer &out)) {
202 
203  VerifyCubeIO();
204  ProcessByBrick::StartProcess(funct);
205  }
206 
216  void ProcessByLine::VerifyCubeIOList(void)
217  {
218  // Make sure we had an image
219  if(InputCubes.size() + OutputCubes.size() < 1) {
220  string m = "You have not specified any input or output cubes";
221  throw IException(IException::Programmer, m, _FILEINFO_);
222  }
223 
224  // Make sure all the output images have the same number of bands as
225  // the first input/output cube
226  for(unsigned int i = 0; i < OutputCubes.size(); i++) {
227  if(OutputCubes[i]->lineCount() != OutputCubes[0]->lineCount()) {
228  string m = "All output cubes must have the same number of lines ";
229  m += "as the first input cube or output cube";
230  throw IException(IException::Programmer, m, _FILEINFO_);
231  }
232  if(OutputCubes[i]->bandCount() != OutputCubes[0]->bandCount()) {
233  string m = "All output cubes must have the same number of bands ";
234  m += "as the first input cube or output cube";
235  throw IException(IException::Programmer, m, _FILEINFO_);
236  }
237  }
238 
239  for(unsigned int i = 0; i < InputCubes.size(); i++) {
240  SetInputBrickSize(InputCubes[i]->sampleCount(), 1, 1, i + 1);
241  }
242  for(unsigned int i = 0; i < OutputCubes.size(); i++) {
243  SetOutputBrickSize(OutputCubes[i]->sampleCount(), 1, 1, i + 1);
244  }
245  }
257  void ProcessByLine::StartProcess(
258  void funct(std::vector<Isis::Buffer *> &in,
259  std::vector<Isis::Buffer *> &out)) {
260 
261  VerifyCubeIOList();
262  ProcessByBrick::StartProcess(funct);
263  }
264 }