Example #1
0
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator LeftEyeRightCornerPoint = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner);
            Cl3DModel.Cl3DModelPointIterator RightEyeLeftCornerPoint = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner);

            CalculateDistancesFromPoint("UV_LeftEyeRightCornerDistance", LeftEyeRightCornerPoint.U, LeftEyeRightCornerPoint.V, p_Model);
            CalculateDistancesFromPoint("UV_RightEyeLeftCornerDistance", RightEyeLeftCornerPoint.U, RightEyeLeftCornerPoint.V, p_Model);
            CalculateDistancesFromPoint("UV_NoseTipDistance", 0.0f, 0.0f, p_Model);

            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            do
            {
                double UV_LeftEyeRightCornerDistance = 0;
                iter.GetSpecificValue("UV_LeftEyeRightCornerDistance", out UV_LeftEyeRightCornerDistance);

                double UV_RightEyeLeftCornerDistance = 0;
                iter.GetSpecificValue("UV_RightEyeLeftCornerDistance", out UV_RightEyeLeftCornerDistance);

                double UV_NoseTipDistance = 0;
                iter.GetSpecificValue("UV_NoseTipDistance", out UV_NoseTipDistance);

                double alldistances = Math.Sqrt(Math.Pow(UV_LeftEyeRightCornerDistance, 2) + Math.Pow(UV_RightEyeLeftCornerDistance, 2) + Math.Pow(UV_NoseTipDistance, 2));
                iter.AddSpecificValue("AllDistancesUV", alldistances);
            } while (iter.MoveToNext());
        }
        private void CalculateGeodesicDistancesFromPoint(string DistanceName, Cl3DModel.Cl3DModelPointIterator p_BasicPoint, Cl3DModel p_Model)
        {
            List <Cl3DModel.Cl3DModelPointIterator> ListToCheck    = null;
            List <Cl3DModel.Cl3DModelPointIterator> NewListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();

            NewListToCheck.Add(p_BasicPoint);
            p_BasicPoint.AddSpecificValue(DistanceName, 0.0f);

            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            do
            {
                ListToCheck = NewListToCheck;

                NewListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();

                foreach (Cl3DModel.Cl3DModelPointIterator PointToCheck in ListToCheck)
                {
                    double PointToCheckDistance = 0;
                    if (!PointToCheck.GetSpecificValue(DistanceName, out PointToCheckDistance))
                    {
                        throw new Exception("Cannot get distance value");
                    }

                    PointToCheck.AlreadyVisited = true;

                    List <Cl3DModel.Cl3DModelPointIterator> Neighbors = PointToCheck.GetListOfNeighbors();
                    foreach (Cl3DModel.Cl3DModelPointIterator NeighboorPoint in Neighbors)
                    {
                        double CurrentDistance = PointToCheck - NeighboorPoint;

                        double newDistance = PointToCheckDistance + CurrentDistance;

                        double NeighborOldDistance = 0;
                        if (NeighboorPoint.GetSpecificValue(DistanceName, out NeighborOldDistance))// if point was already visited, check if we dont have sometimes shorter path to it
                        {
                            if (NeighborOldDistance > newDistance)
                            {
                                NeighboorPoint.AddSpecificValue(DistanceName, newDistance);
                            }
                        }
                        else
                        {
                            NeighboorPoint.AddSpecificValue(DistanceName, newDistance);
                        }

                        if (!NeighboorPoint.AlreadyVisited)
                        {
                            NeighboorPoint.AlreadyVisited = true;
                            NewListToCheck.Add(NeighboorPoint);
                        }
                    }
                }
            } while (NewListToCheck.Count != 0);

            iter = p_Model.GetIterator();
            do
            {
                iter.AlreadyVisited = false;
            } while (iter.MoveToNext());
        }
Example #3
0
 private void CalculateDistancesFromPoint(string DistanceName, float U, float V, Cl3DModel p_Model)
 {
     Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
     do
     {
         double distance = Math.Sqrt(Math.Pow(U - iter.U, 2) + Math.Pow(V - iter.V, 2));
         iter.AddSpecificValue(DistanceName, distance);
     } while (iter.MoveToNext());
 }
 private void CalculateEuclideanDistancesFromPoint(string DistanceName, Cl3DModel.Cl3DModelPointIterator point, Cl3DModel p_Model)
 {
     Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
     do
     {
         double distance = Math.Sqrt(Math.Pow(point.X - iter.X, 2) + Math.Pow(point.Y - iter.Y, 2) + Math.Pow(point.Z - iter.Z, 2));
         iter.AddSpecificValue(DistanceName, distance);
     } while (iter.MoveToNext());
 }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel ConformalModel = new Cl3DModel();

            ConformalModel.LoadModel(p_Model.ModelFileFolder + ConformalMapFolder + "\\" + p_Model.ModelFileName + ".m_Out.pos.m");

            Cl3DModel.Cl3DModelPointIterator iter      = p_Model.GetIterator();
            List <ClTools.ClTriangle>        Triangles = null;

            float ModelArea = CalculateWholeModelArea(p_Model);

            float ConformalMapArea = CalculateWholeModelArea(ConformalModel);

            if (iter.IsValid())
            {
                do
                {
                    float area3D = 0;
                    ClTools.GetListOfTriangles(out Triangles, iter);

                    //    if (Triangles.Count != 6)
                    //       continue;

                    foreach (ClTools.ClTriangle triangle in Triangles)
                    {
                        area3D += ClTools.CalculateTriangleArea(triangle);
                    }

                    area3D /= Triangles.Count;

                    iter.AddSpecificValue("ConnectedTrianglesArea", area3D);

                    Cl3DModel.Cl3DModelPointIterator ConformalIter = ConformalModel.GetIterator();
                    if (!ConformalIter.MoveToPoint(iter.PointID))
                    {
                        continue;//throw new Exception("Cannot find on conformal model point with no: " + iter.PointID.ToString());
                    }
                    float area2D = 0;
                    ClTools.GetListOfTriangles(out Triangles, ConformalIter);
                    foreach (ClTools.ClTriangle triangle in Triangles)
                    {
                        area2D += ClTools.CalculateTriangleArea(triangle);
                    }

                    area2D /= Triangles.Count;

                    float ConformalFactor = (area3D / ModelArea) / (area2D / ConformalMapArea);

                    ConformalIter.AddSpecificValue("ConformalFactor", ConformalFactor);
                } while (iter.MoveToNext());
            }

            p_Model = ConformalModel;
        }
Example #6
0
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            string k1 = "K1_" + NeighborhoodSize.ToString();
            string k2 = "K2_" + NeighborhoodSize.ToString();
            string CurvednessIndex = "CurvednessIndex_" + NeighborhoodSize.ToString();

            do
            {
                double vK1, vK2;
                if (!iter.GetSpecificValue(k1, out vK1) || !iter.GetSpecificValue(k2, out vK2))
                {
                    continue;
                }

                double CurvednessIndexValue = Math.Sqrt(Math.Pow(vK1, 2) + Math.Pow(vK2, 2)) / 2;
                iter.AddSpecificValue("CurvednessIndex_" + NeighborhoodSize.ToString(), CurvednessIndexValue);
            } while (iter.MoveToNext());
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator LeftEyeRightCornerPoint = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner);
            Cl3DModel.Cl3DModelPointIterator RightEyeLeftCornerPoint = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner);
            Cl3DModel.Cl3DModelPointIterator NoseTipPoint            = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip);

            if (m_bEuclidean)
            {
                CalculateEuclideanDistancesFromPoint("XYZ_LeftEyeRightCornerDistance", LeftEyeRightCornerPoint, p_Model);
                CalculateEuclideanDistancesFromPoint("XYZ_RightEyeLeftCornerDistance", RightEyeLeftCornerPoint, p_Model);
                CalculateEuclideanDistancesFromPoint("XYZ_NoseTipDistance", NoseTipPoint, p_Model);
            }
            else
            {
                Cl3DModel.Cl3DModelPointIterator iterRmoeve = p_Model.GetIterator();
                do
                {
                    iterRmoeve.RemoveSpecificValue("XYZ_LeftEyeRightCornerDistance");
                    iterRmoeve.RemoveSpecificValue("XYZ_RightEyeLeftCornerDistance");
                    iterRmoeve.RemoveSpecificValue("XYZ_NoseTipDistance");
                } while (iterRmoeve.MoveToNext());
                CalculateGeodesicDistancesFromPoint("XYZ_LeftEyeRightCornerDistance", LeftEyeRightCornerPoint, p_Model);
                CalculateGeodesicDistancesFromPoint("XYZ_RightEyeLeftCornerDistance", RightEyeLeftCornerPoint, p_Model);
                CalculateGeodesicDistancesFromPoint("XYZ_NoseTipDistance", NoseTipPoint, p_Model);
            }

            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            do
            {
                double XYZ_LeftEyeRightCornerDistance = 0;
                iter.GetSpecificValue("XYZ_LeftEyeRightCornerDistance", out XYZ_LeftEyeRightCornerDistance);

                double XYZ_RightEyeLeftCornerDistance = 0;
                iter.GetSpecificValue("XYZ_RightEyeLeftCornerDistance", out XYZ_RightEyeLeftCornerDistance);

                double XYZ_NoseTipDistance = 0;
                iter.GetSpecificValue("XYZ_NoseTipDistance", out XYZ_NoseTipDistance);

                double alldistances = Math.Sqrt(Math.Pow(XYZ_LeftEyeRightCornerDistance, 2) + Math.Pow(XYZ_RightEyeLeftCornerDistance, 2) + Math.Pow(XYZ_NoseTipDistance, 2));
                iter.AddSpecificValue("AllDistancesXYZ", alldistances);
            } while (iter.MoveToNext());
        }
        private void MarkHighCurvEdges(ref Cl3DModel Model)
        {
            Cl3DModel.Cl3DModelPointIterator NoseTip  = Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip);
            Cl3DModel.Cl3DModelPointIterator LeftEye  = Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner);
            Cl3DModel.Cl3DModelPointIterator RightEye = Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner);

            float diistance = (float)Math.Sqrt(Math.Pow(NoseTip - LeftEye, 2) + Math.Pow(NoseTip - RightEye, 2) + Math.Pow(LeftEye - RightEye, 2)) * 1.15f;

            List <Cl3DModel.Cl3DModelPointIterator> pointsIn = new List <Cl3DModel.Cl3DModelPointIterator>();

            Cl3DModel.Cl3DModelPointIterator iter = Model.GetIterator();
            do
            {
                float dist = (float)Math.Sqrt(Math.Pow((float)(iter - NoseTip), 2) + Math.Pow((float)(iter - LeftEye), 2) + Math.Pow((float)(iter - RightEye), 2));
                if (dist < diistance)
                {
                    pointsIn.Add(iter.CopyIterator());
                }
            } while (iter.MoveToNext());

            double MaxK1_10 = double.MinValue;
            double MinK1_10 = double.MaxValue;

            double MaxK1_15 = double.MinValue;
            double MinK1_15 = double.MaxValue;

            double MaxK1_20 = double.MinValue;
            double MinK1_20 = double.MaxValue;

            double MaxK1_25 = double.MinValue;
            double MinK1_25 = double.MaxValue;

            double MaxK1_55 = double.MinValue;
            double MinK1_40 = double.MaxValue;

            foreach (Cl3DModel.Cl3DModelPointIterator PointIn in pointsIn)
            {
                double valK1_10;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_10, out valK1_10))
                {
                    ClInformationSender.SendInformation("K1 10 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_15;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_15, out valK1_15))
                {
                    ClInformationSender.SendInformation("K1 15 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_20;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_20, out valK1_20))
                {
                    ClInformationSender.SendInformation("K1 20 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_25;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_25, out valK1_25))
                {
                    ClInformationSender.SendInformation("K1 25 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_40;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_40, out valK1_40))
                {
                    ClInformationSender.SendInformation("K1 40 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                if (MinK1_10 > valK1_10)
                {
                    MinK1_10 = valK1_10;
                }
                if (MaxK1_10 < valK1_10)
                {
                    MaxK1_10 = valK1_10;
                }

                if (MinK1_15 > valK1_15)
                {
                    MinK1_15 = valK1_15;
                }
                if (MaxK1_15 < valK1_15)
                {
                    MaxK1_15 = valK1_15;
                }

                if (MinK1_20 > valK1_20)
                {
                    MinK1_20 = valK1_20;
                }
                if (MaxK1_20 < valK1_20)
                {
                    MaxK1_20 = valK1_20;
                }

                if (MinK1_25 > valK1_25)
                {
                    MinK1_25 = valK1_25;
                }
                if (MaxK1_25 < valK1_25)
                {
                    MaxK1_25 = valK1_25;
                }

                if (MinK1_40 > valK1_40)
                {
                    MinK1_40 = valK1_40;
                }
                if (MaxK1_55 < valK1_40)
                {
                    MaxK1_55 = valK1_40;
                }
            }

            iter = Model.GetIterator();
            do
            {
                double valK1_10;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_10, out valK1_10))
                {
                    continue;
                }

                double valK1_15;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_15, out valK1_15))
                {
                    continue;
                }

                double valK1_20;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_20, out valK1_20))
                {
                    continue;
                }

                double valK1_25;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_25, out valK1_25))
                {
                    continue;
                }

                double valK1_40;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_40, out valK1_40))
                {
                    continue;
                }

                if (valK1_10 < MinK1_10 || valK1_10 > MaxK1_10 ||
                    valK1_15 < MinK1_15 || valK1_15 > MaxK1_15 ||
                    valK1_20 < MinK1_20 || valK1_20 > MaxK1_20 ||
                    valK1_25 < MinK1_25 || valK1_25 > MaxK1_25 ||
                    valK1_40 < MinK1_40 || valK1_40 > MaxK1_55
                    )
                {
                    // iter.Color = Color.LightBlue;
                    iter.AddSpecificValue("ToRemove_HighCurvature", 1.0f);
                }
            } while (iter.MoveToNext());
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            if (p_Model.ModelFileName.Equals("Neutral"))
            {
                NeutralModel = p_Model;
            }
            else
            {
                ExpressionModel = p_Model;
            }

            if (NeutralModel == null || ExpressionModel == null)
            {
                return;
            }

            Cl3DModel.Cl3DModelPointIterator NeutralSavedNoseTip = null;
            Cl3DModel.Cl3DModelPointIterator NeutralLeftEye      = null;
            Cl3DModel.Cl3DModelPointIterator NeutralRightEye     = null;

            if (!NeutralModel.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip, ref NeutralSavedNoseTip) || !NeutralModel.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner, ref NeutralLeftEye) || !NeutralModel.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner, ref NeutralRightEye))
            {
                throw new Exception("Cannot get all specific points (Neutral model)");
            }

            Cl3DModel.Cl3DModelPointIterator ExpressionSavedNoseTip = null;
            Cl3DModel.Cl3DModelPointIterator ExpressionLeftEye      = null;
            Cl3DModel.Cl3DModelPointIterator ExpressionRightEye     = null;

            if (!ExpressionModel.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip, ref ExpressionSavedNoseTip) || !ExpressionModel.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner, ref ExpressionLeftEye) || !ExpressionModel.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner, ref ExpressionRightEye))
            {
                throw new Exception("Cannot get all specific points (Exprssion model)");
            }

            ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(NeutralSavedNoseTip, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip.ToString());
            ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(NeutralLeftEye, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToLeftEye.ToString());
            ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(NeutralRightEye, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToRightEye.ToString());

            ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(ExpressionSavedNoseTip, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip.ToString());
            ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(ExpressionLeftEye, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToLeftEye.ToString());
            ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(ExpressionRightEye, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToRightEye.ToString());

            Cl3DModel.Cl3DModelPointIterator iterNeutral = NeutralModel.GetIterator();
            do
            {
                // search for the closest point in distance geodesic distance domain
                Cl3DModel.Cl3DModelPointIterator iterExpression = ExpressionModel.GetIterator();
                Cl3DModel.Cl3DModelPointIterator ClossestPoint  = null;
                double ClosestPointDistance = 0;
                bool   first = true;
                double NoseDistanceNeutral     = 0;
                double LeftEyeDistanceNeutral  = 0;
                double RightEyeDistanceNeutral = 0;

                if (!iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip, out NoseDistanceNeutral) || !iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToLeftEye, out LeftEyeDistanceNeutral) || !iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToRightEye, out RightEyeDistanceNeutral))
                {
                    throw new Exception("Cannot get specific value");
                }

                double NoseDistanceExpression;
                double LeftEyeDistanceExpression;
                double RightEyeDistanceExpression;

                do
                {
                    if (!iterExpression.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip, out NoseDistanceExpression) || !iterExpression.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToLeftEye, out LeftEyeDistanceExpression) || !iterExpression.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToRightEye, out RightEyeDistanceExpression))
                    {
                        throw new Exception("Cannot get specific value");
                    }

                    double newClosestPointDistance = Math.Sqrt(Math.Pow(NoseDistanceNeutral - NoseDistanceExpression, 2) + Math.Pow(LeftEyeDistanceNeutral - LeftEyeDistanceExpression, 2) + Math.Pow(RightEyeDistanceNeutral - RightEyeDistanceExpression, 2));
                    if (first)
                    {
                        ClossestPoint        = iterExpression.CopyIterator();
                        ClosestPointDistance = newClosestPointDistance;
                        first = false;
                        continue;
                    }

                    if (ClosestPointDistance > newClosestPointDistance)
                    {
                        ClossestPoint        = iterExpression.CopyIterator();
                        ClosestPointDistance = newClosestPointDistance;
                    }
                } while (iterExpression.MoveToNext());


                double ValNatural;
                double ValExpression;

                iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.Mean_25, out ValNatural);
                ClossestPoint.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.Mean_25, out ValExpression);
                iterNeutral.AddSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.DifferenceBetween_HCurvatures_25, ValNatural - ValExpression);

                iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.Gaussian_25, out ValNatural);
                ClossestPoint.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.Gaussian_25, out ValExpression);
                iterNeutral.AddSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.DifferenceBetween_KCurvatures_25, ValNatural - ValExpression);

                iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_25, out ValNatural);
                ClossestPoint.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_25, out ValExpression);
                iterNeutral.AddSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.DifferenceBetween_K1Curvatures_25, ValNatural - ValExpression);

                iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K2_25, out ValNatural);
                ClossestPoint.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K2_25, out ValExpression);
                iterNeutral.AddSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.DifferenceBetween_K2Curvatures_25, ValNatural - ValExpression);

                iterNeutral.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.ShapeIndex_25, out ValNatural);
                ClossestPoint.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.ShapeIndex_25, out ValExpression);
                iterNeutral.AddSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.DifferenceBetween_ShapeIndexCurvatures_25, ValNatural - ValExpression);
            } while (iterNeutral.MoveToNext());
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            int maxX = (int)iter.X;
            int minX = (int)iter.X;
            int maxY = (int)iter.Y;
            int minY = (int)iter.Y;

            do
            {
                if (maxX < iter.X)
                {
                    maxX = (int)iter.X;
                }
                if (maxY < iter.Y)
                {
                    maxY = (int)iter.Y;
                }

                if (minX > iter.X)
                {
                    minX = (int)iter.X;
                }
                if (minY > iter.Y)
                {
                    minY = (int)iter.Y;
                }
            } while (iter.MoveToNext());

            int width  = (maxX - minX) + 1;
            int height = (maxY - minY) + 1;

            List <Cl3DModel.Cl3DModelPointIterator>[,] map = new List <Cl3DModel.Cl3DModelPointIterator> [width, height];

            iter = p_Model.GetIterator();
            do
            {
                int x = (int)iter.X - minX;
                int y = (int)iter.Y - minY;
                if (map[x, y] == null)
                {
                    map[x, y] = new List <Cl3DModel.Cl3DModelPointIterator>();
                }

                map[x, y].Add(iter.CopyIterator());
            } while (iter.MoveToNext());

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (map[x, y] != null)
                    {
                        int   MeanR = 0;
                        int   MeanG = 0;
                        int   MeanB = 0;
                        float MeanX = 0;
                        float MeanY = 0;
                        float MeanZ = 0;

                        float MeanU = 0;
                        float MeanV = 0;

                        float MeanRangeX = 0;
                        float MeanRangeY = 0;

                        Dictionary <string, List <double> > MeanSpecificValues = new Dictionary <string, List <double> >();

                        Cl3DModel.Cl3DModelPointIterator MaxPoint = null;

                        string specPoint  = Cl3DModel.eSpecificPoints.UnspecifiedPoint.ToString();
                        bool   isSpecific = false;
                        foreach (Cl3DModel.Cl3DModelPointIterator point in map[x, y])
                        {
                            point.AlreadyVisited = true;
                            if (!isSpecific)
                            {
                                isSpecific = p_Model.IsThisPointInSpecificPoints(point, ref specPoint);
                            }

                            if (m_bMean)
                            {
                                MeanR += point.ColorR;
                                MeanG += point.ColorG;
                                MeanB += point.ColorB;
                                MeanX += point.X;
                                MeanY += point.Y;
                                MeanZ += point.Z;

                                MeanU += point.U;
                                MeanV += point.V;

                                MeanRangeX += point.RangeImageX;
                                MeanRangeY += point.RangeImageY;

                                List <string> listOfValuesNames = point.GetListOfSpecificValues();
                                foreach (string name in listOfValuesNames)
                                {
                                    List <double> listOfValues = null;
                                    if (!MeanSpecificValues.TryGetValue(name, out listOfValues))
                                    {
                                        listOfValues = new List <double>();
                                        MeanSpecificValues.Add(name, listOfValues);
                                    }
                                    double val = point.GetSpecificValue(name);
                                    listOfValues.Add(val);
                                }
                            }
                            else
                            {// search for max Z
                                if (MaxPoint == null)
                                {
                                    MaxPoint = point;
                                }
                                else if (MaxPoint.Z < point.Z)
                                {
                                    MaxPoint = point;
                                }
                            }
                        }

                        if (m_bMean)
                        {
                            MeanR /= map[x, y].Count;
                            MeanG /= map[x, y].Count;
                            MeanB /= map[x, y].Count;
                            MeanX /= map[x, y].Count;
                            MeanY /= map[x, y].Count;
                            MeanZ /= map[x, y].Count;

                            MeanU /= map[x, y].Count;
                            MeanV /= map[x, y].Count;

                            MeanRangeX /= map[x, y].Count;
                            MeanRangeY /= map[x, y].Count;
                        }
                        else
                        {
                            MeanR = MaxPoint.ColorR;
                            MeanG = MaxPoint.ColorG;
                            MeanB = MaxPoint.ColorB;
                            MeanX = MaxPoint.X;
                            MeanY = MaxPoint.Y;
                            MeanZ = MaxPoint.Z;

                            MeanU = MaxPoint.U;
                            MeanV = MaxPoint.V;

                            MeanRangeX = MaxPoint.RangeImageX;
                            MeanRangeY = MaxPoint.RangeImageY;
                        }

                        List <Cl3DModel.Cl3DModelPointIterator> connections = new List <Cl3DModel.Cl3DModelPointIterator>();

                        foreach (Cl3DModel.Cl3DModelPointIterator point in map[x, y])
                        {
                            foreach (Cl3DModel.Cl3DModelPointIterator InnerPoint in point.GetListOfNeighbors())
                            {
                                if (InnerPoint.AlreadyVisited == false)
                                {
                                    connections.Add(InnerPoint);
                                }
                            }
                        }

                        Cl3DModel.Cl3DModelPointIterator pt = p_Model.AddPointToModel((int)MeanX, (int)MeanY, MeanZ, x, width - y);
                        pt.Color = Color.FromArgb(MeanR, MeanG, MeanB);
                        pt.U     = MeanU;
                        pt.V     = MeanV;

                        foreach (KeyValuePair <string, List <double> > kvValues in MeanSpecificValues)
                        {
                            string        valueName = kvValues.Key;
                            List <double> values    = kvValues.Value;
                            double        meanVal   = 0;
                            foreach (double val in values)
                            {
                                meanVal += val;
                            }
                            meanVal /= values.Count;
                            pt.AddSpecificValue("Mean_" + valueName, meanVal);
                        }


                        if (isSpecific)
                        {
                            p_Model.AddSpecificPoint(specPoint, pt);
                        }

                        List <Cl3DModel.Cl3DModelPointIterator> lista = map[x, y];
                        for (int i = 0; i < lista.Count; i++)
                        {
                            p_Model.RemovePointFromModel(lista[i]);
                        }

                        foreach (Cl3DModel.Cl3DModelPointIterator point in connections)
                        {
                            pt.AddNeighbor(point);
                        }
                    }
                }
            }
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator NoseTip = null;

            if (!p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip, ref NoseTip))
            {
                throw new Exception("Cannot find specific point NoseTip");
            }

            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            float MaxZ = float.MinValue;
            float MinZ = float.MaxValue;

            do
            {
                if (MaxZ < iter.Z)
                {
                    MaxZ = iter.Z;
                }
                if (MinZ > iter.Z)
                {
                    MinZ = iter.Z;
                }
            }while(iter.MoveToNext());

            float step = 1f;
            int   name = (int)step;
            List <Cl3DModel.Cl3DModelPointIterator> PointsToRemove = new List <Cl3DModel.Cl3DModelPointIterator>();

            for (float Threshold = NoseTip.Z - step; Threshold > MinZ; Threshold -= step)
            {
                List <Cl3DModel.Cl3DModelPointIterator> PointsToCheck   = new List <Cl3DModel.Cl3DModelPointIterator>();
                List <Cl3DModel.Cl3DModelPointIterator> NewPoinsToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();
                List <Cl3DModel.Cl3DModelPointIterator> VisitedPoints   = new List <Cl3DModel.Cl3DModelPointIterator>();
                PointsToCheck.Add(NoseTip.CopyIterator());
                while (PointsToCheck.Count != 0)
                {
                    foreach (Cl3DModel.Cl3DModelPointIterator point in PointsToCheck)
                    {
                        if (point.IsSpecificValueCalculated("ToRemove"))
                        {
                            continue;
                        }

                        point.AlreadyVisited = true;
                        VisitedPoints.Add(point.CopyIterator());

                        List <Cl3DModel.Cl3DModelPointIterator> Neighbors = point.GetListOfNeighbors();
                        foreach (Cl3DModel.Cl3DModelPointIterator Neighb in Neighbors)
                        {
                            if (Neighb.IsSpecificValueCalculated("ToRemove"))
                            {
                                continue;
                            }
                            if (Neighb.Z > Threshold && !Neighb.AlreadyVisited)
                            {
                                Neighb.AlreadyVisited = true;
                                NewPoinsToCheck.Add(Neighb.CopyIterator());
                            }
                        }
                    }
                    PointsToCheck   = NewPoinsToCheck;
                    NewPoinsToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();
                }
                Cl3DModel.Cl3DModelPointIterator unconnected = p_Model.GetIterator();
                do
                {
                    if (!unconnected.AlreadyVisited && unconnected.Z > Threshold && !unconnected.IsSpecificValueCalculated("ToRemove"))
                    {
                        if (m_SaveScreenShots)
                        {
                            unconnected.Color = Color.Red;
                        }
                        unconnected.AddSpecificValue("ToRemove", 1.0f);
                        PointsToRemove.Add(unconnected.CopyIterator());
                    }
                } while (unconnected.MoveToNext());

                foreach (Cl3DModel.Cl3DModelPointIterator pts in VisitedPoints)
                {
                    if (m_SaveScreenShots)
                    {
                        pts.Color = Color.Green;
                    }
                    pts.AlreadyVisited = false;
                }
                if (m_SaveScreenShots)
                {
                    Bitmap mapa;
                    p_Model.GetBMPImage(out mapa, 1.0f);
                    mapa.Save(p_Model.ModelFilePath + name.ToString() + ".bmp");
                    name += (int)step;
                }
            }
            List <Cl3DModel.Cl3DModelPointIterator> RemPointsVisited = new List <Cl3DModel.Cl3DModelPointIterator>();

            foreach (Cl3DModel.Cl3DModelPointIterator RemPoint in PointsToRemove)
            {
                if (!RemPoint.IsValid() || RemPoint.AlreadyVisited)
                {
                    continue;
                }

                List <Cl3DModel.Cl3DModelPointIterator> PointsToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();

                PointsToCheck.Add(RemPoint);
                bool remove = false;
                while (PointsToCheck.Count != 0)
                {
                    List <Cl3DModel.Cl3DModelPointIterator> NewPtsToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();
                    foreach (Cl3DModel.Cl3DModelPointIterator pt in PointsToCheck)
                    {
                        if (!pt.IsValid() || pt.AlreadyVisited)
                        {
                            continue;
                        }
                        pt.AlreadyVisited = true;

                        RemPointsVisited.Add(pt);

                        List <Cl3DModel.Cl3DModelPointIterator> Neighbors = pt.GetListOfNeighbors();
                        if (Neighbors.Count != 8)
                        {
                            remove = true;
                        }
                        else
                        {
                            foreach (Cl3DModel.Cl3DModelPointIterator ne in Neighbors)
                            {
                                if (ne.IsSpecificValueCalculated("ToRemove") && !ne.AlreadyVisited)
                                {
                                    NewPtsToCheck.Add(ne);
                                }
                            }
                        }
                    }
                    PointsToCheck = NewPtsToCheck;
                }
                if (remove)
                {
                    foreach (Cl3DModel.Cl3DModelPointIterator ppt in RemPointsVisited)
                    {
                        p_Model.RemovePointFromModel(ppt);
                    }
                }
                RemPointsVisited = new List <Cl3DModel.Cl3DModelPointIterator>();
            }
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            string name = "";

            if (p_Model.ModelType.Equals("abs") || p_Model.ModelType.Equals("binaryModel"))
            {
                string[] splitted = p_Model.ModelFileName.Split('d');
                int      no       = Int32.Parse(splitted[1]);
                no++;

                if (no < 10)
                {
                    name = p_Model.ModelFileFolder + splitted[0] + "d0" + no.ToString() + ".ppm";
                }
                else
                {
                    name = p_Model.ModelFileFolder + splitted[0] + "d" + no.ToString() + ".ppm";
                }
            }
            else
            {
                throw new Exception("Method does not supprt this kind of files");
            }

            using (FileStream fs = File.OpenRead(name))
            {
                try
                {
                    Bitmap Texture    = null;
                    int    TextWidth  = 0;
                    int    TextHeight = 0;

                    bool readHeader = true;

                    bool doWeHaveFileType    = false;
                    bool doWeHaveWidth       = false;
                    bool doWeHaveHeight      = false;
                    bool doWeHaveMaxPixelVal = false;

                    BinaryReader ReaderBinary = new BinaryReader(fs);

                    #region readHeader

                    while (readHeader)
                    {
                        string line = "";
                        char   cSign;
                        while (true)
                        {
                            cSign = ReaderBinary.ReadChar();

                            if (cSign == '\n')
                            {
                                break;
                            }

                            line += cSign;
                        }

                        line = line.Split('#')[0];

                        if (line.Length == 0 || line.Equals(" "))
                        {
                            continue;
                        }

                        string[] val = line.Split(' ');
                        for (int i = 0; i < val.Length; i++)
                        {
                            if (val[i].Equals("P6") && i == 0 && doWeHaveFileType == false)
                            {
                                doWeHaveFileType = true;
                                continue;
                            }
                            else if (!doWeHaveFileType)
                            {
                                throw new Exception("Wrong file format, cannot find on beginning tag 'P6'");
                            }

                            if (doWeHaveWidth == false)
                            {
                                TextWidth     = Int32.Parse(val[i]);
                                doWeHaveWidth = true;
                            }
                            else if (doWeHaveHeight == false)
                            {
                                TextHeight     = Int32.Parse(val[i]);
                                doWeHaveHeight = true;
                            }
                            else if (doWeHaveMaxPixelVal == false)
                            {
                                if (!val[i].Equals("255"))
                                {
                                    throw new Exception("Method supports only max pixel value 255, and value is equal: " + val[i]);
                                }
                                doWeHaveMaxPixelVal = true;
                            }
                            else
                            {
                                throw new Exception("Unrecognized tocken");
                            }

                            if (doWeHaveWidth &&
                                doWeHaveMaxPixelVal &&
                                doWeHaveHeight &&
                                doWeHaveFileType)
                            {
                                readHeader = false;
                                break;
                            }
                        }
                    }
                    #endregion

                    Texture = new Bitmap(TextWidth, TextHeight);

                    int  bitmapX = 0;
                    int  bitmapY = 0;
                    byte info;
                    int  count = 0;
                    int  r     = 0;
                    int  g     = 0;
                    int  b     = 0;
                    try
                    {
                        while (true)
                        {
                            info = ReaderBinary.ReadByte();

                            if (count == 0)
                            {
                                r = (int)info;
                            }
                            else if (count == 1)
                            {
                                g = (int)info;
                            }
                            else
                            {
                                b = (int)info;
                            }

                            if (count == 2)
                            {
                                if (bitmapX >= TextWidth || bitmapY >= TextHeight)
                                {
                                    throw new Exception("File has wrong format, too many pixels are saved in file");
                                }

                                Texture.SetPixel(bitmapX, bitmapY, Color.FromArgb(r, g, b));
                                bitmapX++;
                                count = 0;
                            }
                            else
                            {
                                count++;
                            }

                            if (bitmapX == TextWidth)
                            {
                                bitmapX = 0;
                                bitmapY++;
                                //    ClInformationSender.SendInformation(bitmapY.ToString() + "/" + m_TextHeight.ToString(), ClInformationSender.eInformationType.eProgress);
                            }
                        }
                    }
                    catch (System.IO.EndOfStreamException)
                    {
                        if (bitmapX != 0 || bitmapY != TextHeight)
                        {
                            fs.Close();
                            throw new Exception("File has wrong structure, not every pixel has value");
                        }
                    }
                    fs.Close();

                    Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
                    do
                    {
                        iter.Color = Texture.GetPixel(iter.RangeImageX, iter.RangeImageY);
                        iter.AddSpecificValue("Texture", iter.Color.ToArgb());
                    } while (iter.MoveToNext());
                }
                catch (Exception e)
                {
                    fs.Close();
                    throw;
                }
            }
        }
Example #13
0
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            string name = p_Model.ModelFileName;

            if (name.IndexOf('.') != -1)
            {
                name = name.Substring(0, name.IndexOf('.'));
            }

            m_bMFile = p_Model.ModelType.Equals("m");

            string fileName = p_Model.ModelFileFolder + name + ".curv";

            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            using (StreamReader FileStream = File.OpenText(fileName))
            {
                string line;
                uint   pointNo;
                bool   skipThisPoint = false;
                while ((line = FileStream.ReadLine()) != null)
                {
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    if (line[0].Equals('@'))
                    {
                        continue;
                    }

                    if (line[0].Equals('('))
                    {
                        int    startNo = line.IndexOf('(');
                        int    endNo   = line.IndexOf(')');
                        string NO      = line.Substring(startNo + 1, endNo - startNo - 1);
                        pointNo = UInt32.Parse(NO, System.Globalization.CultureInfo.InvariantCulture);
                        if (m_bMFile)
                        {
                            pointNo++;
                        }

                        if (iter.MoveToPoint(pointNo))
                        {
                            skipThisPoint = false;
                            continue;
                        }
                        else
                        {
                            skipThisPoint = true;
                        }
                    }
                    if (line[0].Equals('\t') && skipThisPoint == false)
                    {
                        string[] splited       = line.Split(':');
                        string   curvatureName = splited[0].Substring(1);
                        double   curvatureVal  = Double.Parse(splited[1], System.Globalization.CultureInfo.InvariantCulture);

                        iter.AddSpecificValue(curvatureName, curvatureVal);
                    }
                }
            }
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            string name = "";

            if (p_Model.ModelType.Equals("bnt"))
            {
                name = p_Model.ModelFileFolder + p_Model.ModelFileName + ".png";
            }
            else
            {
                throw new Exception("Method does not supprt this kind of files");
            }

            Bitmap Texture = new Bitmap(name);


            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            if (!iter.IsValid())
            {
                throw new Exception("Model iterator not Valid");
            }

            int MinX;
            int MaxX;
            int MinY;
            int MaxY;

            MinX = iter.RangeImageX;
            MaxX = iter.RangeImageX;
            MinY = iter.RangeImageY;
            MaxY = iter.RangeImageY;

            do
            {
                if (MinX > iter.RangeImageX)
                {
                    MinX = iter.RangeImageX;
                }
                if (MaxX < iter.RangeImageX)
                {
                    MaxX = iter.RangeImageX;
                }

                if (MinY > iter.RangeImageY)
                {
                    MinY = iter.RangeImageY;
                }
                if (MaxY < iter.RangeImageY)
                {
                    MaxY = iter.RangeImageY;
                }
            } while (iter.MoveToNext());

            iter = p_Model.GetIterator();
            do
            {
                float x = ((float)iter.RangeImageX - MinX) / (MaxX - MinX + 1);
                float y = ((float)iter.RangeImageY - MinY) / (MaxY - MinY + 1);
                iter.Color = Texture.GetPixel((int)(x * Texture.Width), (int)(y * Texture.Height));
                iter.AddSpecificValue("Texture", iter.Color.ToArgb());
            } while (iter.MoveToNext());
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();

            uint   current          = 0;
            string NeighborhoodSize = m_fNeighborhoodSize.ToString();

            if (m_bFirstNeighbor)
            {
                NeighborhoodSize = "1Neighb";
            }
            string ShapeIndexString = "ShapeIndex_" + NeighborhoodSize;

            if (iter.IsValid())
            {
                do
                {
                    double A = 0;
                    double B = 0;
                    double C = 0;
                    double D = 0;
                    double E = 0;
                    double F = 0;

                    double H               = 0;
                    double K               = 0;
                    double k1              = 0;
                    double k2              = 0;
                    double ShapeIndex      = 0;
                    double CurvednessIndex = 0;
                    List <Cl3DModel.Cl3DModelPointIterator> ListOfneighborhood;
                    double dx;
                    double dy;
                    double dxy;
                    double dxx;
                    double dyy;

                    //------------------------- Neighborhood Custom --------------------------------------------------
                    if (!iter.IsSpecificValueCalculated(ShapeIndexString) || m_bRecalculateCurvature)
                    {
                        if (!m_bFirstNeighbor)
                        {
                            ClTools.GetNeighborhoodWithGeodesicDistance(out ListOfneighborhood, iter, m_fNeighborhoodSize);
                        }
                        else
                        {
                            ListOfneighborhood = iter.GetListOfNeighbors();
                        }

                        if (m_bNeighborhoodRotation)
                        {
                            Matrix Rotation = ClTools.CalculateRotationMatrix(iter.NormalVector, new Vector(new double[] { iter.NormalVector[0], iter.NormalVector[1], 1 }));
                            List <ClTools.MainPoint3D> Neighbors = new List <ClTools.MainPoint3D>();
                            foreach (Cl3DModel.Cl3DModelPointIterator Neighb in ListOfneighborhood)
                            {
                                Matrix after = Rotation * Neighb;
                                Neighbors.Add(new ClTools.MainPoint3D((float)after[0, 0], (float)after[1, 0], (float)after[2, 0], ""));
                            }

                            if (!ClTools.CountSurfaceCoefficients(Neighbors, ref A, ref B, ref C, ref D, ref E, ref F))
                            {
                                iter.RemoveSpecificValue("Gaussian_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("Mean_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K1_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K2_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("ShapeIndex_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("CurvednessIndex_" + NeighborhoodSize);
                                continue;
                            }
                        }
                        else
                        {
                            if (!ClTools.CountSurfaceCoefficients(ListOfneighborhood, ref A, ref B, ref C, ref D, ref E, ref F))
                            {
                                iter.RemoveSpecificValue("Gaussian_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("Mean_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K1_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K2_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("ShapeIndex_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("CurvednessIndex_" + NeighborhoodSize);
                                continue;
                            }
                        }


                        dx  = B + 2 * D * iter.X + E * iter.Y;
                        dy  = C + E * iter.X + 2 * F * iter.Y;
                        dxy = E;
                        dxx = 2 * D;
                        dyy = 2 * F;
                        //Mean
                        H = ((((1 + Math.Pow(dy, 2)) * dxx) - (2 * dx * dy * dxy) + ((1 + Math.Pow(dx, 2)) * dyy)) / (2 * Math.Pow((1 + Math.Pow(dx, 2) + Math.Pow(dy, 2)), 3.0d / 2.0d)));
                        //Gaussian
                        K               = (((dxx * dyy) - Math.Pow(dxy, 2)) / Math.Pow((1 + Math.Pow(dx, 2) + Math.Pow(dy, 2)), 2));
                        k1              = H + Math.Sqrt(Math.Pow(H, 2) - K);
                        k2              = H - Math.Sqrt(Math.Pow(H, 2) - K);
                        ShapeIndex      = 0.5d - (1 / Math.PI) * Math.Atan((k1 + k2) / (k1 - k2));
                        CurvednessIndex = Math.Sqrt(Math.Pow(k1, 2) + Math.Pow(k2, 2)) / 2;

                        iter.AddSpecificValue("Gaussian_" + NeighborhoodSize, K);
                        iter.AddSpecificValue("Mean_" + NeighborhoodSize, H);
                        iter.AddSpecificValue("K1_" + NeighborhoodSize, k1);
                        iter.AddSpecificValue("K2_" + NeighborhoodSize, k2);
                        iter.AddSpecificValue("ShapeIndex_" + NeighborhoodSize, ShapeIndex);
                        iter.AddSpecificValue("CurvednessIndex_" + NeighborhoodSize, CurvednessIndex);
                    }

                    ClInformationSender.SendInformation((current * 100 / p_Model.ModelPointsCount).ToString(System.Globalization.CultureInfo.InvariantCulture), ClInformationSender.eInformationType.eProgress);
                    current++;
                } while (iter.MoveToNext());
            }
        }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            try
            {
                Dictionary <string, Cl3DModel.Cl3DModelPointIterator> Points = new Dictionary <string, Cl3DModel.Cl3DModelPointIterator>();
                using (StreamReader FileStream = File.OpenText(p_sFilePath))
                {
                    string line = "";
                    while ((line = FileStream.ReadLine()) != null)
                    {
                        if (line.Contains("    [POLYGON [PLANE"))
                        {
                            Cl3DModel.Cl3DModelPointIterator[] polygon = new Cl3DModel.Cl3DModelPointIterator[3];
                            for (int i = 0; i < 3; i++)
                            {
                                if ((line = FileStream.ReadLine()) != null)
                                {
                                    string[] param = line.Replace('[', ' ').Replace(']', ' ').Split(' ');
                                    double   H     = Double.Parse(param[3]);
                                    double   K     = Double.Parse(param[7]);

                                    if ((line = FileStream.ReadLine()) != null)
                                    {
                                        param = line.Replace('[', ' ').Replace(']', ' ').Replace('"', ' ').Split(' ');
                                        float U = Single.Parse(param[3]);
                                        float V = Single.Parse(param[4]);

                                        float X = 0;
                                        float Y = 0;
                                        float Z = 0;

                                        string ID = "";
                                        if (line.Contains("[NORMAL"))
                                        {
                                            X  = Single.Parse(param[9]);
                                            Y  = Single.Parse(param[10]);
                                            Z  = Single.Parse(param[11]);
                                            ID = param[9] + param[10] + param[11];
                                        }
                                        else
                                        {
                                            X  = Single.Parse(param[7]);
                                            Y  = Single.Parse(param[8]);
                                            Z  = Single.Parse(param[9]);
                                            ID = param[7] + param[8] + param[9];
                                        }

                                        Cl3DModel.Cl3DModelPointIterator it = null;
                                        if (!Points.TryGetValue(ID, out it))
                                        {
                                            it   = p_mModel3D.AddPointToModel(X, Y, Z);
                                            it.U = U;
                                            it.V = V;
                                            it.AddSpecificValue("GroundK", K);
                                            it.AddSpecificValue("GroundH", H);

                                            Points.Add(ID, it);
                                        }

                                        polygon[i] = it;
                                    }
                                    else
                                    {
                                        throw new Exception("Something wrong 2");
                                    }
                                }
                                else
                                {
                                    throw new Exception("Something wrong 1");
                                }
                            }
                            polygon[0].AddNeighbor(polygon[1]);
                            polygon[0].AddNeighbor(polygon[2]);
                            polygon[1].AddNeighbor(polygon[2]);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            catch (Exception)
            {
                p_mModel3D.ResetModel();
                throw;
            }
        }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            try
            {
                using (StreamReader FileStream = File.OpenText(p_sFilePath))
                {
                    string line = "";
                    while ((line = FileStream.ReadLine()) != null)
                    {
                        if (line.Length == 0 || line.StartsWith("#"))
                        {
                            continue;
                        }

                        char[]   delimiterChars = { ' ', '{', '}', '(', ')' };
                        string[] splited        = line.Split(delimiterChars);
                        //splited.
                        if (splited[0].Equals("Vertex"))
                        {
                            int  no = 1;
                            uint ID = UInt32.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                            if (splited[no].Equals(""))
                            {
                                no++;
                            }
                            float x = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                            float y = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                            float z = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);

                            Cl3DModel.Cl3DModelPointIterator iter = p_mModel3D.AddPointToModel(x, y, z, ID);

                            if (splited.Length > 6)
                            {
                                if (splited[no].Equals(""))
                                {
                                    no++;
                                }

                                if (splited.Length > 6 && splited[no++].Equals("rgb="))
                                {
                                    float r = 1;
                                    float g = 1;
                                    float b = 1;

                                    r = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                                    g = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                                    b = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);

                                    iter.Color = Color.FromArgb((int)(r * 255), (int)(g * 255), (int)(b * 255));
                                    iter.AddSpecificValue("Texture", iter.Color.ToArgb());
                                    no++;
                                }
                                if (splited.Length > 11 && splited[no++].Equals("uv="))
                                {
                                    float U = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                                    float V = Single.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);

                                    iter.U = U;
                                    iter.V = V;
                                }
                            }
                        }
                        else if (splited[0].Equals("Face"))
                        {
                            int no = 2;
                            if (splited[no].Equals(""))
                            {
                                no++;
                            }

                            uint ID1 = UInt32.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                            uint ID2 = UInt32.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);
                            uint ID3 = UInt32.Parse(splited[no++], System.Globalization.CultureInfo.InvariantCulture);

                            Cl3DModel.Cl3DModelPointIterator iter1 = p_mModel3D.GetIterator();
                            Cl3DModel.Cl3DModelPointIterator iter2 = p_mModel3D.GetIterator();
                            Cl3DModel.Cl3DModelPointIterator iter3 = p_mModel3D.GetIterator();

                            if (!iter1.MoveToPoint(ID1))
                            {
                                throw new Exception("Cannot find point with ID: " + ID1.ToString());
                            }

                            if (!iter2.MoveToPoint(ID2))
                            {
                                throw new Exception("Cannot find point with ID: " + ID2.ToString());
                            }

                            if (!iter3.MoveToPoint(ID3))
                            {
                                throw new Exception("Cannot find point with ID: " + ID3.ToString());
                            }

                            iter1.AddNeighbor(iter2);
                            iter2.AddNeighbor(iter3);
                            iter3.AddNeighbor(iter1);
                        }
                        else
                        {
                            throw new Exception("Unknown tocken: " + splited[0]);
                        }
                    }
                    FileStream.Close();
                }
            }
            catch (Exception e)
            {
                p_mModel3D.ResetModel();
                Exception ex = new Exception("Wrong M File Format: " + p_mModel3D.ModelFilePath, e);
                throw ex;
            }
        }
        private void SampleUVParametriztion(Cl3DModel p_Model, out Cl3DModel.Cl3DModelPointIterator[,] SampledModel, int MatrixWidth, int MatrixHeight)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            float maxU = iter.U;
            float minU = iter.U;
            float maxV = iter.V;
            float minV = iter.V;

            do
            {
                if (maxU < iter.U)
                {
                    maxU = iter.U;
                }
                if (maxV < iter.V)
                {
                    maxV = iter.V;
                }

                if (minU > iter.U)
                {
                    minU = iter.U;
                }
                if (minV > iter.V)
                {
                    minV = iter.V;
                }
            } while (iter.MoveToNext());

            List <Cl3DModel.Cl3DModelPointIterator>[,] SampledModelList = new List <Cl3DModel.Cl3DModelPointIterator> [MatrixWidth, MatrixHeight];
            SampledModel = new Cl3DModel.Cl3DModelPointIterator[MatrixWidth, MatrixHeight];

            iter = p_Model.GetIterator();
            do
            {
                float U = iter.U - minU;
                float V = iter.V - minV;

                int RoundU = (int)((U / (maxU - minU)) * (MatrixWidth - 1));
                int RoundV = (int)((V / (maxV - minV)) * (MatrixHeight - 1));

                if (SampledModelList[RoundU, RoundV] == null)
                {
                    SampledModelList[RoundU, RoundV] = new List <Cl3DModel.Cl3DModelPointIterator>();
                }

                SampledModelList[RoundU, RoundV].Add(iter.CopyIterator());
            } while (iter.MoveToNext());

            for (int i = 0; i < MatrixWidth; i++)
            {
                for (int j = 0; j < MatrixHeight; j++)
                {
                    if (SampledModelList[i, j] != null)
                    {
                        float  x          = 0;
                        float  y          = 0;
                        float  z          = 0;
                        float  u          = 0;
                        float  v          = 0;
                        int    ColorR     = 0;
                        int    ColorG     = 0;
                        int    ColorB     = 0;
                        string specPoint  = Cl3DModel.eSpecificPoints.UnspecifiedPoint.ToString();
                        bool   isSpecific = false;

                        Dictionary <string, double> SumOfSpecificValues = new Dictionary <string, double>();
                        foreach (Cl3DModel.Cl3DModelPointIterator pts in SampledModelList[i, j])
                        {
                            pts.AlreadyVisited = true;
                            if (!isSpecific)
                            {
                                isSpecific = p_Model.IsThisPointInSpecificPoints(pts, ref specPoint);
                            }

                            List <string> specValues = pts.GetListOfSpecificValues();
                            foreach (string valueName in specValues)
                            {
                                double currentVal = 0;
                                pts.GetSpecificValue(valueName, out currentVal);
                                double countedVal = 0;
                                SumOfSpecificValues.TryGetValue(valueName, out countedVal);

                                SumOfSpecificValues.Remove(valueName);
                                SumOfSpecificValues.Add(valueName, countedVal + currentVal);
                            }
                            x      += pts.X;
                            y      += pts.Y;
                            z      += pts.Z;
                            u      += pts.U;
                            v      += pts.V;
                            ColorR += pts.ColorR;
                            ColorG += pts.ColorG;
                            ColorB += pts.ColorB;
                        }

                        int Count = SampledModelList[i, j].Count;

                        List <Cl3DModel.Cl3DModelPointIterator> connections = new List <Cl3DModel.Cl3DModelPointIterator>();

                        foreach (Cl3DModel.Cl3DModelPointIterator point in SampledModelList[i, j])
                        {
                            foreach (Cl3DModel.Cl3DModelPointIterator InnerPoint in point.GetListOfNeighbors())
                            {
                                if (InnerPoint.AlreadyVisited == false)
                                {
                                    connections.Add(InnerPoint);
                                }
                            }
                        }

                        Cl3DModel.Cl3DModelPointIterator pt = p_Model.AddPointToModel(x / Count,
                                                                                      y / Count,
                                                                                      z / Count);
                        pt.Color = Color.FromArgb(ColorR / Count,
                                                  ColorG / Count,
                                                  ColorB / Count);

                        pt.U = (int)((u / SampledModelList[i, j].Count) / maxU * MatrixWidth);
                        pt.V = (int)((v / SampledModelList[i, j].Count) / maxV * MatrixHeight);

                        foreach (KeyValuePair <string, double> SpecVal in SumOfSpecificValues)
                        {
                            pt.AddSpecificValue(SpecVal.Key, SpecVal.Value / Count);
                        }

                        SampledModel[i, j] = pt;

                        if (isSpecific)
                        {
                            p_Model.AddSpecificPoint(specPoint, pt);
                        }

                        foreach (Cl3DModel.Cl3DModelPointIterator point in SampledModelList[i, j])
                        {
                            p_Model.RemovePointFromModel(point);
                        }

                        foreach (Cl3DModel.Cl3DModelPointIterator point in connections)
                        {
                            pt.AddNeighbor(point);
                        }
                    }
                }
            }
        }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            try
            {
                ReadTexture(p_sFilePath);
                // using ( cannot be used cause we open file stream once again
                StreamReader FileStream = File.OpenText(p_sFilePath);
                {
                    bool foundTocken = FindTockenInFile("Coordinate", FileStream);
                    if (!foundTocken)
                    {
                        FileStream  = File.OpenText(p_sFilePath);
                        foundTocken = FindTockenInFile("Coordinate3", FileStream);
                        if (!foundTocken)
                        {
                            throw new Exception("Wrong file format, cannot find 'Coordinate' tocken");
                        }
                    }

                    bool   finishReading = false;
                    String line;
                    int    pointNO = 0;
                    while ((line = FileStream.ReadLine()) != null && !finishReading)
                    {
                        if (line.Contains("point"))
                        {
                            continue;
                        }

                        string[] parts = line.Split(' ');
                        for (int i = 0; i < parts.Length; i++)
                        {
                            if (parts[i].Contains("]"))
                            {
                                finishReading = true;
                                break;
                            }
                        }
                        if (finishReading)
                        {
                            break;
                        }

                        List <string> numbers = new List <string>();

                        foreach (string s in parts)
                        {
                            if (s.Equals(""))
                            {
                                continue;
                            }
                            else
                            {
                                numbers.Add(s);
                            }
                        }

                        if (numbers.Count != 3)
                        {
                            throw new Exception("Wrong file format, less coordinates than expected");
                        }

                        float X = Single.Parse(numbers[0].Replace(',', ' '), System.Globalization.CultureInfo.InvariantCulture);
                        float Y = Single.Parse(numbers[1].Replace(',', ' '), System.Globalization.CultureInfo.InvariantCulture);
                        float Z = Single.Parse(numbers[2].Replace(',', ' '), System.Globalization.CultureInfo.InvariantCulture);

                        Cl3DModel.Cl3DModelPointIterator newPoint = p_mModel3D.AddPointToModel(X, Y, Z);
                        if (texture != null && TextureCoord.Count != 0)
                        {
                            newPoint.Color = texture.GetPixel((int)(TextureCoord[pointNO].no1 * texture.Width),
                                                              (int)(TextureCoord[pointNO].no2 * texture.Height));
                            newPoint.AddSpecificValue("Texture", newPoint.Color.ToArgb());
                        }
                        pointNO++;
                    }

                    foundTocken = FindTockenInFile("coordIndex", FileStream);
                    if (!foundTocken)
                    {
                        throw new Exception("Wrong file format, cannot find 'coordIndex' tocken");
                    }

                    while ((line = FileStream.ReadLine()) != null)
                    {
                        if (line.Contains("]"))
                        {
                            break;
                        }


                        List <Cl3DModel.Cl3DModelPointIterator> points = new List <Cl3DModel.Cl3DModelPointIterator>();

                        Cl3DModel.Cl3DModelPointIterator iter = p_mModel3D.GetIterator();
                        string[] parts     = line.Split(new Char [] { ' ', ',' });
                        bool     EndOfLine = false;
                        foreach (string part in parts)
                        {
                            if (part.Length == 0)
                            {
                                continue;
                            }

                            int no = Int32.Parse(part);

                            if (no == -1)
                            {
                                EndOfLine = true;
                            }

                            if (EndOfLine)
                            {
                                for (int i = 0; i < points.Count; i++)
                                {
                                    if (i == points.Count - 2)
                                    {
                                        points[i].AddNeighbor(points[i + 1]);
                                        points[i + 1].AddNeighbor(points[0]);
                                        break;
                                    }
                                    if (i == points.Count - 3)
                                    {
                                        points[i].AddNeighbor(points[i + 1]);
                                        points[i + 1].AddNeighbor(points[i + 2]);
                                        points[i + 2].AddNeighbor(points[i]);
                                    }
                                    else
                                    {
                                        points[i].AddNeighbor(points[i + 1]);
                                        points[i + 1].AddNeighbor(points[i + 2]);
                                        points[i + 2].AddNeighbor(points[i]);
                                    }
                                }
                                points.Clear();
                                EndOfLine = false;
                            }
                            else
                            {
                                if (!iter.MoveToPoint((uint)no))
                                {
                                    throw new Exception("Cannot find point no: " + no);
                                }
                                points.Add(iter.CopyIterator());
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                p_mModel3D.ResetModel();
                throw;
            }
        }