Example #1
0
        public CameraSpacePoint GetCamSpacePointFromMousePoint(Point mousePt, SpaceMode spMode)
        {
            CameraSpacePoint camPtFromMousePt = default(CameraSpacePoint);

            if (!IsSnapshotTaken)
            {
                return(camPtFromMousePt);
            }

            try
            {
                Tuple <float, float> dimensions = KinectExtensions.FrameDimensions[spMode];
                float x_temp = (float)(mousePt.X * dimensions.Item1 / wCanvas.ActualWidth);
                float y_temp = (float)(mousePt.Y * dimensions.Item2 / wCanvas.ActualHeight);

                DepthSpacePoint depPtFromMousePt = dCoordinatesInColorFrame[(int)(x_temp + 0.5f) + (int)(y_temp + 0.5f) * (int)dimensions.Item1];

                if (depPtFromMousePt.X == float.NegativeInfinity || depPtFromMousePt.Y == float.NegativeInfinity)
                {
                    return(default(CameraSpacePoint));
                }

                ushort depth = wallDepthData[(int)depPtFromMousePt.X + (int)(depPtFromMousePt.Y) * (int)KinectExtensions.FrameDimensions[SpaceMode.Depth].Item1];
                camPtFromMousePt = wallMapper.MapDepthPointToCameraSpace(depPtFromMousePt, depth);
            }
            catch (Exception ex)
            {
            }

            return(camPtFromMousePt);
        }
Example #2
0
 public AttributeForm2(IFeatureClass FeatureClass, IGeometry geometry, SpaceMode mode,string Title,DataType dataType,IFeatureClass FeatureClass2=null,IFeature Feature=null)
 {
     InitializeComponent();
     this.FeatureClass = FeatureClass;
     this.geometry = geometry;
     this.Mode = mode;
     this.Title = Title;
     this.dataType = dataType;
     this.FeatureClass2 = FeatureClass2;
     this.Feature = Feature;
 }
Example #3
0
        public static DataTable GetTable(IFeatureClass featureClass, string Filter,out Dictionary<int,IFeature> FeatureDict,IGeometry geometry=null,SpaceMode mode=SpaceMode.Intersect)
        {
            ReadFieldIndexDict(featureClass,"序号");
            Tranlate(featureClass.AliasName.GetAlongName());
            DataTable dataTable = new DataTable();
            string temp = string.Empty;
            foreach (var key in IndexDict.Keys)
            {
                if (FieldDict.ContainsKey(key))
                {
                    temp = FieldDict[key];
                }
                else
                {
                    temp = key;
                }
                dataTable.Columns.Add(temp);
            }
            List<IFeature> FeatureList = null;
            if (geometry == null)
            {
                FeatureList = GISHelper.Search(featureClass, Filter);
            }
            else
            {
                FeatureList = GISHelper.Search(featureClass, geometry, mode);
            }

            DataRow dataRow = null;
            int Serial = 0;
            FeatureDict = new Dictionary<int, IFeature>();
            foreach (var feature in FeatureList)
            {
                FeatureDict.Add(Serial, feature);
                dataRow = dataTable.NewRow();
                string val = string.Empty;
                foreach (var key in IndexDict.Keys)
                {
                    val = feature.get_Value(IndexDict[key]).ToString();
                    if (FieldDict.ContainsKey(key))
                    {
                        dataRow[FieldDict[key]] = val;
                    }
                    else
                    {
                        dataRow[key] = val;
                    }
                }
                dataRow["序号"] = ++Serial;
                dataTable.Rows.Add(dataRow);
            }
            return dataTable;
        }
Example #4
0
 public SpacePointBase(float x, float y, SpaceMode mode)
 {
     X          = x;
     Y          = y;
     _pointType = mode;
     if (x == float.NegativeInfinity && y == float.NegativeInfinity)
     {
         IsValid = false;
     }
     else
     {
         IsValid = true;
     }
 }
        private CameraSpacePoint GetCamSpacePtFromMouseClick(Point mousePt, SpaceMode spMode)
        {
            Tuple <float, float> dimensions = KinectExtensions.FrameDimensions[spMode];
            float x_temp = (float)(mousePt.X * dimensions.Item1 / canvas.ActualWidth);
            float y_temp = (float)(mousePt.Y * dimensions.Item2 / canvas.ActualHeight);

            DepthSpacePoint depPtFromMousePt = colorMappedToDepthSpace[(int)(x_temp + 0.5f) + (int)(y_temp + 0.5f) * (int)dimensions.Item1];

            if (depPtFromMousePt.X == float.NegativeInfinity || depPtFromMousePt.Y == float.NegativeInfinity)
            {
                return(default(CameraSpacePoint));
            }

            ushort depth = kinectDepthData[(int)depPtFromMousePt.X + (int)(depPtFromMousePt.Y) * (int)KinectExtensions.FrameDimensions[SpaceMode.Depth].Item1];

            return(kinectManagerClient.kinectSensor.CoordinateMapper.MapDepthPointToCameraSpace(depPtFromMousePt, depth));
        }
Example #6
0
        public static void DrawSkeleton(this Canvas canvas, Body body, CoordinateMapper mapper, SpaceMode mode)
        {
            if (body == null)
            {
                return;
            }

            foreach (Joint joint in body.Joints.Values)
            {
                canvas.DrawPoint(joint, mapper, mode);
            }

            foreach (Tuple <JointType, JointType> standardJointLine in StandardJointLines)
            {
                canvas.DrawLine(body.Joints[standardJointLine.Item1], body.Joints[standardJointLine.Item2], mapper, mode);
            }
        }
Example #7
0
        public SpacePointBase ScaleTo(double width, double height, SpaceMode mode)
        {
            Tuple <float, float> dimensions = KinectExtensions.FrameDimensions[mode];

            return(ScaleTo(width, height, dimensions.Item1, dimensions.Item2));
        }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="Feature">点击选中的道路</param>
 /// <param name="mode">空间关系</param>
 /// <param name="FeatureLayer1">公交路线 要素图层</param>
 /// <param name="Title">表名</param>
 /// <param name="FeatureLayer2">路网要素图层</param>
 private void AnalyzeBase(IFeature Feature, SpaceMode mode, IFeatureLayer FeatureLayer1,string Title,IFeatureLayer FeatureLayer2)
 {
     SelectFeature(Feature.Shape, mode, FeatureLayer1);
     var result = new AttributeForm2(FeatureLayer1.FeatureClass, Feature.Shape, mode, Title, this.dataType,FeatureLayer2.FeatureClass,Feature);
     result.Show(this);
 }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        anime.SetFloat("speed", 0f);
        // Move
        #region Move
        if (Input.GetKey(KeyCode.W))
        {
            transform.localPosition += Const.moveSpeed * Time.deltaTime * transform.forward;
        }
        else if (Input.GetKey(KeyCode.S))
        {
            transform.localPosition += -1 * Const.moveSpeed * Time.deltaTime * transform.forward;
        }
        if (Input.GetKey(KeyCode.D))
        {
            transform.localPosition += Const.moveSpeed * Time.deltaTime * transform.right;
        }
        else if (Input.GetKey(KeyCode.A))
        {
            transform.localPosition += -1 * Const.moveSpeed * Time.deltaTime * transform.right;
        }
        anime.SetFloat("speed", rb.velocity.magnitude);
        if (transform.position.y < Const.mapOrigin.y)
        {
            transform.position = Ground.getPointOnGround(new Vector3(Const.mapSize.x / 2, 0, Const.mapSize.z / 2));
        }
        #endregion
        // Jump
        #region Jump
        if (Input.GetKey(KeyCode.Space))
        {
            if (clickEvent.modestate && Time.time - lastSpaceReleaseTime < 1)
            {
                Debug.Log("mode changed" + spaceMode.ToString());
                if (spaceMode == SpaceMode.Jump)
                {
                    spaceMode = SpaceMode.Flying;
                    transform.GetComponent <Rigidbody>().useGravity = false;
                }
                else if (spaceMode == SpaceMode.Flying)
                {
                    spaceMode = SpaceMode.Jump;
                    transform.GetComponent <Rigidbody>().useGravity = true;
                }
            }
            if (spaceMode == SpaceMode.Jump)
            {
                if (!is_jumping && Time.time - lastJumpTime > 0.5)
                {
                    //rb.AddForce(jumpForce * Time.deltaTime * Vector3.up, ForceMode.Impulse);
                    is_jumping   = true;
                    lastJumpTime = Time.time;
                    rb.AddForce(new Vector3(0, 7, 0), ForceMode.Impulse);
                    //transform.localPosition += jumpForce * Time.deltaTime * Vector3.up;
                }
            }
            else if (spaceMode == SpaceMode.Flying)
            {
                transform.localPosition += Const.moveSpeed * Time.deltaTime * transform.up;
            }
        }
        else
        {
            lastSpaceReleaseTime = Time.time;
        }

        if (Input.GetKey(KeyCode.LeftShift) && spaceMode == SpaceMode.Flying)
        {
            transform.localPosition -= Const.moveSpeed * Time.deltaTime * transform.up;
        }
        #endregion
        // Rotate
        #region Rotate
        Vector3 dis = Input.mousePosition - mouseInitial;
        transform.localEulerAngles = new Vector3(0, Const.rotateSpeed * dis.x, 0);
        Transform cam    = transform.Find("Main Camera");
        float     rotate = Mathf.Abs(-1 * Const.updownSpeed * dis.y) > 90 ? (dis.y > 0 ? -90 : 90) : -1 * Const.updownSpeed * dis.y;
        cam.transform.localEulerAngles = new Vector3(rotate, 0, 0);
        #endregion
        // Click
        #region MouseClick
        if (Input.GetMouseButton(0))
        {
            //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2));
            RaycastHit rch;
            if (Physics.Raycast(ray, out rch))
            {
                Const.GameItemID hitId = ItemMap.getItemsID(rch.transform.gameObject.name);
                //Debug.Log("Hit= "+ hitId.ToString());
                int instanceId = rch.transform.gameObject.GetInstanceID();
                // Cube
                if (ItemMap.isItem(hitId))
                {
                    if (!audio.isPlaying)
                    {
                        audio.Play(0);
                    }
                    int destroyLevel = live.isAlive(hitId, instanceId, Const.attackPower * Time.deltaTime);

                    /*if(destroyLevel == -1) {
                     *  Material breakM1 = (Material)Resources.Load(ItemMap.getTextureName(hitId));
                     *  preTran.GetComponent<Renderer>().material = breakM1;
                     * }*/
                    if (destroyLevel <= 0)
                    {
                        toolbox.pushItem(hitId);
                        Destroy(rch.transform.gameObject);
                    }
                    else
                    {
                        string     name    = "destroy/Materials/destroy_stage_" + (9 - destroyLevel);
                        Material[] breakM1 = new Material[2];
                        breakM1[0] = (Material)Resources.Load(ItemMap.getTextureName(hitId));
                        breakM1[1] = (Material)Resources.Load(name);
                        rch.transform.GetComponent <Renderer>().materials = breakM1;
                    }
                    //preTran = rch.transform;
                }
                // Creature
                else
                {
                    rch.transform.GetComponent <LiveManager>().attack(Const.attackPower);// * Time.deltaTime);
                    rch.transform.GetComponent <Rigidbody>().AddForce(ray.direction.normalized * 2000);
                }
            }
        }
        if (Input.GetMouseButton(1))
        {
            if (toolbox.isSelected() && Time.time - lastClickTime > 0.5)
            {
                Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2));
                RaycastHit rch;
                if (Physics.Raycast(ray, out rch))
                {
                    Vector3 target = rch.point + rch.normal / 2;
                    target.x = Mathf.Round(target.x);
                    target.y = Mathf.Round(target.y);
                    target.z = Mathf.Round(target.z);
                    ground.instantiateItem(toolbox.deleteSeletedItem(), target);
                }
                lastClickTime = Time.time;
            }
        }
        #endregion
    }
 public IEnumerable <Shape> DrawSkeletonInPlaygroundCanvas(Body body, CoordinateMapper coorMapper, SpaceMode spaceMode)
 {
     return(playgroundCanvas.DrawSkeleton(body, coorMapper, spaceMode));
 }
Example #11
0
 public static Shape DrawPoint(this Canvas canvas, Joint joint, CoordinateMapper mapper, SpaceMode mode)
 {
     return(DrawPoint(canvas, joint, mapper, mode, new SolidColorBrush(Colors.LightBlue)));
 }
Example #12
0
        public void SelectFeature(IGeometry geometry,SpaceMode mode,IFeatureLayer FeatureLayer)
        {
            ISpatialFilter spatialFilter = new SpatialFilterClass();
            spatialFilter.Geometry = geometry;
            switch (mode)
            {
                case SpaceMode.Contains:
                    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                    break;
                case SpaceMode.Crossed:
                    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                    break;
                case SpaceMode.Intersect:
                    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    break;
                case SpaceMode.Overlaps:
                    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelOverlaps;
                    break;
                case SpaceMode.Touches:
                    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelTouches;
                    break;
                case SpaceMode.Within:
                    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;
                    break;
            }

            short Opacity = 0;
            if (short.TryParse(System.Configuration.ConfigurationManager.AppSettings["OPACITY"], out Opacity))
            {
                ILayerEffects layerEffects = FeatureLayer as ILayerEffects;
                layerEffects.Transparency = Opacity;
            }
            IFeatureSelection featureSelection = FeatureLayer as IFeatureSelection;
            featureSelection.SelectFeatures((IQueryFilter)spatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);
            if (this.dataType == DataType.BusLine || this.dataType == DataType.BusStop)
            {
                featureSelection.SelectionColor = DisplayHelper.GetSelectRGBColor();
            }

            MapRefresh();
        }
Example #13
0
        ///<summary>
        ///canvas extension function, get frame streams upon receiving frame source
        /// </summary>
        public static void Reader_MultiSourceFrameArrived(this Canvas canvas, object sender, MultiSourceFrameArrivedEventArgs e, SpaceMode _mode, Image cameraIMG, IList <Body> _bodies, CoordinateMapper coMapper, bool _displayBody)
        {
            // Get a reference to the multi-frame
            var reference = e.FrameReference.AcquireFrame();

            // Open color frame
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (_mode == SpaceMode.Color)
                    {
                        //pass the frame bitmap to MainWindow <Image>
                        cameraIMG.Source = ToBitmap(frame);
                    }
                }
            }

            // Open depth frame
            using (var frame = reference.DepthFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    // Do something with the frame...
                    if (_mode == SpaceMode.Depth)
                    {
                        //pass the frame bitmap to MainWindow <Image>
                        //true ==> use reliable depth
                        cameraIMG.Source = ToBitmap(frame, true);
                    }
                }
            }

            // Open infrared frame
            using (var frame = reference.InfraredFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    // Do something with the frame...
                    if (_mode == SpaceMode.Infrared)
                    {
                        //pass the frame bitmap to MainWindow <Image>
                        //true ==> use reliable depth
                        cameraIMG.Source = ToBitmap(frame);
                    }
                }
            }

            // Open body frame and draw Skeleton
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    canvas.Children.Clear();

                    _bodies = new Body[frame.BodyFrameSource.BodyCount];

                    frame.GetAndRefreshBodyData(_bodies);

                    foreach (var body in _bodies)
                    {
                        //Do something with the body...
                        if (body != null)
                        {
                            if (body.IsTracked)
                            {
                                if (_displayBody)
                                {
                                    canvas.DrawSkeleton(body, coMapper, _mode);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #14
0
        public static Point MapCameraSpacePointToPointOnCanvas(this CoordinateMapper coorMap, CameraSpacePoint camSP, Canvas canvas, SpaceMode spaceMode)
        {
            ColorSpacePoint colorSP = coorMap.MapCameraPointToColorSpace(camSP);

            if (float.IsInfinity(colorSP.X) || float.IsInfinity(colorSP.Y))
            {
                throw new Exception("Error when calling MapCameraSpacePointToPointOnCanvas(): " + Environment.NewLine +
                                    "Resultant ColorSpacePoint at negative infinity.");
            }

            double normedColorSPX = colorSP.X / FrameDimensions[spaceMode].Item1;
            double normedColorSPY = colorSP.Y / FrameDimensions[spaceMode].Item2;

            return(new Point(normedColorSPX * canvas.ActualWidth, normedColorSPY * canvas.ActualHeight));
        }
Example #15
0
        ///<summary>
        ///canvas extension function, get frame streams upon receiving frame source
        /// </summary>
        public static void Reader_MultiSourceFrameArrived(this Canvas canvas, object sender, MultiSourceFrameArrivedEventArgs e, SpaceMode _mode, Image cameraIMG, IList <Body> _bodies, CoordinateMapper coMapper, bool _displayBody)
        {
            // Get a reference to the multi-frame
            var reference = e.FrameReference.AcquireFrame();

            // Open color frame
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (_mode == SpaceMode.Color)
                    {
                        int         width  = frame.FrameDescription.Width;
                        int         height = frame.FrameDescription.Height;
                        PixelFormat format = PixelFormats.Bgr32;

                        byte[] pixels = new byte[width * height * ((PixelFormats.Bgr32.BitsPerPixel + 7) / 8)];

                        if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
                        {
                            frame.CopyRawFrameDataToArray(pixels);
                        }
                        else
                        {
                            frame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Bgra);
                        }

                        int stride = width * format.BitsPerPixel / 8;

                        //pass the frame bitmap to MainWindow <Image>
                        cameraIMG.Source = BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);;
                    }
                }
            }

            // Open depth frame
            using (var frame = reference.DepthFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    // Do something with the frame...
                    if (_mode == SpaceMode.Depth)
                    {
                        int         width    = frame.FrameDescription.Width;
                        int         height   = frame.FrameDescription.Height;
                        PixelFormat format   = PixelFormats.Bgr32;
                        ushort      minDepth = 0;
                        ushort      maxDepth = ushort.MaxValue;
                        bool        reliable = true;

                        if (reliable)
                        {
                            //minDepth = frame.DepthMinReliableDistance;
                            minDepth = 2000; //frame.DepthMinReliableDistance;
                            maxDepth = 5000; //frame.DepthMaxReliableDistance;
                                             //Debug.WriteLine($"Use Reliable Depth: {minDepth}.min, {maxDepth}.max");
                        }

                        ushort[] depthData = new ushort[width * height];
                        byte[]   pixelData = new byte[width * height * (PixelFormats.Bgr32.BitsPerPixel + 7) / 8];

                        frame.CopyFrameDataToArray(depthData);

                        int colorIndex = 0;
                        for (int depthIndex = 0; depthIndex < depthData.Length; ++depthIndex)
                        {
                            ushort depth = depthData[depthIndex];
                            //byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? 255 - ((depth - minDepth) * 256 / (maxDepth - minDepth)) : 0);
                            ushort intensity = (ushort)(depth >= minDepth && depth <= maxDepth ? depth % 256 : 0);

                            //pixelData[colorIndex++] = intensity; // Blue
                            //pixelData[colorIndex++] = intensity; // Green
                            //pixelData[colorIndex++] = intensity; // Red

                            pixelData[colorIndex++] = (byte)(intensity <= 127 ? intensity * 2 : 255 - intensity * 2); // Blue
                            pixelData[colorIndex++] = (byte)(intensity <= 127 ? 255 - intensity * 2 : intensity * 2); // Green
                            pixelData[colorIndex++] = (byte)(intensity <= 127 ? 255 - intensity * 2 : intensity * 2); // Red



                            ++colorIndex;
                        }

                        int stride = width * format.BitsPerPixel / 8;

                        //pass the frame bitmap to MainWindow <Image>
                        //true ==> use reliable depth
                        cameraIMG.Source = BitmapSource.Create(width, height, 96, 96, format, null, pixelData, stride);
                    }
                }
            }

            // Open infrared frame
            using (var frame = reference.InfraredFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    // Do something with the frame...
                    if (_mode == SpaceMode.Infrared)
                    {
                        int         width  = frame.FrameDescription.Width;
                        int         height = frame.FrameDescription.Height;
                        PixelFormat format = PixelFormats.Bgr32;

                        ushort[] frameData = new ushort[width * height];
                        byte[]   pixels    = new byte[width * height * (format.BitsPerPixel + 7) / 8];

                        frame.CopyFrameDataToArray(frameData);

                        int colorIndex = 0;
                        for (int infraredIndex = 0; infraredIndex < frameData.Length; infraredIndex++)
                        {
                            ushort ir = frameData[infraredIndex];

                            byte intensity = (byte)(ir >> 7);

                            pixels[colorIndex++] = (byte)(intensity / 1);   // Blue
                            pixels[colorIndex++] = (byte)(intensity / 1);   // Green
                            pixels[colorIndex++] = (byte)(intensity / 0.4); // Red

                            colorIndex++;
                        }

                        int stride = width * format.BitsPerPixel / 8;

                        //pass the frame bitmap to MainWindow <Image>
                        cameraIMG.Source = BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);
                    }
                }
            }

            // Open body frame and draw Skeleton
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    canvas.Children.Clear();

                    _bodies = new Body[frame.BodyFrameSource.BodyCount];

                    frame.GetAndRefreshBodyData(_bodies);

                    foreach (var body in _bodies)
                    {
                        //Do something with the body...
                        if (body != null)
                        {
                            if (body.IsTracked)
                            {
                                if (_displayBody)
                                {
                                    canvas.DrawSkeleton(body, coMapper, _mode);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #16
0
        public static Shape DrawLine(this Canvas canvas, Joint first, Joint second, CoordinateMapper mapper, SpaceMode mode,
                                     double thickness, Brush brush)
        {
            Shape lineToReturn = null;

            if (first.TrackingState == TrackingState.NotTracked || second.TrackingState == TrackingState.NotTracked)
            {
                return(null);
            }

            SpacePointBase myFirstPoint;
            SpacePointBase mySecondPoint;

            switch (mode)
            {
            case SpaceMode.Color:
            default:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToColorSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToColorSpace(second.Position));

                break;

            case SpaceMode.Depth:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToDepthSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToDepthSpace(second.Position));

                break;
            }

            //Both points that the line joins must be mapped correctly
            if (myFirstPoint.IsValid && mySecondPoint.IsValid)
            {
                myFirstPoint  = myFirstPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);
                mySecondPoint = mySecondPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);

                //call static DrawLine from class SpacePointBae
                lineToReturn = SpacePointBase.DrawLine(canvas, myFirstPoint, mySecondPoint, thickness, brush);
            }

            return(lineToReturn);
        }
Example #17
0
 public static Shape DrawLine(this Canvas canvas, Joint first, Joint second, CoordinateMapper mapper, SpaceMode mode)
 {
     return(DrawLine(canvas, first, second, mapper, mode, 8, new SolidColorBrush(Colors.LightBlue)));
 }
Example #18
0
        public static void DrawPoint(this Canvas canvas, Joint joint, CoordinateMapper mapper, SpaceMode mode)
        {
            // 0) Check whether the joint is tracked.
            if (joint.TrackingState == TrackingState.NotTracked)
            {
                return;
            }

            SpacePointBase spPt;

            switch (mode)
            {
            case SpaceMode.Color:
            default:
                // 1a) Convert Joint positions to Color space coordinates.
                ColorSpacePoint colSpaceJoint = mapper.MapCameraPointToColorSpace(joint.Position);
                spPt = new SpacePointBase(colSpaceJoint);

                break;

            case SpaceMode.Depth:
                // 1b) Convert Joint positions to Depth space coordinates.
                DepthSpacePoint depSpacePoint = mapper.MapCameraPointToDepthSpace(joint.Position);
                spPt = new SpacePointBase(depSpacePoint);

                break;
            }

            #region Joint Mapping Messages
            if (spPt.X == float.NegativeInfinity || spPt.Y == float.NegativeInfinity)
            {
                //Console.WriteLine($"Joint Mapping Error: Joint[{joint.JointType.ToString()}] ( {spPt.X} , {spPt.Y} )");
            }
            else if ((spPt.X < 0 || spPt.Y < 0 || spPt.X > FrameDimensions[mode].Item1 || spPt.Y > FrameDimensions[mode].Item2))
            {
                //Console.WriteLine($"Joint Mapping Overflow: Joint[{joint.JointType.ToString()}] ( {spPt.X} , {spPt.Y} )");
            }
            #endregion


            //-inf meaning Joint is not detected and no corresponding mapped space point
            if (spPt.IsValid)
            {
                // 2) Scale the mapped coordinates to window dimensions.
                spPt = spPt.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);
                //if (joint.JointType == 0) Console.WriteLine($"Head Position in Color Space = {spPt.X}, {spPt.Y}");

                // 3) Draw the point on Canvas
                spPt.DrawPoint(canvas);
            }
        }
Example #19
0
 /// <summary>
 /// 空间搜索
 /// </summary>
 /// <param name="FeatureClass"></param>
 /// <param name="geometry"></param>
 /// <param name="spaceMode"></param>
 /// <returns></returns>
 public static List<IFeature> Search(IFeatureClass FeatureClass, IGeometry geometry, SpaceMode spaceMode)
 {
     IQueryFilter queryFilter = new QueryFilterClass();
     ISpatialFilter spatialFilter = new SpatialFilterClass();
     spatialFilter.GeometryField = "shape";
     spatialFilter.Geometry = geometry;
     switch (spaceMode)
     {
         case SpaceMode.Touches:
             spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelTouches;
             break;
         case SpaceMode.Overlaps:
             spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelOverlaps;
             break;
         case SpaceMode.Intersect:
             spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
             break;
         case SpaceMode.Crossed:
             spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
             break;
         case SpaceMode.Contains:
             spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
             break;
         case SpaceMode.Within:
             spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;
             break;
     }
     queryFilter = spatialFilter as IQueryFilter;
     IFeatureCursor featureCursor = FeatureClass.Search(queryFilter, false);
     IFeature feature = featureCursor.NextFeature();
     var list = new List<IFeature>();
     while (feature != null)
     {
         list.Add(feature);
         feature = featureCursor.NextFeature();
     }
     System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
     return list;
 }
Example #20
0
        public static void DrawLine(this Canvas canvas, Joint first, Joint second, CoordinateMapper mapper, SpaceMode mode)
        {
            if (first.TrackingState == TrackingState.NotTracked || second.TrackingState == TrackingState.NotTracked)
            {
                return;
            }

            SpacePointBase myFirstPoint;
            SpacePointBase mySecondPoint;

            switch (mode)
            {
            case SpaceMode.Color:
            default:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToColorSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToColorSpace(second.Position));

                break;

            case SpaceMode.Depth:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToDepthSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToDepthSpace(second.Position));

                break;
            }

            //Both points that the line joins must be mapped correctly
            if (
                (!float.IsNegativeInfinity(myFirstPoint.X) &&
                 !float.IsNegativeInfinity(myFirstPoint.Y)) ||
                (!float.IsNegativeInfinity(mySecondPoint.X) &&
                 !float.IsNegativeInfinity(mySecondPoint.Y))
                )
            {
                myFirstPoint  = myFirstPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);
                mySecondPoint = mySecondPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);

                //call static DrawLine from class SpacePointBae
                SpacePointBase.DrawLine(canvas, myFirstPoint, mySecondPoint);
            }
        }
Example #21
0
        public static IEnumerable <Shape> DrawSkeleton(this Canvas canvas, Body body, CoordinateMapper mapper, SpaceMode mode)
        {
            if (body == null)
            {
                return(null);
            }

            IList <Shape> skeleton = new List <Shape>();

            foreach (Joint joint in body.Joints.Values)
            {
                skeleton.Add(canvas.DrawPoint(joint, mapper, mode));
            }

            foreach (Tuple <JointType, JointType> standardJointLine in StandardJointLines)
            {
                skeleton.Add(canvas.DrawLine(body.Joints[standardJointLine.Item1], body.Joints[standardJointLine.Item2], mapper, mode));

                //if (standardJointLine.Item1 == JointType.ElbowLeft && standardJointLine.Item2 == JointType.WristLeft)
                //{
                //    Joint first = body.Joints[standardJointLine.Item1];
                //    Joint second = body.Joints[standardJointLine.Item2];

                //    Joint firstToSecond = second.Subtract(first).Multiply(1.2f);
                //    Joint extendedSecond = first.Add(firstToSecond);
                //    extendedSecond.TrackingState = TrackingState.Inferred;

                //    skeleton.Add(canvas.DrawLine(first, extendedSecond, mapper, mode, 8, new SolidColorBrush(Colors.GreenYellow)));
                //    skeleton.Add(canvas.DrawPoint(extendedSecond, mapper, mode, new SolidColorBrush(Colors.YellowGreen)));
                //}
            }

            return(skeleton);
        }
Example #22
0
        //public static byte[] ReflectImage(byte[] bitMap, int width, int height)
        //{
        //    byte[] reflection = new byte[width*height];
        //    int imagePosition = 0;
        //    // repeat for each row
        //    for (int row = 0; row < height; row++)
        //    {
        //          // read from the left edge
        //          int fromPos = imagePosition + (row * width);
        //          // write to the right edge
        //          int toPos = fromPos + width - 1;
        //          while (fromPos < width)
        //          {
        //              reflection[toPos] = bitMap[fromPos];
        //              //copy the pixel
        //              fromPos++; // move towards the middle
        //              toPos--; // move back from the right edge
        //          }
        //    }
        //    return reflection;
        //}

        #endregion


        #region CoordinateMapper

        public static Point MapCameraSpacePointToPointOnCanvas(this CoordinateMapper coorMap, CameraSpacePoint camSP, Canvas canvas, SpaceMode spaceMode)
        {
            ColorSpacePoint colorSP        = coorMap.MapCameraPointToColorSpace(camSP);
            double          normedColorSPX = colorSP.X / FrameDimensions[spaceMode].Item1;
            double          normedColorSPY = colorSP.Y / FrameDimensions[spaceMode].Item2;

            return(new Point(normedColorSPX * canvas.Width, normedColorSPY * canvas.Height));
        }
Example #23
0
 public void AnalyzeBase(IGeometry geometry,SpaceMode mode,IFeatureLayer FeatureLayer,string Title)
 {
     SelectFeature(geometry, mode, FeatureLayer);
     var result = new AttributeForm2(FeatureLayer.FeatureClass, geometry, mode, Title,this.dataType);
     result.Show(this);
 }