Esempio n. 1
0
 public DataCube(string name, DataStatement statement, string assignTo)
 {
     NaDrop             = new NaDrop();
     ReplaceNull        = new NullReplace();
     ReplaceString      = new StringReplace();
     this.StatementType = statement;
     SchemaName         = "";
     VariableName       = name;
     AssignTo           = assignTo;
     Distrinct          = false;
     SelectStatement    = new Select();
     GroupByStatement   = new GroupBy();
     CubeStatement      = new Cube();
     ExceptStatement    = new Except();
     IntersectStatement = new Intersect();
     DropStatement      = new Drop();
     JoinStatement      = new List <Join>();
     RollupStatement    = new Rollup();
     SearchStatement    = new Search();
     SortStatement      = new SortBy();
     LimitStatement     = new Limit();
     LoadStatement      = new Load();
     Fields             = new List <IField>();
     Drop           = false;
     UnionStatement = new Union();
     Declaration    = new Declaration();
     DataWith       = new With();
 }
Esempio n. 2
0
        IDrawable run(IDrawable input)
        {
            if (!(input is SegmentSet))
            {
                throw new Exception("SegmentTest. Input is not Segments.");
            }

            var inp = input as SegmentSet;

            Segment a = inp[0];
            Segment b = inp[1];

            //Circle circle = new Circle(a.End,1);

            //Segment a = new Segment(20,0,20,80);
            //Segment b = new Segment(0, 20, 0, 80);

            var x = Intersect.GetIntersection(a, b);

            //var x = Intersect.GetArrowBase(a.Begin, a.End);
            if (x.Count > 0)
            {
                return(new PointSet(x[0]));
            }
            else
            {
                return(new PointSet());
            }
        }
Esempio n. 3
0
        private void False_Intersect(Line2 line, Circle2 circle)
        {
            IntersectionLineCircle intersection;

            Assert.False(Intersect.LineCircle(line.origin, line.direction, circle.center, circle.radius, out intersection), format, line, circle);
            Assert.False(Intersect.LineCircle(line.origin, -line.direction, circle.center, circle.radius, out intersection), format, line, circle);
        }
Esempio n. 4
0
        /// <summary>
        /// 给定延伸方式求曲线交点
        /// </summary>
        /// <param name="C1">曲线1</param>
        /// <param name="C2">曲线2</param>
        /// <param name="inter">延伸方式</param>
        /// <returns>交点集合</returns>
        public static Point3dCollection Intersect(Curve cur1, Curve cur2, Intersect inter)
        {
            Point3dCollection ptc = new Point3dCollection();

            cur1.IntersectWith(cur2, inter, ptc, 0, 0);
            return(ptc);
        }
        private static bool BisectorBisector(Plan.Vertex vertexA, Plan.Vertex vertexB, out float offset)
        {
            IntersectionRayRay2 intersection;

            if (Intersect.RayRay(vertexA.position, vertexA.bisector, vertexB.position, vertexB.bisector, out intersection))
            {
                if (intersection.type == IntersectionType.Point)
                {
                    float offsetA = GetBisectorBisectorOffset(vertexA, intersection.pointA);
                    float offsetB = GetBisectorBisectorOffset(vertexB, intersection.pointA);
                    offset = Mathf.Min(offsetA, offsetB);
                    return(true);
                }
                if (intersection.type == IntersectionType.Segment)
                {
                    float toIntersection = Vector2.Distance(vertexA.position, vertexB.position);
                    float offsetA        = GetBisectorBisectorOffset(vertexA, toIntersection) / 2;
                    float offsetB        = GetBisectorBisectorOffset(vertexB, toIntersection) / 2;
                    offset = Mathf.Min(offsetA, offsetB);
                    return(true);
                }

                // BEGIN: Modified by Microsoft Corporation for generic logging purposes.
                API.MREAPI.Logger.LogError(string.Format("Invalid bisector intersection\ntype: {0}\npointA: {1} pointB: {2}\nbisectorA: {3} bisectorB:{4}",
                                                         intersection.type, intersection.pointA, intersection.pointB, vertexA.bisector, vertexB.bisector));
                // END: Modified by Microsoft Corporation for generic logging purposes.

                offset = 0;
                return(false);
            }
            offset = 0;
            return(false);
        }
Esempio n. 6
0
    void OnSceneGUI()
    {
        RootAnimation roots = (RootAnimation)target;

        if (Event.current.control)
        {
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        }

        if (Event.current.control && Event.current.type == EventType.MouseDown)
        {
            Ray     ray    = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            Vector3 hitpos = Intersect.RaycastMesh(roots.target.GetComponent <MeshFilter>().sharedMesh, roots.target.transform.position, ray);

            if (hitpos != Vector3.zero)
            {
                //AddPointToPath(0, hitpos - ray.direction * 0.7f);
            }

            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast(ray, out hit, 50))
            {
                AddPointToPath(0, hit.point);
            }
        }
    }
 private void False_Intersect(Circle2 circleA, Circle2 circleB)
 {
     Assert.False(Intersect.CircleCircle(circleA, circleB));
     Assert.False(Intersect.CircleCircle(circleA, circleB, out _));
     Assert.False(Intersect.CircleCircle(circleB, circleA));
     Assert.False(Intersect.CircleCircle(circleB, circleA, out _));
 }
Esempio n. 8
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PointSegmentTest. Input is not PointSegmentTest.");
            }

            var inp = input as PointSet;

            Point   a = inp[0];
            Point   b = inp[1];
            Point   c = inp[2];
            Segment d = new Segment(b, c);

            bool x = Intersect.IsIntersected(a, d);

            if (x)
            {
                return
                    (new DrawableSet(new List <IDrawable>()
                {
                    new SegmentSet(d), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new SegmentSet(d), DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
        }
Esempio n. 9
0
        public void LineCircleIntersection3()
        {
            var pts = Intersect.LineCircleXY(new Line(0, 1, 10, 1), new Circle(2, new Vector(5, 0)));

            Assert.AreEqual(2, pts.Length);
            //Assert.AreEqual(new Vector(5, 1), pts[0]);
        }
Esempio n. 10
0
        private void IsFalse_Intersect(Line2 line, Ray2D ray)
        {
            IntersectionLineRay2 intersection;
            string message = string.Format(format, line, ray.ToString("F8"));

            Assert.IsFalse(Intersect.LineRay(line, ray, out intersection), message);
        }
Esempio n. 11
0
 public Point3dCollection IntersectWith(UniversalLineSegment other, Intersect intersectType)
 {
     using (var otherLine = new Line(other.ncadSegment.StartPoint, other.ncadSegment.EndPoint))
     {
         return(IntersectWith(otherLine, intersectType));
     }
 }
Esempio n. 12
0
 private void button3_Click(object sender, EventArgs e)
 {
     set1        = getSet();
     set2        = getSet();
     label1.Text = (Intersect.intersect(set1, set2) == Intersect.Set.NoPoint) ? "no" : "yes";
     this.Invalidate();
 }
        private void IsFalse_Intersect(Ray2D ray, Segment2 segment)
        {
            string message = string.Format(format, ray.ToString("F8"), segment);

            Assert.IsFalse(Intersect.RaySegment(ray.origin, ray.direction, segment.a, segment.b, out _), message);
            Assert.IsFalse(Intersect.RaySegment(ray.origin, ray.direction, segment.b, segment.a, out _), message);
        }
Esempio n. 14
0
        private void IsFalse_IntersectSwap(Line2 line, Ray2D ray)
        {
            string message = string.Format(format, line, ray.ToString("F8"));

            Assert.IsFalse(Intersect.LineRay(line.origin, line.direction, ray.origin, ray.direction, out _), message);
            Assert.IsFalse(Intersect.LineRay(line.origin, line.direction, ray.origin, -ray.direction, out _), message);
        }
        private void IsFalse_Intersect(Ray2D rayA, Ray2D rayB)
        {
            string message = string.Format(format, rayA.ToString("F8"), rayB.ToString("F8"));

            Assert.IsFalse(Intersect.RayRay(rayA, rayB, out _), message);
            Assert.IsFalse(Intersect.RayRay(rayB, rayA, out _), message);
        }
Esempio n. 16
0
        public static double IntegrateCurve(Curve fx, Vector direction, double from, double to, ref double centroid, double increment = 0.001)
        {
            double result        = 0;
            double max           = System.Math.Max(from, to);
            double min           = System.Math.Min(from, to);
            double sumAreaLength = 0;
            int    segments      = (int)((max - min) / increment);

            increment = (max - min) / (double)(segments + 1);
            Point origin = Point.Origin;
            Plane plane  = new Plane(origin, direction);

            for (double dx = min; dx < max; dx += increment)
            {
                double currentCentre = dx + increment / 2;
                double sliceWidth    = (increment);
                plane.Origin = (origin + plane.Normal * currentCentre);
                List <Point> points       = Intersect.PlaneCurve(plane, fx, 0.001);
                double       currentValue = 0;
                if (points.Count == 2)
                {
                    currentValue = System.Math.Abs(points[0].Y - points[1].Y);
                }
                else if (points.Count == 1)
                {
                    currentValue = points[0].Y;
                }
                result        += currentValue * sliceWidth;
                sumAreaLength += currentValue * sliceWidth * currentCentre;
            }
            centroid = result != 0 ? sumAreaLength / result : 0;
            return(result);
        }
Esempio n. 17
0
 private void False_Intersect(Segment2 segment1, Segment2 segment2)
 {
     Assert.IsFalse(Intersect.SegmentSegment(segment1.a, segment1.b, segment2.a, segment2.b, out _), format, segment1, segment2);
     Assert.IsFalse(Intersect.SegmentSegment(segment1.a, segment1.b, segment2.b, segment2.a, out _), format, segment1, segment2);
     Assert.IsFalse(Intersect.SegmentSegment(segment2.a, segment2.b, segment1.a, segment1.b, out _), format, segment1, segment2);
     Assert.IsFalse(Intersect.SegmentSegment(segment2.a, segment2.b, segment1.b, segment1.a, out _), format, segment1, segment2);
 }
Esempio n. 18
0
        private void IsFalse_Intersect(Line2 line, Segment2 segment)
        {
            IntersectionLineSegment2 intersection;

            Assert.IsFalse(Intersect.LineSegment(line.origin, line.direction, segment.a, segment.b, out intersection), format, line, segment);
            Assert.IsFalse(Intersect.LineSegment(line.origin, line.direction, segment.b, segment.a, out intersection), format, line, segment);
        }
Esempio n. 19
0
 private void True_IntersectTwoPoints(Segment3 segment, Sphere sphere, Vector3 expectedA, Vector3 expectedB)
 {
     Assert.True(Intersect.SegmentSphere(segment.a, segment.b, sphere.center, sphere.radius, out IntersectionSegmentSphere intersection), format, segment, sphere);
     Assert.AreEqual(IntersectionType.TwoPoints, intersection.type, format, segment, sphere);
     AreEqual(intersection.pointA, expectedA);
     AreEqual(intersection.pointB, expectedB);
 }
Esempio n. 20
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PolygonTest. Input is not PolygonTest.");
            }
            var   inp = input as PointSet;
            Point c = inp[0]; Point d = inp[1]; Point e = inp[2]; Point fe = inp[3];

            ConvexPolygon f1 = new ConvexPolygon(new Point((c.X + d.X) / 2, c.Y), new Point(d.X, (c.Y + d.Y) / 3), new Point(d.X, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2, d.Y), new Point(c.X, 2 * ((d.Y + c.Y) / 3)), new Point(c.X, ((d.Y + c.Y) / 3)));
            ConvexPolygon f2 = new ConvexPolygon(new Point((e.X + fe.X) / 2, e.Y), new Point(fe.X, (e.Y + fe.Y) / 3), new Point(fe.X, 2 * ((fe.Y + e.Y) / 3)), new Point((e.X + fe.X) / 2, fe.Y), new Point(e.X, 2 * ((fe.Y + e.Y) / 3)), new Point(e.X, ((fe.Y + e.Y) / 3)));
            var           x  = Intersect.GetIntersection(f1, f2);

            if (x.Count > 0)
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.ToArray()), new PolygonSet(f1, f2), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.ToArray()), new PolygonSet(f1, f2), DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
        }
Esempio n. 21
0
        private void False_Intersect(Ray2D ray, Circle2 circle)
        {
            IntersectionRayCircle intersection;
            string message = string.Format(format, ray.ToString("F8"), circle);

            Assert.False(Intersect.RayCircle(ray.origin, ray.direction, circle.center, circle.radius, out intersection), message);
        }
Esempio n. 22
0
    private static Intersect LineIntersect(Vector3 a1, Vector3 a2, Vector3 b1, Vector3 b2)
    {
        var res = new Intersect();

        res.result = -1;
        res.point  = new Vector3();

        float d  = (a1.x - a2.x) * (b2.y - b1.y) - (a1.y - a2.y) * (b2.x - b1.x);
        float da = (a1.x - b1.x) * (b2.y - b1.y) - (a1.y - b1.y) * (b2.x - b1.x);
        float db = (a1.x - a2.x) * (a1.y - b1.y) - (a1.y - a2.y) * (a1.x - b1.x);

        if (System.Math.Abs(d) < 0.000001)
        {
            res.result = 0;
        }
        else
        {
            float ta = da / d;
            float tb = db / d;
            if ((0 <= ta) && (ta <= 1) && (0 <= tb) && (tb <= 1))
            {
                res.result  = 1;
                res.point.x = a1.x + ta * (a2.x - a1.x);
                res.point.y = a1.y + ta * (a2.y - a1.y);
            }
        }
        return(res);
    }
Esempio n. 23
0
        private String RasterAPuntos(string sRasterLayer, string sOutputFC, Geoprocessor gp)
        {
            string sCapaMpios_parques_cobertura = "mpios_parques_cobertura";
            string sFCCruce = _sigpi.Parametros.RutaGBD + "\\" + sCapaMpios_parques_cobertura;

            try
            {
                RasterToPoint raster2Pnt = new RasterToPoint(sRasterLayer, sOutputFC);
                raster2Pnt.raster_field = "VALUE";

                gp.Execute(raster2Pnt, null);

                Intersect intersect = new Intersect();
                intersect.in_features       = sOutputFC + " ; " + sFCCruce;
                intersect.out_feature_class = sOutputFC.Replace(".shp", "_intersect.shp");
                intersect.join_attributes   = "NO_FID";
                intersect.output_type       = "POINT";

                gp.Execute(intersect, null);
                return(intersect.out_feature_class.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("Verifique que exista información para el día seleccionado");
            }
        }
Esempio n. 24
0
        /***************************************************/

        static void IntersectNewLineLine(int iter)
        {
            int i = iter % (newControlPoints.Count - 3);

            //Intersect.LineLine(new Line(newControlPoints[i], newControlPoints[i + 1]), new Line(newControlPoints[i + 2], newControlPoints[i + 3]));
            Intersect.LineLine(newLine1, newLine2);
        }
        private static bool BisectorSegment(Plan.Vertex vertex, Vector2 segmentA, Vector2 segmentB, out float offset)
        {
            IntersectionRaySegment2 intersection;

            if (Intersect.RaySegment(vertex.position, vertex.bisector, segmentA, segmentB, out intersection))
            {
                if (intersection.type == IntersectionType.Point)
                {
                    Vector2 segmentDirection  = (segmentB - segmentA).normalized;
                    float   toIntersection    = Vector2.Distance(vertex.position, intersection.pointA);
                    float   intersectionAngle = Vector2.Angle(vertex.bisector, segmentDirection);
                    float   intersectionSin   = Mathf.Sin(intersectionAngle * Mathf.Deg2Rad);
                    float   bisectorSin       = Geometry.GetAngleBisectorSin(vertex.angle);
                    offset = toIntersection / (1 / intersectionSin + 1 / bisectorSin);
                    return(true);
                }

                // BEGIN: Modified by Microsoft Corporation for generic logging purposes.
                API.MREAPI.Logger.LogError(string.Format("Invalid bisector intersection\ntype: {0}\npointA: {1} pointB: {2}\nray: {3} segmentA:{4} segmentB:{5}",
                                                         intersection.type, intersection.pointA, intersection.pointB, vertex.bisector, segmentA, segmentB));
                // END: Modified by Microsoft Corporation for generic logging purposes.

                offset = 0;
                return(false);
            }
            offset = 0;
            return(false);
        }
Esempio n. 26
0
        public override Point3dCollection IntersectWith(Entity entity, Intersect intersectType)
        {
            var intersection = new Point3dCollection();

            ncadLine.IntersectWith(entity, intersectType, intersection, IntPtr.Zero, IntPtr.Zero);
            return(intersection);
        }
Esempio n. 27
0
 /// <summary>
 /// Does this polyline self-intersect on the XY plane?
 /// </summary>
 /// <returns></returns>
 public override bool IsSelfIntersectingXY()
 {
     if (Vertices.Count < 4)
     {
         return(false);
     }
     for (int i = 0; i < SegmentCount - 1; i++)
     {
         Vertex vA0 = Vertices[i];
         Vertex vA1 = Vertices[i + 1];
         for (int j = i + 2; j < SegmentCount; j++)
         {
             if (!(Closed && i == 0 && j == SegmentCount - 1))
             {
                 Vertex vB0          = Vertices[j];
                 Vertex vB1          = Vertices.GetWrapped(j + 1);
                 double t0           = 0;
                 double t1           = 0;
                 Vector intersection = Intersect.LineLineXY(vA0.Position, vA1.Position - vA0.Position,
                                                            vB0.Position, vB1.Position - vB0.Position, ref t0, ref t1);
                 if (intersection.IsValid() && t0 >= 0 && t0 <= 1 && t1 >= 0 && t1 <= 1)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 28
0
        public void PolyCurveDomainInPolygon2()
        {
            var pline = new PolyLine(
                new Vector(0, 0),
                new Vector(0, 10),
                new Vector(-20, 10),
                new Vector(-20, 0));

            pline.Close();
            var polyCrv = pline.ToPolyCurve();

            var polygon = new Vertex[]
            {
                new Vertex(-10, 0),
                new Vertex(-0.0001, 0),
                new Vertex(-0.0001, -10),
                new Vertex(-10, -10)
            };

            var ints = Intersect.CurveDomainInPolygonXY(polyCrv, polygon);

            Assert.AreEqual(1, ints.Count);
            Assert.AreEqual(0.875, ints[0].Start);
            Assert.AreEqual(0.99999875, ints[0].End);
        }
Esempio n. 29
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PointPolygonTest. Input is not PointPolygonTest.");
            }

            var inp = input as PointSet;

            Point a = inp[0]; Point c = inp[1]; Point d = inp[2];
            var   b = new ConvexPolygon(new Point(c.X, c.Y), new Point(d.X, c.Y), new Point(d.X, d.Y), new Point(c.X, d.Y));

            var x = Intersect.IsIntersected(a, b);

            //var x = Intersect.GetIntersection(b, a);
            if (x)
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(), new PolygonSet(b), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(), new PolygonSet(b), DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
            //return new PointSet(x.ToArray());
        }
Esempio n. 30
0
        /// <summary>
        /// Creates a comic rendered copy of the input image.
        /// </summary>
        public override Bitmap Render(Bitmap sourceImage)
        {
            // Converters
            GrayscaleY     convertGray  = new GrayscaleY();
            GrayscaleToRGB convertColor = new GrayscaleToRGB();

            // Convert grayscal images
            if (sourceImage.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                sourceImage = convertColor.Apply(sourceImage);
            }

            Bitmap comicImage = AForge.Imaging.Image.Clone(sourceImage);
            Bitmap edgeLayer  = null;
            Bitmap glowLayer  = null;

            // Glow for smooth colors
            GaussianBlur filterBlur = new GaussianBlur();

            filterBlur.Sigma = 2.0;
            filterBlur.Size  = 4;
            glowLayer        = filterBlur.Apply(comicImage);

            //SmartBlur filterBlur = new SmartBlur(10, 0.2);
            //glowLayer = filterBlur.Apply(comicImage);

            ContrastCorrection filterContrast = new ContrastCorrection(1 - (-this.Coloring * 0.1));

            filterContrast.ApplyInPlace(glowLayer);

            BrightnessCorrection filterBrightness = new BrightnessCorrection((-this.Coloring * 0.1) + 0.1);

            filterBrightness.ApplyInPlace(glowLayer);

            Screen blendScreen = new Screen(glowLayer);

            blendScreen.ApplyInPlace(comicImage);


            // Create a layer for edges
            Convolution filterConvolution = new Convolution(ConvolutionKernel);

            edgeLayer = filterConvolution.Apply(comicImage);

            // Convert to grayscale
            edgeLayer = convertGray.Apply(edgeLayer);

            // Threshold (edge thickness)
            Threshold filterThreshold = new Threshold((byte)(this.Edging * 255 / 100));

            filterThreshold.ApplyInPlace(edgeLayer);
            edgeLayer = convertColor.Apply(edgeLayer);

            // intersect comic with top layer (Darken blend)
            Intersect blendIntersect = new Intersect(edgeLayer);

            blendIntersect.ApplyInPlace(comicImage);

            return(comicImage);
        }
        public void init(int programID, AxMapControl mc, AxToolbarControl tc, Intersect.ProgramStepUserControl.OnFinish of, MainWindow mw)
        {
            inited = true;

            villageColorRandomer = new VillageColorRandomer();
            program = new Program();
            program.id = programID;
            program.select();
            villageList = program.getAllRelatedVillage();
            if (villageList == null)
            {
                villageList = new ObservableCollection<Village>();
            }
            else
            {
                foreach (Village village in villageList)
                {
                    village.polygonElementColorString = villageColorRandomer.randomColor();
                    InnerRoad innerRoad = village.getRelatedInnerRoad();
                    village.innerRoad = innerRoad;
                }
            }

            mapControl = mc;
            toolbarControl = tc;
            mainWindow = mw;
            foreach (Village village in villageList)
            {
                GisUtil.drawPolygonElement(village.polygonElement, mapControl);
                GisUtil.UpdatePolygonElementColor(village.polygonElement, mapControl
                    , VillageColorRandomer.GetRedFromColorString(village.polygonElementColorString)
                    , VillageColorRandomer.GetGreenFromColorString(village.polygonElementColorString)
                    , VillageColorRandomer.GetBlueFromColorString(village.polygonElementColorString));
                if (village.innerRoad.lineElement != null)
                    GisUtil.DrawPolylineElement(village.innerRoad.lineElement, mapControl);
                if (village.inUse)
                {
                    string reverseColorString = VillageColorRandomer.GetReverseVillageColorString(village.polygonElementColorString);
                    GisUtil.UpdatePolygonElementOutline(village.polygonElement, mapControl
                        , VillageColorRandomer.GetRedFromColorString(reverseColorString)
                        , VillageColorRandomer.GetGreenFromColorString(reverseColorString)
                        , VillageColorRandomer.GetBlueFromColorString(reverseColorString));
                }
            }

            valid = isValid();
            dirty = false;

            onFinish = of;

            mapControlMouseDown = null;
            VillageListBox.ItemsSource = villageList;
        }
Esempio n. 32
0
        public void init(int programID, AxMapControl mc, Intersect.ProgramStepUserControl.OnFinish of, MainWindow mw)
        {
            inited = true;

            if (program == null)
                program = new Program();
            program.id = programID;
            program.select();

            if (project == null)
                project = new Project();
            project.id = program.projectID;
            project.select();

            NetSizeUserControl.init(program.id);
            ConditionUserControl.init(program.id);

            mapControl = mc;
            onFinish = of;
            mainWindow = mw;

            mapControlMouseDown = null;

            //在初始化时就要对valid进行判断.
            Thread t = new Thread(delegate()
            {
                System.Threading.Thread.Sleep(500);
                Dispatcher.BeginInvoke((ThreadStart)delegate()
                {
                    if (isValid())
                    {
                        valid = true;
                        onFinish(true);
                        IFeatureClass resultFeatureClass;
                        if ((resultFeatureClass = GisUtil.getFeatureClass(System.IO.Path.GetDirectoryName(project.path), "评价结果.shp")) != null)
                        {
                            IFeatureLayer resultFeatureLayer = new FeatureLayerClass();
                            resultFeatureLayer.FeatureClass = resultFeatureClass;
                            mapControl.AddLayer(resultFeatureLayer);
                        }
                        else
                        {
                            SiteSelector siteSelector = new SiteSelector(mapControl, program.id);
                            siteSelector.startSelectSite();
                        }
                    }
                });
            });
            t.Start();
        }
        public void init(int programID, AxMapControl mc, Intersect.ProgramStepUserControl.OnFinish of)
        {
            inited = true;

            if (program == null)
                program = new Program();
            program.id = programID;
            program.select();

            if (project == null)
                project = new Project();
            project.id = program.projectID;
            project.select();

            NetSizeUserControl.init(program.id);
            ConditionUserControl.init(program.id);

            mapControl = mc;
            onFinish = of;

            mapControlMouseDown = null;

            //在初始化时就要对valid进行判断.
            Thread t = new Thread(delegate()
            {
                System.Threading.Thread.Sleep(500);
                Dispatcher.BeginInvoke((ThreadStart)delegate()
                {
                    if (isValid())
                    {
                        valid = true;
                        onFinish(true);
                        SiteSelector siteSelector = new SiteSelector(mapControl, program.id);
                        siteSelector.startSelectSite();
                    }
                });
            });
            t.Start();
        }
        public void init(int programID, AxMapControl mc, Intersect.ProgramStepUserControl.OnFinish of)
        {
            inited = true;
            onFinish = of;

            program = new Program();
            program.id = programID;
            program.select();

            housePlacerIndexCount = 0;

            villageList = program.getAllRelatedVillage();
            if (villageList == null)
            {
                villageList = new ObservableCollection<Village>();
            }
            else
            {
                ObservableCollection<Village> inUseVillageList = new ObservableCollection<Village>();
                foreach (Village village in villageList)
                {
                    if (village.inUse)
                    {
                        inUseVillageList.Add(village);
                        CommonHouse commonHouse = village.getRelatedCommonHouse();
                        if (commonHouse == null)
                        {
                            commonHouse = CommonHouse.GetDefaultCommonHouse();
                            commonHouse.villageID = village.id;
                        }
                        village.commonHouse = commonHouse;
                        ObservableCollection<House> houseList = village.getAllRelatedHouse();
                        if (houseList == null)
                            houseList = new ObservableCollection<House>();
                        else
                        {
                            foreach (House house in houseList)
                            {
                                house.housePlacerListIndex = housePlacerIndexCount++;
                            }
                        }
                        village.houseList = houseList;
                        village.innerRoad = village.getRelatedInnerRoad();
                    }
                }
                villageList = inUseVillageList;
            }

            mapControl = mc;

            dirty = false;
            prePlaced = false;

            mapControlMouseDown = null;
            HousePlacerListBox.ItemsSource = villageList;

            Thread t = new Thread(delegate()
            {
                System.Threading.Thread.Sleep(500);
                Dispatcher.BeginInvoke((ThreadStart)delegate()
                {
                    if (isValid())
                    {
                        valid = true;
                        onFinish(true);
                    }
                });
            });
            t.Start();
        }
Esempio n. 35
0
            public Intersect CalculateIntersect(Vector3 location, Vector3 direction)
            {
                Intersect i = new Intersect();

                i.intersectPoint = new Vector3(0, 0, 0);
                i.intersects = false;

                Plane plane = new Plane(this);

                float distance = plane.Distance(location, direction);
                //Console.WriteLine("Distance = {0}", distance);

                i.distance = distance;
                i.intersectPoint = distance * direction + location;
                if (distance < 0)
                {
                    i.intersects = false;
                }
                else
                {
                    i.intersects = ObjLoader.IsPointInPolygon(this, i.intersectPoint);
                }

                return i;
            }
Esempio n. 36
0
        public float IsPointOnObject(Vector3 location, Vector3 direction)
        {
            Intersect closest = new Intersect();
            closest.distance = float.PositiveInfinity;
            for (int a = 0; a < faces.Count(); a++)
            {
                Face f = faces[a];
                Intersect i = f.CalculateIntersect(location, direction);
                if (i.intersects)
                {
                    if (i.distance < closest.distance)
                    {
                        closest = i;
                        closestFace = a;
                    }
                }
            }
            withinFace = true;
            mousePoint = new Vector3(0, 0, 0);
            if (float.IsInfinity(closest.distance))
            {
                withinFace = false;

            }
            else
            {
                mousePoint = closest.intersectPoint;
                //float d = DistanceToCylinder(new Vector3(1000, 0, 0), new Vector3(0, 0, 0), mousePoint);
                //Console.WriteLine("Distance to Cylinder = {0}, Point = {1}", d, mousePoint);
                //Console.WriteLine("Mouse Point = {0}", mousePoint);

                //Vector3 original = new Vector3(1, 0, 0);
                //Vector3 another = mousePoint - new Vector3 (500, 500, 0);
                //another.Normalize();
                //float d = OpenTK.MathHelper.RadiansToDegrees(Angle(original, another, new Vector3(0, 0, 1)));
                //Console.WriteLine("Angle = " + d);
            }
            return closest.distance;
            //Console.WriteLine("Outside Face");
        }
Esempio n. 37
0
 public void IntersectFeature(Geoprocessor gp, string sourseFeature1, string n1, string sourseFeature2Name, string SavaFeature)
 {
     try
     {
         ESRI.ArcGIS.AnalysisTools.Intersect intersectFeatures = new Intersect();
         intersectFeatures.in_features = sourseFeature1 + "\\" + n1 + ";" + sourseFeature2Name;
         intersectFeatures.out_feature_class = SavaFeature;
         intersectFeatures.output_type = "POINT";
         gp.OverwriteOutput = true;
         gp.Execute(intersectFeatures, null);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 38
0
        //copy要素赋值
        public void IntersectFeature(Geoprocessor gp, string sourseFeature,string aimFeature)
        {
            try
            {
                ESRI.ArcGIS.AnalysisTools.Intersect intersectFeatures = new Intersect();

                gp.Execute(intersectFeatures, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 39
0
 //村庄点面叠置
 public void JoinPoint(Geoprocessor gp,string environment,string SourseName1,string SourseName2,string SavaName)
 {
     try
     {
         ESRI.ArcGIS.AnalysisTools.Intersect  intersect = new Intersect();
         intersect.in_features = environment + SourseName1 + ".shp;" + environment + SourseName2 + ".shp";
             //@"D:\移动风险监测\新数据测试数据\6风险图应用业务相关数据\6.2淹没过程动态展示支撑数据\copy\ymss1.shp;D:\移动风险监测\新数据测试数据\6风险图应用业务相关数据\6.2淹没过程动态展示支撑数据\copy\czLayer.shp";
         intersect.out_feature_class = environment + SavaName;
         intersect.output_type = "POINT";
         gp.Execute(intersect, null);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 40
0
        private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image)
        {
            Invert inv = new Invert();
            inv.ApplyInPlace(image);

            UnmanagedImage ui = UnmanagedImage.FromManagedImage(image);

            pictureBox1.Image = image;


            if (controller.Tracker.TrackingObject == null)
                return;

            if (controller.Tracker.TrackingObject.IsEmpty)
                return;

            var rect = controller.Tracker.TrackingObject.Rectangle;
            Crop crop = new Crop(rect);

            UnmanagedImage head = crop.Apply(ui);

            var points = new List<IntPoint>() { new IntPoint(head.Width / 2, head.Height / 2) };
            var pps = head.Collect16bppPixelValues(points);

            double mean = Accord.Statistics.Tools.Mean(pps);

            double cutoff = mean + 15;
            Threshold t = new Threshold((int)cutoff);
            var mask = t.Apply(ui);



            LevelsLinear16bpp levels = new LevelsLinear16bpp();
            levels.InGray = new IntRange((int)cutoff, 65535);
            levels.OutGray = new IntRange(0, 65535);
            levels.ApplyInPlace(ui);


            var mask8bit = AForge.Imaging.Image.Convert16bppTo8bpp(mask.ToManagedImage());



            BlobCounter bc = new BlobCounter();
            bc.ObjectsOrder = ObjectsOrder.Area;
            bc.ProcessImage(mask8bit);
            var blobs = bc.GetObjectsInformation();

            inv.ApplyInPlace(image);
            Intersect intersect = new Intersect();
            intersect.UnmanagedOverlayImage = mask;
            mask = intersect.Apply(ui);

            List<Rectangle> rects = new List<Rectangle>();

            // Extract the uppermost largest blobs.
            for (int i = 0; i < blobs.Length; i++)
            {
                double dx = (blobs[i].Rectangle.Top - controller.Tracker.TrackingObject.Center.Y);
                double d = (dx * dx) / controller.Tracker.TrackingObject.Area;
                if (d < 2 && blobs[i].Area > 1000)
                    rects.Add(blobs[i].Rectangle);
            }

            rects.Sort(compare);

            if (rects.Count > 0)
            {
                captureHand(mask, rects[0], pbLeftArm, pbLeftHand);
            }
            if (rects.Count > 1)
            {
                captureHand(mask, rects[1], pbRightArm, pbRightHand);

            }

            RectanglesMarker marker = new RectanglesMarker(rects);
            marker.MarkerColor = Color.White;
            marker.ApplyInPlace(mask8bit);

            image = mask.ToManagedImage();
        }
Esempio n. 41
0
        private void captureHand(UnmanagedImage mask, Rectangle rect, PictureBox pbArm, PictureBox pbHand)
        {
            Crop c = new Crop(rect);
            var handImage = c.Apply(mask);

            var ps = handImage.Collect16bppPixelValues(handImage.CollectActivePixels());

            if (ps.Length > 0)
            {
                ushort max = Matrix.Max(ps);

                LevelsLinear16bpp levels = new LevelsLinear16bpp();
                levels.InGray = new IntRange(0, max);
                levels.OutGray = new IntRange(0, 65535);
                levels.ApplyInPlace(handImage);


               // pbArm.Image = handImage.ToManagedImage();


                double cutoff = 30000;
                Threshold th = new Threshold((int)cutoff);
                var handMask = th.Apply(handImage);

                var handMask8bit = AForge.Imaging.Image.Convert16bppTo8bpp(handMask.ToManagedImage());

                BlobCounter bch = new BlobCounter();
                bch.ObjectsOrder = ObjectsOrder.Area;
                bch.ProcessImage(handMask8bit);
                var blob = bch.GetObjectsInformation();

                if (blob.Length > 0)
                {
                    Intersect inters = new Intersect();
                    inters.UnmanagedOverlayImage = handMask;
                    inters.ApplyInPlace(handImage);

                    Crop ch = new Crop(blob[0].Rectangle);
                    handImage = ch.Apply(handImage);

                    ResizeNearestNeighbor res = new ResizeNearestNeighbor(25, 25);
                    handImage = res.Apply(handImage);

                    var leftHand = AForge.Imaging.Image.Convert16bppTo8bpp(handImage.ToManagedImage());

                    pbHand.Image = leftHand;
                }
            }
        }
        public void init(int programID, Intersect.ProgramStepUserControl.OnFinish of, AxMapControl mc, AxToolbarControl tc, MainWindow mainWindow)
        {
            inited = true;
            onFinish = of;

            Pager.nowStep = 1;
            Pager.totalStep = 2;
            Pager.update();

            Pager.nextStepButtonCheck = nextStepCheckValid;
            Pager.nextStepButtonClick += new EventHandler(nextStepClick);
            Pager.previewStepButtonClick += new EventHandler(previewStepClick);

            mapControl = mc;
            toolbarControl = tc;
            mapControlMouseDown = onMapControlMouseDown;
            SelectMainRoadUserControl.init(programID, mapControl, toolbarControl, mainWindow);
            SelectVillageUserControl.init(programID, mapControl, toolbarControl, of, mainWindow);

            Thread t = new Thread(delegate()
            {
                System.Threading.Thread.Sleep(500);
                Dispatcher.BeginInvoke((ThreadStart)delegate()
                {
                    if (isValid())
                    {
                        onFinish(true);
                    }
                });
            });
            t.Start();
        }
        //开始分析
        private void btnOK_Click(object sender, EventArgs e)
        {
            //判断是否选择要素
            if (this.txtInputLayer.Text == "" || this.txtInputLayer.Text == null ||
                this.txtOverlayLayer.Text == "" || this.txtOverlayLayer.Text == null)
            {
                txtMessage.Text = "请选择参加叠置分析的图层!";
                return;
            }
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;

            //设置参与叠置分析的多个对象
            object inputFeat = this.txtInputLayer.Text;
            object overlayFeat = this.txtOverlayLayer.Text;
            IGpValueTableObject pObject = new GpValueTableObjectClass();
            pObject.SetColumns(2);
            pObject.AddRow(ref inputFeat);
            pObject.AddRow(ref overlayFeat);

            //获取要素名称
            string str = System.IO.Path.GetFileName(this.txtInputLayer.Text);
            int index = str.LastIndexOf(".");
            string strName = str.Remove(index);

            //设置输出路径
            strOutputPath = txtOutputLayerPath.Text;

            //叠置分析结果
            IGeoProcessorResult result = null;

            //创建叠置分析实例,执行叠置分析
            string strOverlay = cmbOverlayType.SelectedItem.ToString();
            try
            {
                //添加处理过程消息
                txtMessage.Text = "开始叠置分析……" + "\r\n";
                switch (strOverlay)
                {
                    case "叠置求交(Intersect)":
                        Intersect intersectTool = new Intersect();
                        //设置输入要素
                        intersectTool.in_features = pObject;
                        //设置输出路径
                        strOutputPath += strName + "_" + "_intersect.shp";
                        intersectTool.out_feature_class = strOutputPath;
                        //执行求交运算
                        result = gp.Execute(intersectTool, null) as IGeoProcessorResult;
                        break;
                    case "叠置求并(Union)":
                        Union unionTool = new Union();
                        //设置输入要素
                        unionTool.in_features = pObject;
                        //设置输出路径
                        strOutputPath += strName + "_" + "_union.shp";
                        unionTool.out_feature_class = strOutputPath;
                        //执行联合运算
                        result = gp.Execute(unionTool, null) as IGeoProcessorResult;
                        break;
                    case "叠置标识(Identity)":
                        Identity identityTool = new Identity();
                        //设置输入要素
                        identityTool.in_features = inputFeat;
                        identityTool.identity_features = overlayFeat;
                        //设置输出路径
                        strOutputPath += strName + "_" + "_identity.shp";
                        identityTool.out_feature_class = strOutputPath;
                        //执行标识运算
                        result = gp.Execute(identityTool, null) as IGeoProcessorResult;
                        break;
                }
            }
            catch (System.Exception ex)
            {
                //添加处理过程消息
                txtMessage.Text += "叠置分析过程出现错误:" + ex.Message + "\r\n";
            }

            //判断叠置分析是否成功
            if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                txtMessage.Text += "叠置失败!";
            else
            {
                this.DialogResult = DialogResult.OK;
                txtMessage.Text += "叠置成功!";
            }
        }
Esempio n. 44
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            /*FileInfo openpath = new FileInfo(textBox1.Text);
            string ss = openpath.Directory.ToString();//·���ĸ�Ŀ¼

            ILayer pLayer;
            pLayer = m_mapControl.Map.get_Layer(comboBox1.SelectedIndex);
            IFeatureLayer pInputFeatureLayer;
            pInputFeatureLayer = pLayer as IFeatureLayer;
            IFeatureClass pInputFeatureClass = pInputFeatureLayer.FeatureClass;

            ITable pInputTable;
            pInputTable = pInputFeatureClass as ITable;

            pInputFeatureClass = pInputFeatureLayer.FeatureClass;

            pLayer = m_mapControl.Map.get_Layer(comboBox2.SelectedIndex);
            IFeatureLayer pOverlayFeatureLayer;
            pOverlayFeatureLayer = pLayer as IFeatureLayer;
            IFeatureClass pOverlayFeatureClass;
            pOverlayFeatureClass = pOverlayFeatureLayer.FeatureClass;

            ITable pOverlayTable;
            pOverlayTable = pOverlayFeatureClass as ITable;

            //IFeatureClass pOverlayFeatureClass;
            //pOverlayFeatureClass = pOverlayFeatureLayer.FeatureClass;

            if (pInputTable == null)
            {
                MessageBox.Show("����ͼ��Ϊ��");
                return;
            }

            if (pOverlayTable == null)
            {
                MessageBox.Show("����ͼ��Ϊ��");
                return;
            }

            IFeatureClassName pFeatureClassName;
            pFeatureClassName = new FeatureClassNameClass();
            pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
            pFeatureClassName.ShapeFieldName = "Shape";
            pFeatureClassName.ShapeType = pInputFeatureClass.ShapeType;

            IWorkspaceName pNewWSName;
            pNewWSName = new WorkspaceNameClass();
            pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
            pNewWSName.PathName = ss;

            IDatasetName pDatasetName;
            pDatasetName = pFeatureClassName as IDatasetName;
            pDatasetName.Name = openpath.Name;  //"Intersect_Result";
            pDatasetName.WorkspaceName = pNewWSName;

            double tol = 0.1;

            IBasicGeoprocessor pBGP;
            pBGP = new BasicGeoprocessorClass();
            pBGP.SpatialReference = m_mapControl.Map.SpatialReference;
            IFeatureClass pOutputFeatureClass;
            IFeatureLayer pOutputFeatLayer;
            pOutputFeatLayer = new FeatureLayerClass();
            int n = listBox1.SelectedIndex;

            if (n>= 0 && n< 3)
            {
                switch (n)
                {
                    case(0):
                        pOutputFeatureClass = pBGP.Intersect(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
                        pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
                        pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
                        m_mapControl.Map.AddLayer(pOutputFeatLayer);
                        break;
                    case(1):
                        pOutputFeatureClass = pBGP.Union(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
                        pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
                        pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
                        m_mapControl.Map.AddLayer(pOutputFeatLayer);
                        break;
                    case(2):
                        pOutputFeatureClass = pBGP.Clip(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
                        pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
                        pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
                        m_mapControl.Map.AddLayer(pOutputFeatLayer);
                        break;
                }
            }*/
            //Geoprocessor processor = new Geoprocessor();
            IFeatureLayer inputLyr = m_mapControl.Map.get_Layer(comboBox1.SelectedIndex) as IFeatureLayer;
            IDataLayer2 dataLy = inputLyr as IDataLayer2;
            IDatasetName inputdsName = dataLy.DataSourceName as IDatasetName;
            IWorkspaceName inputws = inputdsName.WorkspaceName as IWorkspaceName;
            string input=inputws.PathName+"\\"+inputLyr.Name;

            IFeatureLayer overlayLyr = m_mapControl.Map.get_Layer(comboBox2.SelectedIndex) as IFeatureLayer;
            IDataLayer2 dataOverlay = overlayLyr as IDataLayer2;
            IDatasetName overlayDsName = dataOverlay.DataSourceName as IDatasetName;
            IWorkspaceName overlayWs = overlayDsName.WorkspaceName;
            string overlay =overlayWs.PathName+"\\"+overlayLyr.Name;

            string output =textBox1.Text;

            Geoprocessor processor = new Geoprocessor();
            processor.OverwriteOutput = true;
            IGPProcess process=null;
            switch (listBox1.SelectedIndex)
            {
                case 0:
                    Intersect intersect = new Intersect();
                    intersect.in_features = "'" + input + "'" + ";" + "'" + overlay + "'";
                    intersect.out_feature_class =output;
                    intersect.output_type = "INPUT";
                    intersect.join_attributes = "ALL";
                    //intersect.cluster_tolerance=0.1;
                    process = intersect;
                    break;
                case 1:
                    Union union = new Union();
                    union.in_features = "'" + input+"'" +";"+"'"+overlay+ "'";
                    union.out_feature_class = @""+output;
                    union.join_attributes = "ALL";
                    //union.cluster_tolerance = 0.1;
                    process = union;
                    break;
                case 2:
                    Erase erase = new Erase();
                    erase.in_features = "'" + input + "'";
                    erase.erase_features = "'" + overlay + "'";
                    erase.out_feature_class = output;
                    //erase.cluster_tolerance = 0.1;
                    process = erase;
                    break;

            }
            processor.Validate(process, true);
            processor.Execute(process, null);
            this.Dispose();

            FileInfo fi = new FileInfo(textBox1.Text);
            string pathDir = fi.Directory.FullName;
            string name = fi.Name;
            IWorkspaceFactory wsf = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace fws = wsf.OpenFromFile(pathDir, 0) as IFeatureWorkspace;
            IFeatureClass featCls = fws.OpenFeatureClass(name);
            IFeatureLayer layer = new FeatureLayerClass();
            layer.FeatureClass = featCls;
            layer.Name = featCls.AliasName;
            m_mapControl.Map.AddLayer(layer as ILayer);
        }
Esempio n. 45
0
        /// <summary>
        /// This uses the bounces to calculate when to stop the collision simulation.
        /// </summary>
        private void findIntersections()
        {
            // If the user wants to generate the collisions from the tessellation, branch to the method that does it, then return
            if (fromTessellation)
            {
                findIntersectionsFromTess();
                return;
            }

            // If the starting point or angle entered was not right, don't continue
            if (startPoint <= 0 || startPoint >= 1 || startAngle <= 0 || startAngle >= 180 || bounces <= 0)
                return;

            // Clear the last simulation done from the collisions List
            collisions.Clear();

            // Find the total starting width, multiply it by the ratio entered (0,1) and add it to the startareas x1 position
            // If you're confused, this is for shapes like the hexagon where the starting area is only a small portion of the shapes width
            double startingPoint = startArea.x1 + (startPoint * Math.Abs(startArea.x1 - startArea.x2));

            DoublePoint tempProjection = null;
            // Reset any member fields
            this.undefCollision = false;
            // Set up the first intersect and data before running through the loop
            Intersect tempInt = new Intersect();
            tempInt.x1 = startingPoint;
            tempInt.x2 = 0d;
            tempInt.wall = 0;
            tempInt.angle = startAngle;
            collisions.Add(tempInt);
            // Perform the loop for each of the bounces
            // At the end of the loop, set the values of intersect[] for i + 1
            for (int i = 0; i < bounces; i++)
            {
                Intersect curIntersect = collisions.ElementAt<Intersect>(i);
                // Temporary variable for finding the collisions with EACH of the walls (to determine which is the least distance
                Intersect[] tempIntersects = new Intersect[numWalls];
                for (int j = 0; j < tempIntersects.Length; j++)
                {
                    tempIntersects[j] = new Intersect();
                }
                // leastDistance is to choose the index of tempIntersects which has the right wall
                int leastDistance = -1;
                // Find the project from the current point, longest possible distance, angle of reflection.
                tempProjection = MathUtilities.findProjection(curIntersect.x1, curIntersect.x2, width, curIntersect.angle);
                double x3 = tempProjection.x1;
                double x4 = tempProjection.x2;
                // For each of the walls
                for (int j = 0; j < numWalls; j++)
                {
                    // If the wall is not the wall that the last collision took place
                    if (curIntersect.wall != j)
                    {
                        int tempMod = (int)MathUtilities.mod(j - 1, numWalls); // Use tempMod to find the correct vertex to determine a line for the current wall
                        // Find the intersect with the current wall
                        DoublePoint temp = MathUtilities.getIntersect(curIntersect.x1, curIntersect.x2, x3, x4, vertexAt(tempMod).x1, vertexAt(tempMod).x2, vertexAt(j).x1, vertexAt(j).x2);
                        if (temp == null)
                            continue;
                        tempIntersects[j].x1 = temp.x1;
                        tempIntersects[j].x2 = temp.x2;
                        tempIntersects[j].wall = j;
                        tempIntersects[j].distance = Math.Sqrt(Math.Pow(curIntersect.x1 - tempIntersects[j].x1, 2) + Math.Pow(curIntersect.x2 - tempIntersects[j].x2, 2));

                        // Run through the current walls' vertices and determine the min and max for the x position and min and max for the y position
                        DoublePoint minXPoint = new DoublePoint();
                        DoublePoint maxXPoint = new DoublePoint();
                        DoublePoint minYPoint = new DoublePoint();
                        DoublePoint maxYPoint = new DoublePoint();
                        if (vertexAt(tempMod).x1 > vertexAt(j).x1)
                        {
                            minXPoint.x1 = vertexAt(j).x1;
                            minXPoint.x2 = vertexAt(j).x2;
                            maxXPoint.x1 = vertexAt(tempMod).x1;
                            maxXPoint.x2 = vertexAt(tempMod).x2;
                        }
                        else
                        {
                            minXPoint.x1 = vertexAt(tempMod).x1;
                            minXPoint.x2 = vertexAt(tempMod).x2;
                            maxXPoint.x1 = vertexAt(j).x1;
                            maxXPoint.x2 = vertexAt(j).x2;
                        }

                        if (vertexAt(tempMod).x2 > vertexAt(j).x2)
                        {
                            minYPoint.x1 = vertexAt(j).x1;
                            minYPoint.x2 = vertexAt(j).x2;
                            maxYPoint.x1 = vertexAt(tempMod).x1;
                            maxYPoint.x2 = vertexAt(tempMod).x2;
                        }
                        else
                        {
                            minYPoint.x1 = vertexAt(tempMod).x1;
                            minYPoint.x2 = vertexAt(tempMod).x2;
                            maxYPoint.x1 = vertexAt(j).x1;
                            maxYPoint.x2 = vertexAt(j).x2;
                        }
                        // Use this data to determine whether the collision we found is actually a valid collision (inside the shape)
                        if (tempIntersects[j].distance > 0 &&
                            tempIntersects[j].x1 >= minXPoint.x1 && tempIntersects[j].x1 <= maxXPoint.x1 &&
                            tempIntersects[j].x2 >= minYPoint.x2 && tempIntersects[j].x2 <= maxYPoint.x2)
                        {   // If it is valid and leastDistance has not yet been set, set it to this index
                            if (leastDistance == -1)
                            {
                                leastDistance = j;
                            }
                            else
                            {   // If it valid and leastDistance has been set, check to see that the new distance is more than the distance at the index marked
                                // by leastDistance, if it is, set leastDistance equal to this index
                                if (tempIntersects[leastDistance].distance > tempIntersects[j].distance)
                                {
                                    leastDistance = j;
                                }
                            }
                        }
                    }
                }
                // After leastDistance has been determined for the current iteration of the algorithm, test to make sure it's not equal to any
                // of the current shapes vertices (which would be illegal)
                for (int j = 0; j < numWalls; j++)
                {
                    if (tempIntersects[leastDistance].x1 == vertexAt(j).x1 && tempIntersects[leastDistance].x2 == vertexAt(j).x2)
                        this.undefCollision = true;
                }
                // If there was an undefined collision found, return and trigger the event that will fill in the boxes with Undef if it detects it
                if (this.undefCollision)
                {
                    EventSource.finishedDrawShape();
                    return;
                }
                // Set fields for the tempIntersect and add it to the current collisions
                double projection = MathUtilities.findAngle(curIntersect.x1, curIntersect.x2, tempIntersects[leastDistance].x1, tempIntersects[leastDistance].x2);
                tempIntersects[leastDistance].angle = MathUtilities.findReflection(projection, walls[leastDistance].x2);
                tempIntersects[leastDistance].wall = leastDistance;
                collisions.Add(tempIntersects[leastDistance]);
            }
            EventSource.finishedDrawShape();
        }
Esempio n. 46
0
 public void IntersectWith(Entity entityPointer, Intersect intersectType, Plane projectionPlane, Point3dCollection points, long thisGraphicSystemMarker, long otherGraphicSystemMarker)
 {
     createInstance();
     BaseEntity.IntersectWith(entityPointer, intersectType, projectionPlane, points, thisGraphicSystemMarker, otherGraphicSystemMarker);
     tr.Dispose();
 }
Esempio n. 47
0
 public void BoundingBoxIntersectWith(Entity entityPointer, Intersect intersectType, Point3dCollection points, IntPtr thisGraphicSystemMarker, IntPtr otherGraphicSystemMarker)
 {
     createInstance();
     BaseEntity.BoundingBoxIntersectWith(entityPointer, intersectType,points,thisGraphicSystemMarker,otherGraphicSystemMarker);
     tr.Dispose();
 }
Esempio n. 48
0
        /// <summary>
        /// This uses this distance to determine when to stop the collision simulation as oppose to the bounces, then calculates the bounces.
        /// </summary>
        private void findIntersectionsFromTess()
        {
            // If the starting point or angle entered was not right, don't continue
            if (startPoint <= 0 || startPoint >= 1 || startAngle <= 0 || startAngle >= 180)
                return;

            // Clear the last simulation done from the collisions List
            collisions.Clear();

            // Find the total starting width, multiply it by the ratio entered (0,1) and add it to the startareas x1 position
            // If you're confused, this is for shapes like the hexagon where the starting area is only a small portion of the shapes width
            double startingPoint = startArea.x1 + (startPoint * Math.Abs(startArea.x1 - startArea.x2));

            // Reset any member fields
            this.undefCollision = false;
            double totalDistance = 0;
            // If the distance from the mouse clicks has not yet been scaled up, scale it up
            if (isNotScaled)
            {
                distance = (this.height / tessShapeHeight) * distance;
                isNotScaled = false;
            }
            DoublePoint tempProjection = null;
            int i = 0;
            bounces = 0;
            // Set up the first intersect and data before running through the loop
            Intersect tempInt = new Intersect();
            tempInt.x1 = startingPoint;
            tempInt.x2 = 0d;
            tempInt.wall = 0;
            tempInt.angle = startAngle;
            collisions.Add(tempInt);
            // Perform the loop for each of the bounces
            // At the end of the loop, set the values of intersect[] for i + 1
            // Determine the distance traveled and if it not yet more than the scaled up distance, keep looping and getting more collisions
            while (totalDistance <= distance - 0.000001d)
            {
                Intersect curIntersect = collisions.ElementAt<Intersect>(i);
                // Temporary variable for finding the collisions with EACH of the walls (to determine which is the least distance
                Intersect[] tempIntersects = new Intersect[numWalls];
                for (int j = 0; j < tempIntersects.Length; j++)
                {
                    tempIntersects[j] = new Intersect();
                }
                // leastDistance is to choose the index of tempIntersects which has the right wall
                int leastDistance = -1;
                // Find the project from the current point, longest possible distance, angle of reflection.
                tempProjection = MathUtilities.findProjection(curIntersect.x1, curIntersect.x2, width, curIntersect.angle);
                double x3 = tempProjection.x1;
                double x4 = tempProjection.x2;
                // For each of the walls
                for (int j = 0; j < numWalls; j++)
                {
                    // If the wall is not the wall that the last collision took place
                    if (curIntersect.wall != j)
                    {
                        int tempMod = (int)MathUtilities.mod(j - 1, numWalls); // Use tempMod to find the correct vertex to determine a line for the current wall
                        // Find the intersect with the current wall
                        DoublePoint temp = MathUtilities.getIntersect(curIntersect.x1, curIntersect.x2, x3, x4, vertexAt(tempMod).x1, vertexAt(tempMod).x2, vertexAt(j).x1, vertexAt(j).x2);
                        if (temp == null)
                            continue;

                        tempIntersects[j].x1 = temp.x1;
                        tempIntersects[j].x2 = temp.x2;
                        tempIntersects[j].wall = j;
                        tempIntersects[j].distance = Math.Sqrt(Math.Pow(curIntersect.x1 - tempIntersects[j].x1, 2) + Math.Pow(curIntersect.x2 - tempIntersects[j].x2, 2));

                        if(MathUtilities.isValidIntersect(vertices, tempIntersects[j], j))
                        {   // If it is valid and leastDistance has not yet been set, set it to this index
                            if (leastDistance == -1)
                            {
                                leastDistance = j;
                            }
                            else
                            {   // If it valid and leastDistance has been set, check to see that the new distance is more than the distance at the index marked
                                // by leastDistance, if it is, set leastDistance equal to this index
                                if (tempIntersects[leastDistance].distance > tempIntersects[j].distance)
                                {
                                    leastDistance = j;
                                }
                            }
                        }
                    }
                }
                // After leastDistance has been determined for the current iteration of the algorithm, test to make sure it's not equal to any
                // of the current shapes vertices (which would be illegal)
                for (int j = 0; j < numWalls; j++)
                {
                    if (tempIntersects[leastDistance].x1 == vertexAt(j).x1 && tempIntersects[leastDistance].x2 == vertexAt(j).x2)
                        this.undefCollision = true;
                }
                // If so, call the event the triggers this and return from this algorithm. Going further could crash this draw function rendering the shape useless
                // .NET quarantines the draw function when it throws an exception for this shape, only way to get around it is to delete the tab containing the shape or close the program
                if (this.undefCollision)
                {
                    EventSource.finishedDrawTess(bounces);
                    EventSource.finishedDrawShape();
                    return;
                }
                // With the current collision, find the angle from the last intersect to this one
                double projection = MathUtilities.findAngle(curIntersect.x1, curIntersect.x2, tempIntersects[leastDistance].x1, tempIntersects[leastDistance].x2);
                tempIntersects[leastDistance].angle = MathUtilities.findReflection(projection, walls[leastDistance].x2);
                tempIntersects[leastDistance].wall = leastDistance;
                // Add the tempIntersect to the collisions container
                collisions.Add(tempIntersects[leastDistance]);
                totalDistance += tempIntersects[leastDistance].distance;
                bounces++;
                i++;
            }
            EventSource.finishedDrawTess(bounces);
            EventSource.finishedDrawShape();
        }