Exemple #1
0
        private void Read_modelRead(object sender, ModelReadEventArgs e)
        {
            pointsExC = new List <PointEx>();
            pointsExS = new List <PointEx>();

            facesC = new List <Fase>();
            facesS = new List <Fase>();

            #region Separate C and S and create obj files

            PointByTheta pointByTheta = new PointByTheta(ref read.points);

            for (int i = 0; i < read.points.Count; i++)
            {
                if (read.points[i].Lambda == 0)
                {
                    pointsExC.Add(read.points[i]);
                }
                else
                {
                    pointsExS.Add(read.points[i]);
                }
            }

            for (int i = pointsExC.Count - 1; i >= pointsExC.Count - pointByTheta.m_noOfThetaGroups; i--)
            {
                pointsExS.Insert(0, pointsExC[i]);
            }

            Calculate.GetFaces(ref facesC, ref pointsExC, pointByTheta.m_noOfThetaGroups, Model.cylinder);
            Calculate.GetFaces(ref facesS, ref pointsExS, pointByTheta.m_noOfThetaGroups, Model.sphere);

            Write.OBJFileEx(ref pointsExC, ref facesC, "C");
            Write.OBJFileEx(ref pointsExS, ref facesS, "S");

            #endregion

            #region Volume calculation

            threadS = new Thread(() => volumeS.TotalVolume(ref pointsExS, ref facesS, Model.sphere));
            threadC = new Thread(() => volumeC.TotalVolume(ref pointsExC, ref facesC, Model.cylinder));
            threadS.Start();
            threadC.Start();
            #endregion
        }
        private void GtnGen_Click(object sender, EventArgs e)
        {
            #region Generate points
            List <PointEx> pointsEx = new List <PointEx>();
            Random         random   = new Random();

            float theta_steps  = (float)(System.Convert.ToDouble(textBoxThetaStepSize.Text));
            float lambda_steps = (float)(System.Convert.ToDouble(textBoxLambdaStepSizeS.Text));
            float z_steps_c    = (float)(System.Convert.ToDouble(textBoxZStepSizeC.Text));
            float z_from_c     = (float)System.Convert.ToDouble(textBoxZfromC.Text);
            float z_to_c       = (float)System.Convert.ToDouble(textBoxZToC.Text);
            float radius       = (float)System.Convert.ToDouble(textBoxRadius.Text);

            ModelVolume.updated = true;
            ModelVolume.volumeS = (2 * Math.PI * radius * radius * radius) / 3;
            ModelVolume.volumeC = Math.PI * radius * radius * (z_to_c - z_from_c);

            if (checkBoxNoise.Checked)//generate points with noise
            {
                int percentage = comboBoxPercentage.SelectedIndex;

                for (float z = z_from_c; z <= z_to_c; z = z + z_steps_c)
                {
                    for (float t = 0; t < 360; t = t + theta_steps)
                    {
                        pointsEx.Add(ConvertCoordinate.CylindricalToCartesianEx(t, radius + RandGen(random, (int)radius, percentage), z, 0));
                    }
                }

                for (float l = lambda_steps; l < 90; l = l + lambda_steps)
                {
                    for (float t = 0; t < 360; t = t + theta_steps)
                    {
                        pointsEx.Add(ConvertCoordinate.SphericalToCartesianEx(radius + RandGen(random, (int)radius, percentage), l, t, z_to_c));
                    }
                }
                pointsEx.Add(ConvertCoordinate.SphericalToCartesianEx(radius + RandGen(random, (int)radius, percentage), 90, 0, z_to_c)); // Bottom point
            }
            else//whiout noise
            {
                for (float z = z_from_c; z <= z_to_c; z = z + z_steps_c)
                {
                    for (float t = 0; t < 360; t = t + theta_steps)
                    {
                        pointsEx.Add(ConvertCoordinate.CylindricalToCartesianEx(t, radius, z, 0));
                    }
                }

                for (float l = lambda_steps; l < 90; l = l + lambda_steps)
                {
                    for (float t = 0; t < 360; t = t + theta_steps)
                    {
                        pointsEx.Add(ConvertCoordinate.SphericalToCartesianEx(radius, l, t, z_to_c));
                    }
                }
                pointsEx.Add(ConvertCoordinate.SphericalToCartesianEx(radius, 90, 0, z_to_c)); // Bottom point
            }
            #endregion

            #region Generate faces for points
            List <Fase> faces      = new List <Fase>();
            int         N          = (int)(360 / theta_steps);
            int         pointCount = pointsEx.Count;

            Calculate.GetFaces(ref faces, ref pointsEx, N, Model.Complete_Model);
            #endregion

            Write.PCDFileEx(ref pointsEx);
            Write.OBJFileEx(ref pointsEx, ref faces, "Points");
            Write.ModelFileEx(ref pointsEx, "PointsEx");

            pointsEx.Clear();
            faces.Clear();
        }