コード例 #1
0
        public CurvatureViewModel()
        {
            Camera.LookDirection = new Vector3D(-100, -65, -180);
            Camera.Position      = (Point3D)(-Camera.LookDirection + new Vector3D(0, 0, 50));

            Items.Add(_refLines = new LineGeometryModel3D {
                Color      = Colors.White,
                Smoothness = 0.7
            });

            Items.Add(new LineGeometryModel3D {
                Color      = Colors.Gray,
                Smoothness = 0.7,
                Geometry   = BuildGrid()
            });

            var mat = PhongMaterials.Brass.CloneMaterial();

            mat.DiffuseColor = new Color4((Color3)mat.DiffuseColor, 0.9f);
            Items.Add(_model = new MeshGeometryModel3D {
                Material = mat,
                CullMode = CullMode.Back
            });

            mat = mat.CloneMaterial();
            mat.DiffuseColor           = new Color4(1, 0, 0, 0.5f);
            Items.Add(_deflectionModel = new MeshGeometryModel3D {
                Material = mat,
                CullMode = CullMode.Back
            });
        }
コード例 #2
0
        private void BuildViewFrustumModel()
        {
            // frustum
            LineBuilder b1 = new LineBuilder();

            b1.AddLine(this.nearBL.ToVector3(), this.farBL.ToVector3());
            b1.AddLine(this.nearBR.ToVector3(), this.farBR.ToVector3());
            b1.AddLine(this.nearTR.ToVector3(), this.farTR.ToVector3());
            b1.AddLine(this.nearTL.ToVector3(), this.farTL.ToVector3());

            b1.AddLine(this.nearBL.ToVector3(), this.nearBR.ToVector3());
            b1.AddLine(this.nearBR.ToVector3(), this.nearTR.ToVector3());
            b1.AddLine(this.nearTR.ToVector3(), this.nearTL.ToVector3());
            b1.AddLine(this.nearTL.ToVector3(), this.nearBL.ToVector3());

            b1.AddLine(this.farBL.ToVector3(), this.farBR.ToVector3());
            b1.AddLine(this.farBR.ToVector3(), this.farTR.ToVector3());
            b1.AddLine(this.farTR.ToVector3(), this.farTL.ToVector3());
            b1.AddLine(this.farTL.ToVector3(), this.farBL.ToVector3());

            this.model = new LineGeometryModel3D()
            {
                Geometry         = b1.ToLineGeometry3D(),
                Color            = Color.Yellow,
                Thickness        = 0.5f,
                Visibility       = (this.ShowFrustum) ? Visibility.Visible : Visibility.Collapsed,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
            };
            this.Children.Add(this.model);

            //// normals
            //LineBuilder b2 = new LineBuilder();
            //for (int i = 0; i < 6; i++)
            //{
            //    int fact;
            //    if (i == 1)
            //        fact = 1000;
            //    else
            //        fact = 2;
            //    b2.AddLine(this.posOnBoundary[i].ToVector3(), (this.posOnBoundary[i] + fact * this.normals[i]).ToVector3());
            //}
            //LineGeometryModel3D debug = new LineGeometryModel3D()
            //{
            //    Geometry = b2.ToLineGeometry3D(),
            //    Color = Color.Orange,
            //    Thickness = 2f,
            //    Visibility = (this.ShowFrustum) ? Visibility.Visible : Visibility.Collapsed,
            //    IsHitTestVisible = false,
            //    Transform = new MatrixTransform3D(Matrix3D.Identity),
            //};
            //this.Children.Add(debug);

            // re-attach to renderer
            if (this.renderHost != null)
            {
                this.Attach(this.renderHost);
            }
        }
コード例 #3
0
        public void SetupGrid()
        {
            // floor plane grid
            var lineGeom = new LineGeometryModel3D
            {
                Geometry  = LineBuilder.GenerateGrid(),
                Color     = Color.Black,
                Transform = new TranslateTransform3D(-5, -4, -5)
            };

            view1.Items.Add(lineGeom);
        }
コード例 #4
0
        private void CreateWireFrameModels(IFCItem item, Vector3 center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0)
                {
                    var geo = new LineGeometry3D();
                    geo.Positions = new Vector3Collection();
                    geo.Indices   = new IntCollection();
                    var points = new Vector3Collection();
                    if (item.verticesForWireFrame != null)
                    {
                        for (int i = 0; i < item.noVerticesForWireFrame; i++)
                        {
                            points.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                            geo.Positions.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                        }
                    }

                    if (item.indicesForWireFrameLineParts != null)
                    {
                        for (int i = 0; i < item.noPrimitivesForWireFrame; i++)
                        {
                            var idx = item.indicesForWireFrameLineParts[2 * i + 0];
                            geo.Indices.Add(idx);
                            idx = item.indicesForWireFrameLineParts[2 * i + 1];
                            geo.Indices.Add(idx);
                        }
                    }
                    else
                    {
                        for (int i = 0, count = points.Count; i < count; i++)
                        {
                            geo.Indices.Add(i);
                            geo.Indices.Add((i + 1) % count);
                        }
                    }

                    LineGeometryModel3D line = new LineGeometryModel3D();
                    line.Geometry  = geo;
                    line.Color     = _defaultLineColor;
                    line.Thickness = 0.5;
                    item.Wireframe = line;

                    line.Tag = item.ifcType + ":" + item.ifcID;
                    model.Add(line);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
コード例 #5
0
        public DynaShapeDisplay(Solver solver)
        {
            this.solver = solver;

            pointGeometry = new PointGeometry3D
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            lineGeometry = new LineGeometry3D()
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            DynaShapeViewExtension.DynamoWindow.Dispatcher.Invoke(
                () =>
            {
                pointModel = new PointGeometryModel3D
                {
                    Size   = new Size(5, 5),
                    Figure = PointGeometryModel3D.PointFigure.Ellipse,
                    Color  = Color.White,
                };


                lineModel = new LineGeometryModel3D
                {
                    Thickness = 0.5,
                    Color     = Color.White,
                };

                List <string> info1 = new List <string>();
                foo(DynaShapeViewExtension.DynamoWindow.Content, info1, 0);

                List <string> info2 = new List <string>();
                ListContent(DynaShapeViewExtension.DynamoWindow.Content as Grid, 0, info2);
            },
                DispatcherPriority.Send);

            DynaShapeViewExtension.ViewModel.RequestViewRefresh += RequestViewRefreshHandler;

            DynaShapeViewExtension.DynamoWindow.Closed += (sender, args) =>
            {
                Dispose();
            };
        }
コード例 #6
0
        /// <summary>
        /// The on children changed.
        /// </summary>
        protected virtual void OnChildrenChanged()
        {
            this.translateXL.Length = 0.5;
            this.translateYL.Length = 0.5;
            this.translateZL.Length = 0.5;
            this.translateXR.Length = 0.5;
            this.translateYR.Length = 0.5;
            this.translateZR.Length = 0.5;

            this.Children.Clear();

            if (this.CanTranslateX)
            {
                this.Children.Add(this.translateXL);
                this.Children.Add(this.translateXR);
            }

            if (this.CanTranslateY)
            {
                this.Children.Add(this.translateYL);
                this.Children.Add(this.translateYR);
            }

            if (this.CanTranslateZ)
            {
                this.Children.Add(this.translateZL);
                this.Children.Add(this.translateZR);
            }


            {
                var g = new LineBuilder();
                g.AddLine(new Vector3(0, 0, 0), new Vector3(1, 0, 0));
                g.AddLine(new Vector3(1, 0, 0), new Vector3(1, 1, 0));
                g.AddLine(new Vector3(1, 1, 0), new Vector3(0, 1, 0));
                g.AddLine(new Vector3(0, 1, 0), new Vector3(0, 0, 0));
                this.selectionBounds = new LineGeometryModel3D()
                {
                    Thickness        = 3,
                    Smoothness       = 2,
                    Color            = System.Windows.Media.Colors.Red,
                    IsThrowingShadow = false,
                    Geometry         = g.ToLineGeometry3D(),
                };
                this.Children.Add(this.selectionBounds);
            }
        }
コード例 #7
0
ファイル: ViewController.cs プロジェクト: stefkeB/IfcEngineCS
        private void CreateWireFrameModels(IFCItem item, Vector3D center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0)
                {
                    var points = new Vector3Collection();
                    Vector3Collection positions;
                    if (item.verticesForWireFrame != null)
                    {
                        for (int i = 0; i < item.noVerticesForWireFrame; i++)
                        {
                            points.Add(new Vector3((float)(item.verticesForWireFrame[3 * i + 0] - center.X), (float)(item.verticesForWireFrame[3 * i + 1] - center.Y), (float)(item.verticesForWireFrame[3 * i + 2] - center.Z)));
                        }
                    }

                    if (item.indicesForWireFrameLineParts != null)
                    {
                        positions = new Vector3Collection();
                        for (int i = 0; i < item.noPrimitivesForWireFrame; i++)
                        {
                            var idx = item.indicesForWireFrameLineParts[2 * i + 0];
                            positions.Add(points[idx]);
                            idx = item.indicesForWireFrameLineParts[2 * i + 1];
                            positions.Add(points[idx]);
                        }
                    }
                    else
                    {
                        positions = points;
                    }


                    var lineBuilder = new LineBuilder();
                    lineBuilder.Add(false, positions.ToArray());
                    LineGeometryModel3D line = new LineGeometryModel3D();
                    line.Geometry  = lineBuilder.ToLineGeometry3D();
                    line.Color     = new SharpDX.Color(0, 0, 0, 0);
                    item.Wireframe = line;
                    model.Add(line as Element3D);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
コード例 #8
0
        public DynaShapeDisplay(Solver solver)
        {
            this.solver = solver;

            pointGeometry = new PointGeometry3D
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            lineGeometry = new LineGeometry3D()
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            billboardText = new BillboardText3D();

            DynaShapeViewExtension.DynamoWindow.Dispatcher.Invoke(
                () =>
            {
                pointModel = new PointGeometryModel3D
                {
                    Size   = new Size(5, 5),
                    Figure = PointGeometryModel3D.PointFigure.Ellipse,
                    Color  = Color.White,
                };

                lineModel = new LineGeometryModel3D
                {
                    Thickness = 0.5,
                    Color     = Color.White,
                };

                billboardTextModel = new BillboardTextModel3D()
                {
                };
            },
                DispatcherPriority.Send);

            DynaShapeViewExtension.ViewModel.RequestViewRefresh += RequestViewRefreshHandler;
            DynaShapeViewExtension.DynamoWindow.Closed          += (sender, args) => Dispose();
        }
コード例 #9
0
        /// <summary>
        /// Initialize the Helix with these values. These values should be attached before the
        /// visualization starts. Deleting them and attaching them does not make any effect on helix.
        /// So they are initialized before the process starts.
        /// </summary>
        private void InitializeHelix()
        {
            directionalLight = new DirectionalLight3D
            {
                Color     = directionalLightColor,
                Direction = directionalLightDirection
            };

            if (model3DDictionary != null && !model3DDictionary.ContainsKey("DirectionalLight"))
            {
                model3DDictionary.Add("DirectionalLight", directionalLight);
            }

            LineGeometryModel3D gridModel3D = new LineGeometryModel3D
            {
                Geometry         = Grid,
                Transform        = Model1Transform,
                Color            = SharpDX.Color.White,
                Thickness        = 0.3,
                IsHitTestVisible = false
            };

            if (model3DDictionary != null && !model3DDictionary.ContainsKey("Grid"))
            {
                model3DDictionary.Add("Grid", gridModel3D);
            }

            LineGeometryModel3D axesModel3D = new LineGeometryModel3D
            {
                Geometry         = Axes,
                Transform        = Model1Transform,
                Color            = SharpDX.Color.White,
                Thickness        = 0.3,
                IsHitTestVisible = false
            };

            if (model3DDictionary != null && !model3DDictionary.ContainsKey("Axes"))
            {
                model3DDictionary.Add("Axes", axesModel3D);
            }
        }
コード例 #10
0
        /// <summary>
        /// set start point or end point
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void viewport3D_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var point = e.GetPosition((IInputElement)sender);
            var p     = viewport3D.FindNearestPoint(point);

            if (!p.HasValue)
            {
                return;
            }


            if (StartBall == null)
            {
                StartBall = CreateBall(PhongMaterials.Green);
            }
            if (EndBall == null)
            {
                EndBall = CreateBall(PhongMaterials.Red);
            }
            if (WayPath == null)
            {
                WayPath       = new LineGeometryModel3D();
                WayPath.Color = SharpDX.Color.Blue;
                mViewModel.PlayersGeometry.Add(WayPath);
                WayPath.Attach(mViewModel.modelView.RenderHost);
            }
            if (Keyboard.IsKeyDown(Key.LeftShift))
            {
                EndBall.Transform = new TranslateTransform3D(p.Value.X, p.Value.Y, p.Value.Z);
            }
            else
            {
                StartBall.Transform = new TranslateTransform3D(p.Value.X, p.Value.Y, p.Value.Z);
            }
            RenderPath();
        }
コード例 #11
0
        private void BuildGraphVisualization()
        {
            if (this.nodes == null || this.edges == null)
            {
                return;
            }

            this.Children.Clear();

            // pepare
            PhongMaterial material_nodes = new PhongMaterial();

            material_nodes.DiffuseColor      = new Color4(1f);
            material_nodes.AmbientColor      = new Color4(0.8f, 0.8f, 0.8f, 1f);
            material_nodes.SpecularColor     = new Color4(1f, 0.75f, 0f, 1f);
            material_nodes.SpecularShininess = 3;
            material_nodes.EmissiveColor     = new Color4(0.5f, 0.5f, 0.5f, 1f);

            LineBuilder lb = new LineBuilder();
            MeshBuilder mb = new MeshBuilder();

            // define geometry
            foreach (NeighbEdge e in this.edges)
            {
                if (e.IsValid)
                {
                    Vector3 connector1 = Utils.MeshesCustom.GetPolygonPivot(e.Match.Match01.VerticesInOrder.ToList());
                    Vector3 connector2 = Utils.MeshesCustom.GetPolygonPivot(e.Match.Match02.VerticesInOrder.ToList());

                    lb.AddLine(e.Node1.Volume.Volume_Pivot, connector1);
                    lb.AddLine(connector1, connector2);
                    lb.AddLine(connector2, e.Node2.Volume.Volume_Pivot);

                    mb.AddSphere(connector1, 0.1f, 8, 8);
                    mb.AddSphere(connector2, 0.1f, 8, 8);
                }
            }
            foreach (NeighbNode n in this.nodes)
            {
                if (n.IsValid)
                {
                    mb.AddSphere(n.Volume.Volume_Pivot, 0.25f, 8, 8);
                }
            }

            // define visualization
            this.edge_vis = new LineGeometryModel3D()
            {
                Geometry         = lb.ToLineGeometry3D(),
                Color            = Color.White,
                Thickness        = 1f,
                Visibility       = System.Windows.Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
            };
            this.Children.Add(this.edge_vis);

            this.nodes_vis = new MeshGeometryModel3D()
            {
                Geometry         = mb.ToMeshGeometry3D(),
                Material         = material_nodes,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
            };
            this.Children.Add(this.nodes_vis);

            // re-attach to renderer
            if (this.renderHost != null)
            {
                this.Attach(this.renderHost);
            }

            this.NeighborsUpToDate = true;
        }
コード例 #12
0
ファイル: Visualizer.cs プロジェクト: thegodi/Gygax
        public static GeometryModel3D[] GetCameraSpherical(CameraPosition camera, double radius = 1)
        {
            List <GeometryModel3D> models = new List <GeometryModel3D>();

            MeshBuilder         mb    = new MeshBuilder();
            MeshGeometryModel3D model = new MeshGeometryModel3D();

            mb.AddSphere(camera.CameraCenter.ToVector3(), radius);
            var geometry = mb.ToMeshGeometry3D();

            for (int i = 0; i < geometry.TextureCoordinates.Count; i++)
            {
                var v = geometry.TextureCoordinates[i];
                v.X = 1 - v.X;
                geometry.TextureCoordinates[i] = v;
            }

            model.Geometry        = geometry;
            model.Geometry.Colors = new Color4Collection(geometry.TextureCoordinates.Select(x => x.ToColor4()));

            model.Transform = new TranslateTransform3D(0, 0, 0);

            model.Material = PhongMaterials.Blue;

            model.Name = "SphericalCamera_" + camera.Name + "_" + camera.Id;

            models.Add(model);

            var linemodel = new LineGeometryModel3D();
            var lb        = new LineBuilder();

            //lb.AddLine(camera.CameraCenter, camera.CameraCenter + CameraPosition.Rotate(camera.Orientation, new Vector3(1, 0, 0)));
            //linemodel.Geometry = lb.ToLineGeometry3D();
            //linemodel.Color = new Color(255, 0, 0);

            //models.Add(linemodel);


            //linemodel = new LineGeometryModel3D();
            //lb = new LineBuilder();
            //lb.AddLine(camera.CameraCenter, camera.CameraCenter + CameraPosition.Rotate(camera.Orientation, new Vector3(0, 1, 0)));
            //linemodel.Geometry = lb.ToLineGeometry3D();
            //linemodel.Color = new Color(0, 255, 0);

            //models.Add(linemodel);

            //linemodel = new LineGeometryModel3D();
            //lb = new LineBuilder();
            //lb.AddLine(camera.CameraCenter, camera.CameraCenter + CameraPosition.Rotate(camera.Orientation, new Vector3(0, 0, 1)));
            //linemodel.Geometry = lb.ToLineGeometry3D();
            //linemodel.Color = new Color(0, 0, 255);

            //models.Add(linemodel);

            linemodel = new LineGeometryModel3D();
            lb        = new LineBuilder();
            lb.AddLine(camera.CameraCenter.ToVector3(), (camera.CameraCenter + camera.Orientation.Axis).ToVector3());
            linemodel.Geometry = lb.ToLineGeometry3D();
            linemodel.Color    = new Color(255, 255, 0);

            linemodel.Name = "Orientation_SphericalCamera_" + camera.Name + "_" + camera.Id;

            models.Add(linemodel);

            return(models.ToArray());
        }
コード例 #13
0
        protected virtual void UpdateOnCoordsChange()
        {
            // initialize coordinates
            Coords2Pos();

            if (pos == null)
            {
                return;
            }

            this.Children.Clear();

            // initialise handle lists
            int n = pos.Count;

            endHandles      = new List <DraggableGeometryWoSnapModel3D>(n);
            midpointHandles = new List <MeshGeometryModel3D>(n);
            edgeHandles     = new List <MeshGeometryModel3D>(n);

            endH_indInChildren  = new List <int>(n);
            midPH_indInChildren = new List <int>(n);
            edgeH_indInChildren = new List <int>(n);

            // determine scaling factor of grips
            BoundingBox bb         = BoundingBox.FromPoints(pos.ToArray());
            float       avgDistCam = Vector3.Distance(Vector3.Lerp(bb.Maximum, bb.Minimum, 0.5f), this.CamPos.ToVector3());

            this.scaleCamPos = Math.Max(1f, avgDistCam);

            for (int i = 0; i < n; i++)
            {
                // this.scaleCamPos = Vector3.Distance(pos[i], this.CamPos.ToVector3());
                // ENDPOINT handles
                Matrix3D T = Matrix3D.Identity;
                T.Scale(new Vector3D(this.scaleCamPos, this.scaleCamPos, this.scaleCamPos));
                T.Translate(pos[i].ToVector3D());
                var m1 = new DraggableGeometryWoSnapModel3D()
                {
                    Visibility = Visibility.Visible,
                    Material   = this.SelMaterial,
                    Geometry   = NodeGeometry,
                    Transform  = new MatrixTransform3D(T),
                };
                m1.MouseDown3D += OnNodeMouse3DDown;
                m1.MouseMove3D += OnNodeMouse3DMove;
                m1.MouseUp3D   += OnNodeMouse3DUp;
                this.endHandles.Add(m1);
                this.Children.Add(m1);
                this.endH_indInChildren.Add(this.Children.Count - 1);

                // MIDPOINT handles
                Matrix3D M = Matrix3D.Identity;
                M.Scale(new Vector3D(this.scaleCamPos, this.scaleCamPos, this.scaleCamPos));
                M.Translate(Vector3.Lerp(pos[i], pos[(i + 1) % n], 0.5f).ToVector3D());
                var m2 = new MeshGeometryModel3D()
                {
                    Geometry         = MidEdgeGeometry,
                    Material         = this.SelMaterial,
                    Visibility       = Visibility.Visible,
                    IsHitTestVisible = true,
                    Transform        = new MatrixTransform3D(M),
                };
                m2.MouseDown3D += OnMidNodeMouse3DDown;
                m2.MouseMove3D += OnMidNodeMouse3DMove;
                m2.MouseUp3D   += OnMidNodeMouse3DUp;
                this.midpointHandles.Add(m2);
                this.Children.Add(m2);
                this.midPH_indInChildren.Add(this.Children.Count - 1);

                // EDGE handles
                Matrix L  = calcTransf(pos[i], pos[(i + 1) % n], this.scaleCamPos * EDGE_GRIP_SIZE);
                var    m3 = new MeshGeometryModel3D()
                {
                    Geometry         = EdgeGeometry,
                    Material         = this.materialLines,
                    Visibility       = Visibility.Visible,
                    IsHitTestVisible = true,
                    Transform        = new MatrixTransform3D(L.ToMatrix3D()),
                };
                m3.MouseDown3D += OnEdgeMouse3DDown;
                m3.MouseMove3D += OnEdgeMouse3DMove;
                m3.MouseUp3D   += OnEdgeMouse3DUp;
                this.edgeHandles.Add(m3);
                this.Children.Add(m3);
                this.edgeH_indInChildren.Add(this.Children.Count - 1);
            }

            // lines showing Modification along axes (hidden for the moment)
            this.modifyLines = new LineGeometryModel3D()
            {
                Geometry         = LineGeometry,
                Color            = SharpDX.Color.White,
                Thickness        = 0.5,
                Visibility       = Visibility.Hidden,
                IsHitTestVisible = false,
            };
            this.Children.Add(modifyLines);
            this.posML_old = Vector3.Zero;

            // adjust for open / closed polyline
            OnIsPolyLineClosedProperty_IsFalse();

            // !!!!!!! REATTACH TO THE RENDER HOST !!!!!!!
            if (this.renderHost != null)
            {
                Attach(this.renderHost);
            }
        }
コード例 #14
0
ファイル: Control3D.xaml.cs プロジェクト: thegodi/Gygax
        private void ViewModel()
        {
            Application.Current.Dispatcher.Invoke(delegate
            {
                InitViewport();

                var vis = Visualizer.Visualizer.GetModels(_streamableObject.Data);

                if (vis == null)
                {
                    return;
                }

                foreach (var m in vis)
                {
                    var model = m;

                    if (model.Parent != null)
                    {
                        if (model is MeshGeometryModel3D)
                        {
                            model = new MeshGeometryModel3D()
                            {
                                Geometry  = ((MeshGeometryModel3D)m).Geometry,
                                Material  = ((MeshGeometryModel3D)m).Material,
                                Transform = ((MeshGeometryModel3D)m).Transform
                            };
                        }
                        else if (model is PointGeometryModel3D)
                        {
                            model = new PointGeometryModel3D()
                            {
                                Geometry  = ((PointGeometryModel3D)m).Geometry,
                                Transform = ((PointGeometryModel3D)m).Transform,
                                Color     = ((PointGeometryModel3D)m).Color
                            };
                        }
                        else if (model is LineGeometryModel3D)
                        {
                            model = new LineGeometryModel3D()
                            {
                                Geometry  = ((LineGeometryModel3D)m).Geometry,
                                Transform = ((LineGeometryModel3D)m).Transform,
                                Color     = ((LineGeometryModel3D)m).Color
                            };
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (Viewport.RenderHost.RenderTechnique != null)
                    {
                        model.Attach(Viewport.RenderHost);
                    }

                    Viewport.Items.Add(model);
                }

                ViewportHelper.ZoomExtents(Viewport);

                Viewport.Visibility         = Visibility.Visible;
                LoadingAnimation.Visibility = Visibility.Hidden;
            });
        }
コード例 #15
0
        private void AggregateRenderPackages(PackageAggregationParams parameters)
        {
            //Clear the geometry values before adding the package.
            VisualizationManager_WorkspaceOpenedClosedHandled();

            foreach (var rp in parameters.Packages)
            {
                //Node ID gets updated with a ":" everytime this function is called.
                //For example, if the same point node is called multiple times (CBN), the ID has a ":"
                //and this makes the dictionary to have multiple entries for the same node.
                var baseId = rp.Description;
                if (baseId.IndexOf(":", StringComparison.Ordinal) > 0)
                {
                    baseId = baseId.Split(':')[0];
                }
                var id = baseId;

                var p = rp.Points;
                if (p.Positions.Any())
                {
                    id = baseId + ":points";

                    PointGeometryModel3D pointGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        pointGeometry3D = model3DDictionary[id] as PointGeometryModel3D;
                    }
                    else
                    {
                        pointGeometry3D = new PointGeometryModel3D
                        {
                            Geometry         = HelixRenderPackage.InitPointGeometry(),
                            Transform        = Model1Transform,
                            Color            = SharpDX.Color.White,
                            Figure           = PointGeometryModel3D.PointFigure.Ellipse,
                            Size             = DefaultPointSize,
                            IsHitTestVisible = true,
                            IsSelected       = rp.IsSelected
                        };
                        model3DDictionary.Add(id, pointGeometry3D);
                    }

                    var points   = pointGeometry3D.Geometry as PointGeometry3D;
                    var startIdx = points.Positions.Count;

                    points.Positions.AddRange(p.Positions);
                    points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                    points.Indices.AddRange(p.Indices.Select(i => i + startIdx));

                    if (rp.DisplayLabels)
                    {
                        var pt = p.Positions[0];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    pointGeometry3D.Geometry     = points;
                    pointGeometry3D.Name         = baseId;
                    pointGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var l = rp.Lines;
                if (l.Positions.Any())
                {
                    id = baseId + ":lines";

                    LineGeometryModel3D lineGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        lineGeometry3D = model3DDictionary[id] as LineGeometryModel3D;
                    }
                    else
                    {
                        lineGeometry3D = new LineGeometryModel3D()
                        {
                            Geometry         = HelixRenderPackage.InitLineGeometry(),
                            Transform        = Model1Transform,
                            Color            = SharpDX.Color.White,
                            Thickness        = 0.5,
                            IsHitTestVisible = true,
                            IsSelected       = rp.IsSelected
                        };

                        model3DDictionary.Add(id, lineGeometry3D);
                    }

                    var lineSet  = lineGeometry3D.Geometry as LineGeometry3D;
                    var startIdx = lineSet.Positions.Count;

                    lineSet.Positions.AddRange(l.Positions);
                    lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                    lineSet.Indices.AddRange(l.Indices.Any() ? l.Indices.Select(i => i + startIdx) : Enumerable.Range(startIdx, startIdx + l.Positions.Count));

                    if (rp.DisplayLabels)
                    {
                        var pt = lineSet.Positions[startIdx];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    lineGeometry3D.Geometry     = lineSet;
                    lineGeometry3D.Name         = baseId;
                    lineGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var m = rp.Mesh;
                if (!m.Positions.Any())
                {
                    continue;
                }

                id = ((rp.RequiresPerVertexColoration || rp.Colors != null) ? rp.Description : baseId) + ":mesh";

                DynamoGeometryModel3D meshGeometry3D;

                if (model3DDictionary.ContainsKey(id))
                {
                    meshGeometry3D = model3DDictionary[id] as DynamoGeometryModel3D;
                }
                else
                {
                    meshGeometry3D = new DynamoGeometryModel3D()
                    {
                        Transform                   = Model1Transform,
                        Material                    = WhiteMaterial,
                        IsHitTestVisible            = true,
                        RequiresPerVertexColoration = rp.RequiresPerVertexColoration,
                        IsSelected                  = rp.IsSelected,
                    };

                    if (rp.Colors != null)
                    {
                        var pf     = PixelFormats.Bgra32;
                        var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8;
                        try
                        {
                            var diffMap = BitmapSource.Create(rp.ColorsStride / 4, rp.Colors.Count() / rp.ColorsStride, 96.0, 96.0, pf, null,
                                                              rp.Colors.ToArray(), stride);
                            var diffMat = new PhongMaterial
                            {
                                Name              = "White",
                                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                                DiffuseColor      = materialColor,
                                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                                SpecularShininess = 12.8f,
                                DiffuseMap        = diffMap
                            };
                            meshGeometry3D.Material = diffMat;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    ((MaterialGeometryModel3D)meshGeometry3D).SelectionColor = selectionColor;
                    model3DDictionary.Add(id, meshGeometry3D);
                }

                var mesh = meshGeometry3D.Geometry == null?HelixRenderPackage.InitMeshGeometry() : meshGeometry3D.Geometry as MeshGeometry3D;

                var idxCount = mesh.Positions.Count;

                mesh.Positions.AddRange(m.Positions);

                mesh.Colors.AddRange(m.Colors);
                mesh.Normals.AddRange(m.Normals);
                mesh.TextureCoordinates.AddRange(m.TextureCoordinates);
                mesh.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                if (mesh.Colors.Any(c => c.Alpha < 1.0))
                {
                    meshGeometry3D.HasTransparency = true;
                }

                if (rp.DisplayLabels)
                {
                    var pt = mesh.Positions[idxCount];
                    parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    Text = parameters.Text;
                }

                meshGeometry3D.Geometry     = mesh;
                meshGeometry3D.Name         = baseId;
                meshGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
            }

            Attach();
        }
コード例 #16
0
        public VolumeDisplay()
        {
            coords_polygons = new List <List <Point3D> >();

            // fill in polygon data with test values

            // CASE 1
            //coords_polygons.Add(VolumeDisplay.TestPoly1);

            //Matrix3D M2 = Matrix3D.Identity;
            //M2.Scale(new Vector3D(0.5, 1, 0.5));
            //Point3D[] testPoly2_ar = VolumeDisplay.TestPoly2.ToArray();
            //M2.Transform(testPoly2_ar);
            //coords_polygons.Add(new List<Point3D>(testPoly2_ar));

            //reverse_polygons = new List<bool> { false, false };

            // CASE 2
            coords_polygons.Add(VolumeDisplay.TestPolyA1);
            coords_polygons.Add(VolumeDisplay.TestPolyA2);
            coords_polygons.Add(VolumeDisplay.TestPolyA3);
            coords_polygons.Add(VolumeDisplay.TestPolyA4);

            reverse_polygons = new List <bool> {
                true, true, true, true
            };

            // Geometry Model Definitions
            this.polygons = new LineGeometryModel3D()
            {
                Geometry         = null,
                Color            = Color.LightBlue,
                Thickness        = 1,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(polygons);

            this.volume = new MeshGeometryModel3D()
            {
                Geometry         = null,
                Material         = VolumeDisplay.VolumeMat,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(volume);

            this.volumeEdges = new LineGeometryModel3D()
            {
                Geometry         = null,
                Color            = Color.White,
                Thickness        = 0.5,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(volumeEdges);

            this.volumeNormals = new LineGeometryModel3D()
            {
                Geometry         = null,
                Color            = Color.DarkBlue,
                Thickness        = 0.5,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(volumeNormals);

            UpdateGeometry();
        }
コード例 #17
0
ファイル: Common3DSpace.xaml.cs プロジェクト: thegodi/Gygax
        public void UpdateView()
        {
            if (Visibility != Visibility.Visible)
            {
                return;
            }

            foreach (var streamable in Items)
            {
                if (streamable.Name == null || streamable.Name == "")
                {
                    continue;
                }

                var foundOne = false;

                //Check if datastream is already in the tree
                foreach (var item in DatastreamTree.Items)
                {
                    if ((TreeViewItem)item == null || ((TreeViewItem)item).DataContext == streamable)
                    {
                        foundOne = true;
                        break;
                    }
                }

                if (foundOne)
                {
                    continue;
                }

                var elements = Visualizer.Visualizer.GetModels(streamable.Data);

                var adds = Visualizer.Visualizer.GetTreeItems(streamable, elements);

                if (adds == null)
                {
                    continue;
                }

                DatastreamTree.Items.Add(adds);

                if (elements == null)
                {
                    continue;
                }
                if (elements == null)
                {
                    continue;
                }

                foreach (var m in elements)
                {
                    var model = m;

                    if (model.Parent != null)
                    {
                        if (model is MeshGeometryModel3D)
                        {
                            model = new MeshGeometryModel3D()
                            {
                                Geometry  = ((MeshGeometryModel3D)m).Geometry,
                                Material  = ((MeshGeometryModel3D)m).Material,
                                Transform = ((MeshGeometryModel3D)m).Transform,
                            };
                        }
                        else if (model is PointGeometryModel3D)
                        {
                            model = new PointGeometryModel3D()
                            {
                                Geometry  = ((PointGeometryModel3D)m).Geometry,
                                Transform = ((PointGeometryModel3D)m).Transform,
                                Color     = ((PointGeometryModel3D)m).Color
                            };
                        }
                        else if (model is LineGeometryModel3D)
                        {
                            model = new LineGeometryModel3D()
                            {
                                Geometry  = ((LineGeometryModel3D)m).Geometry,
                                Transform = ((LineGeometryModel3D)m).Transform,
                                Color     = ((LineGeometryModel3D)m).Color
                            };
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (Viewport.RenderHost.RenderTechnique != null)
                    {
                        model.Attach(Viewport.RenderHost);
                    }

                    Viewport.Items.Add(model);
                }
            }

            ViewportHelper.ZoomExtents(Viewport);
        }
コード例 #18
0
ファイル: Visualizer.cs プロジェクト: thegodi/Gygax
        private static GeometryModel3D[] GetCameraPlanar(CameraPosition camera)
        {
            List <GeometryModel3D> models = new List <GeometryModel3D>();

            var model = new MeshGeometryModel3D();

            var length = (camera.FocalLength / Math.Sqrt(Math.Pow(camera.Height, 2) + Math.Pow(camera.Width, 2)));

            var p1 = camera.CameraCenter +
                     length * (CameraPosition.GetCornerPointToAxis(camera, camera.Orientation,
                                                                   CameraPosition.Direction.TopLeft));

            var p2 = camera.CameraCenter +
                     length * (CameraPosition.GetCornerPointToAxis(camera, camera.Orientation,
                                                                   CameraPosition.Direction.TopRight));

            var p3 = camera.CameraCenter +
                     length * (CameraPosition.GetCornerPointToAxis(camera, camera.Orientation,
                                                                   CameraPosition.Direction.BottomRight));

            var p4 = camera.CameraCenter +
                     length * (CameraPosition.GetCornerPointToAxis(camera, camera.Orientation,
                                                                   CameraPosition.Direction.BottomLeft));

            model.Geometry = PrimitiveBuilder.GetRect(p1.ToVector3(), p2.ToVector3(), p3.ToVector3(), p4.ToVector3());

            //model.Material = new PhongMaterial
            //{
            //    DiffuseMap = new BitmapImage(new Uri(camera.File))
            //};

            ////model.Material = PhongMaterials.Yellow;

            ////Viewport.Items.Add(model);
            //models.Add(model);

            var linemodel = new LineGeometryModel3D();
            var lb        = new LineBuilder();

            lb.AddLine(camera.CameraCenter.ToVector3(), p1.ToVector3());
            lb.AddLine(camera.CameraCenter.ToVector3(), p2.ToVector3());
            lb.AddLine(camera.CameraCenter.ToVector3(), p3.ToVector3());
            lb.AddLine(camera.CameraCenter.ToVector3(), p4.ToVector3());
            lb.AddLine(p1.ToVector3(), p2.ToVector3());
            lb.AddLine(p2.ToVector3(), p3.ToVector3());
            lb.AddLine(p3.ToVector3(), p4.ToVector3());
            lb.AddLine(p4.ToVector3(), p1.ToVector3());
            lb.AddLine(p1.ToVector3(), p3.ToVector3());
            lb.AddLine(p2.ToVector3(), p4.ToVector3());

            linemodel.Geometry = lb.ToLineGeometry3D();
            linemodel.Color    = LUT.GetRandomColor();

            linemodel.Name = "PlanarCamera_" + Path.GetFileName(camera.File).Split('.').First() + "_" + camera.Id;

            models.Add(linemodel);

            MeshBuilder         mb = new MeshBuilder();
            MeshGeometryModel3D modelCameraCenter = new MeshGeometryModel3D();

            mb.AddSphere(camera.CameraCenter.ToVector3(), 0.03);
            mb.AddSphere(p1.ToVector3(), 0.03);
            modelCameraCenter.Geometry = mb.ToMeshGeometry3D();

            modelCameraCenter.Material = new PhongMaterial()
            {
                DiffuseColor = linemodel.Color,
                AmbientColor = linemodel.Color
            };


            //models.Add(modelCameraCenter);

            return(models.ToArray());
        }
コード例 #19
0
        public PolygonDisplay()
        {
            //// CASE: Extra points
            //this.polygonDef = PolygonDisplay.PolyBig_2;
            //this.holesDef = null;

            //// CASE: PPT Lecture
            //this.polygonDef = PolygonDisplay.PolyBig_4;
            //this.holesDef = null;

            //// CASE: My Test
            //this.polygonDef = PolygonDisplay.PolyBig_3;
            //this.holesDef = new List<List<Point3D>>();
            //this.holesDef.Add(PolygonDisplay.PolyBig_3_HOLE_1);
            //this.holesDef.Add(PolygonDisplay.PolyBig_3_HOLE_2);

            //// CASE: Chaos
            //this.polygonDef = PolygonDisplay.PolyBig_Paper;
            //this.holesDef = new List<List<Point3D>>();
            //this.holesDef.Add(PolygonDisplay.PolyBig_Paper_HOLE_1);
            //this.holesDef.Add(PolygonDisplay.PolyBig_Paper_HOLE_2);
            //this.holesDef.Add(PolygonDisplay.PolyBig_Paper_HOLE_3);

            //// CASE: ARCHITECTURE w/o holes
            //this.polygonDef = PolygonDisplay.PolyBig_ARC1;
            //this.holesDef = null;

            // CASE: ARCHITECTURE 1 w HOLEs
            this.polygonDef = PolygonDisplay.PolyBig_ARC2;
            this.holesDef   = new List <List <Point3D> >();
            this.holesDef.Add(PolygonDisplay.PolyBig_ARC2_HOLE_1);
            this.holesDef.Add(PolygonDisplay.PolyBig_ARC2_HOLE_2);
            this.holesDef.Add(PolygonDisplay.PolyBig_ARC2_HOLE_3);
            this.holesDef.Add(PolygonDisplay.PolyBig_ARC2_HOLE_4);
            this.holesDef.Add(PolygonDisplay.PolyBig_ARC2_HOLE_5);
            this.holesDef.Add(PolygonDisplay.PolyBig_ARC2_HOLE_6);
            this.holesDef.Add(PolygonDisplay.PolyBig_ARC2_HOLE_7);

            //// CASE: ARCHITECTURE 2
            //this.polygonDef = PolygonDisplay.EG_POLY_1;
            //this.holesDef = new List<List<Point3D>>();
            //this.holesDef.Add(PolygonDisplay.EG_POLY_1_HOLE_1);
            //this.holesDef.Add(PolygonDisplay.EG_POLY_1_HOLE_2);
            //this.holesDef.Add(PolygonDisplay.EG_POLY_1_HOLE_3);

            //// CASE: ARCHITECTURE 3
            //this.polygonDef = PolygonDisplay.OG2_POLY_1;
            //this.holesDef = new List<List<Point3D>>();
            //this.holesDef.Add(PolygonDisplay.OG2_POLY_1_HOLE_1);
            //this.holesDef.Add(PolygonDisplay.OG2_POLY_1_HOLE_2);
            //this.holesDef.Add(PolygonDisplay.OG2_POLY_1_HOLE_3);
            //this.holesDef.Add(PolygonDisplay.OG2_POLY_1_HOLE_4);
            //this.holesDef.Add(PolygonDisplay.OG2_POLY_1_HOLE_5);
            //this.holesDef.Add(PolygonDisplay.OG2_POLY_1_HOLE_6);

            CreateSubpolygonGeometry();

            this.polygonEdges = new LineGeometryModel3D()
            {
                Geometry         = null,
                Color            = Color.Indigo,
                Thickness        = 1,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(this.polygonEdges);

            this.polygonFill = new MeshGeometryModel3D()
            {
                Geometry         = null,
                Material         = PolygonDisplay.VolumeMat,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(this.polygonFill);

            this.polygonFillEdges = new LineGeometryModel3D()
            {
                Geometry         = null,
                Color            = Color.Indigo,
                Thickness        = 0.3,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(this.polygonFillEdges);

            this.UpdateGeometry();
        }
コード例 #20
0
ファイル: MainWindow.xaml.cs プロジェクト: rubedos/viper_win
        /// <summary>
        /// Process point cloud as soon as it arrives
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImagingPipeline_ImageDataProcessed(object sender, Rubedos.PointcloudProcessing.ImagingPipelineProcessedEventArgs e)
        {
            var rgbd = pointCloudViewModel.ImagingPipeline.RgbdOut;

            if (points == null)
            {
                points = new float[rgbd.Cols * rgbd.Rows * rgbd.NumberOfChannels];
            }
            int w = rgbd.Cols, h = rgbd.Rows;

            // hint: working with data buffer is much faster than accessing individual points in Cv.Mat
            System.Runtime.InteropServices.Marshal.Copy(rgbd.DataPointer, points, 0, points.Length);

            float minZ = groundZ,
                  maxX = -groundW, minX = groundW, minY = groundD, maxY = -groundD;

            for (int y = 1; y < h; y += 1)
            {
                for (int x = 1; x < w; x += 1)
                {
                    var current = GetPoint(points, x, y, w, h);
                    if (current.Z > groundZ || current.Z < 1.0f ||
                        current.X > groundW / 2 || current.X < -groundW / 2 ||
                        current.Y > groundD / 2 || current.Y < -groundD / 2)
                    {
                        continue; // Out of space of interest
                    }
                    if (current.X > maxX)
                    {
                        maxX = current.X;
                    }
                    if (current.X < minX)
                    {
                        minX = current.X;
                    }
                    if (current.Y > maxY)
                    {
                        maxY = current.Y;
                    }
                    if (current.Y < minY)
                    {
                        minY = current.Y;
                    }
                    if (current.Z < minZ)
                    {
                        minZ = current.Z;
                    }
                }
            }
            Console.WriteLine("Boundaries: X ({0:0.00}; {1:0.00}) Y ({2:0.00}; {3:0.00}) Z ({4:0.00}; {5:0.00})",
                              maxX, minX, maxY, minY, groundZ, minZ);

            // Synchronizing with 3D rendering thread
            pointCloudViewModel.Context.Send((o) =>
            {
                boundingBoxGroup.Children.Clear();
                MeshBuilder mb = new MeshBuilder();
                var center     = new Vector3((maxY + minY) / 2, (maxX + minX) / 2, (groundZ - minZ) / 2);
                float xlen     = maxY - minY, ylen = maxX - minX, zlen = groundZ - minZ;
                mb.AddBox(center, xlen, ylen, zlen);

                MeshGeometryModel3D mmodel = new MeshGeometryModel3D();
                boundingBoxGroup.Children.Add(mmodel);
                mmodel.Geometry = mb.ToMeshGeometry3D();

                var boxColor    = System.Windows.Media.Color.FromArgb(30, 50, 0, 255).ToColor4();
                mmodel.Material = new PhongMaterial()
                {
                    AmbientColor = boxColor,      // System.Windows.Media.Colors.Gray.ToColor4(),
                    DiffuseColor = boxColor,      //System.Windows.Media.Colors.Yellow.ToColor4(),
                                                  //System.Windows.Media.Color.FromArgb(100, 255, 0 , 0).ToColor4(),
                    SpecularColor     = boxColor, // System.Windows.Media.Colors.Gray.ToColor4(),
                    SpecularShininess = 100f,
                };

                LineGeometryModel3D linem = new LineGeometryModel3D();
                var lb = new LineBuilder();
                lb.AddBox(center, xlen, ylen, zlen);
                linem.Thickness = 1;
                linem.Color     = System.Windows.Media.Colors.Yellow; //System.Windows.Media.Color.FromArgb(30, 50, 0, 255).ToColor4();
                linem.Geometry  = lb.ToLineGeometry3D();
                boundingBoxGroup.Children.Add(linem);
                float scale = 1.0f;
                labels.TextInfo.Clear();
                labels.TextInfo.Add(new TextInfo()
                {
                    Text   = String.Format("H = {0:0.0} m", zlen),
                    Origin = new Vector3(xlen / 2 + 0.1f, -(ylen / 2 + 0.1f), zlen / 2) + center, Foreground = Colors.Black.ToColor4(), Scale = scale
                });

                labels.TextInfo.Add(new TextInfo()
                {
                    Text       = String.Format("W = {0:0.0} m", xlen),
                    Origin     = new Vector3(0, ylen / 2 + 0.1f, zlen + 0.1f) + center,
                    Foreground = Colors.Black.ToColor4(),
                    Scale      = scale
                });

                labels.TextInfo.Add(new TextInfo()
                {
                    Text       = String.Format("D = {0:0.0} m", ylen),
                    Origin     = new Vector3(xlen / 2 + 0.1f, 0f, zlen + 0.1f) + center,
                    Foreground = Colors.Black.ToColor4(),
                    Scale      = scale
                });
            }, null);
        }
コード例 #21
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // =============================================== CONSTRUCTORS =========================================== //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region CONSTRUCTOR
        public OcTreeManager()
        {
            this.root = new OcTree();

            // OcTree CELL visualization
            this.cell = new LineGeometryModel3D()
            {
                Geometry         = OcTreeManager.CellFrame,
                Color            = SharpDX.Color.White,
                Thickness        = 0.5,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(cell);

            // Collision MARKERS visualization
            this.colPointMarker = new LineGeometryModel3D()
            {
                Geometry         = OcTreeManager.IntPoint,
                Color            = SharpDX.Color.Red,
                Thickness        = 1.5,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(colPointMarker);

            // Collision REGIONS visualization
            this.cellFill = new MeshGeometryModel3D()
            {
                Geometry         = OcTreeManager.ChamferedBoxMesh,
                Material         = OcTreeManager.RedTransparent,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(cellFill);

            // Visible REGIONS visualization
            this.cellVisible = new MeshGeometryModel3D()
            {
                Geometry         = OcTreeManager.ChamferedBoxMesh,
                Material         = OcTreeManager.YellowTransparent,
                Visibility       = Visibility.Visible,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(cellVisible);

            // DEBUG
            this.cellVisibleNormals = new LineGeometryModel3D()
            {
                Geometry         = OcTreeManager.ChamferedBoxMesh_Normals,
                Color            = Color.DarkBlue,
                Thickness        = 0.5,
                Visibility       = Visibility.Hidden,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
                Instances        = new List <SharpDX.Matrix>(),
            };
            this.Children.Add(cellVisibleNormals);
            // DEBUG

            // ------------------------------------ OBJECT SNAP -------------------------------------- //
            this.PointsCollision   = new List <Point3D>();
            this.PointsVisible_End = new List <Point3D>();
            this.PointsVisible_Mid = new List <Point3D>();
            this.snapMarker        = new LineGeometryModel3D()
            {
                Geometry         = OcTreeManager.EndPoint,
                Color            = SharpDX.Color.Yellow,
                Thickness        = 1,
                Visibility       = Visibility.Hidden,
                IsHitTestVisible = false,
                Transform        = new MatrixTransform3D(Matrix3D.Identity),
            };
            this.Children.Add(this.snapMarker);
            // ------------------------------------ OBJECT SNAP -------------------------------------- //

            // commands
            this.CheckForCollisionsSimpleCmd = new RelayCommand((x) => CheckForCollisionSimpleCommand(), (x) => CanExecute_CheckForCollisionsCommand());
            this.CheckForCollisionsCmd       = new RelayCommand((x) => CheckForCollisionsCommand(), (x) => CanExecute_CheckForCollisionsCommand());

            this.CheckForVisibilitySimpleCmd = new RelayCommand((x) => CheckForVisibilitySimpleCommand(x), (x) => CanExecute_CheckForVisibilityCommand(x));
            this.CheckForVisibilityCmd       = new RelayCommand((x) => CheckForVisibilityCommand(x), (x) => CanExecute_CheckForVisibilityCommand(x));

            this.UpdateOcTreeCmd    = new RelayCommand((x) => UpdateOcTree());
            this.CleanVisualAidsCmd = new RelayCommand((x) => CleanUpCells());
        }