Exemple #1
0
        private static double CalculateSingleEdgeLowerBound(
            ShapeModel model, ShapeConstraints shapeConstraints, IList <ILengthAngleConstraints> lengthAngleConstraints)
        {
            // TODO: support models with multiple edges but without pairwise constraints
            Debug.Assert(model.Structure.Edges.Count == 1);
            Debug.Assert(lengthAngleConstraints.Count == 1);

            double result;

            // Calculate best possible edge width penalty
            EdgeConstraints edgeConstraints   = shapeConstraints.EdgeConstraints[0];
            ShapeEdgeParams edgeParams        = model.GetEdgeParams(0);
            Range           lengthBoundary    = lengthAngleConstraints[0].LengthBoundary;
            Range           scaledLengthRange = new Range(lengthBoundary.Left * edgeParams.WidthToEdgeLengthRatio, lengthBoundary.Right * edgeParams.WidthToEdgeLengthRatio);
            Range           widthRange        = new Range(edgeConstraints.MinWidth, edgeConstraints.MaxWidth);

            if (scaledLengthRange.IntersectsWith(widthRange))
            {
                result = 0;
            }
            else
            {
                result = model.CalculateEdgeWidthEnergyTerm(0, widthRange.Right, lengthBoundary.Left);
                result = Math.Min(result, model.CalculateEdgeWidthEnergyTerm(0, widthRange.Left, lengthBoundary.Right));
            }

            return(result);
        }
Exemple #2
0
        private static double CalculateMinUnaryEdgeEnergy(int edgeIndex, ShapeModel model, ShapeConstraints shapeConstraints, double edgeLength)
        {
            double          bestWidth       = edgeLength * model.GetEdgeParams(edgeIndex).WidthToEdgeLengthRatio;
            EdgeConstraints edgeConstraints = shapeConstraints.EdgeConstraints[edgeIndex];

            bestWidth = MathHelper.Trunc(bestWidth, edgeConstraints.MinWidth, edgeConstraints.MaxWidth);
            return(model.CalculateEdgeWidthEnergyTerm(edgeIndex, bestWidth, edgeLength));
        }
        private static double CalculateSingleEdgeLowerBound(
            ShapeModel model, ShapeConstraints shapeConstraints, IList<ILengthAngleConstraints> lengthAngleConstraints)
        {
            // TODO: support models with multiple edges but without pairwise constraints
            Debug.Assert(model.Structure.Edges.Count == 1);
            Debug.Assert(lengthAngleConstraints.Count == 1);

            double result;

            // Calculate best possible edge width penalty
            EdgeConstraints edgeConstraints = shapeConstraints.EdgeConstraints[0];
            ShapeEdgeParams edgeParams = model.GetEdgeParams(0);
            Range lengthBoundary = lengthAngleConstraints[0].LengthBoundary;
            Range scaledLengthRange = new Range(lengthBoundary.Left * edgeParams.WidthToEdgeLengthRatio, lengthBoundary.Right * edgeParams.WidthToEdgeLengthRatio);
            Range widthRange = new Range(edgeConstraints.MinWidth, edgeConstraints.MaxWidth);
            if (scaledLengthRange.IntersectsWith(widthRange))
                result = 0;
            else
            {
                result = model.CalculateEdgeWidthEnergyTerm(0, widthRange.Right, lengthBoundary.Left);
                result = Math.Min(result, model.CalculateEdgeWidthEnergyTerm(0, widthRange.Left, lengthBoundary.Right));
            }

            return result;
        }
 private static double CalculateMinUnaryEdgeEnergy(int edgeIndex, ShapeModel model, ShapeConstraints shapeConstraints, double edgeLength)
 {
     double bestWidth = edgeLength * model.GetEdgeParams(edgeIndex).WidthToEdgeLengthRatio;
     EdgeConstraints edgeConstraints = shapeConstraints.EdgeConstraints[edgeIndex];
     bestWidth = MathHelper.Trunc(bestWidth, edgeConstraints.MinWidth, edgeConstraints.MaxWidth);
     return model.CalculateEdgeWidthEnergyTerm(edgeIndex, bestWidth, edgeLength);
 }