private void AddGeometryToExistingPoint(PointGeometryModel3D point, Vector3 location)
        {
            if (point == null || point.Geometry == null)
            {
                return;
            }

            point.Geometry.Positions.Add(location);
            point.Geometry.Colors.Add(new Color4());
            point.Geometry.Indices.Add(point.Geometry.Indices.Any()? point.Geometry.Indices.Last() + 1: 0);
        }
Example #2
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();
            };
        }
Example #3
0
        public static GeometryModel3D[] GetModels(NViewMatch nvm)
        {
            var showCameras = true;

            var tg = new MatrixTransform3D(nvm.Transform);

            List <GeometryModel3D> models = new List <GeometryModel3D>();

            if (showCameras)
            {
                foreach (var cameraPosition in nvm.CameraPositions)
                {
                    var pos = GetCamera(cameraPosition);

                    foreach (var c in pos)
                    {
                        c.Transform = tg;
                        models.Add(c);
                    }
                }
            }

            if (nvm.Patches.Count <= 0)
            {
                return(models.ToArray());
            }

            PointGeometryModel3D model = new PointGeometryModel3D();

            model.Color = Color.White;

            model.Geometry = Pointcloud.ConvertToPointGeometry3D(
                nvm.Patches.Select(patch => new PclWrapper.Points
            {
                x = patch.Position.X,
                y = patch.Position.Y,
                z = patch.Position.Z,
                r = (byte)patch.Color.Red,
                g = (byte)patch.Color.Green,
                b = (byte)patch.Color.Blue,
                a = 255
            }).ToArray());

            models.Add(model);

            model.Transform = tg;

            return(models.ToArray());
        }
        public void Setup()
        {
            closePoint = InitializePointWithId("closePoint");
            farPoint   = InitializePointWithId("farPoint", new Vector3(10000, 10000, 10000));
            var builder = new MeshBuilder();

            builder.AddBox(new Vector3(-10000, -10000, -5000), 5, 5, 5, BoxFaces.All);
            var boxGeom = builder.ToMeshGeometry3D();

            cube = new MeshGeometryModel3D()
            {
                Geometry = boxGeom,
                Name     = "cube"
            };
        }
        private PointGeometryModel3D InitializePointWithId(string id, Vector3 location = new Vector3())
        {
            var pointGeom = HelixRenderPackage.InitPointGeometry();

            pointGeom.Positions.Add(location);
            pointGeom.Colors.Add(new Color4());
            pointGeom.Indices.Add(0);
            var point = new PointGeometryModel3D
            {
                Geometry = pointGeom,
                Name     = id
            };

            return(point);
        }
Example #6
0
        public static GeometryModel3D[] GetModels(PointGeometry3D pointcloud)
        {
            List <GeometryModel3D> models = new List <GeometryModel3D>();

            PointGeometryModel3D model = new PointGeometryModel3D();

            // This one is important, otherwise it will be just black
            model.Color = Color.White;

            model.Geometry = pointcloud;

            model.Name = "Points";

            models.Add(model);

            return(models.ToArray());
        }
Example #7
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();
        }
Example #8
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();
        }
Example #9
0
        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);
        }
Example #10
0
        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;
            });
        }