Beispiel #1
0
        /// <summary>
        /// Apply specifed viewType to camera according to bounding box's size and position.
        /// <para>    +-------+    </para>
        /// <para>   /|      /|    </para>
        /// <para>  +-------+ |    </para>
        /// <para>  | |     | |    </para>
        /// <para>  | O-----|-+---X</para>
        /// <para>  |/      |/     </para>
        /// <para>  +-------+      </para>
        /// <para> /  |            </para>
        /// <para>Y   Z            </para>
        /// <para>其边长为(2 * Math.Sqrt(3)), 所在的坐标系如下</para>
        /// <para>   O---X</para>
        /// <para>  /|    </para>
        /// <para> Y |    </para>
        /// <para>   Z    </para>
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="boundingBox"></param>
        /// <param name="viewType"></param>
        public static void ApplyViewType(this IPerspectiveViewCamera camera, IBoundingBox boundingBox,
            ViewTypes viewType)
        {
            float sizeX, sizeY, sizeZ;
            boundingBox.GetBoundDimensions(out sizeX, out sizeY, out sizeZ);
            float size = Math.Max(Math.Max(sizeX, sizeY), sizeZ);

            {
                float centerX, centerY, centerZ;
                boundingBox.GetCenter(out centerX, out centerY, out centerZ);
                vec3 target = new vec3(centerX, centerY, centerZ);

                vec3 target2Position;
                vec3 upVector;
                GetBackAndUp(out target2Position, out upVector, viewType);

                vec3 position = target + target2Position * (size * 2 + 1);

                camera.Position = position;
                camera.Target = target;
                camera.UpVector = upVector;
            }

            {
                int[] viewport = new int[4];
                GL.GetInteger(GetTarget.Viewport, viewport);
                int width = viewport[2]; int height = viewport[3];

                IPerspectiveCamera perspectiveCamera = camera;
                perspectiveCamera.FieldOfView = 60;
                perspectiveCamera.AspectRatio = (double)width / (double)height;
                perspectiveCamera.Near = 0.01;
                perspectiveCamera.Far = size * 3 + 1;// double.MaxValue;
            }
        }
        public static ImageAnnotation AddAnnotation(string library, Bitmap image, IBoundingBox region, JObject data)
        {

            CouchDatabase db = GetDatabase(library);
            string imgid = AddImage(db, image);
            ImageAnnotation toAdd = new ImageAnnotation(region, data, imgid);

            if (HasDocument(db, toAdd.Id))
                throw new InvalidOperationException("There already exists an annotation for this image with this location. Retreive that annotation and update its data accordingly.");

            CouchDbAnnotation ca = new CouchDbAnnotation();

            ca.data = toAdd.Data;
            ca.top = toAdd.Region.Top;
            ca.left = toAdd.Region.Left;
            ca.width = toAdd.Region.Width;
            ca.height = toAdd.Region.Height;
            ca.screenshotId = toAdd.ImageId;
            ca.type = "annotation";
            Document<CouchDbAnnotation> document = new Document<CouchDbAnnotation>(ca);
            document.Id = toAdd.Id;
            db.CreateDocument(document);


            return toAdd;
        }
Beispiel #3
0
		public AnnotatedNode(Tree matchingNode, Tree root, JObject data, IBoundingBox region, string imageId){
			this.MatchingNode = matchingNode;
			this.Root = root;
			this.Data = data;
			this.Region = region;
			this.ImageId = imageId;
		}
 /// <summary>
 /// Copies the specified XNA rectangle to the Protogame bounding box.
 /// </summary>
 /// <param name="rectangle">
 /// The XNA rectangle to copy from.
 /// </param>
 /// <param name="boundingBox">
 /// The Protogame bounding box to copy to.
 /// </param>
 public static void CopyTo(this Rectangle rectangle, IBoundingBox boundingBox)
 {
     boundingBox.X = rectangle.X;
     boundingBox.Y = rectangle.Y;
     boundingBox.Width = rectangle.Width;
     boundingBox.Height = rectangle.Height;
 }
 /// <summary>
 /// Copies the specified XNA rectangle to the Protogame bounding box.
 /// </summary>
 /// <param name="rectangle">
 /// The XNA rectangle to copy from.
 /// </param>
 /// <param name="boundingBox">
 /// The Protogame bounding box to copy to.
 /// </param>
 public static void CopyTo(this Rectangle rectangle, IBoundingBox boundingBox)
 {
     boundingBox.Transform.LocalPosition *= 
         new Vector3(rectangle.X, rectangle.Y, 0) - boundingBox.Transform.LocalPosition;
     boundingBox.Width = rectangle.Width;
     boundingBox.Height = rectangle.Height;
 }
Beispiel #6
0
		public ImageAnnotation (IBoundingBox region, JObject data, string imgid)
		{
			Region = region;
			Data = data;
			ImageId = imgid;

		}
        /// <summary>
        /// expand this boudning box's positions to wrap another one.
        /// </summary>
        /// <param name="boundingBox"></param>
        /// <param name="another"></param>
        public static BoundingBox Union(this IBoundingBox boundingBox, IBoundingBox another)
        {
            vec3 min = Min(boundingBox.MinPosition, another.MinPosition);
            vec3 max = Max(boundingBox.MaxPosition, another.MaxPosition);

            return new BoundingBox(min, max);
        }
Beispiel #8
0
        ///// <summary>
        ///// Adjusts camera's settings according to bounding box.
        ///// <para>Use this when bounding box's size or positon is changed.</para>
        ///// </summary>
        ///// <param name="camera"></param>
        ///// <param name="boundingBox"></param>
        //public static void ZoomCamera(this IScientificCamera camera, IBoundingBox boundingBox)
        //{
        //    float sizeX, sizeY, sizeZ;
        //    boundingBox.GetBoundDimensions(out sizeX, out sizeY, out sizeZ);
        //    float size = Math.Max(Math.Max(sizeX, sizeY), sizeZ);

        //    {
        //        float centerX, centerY, centerZ;
        //        boundingBox.GetCenter(out centerX, out centerY, out centerZ);
        //        vec3 target = new vec3(centerX, centerY, centerZ);

        //        vec3 target2Position = camera.Position - camera.Target;
        //        target2Position.Normalize();

        //        vec3 position = target + target2Position * (size * 2 + 1);

        //        camera.Position = position;
        //        camera.Target = target;
        //        //camera.UpVector = new vec3(0f, 1f, 0f);
        //    }

        //    {
        //        int[] viewport = new int[4];
        //        GL.GetInteger(GetTarget.Viewport, viewport);
        //        int width = viewport[2]; int height = viewport[3];

        //        IPerspectiveViewCamera perspectiveViewCamera = camera;
        //        perspectiveViewCamera.FieldOfView = 60;
        //        perspectiveViewCamera.AspectRatio = (double)width / (double)height;
        //        perspectiveViewCamera.Near = 0.01;
        //        perspectiveViewCamera.Far = size * 3 + 1;// double.MaxValue;
        //    }
        //    {
        //        int[] viewport = new int[4];
        //        GL.GetInteger(GetTarget.Viewport, viewport);
        //        int width = viewport[2]; int height = viewport[3];

        //        IOrthoViewCamera orthoViewCamera = camera;
        //        if (width > height)
        //        {
        //            orthoViewCamera.Left = -size * width / height;
        //            orthoViewCamera.Right = size * width / height;
        //            orthoViewCamera.Bottom = -size;
        //            orthoViewCamera.Top = size;
        //        }
        //        else
        //        {
        //            orthoViewCamera.Left = -size;
        //            orthoViewCamera.Right = size;
        //            orthoViewCamera.Bottom = -size * height / width;
        //            orthoViewCamera.Top = size * height / width;
        //        }
        //        orthoViewCamera.Near = 0;
        //        orthoViewCamera.Far = size * 3 + 1;// double.MaxValue;
        //    }
        //}

        /// <summary>
        /// Adjusts camera's settings according to bounding box.
        /// <para>Use this when bounding box's size or positon is changed.</para>
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="boundingBox"></param>
        public static void ZoomCamera(this IPerspectiveViewCamera camera, IBoundingBox boundingBox)
        {
            float sizeX, sizeY, sizeZ;
            boundingBox.GetBoundDimensions(out sizeX, out sizeY, out sizeZ);
            float size = Math.Max(Math.Max(sizeX, sizeY), sizeZ);

            {
                float centerX, centerY, centerZ;
                boundingBox.GetCenter(out centerX, out centerY, out centerZ);
                vec3 target = new vec3(centerX, centerY, centerZ);

                vec3 target2Position = camera.Position - camera.Target;
                target2Position.Normalize();

                vec3 position = target + target2Position * (size * 2 + 1);

                camera.Position = position;
                camera.Target = target;
                //camera.UpVector = new vec3(0f, 1f, 0f);
            }

            {
                int[] viewport = new int[4];
                GL.GetInteger(GetTarget.Viewport, viewport);
                int width = viewport[2]; int height = viewport[3];

                camera.FieldOfView = 60;
                camera.AspectRatio = (double)width / (double)height;
                camera.Near = 0.01;
                camera.Far = size * 3 + 1;// double.MaxValue;
            }
        }
Beispiel #9
0
        public static MutableTree from_bounding_box(IBoundingBox box, PythonDictionary dict)
        {
            var csharpDict = new Dictionary<string, object>();
            foreach (string key in dict.Keys)
            {
                csharpDict[key] = dict[key];
            }

            return MutableTree.FromBoundingBox(box, csharpDict);
        }
Beispiel #10
0
        public static void TestObstacle(Point start, Point end, int steps, IEnumerable<LineD> obstacles, IBoundingBox bb)
        {
            var result = Solver.Solver.DoIt(new Description(new Car(start), end, obstacles.ToList(), bb, steps));

            var shouldBeEnd = result.Solution.Aggregate(new Car(start), (car, acc) => car.Iterate(acc.Direction));

            shouldBeEnd.Position.Should().Be(end);
            shouldBeEnd.Speed.Should().Be(Point.Zero);

            Console.WriteLine("Druchläufe " + result.Loops);
        }
Beispiel #11
0
		public static Tree FromBoundingBox(IBoundingBox bb, Dictionary<string,object> tags){
			Tree tree = new Tree();
			tree.Occurrence = bb;

			if(tags != null)
				tree._tags = new Dictionary<string, object>(tags);
			else
				tree._tags = new Dictionary<string, object>();

			tree._children = new List<Tree>();

			return tree;
		}
        public void RenderWireframeCube(
            IRenderContext renderContext,
            IBoundingBox boundingBox,
            Color? color = null)
        {
            if (color == null) color = Color.White;
            var vertexes = new[]
            {
                new VertexPositionColor(new Vector3(0, 0, 0), color.Value),
                new VertexPositionColor(new Vector3(0, 0, 1), color.Value),
                new VertexPositionColor(new Vector3(0, 1, 0), color.Value),
                new VertexPositionColor(new Vector3(0, 1, 1), color.Value),
                new VertexPositionColor(new Vector3(1, 0, 0), color.Value),
                new VertexPositionColor(new Vector3(1, 0, 1), color.Value),
                new VertexPositionColor(new Vector3(1, 1, 0), color.Value),
                new VertexPositionColor(new Vector3(1, 1, 1), color.Value)
            };

            var indicies = new short[]
            {
                0, 1, 0, 2, 1, 3, 2, 3,
                4, 5, 4, 6, 5, 7, 6, 7,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            renderContext.EnableVertexColors();
            var world = renderContext.World;
            var xnaBoundingBox = boundingBox.ToXna();
            renderContext.World =
                Matrix.CreateScale(xnaBoundingBox.Max - xnaBoundingBox.Min) *
                Matrix.CreateTranslation(xnaBoundingBox.Min);

            foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                renderContext.GraphicsDevice.DrawUserIndexedPrimitives(
                    PrimitiveType.LineList,
                    vertexes,
                    0,
                    vertexes.Length,
                    indicies,
                    0,
                    vertexes.Length / 2);
            }

            renderContext.World = world;
        }
        public static ImageAnnotation GetAnnotation(string library, Bitmap image, IBoundingBox region)
        {

            CouchDatabase db = GetDatabase(library);
            string imgid = ImageAnnotation.GetImageId(image);
            ImageAnnotation ia = new ImageAnnotation(region, null, imgid);
            
            try
            {
                CouchDbAnnotation ca = db.GetDocument<CouchDbAnnotation>(ia.Id);
                return new ImageAnnotation(region, ca.data, imgid);
            }
            catch
            {
                return null;
            }
        }
Beispiel #14
0
        public static MutableTree FromBoundingBox(IBoundingBox bb, Dictionary<string, object> tags)
        {
            MutableTree tree = new MutableTree();
            tree.Top = bb.Top;
            tree.Left = bb.Left;
            tree.Width = bb.Width;
            tree.Height = bb.Height;

            if (tags != null)
                tree._tags = new Dictionary<string, object>(tags);
            else
                tree._tags = new Dictionary<string, object>();

            tree._children = new List<MutableTree>();

            return tree;
        }
Beispiel #15
0
        /// <summary>
        /// Adjusts camera's settings according to bounding box.
        /// <para>Use this when bounding box's size or positon is changed.</para>
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="boundingBox"></param>
        public static void ZoomCamera(this IPerspectiveViewCamera camera, IBoundingBox boundingBox)
        {
            vec3 length = boundingBox.MaxPosition - boundingBox.MinPosition;
            float size = Math.Max(Math.Max(length.x, length.y), length.z);

            {
                vec3 target = boundingBox.MaxPosition / 2 + boundingBox.MinPosition / 2;

                vec3 target2Position = (camera.Position - camera.Target).normalize();

                vec3 position = target + target2Position * (size * 2 + 1);

                camera.Position = position;
                camera.Target = target;
                //camera.UpVector = new vec3(0f, 1f, 0f);
            }
        }
Beispiel #16
0
        /// TODO:摄像机的perspective和ortho视角,是否应该同时变化?
        /// <summary>
        /// Zoom camera to fit in specified <paramref name="boundingBox"/>.
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="boundingBox"></param>
        public static void ZoomCamera(this ICamera camera, IBoundingBox boundingBox)
        {
            if (boundingBox == null || camera == null) { throw new ArgumentNullException(); }

            switch (camera.CameraType)
            {
                case CameraType.Perspecitive:
                    ((IPerspectiveViewCamera)camera).ZoomCamera(boundingBox);
                    break;

                case CameraType.Ortho:
                    ((IOrthoViewCamera)camera).ZoomCamera(boundingBox);
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
Beispiel #17
0
 public static bool Check(IBoundingBox a, IBoundingBox b)
 {
     float aX2 = a.X + a.Width;
     float aY2 = a.Y + a.Height;
     float bX2 = b.X + b.Width;
     float bY2 = b.Y + b.Height;
     if (a is IEntity)
     {
         aX2 += (a as IEntity).Origin.X;
         aY2 += (a as IEntity).Origin.Y;
     }
     if (b is IEntity)
     {
         bX2 += (b as IEntity).Origin.X;
         bY2 += (b as IEntity).Origin.Y;
     }
     return (a.X - Math.Abs(a.XSpeed) < bX2 + Math.Abs(b.XSpeed) && aX2 + Math.Abs(a.XSpeed) > b.X - Math.Abs(b.XSpeed) &&
         a.Y < bY2 && aY2 > b.Y);
 }
        public static PathGeometry GetBubbleCursorPathFigure(IBoundingBox closestOccurrence, double cursorleft, double cursortop)
        {
            if (closestOccurrence == null)
                return new PathGeometry();

            List<System.Windows.Point> pointlist = new List<System.Windows.Point>();

            System.Windows.Point p1 = new System.Windows.Point(closestOccurrence.Left, closestOccurrence.Top);
            System.Windows.Point p2 = new System.Windows.Point(closestOccurrence.Left + closestOccurrence.Width, closestOccurrence.Top);
            System.Windows.Point p3 = new System.Windows.Point(closestOccurrence.Left + closestOccurrence.Width, closestOccurrence.Top + closestOccurrence.Height);
            System.Windows.Point p4 = new System.Windows.Point(closestOccurrence.Left, closestOccurrence.Top + closestOccurrence.Height);

            pointlist.Add(p1);
            pointlist.Add(p2);
            pointlist.Add(p3);
            pointlist.Add(p4);

            PathGeometry path = new PathGeometry();
            PathSegmentCollection collection = BubbleCursorVisualizer.PointsAroundWidget(pointlist);

            //Box around widget
            PathFigure figure = new PathFigure();
            figure.StartPoint = p1;
            figure.Segments = collection;
            figure.IsClosed = false;
            path.Figures.Add(figure);
            //----------------

            //Tractor beam
            if (!BoundingBox.Contains(closestOccurrence, (int)cursorleft, (int)cursortop))
            {
                PathFigure tractorbeam = new PathFigure();
                tractorbeam.StartPoint = new System.Windows.Point(cursorleft, cursortop);
                tractorbeam.Segments = BubbleCursorVisualizer.PointsForTractorBeam(tractorbeam.StartPoint, pointlist);
                tractorbeam.IsClosed = true;
                path.Figures.Add(tractorbeam);
            }
            //------------------

            path.FillRule = FillRule.EvenOdd;

            return path;
        }
Beispiel #19
0
        /// <summary>
        /// Adjusts camera's settings according to bounding box.
        /// <para>Use this when bounding box's size or positon is changed.</para>
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="boundingBox"></param>
        public static void ZoomCamera(this IOrthoViewCamera camera, IBoundingBox boundingBox)
        {
            vec3 length = boundingBox.MaxPosition - boundingBox.MinPosition;
            float size = Math.Max(Math.Max(length.x, length.y), length.z);

            {
                vec3 target = boundingBox.MaxPosition / 2 + boundingBox.MinPosition / 2;

                vec3 target2Position = (camera.Position - camera.Target).normalize();

                vec3 position = target + target2Position * (size * 2 + 1);

                camera.Position = position;
                camera.Target = target;
                //camera.UpVector = new vec3(0f, 1f, 0f);
            }

            {
                int[] viewport = new int[4];
                OpenGL.GetInteger(GetTarget.Viewport, viewport);
                int width = viewport[2]; int height = viewport[3];

                if (width > height)
                {
                    camera.Left = -size * width / height;
                    camera.Right = size * width / height;
                    camera.Bottom = -size;
                    camera.Top = size;
                }
                else
                {
                    camera.Left = -size;
                    camera.Right = size;
                    camera.Bottom = -size * height / width;
                    camera.Top = size * height / width;
                }
                camera.Near = 0;
                camera.Far = size * 3 + 1;// double.MaxValue;
            }
        }
 /// <summary>
 /// The apply action until.
 /// </summary>
 /// <param name="entity">
 /// The entity.
 /// </param>
 /// <param name="action">
 /// The action.
 /// </param>
 /// <param name="check">
 /// The check.
 /// </param>
 /// <param name="maximum">
 /// The maximum.
 /// </param>
 public void ApplyActionUntil(
     IBoundingBox entity, 
     Action<IBoundingBox> action, 
     Func<IBoundingBox, bool> check, 
     int? maximum)
 {
     if (maximum == null)
     {
         while (!check(entity))
         {
             action(entity);
         }
     }
     else
     {
         for (var i = 0; i < maximum.Value; i++)
         {
             if (!check(entity))
             {
                 action(entity);
             }
         }
     }
 }
Beispiel #21
0
 public static string GetAnnotationId(Bitmap image, IBoundingBox region)
 {
     string imgid = GetImageId(image);
     return GetAnnotationId(imgid, region);
 }
			public Example(IBoundingBox region, bool isPositive, string imageId){
				this.Region = region;
				this.IsPositive = isPositive;
				this.ImageId = imageId;
			}
 /// <summary>
 /// Finds out if this bounding box intersects with bB and saves the estimated hitPoint in hitPoint
 /// </summary>
 /// <param name="bB">Bounding box to check intersection</param>
 /// <param name="hitPoint">the point where bB and this bounding box intersected the first time</param>
 /// <param name="velocity">Speed of the object intersecting</param>
 /// <returns>true if intersection</returns>
 public abstract bool Intersect(IBoundingBox bB, out Vector hitPoint, Vector velocity);
 /// <summary>
 /// Finds out if this bounding box intersects with bB and saves the estimated hitPoint in hitPoint
 /// </summary>
 /// <param name="bB">Bounding box to check intersection</param>
 /// <param name="hitPoint">the point where bB and this bounding box intersected the first time</param>
 /// <returns>true if intersection</returns>
 public abstract bool Intersect(IBoundingBox bB, out Vector hitPoint);
 public Tree create_node(IBoundingBox bb, PythonDictionary tags)
 {
     return create_node(bb.Left, bb.Top, bb.Width, bb.Height, tags);
 }
Beispiel #26
0
 private static int CompareByHeightBiggerFirst(IBoundingBox a, IBoundingBox b)
 {
     return b.Height - a.Height;
 }
Beispiel #27
0
 public void Add(IBoundingBox box)
 {
     Group.Add(box);
     Boundary = BoundingBox.Union(box, Boundary);
 }
Beispiel #28
0
 public GroupedText(IBoundingBox first)
 {
     Group = new List<IBoundingBox>();
     Boundary = first;
     Group.Add(Boundary);
 }
Beispiel #29
0
        private static GroupedText GetClosest(IBoundingBox txt, List<GroupedText> groups)
        {
            double mindist = double.MaxValue;
            GroupedText closest = null;

            foreach (GroupedText set in groups)
            {
                double xdist = 0;
                double ydist = 0;
                double dist = 0;

                if (!BoundingBox.IsAlignedVertically(txt, set.Boundary))
                {
                    if (txt.Left < set.Boundary.Left)
                        xdist = set.Boundary.Left - (txt.Left + txt.Width);
                    else
                        xdist = txt.Left - (set.Boundary.Left + set.Boundary.Width);
                }
                if (!BoundingBox.IsAlignedHorizontally(txt, set.Boundary))
                {
                    if (txt.Top < set.Boundary.Top)
                        ydist = set.Boundary.Top - (txt.Top + txt.Height);
                    else
                        ydist = txt.Top - (set.Boundary.Top + set.Boundary.Height);
                }

                dist = Math.Sqrt(xdist * xdist + ydist * ydist);

                if(dist < mindist)
                {
                    mindist = dist;
                    closest = set;
                }
            }

            return closest;
        }
Beispiel #30
0
 private static int CompareByRight(IBoundingBox a, IBoundingBox b)
 {
     return (a.Left + a.Width) - (b.Left + b.Width);
 }