Example #1
0
        private void GenerateHistogramPoints()
        {
            RedHistogramPoints   = new System.Windows.Media.PointCollection();
            GreenHistogramPoints = new System.Windows.Media.PointCollection();
            BlueHistogramPoints  = new System.Windows.Media.PointCollection();

            int rMax = RedHistogram.Max();
            int gMax = GreenHistogram.Max();
            int bMax = BlueHistogram.Max();

            RedHistogramPoints.Add(new System.Windows.Point(0, rMax));
            GreenHistogramPoints.Add(new System.Windows.Point(0, gMax));
            BlueHistogramPoints.Add(new System.Windows.Point(0, bMax));

            for (int i = 0; i < 255; i++)
            {
                RedHistogramPoints.Add(new System.Windows.Point(i, rMax - RedHistogram[i]));
                GreenHistogramPoints.Add(new System.Windows.Point(i, gMax - GreenHistogram[i]));
                BlueHistogramPoints.Add(new System.Windows.Point(i, bMax - BlueHistogram[i]));
            }
            RedHistogramPoints.Add(new System.Windows.Point(255, rMax));
            GreenHistogramPoints.Add(new System.Windows.Point(255, gMax));
            BlueHistogramPoints.Add(new System.Windows.Point(255, bMax));

            OnPropertyChanged("RedHistogramPoints");
            OnPropertyChanged("BlueHistogramPoints");
            OnPropertyChanged("GreenHistogramPoints");
        }
        private void DrawFacet(NodeModel node, object obj, string tag, RenderDescription rd,
                               Octree.OctreeSearch.Octree octree)
        {
            var facet = obj as Facet;

            if (facet == null)
            {
                return;
            }

            var builder = new MeshBuilder();
            var points  = new Point3DCollection();
            var tex     = new PointCollection();
            var norms   = new Vector3DCollection();
            var tris    = new List <int>();

            var a = facet.Points[0];
            var b = facet.Points[1];
            var c = facet.Points[2];

            var side1 = (b - a).Normalize();
            var side2 = (c - a).Normalize();
            var norm  = side1.CrossProduct(side2);

            int count = 0;

            foreach (var pt in facet.Points)
            {
                points.Add(new Point3D(pt.X, pt.Y, pt.Z));
                tex.Add(new System.Windows.Point(0, 0));
                tris.Add(count);
                norms.Add(new Vector3D(norm.X, norm.Y, norm.Z));
                count++;
            }

            builder.Append(points, tris, norms, tex);

            if (node.IsSelected)
            {
                rd.SelectedMeshes.Add(builder.ToMesh(true));
            }
            else
            {
                rd.Meshes.Add(builder.ToMesh(true));
            }

            if (node.DisplayLabels)
            {
                var cp = (a + b + c) / 3;
                rd.Text.Add(new BillboardTextItem {
                    Text = tag, Position = new Point3D(cp.X, cp.Y, cp.Z)
                });
            }
        }
        private Polygon MCvBox2D2Polygon(MCvBox2D box)
        {
            System.Windows.Media.PointCollection polyPoints = new System.Windows.Media.PointCollection();
            foreach (var p in box.GetVertices())
            {
                polyPoints.Add(new System.Windows.Point(p.X, p.Y));
            }
            Polygon poly = new Polygon();

            poly.Points = polyPoints;
            return(poly);
        }
Example #4
0
        protected void UpdatePointCache()
        {
            vertices          = Dependencies.Where(f => f is IPoint).Cast <IPoint>().ToArray(); // Tolerates non-IPoint dependencies.
            vertexCoordinates = new Point[vertices.Length];
            var cache = new System.Windows.Media.PointCollection();

            Shape.Points = cache;

            for (int i = 0; i < vertices.Length; i++)
            {
                cache.Add(new Point());
            }
        }
 public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value.GetType() == typeof(System.Collections.ObjectModel.ObservableCollection<ColoredPoint>) && targetType == typeof(System.Windows.Media.PointCollection))
     {
         var pointCollection = new System.Windows.Media.PointCollection();
         foreach (var coloredPoint in value as System.Collections.ObjectModel.ObservableCollection<ColoredPoint>)
         {
             if (coloredPoint.IsFromMouse = true && Polygon.Instance.closed == false)
             {
                 //we don't add anything to the polygon canvas until it's closed
             }
             else
             {
                 pointCollection.Add(coloredPoint.point);
             }
         }
         return pointCollection;
     }
     return null;
 }
        /// <summary>
        /// Convert a Revit mesh to a Helix mesh for visualization.
        /// In order to merge mesh vertices, this method uses a dictionary with a string key formed as x:y:z of the point.
        /// This assumes that where vertices are the "same" in the Revit mesh, they will have the same coordinates. This
        /// is NOT a safe strategy to use in other mesh-processing contexts where vertices might have small discrepancies.
        /// </summary>
        /// <param name="rmesh"></param>
        /// <param name="octree"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private static MeshGeometry3D RevitMeshToHelixMesh(Mesh rmesh, Octree.OctreeSearch.Octree octree, NodeModel node)
        {
            var builder = new MeshBuilder();
            var points  = new Point3DCollection();
            var tex     = new PointCollection();
            var norms   = new Vector3DCollection();
            var tris    = new List <int>();

            //A dictionary which will contain a point, a normal, and an index
            //keyed on the location of the point as a hash
            var pointDict = new Dictionary <string, PointData>();

            for (int i = 0; i < rmesh.NumTriangles; ++i)
            {
                var tri = rmesh.get_Triangle(i);
                //calculate the face normal by
                //getting the cross product of two edges
                var a       = tri.get_Vertex(0);
                var b       = tri.get_Vertex(1);
                var c       = tri.get_Vertex(2);
                var e1      = b - a;
                var e2      = c - a;
                var normXYZ = e1.CrossProduct(e2).Normalize();
                var normal  = new Vector3D(normXYZ.X, normXYZ.Y, normXYZ.Z);

                for (int j = 0; j < 3; j++)
                {
                    var pt  = RevitPointToWindowsPoint(tri.get_Vertex(j));
                    var key = pt.X + ":" + pt.Y + ":" + pt.Z;
                    if (!pointDict.ContainsKey(key))
                    {
                        //if the dictionary doesn't contain the key
                        var pd = new PointData(pt.X, pt.Y, pt.Z);
                        pd.Normals.Add(normal);
                        pd.Index = pointDict.Count;
                        pointDict.Add(key, pd);
                        tris.Add(pd.Index);
                    }
                    else
                    {
                        //add an index to our tris array
                        //add a normal to our internal collection
                        //for post processing
                        var data = pointDict[key];
                        tris.Add(data.Index);
                        data.Normals.Add(normal);
                    }
                }
            }

            var lst = pointDict.ToList();

            lst.ForEach(x => points.Add(x.Value.Position));
            lst.ForEach(x => octree.AddNode(x.Value.Position.X, x.Value.Position.Y, x.Value.Position.Z, node.GUID.ToString()));
            lst.ForEach(x => tex.Add(x.Value.Tex));

            //merge the normals
            foreach (var pd in lst)
            {
                var avg   = new Vector3D();
                var nList = pd.Value.Normals;
                foreach (var n in nList)
                {
                    avg.X += n.X;
                    avg.Y += n.Y;
                    avg.Z += n.Z;
                }
                avg.X = avg.X / nList.Count;
                avg.Y = avg.Y / nList.Count;
                avg.Z = avg.Z / nList.Count;
                norms.Add(avg);
            }

            builder.Append(points, tris, norms, tex);
            Debug.WriteLine(string.Format("Mesh had {0} faces coming in and {1} faces going out.", rmesh.NumTriangles, builder.TriangleIndices.Count / 3));

            return(builder.ToMesh(true));
        }
Example #7
0
        private static MeshGeometry3D RevitMeshToHelixMesh(Mesh rmesh, Octree.OctreeSearch.Octree octree, NodeModel node)
        {
            var builder = new MeshBuilder();
            var points  = new Point3DCollection();
            var tex     = new PointCollection();
            var norms   = new Vector3DCollection();
            var tris    = new List <int>();

            for (int i = 0; i < rmesh.NumTriangles; ++i)
            {
                var tri = rmesh.get_Triangle(i);

                //calculate the face normal by
                //getting the cross product of two edges
                var a       = tri.get_Vertex(0);
                var b       = tri.get_Vertex(1);
                var c       = tri.get_Vertex(2);
                var e1      = b - a;
                var e2      = c - a;
                var normXYZ = e1.CrossProduct(e2).Normalize();
                var normal  = new Vector3D(normXYZ.X, normXYZ.Y, normXYZ.Z);

                for (int j = 0; j < 3; j++)
                {
                    var new_point = RevitPointToWindowsPoint(tri.get_Vertex(j));

                    int foundIndex = -1;
                    for (int k = 0; k < points.Count; k++)
                    {
                        var testPt   = points[k];
                        var testNorm = norms[k];

                        if (new_point.X == testPt.X &&
                            new_point.Y == testPt.Y &&
                            new_point.Z == testPt.Z)
                        {
                            foundIndex = k;
                            //average the merged normals
                            norms[k] = (testNorm + normal) / 2;
                            break;
                        }
                    }

                    if (foundIndex != -1)
                    {
                        tris.Add(foundIndex);
                        continue;
                    }

                    tris.Add(points.Count);
                    points.Add(new_point);
                    norms.Add(normal);
                    tex.Add(new System.Windows.Point(0, 0));
                    octree.AddNode(new_point.X, new_point.Y, new_point.Z, node.GUID.ToString());
                }

                builder.Append(points, tris, norms, tex);
            }

            return(builder.ToMesh(true));
        }
        private void RysujKonturChodnika()
        {
            foreach (KrawedzGrafu krawedz in generatorPolaczenPieszych.Chodniki)
            {
                System.Windows.Shapes.Polyline yellowPolyline = new System.Windows.Shapes.Polyline()
                {
                    Stroke          = System.Windows.Media.Brushes.Black,
                    StrokeThickness = 4
                };

                int r = GeneratorLosowosci.Next(0, 10);
                if (r == 0)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.Black;
                }
                if (r == 1)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.Aqua;
                }
                if (r == 2)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.Red;
                }
                if (r == 3)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.Green;
                }
                if (r == 4)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.Honeydew;
                }
                if (r == 5)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.Indigo;
                }
                if (r == 6)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.LightSkyBlue;
                }
                if (r == 7)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.Khaki;
                }
                if (r == 8)
                {
                    yellowPolyline.Stroke = System.Windows.Media.Brushes.PaleVioletRed;
                }

                System.Windows.Media.PointCollection polygonPoints = new System.Windows.Media.PointCollection();
                polygonPoints.Add(new System.Windows.Point(krawedz.WierzcholekA.Pozycja.X * 40 + 20, krawedz.WierzcholekA.Pozycja.Y * 40 + 20));
                polygonPoints.Add(new System.Windows.Point(krawedz.WierzcholekB.Pozycja.X * 40 + 20, krawedz.WierzcholekB.Pozycja.Y * 40 + 20));
                yellowPolyline.Points = polygonPoints;

                Canvas.SetZIndex(yellowPolyline, 4);
                Symulacja.Warstwa.Children.Add(yellowPolyline);
            }

            foreach (WierzcholekChodnika wierzcholek in generatorPolaczenPieszych.WierzcholkiChodnikow)
            {
                TextBlock yellowPolyline = new TextBlock()
                {
                    FontSize = 8,
                    Text     = wierzcholek.Krawedzie.Count.ToString()
                };
                Canvas.SetLeft(yellowPolyline, wierzcholek.Pozycja.X * 40 + 20);
                Canvas.SetTop(yellowPolyline, wierzcholek.Pozycja.Y * 40 + 20);

                Canvas.SetZIndex(yellowPolyline, 5);
                Symulacja.Warstwa.Children.Add(yellowPolyline);
            }
        }
        /// <summary>
        /// Plot the series.  This will remove all the old series.  Then add the
        /// new series lines.
        /// </summary>
        /// <param name="stData">Ship Track data.</param>
        private void PlotMapData(List <ShipTrackData> stDataList)
        {
            // Init the value
            double avgMag = 0.0;
            double avgDir = 0.0;

            // Keep Track of previous point to draw
            // the ship track line
            //LatLon prevLatLon = new LatLon { Latitude = 0.0, Longitude = 0.0, IsGood = false };
            IList <PointLatLng> points = new List <PointLatLng>();

            // Last point
            ShipTrackData lastGoodShipTrack = null;

            foreach (ShipTrackData stData in stDataList)
            {
                avgMag = stData.VelMagDir.AvgMagnitude;
                avgDir = stData.VelMagDir.AvgDirectionYNorth;
                LatLon currLatLon = stData.GetLatLon();

                if (currLatLon.IsGood)
                {
                    // Add the point to the route
                    points.Add(new PointLatLng(currLatLon.Latitude, currLatLon.Longitude));

                    // Convert the value to color from the color map
                    System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush(ColorHM.GetColorForValue(avgMag, _MinValue, _MaxValue));

                    // Mark
                    GMapMarker marker = new GMapMarker(new GMap.NET.PointLatLng(currLatLon.Latitude, currLatLon.Longitude));
                    //System.Windows.Media.BrushConverter converter = new System.Windows.Media.BrushConverter();

                    if (_SelectedPlotOption == PLOT_OPTION_QUIVER)
                    {
                        // Degrees to radian
                        double angle = Math.PI * avgDir / 180.0;

                        marker.Shape = new Line
                        {
                            X1 = 0,
                            Y1 = 0,
                            X2 = (Math.Abs(avgMag) * MagScale) * Math.Cos(angle),
                            Y2 = -((Math.Abs(avgMag) * MagScale) * Math.Sin(angle)),        // Flip the sign
                            StrokeThickness = 3,
                            Stroke          = brush,
                            ToolTip         = string.Format("[{0}] [{1}] Mag: {2} Dir: {3} Range: {4} Heading: {5}", stData.EnsNum, stData.DateTime, avgMag.ToString("0.0"), avgDir.ToString("0.0"), stData.AvgRange.ToString("0.0"), stData.Heading.ToString("0.0")),
                            Name            = string.Format("Line_{0}", stData.EnsNum)
                        };
                        marker.ZIndex = (int)MapLayers.Quiver;
                    }
                    else if (_SelectedPlotOption == PLOT_OPTION_VELOCITY_RECTANGLE)
                    {
                        marker.Shape = new Rectangle
                        {
                            Width   = 20 * MagScale,
                            Height  = 20 * MagScale,
                            Fill    = brush,
                            Stroke  = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent),
                            ToolTip = string.Format("[{0}] [{1}] Mag: {2} Dir: {3} Range: {4} Heading: {5}", stData.EnsNum, stData.DateTime, avgMag.ToString("0.0"), avgDir.ToString("0.0"), stData.AvgRange.ToString("0.0"), stData.Heading.ToString("0.0")),
                            Name    = string.Format("Rect_Vel_{0}", stData.EnsNum)
                        };
                        marker.ZIndex = (int)MapLayers.Velocity_Rectangle;
                    }
                    else if (_SelectedPlotOption == PLOT_OPTION_BT_RANGE)
                    {
                        // Convert the average Range to color from the color map
                        brush = new System.Windows.Media.SolidColorBrush(ColorHM.GetColorForValue(stData.AvgRange, _MinValue, _MaxValue));

                        marker.Shape = new Rectangle
                        {
                            Width   = 20 * MagScale,
                            Height  = 20 * MagScale,
                            Fill    = brush,
                            Stroke  = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent),
                            ToolTip = string.Format("[{0}] [{1}] Mag: {2} Dir: {3} Range: {4} Heading: {5}", stData.EnsNum, stData.DateTime, avgMag.ToString("0.0"), avgDir.ToString("0.0"), stData.AvgRange.ToString("0.0"), stData.Heading.ToString("0.0")),
                            Name    = string.Format("Rect_Range_{0}", stData.EnsNum)
                        };
                        marker.ZIndex = (int)MapLayers.Range_Rectangle;
                    }

                    // Record the last point to get a special marker
                    lastGoodShipTrack = stData;

                    // Add the marker to the list
                    Markers.Add(marker);
                }
            }



            // Plot the path that we taken
            GMapRoute route = new GMapRoute(points);

            System.Windows.Media.SolidColorBrush routeBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
            routeBrush.Opacity = 0.4;
            route.Shape        = new System.Windows.Shapes.Path()
            {
                StrokeThickness = 3, Stroke = routeBrush, Fill = routeBrush
            };
            route.ZIndex = (int)MapLayers.Ship_Track_Line;
            Markers.Add(route);

            // Add a marker for the last point to know which direction it traveled
            if (lastGoodShipTrack != null)
            {
                LatLon lastLatLon = lastGoodShipTrack.GetLatLon();

                if (lastLatLon.IsGood)
                {
                    GMapMarker lastMarker = new GMapMarker(new GMap.NET.PointLatLng(lastLatLon.Latitude, lastLatLon.Longitude));
                    if (IsLastMarkerEllipse)
                    {
                        lastMarker.Shape = new Ellipse
                        {
                            //Points = trianglePts,
                            RenderTransform = new System.Windows.Media.TranslateTransform(-((1 * LastMarkerScale) / 2), -((1 * LastMarkerScale) / 2)),
                            Width           = 1 * LastMarkerScale,
                            Height          = 1 * LastMarkerScale,
                            Fill            = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Yellow),
                            Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red),
                            ToolTip         = string.Format("[{0}] [{1}] Mag: {2} Dir: {3} Range: {4} Heading: {5}", lastGoodShipTrack.EnsNum, lastGoodShipTrack.DateTime, avgMag.ToString("0.0"), avgDir.ToString("0.0"), lastGoodShipTrack.AvgRange.ToString("0.0"), lastGoodShipTrack.Heading.ToString("0.0"))
                        };
                    }
                    else
                    {
                        System.Windows.Media.PointCollection trianglePts = new System.Windows.Media.PointCollection();
                        //trianglePts.Add(new Point(0.0, 1.0 * LastMarkerScale));
                        //trianglePts.Add(new Point(0.0, -1.0 * LastMarkerScale));
                        //trianglePts.Add(new Point(-1.0 * LastMarkerScale, 0.0));
                        trianglePts.Add(new Point(-1.0 * LastMarkerScale, 0.0));
                        trianglePts.Add(new Point(1.0 * LastMarkerScale, 0.0));
                        trianglePts.Add(new Point(0.0, -1.0 * LastMarkerScale));
                        lastMarker.Shape = new Polygon
                        {
                            Points          = trianglePts,
                            RenderTransform = new System.Windows.Media.RotateTransform(lastGoodShipTrack.Heading),
                            Fill            = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Yellow),
                            Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red),
                            ToolTip         = string.Format("[{0}] [{1}] Mag: {2} Dir: {3} Range: {4} Heading: {5}", lastGoodShipTrack.EnsNum, lastGoodShipTrack.DateTime, avgMag.ToString("0.0"), avgDir.ToString("0.0"), lastGoodShipTrack.AvgRange.ToString("0.0"), lastGoodShipTrack.Heading.ToString("0.0"))
                        };
                    }

                    // Set the zIndex so we can filter the layers
                    lastMarker.ZIndex = (int)MapLayers.Last_Point;

                    // Add the last point to the end
                    Markers.Add(lastMarker);
                }
            }

            // Set the center position
            Position = GetCenterPoint(Markers);
            Zoom     = 17;
        }
        /// <summary>
        /// Convert a Revit mesh to a Helix mesh for visualization.
        /// In order to merge mesh vertices, this method uses a dictionary with a string key formed as x:y:z of the point.
        /// This assumes that where vertices are the "same" in the Revit mesh, they will have the same coordinates. This
        /// is NOT a safe strategy to use in other mesh-processing contexts where vertices might have small discrepancies.
        /// </summary>
        /// <param name="rmesh"></param>
        /// <param name="octree"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private static MeshGeometry3D RevitMeshToHelixMesh(Mesh rmesh, Octree.OctreeSearch.Octree octree, NodeModel node)
        {
            var builder = new MeshBuilder();
            var points = new Point3DCollection();
            var tex = new PointCollection();
            var norms = new Vector3DCollection();
            var tris = new List<int>();

            //A dictionary which will contain a point, a normal, and an index
            //keyed on the location of the point as a hash
            var pointDict = new Dictionary<string, PointData>();
            for (int i = 0; i < rmesh.NumTriangles; ++i)
            {
                var tri = rmesh.get_Triangle(i);
                //calculate the face normal by
                //getting the cross product of two edges
                var a = tri.get_Vertex(0);
                var b = tri.get_Vertex(1);
                var c = tri.get_Vertex(2);
                var e1 = b - a;
                var e2 = c - a;
                var normXYZ = e1.CrossProduct(e2).Normalize();
                var normal = new Vector3D(normXYZ.X, normXYZ.Y, normXYZ.Z);

                for (int j = 0; j < 3; j++)
                {
                    var pt = RevitPointToWindowsPoint(tri.get_Vertex(j));
                    var key = pt.X + ":" + pt.Y + ":" + pt.Z;
                    if (!pointDict.ContainsKey(key))
                    {
                        //if the dictionary doesn't contain the key
                        var pd = new PointData(pt.X,pt.Y,pt.Z);
                        pd.Normals.Add(normal);
                        pd.Index = pointDict.Count;
                        pointDict.Add(key, pd);
                        tris.Add(pd.Index);
                    }
                    else
                    {
                        //add an index to our tris array
                        //add a normal to our internal collection
                        //for post processing
                        var data = pointDict[key];
                        tris.Add(data.Index);
                        data.Normals.Add(normal);
                    }
                }
            }

            var lst = pointDict.ToList();
            lst.ForEach(x => points.Add(x.Value.Position));
            lst.ForEach(x=>octree.AddNode(x.Value.Position.X, x.Value.Position.Y, x.Value.Position.Z, node.GUID.ToString()));
            lst.ForEach(x=>tex.Add(x.Value.Tex));

            //merge the normals
            foreach (var pd in lst)
            {
                var avg = new Vector3D();
                var nList = pd.Value.Normals;
                foreach (var n in nList)
                {
                    avg.X += n.X;
                    avg.Y += n.Y;
                    avg.Z += n.Z;
                }
                avg.X = avg.X / nList.Count;
                avg.Y = avg.Y / nList.Count;
                avg.Z = avg.Z / nList.Count;
                norms.Add(avg);
            }

            builder.Append(points, tris, norms, tex);
            Debug.WriteLine(string.Format("Mesh had {0} faces coming in and {1} faces going out.", rmesh.NumTriangles, builder.TriangleIndices.Count / 3));

            return builder.ToMesh(true);
        }
        private void DrawFacet(NodeModel node, object obj, string tag, RenderDescription rd,
            Octree.OctreeSearch.Octree octree)
        {
            var facet = obj as Facet;
            if (facet == null)
                return;

            var builder = new MeshBuilder();
            var points = new Point3DCollection();
            var tex = new PointCollection();
            var norms = new Vector3DCollection();
            var tris = new List<int>();

            var a = facet.Points[0];
            var b = facet.Points[1];
            var c = facet.Points[2];

            var side1 = (b - a).Normalize();
            var side2 = (c - a).Normalize();
            var norm = side1.CrossProduct(side2);

            int count = 0;
            foreach (var pt in facet.Points)
            {
                points.Add(new Point3D(pt.X,pt.Y,pt.Z));
                tex.Add(new System.Windows.Point(0,0));
                tris.Add(count);
                norms.Add(new Vector3D(norm.X,norm.Y,norm.Z));
                count++;
            }

            builder.Append(points, tris, norms, tex);

            if (node.IsSelected)
            {
                rd.SelectedMeshes.Add(builder.ToMesh(true));
            }
            else
            {
                rd.Meshes.Add(builder.ToMesh(true));
            }

            if (node.DisplayLabels)
            {
                var cp = (a + b + c)/3;
                rd.Text.Add(new BillboardTextItem { Text = tag, Position = new Point3D(cp.X,cp.Y,cp.Z)});
            }
        }
        private void ReadMapData()
        {
            Excel.Application excelApp = null;
            Excel.Workbook    wb       = null;
            Excel.Worksheet   ws       = null;

            try
            {
                excelApp = new Excel.Application();
                wb       = excelApp.Workbooks.Open(Environment.CurrentDirectory.ToString() + "\\seoul.xls");
                ws       = wb.Worksheets.get_Item(1) as Excel.Worksheet;
                Excel.Range rng = ws.UsedRange;

                object[,] data = rng.Value;

                int r = 1;
                for (int i = 0; i < 25; i++)
                {
                    Polygon p = new Polygon();
                    p.Name = data[r, 2].ToString().Replace("-", "");
                    System.Windows.Media.PointCollection pc = new System.Windows.Media.PointCollection();
                    List <GeoCoordinate> pList = new List <GeoCoordinate>();
                    r++;

                    for (int j = r; j <= data.GetLength(0); j++)
                    {
                        try
                        {
                            if ((data[j, 2].ToString().Equals("name") && pc.Count != 0) || j == data.GetLength(0))
                            {
                                p.Points = pc;
                                polygonList.Add(p);
                                polyCoordList.Add(pList);
                                r = j;
                                break;
                            }
                            else
                            {
                                float lat      = float.Parse(data[j, 1].ToString());
                                float lon      = float.Parse(data[j, 2].ToString());
                                int   pixelRow = Utils.TransformLatToPixel(lat);
                                int   pixelCol = Utils.TransformLonToPixel(lon);
                                pc.Add(new System.Windows.Point(pixelCol, pixelRow));
                                pList.Add(new GeoCoordinate(lat, lon));
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }

                wb.Close(true);
                excelApp.Quit();
            }
            finally
            {
                ReleaseExcelObject(ws);
                ReleaseExcelObject(wb);
                ReleaseExcelObject(excelApp);
            }
        }
Example #13
0
 static System.Windows.Media.PointCollection ShiftPoints(System.Windows.Media.PointCollection input, System.Windows.Vector shift)
 {
     System.Windows.Media.PointCollection pc = new System.Windows.Media.PointCollection(input.Count);
     foreach (System.Windows.Point s in input)
     {
         pc.Add(s + shift );
     }
     return pc;
 }
Example #14
0
 static System.Windows.Media.PointCollection GetPointsFromString(string input)
 {
     System.Windows.Media.PointCollection pts = new System.Windows.Media.PointCollection();
     string[] splitter = input.Split(' ');
     foreach (string point in splitter)
     {
         string[] parts = point.Split(',');
         if (parts.Length == 2)
         {
             pts.Add(new System.Windows.Point(double.Parse(parts[0]), double.Parse(parts[1])));
         }
     }
     return pts;
 }