Isis 3.0
Home
Chip.h
Go to the documentation of this file.
1 
24 #ifndef Chip_h
25 #define Chip_h
26 
27 
28 #include "Affine.h"
29 #include "Interpolator.h"
30 #include "Pvl.h"
31 #include "SpecialPixel.h"
32 
33 #include <vector>
34 
35 #include <geos/geom/MultiPolygon.h>
36 
37 namespace Isis {
38  class Cube;
39  class Statistics;
40 
101  class Chip {
102  public:
103  Chip();
104  Chip(const Chip &other);
105  Chip(const int samples, const int lines);
106  virtual ~Chip();
107 
108  void SetSize(const int samples, const int lines);
109  bool IsInsideChip(double sample, double line);
110 
114  inline int Samples() const {
115  return m_chipSamples;
116  };
117 
121  inline int Lines() const {
122  return m_chipLines;
123  };
124 
128  inline QString FileName() const {
129  return m_filename;
130  };
131 
132  void SetAllValues(const double &d);
133 
141  void SetValue(int sample, int line, const double &value) {
142  m_buf[line-1][sample-1] = value;
143  }
144 
158  inline double GetValue(int sample, int line) {
159  return m_buf[line-1][sample-1];
160  }
161 
174  inline double GetValue(int sample, int line) const {
175  return m_buf[line-1][sample-1];
176  }
177 
178  void TackCube(const double cubeSample, const double cubeLine);
179 
187  inline int TackSample() const {
188  return m_tackSample;
189  };
190 
198  inline int TackLine() const {
199  return m_tackLine;
200  };
201 
202  void Load(Cube &cube, const double rotation = 0.0, const double scale = 1.0,
203  const int band = 1);
204  void Load(Cube &cube, Chip &match, Cube &matchChipCube,
205  const double scale = 1.0, const int band = 1);
206  void Load(Cube &cube, const Affine &affine, const bool &keepPoly = true,
207  const int band = 1);
208 
209  void SetChipPosition(const double sample, const double line);
210 
212  inline double CubeSample() const {
213  return m_cubeSample;
214  };
215 
217  inline double CubeLine() const {
218  return m_cubeLine;
219  };
220 
221  void SetCubePosition(const double sample, const double line);
222 
224  double ChipSample() const {
225  return m_chipSample;
226  };
227 
229  double ChipLine() const {
230  return m_chipLine;
231  };
232 
233  void SetValidRange(const double minimum = Isis::ValidMinimum,
234  const double maximum = Isis::ValidMaximum);
235  bool IsValid(double percentage);
236 
244  inline bool IsValid(int sample, int line) {
245  double value = GetValue(sample, line);
246  if (value < m_validMinimum) return false;
247  if (value > m_validMaximum) return false;
248  return true;
249  }
250 
251  Chip Extract(int samples, int lines, int samp, int line);
252  void Extract(int samp, int line, Chip &output);
254  void Extract(Chip &output, Affine &affine);
255  void Write(const QString &filename);
256 
257  void SetClipPolygon(const geos::geom::MultiPolygon &clipPolygon);
258 
259  Chip &operator=(const Chip &other);
260 
270  const Affine &GetTransform() const {
271  return (m_affine);
272  }
273 
285  void SetTransform(const Affine &affine, const bool &keepPoly = true) {
286  m_affine = affine;
287  if (!keepPoly) {
288  delete m_clipPolygon;
289  m_clipPolygon = 0;
290  }
291  return;
292  }
293 
305  return m_readInterpolator;
306  }
307 
319  if (type == Interpolator::NearestNeighborType ||
320  type == Interpolator::BiLinearType ||
322  m_readInterpolator = type;
323  return;
324  }
325  // Interpolator::None is not valid type
326  QString msg = "Invalid Interpolator type. Cannot use [";
327  msg += toString(type) + "] to read cube into chip.";
329  }
330 
331  private:
332  void Init(const int samples, const int lines);
333  void Read(Cube &cube, const int band);
334  std::vector<int> MovePoints(int startSamp, int startLine,
335  int endSamp, int endLine);
336  bool PointsColinear(double x0, double y0,
337  double x1, double y1,
338  double x2, double y2,
339  double tol);
340 
341  int m_chipSamples;
342  int m_chipLines;
343  std::vector< std::vector<double> > m_buf;
344  int m_tackSample;
345  int m_tackLine;
346 
347  double m_cubeTackSample;
348  double m_cubeTackLine;
349 
350  double m_validMinimum;
351  double m_validMaximum;
352 
353  double m_chipSample;
354  double m_chipLine;
355  double m_cubeSample;
356  double m_cubeLine;
357 
358  geos::geom::MultiPolygon *m_clipPolygon;
359  // (line,samp)
360 
361  Affine m_affine;
362  // Used to load cubes into chip
363 
364  Interpolator::interpType m_readInterpolator;
365  // SetReadInterpolator. Used to read
366  // cubes into chip.
367 
368  QString m_filename;
369  };
370 };
371 
372 #endif
void SetChipPosition(const double sample, const double line)
Compute the position of the cube given a chip coordinate.
Definition: Chip.cpp:665
void SetValidRange(const double minimum=Isis::ValidMinimum, const double maximum=Isis::ValidMaximum)
Set the valid range of data in the chip.
Definition: Chip.cpp:703
void SetCubePosition(const double sample, const double line)
Compute the position of the chip given a cube coordinate.
Definition: Chip.cpp:682
bool IsValid(double percentage)
Return if the pixel is valid at a particular position.
Definition: Chip.cpp:739
virtual ~Chip()
Destroys the Chip object.
Definition: Chip.cpp:110
const Affine & GetTransform() const
Returns the Affine transformation of chip-to-cube indices.
Definition: Chip.h:270
interpType
The interpolator type, including: None, Nearest Neighbor, BiLinear or Cubic Convultion.
Definition: Interpolator.h:57
const double ValidMinimum
The minimum valid double value for Isis pixels.
Definition: SpecialPixel.h:101
A small chip of data used for pattern matching.
Definition: Chip.h:101
double GetValue(int sample, int line) const
Get a value from a Chip.
Definition: Chip.h:174
Definition: Interpolator.h:59
bool IsInsideChip(double sample, double line)
Definition: Chip.cpp:184
double ChipLine() const
Returns chip line after invoking SetCubePosition.
Definition: Chip.h:229
void TackCube(const double cubeSample, const double cubeLine)
This sets which cube position will be located at the chip tack position.
Definition: Chip.cpp:204
void SetTransform(const Affine &affine, const bool &keepPoly=true)
Sets the internal Affine transform to new translation.
Definition: Chip.h:285
void SetReadInterpolator(const Interpolator::interpType type)
Sets Interpolator Type for loading a chip.
Definition: Chip.h:318
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
Chip Extract(int samples, int lines, int samp, int line)
Extract a sub-chip from a chip.
Definition: Chip.cpp:765
int Samples() const
Return the number of samples in the chip.
Definition: Chip.h:114
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:109
Isis::Statistics * Statistics()
Returns a statistics object of the current data in the chip.
Definition: Chip.cpp:947
Affine basis function.
Definition: Affine.h:79
bool IsValid(int sample, int line)
Returns whether the value at the given sample, line position is within the valid range.
Definition: Chip.h:244
void Write(const QString &filename)
Writes the contents of the Chip to a cube.
Definition: Chip.cpp:1023
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
Interpolator::interpType GetReadInterpolator()
Access method that returns the Interpolator Type used for loading a chip.
Definition: Chip.h:304
void SetAllValues(const double &d)
Single value assignment operator.
Definition: Chip.cpp:122
int TackSample() const
Return the fixed tack sample of the chip.
Definition: Chip.h:187
void SetSize(const int samples, const int lines)
Change the size of the Chip.
Definition: Chip.cpp:156
double CubeLine() const
Returns cube line after invoking SetChipPosition.
Definition: Chip.h:217
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:225
Chip()
Constructs a Chip.
Definition: Chip.cpp:57
void SetClipPolygon(const geos::geom::MultiPolygon &clipPolygon)
Sets the clipping polygon for this chip.
Definition: Chip.cpp:1046
void SetValue(int sample, int line, const double &value)
Sets a value in the chip.
Definition: Chip.h:141
const double ValidMaximum
The maximum valid double value for Isis pixels.
Definition: SpecialPixel.h:136
Definition: Interpolator.h:60
int Lines() const
Return the number of lines in the chip.
Definition: Chip.h:121
Isis exception class.
Definition: IException.h:99
Definition: Interpolator.h:61
Chip & operator=(const Chip &other)
Copy assignment operator.
Definition: Chip.cpp:1057
double GetValue(int sample, int line)
Loads a Chip with a value.
Definition: Chip.h:158
double CubeSample() const
Returns cube sample after invoking SetChipPosition.
Definition: Chip.h:212
int TackLine() const
Return the fixed tack line of the chip.
Definition: Chip.h:198
QString FileName() const
Returns the expanded filename of the cube from which this chip was chipped.
Definition: Chip.h:128
double ChipSample() const
Returns chip sample after invoking SetCubePosition.
Definition: Chip.h:224
IO Handler for Isis Cubes.
Definition: Cube.h:158