EyeCalibration::SegmentVector EyeCalibration::getEdges(CalibrationPointVector processingPoints) { SegmentVector edges; for (unsigned int i = 0; i < processingPoints.size(); i++) { for (unsigned int j = i + 1; j < processingPoints.size(); j++) { edges.push_back( Segment(processingPoints.at(i), processingPoints.at(j)) ); } } return edges; }
const SegmentVector TerrainPageGeometry::getValidSegments() const { SegmentVector validSegments; for (SegmentRefStore::const_iterator I = mLocalSegments.begin(); I != mLocalSegments.end(); ++I) { for (SegmentRefColumn::const_iterator J = I->second.begin(); J != I->second.end(); ++J) { Mercator::Segment& segment = J->second->getMercatorSegment(); PageSegment pageSegment; pageSegment.index = TerrainPosition(I->first, J->first); pageSegment.segment = &segment; validSegments.push_back(pageSegment); } } return validSegments; }
EyeCalibration::SegmentVector EyeCalibration::calculateConvexHull(CalibrationPointVector processingPoints) { // Edges SegmentVector segments; if (processingPoints.size() < 3) return segments; CalibrationPoint minX = processingPoints.at(0), minY = processingPoints.at(0), maxX = processingPoints.at(0), maxY = processingPoints.at(0); for (unsigned int i = 0; i < processingPoints.size(); i++) { CalibrationPoint point = processingPoints.at(i); osg::Vec3 ray = point.ray(); if (minX.x() > point.x()) minX = point; if (minY.y() > point.y()) minY = point; if (maxX.x() < point.x()) maxX = point; if (maxY.y() < point.y()) maxY = point; } // Get center int center_x = (maxX.x() - minX.x())/2; int center_y = (maxY.y() - minY.y())/2; // Ordered Point CalibrationPointVector orderedPoints(processingPoints); // Sort Points sort(orderedPoints, center_x, center_y); // Create segments for (unsigned int i = 0; i < orderedPoints.size(); i++) { CalibrationPoint from = orderedPoints.at(i); for (unsigned int k = 0; k < orderedPoints.size(); k++) { if (i == k) continue; CalibrationPoint to = orderedPoints.at(k); Segment segment(from, to); segments.push_back(segment); } } unsigned int i = 0; unsigned int j = 0; while ( i < segments.size() ) { //ProcessingPoints will be the points that are not in the current segment CalibrationPointVector processingPoints(orderedPoints); Segment segment = segments.at(i); //this loop prepares the ProcessingPoints list for each segment while ( j < processingPoints.size() ) { CalibrationPoint point = processingPoints.at(j); if((segment.x1() == point.x() && segment.y1() == point.y()) || (segment.x2() == point.x() && segment.y2() == point.y())) { //eliminating the points that are already in the current segment... //we don't need them processingPoints.erase(processingPoints.begin()+j); j = 0; } else { j++; } } //checking if the current segment is an edge or notBy calling isEdge function if( !isEdge(processingPoints, segments.at(i)) ) { segments.erase(segments.begin()+i); i = 0; } else { i++; } } return segments; }