Isis 3 Programmer Reference
Centroid.cpp
1 
2 
21 #include "Centroid.h"
22 
23 
24 using namespace std;
25 namespace Isis {
26  Centroid::Centroid(){
27  m_maxDN = 0; //range of dynamic numbers (DN's) to be included in the selection
28  m_minDN = 0;
29  };
30 
31  Centroid::~Centroid(){};
32 
33 
44  int Centroid::select(Chip *inputChip,Chip *selectionChip) {
45  //check the sizes of the chips and make the selectionChip match the inputChip
46  int lines, samples,line,sample;
47 
48  unsigned int i;
49 
50  double dn;
51 
52  lines = inputChip->Lines();
53  samples = inputChip->Samples();
54 
55  if (lines <= 0 || samples <= 0)
56  return 0; //abort if the input chips isn't 2D
57 
58  selectionChip->SetSize(samples,lines);
59 
60  sample = int(inputChip->ChipSample());//(samples-1)/2;
61  line = int(inputChip->ChipLine());//(lines-1)/2;
62  //printf("DEBUG: centroid starting sample line: %d %d\n",sample,line);
63 
64  //set all values to unselected
65  selectionChip->SetAllValues(0.0);
66 
67  std::vector < std::vector<int> > Q; //queue of nodes to check
68  std::vector <int> pt(2);
69 
70  dn = inputChip->GetValue(sample,line);
71  if (dn < m_minDN || dn > m_maxDN) {
72  // If the seed value doesn't meet the criteria then the selection is the empty set and the
73  // work is done
74  return 0;
75  }
76  else {
77  pt[0] = sample;
78  pt[1] = line;
79  Q.push_back(pt); //otherwise it's the first point in the queue
80  }
81  for (i=0;i<Q.size();i++) {
82  dn = inputChip->GetValue(Q[i][0], Q[i][1]);
83  //if the point is in the dynamic range and not yet selected
84  sample = Q[i][0];
85  if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(Q[i][0], Q[i][1]) == 0.0) {
86  line = Q[i][1];
87  selectionChip->SetValue(sample, line, 1.0); //set the cell to selected
88  //test the four direction pixels and add them the queue if they meet the criteria
89  if (sample < samples) {
90  dn = inputChip->GetValue(sample + 1, line);
91  //if the point is in the dynamic range and not yet selected
92  if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample+1, line) == 0.0) {
93  pt[0] = sample + 1;
94  pt[1] = line;
95  Q.push_back(pt);
96  }
97  }
98  if (sample > 1) {
99  dn = inputChip->GetValue(sample-1, line);
100  //if the point is in the dynamic range and not yet selected
101  if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample-1, line) == 0.0) {
102  pt[0] = sample-1;
103  pt[1] = line;
104  Q.push_back(pt);
105  }
106  }
107  if (line < lines) {
108  dn = inputChip->GetValue(sample, line +1);
109  //if the point is in the dynamic range and not yet selected
110  if( dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample, line+1) == 0.0 ) {
111  pt[0] = sample;
112  pt[1] = line + 1;
113  Q.push_back(pt);
114  }
115  }
116  if (line > 1) {
117  dn = inputChip->GetValue(sample, line-1);
118  //if the point is in the dynamic range and not yet selected
119  if( dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample, line-1) == 0.0 ) {
120  pt[0] = sample;
121  pt[1] = line-1;
122  Q.push_back(pt);
123  }
124  }
125  }
126  }
127 
128  return 1;
129  }
130 
131 
140  int Centroid::setDNRange( double minimumDN,double maximumDN ) {
141  //method to set the dynamic range of the pixels to be selected
142  if (maximumDN < minimumDN)
143  return 0; //max must be >= min
144  m_minDN = minimumDN;
145  m_maxDN = maximumDN;
146  return 1;
147  }
148 
149 
153  double Centroid::getMinDN() {
154  return m_minDN;
155  }
156 
157 
161  double Centroid::getMaxDN() {
162  return m_maxDN;
163  }
164 }
A small chip of data used for pattern matching.
Definition: Chip.h:102
Namespace for the standard library.
int Lines() const
Definition: Chip.h:122
void SetAllValues(const double &d)
Single value assignment operator.
Definition: Chip.cpp:122
double ChipLine() const
Definition: Chip.h:242
void SetSize(const int samples, const int lines)
Change the size of the Chip.
Definition: Chip.cpp:156
void SetValue(int sample, int line, const double &value)
Sets a value in the chip.
Definition: Chip.h:142
int Samples() const
Definition: Chip.h:115
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double ChipSample() const
Definition: Chip.h:235
double GetValue(int sample, int line)
Loads a Chip with a value.
Definition: Chip.h:161