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
14using namespace std;
15namespace 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
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());
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);
102 }
103
104 }
105
113
114 p_boxsizeSet = false;
116
117 }
118
124
125 p_boxsizeSet = false;
127
128 }
129} // end namespace isis
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 by boxcar.
Buffer for reading and writing cube data.
Definition Buffer.h:53
int size() const
Returns the total number of pixels in the shape buffer.
Definition Buffer.h:97
bool begin()
Moves the shape buffer to the first position.
bool end() const
Returns true if the shape buffer has accessed the end of the cube.
bool next()
Moves the shape buffer to the next position.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Buffer manager, for moving through a cube in lines.
Definition LineManager.h:39
void EndProcess()
End the boxcar processing sequence and cleans up by closing cubes, freeing memory,...
int p_boxLines
Number of lines in boxcar.
virtual void StartProcess(void funct(Isis::Buffer &in, double &out))
Starts the systematic processing of the input cube by moving a boxcar, p_boxSamples by p_boxLines,...
void SetBoxcarSize(const int ns, const int nl)
Sets the boxcar size.
bool p_boxsizeSet
Indicates whether the boxcar size has been set.
void Finalize()
End the boxcar processing sequence and cleans up by closing cubes, freeing memory,...
int p_boxSamples
Number of samples in boxcar.
virtual void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Definition Process.cpp:462
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
Definition Process.h:185
Isis::Progress * p_progress
Pointer to a Progress object.
Definition Process.h:145
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
Definition Process.h:191
virtual void Finalize()
Cleans up by closing cubes and freeing memory for owned cubes.
Definition Process.cpp:471
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
Definition Progress.cpp:85
void CheckStatus()
Checks and updates the status.
Definition Progress.cpp:105
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
Namespace for the standard library.