Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        public CoordinateSystemNode()
        {
            var builder = new MeshBuilder(true, false, false);

            builder.AddArrow(Vector3.Zero, new Vector3(arrowSize, 0, 0), arrowWidth, arrowHead, 8);
            builder.AddArrow(Vector3.Zero, new Vector3(0, arrowSize, 0), arrowWidth, arrowHead, 8);
            builder.AddArrow(Vector3.Zero, new Vector3(0, 0, arrowSize), arrowWidth, arrowHead, 8);
            var mesh = builder.ToMesh();

            arrowMeshModel.Material = new PhongMaterialCore()
            {
                DiffuseColor = Color.White
            };
            arrowMeshModel.Geometry              = mesh;
            arrowMeshModel.CullMode              = CullMode.Back;
            arrowMeshModel.OnSetRenderTechnique += (host) => { return(host.EffectsManager[DefaultRenderTechniqueNames.Colors]); };
            arrowMeshModel.IsHitTestVisible      = false;
            arrowMeshModel.RenderCore.RenderType = RenderType.ScreenSpaced;

            axisBillboard.IsHitTestVisible       = false;
            axisBillboard.RenderCore.RenderType  = RenderType.ScreenSpaced;
            axisBillboard.EnableViewFrustumCheck = false;
            var axisLabel = new BillboardText3D();

            axisLabel.TextInfo.Add(new TextInfo());
            axisLabel.TextInfo.Add(new TextInfo());
            axisLabel.TextInfo.Add(new TextInfo());
            axisBillboard.Geometry = axisLabel;
            UpdateAxisColor(mesh, 0, AxisXColor, LabelX, LabelColor);
            UpdateAxisColor(mesh, 1, AxisYColor, LabelY, LabelColor);
            UpdateAxisColor(mesh, 2, AxisZColor, LabelZ, LabelColor);

            this.AddChildNode(arrowMeshModel);
            this.AddChildNode(axisBillboard);
        }
        public CoordinateSystemModel3D()
        {
            var builder = new MeshBuilder(true, false, false);

            builder.AddArrow(Vector3.Zero, new Vector3(10, 0, 0), 1, 2, 10);
            builder.AddArrow(Vector3.Zero, new Vector3(0, 10, 0), 1, 2, 10);
            builder.AddArrow(Vector3.Zero, new Vector3(0, 0, 10), 1, 2, 10);
            var mesh = builder.ToMesh();

            this.Material     = PhongMaterials.White;
            axisBillboards[0] = new BillboardTextModel3D()
            {
                IsHitTestVisible = false
            };
            axisBillboards[1] = new BillboardTextModel3D()
            {
                IsHitTestVisible = false
            };
            axisBillboards[2] = new BillboardTextModel3D()
            {
                IsHitTestVisible = false
            };
            UpdateAxisColor(mesh, 0, AxisXColor.ToColor4());
            UpdateAxisColor(mesh, 1, AxisYColor.ToColor4());
            UpdateAxisColor(mesh, 2, AxisZColor.ToColor4());
            Geometry = mesh;
            CullMode = CullMode.Back;
        }
            private void UpdateModel()
            {
                var builder = new MeshBuilder(true, false, false);

                builder.AddArrow(Vector3.Zero, new Vector3(arrowSize, 0, 0), arrowWidth, arrowHead, 8);
                builder.AddArrow(Vector3.Zero, new Vector3(0, arrowSize, 0), arrowWidth, arrowHead, 8);
                builder.AddArrow(Vector3.Zero, new Vector3(0, 0, arrowSize), arrowWidth, arrowHead, 8);

                var mesh = builder.ToMesh();

                arrowMeshModel.Geometry = mesh;
                UpdateAxisColor(arrowMeshModel.Geometry, 0, AxisXColor, LabelX, LabelColor);
                UpdateAxisColor(arrowMeshModel.Geometry, 1, AxisYColor, LabelY, LabelColor);
                UpdateAxisColor(arrowMeshModel.Geometry, 2, AxisZColor, LabelZ, LabelColor);
            }
Esempio n. 4
0
        protected override MeshGeometry3D Tessellate()
        {
            var builder = new MeshBuilder(true, true);

            builder.AddArrow(Point1, Point2, Diameter, 3, ThetaDiv);
            return(builder.ToMesh());
        }
        private static GeometryModel3D GetCountryEllipsoidArrowGeometry(
            double latitude,
            double longitude,
            int booksCount,
            Color color)
        {
            PolygonPoint latLong = new PolygonPoint {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);
            double height = 1 + Math.Log(booksCount);

            GeometryModel3D countryGeometry = new GeometryModel3D();
            SolidColorBrush brush           = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));

            countryGeometry.Material = MaterialHelper.CreateMaterial(brush, ambient: 177);
            MeshBuilder meshBuilder = new MeshBuilder(false, false);

            Point3D countryPoint = new Point3D(x, y, 0);

            meshBuilder.AddEllipsoid(countryPoint, 1.0, 1.0, height);

            Point3D top       = new Point3D(x, y, height);
            Point3D textStart = new Point3D(x, y + 1, height + 1);

            meshBuilder.AddArrow(textStart, top, 0.1);

            countryGeometry.Geometry = meshBuilder.ToMesh();
            return(countryGeometry);
        }
Esempio n. 6
0
        public void Addwire(dynamic pos1, dynamic pos2, string color)
        {
            try
            {
                if (!Properties.Settings.Default.colorwires)
                {
                    color = Properties.Settings.Default.wirecolor.Substring(1, 6);
                }
                Material material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(Properties.Settings.Default.coloropacity,
                                                                                           Convert.ToByte(color.Substring(0, 2), 16), Convert.ToByte(color.Substring(2, 2), 16), Convert.ToByte(color.Substring(4, 2), 16))));

                var meshBuilder = new MeshBuilder(false, false);

                meshBuilder.AddArrow(new Point3D(Convert.ToDouble(pos1.x.ToString()),
                                                 Convert.ToDouble(pos1.y.ToString()),
                                                 Convert.ToDouble(pos1.z.ToString())),
                                     new Point3D(Convert.ToDouble(pos2.x.ToString()),
                                                 Convert.ToDouble(pos2.y.ToString()),
                                                 Convert.ToDouble(pos2.z.ToString())),
                                     0.15, 4);
                var Mesh = meshBuilder.ToMesh(true);
                this.Wires.Children.Add(new GeometryModel3D {
                    Geometry = Mesh, Material = material
                });
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "wire render failed");
            }
        }
        private GeometryModel3D GetCountryHelixArrowGeometry(
            double latitude, double longitude, double height, OxyColor color)
        {
            PolygonPoint latLong = new PolygonPoint()
            {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);

            GeometryModel3D countryGeometry = new GeometryModel3D();
            var             brush           = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));

            countryGeometry.Material = MaterialHelper.CreateMaterial(brush, ambient: 177);
            var meshBuilder = new MeshBuilder(false, false);

            var top          = new Point3D(x, y, height);
            var countryPoint = new Point3D(x, y, 0);

            meshBuilder.AddCone(top, countryPoint, 1.0, true, 16);

            var textStart = new Point3D(x, y + 1, height + 1);

            meshBuilder.AddArrow(textStart, top, 0.1);

            countryGeometry.Geometry = meshBuilder.ToMesh();
            return(countryGeometry);
        }
        static TransformManipulator3D()
        {
            var   bd          = new MeshBuilder();
            float arrowLength = 1.5f;

            bd.AddArrow(Vector3.UnitX * arrowLength, new Vector3(1.2f * arrowLength, 0, 0), 0.08, 4, 12);
            bd.AddCylinder(Vector3.Zero, Vector3.UnitX * arrowLength, 0.04, 12);
            TranslationXGeometry = bd.ToMesh();

            bd = new MeshBuilder();
            var circle = MeshBuilder.GetCircle(32, true);
            var path   = circle.Select(x => new Vector3(0, x.X, x.Y)).ToArray();

            bd.AddTube(path, 0.06, 8, true);
            RotationXGeometry = bd.ToMesh();

            bd = new MeshBuilder();
            bd.AddBox(Vector3.UnitX * 0.8f, 0.15, 0.15, 0.15);
            bd.AddCylinder(Vector3.Zero, Vector3.UnitX * 0.8f, 0.02, 4);
            ScalingGeometry = bd.ToMesh();

            TranslationXGeometry.OctreeParameter.MinimumOctantSize = 0.01f;
            TranslationXGeometry.UpdateOctree();

            RotationXGeometry.OctreeParameter.MinimumOctantSize = 0.01f;
            RotationXGeometry.UpdateOctree();

            ScalingGeometry.OctreeParameter.MinimumOctantSize = 0.01f;
            ScalingGeometry.UpdateOctree();
        }
Esempio n. 9
0
        private void UpdateModel()
        {
            // http://en.wikipedia.org/wiki/Lorenz_attractor
            Func <double[], double[]> lorenzAttractor = x =>
            {
                var dx = new double[3];
                dx[0] = sigma * (x[1] - x[0]);
                dx[1] = x[0] * (rho - x[2]) - x[1];
                dx[2] = x[0] * x[1] - beta * x[2];
                return(dx);
            };
            // solve the ODE
            var x0 = new[] { 0, 1, 1.05 };
            IEnumerable <double[]> solution = EulerSolver(lorenzAttractor, x0, 25);
            // todo: should have a better ODE solver (R-K(4,5)? http://www.mathworks.com/help/techdoc/ref/ode45.html)
            List <Point3D> path = solution.Select(x => new Point3D(x[0], x[1], x[2])).ToList();

            // create the WPF3D model
            var m  = new Model3DGroup();
            var gm = new MeshBuilder();

            gm.AddTube(path, 0.8, 10, false);
            if (directionArrows)
            {
                // sphere at the initial point
                gm.AddSphere(path[0], 1);
                // arrow heads every 100 point
                for (int i = 100; i + 1 < path.Count; i += 100)
                {
                    gm.AddArrow(path[i], path[i + 1], 0.8);
                }
                // arrow head at the end
                Point3D p0 = path[path.Count - 2];
                Point3D p1 = path[path.Count - 1];
                var     d  = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
                d.Normalize();
                Point3D p2 = p1 + d * 2;
                gm.AddArrow(p1, p2, 0.8);
            }

            m.Children.Add(new GeometryModel3D(gm.ToMesh(), Materials.Gold));

            Model = m;
        }
        public static MeshGeometry3D ToGeometry3D(this Vector3D vector, Point3D point = new Point3D())
        {
            var meshBuilder = new MeshBuilder();

            var startPoint = point;
            var endPoint   = point + vector;

            meshBuilder.AddArrow(startPoint, endPoint, 0.1);

            return(meshBuilder.ToMesh());
        }
        /// <summary>
        ///   Called when geometry has been changed.
        /// </summary>
        protected override void OnGeometryChanged()
        {
            var mb = new MeshBuilder(false, false);
            var p0 = new Point3D(0, 0, 0);
            var d  = this.Direction;

            d.Normalize();
            var p1 = p0 + (d * this.Length);

            mb.AddArrow(p0, p1, this.Diameter);
            this.Model.Geometry = mb.ToMesh();
        }
Esempio n. 12
0
        /// <summary>
        /// Do the tesselation and return the <see cref="MeshGeometry3D"/>.
        /// </summary>
        /// <returns>A triangular mesh geometry.</returns>
        protected override MeshGeometry3D Tessellate()
        {
            if (this.Diameter <= 0)
            {
                return(null);
            }

            var builder = new MeshBuilder(true, true);

            builder.AddArrow(this.Point1, this.Point2, this.Diameter, this.HeadLength, this.ThetaDiv);
            return(builder.ToMesh());
        }
Esempio n. 13
0
        /// <summary>
        /// Called when geometry has been changed.
        /// </summary>
        protected override void OnModelChanged()
        {
            var mb = new MeshBuilder();
            var p0 = this.Offset;// new Vector3(0, 0, 0);
            var d  = this.Direction;

            d.Normalize();
            var p1 = p0 + (d * (float)this.Length);

            mb.AddArrow(p0, p1, this.Diameter, 2, 64);
            this.Geometry = mb.ToMeshGeometry3D();
        }
        static StartPositionMarker3D()
        {
            var builder = new MeshBuilder();

            var baseHeight = 0.075f;
            var halfHeight = baseHeight / 2f;
            var baseRadius = 0.2f;

            builder.AddCylinder(Vector3.Zero, new Vector3(0, 0, baseHeight), baseRadius, 18, true, true);
            builder.AddArrow(new Vector3(0, 0, halfHeight), new Vector3(baseRadius * 1.6f, 0, halfHeight), halfHeight, 3, 18);

            MarkerGeometry = builder.ToMesh();
        }
Esempio n. 15
0
        public void Tesellate()
        {
            var builder = new MeshBuilder(false, false);

            builder.AddArrow(Position, Position + new Vector3D(0, 1, 0) * Length, Diameter);

            m_yArrow.Model = new GeometryModel3D(builder.ToMesh(true), RedMat)
            {
                BackMaterial = RedMat
            };

            // builder.Clear();
            builder.AddArrow(Position, Position + new Vector3D(1, 0, 0) * Length, Diameter);

            m_xArrow.Model = new GeometryModel3D(builder.ToMesh(true), BlueMat)
            {
                BackMaterial = BlueMat
            };

            //   builder.Clear();
            builder.AddArrow(Position, Position + new Vector3D(-0.70, -0.70, 0) * Length, Diameter);

            m_zArrow.Model = new GeometryModel3D(builder.ToMesh(true), GreenMat)
            {
                BackMaterial = GreenMat
            };

            //  builder.Clear();
            var pos  = Position;
            var axis = new Vector3D(0, 0, 1);

            builder.AddPipe(pos - axis * 0.1 * 0.5, pos + axis * 0.1 * 0.5, 2.4, 2.7, 60);

            m_zPipe.Model = new GeometryModel3D(builder.ToMesh(true), GoldMat)
            {
                BackMaterial = GoldMat
            };
        }
Esempio n. 16
0
        static DecalMarker3D()
        {
            var builder = new MeshBuilder();

            var baseHeight = 0.05f;
            var halfHeight = baseHeight / 2f;
            var sideLength = 0.4f;

            builder.AddBox(Vector3.UnitZ * halfHeight, Vector3.UnitX, Vector3.UnitY, sideLength, sideLength, baseHeight);
            builder.AddCylinder(Vector3.Zero, new Vector3(0, 0, sideLength * 0.6f), halfHeight / 2f, 18, true, true);
            builder.AddArrow(new Vector3(0, 0, halfHeight), new Vector3(sideLength * 0.9f, 0, halfHeight), halfHeight, 3, 18);

            MarkerGeometry = builder.ToMesh();
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value != null) && (value is MVMIH.IPositionHandle ph))
            {
                var me     = ph as IMachineElement;
                var parent = me.Parent;
                var eh     = parent as MVMIH.IElementHandle;

                if (eh != null)
                {
                    var bb        = new BoundingBox(new Vector3((float)eh.MinX, (float)eh.MinY, (float)eh.MinZ), new Vector3((float)eh.MaxX, (float)eh.MaxY, (float)eh.MaxZ));
                    var c         = bb.Center();
                    var diameter  = GetDiameter(bb, ph.Type);
                    var distance  = GetDistance(bb, ph.Type);
                    var length    = diameter * 5.0f;
                    var direction = GetDirection(ph.Type);
                    var p1        = c + direction * distance;
                    var p2        = c - direction * distance;
                    var p3        = c + direction * (distance + length);
                    var p4        = c - direction * (distance + length);
                    var builder   = new MeshBuilder();

                    builder.AddArrow(p1, p3, diameter);
                    builder.AddArrow(p2, p4, diameter);

                    return(builder.ToMesh());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 18
0
        private GeometryModel3D GetGeometryArrow(Point3D start, Point3D end)
        {
            MeshBuilder meshBuilder = new MeshBuilder(false, false);

            meshBuilder.AddArrow(start, end, PointSize);
            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            return(new GeometryModel3D
            {
                Geometry = mesh,
                Material = defaultMaterial,
                BackMaterial = insideMaterial
            });
        }
Esempio n. 19
0
        /// <summary>
        /// Updates the visuals.
        /// </summary>
        protected virtual void OnMeshChanged()
        {
            this.Children.Clear();

            var builder = new MeshBuilder();

            for (int i = 0; i < this.Mesh.Positions.Count; i++)
            {
                builder.AddArrow(
                    this.Mesh.Positions[i], this.Mesh.Positions[i] + this.Mesh.Normals[i], this.Diameter, 3, 10);
            }

            this.Content = new GeometryModel3D
            {
                Geometry = builder.ToMesh(true), Material = MaterialHelper.CreateMaterial(this.Color)
            };
        }
        static SpawnPointMarker3D()
        {
            var builder = new MeshBuilder();

            var baseHeight = 0.075f;
            var halfHeight = baseHeight / 2f;
            var baseRadius = 0.2f;

            builder.AddCylinder(Vector3.Zero, new Vector3(0, 0, baseHeight), baseRadius, 18, true, true);
            builder.AddArrow(new Vector3(0, 0, halfHeight), new Vector3(baseRadius * 1.6f, 0, halfHeight), halfHeight, 3, 18);

            var diamondSize = 0.3f;

            builder.AddOctahedron(new Vector3(0f, 0f, diamondSize * 1.5f), Vector3.UnitX, Vector3.UnitZ, diamondSize, diamondSize);
            builder.AddOctahedron(new Vector3(0f, 0f, diamondSize * 0.5f), Vector3.UnitX, -Vector3.UnitZ, diamondSize, diamondSize);

            MarkerGeometry = builder.ToMesh();
        }
        private GeometryModel3D GetCountryOctahedronGeometry(
            double latitude, double longitude, double height, OxyColor color, int books, Uri image = null)
        {
            PolygonPoint latLong = new PolygonPoint()
            {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);

            GeometryModel3D countryGeometry = new GeometryModel3D();
            var             brush           = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));

            countryGeometry.Material = MaterialHelper.CreateMaterial(brush, ambient: 177);

            var meshBuilder = new MeshBuilder(false, false);

            var top          = new Point3D(x, y, height);
            var countryPoint = new Point3D(x, y, 0);

            Vector3D normalVector = new Vector3D(1, 1, 0);
            Vector3D upVector     = new Vector3D(0, 0, 1);

            meshBuilder.AddCone(top, countryPoint, 1.0, true, 16);

            double side = (1 + Math.Log(books)) / Math.Log(3);

            meshBuilder.AddOctahedron(countryPoint, normalVector, upVector, side, height);

            var textStart = new Point3D(x, y + 1, height + 1);

            meshBuilder.AddArrow(textStart, top, 0.1);

            countryGeometry.Geometry = meshBuilder.ToMesh();
            return(countryGeometry);
        }
Esempio n. 22
0
        public void UpdateAll()
        {
            Model3DGroup group = Model as Model3DGroup;
            Material mat = Materials.Red;

            BuildDoors();

            group.Children.Clear();

            if (_doorObjects != null)
            {
                foreach (var dr in _doorObjects)
                {
                    var builder = new MeshBuilder();
                    var transforms = dr.GetTransforms();
                    if (dr.Polygons.ElementAt(0).BitmapInfo != null)
                    {
                        var img = dr.Polygons.ElementAt(0).BitmapInfo.Image;
                        var brush = new System.Windows.Media.ImageBrush(img);
                        brush.ViewportUnits = System.Windows.Media.BrushMappingMode.Absolute;
                        brush.TileMode = System.Windows.Media.TileMode.Tile;
                        mat = HelixToolkit.Wpf.MaterialHelper.CreateMaterial(brush);
                    }
                    else
                    {
                        mat = Materials.LightGray;
                    }

                    foreach (var poly in dr.Polygons)
                    {
                        Point3D p1 = new Point3D(poly.V1.X, poly.V1.Y, poly.V1.Z);
                        Point3D p2 = new Point3D(poly.V2.X, poly.V2.Y, poly.V2.Z);
                        Point3D p3 = new Point3D(poly.V3.X, poly.V3.Y, poly.V3.Z);

                        foreach (var transform in transforms)
                        {
                            p1 = transform.Transform(p1);
                            p2 = transform.Transform(p2);
                            p3 = transform.Transform(p3);
                        }

                        if (!Clipping.DrawPoint(p1) || !Clipping.DrawPoint(p2) || !Clipping.DrawPoint(p3))
                        {
                            continue;
                        }

                        var t1 = new System.Windows.Point(poly.V1.U, 1 - poly.V1.V);
                        var t2 = new System.Windows.Point(poly.V2.U, 1 - poly.V2.V);
                        var t3 = new System.Windows.Point(poly.V3.U, 1 - poly.V3.V);
                        //builder.AddTriangle(p3, p2, p1, t3, t2, t1);
                        builder.AddTriangle(p1, p2, p3, t1, t2, t3);
                    }
                    group.Children.Add(new GeometryModel3D(builder.ToMesh(), mat));
                }
            }

            var rotate = new RotateTransform3D();
            rotate.Rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90);
            foreach (var door in _manager.Doors)
            {
                var bbuilder = new MeshBuilder();
                Material mater = Materials.Red;

                if (_selected != null && _selected.Contains(door))
                {
                    mater = Materials.Blue;
                }

                var pcenter = new Point3D(door.X, door.Y, door.Z);
                rotate.CenterX = pcenter.X;
                rotate.CenterY = pcenter.Y;

                float radius = 3.0f;
                double hx = pcenter.X + Math.Cos((door.HeadingDegrees - 90) / 180 * Math.PI) * radius;
                double hy = pcenter.Y + Math.Sin((door.HeadingDegrees + 90) / 180 * Math.PI) * radius;

                var p = rotate.Transform(new Point3D(hx, hy, door.Z));

                //bbuilder.AddArrow(pcenter, new Point3D(hx, hy, door.Z), 0.5, 1);
                bbuilder.AddArrow(pcenter,p, 0.5, 1);
                bbuilder.AddBox(pcenter, 0.5, 0.5, 20);

                group.Children.Add(new GeometryModel3D(bbuilder.ToMesh(), mater));
            }
        }
Esempio n. 23
0
        private void CreateGrid(Grid grid)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(grid))
            {
                foreach (Model3D model in _mapping[grid])
                {
                    group.Children.Remove(model);
                }
            }

            foreach (Waypoint wp in grid.Waypoints)
            {
                MeshBuilder builder = new MeshBuilder();
                Point3D p = new Point3D(wp.X,wp.Y,wp.Z);

                if (Clipping != null && !Clipping.DrawPoint(p)) continue;
                builder.AddBox(p, 2, 2, 2);

                Transform3D headingRotate = new RotateTransform3D()
                {
                    CenterX = wp.X,
                    CenterY = wp.Y,
                    CenterZ = wp.Z,
                    Rotation = new AxisAngleRotation3D(
                        new Vector3D(0, 0, -1), wp.HeadingDegrees)
                };

                GeometryModel3D box;
                Material mat;

                if (wp.PauseTime > 0)
                {
                    mat = Materials.Red;
                }
                else
                {
                    mat = Materials.DarkGray;
                }

                box = new GeometryModel3D(builder.ToMesh(),mat);
                box.Transform = headingRotate;
                collection.Add(box);

                builder = new MeshBuilder();
                float radius = 3.0f;
                double hx = wp.X + Math.Cos( (wp.HeadingDegrees-90) / 180 * Math.PI ) * radius;
                double hy = wp.Y + Math.Sin( (wp.HeadingDegrees + 90) / 180 * Math.PI ) * radius;

                builder.AddArrow(new Point3D(wp.X, wp.Y, wp.Z),new Point3D(hx, hy, wp.Z), 0.5,1);
                collection.Add(new GeometryModel3D(builder.ToMesh(), mat));

                //box = new GeometryModel3D(builder.ToMesh(), mat);
                //collection.Add(box);

                if(wp.Name != null && !String.IsNullOrWhiteSpace(wp.Name) )
                {
                    GeometryModel3D text = TextCreator.CreateTextLabelModel3D(wp.Name, BrushHelper.CreateGrayBrush(50), true, 2, new Point3D(p.X, p.Y, p.Z + 5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
                    text.Transform = new ScaleTransform3D(new Vector3D(-1, 1, 1), new Point3D(p.X, p.Y, p.Z));
                    collection.Add(text);
                }

                //GeometryModel3D text = TextCreator.CreateTextLabelModel3D(wp.GridId.ToString() + "G:" + wp.Number.ToString() + "N:" + wp.PauseTime.ToString() + "P", BrushHelper.CreateGrayBrush(5), true, 2,
                  //                                                          new Point3D(p.X, p.Y, p.Z + 5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
                //text.Transform = new ScaleTransform3D(new Vector3D(-1, 1, 1), new Point3D(p.X, p.Y, p.Z));
                //collection.Add(text);

                builder = new MeshBuilder();

                if (grid.WanderType == Grid.WanderTypes.Patrol || grid.WanderType == Grid.WanderTypes.Circular)
                {
                    IEnumerable<Waypoint> nextWaypointQuery = grid.Waypoints.Where(
                        x => x.Number > wp.Number).OrderBy(y => y.Number);
                    if (nextWaypointQuery.Count() > 0)
                    {
                        Waypoint nextWaypoint = nextWaypointQuery.ElementAt(0);
                        builder.AddArrow(p, new Point3D(nextWaypoint.X, nextWaypoint.Y, nextWaypoint.Z), 0.5);

                        collection.Add(
                            new GeometryModel3D(builder.ToMesh(), Materials.White));
                    }
                }

                //collection.Add( new GeometryModel3D(builder.ToMesh(), Materials.
            }

            //collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.White));

            _mapping[grid] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Esempio n. 24
0
        private void CreateNode(EQEmu.Path.Node node)
        {
            Model3DGroup group = Model as Model3DGroup;
            MeshBuilder builder;

            Model3DCollection collection = new Model3DCollection();

            if (_mapping[node] != null)
            {
                foreach (Model3D model in _mapping[node])
                {
                    group.Children.Remove(model);
                }
            }

            if (Clipping != null && !Clipping.DrawPoint(node.Location)) return;

            //builder.AddBox(node.Location, 2, 2, 2);

            _mapping[node] = collection;

            GeometryModel3D box = GetNodeModel();
            box.Transform = new TranslateTransform3D(node.X,node.Y,node.Z);
            collection.Add(box);
            //collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Green));
            //_mapping[node] = new GeometryModel3D(builder.ToMesh(), Materials.Green);

            if (Options.ShowTextLabels)
            {
                GeometryModel3D text = TextCreator.CreateTextLabelModel3D(node.Id.ToString(), BrushHelper.CreateGrayBrush(5), true, 2,
                                                                            new Point3D(node.X, node.Y, node.Z + 5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
                text.Transform = new ScaleTransform3D(new Vector3D(-1, 1, 1), new Point3D(node.X, node.Y, node.Z));
                collection.Add(text);
            }

            foreach (EQEmu.Path.Neighbor neighbor in node.Neighbors)
            {
                if (neighbor.Node == null) continue;

                builder = new MeshBuilder();
                builder.AddArrow(new Point3D(node.X, node.Y, node.Z), new Point3D(neighbor.Node.X, neighbor.Node.Y, neighbor.Node.Z), 0.5);
                //builder.AddPipe(new Point3D(n.X, n.Y, n.Z), new Point3D(neighbor.Node.X, neighbor.Node.Y, neighbor.Node.Z), 0.5, 0.5, 50);
                collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Yellow));
            }

            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }

            //group.Children.Add(_mapping[node]);
        }
Esempio n. 25
0
        private void CreateSpawn(EQEmu.Spawns.Spawn2 spawn,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(spawn))
            {
                foreach (Model3D model in _mapping[spawn])
                {
                    group.Children.Remove(model);
                }
            }

            MeshBuilder builder = new MeshBuilder();
            Point3D p = new Point3D(spawn.X,spawn.Y,spawn.Z);

            if( !Clipping.DrawPoint(p) ) return;

            builder.AddBox(p,2,2,2);

            Transform3D headingRotate = new RotateTransform3D()
            {
                CenterX = p.X,
                CenterY = p.Y,
                CenterZ = p.Z,
                Rotation = new AxisAngleRotation3D(
                    new Vector3D(0,0,-1),spawn.HeadingDegrees)
            };

            GeometryModel3D box;
            Material mat = Materials.White;

            if (flags == DisplayFlags.None)
            {
                if (spawn.RoamAreaId > 0)
                {
                    mat = Materials.Red;
                }
                else if (spawn.GridId > 0)
                {
                    mat = Materials.Yellow;
                }
            }
            else if (flags == DisplayFlags.Green)
            {
                mat = Materials.Green;
            }
            else if (flags == DisplayFlags.DarkGray)
            {
                mat = Materials.DarkGray;
            }
            else if (flags == DisplayFlags.Rainbow)
            {
                mat = Materials.Rainbow;
            }
            else if (flags == DisplayFlags.Blue)
            {
                mat = Materials.Blue;
            }

            box = new GeometryModel3D(builder.ToMesh(), mat);
            box.Transform = headingRotate;
            collection.Add(box);

            builder = new MeshBuilder();
            float radius = 3.0f;
            double hx = spawn.X + Math.Cos((spawn.HeadingDegrees - 90) / 180 * Math.PI) * radius;
            double hy = spawn.Y + Math.Sin((spawn.HeadingDegrees + 90) / 180 * Math.PI) * radius;

            builder.AddArrow(new Point3D(spawn.X, spawn.Y, spawn.Z), new Point3D(hx, hy, spawn.Z), 0.5, 1);
            collection.Add(new GeometryModel3D(builder.ToMesh(), mat));

            _mapping[spawn] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Create the text for the north arrow.
        ///
        /// It is suggested to use an image instead
        /// of text for performance purposes.  I will
        /// look into this later.
        /// </summary>
        /// <returns>3D Text.</returns>
        private Model3D NorthArrow(int numBins)
        {
            Model3DGroup group = new Model3DGroup();

            // Get the length of the cylinder, if it is 0, then display something.
            double arrowLength = CylinderRadius * SCALE_ARROW;

            if (arrowLength <= 0)
            {
                arrowLength = SCALE_ARROW;
            }

            #region Arrow
            //Create the shape of the object
            //This will be an arrow
            //Length will be the scale value
            //The position will be above the plot
            double xAxisLoc = 0;
            double yAxisLoc = 0;
            double zAxisLoc = 0;

            if (YAxis)
            {
                yAxisLoc = -numBins * TRANSLATION_SCALE;
            }
            else
            {
                xAxisLoc = numBins * TRANSLATION_SCALE;
            }

            var mb = new MeshBuilder(false, false);
            if (YAxis)
            {
                mb.AddArrow(new Point3D(xAxisLoc, yAxisLoc, zAxisLoc), new Point3D(arrowLength, yAxisLoc, zAxisLoc), LABEL_ARROW_HEAD_SIZE, 3, 100);
            }
            else
            {
                mb.AddArrow(new Point3D(xAxisLoc, yAxisLoc, zAxisLoc), new Point3D(xAxisLoc, arrowLength, zAxisLoc), LABEL_ARROW_HEAD_SIZE, 3, 100);
            }
            Geometry3D geometry = mb.ToMesh();

            //Set the color
            Material material = MaterialHelper.CreateMaterial(SELECTED_BIN_COLOR);
            material.Freeze();

            var model = new GeometryModel3D(geometry, material);
            model.BackMaterial = material;
            #endregion

            #region Text
            double xAxisLocLabel = 0;
            double yAxisLocLabel = 0;
            double zAxisLocLabel = LABEL_ARROW_HEAD_SIZE;                                       // Make the text just in front of the North arrow
            if (YAxis)
            {
                xAxisLocLabel = arrowLength / 2;                                             // Make the text in the middle of the North arrow
                yAxisLocLabel = -numBins * TRANSLATION_SCALE;                                // Go to the bottom of the column
            }
            else
            {
                xAxisLocLabel = numBins * TRANSLATION_SCALE;
                yAxisLocLabel = arrowLength / 2;
            }

            TextVisual3D txt = new TextVisual3D();
            txt.Position      = new Point3D(xAxisLocLabel, yAxisLocLabel, zAxisLocLabel);
            txt.Height        = 0.5;
            txt.Text          = string.Format("North {0} m/s", (arrowLength / SCALE_ARROW).ToString("0.0")); // Need to get the arrowLenght back to m/s
            txt.TextDirection = new Vector3D(1, 0, 0);                                                       // Set text to run in line with X axis
            txt.UpDirection   = new Vector3D(0, 1, 0);                                                       // Set text to Point Up on Y axis
            txt.Foreground    = new SolidColorBrush(Colors.Black);
            txt.Background    = new SolidColorBrush(Colors.WhiteSmoke);
            txt.Padding       = new Thickness(2);

            #endregion

            group.Children.Add(model);
            group.Children.Add(txt.Content);

            return(group);
        }
        /// <summary>
        /// Load sensors in model
        /// </summary>
        /// <param name="sensors">List of sensors</param>
        public void LoadSensorsValuesInModel(IEnumerable <Sensor> sensors)
        {
            this.sensorGroupModel.Children.Clear();
            this.sensorGroupModel.Children.Add(this.stlModel);

            this.sensorModelArray[this.dataCounter] = new List <GeometryModel3D>();

            foreach (Sensor sensor in sensors)
            {
                MeshBuilder meshBuilder = new MeshBuilder();

                IEnumerable <IGrouping <string, SensorValue> > asd = sensor.Values.GroupBy(a => a.Parameter);

                double value = 0;

                foreach (IGrouping <string, SensorValue> gp in asd)
                {
                    if (gp.Key == this.parameterString)
                    {
                        double cte = gp.Last().Value *Math.PI / 180;

                        Point3D newPoint = new Point3D(sensor.X + (4 * sensor.Size * Math.Cos(cte)), sensor.Y + (4 * sensor.Size * Math.Sin(cte)), sensor.Z);
                        meshBuilder.AddArrow(new Point3D(sensor.X, sensor.Y, sensor.Z), newPoint, this.arrowDiameterSize, this.arrowHeadSize);
                    }
                    else
                    {
                        value = gp.Last().Value;
                        meshBuilder.AddBox(new Point3D(sensor.X, sensor.Y, sensor.Z), sensor.Size, sensor.Size, this.sizeZ);
                    }
                }

                Color color;

                // If sensor does not receive any value, receives yellow as collor
                if (sensor.Values.Count != 0)
                {
                    color = Interpolation.GetHeatMapColor(value, -1, +1);
                }
                else
                {
                    color = new Color()
                    {
                        A = 255, R = 255, G = 255, B = 0
                    };
                }

                GeometryModel3D sensorModel = new GeometryModel3D(meshBuilder.ToMesh(), MaterialHelper.CreateMaterial(color));
                this.sensorModelArray[this.dataCounter].Add(sensorModel);
                this.sensorGroupModel.Children.Add(sensorModel);
            }

            if (this.modelMesh != null)
            {
                this.vertices[this.dataCounter++] = this.interpolation.Interpolate2(this.modelMesh, this.SensorsNotParameter(sensors));
                this.MaxSlider = this.dataCounter - 1;
                this.Slider    = this.MaxSlider;
            }

            this.GroupModel       = this.sensorGroupModel;
            this.device3D.Content = this.groupModel;

            if (!this.ViewPort3d.Children.Contains(this.device3D))
            {
                this.ViewPort3d.Children.Add(this.device3D);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Updates skeleton joints geometry
        /// </summary>
        public static void DrawJoints()
        {
            MeshBuilder meshBuilder     = new MeshBuilder();
            MeshBuilder meshBulderRed   = new MeshBuilder();
            MeshBuilder meshBulderBlue  = new MeshBuilder();
            MeshBuilder meshBulderGreen = new MeshBuilder();

            foreach (Body body in BodyData.Bodies)
            {
                if (body.IsTracked)
                {
                    IReadOnlyDictionary <JointType, Joint> joints = body.Joints;

                    foreach (JointType joint in joints.Keys)
                    {
                        // sometimes the depth(Z) of an inferred joint may show as negative
                        // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)

                        CameraSpacePoint position = joints[joint].Position;

                        if (position.Z < 0)
                        {
                            position.Z = InferredZPositionClamp;
                        }

                        TrackingState trackingState = joints[joint].TrackingState;

                        // create skeleton and hands geometry

                        if (joints[joint].JointType == JointType.HandLeft || joints[joint].JointType == JointType.HandRight)
                        {
                            var handState = body.HandLeftState;
                            if (joints[joint].JointType == JointType.HandRight)
                            {
                                handState = body.HandRightState;
                            }

                            if (handState == HandState.Closed)
                            {
                                meshBulderRed.AddBox(new Vector3((float)position.X, (float)position.Y, (float)position.Z), handBoxSize, handBoxSize, handBoxSize, BoxFaces.All);
                            }

                            if (handState == HandState.Open)
                            {
                                meshBulderGreen.AddBox(new Vector3((float)position.X, (float)position.Y, (float)position.Z), handBoxSize, handBoxSize, handBoxSize, BoxFaces.All);
                            }

                            if (handState == HandState.Lasso)
                            {
                                meshBulderBlue.AddBox(new Vector3((float)position.X, (float)position.Y, (float)position.Z), handBoxSize, handBoxSize, handBoxSize, BoxFaces.All);
                            }

                            meshGeometrySkeletonRed   = meshBulderRed.ToMeshGeometry3D();
                            meshGeometrySkeletonBlue  = meshBulderBlue.ToMeshGeometry3D();
                            meshGeometrySkeletonGreen = meshBulderGreen.ToMeshGeometry3D();

                            MainWindow.main.Dispatcher.Invoke(() =>
                            {
                                MainWindow.main.skeletonRed.Geometry   = meshGeometrySkeletonRed;
                                MainWindow.main.skeletonBlue.Geometry  = meshGeometrySkeletonBlue;
                                MainWindow.main.skeletonGreen.Geometry = meshGeometrySkeletonGreen;
                            });
                        }
                        else
                        {
                            meshBuilder.AddBox(new Vector3((float)position.X, (float)position.Y, (float)position.Z), skeletonBoxSize, skeletonBoxSize, skeletonBoxSize, BoxFaces.All);
                        }
                    }

                    // draw bones
                    foreach (var bone in BodyData.bones)
                    {
                        Joint joint0 = joints[bone.Item1];
                        Joint joint1 = joints[bone.Item1];

                        if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
                        {
                            meshBuilder.AddArrow(BodyData.jointPoints[bone.Item1], BodyData.jointPoints[bone.Item2], 0.01);
                        }
                    }
                }
            }

            meshGeometry = meshBuilder.ToMeshGeometry3D();

            MainWindow.main.Dispatcher.Invoke(() =>
            {
                MainWindow.main.skeletonModel.Geometry = meshGeometry;
            });
        }
Esempio n. 29
0
        public Vector3D ForwardKinematics(double[] angles, double[] tempF)
        {
            F1 = new Transform3DGroup();
            T  = new TranslateTransform3D();
            R  = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(joints[0].rotAxisX, joints[0].rotAxisY, joints[0].rotAxisZ), angles[0]), new Point3D(joints[0].rotPointX, joints[0].rotPointY, joints[0].rotPointZ));
            F1.Children.Add(R);
            F1.Children.Add(T);

            //This moves the first joint attached to the base, it may translate and rotate. Since the joint are already in the right position (the .stl model also store the joints position
            //in the virtual world when they were first created, so if you load all the .stl models of the joint they will be automatically positioned in the right locations)
            //so in all of these cases the first translation is always 0, I just left it for future purposes if something need to be moved
            //After that, the joint needs to rotate of a certain amount (given by the value in the slider), and the rotation must be executed on a specific point
            //After some testing it looks like the point 175, -200, 500 is the sweet spot to achieve the rotation intended for the joint
            //finally we also need to apply the transformation applied to the base
            F2 = new Transform3DGroup();
            T  = new TranslateTransform3D(0, 0, 0);
            R  = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(joints[1].rotAxisX, joints[1].rotAxisY, joints[1].rotAxisZ), angles[1]), new Point3D(joints[1].rotPointX, joints[1].rotPointY, joints[1].rotPointZ));
            F2.Children.Add(T);
            F2.Children.Add(R);
            F2.Children.Add(F1);

            //The second joint is attached to the first one. As before I found the sweet spot after testing, and looks like is rotating just fine. No pre-translation as before
            //and again the previous transformation needs to be applied
            F3     = new Transform3DGroup();
            T      = new TranslateTransform3D(0, 0, 0);
            Tran_2 = new TranslateTransform3D(joints[2].rotAxisX * joints[2].angle, joints[2].rotAxisY * joints[2].angle, joints[2].rotAxisZ * joints[2].angle);
            F3.Children.Add(T);
            F3.Children.Add(Tran_2);
            F3.Children.Add(F2);

            //as before
            F4 = new Transform3DGroup();
            T  = new TranslateTransform3D(0, 0, 0); //1500, 650, 1650
            R  = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(joints[3].rotAxisX, joints[3].rotAxisY, joints[3].rotAxisZ), angles[3]), new Point3D(joints[3].rotPointX, joints[3].rotPointY, joints[3].rotPointZ));
            F4.Children.Add(T);
            F4.Children.Add(R);
            F4.Children.Add(F3);


            //NB: I was having a nightmare trying to understand why it was always rotating in a weird way... SO I realized that the order in which
            //you add the Children is actually VERY IMPORTANT in fact before I was applyting F and then T and R, but the previous transformation
            //Should always be applied as last (FORWARD Kinematics)
            Point3D EndPosition = new Point3D(EndOrigin.Bounds.Location.X, EndOrigin.Bounds.Location.Y, EndOrigin.Bounds.Location.Z);

            if (!IsFirstFlag)  //不是第一次运行这个
            {
                //////重新画力传感器坐标
                ///////////////////////////////////////////////////////////
                FS.Children.Remove(ForceModel);
                MeshBuilder meshBuilderForce = new MeshBuilder(true, true);

                if (ForceShowMode == 0)   //相对于绝对坐标系
                {
                    ///////使用力相对于世界坐标坐标系,而不是相对于力传感器自身
                    Point3D F = new Point3D(tempF[0] + EndPosition.X, tempF[1] + EndPosition.Y, tempF[2] + EndPosition.Z);
                    meshBuilderForce.AddArrow(EndPosition, F, 8);
                    ForceModel = new GeometryModel3D(meshBuilderForce.ToMesh(), Materials.Gold);
                    FS.Children.Add(ForceModel);

                    ///////使用力矩相对于世界坐标坐标系,而不是相对于力传感器自身
                    FS.Children.Remove(TorqueModel);
                    MeshBuilder meshBuilderTorque = new MeshBuilder(true, true);
                    Point3D     M = new Point3D(tempF[3] + EndPosition.X, tempF[4] + EndPosition.Y, tempF[5] + EndPosition.Z);
                    meshBuilderTorque.AddArrow(EndPosition, M, 8);
                    TorqueModel = new GeometryModel3D(meshBuilderTorque.ToMesh(), Materials.Indigo);
                    FS.Children.Add(TorqueModel);
                }
                else    //相对于力传感器的坐标系
                {
                    Point3D F = new Point3D(tempF[1] + OriPosition.X, tempF[0] + OriPosition.Y, -tempF[2] + OriPosition.Z);
                    meshBuilderForce.AddArrow(OriPosition, F, 8);
                    ForceModel = new GeometryModel3D(meshBuilderForce.ToMesh(), Materials.Gold);
                    FS.Children.Add(ForceModel);

                    ///////使用力矩相对于世界坐标坐标系,而不是相对于力传感器自身
                    FS.Children.Remove(TorqueModel);
                    MeshBuilder meshBuilderTorque = new MeshBuilder(true, true);
                    Point3D     M = new Point3D(tempF[4] + OriPosition.X, tempF[3] + OriPosition.Y, -tempF[5] + OriPosition.Z);
                    meshBuilderTorque.AddArrow(OriPosition, M, 8);
                    TorqueModel = new GeometryModel3D(meshBuilderTorque.ToMesh(), Materials.Indigo);
                    FS.Children.Add(TorqueModel);
                }
            }
            ////////////////////////////////////////////////////////
            joints[0].model.Transform = F1; //First joint
            joints[1].model.Transform = F2; //Second joint (the "biceps")
            joints[2].model.Transform = F3; //movemet joint
            joints[3].model.Transform = F4; //the rot
            EndOrigin.Transform       = F4;
            AxisX.Transform           = F4;
            AxisY.Transform           = F4;
            AxisZ.Transform           = F4;
            if (ForceShowMode == 1)
            {
                ForceModel.Transform  = F4;
                TorqueModel.Transform = F4;
            }

            if (IsFirstFlag)  //发现第一此运行的时候
            {
                Tx.Content = 400;
                Ty.Content = 0;
                Tz.Content = 223.5;
            }
            else
            {
                Tx.Content = EndPosition.X;
                Ty.Content = EndPosition.Y;
                Tz.Content = EndPosition.Z;
            }
            return(new Vector3D(EndPosition.X, EndPosition.Y, EndPosition.Z));
        }
Esempio n. 30
0
        public void ShowGraphModel(string filePath)
        {
            var sim = PedSimXMLWriter.Deserialize(filePath);

            if (sim == null)
            {
                return;
            }

            MeshBuilder mb = new MeshBuilder(false, false);

            foreach (var item in sim.layouts[0].scenario.graphs[0].vertices)
            {
                mb.AddSphere(new Point3D(item.center.x, item.center.y, 0), 0.1);
            }

            foreach (var item in sim.layouts[0].scenario.graphs[0].edges)
            {
                var vertexLeft = new vertex();
                foreach (var vertex in sim.layouts[0].scenario.graphs[0].vertices)
                {
                    if (vertex.id == item.idLeft)
                    {
                        vertexLeft = vertex;
                        break;
                    }
                }

                var vertexRight = new vertex();
                foreach (var vertex in sim.layouts[0].scenario.graphs[0].vertices)
                {
                    if (vertex.id == item.idRight)
                    {
                        vertexRight = vertex;
                        break;
                    }
                }

                // Point new Point3D(item.center.x, item.center.y, 0)
                if (vertexRight != null && vertexLeft != null)
                {
                    mb.AddArrow(new Point3D(vertexLeft.center.x, vertexLeft.center.y, 0),
                                new Point3D(vertexRight.center.x, vertexRight.center.y, 0), 0.05, 0);
                }
                else
                {
                    var test = true;
                }
            }

            var myGeometryModel = new GeometryModel3D
            {
                Material = new DiffuseMaterial()
                {
                    Brush = Brushes.Green
                },
                BackMaterial = new DiffuseMaterial()
                {
                    Brush = Brushes.Green
                },
                Geometry = mb.ToMesh(true)
            };

            graphModel = new ModelUIElement3D {
                Model = myGeometryModel
            };
            ViewPort3D.Children.Add(graphModel);
        }
Esempio n. 31
0
        /// <summary>
        /// Create the East and Radius label.
        /// This will display the text for "East" and the size
        /// of the cylinder radius.
        /// </summary>
        /// <param name="numBins">Number of bins in the ensemble.</param>
        /// <returns>Model of the label.</returns>
        private Model3D EastArrow(int numBins)
        {
            Model3DGroup group = new Model3DGroup();

            // Get the length of the cylinder, if it is 0, then display something.
            double arrowLength = CylinderRadius * SCALE_ARROW;

            if (arrowLength <= 0)
            {
                arrowLength = SCALE_ARROW;
            }

            #region Arrow
            //Create the shape of the object
            //This will be an arrow
            //Length will be the scale value
            //The position will be above the plot
            double xAxisLoc = 0;
            double yAxisLoc = 0;
            double zAxisLoc = 0;
            if (YAxis)
            {
                yAxisLoc = -numBins * TRANSLATION_SCALE;                // Go to the bottom of the column
            }
            else
            {
                xAxisLoc = numBins * TRANSLATION_SCALE;
            }

            var mb = new MeshBuilder(false, false);
            mb.AddArrow(new Point3D(xAxisLoc, yAxisLoc, zAxisLoc), new Point3D(xAxisLoc, yAxisLoc, arrowLength), LABEL_ARROW_HEAD_SIZE, 3, 100);
            Geometry3D geometry = mb.ToMesh();

            //Set the color
            Material material = MaterialHelper.CreateMaterial(Colors.Lime);
            material.Freeze();

            ////Rotate the object
            //var rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(xAxisLoc, yAxisLoc, zAxisLoc), 90));
            //rotation.Freeze();

            //var tg = new Transform3DGroup();
            //tg.Children.Add(rotation);

            var model = new GeometryModel3D(geometry, material)
            {
            };
            model.BackMaterial = material;
            #endregion

            #region Text
            double xAxisLocLabel = 0;
            double yAxisLocLabel = 0;
            double zAxisLocLabel = 0;
            if (YAxis)
            {
                xAxisLocLabel = -LABEL_ARROW_HEAD_SIZE;                                              // Make the text in the middle of the East arrow
                yAxisLocLabel = (-numBins * TRANSLATION_SCALE) - (ARROW_HEAD_SIZE * 2);              // Go to the bottom of the column
                zAxisLocLabel = (arrowLength / 2);                                                   // Make the text just in front of the East arrow
            }
            else
            {
                xAxisLocLabel = (numBins * TRANSLATION_SCALE) + (ARROW_HEAD_SIZE * 2);     // Go to the bottom of the column
                yAxisLocLabel = -(ARROW_HEAD_SIZE * 2);                                    // Make the text just in front of the East arrow
                zAxisLocLabel = (arrowLength / 2);                                         // Make the text in the middle of the East arrow
            }

            TextVisual3D txt = new TextVisual3D();
            txt.Position      = new Point3D(xAxisLocLabel, yAxisLocLabel, zAxisLocLabel);
            txt.Height        = 0.5;
            txt.Text          = string.Format("East {0} m/s", (arrowLength / SCALE_ARROW).ToString("0.0"));
            txt.TextDirection = new Vector3D(0, 0, 1);                      // Set text to run in line with X axis
            txt.UpDirection   = new Vector3D(0, 1, 0);                      // Set text to Point Up on Y axis
            txt.Foreground    = new SolidColorBrush(Colors.Black);
            txt.Background    = new SolidColorBrush(Colors.WhiteSmoke);
            txt.Padding       = new Thickness(2);

            #endregion

            group.Children.Add(model);
            group.Children.Add(txt.Content);

            return(group);
        }
        /// <summary>
        /// Updates the visuals.
        /// </summary>
        protected void UpdateVisuals()
        {
            this.vertexVisuals = new Dictionary<HalfEdgeMesh.Vertex, ModelUIElement3D>();
            this.halfEdgeVisuals = new Dictionary<HalfEdgeMesh.HalfEdge, ModelUIElement3D>();
            this.faceVisuals = new Dictionary<HalfEdgeMesh.Face, ModelUIElement3D>();
            this.Children.Clear();
            if (this.Mesh == null)
            {
                return;
            }

            if (this.VertexRadius > 0)
            {
                // Add the vertices
                foreach (var vertex in this.Mesh.Vertices)
                {
                    var gm = new MeshBuilder(false, false);
                    gm.AddSubdivisionSphere(vertex.Position, this.VertexRadius, 4);
                    var vertexElement = new ModelUIElement3D
                        {
                           Model = new GeometryModel3D(gm.ToMesh(), this.VertexMaterial)
                        };
                    var currentVertex = vertex;
                    vertexElement.MouseLeftButtonDown += (s, e) => this.HighlightVertex(currentVertex);
                    this.vertexVisuals.Add(vertex, vertexElement);
                    this.Add(vertexElement);
                }
            }

            var faceCenter = new Dictionary<HalfEdgeMesh.Face, Point3D>();

            foreach (var face in this.Mesh.Faces)
            {
                var faceVertices = face.Vertices.Select(v => v.Position).ToList();

                // Find the face centroid
                var center = this.FindCentroid(faceVertices);
                faceCenter.Add(face, center);

                if (this.ShrinkFactor < 1)
                {
                    // Add the faces
                    for (int i = 0; i < faceVertices.Count; i++)
                    {
                        faceVertices[i] += (center - faceVertices[i]) * this.ShrinkFactor;
                    }

                    var gm = new MeshBuilder(false, false);
                    gm.AddTriangleFan(faceVertices);
                    var faceElement = new ModelUIElement3D
                        {
                            Model =
                                new GeometryModel3D(gm.ToMesh(), this.FaceMaterial)
                                    {
                                       BackMaterial = this.FaceBackMaterial
                                    }
                        };
                    var currentFace = face;
                    faceElement.MouseLeftButtonDown += (s, e) => this.HighlightFace(currentFace);
                    this.faceVisuals.Add(face, faceElement);
                    this.Add(faceElement);
                }
            }

            if (this.EdgeDiameter > 0)
            {
                // Add the edges
                foreach (var edge in this.Mesh.Edges)
                {
                    var start = edge.StartVertex.Position;
                    var end = edge.EndVertex.Position;
                    var center = faceCenter[edge.Face];
                    start = start + (center - start) * this.ShrinkFactor;
                    end = end + (center - end) * this.ShrinkFactor;
                    var gm = new MeshBuilder(false, false);
                    gm.AddArrow(start, end, this.EdgeDiameter);
                    var edgeElement = new ModelUIElement3D
                        {
                           Model = new GeometryModel3D(gm.ToMesh(), this.EdgeMaterial)
                        };
                    var currentEdge = edge;
                    edgeElement.MouseLeftButtonDown += (s, e) => { this.HighlightEdge(currentEdge); };
                    this.halfEdgeVisuals.Add(edge, edgeElement);
                    this.Add(edgeElement);
                }
            }
        }
 /// <summary>
 /// Updates the geometry.
 /// </summary>
 protected override void UpdateGeometry()
 {
     var mb = new MeshBuilder(false, false);
     var p0 = new Point3D(0, 0, 0);
     var d = this.Direction;
     d.Normalize();
     var p1 = p0 + (d * this.Length);
     mb.AddArrow(p0, p1, this.Diameter);
     this.Model.Geometry = mb.ToMesh();
 }
        /// <summary>
        /// Updates the visuals.
        /// </summary>
        protected virtual void OnMeshChanged()
        {
            this.Children.Clear();

            var builder = new MeshBuilder();
            for (int i = 0; i < this.Mesh.Positions.Count; i++)
            {
                builder.AddArrow(
                    this.Mesh.Positions[i], this.Mesh.Positions[i] + this.Mesh.Normals[i], this.Diameter, 3, 10);
            }

            this.Content = new GeometryModel3D
                {
                   Geometry = builder.ToMesh(true), Material = MaterialHelper.CreateMaterial(this.Color)
                };
        }
Esempio n. 35
0
        /// <summary>
        /// Create an arrow representing the magnitude and direction
        /// for a given bin.  This will create an arrow within a column.
        /// The Column will start at 0 and go down, using the bin times a scale
        /// factor to move down the column for each bin.  The magnitude will
        /// give the length and color of the arrow.  The angle will be used to rotate around
        /// the origin of 0,0, to give the direction.  The angle is based off North = 0 degrees.
        /// </summary>
        /// <param name="bin">Bin to create.</param>
        /// <param name="mag">Magnitude of the bin.</param>
        /// <param name="angleYNorth">Direction of the bin with reference to Y as North.</param>
        /// <returns>3D model of the arrow.</returns>
        private GeometryModel3D CreateBin(int bin, double mag, double angleYNorth)
        {
            // Location on the axis for each bin
            // Set the Camera UpDirection in XMAL to UpDirection="0, 1, 0" to make it use Y axis as Up.  Default is Z up.
            double xAxisLoc = 0;
            double yAxisLoc = 0;
            double zAxisLoc = 0;

            if (YAxis)
            {
                yAxisLoc = -bin * TRANSLATION_SCALE;
            }
            else
            {
                xAxisLoc = bin * TRANSLATION_SCALE;
            }

            // Create the shape of the object
            // This will be an arrow
            // Use the magnitude to get the length of the arrow
            // Create a column of bins with arrows
            var mb = new MeshBuilder(false, false);

            if (YAxis)
            {
                mb.AddArrow(new Point3D(xAxisLoc, yAxisLoc, zAxisLoc), new Point3D(mag * SCALE_ARROW, yAxisLoc, zAxisLoc), ARROW_HEAD_SIZE);
            }
            else
            {
                mb.AddArrow(new Point3D(xAxisLoc, yAxisLoc, zAxisLoc), new Point3D(xAxisLoc, mag * SCALE_ARROW, zAxisLoc), ARROW_HEAD_SIZE);
            }
            Geometry3D geometry = mb.ToMesh();

            // Set the color based off the magnitude
            // If the bin is selected, use the selected color
            Material material;

            if (bin != SelectedBin)
            {
                material = MaterialHelper.CreateMaterial(GenerateColor(mag));
            }
            else
            {
                material = MaterialHelper.CreateMaterial(SELECTED_BIN_COLOR);
            }
            material.Freeze();

            // Rotate the object
            var rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(xAxisLoc, yAxisLoc, zAxisLoc), angleYNorth));

            rotation.Freeze();

            // Create the model with the rotation
            var tg = new Transform3DGroup();

            tg.Children.Add(rotation);
            var model = new GeometryModel3D(geometry, material)
            {
                Transform = tg
            };

            return(model);
        }
Esempio n. 36
0
        /// <summary>
        /// Updates the visuals.
        /// </summary>
        protected void UpdateVisuals()
        {
            this.vertexVisuals   = new Dictionary <HalfEdgeMesh.Vertex, ModelUIElement3D>();
            this.halfEdgeVisuals = new Dictionary <HalfEdgeMesh.HalfEdge, ModelUIElement3D>();
            this.faceVisuals     = new Dictionary <HalfEdgeMesh.Face, ModelUIElement3D>();
            this.Children.Clear();
            if (this.Mesh == null)
            {
                return;
            }

            if (this.VertexRadius > 0)
            {
                // Add the vertices
                foreach (var vertex in this.Mesh.Vertices)
                {
                    var gm = new MeshBuilder(false, false);
                    gm.AddSubdivisionSphere(vertex.Position, this.VertexRadius, 4);
                    var vertexElement = new ModelUIElement3D
                    {
                        Model = new GeometryModel3D(gm.ToMesh(), this.VertexMaterial)
                    };
                    var currentVertex = vertex;
                    vertexElement.MouseLeftButtonDown += (s, e) => this.HighlightVertex(currentVertex);
                    this.vertexVisuals.Add(vertex, vertexElement);
                    this.Add(vertexElement);
                }
            }

            var faceCenter = new Dictionary <HalfEdgeMesh.Face, Point3D>();

            foreach (var face in this.Mesh.Faces)
            {
                var faceVertices = face.Vertices.Select(v => v.Position).ToList();

                // Find the face centroid
                var center = this.FindCentroid(faceVertices);
                faceCenter.Add(face, center);

                if (this.ShrinkFactor < 1)
                {
                    // Add the faces
                    for (int i = 0; i < faceVertices.Count; i++)
                    {
                        faceVertices[i] += (center - faceVertices[i]) * this.ShrinkFactor;
                    }

                    var gm = new MeshBuilder(false, false);
                    gm.AddTriangleFan(faceVertices);
                    var faceElement = new ModelUIElement3D
                    {
                        Model =
                            new GeometryModel3D(gm.ToMesh(), this.FaceMaterial)
                        {
                            BackMaterial = this.FaceBackMaterial
                        }
                    };
                    var currentFace = face;
                    faceElement.MouseLeftButtonDown += (s, e) => this.HighlightFace(currentFace);
                    this.faceVisuals.Add(face, faceElement);
                    this.Add(faceElement);
                }
            }

            if (this.EdgeDiameter > 0)
            {
                // Add the edges
                foreach (var edge in this.Mesh.Edges)
                {
                    var start  = edge.StartVertex.Position;
                    var end    = edge.EndVertex.Position;
                    var center = faceCenter[edge.Face];
                    start = start + (center - start) * this.ShrinkFactor;
                    end   = end + (center - end) * this.ShrinkFactor;
                    var gm = new MeshBuilder(false, false);
                    gm.AddArrow(start, end, this.EdgeDiameter);
                    var edgeElement = new ModelUIElement3D
                    {
                        Model = new GeometryModel3D(gm.ToMesh(), this.EdgeMaterial)
                    };
                    var currentEdge = edge;
                    edgeElement.MouseLeftButtonDown += (s, e) => { this.HighlightEdge(currentEdge); };
                    this.halfEdgeVisuals.Add(edge, edgeElement);
                    this.Add(edgeElement);
                }
            }
        }
        private void CreatePoint(ZonePoint zp,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;
            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(zp))
            {
                foreach (Model3D model in _mapping[zp])
                {
                    group.Children.Remove(model);
                }
            }

            double px, py, pz;
            px = zp.X == 999999 ? 0 : zp.X;
            py = zp.Y == 999999 ? 0 : zp.Y;
            pz = zp.Z == 999999 ? 0 : zp.Z;

            Point3D p = new Point3D(px,py,pz);

            if (!Clipping.DrawPoint(p)) return;

            MeshBuilder builder = new MeshBuilder();
            builder.AddBox(p, 20, 20, 2);

            //connect box to destination
            px = zp.TargetX == 999999 ? px : zp.TargetX;
            py = zp.TargetY == 999999 ? py : zp.TargetY;
            pz = zp.TargetZ == 999999 ? pz : zp.TargetZ;

            GeometryModel3D box;
            box = new GeometryModel3D(builder.ToMesh(), Materials.Red);
            collection.Add(box);

            builder = new MeshBuilder();
            Point3D destP = new Point3D(px, py, pz);
            builder.AddArrow(p, destP, 0.5);
            builder.AddBox(destP, 20, 20, 2);

            if (zp.X == 999999 || zp.Y == 999999 || zp.Z == 999999 ||
                zp.TargetX == 999999 || zp.TargetY == 999999 || zp.TargetZ == 999999)
            {
                box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);
            }
            else
            {
                box = new GeometryModel3D(builder.ToMesh(), Materials.White);
            }

            collection.Add(box);

            if (flags != DisplayFlags.None)
            {
                builder = new MeshBuilder();

                if (flags.HasFlag(DisplayFlags.DarkGrayAura))
                {
                    builder.AddBox(p, 25,25, 1);
                    builder.AddBox(destP, 25, 25, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
                    collection.Add(box);
                }
                else if (flags.HasFlag(DisplayFlags.GreenAura))
                {
                    builder.AddBox(p, 25, 25, 1);
                    builder.AddBox(destP, 25, 25, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
                    collection.Add(box);
                }
            }

            _mapping[zp] = collection;

            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
        /// <summary>
        /// Load sensors in model
        /// </summary>
        /// <param name="sensors">List of sensors</param>
        /// <param name="analysisName">Analysis name</param>
        public void LoadSensorsInModel2(IEnumerable <Sensor> sensors, string analysisName)
        {
            // this.ViewPort3d.Children.Remove(this.device3D);
            this.sensorGroupModel.Children.Clear();
            this.sensorGroupModel.Children.Add(this.stlModel);

            this.sensorModelArray[this.dataCounter] = new List <GeometryModel3D>();

            int pos = 0;

            foreach (Sensor sensor in sensors)
            {
                Color color = new Color()
                {
                    A = 255, R = 255, G = 255, B = 0
                };
                MeshBuilder meshBuilder;

                if (sensor.Values.Count != 0)
                {
                    // Get data from analysis
                    IEnumerable <SensorValue> svc = from values in sensor.Values where values.AnalysisName == analysisName select values;

                    if (svc.Count() > 0)
                    {
                        // Group by parameters
                        List <IGrouping <string, SensorValue> > grouped = svc.GroupBy(a => a.Parameter).ToList();

                        int[] indexs = grouped[0].Key == this.parameterString ? new int[] { 0, 1 } : new int[] { 1, 0 };

                        for (int i = 0; i < grouped[indexs[1]].Count(); i++)
                        {
                            if (this.sensorModelArray[i] == null)
                            {
                                this.sensorModelArray[i] = new List <GeometryModel3D>();
                            }

                            meshBuilder = new MeshBuilder();

                            color = Interpolation.GetHeatMapColor(grouped[indexs[1]].ElementAt(i).Value, -1, +1);
                            meshBuilder.AddBox(new Point3D(sensor.X, sensor.Y, sensor.Z), sensor.Size, sensor.Size, this.sizeZ);

                            if (grouped.Count > 1)
                            {
                                double cte = grouped[indexs[0]].ElementAt(i).Value *Math.PI / 180;

                                Point3D newPoint = new Point3D(sensor.X + (4 * sensor.Size * Math.Cos(cte)), sensor.Y + (4 * sensor.Size * Math.Sin(cte)), sensor.Z);
                                meshBuilder.AddArrow(new Point3D(sensor.X, sensor.Y, sensor.Z), newPoint, this.arrowDiameterSize, this.arrowHeadSize);
                            }

                            GeometryModel3D sensorModel2 = new GeometryModel3D(meshBuilder.ToMesh(), MaterialHelper.CreateMaterial(color));

                            this.sensorModelArray[i].Add(sensorModel2);
                        }
                    }
                    else
                    {
                        meshBuilder = new MeshBuilder();

                        color = new Color()
                        {
                            A = 255, R = 255, G = 255, B = 0
                        };
                        meshBuilder.AddBox(new Point3D(sensor.X, sensor.Y, sensor.Z), sensor.Size, sensor.Size, this.sizeZ);

                        GeometryModel3D sensorModel2 = new GeometryModel3D(meshBuilder.ToMesh(), MaterialHelper.CreateMaterial(color));

                        this.sensorModelArray[pos].Add(sensorModel2);
                    }
                }
            }

            // TODO
            // foreach (var model3d in this.sensorModelArray[this.sensorModelArray.Length - 1])
            foreach (var model3d in this.sensorModelArray[0])
            {
                this.sensorGroupModel.Children.Add(model3d);
            }

            this.GroupModel       = this.sensorGroupModel;
            this.device3D.Content = this.groupModel;

            if (!this.ViewPort3d.Children.Contains(this.device3D))
            {
                this.ViewPort3d.Children.Add(this.device3D);
            }
        }