Isis 3 Programmer Reference
Centroid.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "Centroid.h"
8
9
10using namespace std;
11namespace Isis {
12 Centroid::Centroid(){
13 m_maxDN = 0; //range of dynamic numbers (DN's) to be included in the selection
14 m_minDN = 0;
15 };
16
17 Centroid::~Centroid(){};
18
19
30 int Centroid::select(Chip *inputChip,Chip *selectionChip) {
31 //check the sizes of the chips and make the selectionChip match the inputChip
32 int lines, samples,line,sample;
33
34 unsigned int i;
35
36 double dn;
37
38 lines = inputChip->Lines();
39 samples = inputChip->Samples();
40
41 if (lines <= 0 || samples <= 0)
42 return 0; //abort if the input chips isn't 2D
43
44 selectionChip->SetSize(samples,lines);
45
46 sample = int(inputChip->ChipSample());//(samples-1)/2;
47 line = int(inputChip->ChipLine());//(lines-1)/2;
48 //printf("DEBUG: centroid starting sample line: %d %d\n",sample,line);
49
50 //set all values to unselected
51 selectionChip->SetAllValues(0.0);
52
53 std::vector < std::vector<int> > Q; //queue of nodes to check
54 std::vector <int> pt(2);
55
56 dn = inputChip->GetValue(sample,line);
57 if (dn < m_minDN || dn > m_maxDN) {
58 // If the seed value doesn't meet the criteria then the selection is the empty set and the
59 // work is done
60 return 0;
61 }
62 else {
63 pt[0] = sample;
64 pt[1] = line;
65 Q.push_back(pt); //otherwise it's the first point in the queue
66 }
67 for (i=0;i<Q.size();i++) {
68 dn = inputChip->GetValue(Q[i][0], Q[i][1]);
69 //if the point is in the dynamic range and not yet selected
70 sample = Q[i][0];
71 if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(Q[i][0], Q[i][1]) == 0.0) {
72 line = Q[i][1];
73 selectionChip->SetValue(sample, line, 1.0); //set the cell to selected
74 //test the four direction pixels and add them the queue if they meet the criteria
75 if (sample < samples) {
76 dn = inputChip->GetValue(sample + 1, line);
77 //if the point is in the dynamic range and not yet selected
78 if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample+1, line) == 0.0) {
79 pt[0] = sample + 1;
80 pt[1] = line;
81 Q.push_back(pt);
82 }
83 }
84 if (sample > 1) {
85 dn = inputChip->GetValue(sample-1, line);
86 //if the point is in the dynamic range and not yet selected
87 if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample-1, line) == 0.0) {
88 pt[0] = sample-1;
89 pt[1] = line;
90 Q.push_back(pt);
91 }
92 }
93 if (line < lines) {
94 dn = inputChip->GetValue(sample, line +1);
95 //if the point is in the dynamic range and not yet selected
96 if( dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample, line+1) == 0.0 ) {
97 pt[0] = sample;
98 pt[1] = line + 1;
99 Q.push_back(pt);
100 }
101 }
102 if (line > 1) {
103 dn = inputChip->GetValue(sample, line-1);
104 //if the point is in the dynamic range and not yet selected
105 if( dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample, line-1) == 0.0 ) {
106 pt[0] = sample;
107 pt[1] = line-1;
108 Q.push_back(pt);
109 }
110 }
111 }
112 }
113
114 return 1;
115 }
116
117
126 int Centroid::setDNRange( double minimumDN,double maximumDN ) {
127 //method to set the dynamic range of the pixels to be selected
128 if (maximumDN < minimumDN)
129 return 0; //max must be >= min
130 m_minDN = minimumDN;
131 m_maxDN = maximumDN;
132 return 1;
133 }
134
135
140 return m_minDN;
141 }
142
143
148 return m_maxDN;
149 }
150}
int select(Chip *inputChip, Chip *selectionChip)
Given a range of DN this function creates a biniary chip for all continuous pixels that have the DN w...
Definition Centroid.cpp:30
double getMaxDN()
Definition Centroid.cpp:147
int setDNRange(double minimumDN, double maximumDN)
Set the range of the DNs.
Definition Centroid.cpp:126
double m_maxDN
The max DN value to be included in the selection.
Definition Centroid.h:41
double getMinDN()
Definition Centroid.cpp:139
double m_minDN
The min DN value to be included in the selection.
Definition Centroid.h:42
A small chip of data used for pattern matching.
Definition Chip.h:86
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
Namespace for the standard library.