Beispiel #1
0
        public void CopyPropertiesFrom(PointGroup g)
        {
            Depiction                       = g.Depiction;
            DepictionMeshPath               = g.DepictionMeshPath;
            DepictionMeshLevel              = g.DepictionMeshLevel;
            DepictionMeshOffset             = g.DepictionMeshOffset;
            DepictionLocalSurfaceLevel      = g.DepictionLocalSurfaceLevel;
            DepictionLocalSurfaceInvert     = g.DepictionLocalSurfaceInvert;
            DepictionLocalSurfaceOnlyCenter = g.DepictionLocalSurfaceOnlyCenter;

            Color = g.Color;
            Size  = g.Size;
        }
Beispiel #2
0
        public Membrane()
        {
            MeshProgram = new GLSLProgram("Shaders/Membrane.vert", null, null, null, "Shaders/Membrane.frag");
            PointProgram = new GLSLProgram("Shaders/Point.vert", null, null, "Shaders/Point.geom", "Shaders/Point.frag");
            PointGizmoProgram = new GLSLProgram("Shaders/Point.vert", null, null, "Shaders/PointGizmo.geom", "Shaders/Point.frag");
            PointModelProgram = new GLSLProgram("Shaders/PointModel.vert", null, null, null, "Shaders/PointModel.frag");
            SelectionTexture = ImageTexture.FromMRC("Shaders/unicorn.mrc");

            PointGroups.CollectionChanged += PointGroups_CollectionChanged;

            ActiveGroup = new PointGroup { Color = ColorHelper.SpectrumColor(0, 0.3f), Name = "Default Group", Size = 10 };
            PointGroups.Add(ActiveGroup);

            Patches.CollectionChanged += Patches_CollectionChanged;
        }
Beispiel #3
0
        public Membrane()
        {
            MeshProgram       = new GLSLProgram("Shaders/Membrane.vert", null, null, null, "Shaders/Membrane.frag");
            PointProgram      = new GLSLProgram("Shaders/Point.vert", null, null, "Shaders/Point.geom", "Shaders/Point.frag");
            PointGizmoProgram = new GLSLProgram("Shaders/Point.vert", null, null, "Shaders/PointGizmo.geom", "Shaders/Point.frag");
            PointModelProgram = new GLSLProgram("Shaders/PointModel.vert", null, null, null, "Shaders/PointModel.frag");
            SelectionTexture  = ImageTexture.FromMRC("Shaders/unicorn.mrc");

            PointGroups.CollectionChanged += PointGroups_CollectionChanged;

            ActiveGroup = new PointGroup {
                Color = ColorHelper.SpectrumColor(0, 0.3f), Name = "Default Group", Size = 10
            };
            PointGroups.Add(ActiveGroup);

            Patches.CollectionChanged += Patches_CollectionChanged;
        }
Beispiel #4
0
        public void CopyPropertiesFrom(PointGroup g)
        {
            Depiction = g.Depiction;
            DepictionMeshPath = g.DepictionMeshPath;
            DepictionMeshLevel = g.DepictionMeshLevel;
            DepictionMeshOffset = g.DepictionMeshOffset;
            DepictionLocalSurfaceLevel = g.DepictionLocalSurfaceLevel;
            DepictionLocalSurfaceInvert = g.DepictionLocalSurfaceInvert;
            DepictionLocalSurfaceOnlyCenter = g.DepictionLocalSurfaceOnlyCenter;

            Color = g.Color;
            Size = g.Size;
        }
        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 ButtonPointGroupsImport_OnClick(object sender, RoutedEventArgs e)
        {
            if (Options.Membrane.SurfaceMesh == null || Options.Membrane.SurfaceMesh.Triangles.Count == 0)
            {
                MessageBox.Show("This will not work without a mesh.");
                return;
            }

            System.Windows.Forms.OpenFileDialog Dialog = new System.Windows.Forms.OpenFileDialog();
            Dialog.Filter = "Text File|*.txt|Session File|*.xml";
            System.Windows.Forms.DialogResult Result = Dialog.ShowDialog();

            if (Result.ToString() == "OK")
            {
                FileInfo Info = new FileInfo(Dialog.FileName);
                if (Info.Extension.ToLower().Replace(".", "") == "txt")
                {
                    PointGroup NewGroup = new PointGroup
                    {
                        Name = Dialog.SafeFileName.Substring(0, Dialog.SafeFileName.LastIndexOf(".txt")),
                        Size = 10,
                        Color = ColorHelper.SpectrumColor(Options.Membrane.PointGroups.Count, 0.3f)
                    };
                    NewGroup.PointCloud.GLContext = Options.Viewport.GetControl();

                    CultureInfo IC = CultureInfo.InvariantCulture;

                    using (TextReader Reader = new StreamReader(File.OpenRead(Dialog.FileName)))
                    {
                        string Line;

                        while ((Line = Reader.ReadLine()) != null)
                        {
                            if (Line[0] == '#')
                                continue;

                            string[] Parts = Line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            if (Parts.Length < 3)
                                continue;

                            try
                            {
                                Vector3 Position = new Vector3(float.Parse(Parts[0], IC), float.Parse(Parts[1], IC), float.Parse(Parts[2], IC));

                                Triangle ClosestTri = Options.Membrane.SurfaceMesh.Triangles[0];
                                float ClosestDist = float.MaxValue;
                                foreach (var tri in Options.Membrane.SurfaceMesh.Triangles)
                                {
                                    float Dist = (tri.V0.Position - Position).Length;
                                    if (Dist < ClosestDist)
                                    {
                                        ClosestDist = Dist;
                                        ClosestTri = tri;
                                    }
                                }

                                OpenTK.Matrix3 Orientation = ClosestTri.GetPlaneMatrix3();
                                if (Parts.Length >= 3 + 9)
                                {
                                    int Offset = Parts.Length - 9;
                                    Vector3 C1 = new Vector3(float.Parse(Parts[Offset + 0], IC), float.Parse(Parts[Offset + 1], IC), float.Parse(Parts[Offset + 2], IC));
                                    Vector3 C2 = new Vector3(float.Parse(Parts[Offset + 3], IC), float.Parse(Parts[Offset + 4], IC), float.Parse(Parts[Offset + 5], IC));
                                    Vector3 C3 = new Vector3(float.Parse(Parts[Offset + 6], IC), float.Parse(Parts[Offset + 7], IC), float.Parse(Parts[Offset + 8], IC));

                                    Orientation = new OpenTK.Matrix3(C1.X, C2.X, C3.X, C1.Y, C2.Y, C3.Y, C1.Z, C2.Z, C3.Z);
                                }

                                SurfacePoint NewPoint = new SurfacePoint(Position, ClosestTri, Vector3.Zero, 0, Orientation);
                                NewGroup.Points.Add(NewPoint);
                            }
                            catch
                            {
                                MessageBox.Show("Could not import:\n" + Line);
                            }
                        }
                    }

                    if (NewGroup.Points.Count > 0)
                    {
                        Options.Membrane.PointGroups.Add(NewGroup);
                        Options.Viewport.Redraw();
                    }
                }
                else if (Info.Extension.ToLower().Replace(".", "") == "xml")
                {
                    List<string> GroupNames = new List<string>();

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

                        foreach (XPathNavigator groupNav in Reader.Select("//PointGroups/Group"))
                            GroupNames.Add(XMLHelper.LoadAttribute(groupNav, "Name", "Group " + (GroupNames.Count + 1)));
                    }

                    if (GroupNames.Count == 0)
                        return;

                    PointGroupImportDialog ImportDialog = new PointGroupImportDialog();
                    foreach (var groupName in GroupNames)
                        ImportDialog.AvailableGroups.Add(groupName);
                    ImportDialog.SessionPath = Dialog.FileName;

                    ImportDialog.ShowDialog();
                }
            }
        }
        private void ButtonPointGroupsAdd_OnClick(object sender, RoutedEventArgs e)
        {
            PointGroup NewGroup = new PointGroup
            {
                Name = "Group " + (Options.Membrane.PointGroups.Count + 1),
                Size = 10,
                Color = ColorHelper.SpectrumColor(Options.Membrane.PointGroups.Count, 0.3f)
            };
            NewGroup.PointCloud.GLContext = Options.Viewport.GetControl();
            Options.Membrane.PointGroups.Add(NewGroup);

            UpdatePointContextMenu();   // There is a new group points can be moved into
        }