@@ -36,7 +36,7 @@ IslandTree::IslandTree(const DivideTree ÷Tree) :
36
36
mDivideTree(divideTree) {
37
37
}
38
38
39
- void IslandTree::build () {
39
+ void IslandTree::build (bool isBathymetry ) {
40
40
// Initialize topology
41
41
mNodes .resize (mDivideTree .nodes ().size ());
42
42
int index = 1 ; // Peaks are 1-indexed; put in a dummy node 0
@@ -54,7 +54,7 @@ void IslandTree::build() {
54
54
uninvertPeaks ();
55
55
uninvertSaddles ();
56
56
57
- computeProminences ();
57
+ computeProminences (isBathymetry );
58
58
}
59
59
60
60
// Sort peaks so that parent is always higher elevation.
@@ -152,7 +152,7 @@ void IslandTree::uninvertSaddle(int nodeId) {
152
152
}
153
153
}
154
154
155
- void IslandTree::computeProminences () {
155
+ void IslandTree::computeProminences (bool isBathymetry ) {
156
156
for (int i = 1 ; i < (int ) mNodes .size (); ++i) {
157
157
Elevation elev = getPeak (i).elevation ;
158
158
int childNodeId = i;
@@ -177,8 +177,17 @@ void IslandTree::computeProminences() {
177
177
}
178
178
179
179
if (parentNodeId == Node::Null) {
180
- // This is the highest point in the tree
181
- mNodes [i].prominence = elev;
180
+ // This is the highest point in the tree. In "normal" circumstances where
181
+ // all the elevations are nonnegative, we can safely define the prominence as equal
182
+ // to the elevation. But for bathymetry the prominence is not so clear. We
183
+ // use the elevation of the minimum saddle as "sea level". This should agree
184
+ // with the traditional definition (prominence = elevation) for regular terrain,
185
+ // and for bathymetry, it will guarantee that the highest point has the
186
+ // highest prominence, which matches intuition.
187
+ //
188
+ // Other definitions of the prominence of the highest point are possible,
189
+ // for example, height above the minimum sample value.
190
+ mNodes [i].prominence = elev - getSeaLevelValue (isBathymetry);
182
191
} else {
183
192
// Prominence = peak elevation - key col elevation
184
193
int saddlePeakId = mNodes [childNodeId].saddlePeakId ;
@@ -189,6 +198,19 @@ void IslandTree::computeProminences() {
189
198
}
190
199
}
191
200
201
+ Elevation IslandTree::getSeaLevelValue (bool isBathymetry) {
202
+ // If this is bathymetry, find the minimum saddle elevation in the tree.
203
+ if (isBathymetry && !mNodes .empty ()) {
204
+ Elevation elevation = std::numeric_limits<Elevation>::max ();
205
+ for (auto const &saddle : mDivideTree .saddles ()) {
206
+ elevation = std::min (elevation, saddle.elevation );
207
+ }
208
+ return elevation;
209
+ }
210
+
211
+ return 0 ;
212
+ }
213
+
192
214
const Peak &IslandTree::getPeak (int peakId) const {
193
215
return mDivideTree .peaks ()[peakId - 1 ]; // 1-indexed
194
216
}
0 commit comments