コード例 #1
0
        private static void MovePointHandleByRotationSteps(GenericPosture posture, CalibrationHelper calibrationHelper, int handle, PointF point, GenericPostureConstraintRotationSteps constraint)
        {
            if (constraint == null)
            {
                return;
            }

            PointF parent = posture.Points[constraint.Origin];
            PointF leg1   = posture.Points[constraint.Leg1];

            if (parent == leg1 || constraint.Step == 0)
            {
                return;
            }

            int constraintAngleSubdivisions = 360 / constraint.Step;

            posture.Points[posture.Handles[handle].Reference] = GeometryHelper.GetPointAtClosestRotationStep(parent, leg1, point, constraintAngleSubdivisions);
        }
コード例 #2
0
        private static void MovePointHandleByRotationSteps(GenericPosture posture, CalibrationHelper calibrationHelper, int handle, PointF point, GenericPostureConstraintRotationSteps constraint)
        {
            if (constraint == null)
            {
                return;
            }

            PointF parent = posture.PointList[constraint.Origin];
            PointF leg1   = posture.PointList[constraint.Leg1];

            if (parent == leg1 || constraint.Step == 0)
            {
                return;
            }

            PointF candidate = point;

            if (constraint.KeepDistance)
            {
                PointF leg2     = posture.PointList[posture.Handles[handle].Reference];
                float  distance = GeometryHelper.GetDistance(parent, leg2);
                candidate = GeometryHelper.GetPointAtDistance(parent, point, distance);
            }

            int constraintAngleSubdivisions = 360 / constraint.Step;

            posture.PointList[posture.Handles[handle].Reference] = GeometryHelper.GetPointAtClosestRotationStep(parent, leg1, candidate, constraintAngleSubdivisions);
        }
コード例 #3
0
        private void ParseConstraint(XmlReader r)
        {
            // A "constraint" represents the valid positions where the handle can go.
            bool           isEmpty     = r.IsEmptyElement;
            ConstraintType type        = ConstraintType.None;
            string         optionGroup = "";

            if (r.MoveToAttribute("type"))
            {
                type = (ConstraintType)Enum.Parse(typeof(ConstraintType), r.ReadContentAsString());
            }

            if (r.MoveToAttribute("optionGroup"))
            {
                optionGroup = r.ReadContentAsString();
            }

            r.ReadStartElement();

            switch (type)
            {
            case ConstraintType.None:
                Constraint = null;
                break;

            case ConstraintType.LineSlide:
                Constraint = new GenericPostureConstraintLineSlide(r);
                break;

            case ConstraintType.VerticalSlide:
                Constraint = new GenericPostureConstraintVerticalSlide();
                break;

            case ConstraintType.HorizontalSlide:
                Constraint = new GenericPostureConstraintHorizontalSlide();
                break;

            case ConstraintType.DistanceToPoint:
                Constraint = new GenericPostureConstraintDistanceToPoint(r);
                break;

            case ConstraintType.RotationSteps:
                Constraint = new GenericPostureConstraintRotationSteps(r);
                break;

            case ConstraintType.PerpendicularSlide:
                Constraint = new GenericPostureConstraintPerpendicularSlide(r);
                break;

            case ConstraintType.ParallelSlide:
                Constraint = new GenericPostureConstraintParallelSlide(r);
                break;

            case ConstraintType.LockedInPlace:
                Constraint = new GenericPostureConstraintLockedInPlace();
                break;

            default:
                string outerXml = r.ReadOuterXml();
                log.DebugFormat("Unparsed content: {0}", outerXml);
                break;
            }

            if (Constraint != null)
            {
                Constraint.Type = type;

                if (!string.IsNullOrEmpty(optionGroup))
                {
                    Constraint.OptionGroup = optionGroup;
                }
            }

            if (!isEmpty)
            {
                r.ReadEndElement();
            }
        }