Exemple #1
0
        //touch_restriction       :  'touch' 'your'? body_part 'with' 'your'? side 'hand';
        public override Wrapper VisitTouch_restriction(PreposeGesturesParser.Touch_restrictionContext context)
        {
            var joint = (JointGroup)this.Visit(context.body_part());
            var side  = (JointSide)this.Visit(context.side());

            CompositeBodyRestriction restriction = joint.Aggregate(j => new TouchBodyRestriction(j, side, 0.2, dont));

            return(new Wrapper(restriction));
        }
Exemple #2
0
        public override Wrapper VisitPose(PreposeGesturesParser.PoseContext context)
        {
            var bt = new CompositeBodyTransform();
            var br = new CompositeBodyRestriction();
            var ds = new CompositeDelayedStatement();

            foreach (var s in context.statement())
            {
                Contract.Assert(s != null);
                var w = this.Visit(s);
                Contract.Assert(w != null);
                var statement = w.GetValue();
                if (statement != null)
                {
                    if (statement is CompositeBodyTransform)
                    {
                        bt = bt.Compose((CompositeBodyTransform)statement);
                        continue;
                    }

                    if (statement is CompositeBodyRestriction)
                    {
                        br = br.And((CompositeBodyRestriction)statement);
                        continue;
                    }

                    if (statement is CompositeDelayedStatement)
                    {
                        ds = ds.Compose((CompositeDelayedStatement)statement);
                        continue;
                    }

                    throw new ArgumentException("Wrong return type");
                }
            }

            var pose = new Pose(context.ID().GetText(), bt, br, ds);

            if (this.Poses.ContainsKey(pose.Name))
            {
                throw new ArgumentException("Pose " + pose.Name + " has been previosly seen.");
            }

            this.Poses.Add(pose.Name, pose);

            return(new Wrapper(pose));
        }
Exemple #3
0
        //align your body_part and your body_part;
        public override Wrapper VisitAlign_restriction(PreposeGesturesParser.Align_restrictionContext context)
        {
            var target = (JointGroup)this.Visit(context.body_part()[context.body_part().Count - 1]);

            CompositeBodyRestriction restriction = new CompositeBodyRestriction();

            for (int i = 0; i < context.body_part().Count - 1; ++i)
            {
                var joint = (JointGroup)this.Visit(context.body_part()[i]);

                restriction = restriction.And(
                    target.Aggregate(j2 =>
                                     joint.Aggregate(j1 => new AlignBodyRestriction(j1, j2, 20, dont))));
            }

            return(new Wrapper(restriction));
        }
Exemple #4
0
        // TODO test this logic to aggergate restrictions
        //put_restriction :  'put' 'your'? body_part relative_direction body_part;
        public override Wrapper VisitPut_restriction(PreposeGesturesParser.Put_restrictionContext context)
        {
            var target = (JointGroup)this.Visit(context.body_part()[context.body_part().Count - 1]);

            var direction = (RelativeDirection)this.Visit(context.relative_direction());

            CompositeBodyRestriction restriction = new CompositeBodyRestriction();

            for (int i = 0; i < context.body_part().Count - 1; ++i)
            {
                var joint = (JointGroup)this.Visit(context.body_part()[i]);

                restriction = restriction.And(
                    target.Aggregate(j2 =>
                                     joint.Aggregate(j1 => new PutBodyRestriction(j1, j2, direction, dont))));
            }

            return(new Wrapper(restriction));
        }
Exemple #5
0
        public override Wrapper VisitPose(PreposeGesturesParser.PoseContext context)
        {
            var bt = new BodyTransform();
            var br = new CompositeBodyRestriction();

            foreach (var s in context.statement())
            {
                Contract.Assert(s != null);
                var w = this.Visit(s);
                if (w == null)
                {
                    throw new PreposeParserException("Failed to parse statement", s);
                }
                var statement = w.GetValue();
                if (statement != null)
                {
                    if (statement is BodyTransform)
                    {
                        bt = bt.Compose((BodyTransform)statement);
                        continue;
                    }

                    if (statement is CompositeBodyRestriction)
                    {
                        br = br.And((CompositeBodyRestriction)statement);
                        continue;
                    }

                    throw new PreposeParserException("Invalid return type", s);
                }
            }

            var pose = new Pose(context.ID().GetText(), bt, br);

            if (this.Poses.ContainsKey(pose.Name))
            {
                throw new PreposeParserException("Pose " + pose.Name + " has been previously seen.", context);
            }

            this.Poses.Add(pose.Name, pose);

            return(new Wrapper(pose));
        }