bool _HYChartWindow::_ProcessOSEvent (Ptr vEvent) { static long lastH = -1, lastV = -1; if (!_HYTWindow::_ProcessOSEvent (vEvent)) { if (components.lLength == 0) { return false; } _HYPullDown *p1 = (_HYPullDown*)GetObject (4); if (p1&&(p1->GetSelection()>=8)&&(ySeries.lLength)) { _HY_GTK_UI_Message *theMessage = (_HY_GTK_UI_Message*)vEvent; gdouble xc, yc; gdk_event_get_coords (theMessage->theEvent,&xc,&yc); switch (theMessage->theEvent->type) { case GDK_BUTTON_PRESS: { if (((GdkEventButton*)theMessage->theEvent)->button != 1) { return false; } lastH = xc-theWindow->allocation.x-windowContent->allocation.x; lastV = yc-theWindow->allocation.y-windowContent->allocation.y; if (FindClickedCell(lastH, lastV)!=0) { // the chart lastH = -1; lastV = -1; } else { gdk_pointer_grab (theWindow->window,false, (GdkEventMask)(GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK), theWindow->window, NULL, ((GdkEventButton*)theMessage->theEvent)->time); return true; } break; } case GDK_BUTTON_RELEASE: { if (lastH>=0) { gdk_pointer_ungrab (((GdkEventButton*)theMessage->theEvent)->time); lastH = -1; lastV = -1; return true; } break; } case GDK_MOTION_NOTIFY: { if (lastH>=0) { long newH = xc-theWindow->allocation.x-windowContent->allocation.x, newV = yc-theWindow->allocation.y-windowContent->allocation.y; bool redraw = false; _Parameter stepper = pi_const/180.; if (abs(newH-lastH)>abs(newV-lastV)) { stepper *= 1+log (fabs(newH-lastH))/log(2.0); if (newH-lastH<0) { if (xyAngle>0.0) { xyAngle -= stepper; if (xyAngle<0) { xyAngle = 0; } redraw = true; } } else if (xyAngle<pi_const/2) { xyAngle += stepper; if (xyAngle>pi_const/2) { xyAngle = pi_const/2; } redraw = true; } } else { if (newV==lastV) { return false; } stepper *= 1+log (fabs(newV-lastV))/log(2.0); if (newV-lastV>0) { if (zAngle<pi_const/2) { zAngle += stepper; if (zAngle>pi_const/2) { zAngle = pi_const/2; } redraw = true; } } else if (zAngle>0.0) { zAngle -= stepper; if (zAngle<0) { zAngle = 0; } redraw = true; } } if (redraw) { ComputeProjectionSettings(); projectionMatrix = ComputeProjectionMatrix (); forceUpdateForScrolling = true; DrawChart(); forceUpdateForScrolling = false; } lastH = newH; lastV = newV; } break; } } } return false; } return true; }
void LocalPCADistance<TImage>::SetTargetPatch(const itk::ImageRegion<2>& region) { ComputeProjectionMatrix(region); }
int ComputeProjectionMatrixRansac(const Point3Vec& points, const Point2Vec& projections, int ransac_rounds, double ransac_threshold, Mat34* P) { const int num_pts = static_cast<int>(points.size()); if (num_pts < 6) { std::cerr << "[ComputeProjectionMatrixRansac] Error: need at least 6 points!"; return -1; } Point3Vec final_pts; Point2Vec final_projs; int max_inliers = 0; double max_error = std::numeric_limits<double>::max(); for (int round = 0; round < ransac_rounds; round++) { Point3Vec sample_pts; Point2Vec sample_projs; const auto sample_indices = util::GetNRandomIndices(6, num_pts); for (int i : sample_indices) { sample_pts.push_back(points[i]); sample_projs.push_back(projections[i]); } double error = 0.0; const Mat34 hypothesis = ComputeProjectionMatrix(sample_pts, sample_projs); const auto inlier_indices = EvaluateProjectionMatrix(hypothesis, points, projections, ransac_threshold, &error); const int num_inliers = static_cast<int>(inlier_indices.size()); if (num_inliers < 6) continue; if (num_inliers > max_inliers || (num_inliers == max_inliers && error < max_error)) { *P = hypothesis; max_error = error; max_inliers = num_inliers; for (int i : inlier_indices) { final_pts.push_back(points[i]); final_projs.push_back(projections[i]); } // Quick pseudo LO-RANSAC double error_i = 0.0; const Mat34 Pi = ComputeProjectionMatrix(final_pts, final_projs, true); const auto inlier_indices_i = EvaluateProjectionMatrix(Pi, points, projections, ransac_threshold, &error_i); const int num_inliers_i = static_cast<int>(inlier_indices_i.size()); if (num_inliers_i > max_inliers || (num_inliers_i == max_inliers && error_i < max_error)) { *P = Pi; max_error = error_i; max_inliers = num_inliers_i; } } } if (max_inliers < 6) { std::cerr << "[ComputeProjectionMatrixRansac] Error: Too few inliers to continue\n"; return -1; } return max_inliers; }