Isis 3 Programmer Reference
ProcessByBoxcar.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "BoxcarCachingAlgorithm.h"
8 #include "BoxcarManager.h"
9 #include "Buffer.h"
10 #include "LineManager.h"
11 #include "Process.h"
12 #include "ProcessByBoxcar.h"
13 
14 using namespace std;
15 namespace Isis {
16 
24  void ProcessByBoxcar::SetBoxcarSize(const int ns, const int nl) {
25 
26  p_boxSamples = ns;
27  p_boxLines = nl;
28  p_boxsizeSet = true;
29  }
30 
42  void ProcessByBoxcar::StartProcess(void funct(Isis::Buffer &in, double &out)) {
43  // Error checks ... there must be one input and output
44  if(InputCubes.size() != 1) {
45  string m = "You must specify exactly one input cube";
46  throw IException(IException::Programmer, m, _FILEINFO_);
47  }
48  else if(OutputCubes.size() != 1) {
49  string m = "You must specify exactly one output cube";
50  throw IException(IException::Programmer, m, _FILEINFO_);
51  }
52 
53  // The lines in the input and output must match
54  if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) {
55  string m = "The number of lines in the input and output cubes ";
56  m += "must match";
57  throw IException(IException::Programmer, m, _FILEINFO_);
58  }
59 
60  // The samples in the input and output must match
61  if(InputCubes[0]->sampleCount() != OutputCubes[0]->sampleCount()) {
62  string m = "The number of samples in the input and output cubes ";
63  m += "must match";
64  throw IException(IException::Programmer, m, _FILEINFO_);
65  }
66 
67  // The bands in the input and output must match
68  if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) {
69  string m = "The number of bands in the input and output cubes ";
70  m += "must match";
71  throw IException(IException::Programmer, m, _FILEINFO_);
72  }
73 
74  // Make sure the boxcar size has been set
75  if(!p_boxsizeSet) {
76  string m = "Use the SetBoxcarSize method to set the boxcar size";
77  throw IException(IException::Programmer, m, _FILEINFO_);
78  }
79 
80  // Construct boxcar buffer and line buffer managers
81  Isis::BoxcarManager box(*InputCubes[0], p_boxSamples, p_boxLines);
82  Isis::LineManager line(*OutputCubes[0]);
83  double out;
84 
85  InputCubes[0]->addCachingAlgorithm(new BoxcarCachingAlgorithm());
86  OutputCubes[0]->addCachingAlgorithm(new BoxcarCachingAlgorithm());
87 
88  // Loop and let the app programmer use the boxcar to change output pixel
89  p_progress->SetMaximumSteps(InputCubes[0]->lineCount()*InputCubes[0]->bandCount());
90  p_progress->CheckStatus();
91 
92  box.begin();
93  for(line.begin(); !line.end(); line.next()) {
94  for(int i = 0; i < line.size(); i++) {
95  InputCubes[0]->read(box);
96  funct(box, out);
97  line[i] = out;
98  box++;
99  }
100  OutputCubes[0]->write(line);
101  p_progress->CheckStatus();
102  }
103 
104  }
105 
112  void ProcessByBoxcar::EndProcess() {
113 
114  p_boxsizeSet = false;
116 
117  }
118 
123  void ProcessByBoxcar::Finalize() {
124 
125  p_boxsizeSet = false;
127 
128  }
129 } // end namespace isis
Isis::LineManager
Buffer manager, for moving through a cube in lines.
Definition: LineManager.h:39
Isis::BoxcarCachingAlgorithm
This algorithm is designed for applications that jump around between a couple of spots in the cube wi...
Definition: BoxcarCachingAlgorithm.h:32
Isis::BufferManager::next
bool next()
Moves the shape buffer to the next position.
Definition: BufferManager.h:106
Isis::BoxcarManager
Buffer manager, for moving through a cube by boxcar.
Definition: BoxcarManager.h:46
Isis::BufferManager::begin
bool begin()
Moves the shape buffer to the first position.
Definition: BufferManager.h:96
Isis::Process::EndProcess
virtual void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Definition: Process.cpp:455
Isis::Buffer
Buffer for reading and writing cube data.
Definition: Buffer.h:53
Isis::BufferManager::end
bool end() const
Returns true if the shape buffer has accessed the end of the cube.
Definition: BufferManager.h:115
Isis::IException
Isis exception class.
Definition: IException.h:91
std
Namespace for the standard library.
Isis::Buffer::size
int size() const
Returns the total number of pixels in the shape buffer.
Definition: Buffer.h:97
Isis::Process::Finalize
virtual void Finalize()
Cleans up by closing cubes and freeing memory for owned cubes.
Definition: Process.cpp:463
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16