@@ -2466,51 +2466,53 @@ void EdgeDrawingImpl::TestSegment(int i, int index1, int index2)
2466
2466
TestSegment (i, start, index2);
2467
2467
}
2468
2468
2469
- // ----------------------------------------------------------------------------------------------
2470
- // After the validation of the edge segments, extracts the valid ones
2471
- // In other words, updates the valid segments' pixel arrays and their lengths
2469
+ // After validating the edge segments, this function extracts the valid ones.
2470
+ // Specifically, it updates the valid segments' pixel arrays and their lengths based on validation.
2472
2471
void EdgeDrawingImpl::ExtractNewSegments ()
2473
2472
{
2474
2473
vector< vector<Point > > validSegments;
2475
- int noSegments = 0 ;
2476
2474
2477
2475
for (int i = 0 ; i < segmentNos; i++) {
2478
2476
int start = 0 ;
2479
2477
while (start < (int )segmentPoints[i].size ()) {
2480
2478
2479
+ // Find the first valid start point
2481
2480
while (start < (int )segmentPoints[i].size ()) {
2482
2481
int r = segmentPoints[i][start].y ;
2483
2482
int c = segmentPoints[i][start].x ;
2484
2483
2485
- if (edgeImg[r * width + c]) break ;
2484
+ if (edgeImg[r * width + c]) break ; // Found valid point
2486
2485
start++;
2487
2486
}
2488
2487
2489
2488
int end = start + 1 ;
2489
+
2490
+ // Find the end of the valid segment
2490
2491
while (end < (int )segmentPoints[i].size ()) {
2491
2492
int r = segmentPoints[i][end].y ;
2492
2493
int c = segmentPoints[i][end].x ;
2493
2494
2494
- if (edgeImg[r * width + c] == 0 ) break ;
2495
+ if (edgeImg[r * width + c] == 0 ) break ; // End of segment
2495
2496
end++;
2496
2497
}
2497
2498
2499
+ // Length of the segment
2498
2500
int len = end - start;
2501
+
2502
+ // Only accept segments of length >= 10
2499
2503
if (len >= 10 ) {
2500
- // A new segment. Accepted only only long enough (whatever that means)
2501
- // segments[noSegments].pixels = &map->segments[i].pixels[start];
2502
- // segments[noSegments].noPixels = len;
2503
- validSegments.push_back (vector<Point >());
2504
- vector<Point > subVec (&segmentPoints[i][start], &segmentPoints[i][end]);
2505
- validSegments[noSegments] = subVec;
2506
- noSegments++;
2504
+ vector<Point > subVec (segmentPoints[i].begin () + start, segmentPoints[i].begin () + end); // Safer bounds
2505
+ validSegments.push_back (subVec); // Add to valid segments
2507
2506
}
2507
+
2508
+ // Move start to next unprocessed point
2508
2509
start = end + 1 ;
2509
2510
}
2510
2511
}
2511
2512
2513
+ // Replace the old segments with valid segments
2512
2514
segmentPoints = validSegments;
2513
- segmentNos = noSegments;
2515
+ segmentNos = validSegments. size (); // Update number of segments
2514
2516
}
2515
2517
2516
2518
double EdgeDrawingImpl::NFA (double prob, int len)
0 commit comments