private Tuple <Term, Term[]> IncorporateRadiusConstraint(TSnapped snappedPrimitive, Tuple <Term, Term[]> result) { if (snappedPrimitive.LeftSilhouette != null && snappedPrimitive.RightSilhouette != null) { var sil0 = SegmentApproximator.ApproximateSegment(snappedPrimitive.LeftSilhouette.Points); var sil1 = SegmentApproximator.ApproximateSegment(snappedPrimitive.RightSilhouette.Points); var axis2d = Get2DVector(snappedPrimitive.AxisResult); var sil0Top = GetForwardPoint(sil0, axis2d); var sil0Bot = GetForwardPoint(sil0, -axis2d); var sil1Top = GetForwardPoint(sil1, axis2d); var sil1Bot = GetForwardPoint(sil1, -axis2d); var expectedTop = 0.5 * Math.Min( sil0Top.DistanceFromSegment(sil1.Item1, sil1.Item2), sil1Top.DistanceFromSegment(sil0.Item1, sil0.Item2)); var expectedBottom = 0.5 * Math.Min( sil0Bot.DistanceFromSegment(sil1.Item1, sil1.Item2), sil1Bot.DistanceFromSegment(sil0.Item1, sil0.Item2)); var radiusTerm = GetRadiusSoftConstraint(snappedPrimitive, expectedTop, expectedBottom); var newTargetFunc = 0.95 * radiusTerm + 0.05 * result.Item1; return(Tuple.Create(newTargetFunc, result.Item2)); } else { return(result); } }
private Tuple <Term, Term[]> TwoSilhouettesNoFeatures(TSnapped snappedPrimitive, ISet <FeatureCurve> annotated) { var sil0 = SegmentApproximator.ApproximateSegment(snappedPrimitive.LeftSilhouette.Points); var sil1 = SegmentApproximator.ApproximateSegment(snappedPrimitive.RightSilhouette.Points); var axis2d = Get2DVector(snappedPrimitive.AxisResult); var sil0Top = GetForwardPoint(sil0, axis2d); var sil0Bot = GetForwardPoint(sil0, -axis2d); var sil1Top = GetForwardPoint(sil1, axis2d); var sil1Bot = GetForwardPoint(sil1, -axis2d); var topFit = ProjectionFit.Compute( snappedPrimitive.TopFeatureCurve, new Point[] { sil0Top, sil1Top }); var botFit = ProjectionFit.Compute( snappedPrimitive.BottomFeatureCurve, new Point[] { sil0Bot, sil1Bot }); if (annotated.Contains(snappedPrimitive.TopFeatureCurve)) { topFit = Enumerable.Empty <Term>(); } if (annotated.Contains(snappedPrimitive.BottomFeatureCurve)) { botFit = Enumerable.Empty <Term>(); } var objective = TermUtils.SafeSum(topFit.Concat(botFit)); var constraints = new Term[] { snappedPrimitive.Axis.NormSquared - 1 }; return(Tuple.Create(objective, constraints)); }
private Tuple <Term, Term[]> TwoSilhouettesSingleFeature(TSnapped snappedPrimitive, ISet <FeatureCurve> annotated) { var sil0 = SegmentApproximator.ApproximateSegment(snappedPrimitive.LeftSilhouette.Points); var sil1 = SegmentApproximator.ApproximateSegment(snappedPrimitive.RightSilhouette.Points); var axis2d = Get2DVector(snappedPrimitive.AxisResult); var isTopSnapped = snappedPrimitive.TopFeatureCurve.SnappedTo != null; var isBottomSnapped = snappedPrimitive.BottomFeatureCurve.SnappedTo != null; var snappedFeatureCurve = isTopSnapped ? snappedPrimitive.TopFeatureCurve : snappedPrimitive.BottomFeatureCurve; var unsnappedFeatureCurve = isTopSnapped ? snappedPrimitive.BottomFeatureCurve : snappedPrimitive.TopFeatureCurve; var sil0Top = GetForwardPoint(sil0, axis2d); var sil0Bot = GetForwardPoint(sil0, -axis2d); var sil1Top = GetForwardPoint(sil1, axis2d); var sil1Bot = GetForwardPoint(sil1, -axis2d); var sil0Far = isTopSnapped ? sil0Bot : sil0Top; var sil1Far = isTopSnapped ? sil1Bot : sil1Top; var featureProj = ProjectionFit.Compute(snappedFeatureCurve); var farProj = Enumerable.Repeat(EndpointsProjectionFit(unsnappedFeatureCurve, sil0Far, sil1Far), 1); var objective = TermUtils.SafeSum(new Term[] { TermUtils.SafeAvg(featureProj), TermUtils.SafeAvg(farProj) }); var constraints = new Term[] { snappedPrimitive.Axis.NormSquared - 1 }; return(Tuple.Create(objective, constraints)); }
private Tuple <Term, Term[]> TwoSilhouettesSingleFeature(TSnapped snappedPrimitive, ISet <FeatureCurve> annotated) { var sil0 = SegmentApproximator.ApproximateSegment(snappedPrimitive.LeftSilhouette.Points); var sil1 = SegmentApproximator.ApproximateSegment(snappedPrimitive.RightSilhouette.Points); var snappedFeatureCurve = snappedPrimitive.TopCurve == null ? snappedPrimitive.BottomFeatureCurve : snappedPrimitive.TopFeatureCurve; var unsnappedFeatureCurve = snappedPrimitive.TopCurve == null ? snappedPrimitive.TopFeatureCurve : snappedPrimitive.BottomFeatureCurve; var sil0Far = GetFarPoint(sil0, snappedFeatureCurve.SnappedTo); var sil1Far = GetFarPoint(sil1, snappedFeatureCurve.SnappedTo); var featureProj = ProjectionFit(snappedFeatureCurve); var farProj = ProjectionFit(unsnappedFeatureCurve, new Point[] { sil0Far, sil1Far }); if (annotated.Contains(unsnappedFeatureCurve)) { farProj = Enumerable.Empty <Term>(); } var objective = TermUtils.SafeSum(featureProj.Concat(farProj)); var constraints = new Term[] { snappedPrimitive.Axis.NormSquared - 1 }; return(Tuple.Create(objective, constraints)); }