Beispiel #1
0
        public void SetTrianglePatch(IEnumerable <Triangle> triangles, SurfacePatch patch)
        {
            foreach (var t in triangles)
            {
                t.Patch = patch;
            }

            SurfaceMesh.UpdateProcessedGeometry((float)SurfaceOffset);
        }
Beispiel #2
0
        private void UnlockFrom(SurfacePatch target)
        {
            if (target == null || target.ParentWindow == null || target.Viewport == null)
            {
                return;
            }

            target.ParentWindow.SizeChanged        -= TargetWindow_SizeChanged;
            target.Viewport.Camera.PropertyChanged -= TargetCamera_PropertyChanged;
        }
Beispiel #3
0
        private void LockTo(SurfacePatch target)
        {
            if (target == null || target.ParentWindow == null || target.Viewport == null)
            {
                return;
            }

            target.ParentWindow.Closing            += TargetWindow_Closing;
            target.ParentWindow.SizeChanged        += TargetWindow_SizeChanged;
            target.Viewport.Camera.PropertyChanged += TargetCamera_PropertyChanged;

            Random        Rand            = new Random(123);
            List <Vertex> ForRandom       = new List <Vertex>(SurfaceMesh.Vertices);
            List <Vertex> RandomSelection = new List <Vertex>();

            for (int i = 0; i < Math.Min(50, SurfaceMesh.Vertices.Count); i++)
            {
                int Index = Rand.Next(ForRandom.Count - 1);
                RandomSelection.Add(ForRandom[Index]);
                ForRandom.RemoveAt(Index);
            }

            VertexLocks.Clear();

            foreach (var v in RandomSelection)
            {
                float           ClosestDistance = float.MaxValue;
                List <Triangle> Targets         = target.OriginalToTransformed.Values.ToList();
                Triangle        ClosestTriangle = Targets[0];
                foreach (var t in Targets)
                {
                    float Distance = (v.VolumePosition - t.GetVolumeCenter()).Length;
                    if (Distance < ClosestDistance)
                    {
                        ClosestDistance = Distance;
                        ClosestTriangle = t;
                    }
                }

                HashSet <Triangle> Neighborhood = Triangle.Grow(new HashSet <Triangle> {
                    ClosestTriangle
                });
                VertexLocks.Add(v, Neighborhood.ToArray());
            }

            MatchCamera();
            MatchPosition();
        }
        private void ButtonLoadSession_OnClick(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog Dialog = new System.Windows.Forms.OpenFileDialog();
            Dialog.Filter = "XML File|*.xml";
            System.Windows.Forms.DialogResult Result = Dialog.ShowDialog();

            if (Result.ToString() == "OK")
            {
                Options.Viewport.AreUpdatesDisabled = true;

                using (Stream SessionStream = File.OpenRead(Dialog.FileName))
                {
                    XPathDocument Doc = new XPathDocument(SessionStream);
                    XPathNavigator Reader = Doc.CreateNavigator();
                    Reader.MoveToRoot();

                    string ModelPath = XMLHelper.LoadParamNode(Reader, "ModelPath", "");
                    Options.Membrane.LoadModel(ModelPath);

                    string TomogramPath = XMLHelper.LoadParamNode(Reader, "TomogramPath", "");
                    Options.Membrane.LoadTomogram(TomogramPath);

                    // Point groups
                    if (Reader.Select("//PointGroups/Group").Count > 0)
                    {
                        Options.Membrane.ActiveGroup = null;
                        Options.Membrane.PointGroups.Clear();
                    }

                    foreach (XPathNavigator groupNav in Reader.Select("//PointGroups/Group"))
                    {
                        PointGroup NewGroup = new PointGroup
                        {
                            Name = XMLHelper.LoadAttribute(groupNav, "Name", "Group " + (Options.Membrane.PointGroups.Count + 1)),
                            Size = XMLHelper.LoadAttribute(groupNav, "Size", 10),
                            Color = ColorHelper.LoadAttribute(groupNav, "Color", ColorHelper.SpectrumColor(Options.Membrane.PointGroups.Count, 0.3f))
                        };
                        NewGroup.PointCloud.GLContext = Options.Viewport.GetControl();

                        foreach (XPathNavigator pointNav in groupNav.SelectChildren("Point", ""))
                        {
                            int TriangleID = XMLHelper.LoadAttribute(pointNav, "ID", 0);
                            SurfacePoint NewPoint = new SurfacePoint(OpenGLHelper.LoadAttribute(pointNav, "Position", new Vector3(0)),
                                                                     Options.Membrane.SurfaceMesh.Triangles[TriangleID < Options.Membrane.SurfaceMesh.Triangles.Count ? TriangleID : 0],
                                                                     OpenGLHelper.LoadAttribute(pointNav, "Barycentric", new Vector3(0)),
                                                                     XMLHelper.LoadAttribute(pointNav, "Offset", 0f),
                                                                     OpenGLHelper.LoadAttribute(pointNav, "Orientation", new Vector3(0)).X);
                            NewGroup.Points.Add(NewPoint);
                        }

                        Options.Membrane.PointGroups.Add(NewGroup);
                        NewGroup.IsVisible = XMLHelper.LoadAttribute(groupNav, "IsVisible", true);

                        NewGroup.DepictionMeshPath = XMLHelper.LoadAttribute(groupNav, "DepictionMeshPath", "");
                        NewGroup.DepictionMeshLevel = XMLHelper.LoadAttribute(groupNav, "DepictionMeshLevel", 0.02M);
                        NewGroup.DepictionMeshOffset = XMLHelper.LoadAttribute(groupNav, "DepictionMeshOffset", 0M);
                        NewGroup.DepictionLocalSurfaceLevel = XMLHelper.LoadAttribute(groupNav, "DepictionLocalSurfaceLevel", 0.02M);
                        NewGroup.DepictionLocalSurfaceInvert = XMLHelper.LoadAttribute(groupNav, "DepictionLocalSurfaceInvert", true);
                        NewGroup.DepictionLocalSurfaceOnlyCenter = XMLHelper.LoadAttribute(groupNav, "DepictionLocalSurfaceOnlyCenter", true);
                        NewGroup.Depiction = (PointDepiction)XMLHelper.LoadAttribute(groupNav, "Depiction", 1);
                    }

                    if (Reader.Select("//PointGroups/Group").Count > 0)
                    {
                        Options.Membrane.ActiveGroup = Options.Membrane.PointGroups[0];
                    }

                    // Surface patches
                    Options.Membrane.DeselectAllTriangles();
                    foreach (XPathNavigator patchNav in Reader.Select("//SurfacePatches/Patch"))
                    {
                        List<Triangle> Triangles = XMLHelper.LoadAttribute(patchNav.SelectSingleNode("Faces"), "ID", "").
                            Split(',').
                            Select(v => Options.Membrane.SurfaceMesh.Triangles[int.Parse(v) < Options.Membrane.SurfaceMesh.Triangles.Count ? int.Parse(v) : 0]).ToList();

                        if (Triangles.Count == 0)
                            continue;

                        Color PatchColor = ColorHelper.LoadAttribute(patchNav, "Color", ColorHelper.SpectrumColor(Options.Membrane.Patches.Count, 0.2f));
                        SurfacePatch NewPatch = new SurfacePatch(Options.Membrane,
                                                                 XMLHelper.LoadAttribute(patchNav, "Name", "Patch " + (Options.Membrane.Patches.Count + 1)),
                                                                 PatchColor,
                                                                 Triangles);
                        Options.Membrane.Patches.Add(NewPatch);

                        Options.Membrane.SetTriangleColor(Triangles, ColorHelper.ColorToVector(PatchColor));
                        Options.Membrane.SetTrianglePatch(Triangles, NewPatch);

                        NewPatch.IsVisible = XMLHelper.LoadAttribute(patchNav, "IsVisible", true);
                        NewPatch.IsColored = XMLHelper.LoadAttribute(patchNav, "IsColored", true);
                    }

                    Options.Viewport.GetControl().MakeCurrent();
                    Options.Membrane.SurfaceMesh.UpdateBuffers();

                    // Options
                    Options.Membrane.SurfaceOffset = XMLHelper.LoadParamNode(Reader, "SurfaceOffset", 0M);

                    Options.Membrane.TraceDepth = XMLHelper.LoadParamNode(Reader, "TraceDepth", 0);
                    Options.Membrane.TraceDepthOffset = XMLHelper.LoadParamNode(Reader, "TraceDepthOffset", 0);
                    Options.Membrane.TraceSharpening = XMLHelper.LoadParamNode(Reader, "TraceSharpening", 0M);

                    Options.Membrane.OutputRangeMin = XMLHelper.LoadParamNode(Reader, "OutputRangeMin", 0M);
                    Options.Membrane.OutputRangeMax = XMLHelper.LoadParamNode(Reader, "OutputRangeMax", 1M);
                    Options.Membrane.OutputLight = XMLHelper.LoadParamNode(Reader, "OutputLight", 30);

                    Options.Membrane.SelectionAngle = XMLHelper.LoadParamNode(Reader, "SelectionAngle", 90);

                    Options.Viewport.Camera.Target = OpenGLHelper.LoadParamNode(Reader, "CameraTarget", new Vector3(0));
                    Options.Viewport.Camera.Rotation = OpenGLHelper.LoadParamNode(Reader, "CameraRotation", new Quaternion());
                    Options.Viewport.Camera.Distance = XMLHelper.LoadParamNode(Reader, "CameraDistance", 1f);
                    Options.Viewport.Camera.FOV = XMLHelper.LoadParamNode(Reader, "CameraFOV", (decimal)(45f / 180f * (float)Math.PI));
                }

                Options.Viewport.AreUpdatesDisabled = false;
                Options.Viewport.Redraw();
            }
        }
        private void ButtonPatchAdd_OnClick(object sender, RoutedEventArgs e)
        {
            List<Triangle> PatchTriangles = Options.Membrane.GetSelectedTriangles();
            if (PatchTriangles.Count == 0)
                return;

            Options.Membrane.DeselectAllTriangles();

            Color PatchColor = ColorHelper.SpectrumColor(Options.Membrane.Patches.Count, 0.2f);
            SurfacePatch NewPatch = new SurfacePatch(Options.Membrane, "Patch " + (Options.Membrane.Patches.Count + 1), PatchColor, PatchTriangles);
            Options.Membrane.Patches.Add(NewPatch);

            Options.Membrane.SetTriangleColor(PatchTriangles, ColorHelper.ColorToVector(PatchColor));
            Options.Membrane.SetTrianglePatch(PatchTriangles, NewPatch);

            Options.Viewport.GetControl().MakeCurrent();
            Options.Membrane.SurfaceMesh.UpdateBuffers();
            Options.Viewport.Redraw();
        }
Beispiel #6
0
        public void SetTrianglePatch(IEnumerable<Triangle> triangles, SurfacePatch patch)
        {
            foreach (var t in triangles)
                t.Patch = patch;

            SurfaceMesh.UpdateProcessedGeometry((float)SurfaceOffset);
        }
Beispiel #7
0
        private void UnlockFrom(SurfacePatch target)
        {
            if (target == null || target.ParentWindow == null || target.Viewport == null)
                return;

            target.ParentWindow.SizeChanged -= TargetWindow_SizeChanged;
            target.Viewport.Camera.PropertyChanged -= TargetCamera_PropertyChanged;
        }
Beispiel #8
0
        private void LockTo(SurfacePatch target)
        {
            if (target == null || target.ParentWindow == null || target.Viewport == null)
                return;

            target.ParentWindow.Closing += TargetWindow_Closing;
            target.ParentWindow.SizeChanged += TargetWindow_SizeChanged;
            target.Viewport.Camera.PropertyChanged += TargetCamera_PropertyChanged;

            Random Rand = new Random(123);
            List<Vertex> ForRandom = new List<Vertex>(SurfaceMesh.Vertices);
            List<Vertex> RandomSelection = new List<Vertex>();
            for (int i = 0; i < Math.Min(50, SurfaceMesh.Vertices.Count); i++)
            {
                int Index = Rand.Next(ForRandom.Count - 1);
                RandomSelection.Add(ForRandom[Index]);
                ForRandom.RemoveAt(Index);
            }

            VertexLocks.Clear();

            foreach (var v in RandomSelection)
            {
                float ClosestDistance = float.MaxValue;
                List<Triangle> Targets = target.OriginalToTransformed.Values.ToList();
                Triangle ClosestTriangle = Targets[0];
                foreach (var t in Targets)
                {
                    float Distance = (v.VolumePosition - t.GetVolumeCenter()).Length;
                    if (Distance < ClosestDistance)
                    {
                        ClosestDistance = Distance;
                        ClosestTriangle = t;
                    }
                }

                HashSet<Triangle> Neighborhood = Triangle.Grow(new HashSet<Triangle> { ClosestTriangle });
                VertexLocks.Add(v, Neighborhood.ToArray());
            }

            MatchCamera();
            MatchPosition();
        }