예제 #1
0
파일: Settings.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Sets all standard settings to the current values.
        /// </summary>
        public void MakeStandard()
        {
            // Colors
            sBackColor             = backColor;
            sTextColor             = textColor;
            sSolidColor            = solidColor;
            sMeshColor             = meshColor;
            sVertexColor           = vertexColor;
            sTriNormalColor        = triNormalColor;
            sVertNormalColor       = vertNormalColor;
            sObservedVertexColor   = observedVertexColor;
            sObservedEdgeColor     = observedEdgeColor;
            sObservedTriangleColor = observedTriangleColor;
            sXAxisColor            = xAxisColor;
            sYAxisColor            = yAxisColor;
            sZAxisColor            = zAxisColor;

            sNormalAlgo = normalAlgo;
            sLanguage   = language;

            // Display Settings
            sPickingMode           = pickingMode;
            sSmooth                = smooth;
            sSolid                 = solid;
            sMesh                  = mesh;
            sVertices              = vertices;
            sTriangleNormalVectors = triangleNormalVectors;
            sVertexNormalVectors   = vertexNormalVectors;
            sXAxis                 = xAxis;
            sYAxis                 = yAxis;
            sZAxis                 = zAxis;
        }
예제 #2
0
파일: Settings.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Sets the color settings to the standard values.
        /// </summary>
        public void SetToStandardColors()
        {
            // Colors
            backColor = sBackColor;
            if (BackColorChanged != null)
            {
                BackColorChanged();
            }

            textColor             = sTextColor;
            solidColor            = sSolidColor;
            meshColor             = sMeshColor;
            vertexColor           = sVertexColor;
            triNormalColor        = sTriNormalColor;
            vertNormalColor       = sVertNormalColor;
            observedVertexColor   = sObservedVertexColor;
            observedEdgeColor     = sObservedEdgeColor;
            observedTriangleColor = sObservedTriangleColor;
            xAxisColor            = sXAxisColor;
            yAxisColor            = sYAxisColor;
            zAxisColor            = sZAxisColor;

            if (SettingsChanged != null)
            {
                SettingsChanged();
            }
        }
예제 #3
0
파일: Settings.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Sets hardcoded default values, just in case someone destroys the "default.set" file.
        /// </summary>
        public void SetHardDefault()
        {
            // Colors
            backColor             = new ColorOGL(0.0f, 0.0f, 0.0f);
            textColor             = new ColorOGL(1.0f, 1.0f, 1.0f);
            solidColor            = new ColorOGL(0, 0.8f, 0.8f);
            meshColor             = new ColorOGL(0.5f, 0.5f, 0.5f);
            vertexColor           = new ColorOGL(0.8f, 0.8f, 0.0f);
            triNormalColor        = new ColorOGL(0.8f, 0.0f, 0.8f);
            vertNormalColor       = new ColorOGL(0.8f, 0.0f, 0.8f);
            observedVertexColor   = new ColorOGL(1.0f, 1.0f, 1.0f);
            observedEdgeColor     = new ColorOGL(1.0f, 1.0f, 1.0f);
            observedTriangleColor = new ColorOGL(1.0f, 0.0f, 0.0f);
            xAxisColor            = new ColorOGL(0.8f, 0.0f, 0.0f);
            yAxisColor            = new ColorOGL(0.0f, 0.8f, 0.0f);
            zAxisColor            = new ColorOGL(0.0f, 0.0f, 0.8f);

            Language   = "english";
            normalAlgo = 0;

            // Display Settings
            pickingMode           = 0;
            smooth                = false;
            solid                 = true;
            mesh                  = true;
            vertices              = false;
            triangleNormalVectors = false;
            vertexNormalVectors   = false;
            xAxis                 = false;
            yAxis                 = false;
            zAxis                 = false;

            MakeStandard();
        }
예제 #4
0
파일: ColorOGL.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Converts an Integer into a unique ColorOGL.
        /// </summary>
        /// <param name="index">Integer to be converted</param>
        /// <returns>Color</returns>
        public static ColorOGL GetColorFromInt(int index)
        {
            ColorOGL color = new ColorOGL();

            color.R = (float)(255 - index % 256) / 255;
            color.G = (float)(255 - (int)((index - 256 * 256 * (int)(index / (256 * 256))) / 256)) / 255;
            color.B = (float)(255 - (int)(index / (256 * 256))) / 255;

            return(color);
        }
예제 #5
0
        /// <summary>
        /// Sets an array containing a different color for each Edge for picking.
        /// </summary>
        public void SetEdgePickingColors()
        {
            ColorOGL     color;
            List <float> pickingColors = new List <float>(edges.Count * 3);

            for (int i = 0; i < edges.Count; i++)
            {
                color = ColorOGL.GetColorFromInt(i * edgeColorDist);
                pickingColors.AddRange(color.RGB);
            }

            edgePickingColors = pickingColors.ToArray();
        }
예제 #6
0
        /// <summary>
        /// Sets an array containing a different color for each Vertex for picking.
        /// </summary>
        public void SetVertexPickingColors()
        {
            ColorOGL     color;
            List <float> pickingColors = new List <float>(vertices.Count * 3);

            for (int i = 0; i < vertices.Count; i++)
            {
                color = ColorOGL.GetColorFromInt(i * vertexColorDist);
                pickingColors.AddRange(color.RGB);
            }

            vertexPickingColors = pickingColors.ToArray();
        }
예제 #7
0
        /// <summary>
        /// Sets an array containing a different color for each Vertex for picking.
        /// </summary>
        public void SetTrianglePickingColors()
        {
            ColorOGL     color;
            List <float> pickingColors = new List <float>(this.Count * 3);

            for (int i = 0; i < this.Count; i++)
            {
                color = ColorOGL.GetColorFromInt(i * triangleColorDist);
                pickingColors.AddRange(color.RGB);
                pickingColors.AddRange(color.RGB);
                pickingColors.AddRange(color.RGB);
            }

            trianglePickingColors = pickingColors.ToArray();
        }
예제 #8
0
파일: ColorOGL.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Calculates a color table with values interpolated between the given colors.
        /// </summary>
        /// <param name="colors">An arbitrary number of ColorOGLs</param>
        /// <returns>An array of interpolated ColorOGLs</returns>
        public static ColorOGL[] InterpolationArray(params ColorOGL[] colors)
        {
            ColorOGL[] colorTable = new ColorOGL[short.MaxValue + 1];
            int        steps      = colors.Length - 1;

            for (int j = 0; j < steps; j++)
            {
                for (int k = j * short.MaxValue / steps; k <= (j + 1) * short.MaxValue / steps; k++)
                {
                    colorTable[k] = colors[j].Interpolate(colors[j + 1], (float)(steps * k - j * short.MaxValue) / short.MaxValue);
                }
            }

            return(colorTable);
        }
예제 #9
0
파일: ColorOGL.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Takes a float-array of RGB-colors and returns a list of the corresponding Vertices.
        /// Every picked Vertices is added to the list only once.
        /// </summary>
        /// <param name="selected">Array of the picked Vertices</param>
        /// <param name="colorDist">Distance between the colors</param>
        /// <param name="max">Maximum possible index</param>
        /// <returns>Unique list of selected triangles</returns>
        public static List <int> UniqueSelection(float[] selected, int colorDist, int max)
        {
            ColorOGL   color  = new ColorOGL();
            List <int> unique = new List <int>();
            int        index;

            for (int i = 0; i < selected.Length / 3; i++)
            {
                color = new ColorOGL(selected[i * 3], selected[i * 3 + 1], selected[i * 3 + 2]);
                index = GetIntFromColor(color) / colorDist;
                if ((index < max) && (!unique.Contains(index)))
                {
                    unique.Add(index);
                }
            }

            return(unique);
        }
예제 #10
0
파일: ColorOGL.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Calculates the linear interpolation between two Colors,
        /// this color being dist=0, the other being dist=1
        /// </summary>
        /// <param name="other">Other Color</param>
        /// <param name="dist">Keep this between 0 and 1 please</param>
        /// <returns>Interpolated Color</returns>
        public ColorOGL Interpolate(ColorOGL other, float dist)
        {
            ColorOGL c = new ColorOGL();

            for (int i = 0; i < 3; i++)
            {
                c.rgbFloat[i] = this.rgbFloat[i] + (other.rgbFloat[i] - this.rgbFloat[i]) * dist;
                if (c.rgbFloat[i] > 1.0f)
                {
                    c.rgbFloat[i] = 1.0f;
                }
                else if (c.rgbFloat[i] < 0.0f)
                {
                    c.rgbFloat[i] = 0.0f;
                }
            }
            c.color = ColorFromFloat(c.rgbFloat);
            return(c);
        }
예제 #11
0
파일: Settings.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// Sets all settings to the standard values.
        /// </summary>
        public void SetToStandard()
        {
            // Colors
            backColor = sBackColor;
            if (BackColorChanged != null)
            {
                BackColorChanged();
            }

            textColor             = sTextColor;
            solidColor            = sSolidColor;
            meshColor             = sMeshColor;
            vertexColor           = sVertexColor;
            triNormalColor        = sTriNormalColor;
            vertNormalColor       = sVertNormalColor;
            observedVertexColor   = sObservedVertexColor;
            observedEdgeColor     = sObservedEdgeColor;
            observedTriangleColor = sObservedTriangleColor;
            xAxisColor            = sXAxisColor;
            yAxisColor            = sYAxisColor;
            zAxisColor            = sZAxisColor;

            normalAlgo = sNormalAlgo;
            Language   = sLanguage;

            // Display Settings
            pickingMode           = sPickingMode;
            smooth                = sSmooth;
            solid                 = sSolid;
            mesh                  = sMesh;
            vertices              = sVertices;
            triangleNormalVectors = sTriangleNormalVectors;
            vertexNormalVectors   = sVertexNormalVectors;
            xAxis                 = sXAxis;
            yAxis                 = sYAxis;
            zAxis                 = sYAxis;

            if (SettingsChanged != null)
            {
                SettingsChanged();
            }
        }
예제 #12
0
파일: ColorOGL.cs 프로젝트: ShenRen/trimm
 /// <summary>
 /// Converts a float RGB color into a unique Integer.
 /// </summary>
 /// <param name="color">Color</param>
 /// <returns>Corresponding Integer</returns>
 public static int GetIntFromColor(ColorOGL color)
 {
     return((int)(Math.Ceiling((1.0f - color.B) * 255) * 256 * 256 +
                  Math.Ceiling((1.0f - color.G) * 255) * 256 + Math.Ceiling((1.0f - color.R) * 255)));
 }
예제 #13
0
        /// <summary>
        /// Opens a ColorDialog allowing the user to choose a color to draw
        /// the elements chosen in the colorComboBox.
        /// </summary>
        /// <param name="sender">colorButton</param>
        /// <param name="e">Standard RoutedEventArgs</param>
        private void ColorButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.ColorDialog cd = new System.Windows.Forms.ColorDialog();

            if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ColorOGL newColor = new ColorOGL(Color.FromRgb(cd.Color.R, cd.Color.G, cd.Color.B));

                switch (colorComboBox.SelectedIndex)
                {
                case 0:
                    TriMMApp.Settings.BackColor = newColor;
                    break;

                case 1:
                    TriMMApp.Settings.TextColor = newColor;
                    break;

                case 2:
                    TriMMApp.Settings.SolidColor = newColor;
                    break;

                case 3:
                    TriMMApp.Settings.MeshColor = newColor;
                    break;

                case 4:
                    TriMMApp.Settings.VertexColor = newColor;
                    break;

                case 5:
                    TriMMApp.Settings.TriNormalColor = newColor;
                    break;

                case 6:
                    TriMMApp.Settings.VertNormalColor = newColor;
                    break;

                case 7:
                    TriMMApp.Settings.XAxisColor = newColor;
                    break;

                case 8:
                    TriMMApp.Settings.YAxisColor = newColor;
                    break;

                case 9:
                    TriMMApp.Settings.ZAxisColor = newColor;
                    break;

                case 10:
                    TriMMApp.Settings.ObservedVertexColor = newColor;
                    break;

                case 11:
                    TriMMApp.Settings.ObservedEdgeColor = newColor;
                    break;

                case 12:
                    TriMMApp.Settings.ObservedTriangleColor = newColor;
                    break;
                }
            }
        }
예제 #14
0
파일: Settings.cs 프로젝트: ShenRen/trimm
        /// <summary>
        /// The given StreamReader <paramref name="file"/> is parsed and the values set.
        /// </summary>
        /// <param name="file">The path to the *.SET file to be parsed.</param>
        /// <param name="normalAlgo">The algorithm to calculate the Vertex normals with.</param>
        public void Parse(String fileName)
        {
            StreamReader file = new StreamReader(fileName);

            // The numbers in the file must have the decimal separator ".".
            NumberFormatInfo numberFormatInfo = new NumberFormatInfo();

            numberFormatInfo.NumberDecimalSeparator = ".";

#if !DEBUG
            try {
#endif
            String input = null;
            while ((input = file.ReadLine()) != null)
            {
                if (input.Contains("#"))
                {
                    input = input.Substring(0, input.IndexOf("#"));
                }
                input = input.Replace("\t", " ").Trim();
                // RemoveEmptyEntities removes empty entities, resulting from more than one whitespace
                String[] line = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (line.Length == 4)
                {
                    ColorOGL color = new ColorOGL(float.Parse(line[1], NumberStyles.Float, numberFormatInfo), float.Parse(line[2], NumberStyles.Float, numberFormatInfo), float.Parse(line[3], NumberStyles.Float, numberFormatInfo));
                    if (line[0] == "BACKC")
                    {
                        backColor = color;
                    }
                    else if (line[0] == "TEXTC")
                    {
                        textColor = color;
                    }
                    else if (line[0] == "SOLIDC")
                    {
                        solidColor = color;
                    }
                    else if (line[0] == "MESHC")
                    {
                        meshColor = color;
                    }
                    else if (line[0] == "VERTEXC")
                    {
                        vertexColor = color;
                    }
                    else if (line[0] == "TNC")
                    {
                        triNormalColor = color;
                    }
                    else if (line[0] == "VNC")
                    {
                        vertNormalColor = color;
                    }
                    else if (line[0] == "OVERTC")
                    {
                        observedVertexColor = color;
                    }
                    else if (line[0] == "OEDGC")
                    {
                        observedEdgeColor = color;
                    }
                    else if (line[0] == "OTRIC")
                    {
                        observedTriangleColor = color;
                    }
                    else if (line[0] == "XAXISC")
                    {
                        xAxisColor = color;
                    }
                    else if (line[0] == "YAXISC")
                    {
                        yAxisColor = color;
                    }
                    else if (line[0] == "ZAXISC")
                    {
                        zAxisColor = color;
                    }
                }
                else if (line.Length == 2)
                {
                    if (line[0] == "LANG")
                    {
                        Language = line[1];
                    }
                    else
                    {
                        int mode = int.Parse(line[1]);
                        if (line[0] == "NA")
                        {
                            if ((mode < 0) || (mode > 12))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("NAError")[0].InnerText);
                            }
                            normalAlgo = mode;
                        }
                        else if (line[0] == "PICK")
                        {
                            if ((mode < 0) || (mode > 3))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("PICKError")[0].InnerText);
                            }
                            pickingMode = mode;
                        }
                        else if (line[0] == "SMOOTH")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("SMOOTHError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                smooth = false;
                            }
                            else
                            {
                                smooth = true;
                            }
                        }
                        else if (line[0] == "SOLID")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("SOLIDError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                solid = false;
                            }
                            else
                            {
                                solid = true;
                            }
                        }
                        else if (line[0] == "MESH")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("MESHError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                mesh = false;
                            }
                            else
                            {
                                mesh = true;
                            }
                        }
                        else if (line[0] == "VERT")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("VERTError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                vertices = false;
                            }
                            else
                            {
                                vertices = true;
                            }
                        }
                        else if (line[0] == "TRINORM")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("TRINORMError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                triangleNormalVectors = false;
                            }
                            else
                            {
                                triangleNormalVectors = true;
                            }
                        }
                        else if (line[0] == "VERTNORM")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("VERTNORMError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                vertexNormalVectors = false;
                            }
                            else
                            {
                                vertexNormalVectors = true;
                            }
                        }
                        else if (line[0] == "XAXIS")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("XAXISError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                xAxis = false;
                            }
                            else
                            {
                                xAxis = true;
                            }
                        }
                        else if (line[0] == "YAXIS")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("YAXISError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                yAxis = false;
                            }
                            else
                            {
                                yAxis = true;
                            }
                        }
                        else if (line[0] == "ZAXIS")
                        {
                            if ((mode < 0) || (mode > 1))
                            {
                                throw new ArgumentException(TriMMApp.Lang.GetElementsByTagName("ZAXISError")[0].InnerText);
                            }
                            if (mode == 0)
                            {
                                zAxis = false;
                            }
                            else
                            {
                                zAxis = true;
                            }
                        }
                    }
                }
            }

            if (SettingsChanged != null)
            {
                SettingsChanged();
            }
            MakeStandard();
#if !DEBUG
        }

        catch (ArgumentException ex) {
            MessageBox.Show(ex.Message, TriMMApp.Lang.GetElementsByTagName("ErrorTitle")[0].InnerText, MessageBoxButton.OK, MessageBoxImage.Error);
        } catch {
            MessageBox.Show(TriMMApp.Lang.GetElementsByTagName("SETBrokenFileError")[0].InnerText, TriMMApp.Lang.GetElementsByTagName("ErrorTitle")[0].InnerText, MessageBoxButton.OK, MessageBoxImage.Error);
        } finally {
#endif
            file.Close();
#if !DEBUG
        }
#endif
        }