Isis 3 Programmer Reference
Chip.h
1
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#ifndef Chip_h
9#define Chip_h
10
11
12#include "Affine.h"
13#include "Interpolator.h"
14#include "Pvl.h"
15#include "SpecialPixel.h"
16
17#include <vector>
18
19#include <geos/geom/MultiPolygon.h>
20
21namespace Isis {
22 class Cube;
23 class Statistics;
24
86 class Chip {
87 public:
88 Chip();
89 Chip(const Chip &other);
90 Chip(const int samples, const int lines);
91 virtual ~Chip();
92
93 void SetSize(const int samples, const int lines);
94 bool IsInsideChip(double sample, double line);
95
99 inline int Samples() const {
100 return m_chipSamples;
101 };
102
106 inline int Lines() const {
107 return m_chipLines;
108 };
109
113 inline QString FileName() const {
114 return m_filename;
115 };
116
117 void SetAllValues(const double &d);
118
126 void SetValue(int sample, int line, const double &value) {
127 m_buf[line-1][sample-1] = value;
128 }
129
145 inline double GetValue(int sample, int line) {
146 return m_buf[line-1][sample-1];
147 }
148
163 inline double GetValue(int sample, int line) const {
164 return m_buf[line-1][sample-1];
165 }
166
167 void TackCube(const double cubeSample, const double cubeLine);
168
176 inline int TackSample() const {
177 return m_tackSample;
178 };
179
187 inline int TackLine() const {
188 return m_tackLine;
189 };
190
191 void Load(Cube &cube, const double rotation = 0.0, const double scale = 1.0,
192 const int band = 1);
193 void Load(Cube &cube, Chip &match, Cube &matchChipCube,
194 const double scale = 1.0, const int band = 1);
195 void Load(Cube &cube, const Affine &affine, const bool &keepPoly = true,
196 const int band = 1);
197
198 void SetChipPosition(const double sample, const double line);
199
203 inline double CubeSample() const {
204 return m_cubeSample;
205 };
206
210 inline double CubeLine() const {
211 return m_cubeLine;
212 };
213
214 void SetCubePosition(const double sample, const double line);
215
219 double ChipSample() const {
220 return m_chipSample;
221 };
222
226 double ChipLine() const {
227 return m_chipLine;
228 };
229
230 void SetValidRange(const double minimum = Isis::ValidMinimum,
231 const double maximum = Isis::ValidMaximum);
232
240 inline bool IsValid(int sample, int line) {
241 double value = GetValue(sample, line);
242 if (value < m_validMinimum) return false;
243 if (value > m_validMaximum) return false;
244 return true;
245 }
246
255 bool IsValid(double percentage);
256 Chip Extract(int samples, int lines, int samp, int line);
257 void Extract(int samp, int line, Chip &output);
259 void Extract(Chip &output, Affine &affine);
260 void Write(const QString &filename);
261
262 void SetClipPolygon(const geos::geom::MultiPolygon &clipPolygon);
263
264 Chip &operator=(const Chip &other);
265
275 const Affine &GetTransform() const {
276 return (m_affine);
277 }
278
290 void SetTransform(const Affine &affine, const bool &keepPoly = true) {
291 m_affine = affine;
292 if (!keepPoly) {
293 delete m_clipPolygon;
294 m_clipPolygon = 0;
295 }
296 return;
297 }
298
312
324 if (type == Interpolator::NearestNeighborType ||
325 type == Interpolator::BiLinearType ||
326 type == Interpolator::CubicConvolutionType) {
327 m_readInterpolator = type;
328 return;
329 }
330 // Interpolator::None is not valid type
331 QString msg = "Invalid Interpolator type. Cannot use [";
332 msg += toString(type) + "] to read cube into chip.";
333 throw IException(IException::Programmer, msg, _FILEINFO_);
334 }
335
336 private:
337 void Init(const int samples, const int lines);
338 void Read(Cube &cube, const int band);
339 std::vector<int> MovePoints(int startSamp, int startLine,
340 int endSamp, int endLine);
341 bool PointsColinear(double x0, double y0,
342 double x1, double y1,
343 double x2, double y2,
344 double tol);
345
348 std::vector< std::vector<double> > m_buf;
351
354
357
359 double m_chipLine;
361 double m_cubeLine;
362
363 geos::geom::MultiPolygon *m_clipPolygon;
364 // (line,samp)
365
367 // Used to load cubes into chip
368
370 // SetReadInterpolator. Used to read
371 // cubes into chip.
372
373 QString m_filename;
374 };
375};
376
377#endif
Affine basis function.
Definition Affine.h:65
A small chip of data used for pattern matching.
Definition Chip.h:86
double CubeLine() const
Definition Chip.h:210
Affine m_affine
Transform set by SetTransform.
Definition Chip.h:366
void SetReadInterpolator(const Interpolator::interpType type)
Sets Interpolator Type for loading a chip.
Definition Chip.h:323
double m_cubeTackSample
cube sample at the chip tack
Definition Chip.h:352
void SetSize(const int samples, const int lines)
Change the size of the Chip.
Definition Chip.cpp:134
void Write(const QString &filename)
Writes the contents of the Chip to a cube.
Definition Chip.cpp:985
double GetValue(int sample, int line)
Loads a Chip with a value.
Definition Chip.h:145
Interpolator::interpType m_readInterpolator
Interpolator type set by.
Definition Chip.h:369
void SetTransform(const Affine &affine, const bool &keepPoly=true)
Sets the internal Affine transform to new translation.
Definition Chip.h:290
Interpolator::interpType GetReadInterpolator()
Access method that returns the Interpolator Type used for loading a chip.
Definition Chip.h:309
int Samples() const
Definition Chip.h:99
double m_cubeSample
cube sample set by SetCubePosition
Definition Chip.h:360
void SetValidRange(const double minimum=Isis::ValidMinimum, const double maximum=Isis::ValidMaximum)
Set the valid range of data in the chip.
Definition Chip.cpp:681
bool PointsColinear(double x0, double y0, double x1, double y1, double x2, double y2, double tol)
This method is called by Load() to determine whether the given 3 points are nearly colinear.
Definition Chip.cpp:546
double m_cubeLine
cube line set by SetCubePosition
Definition Chip.h:361
int TackSample() const
This method returns a chip's fixed tack sample; the middle of the chip.
Definition Chip.h:176
std::vector< std::vector< double > > m_buf
Chip buffer.
Definition Chip.h:348
bool IsInsideChip(double sample, double line)
Definition Chip.cpp:162
int Lines() const
Definition Chip.h:106
void SetAllValues(const double &d)
Single value assignment operator.
Definition Chip.cpp:100
void SetChipPosition(const double sample, const double line)
Compute the position of the cube given a chip coordinate.
Definition Chip.cpp:643
double ChipSample() const
Definition Chip.h:219
double m_chipLine
chip line set by SetChip/CubePosition
Definition Chip.h:359
double m_validMinimum
valid minimum chip pixel value
Definition Chip.h:355
int m_tackSample
Middle sample of the chip.
Definition Chip.h:349
double ChipLine() const
Definition Chip.h:226
Isis::Statistics * Statistics()
Returns a statistics object of the current data in the chip.
Definition Chip.cpp:909
void SetClipPolygon(const geos::geom::MultiPolygon &clipPolygon)
Sets the clipping polygon for this chip.
Definition Chip.cpp:1008
std::vector< int > MovePoints(int startSamp, int startLine, int endSamp, int endLine)
This method is called by Load() to move a control point across the chip.
Definition Chip.cpp:615
const Affine & GetTransform() const
Returns the Affine transformation of chip-to-cube indices.
Definition Chip.h:275
void Read(Cube &cube, const int band)
This method reads data from a cube and puts it into the chip.
Definition Chip.cpp:939
void TackCube(const double cubeSample, const double cubeLine)
This sets which cube position will be located at the chip tack position.
Definition Chip.cpp:182
double CubeSample() const
Definition Chip.h:203
bool IsValid(int sample, int line)
Definition Chip.h:240
int m_tackLine
Middle line of the chip.
Definition Chip.h:350
virtual ~Chip()
Destroys the Chip object.
Definition Chip.cpp:88
Chip Extract(int samples, int lines, int samp, int line)
Extract a sub-chip from a chip.
Definition Chip.cpp:727
double GetValue(int sample, int line) const
Get a value from a Chip.
Definition Chip.h:163
int m_chipLines
Number of lines in the chip.
Definition Chip.h:347
geos::geom::MultiPolygon * m_clipPolygon
clipping polygon set by SetClipPolygon
Definition Chip.h:363
void Load(Cube &cube, const double rotation=0.0, const double scale=1.0, const int band=1)
Load cube data into the Chip.
Definition Chip.cpp:203
int TackLine() const
This method returns a chip's fixed tack line; the middle of the chip.
Definition Chip.h:187
Chip & operator=(const Chip &other)
Copy assignment operator.
Definition Chip.cpp:1021
Chip()
Constructs a Chip.
Definition Chip.cpp:35
void SetCubePosition(const double sample, const double line)
Compute the position of the chip given a cube coordinate.
Definition Chip.cpp:660
void SetValue(int sample, int line, const double &value)
Sets a value in the chip.
Definition Chip.h:126
void Init(const int samples, const int lines)
Common initialization used by constructors.
Definition Chip.cpp:116
double m_cubeTackLine
cube line at the chip tack
Definition Chip.h:353
double m_chipSample
chip sample set by SetChip/CubePosition
Definition Chip.h:358
QString m_filename
FileName of loaded cube.
Definition Chip.h:373
QString FileName() const
Definition Chip.h:113
int m_chipSamples
Number of samples in the chip.
Definition Chip.h:346
double m_validMaximum
valid maximum chip pixel value
Definition Chip.h:356
IO Handler for Isis Cubes.
Definition Cube.h:168
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
interpType
The interpolator type, including: None, Nearest Neighbor, BiLinear or Cubic Convultion.
This class is used to accumulate statistics on double arrays.
Definition Statistics.h:94
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
const double ValidMaximum
The maximum valid double value for Isis pixels.
const double ValidMinimum
The minimum valid double value for Isis pixels.