Ejemplo n.º 1
0
        /// <summary>
        /// This method returns a 3D representation of this area
        /// </summary>
        /// <param name="nodesDict">List of all the nodes on the map</param>
        /// <param name="map">bounds of the map</param>
        /// <param name="brush">Color of this area</param>
        /// <returns>ModelUIElement3D of this area</returns>
        public virtual ModelUIElement3D get3DSurface(Dictionary <long, OsmSharp.Osm.Node> nodesDict, Map map, System.Windows.Media.SolidColorBrush brush)
        {
            List <PointF> ptlist = getScaledPointsSurface(nodesDict, map);

            // Divide the polygons in triangles, this is code (and these two classes) are from: https://polygontriangulation.codeplex.com/
            PolygonData     poly      = new PolygonData(ptlist);
            List <PointF[]> triangles = Triangulation2D.Triangulate(poly);

            // Surrounding tags of the mesh
            ModelUIElement3D model         = new ModelUIElement3D();
            GeometryModel3D  geometryModel = new GeometryModel3D();

            // Mesh and his his properties
            MeshGeometry3D    mesh      = new MeshGeometry3D();
            DiffuseMaterial   material  = new DiffuseMaterial((System.Windows.Media.Brush)brush);
            Point3DCollection positions = new Point3DCollection();
            Int32Collection   indices   = new Int32Collection();

            // Add points and indices to their collection
            foreach (PointF[] points in triangles)
            {
                foreach (PointF point in points)
                {
                    positions.Add(new Point3D(point.X, point.Y, height));
                }

                int count = positions.Count;
                indices.Add(count - 3);
                indices.Add(count - 2);
                indices.Add(count - 1);
            }

            // Add these collections to the mesh
            mesh.Positions       = positions;
            mesh.TriangleIndices = indices;

            // Set the color of front and back of the triangle
            geometryModel.Material     = material;
            geometryModel.BackMaterial = material;

            // Add the mesh to the model
            geometryModel.Geometry = mesh;
            model.Model            = geometryModel;

            return(model);
        }
Ejemplo n.º 2
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            int i = 0;

            FOutput.SliceCount = FInput.SliceCount;
            foreach (var input in FInput)
            {
                if (FEnabled[i])
                {
                    if (input.Any())
                    {
                        var polygon   = new Polygon(input.ToList());
                        var triangles = Triangulation2D.Triangulate(polygon);
                        FOutput[i].AssignFrom(triangles.SelectMany(t => t));
                    }
                }
                i++;
            }

            //FLogger.Log(LogType.Debug, "hi tty!");
        }