protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();

            if (!iter.MoveToPoint(PointNo))
            {
                throw new Exception("The point does not exist");
            }

            return;

            /*
             * Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
             * double minDistance = 0;
             * if (!iter.GetSpecificValue("AllDistancesXYZ", out minDistance))
             *  return;
             * Cl3DModel.Cl3DModelPointIterator minIter = iter.CopyIterator();
             *
             * iter.MoveToNext();
             * do{
             *
             *  double tmpMin = 0;
             *  if (!iter.GetSpecificValue("AllDistancesXYZ", out tmpMin))
             *      continue;
             *
             *  if(tmpMin < minDistance)
             *  {
             *      minDistance = tmpMin;
             *      minIter = iter.CopyIterator();
             *  }
             * }while(iter.MoveToNext());
             * p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.UnspecifiedPoint.ToString(), minIter);
             */
        }
        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;
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            string name = p_Model.ModelFileName;

            if (m_CharsToSubstract != 0)
            {
                name = name.Substring(0, name.Length - m_CharsToSubstract);
            }

            if (!IDS)
            {
                string fileName = p_Model.ModelFileFolder + name + m_sFilePostFix + ".pts";
                Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
                using (StreamReader FileStream = File.OpenText(fileName))
                {
                    string line = "";
                    while ((line = FileStream.ReadLine()) != null)
                    {
                        if (line.Length == 0)
                        {
                            continue;
                        }

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

                        string[] splited = line.Split(' ');

                        Cl3DModel.eSpecificPoints type = Cl3DModel.eSpecificPoints.LeftEyeRightCorner;

                        if (splited[0].Equals("LeftEyeRightCorner"))
                        {
                            type = Cl3DModel.eSpecificPoints.LeftEyeRightCorner;
                        }
                        else if (splited[0].Equals("RightEyeLeftCorner"))
                        {
                            type = Cl3DModel.eSpecificPoints.RightEyeLeftCorner;
                        }
                        else if (splited[0].Equals("NoseTip"))
                        {
                            type = Cl3DModel.eSpecificPoints.NoseTip;
                        }
                        else
                        {
                            continue;
                        }

                        uint ID = UInt32.Parse(splited[1]);
                        if (!iter.MoveToPoint(ID))
                        {
                            throw new Exception("Cannot find point with ID: " + splited[1]);
                        }

                        p_Model.AddSpecificPoint(type, iter);
                    }
                }
            }
            else
            {
                string fileName = p_Model.ModelFileFolder + name + m_sFilePostFix + ".ptsID";
                Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
                using (StreamReader FileStream = File.OpenText(fileName))
                {
                    string line       = "";
                    int    count      = 0;
                    uint   NoOfPoints = 0;
                    bool   ReadHeader = false;
                    while ((line = FileStream.ReadLine()) != null)
                    {
                        if (!ReadHeader)
                        {
                            NoOfPoints = UInt32.Parse(line);
                            if (NoOfPoints != 3)
                            {
                                throw new Exception("Method ready to read 3 points");
                            }
                            ReadHeader = true;
                        }
                        else
                        {
                            uint id = UInt32.Parse(line);
                            iter.MoveToPoint(id);
                            if (count == 0)
                            {
                                p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip, iter);
                            }
                            if (count == 1)
                            {
                                p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner, iter);
                            }
                            if (count == 2)
                            {
                                p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner, iter);
                            }

                            count++;
                        }
                    }
                }
            }
        }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            try
            {
                using (StreamReader FileStream = File.OpenText(p_sFilePath))
                {
                    string line         = "";
                    int    NoOfVertexes = 0;
                    int    NoOfFaces    = 0;

                    if ((line = FileStream.ReadLine()) == null || !line.Equals("OFF"))
                    {
                        throw new Exception("Incorrect Header");
                    }

                    if ((line = FileStream.ReadLine()) == null)
                    {
                        throw new Exception("Incerrect Header");
                    }

                    string[] splitted = line.Split(' ');
                    NoOfVertexes = Int32.Parse(splitted[0]);
                    NoOfFaces    = Int32.Parse(splitted[1]);

                    for (int i = 0; i < NoOfVertexes; i++)
                    {
                        if ((line = FileStream.ReadLine()) == null)
                        {
                            throw new Exception("Incerrect Header");
                        }

                        splitted = line.Split(' ');
                        float X = float.Parse(splitted[0].Replace('.', ','));
                        float Y = float.Parse(splitted[1].Replace('.', ','));
                        float Z = float.Parse(splitted[2].Replace('.', ','));
                        p_mModel3D.AddPointToModel(X, Y, Z);
                    }
                    for (int i = 0; i < NoOfFaces; i++)
                    {
                        if ((line = FileStream.ReadLine()) == null)
                        {
                            throw new Exception("Incorrect Header");
                        }

                        splitted = line.Split(' ');
                        int noOfVect = int.Parse(splitted[0]);
                        if (noOfVect != 3)
                        {
                            throw new Exception("Wrong number of vertexes in the face");
                        }

                        int vertex1 = int.Parse(splitted[1]);
                        int vertex2 = int.Parse(splitted[2]);
                        int vertex3 = int.Parse(splitted[3]);

                        Cl3DModel.Cl3DModelPointIterator iter  = p_mModel3D.GetIterator();
                        Cl3DModel.Cl3DModelPointIterator iter2 = p_mModel3D.GetIterator();

                        if (!iter.MoveToPoint((uint)vertex1))
                        {
                            throw new Exception("Cannot find the point with ID: " + vertex1.ToString());
                        }
                        if (!iter2.MoveToPoint((uint)vertex2))
                        {
                            throw new Exception("Cannot find the point with ID: " + vertex2.ToString());
                        }

                        iter.AddNeighbor(iter2.CopyIterator());
                        if (!iter2.MoveToPoint((uint)vertex3))
                        {
                            throw new Exception("Cannot find the point with ID: " + vertex3.ToString());
                        }

                        iter.AddNeighbor(iter2.CopyIterator());
                    }
                }
            }
            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;
            }
        }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            try
            {
                Dictionary <uint, KeyValuePair <Cl3DModel.Cl3DModelPointIterator, List <uint> > > modelNeighbors = new Dictionary <uint, KeyValuePair <Cl3DModel.Cl3DModelPointIterator, List <uint> > >();
                using (StreamReader FileStream = File.OpenText(p_sFilePath))
                {
                    string line;
                    bool   Landmarks = false;
                    while ((line = FileStream.ReadLine()) != null)
                    {
                        if (line.Length == 0)
                        {
                            continue;
                        }
                        if (line[0].Equals('@'))
                        {
                            continue;
                        }

                        if (line.Contains("Landmark points"))
                        {
                            Landmarks = true;
                            continue;
                        }

                        if (Landmarks)
                        {
                            //Landmark points (ptID): "+nop
                            string[] splitedLine = line.Split(' ');
                            String   PointLabel  = splitedLine[0];
                            uint     PointID     = UInt32.Parse(splitedLine[1]);

                            Cl3DModel.Cl3DModelPointIterator iter = p_mModel3D.GetIterator();
                            if (!iter.MoveToPoint(PointID))
                            {
                                throw new Exception("Cannot find point no: " + PointID.ToString());
                            }

                            p_mModel3D.AddSpecificPoint(PointLabel, iter);
                        }
                        else
                        {
                            string[] splitedLine = line.Split(' ');
                            uint     PointId     = UInt32.Parse(splitedLine[0], System.Globalization.CultureInfo.InvariantCulture);
                            float    X           = Single.Parse(splitedLine[1], System.Globalization.CultureInfo.InvariantCulture);
                            float    Y           = Single.Parse(splitedLine[2], System.Globalization.CultureInfo.InvariantCulture);
                            float    Z           = Single.Parse(splitedLine[3], System.Globalization.CultureInfo.InvariantCulture);

                            int XImage = Int32.Parse(splitedLine[5], System.Globalization.CultureInfo.InvariantCulture);
                            int YImage = Int32.Parse(splitedLine[6], System.Globalization.CultureInfo.InvariantCulture);

                            Cl3DModel.Cl3DModelPointIterator iter = p_mModel3D.AddPointToModel(X, Y, Z, XImage, YImage, PointId);
                            List <uint> neighbors = new List <uint>();
                            for (int i = 9; i < splitedLine.Length - 1; i++)
                            {
                                neighbors.Add(UInt32.Parse(splitedLine[i], System.Globalization.CultureInfo.InvariantCulture));
                            }
                            modelNeighbors.Add(PointId, new KeyValuePair <Cl3DModel.Cl3DModelPointIterator, List <uint> >(iter, neighbors));
                        }
                    }
                }
                foreach (KeyValuePair <uint, KeyValuePair <Cl3DModel.Cl3DModelPointIterator, List <uint> > > onePoint in modelNeighbors)
                {
                    foreach (uint neighboorNo in onePoint.Value.Value)
                    {
                        KeyValuePair <Cl3DModel.Cl3DModelPointIterator, List <uint> > list;
                        if (modelNeighbors.TryGetValue(neighboorNo, out list))
                        {
                            onePoint.Value.Key.AddNeighbor(list.Key);
                        }
                    }
                }
            }
            catch (Exception)
            {
                p_mModel3D.ResetModel();
                throw;
            }
        }
示例#7
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)
        {
            SaveModel(p_Model);

            string ParameterString = "\"" + p_Model.ModelFileFolder + paramFileName + ".tmp\" " + "0";

            if (m_bAreaWeight)
            {
                ParameterString = "\"" + p_Model.ModelFileFolder + paramFileName + ".tmp\" " + "1";
            }

            ProcessStartInfo proces = new ProcessStartInfo(m_sRunApplication, ParameterString);

            proces.WindowStyle = ProcessWindowStyle.Minimized;

            Process ConformalProcess = System.Diagnostics.Process.Start(proces);

            ConformalProcess.WaitForExit();

            string FileName = p_Model.ModelFileFolder + paramFileName + "_AreaWeight.UV";

            if (m_bAreaWeight)
            {
                FileName = p_Model.ModelFileFolder + paramFileName + "_NoAreaWeight.UV";
            }


            if (!File.Exists(FileName))
            {
                throw new Exception("Something goes wrong with calculation of UV parametrization for the file:" + p_Model.ModelFileName);
            }

            using (StreamReader FileStream = File.OpenText(FileName))
            {
                Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
                string line = "";
                while ((line = FileStream.ReadLine()) != null)
                {
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // UV verID=41496 U=0.0854425 V=0.224188
                    char[]   delimiters = new char[] { ' ', '=' };
                    string[] parts      = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                    uint     ID         = UInt32.Parse(parts[2], System.Globalization.CultureInfo.InvariantCulture);
                    float    U          = Single.Parse(parts[4], System.Globalization.CultureInfo.InvariantCulture);
                    float    V          = Single.Parse(parts[6], System.Globalization.CultureInfo.InvariantCulture);
                    if (!iter.MoveToPoint(ID))
                    {
                        throw new Exception("Cannot move iterator to the position: " + ID.ToString());
                    }

                    iter.U = U;
                    iter.V = V;
                }
                FileStream.Close();
            }
            File.Delete(FileName);
            File.Delete(p_Model.ModelFileFolder + paramFileName + ".tmp");
        }
        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)
                        {
                            continue;
                        }

                        if (line[0] == '#')
                        {
                            continue;
                        }

                        string[] splitted = line.Split(' ');
                        if (splitted[0].Equals("v"))
                        {
                            float X = float.Parse(splitted[1].Replace('.', ','));
                            float Y = float.Parse(splitted[2].Replace('.', ','));
                            float Z = float.Parse(splitted[3].Replace('.', ','));
                            p_mModel3D.AddPointToModel(X, Y, Z);
                        }
                        else if (splitted[0].Equals("f"))
                        {
                            if (splitted.Length != 4)
                            {
                                throw new Exception("Wrong number of vertexes in the face");
                            }

                            int vertex1 = int.Parse(splitted[1]);
                            int vertex2 = int.Parse(splitted[2]);
                            int vertex3 = int.Parse(splitted[3]);

                            Cl3DModel.Cl3DModelPointIterator iter  = p_mModel3D.GetIterator();
                            Cl3DModel.Cl3DModelPointIterator iter2 = p_mModel3D.GetIterator();

                            if (!iter.MoveToPoint((uint)--vertex1))
                            {
                                throw new Exception("Cannot find the point with ID: " + vertex1.ToString());
                            }
                            if (!iter2.MoveToPoint((uint)--vertex2))
                            {
                                throw new Exception("Cannot find the point with ID: " + vertex2.ToString());
                            }

                            iter.AddNeighbor(iter2.CopyIterator());

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

                            iter.AddNeighbor(iter2.CopyIterator());
                        }
                    }
                }
            }
            catch (Exception)
            {
                p_mModel3D.ResetModel();
                throw;
            }
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            try
            {
                if (!File.Exists(m_sPath))
                {
                    throw new Exception("External file does not exist, the path is incorrect: " + m_sPath);
                }

                ClSaveToMFileNew algSave = new ClSaveToMFileNew(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2");
                algSave.MakeAlgorithm(p_Model);

                Process proc = new Process();
                proc.StartInfo.FileName    = m_sPath;
                proc.StartInfo.Arguments   = "-harmonic_map \"" + p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2\" \"" + p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m\"";
                proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                proc.Start();

                if (!proc.WaitForExit(10000))
                {
                    proc.Kill();
                    File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2");
                }

                ClInformationSender.SendInformation("Parametrization calculated", ClInformationSender.eInformationType.eDebugText);

                Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
                using (StreamReader FileStream = File.OpenText(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m"))
                {
                    string line = "";
                    while ((line = FileStream.ReadLine()) != null)
                    {
                        if (!line.Contains("Vertex"))
                        {
                            continue;
                        }
                        int      index     = line.LastIndexOf("uv=") + 3;
                        string   substring = line.Substring(index);
                        string[] subsubs   = substring.Substring(substring.IndexOf('(') + 1, substring.LastIndexOf(')') - substring.IndexOf('(') - 1).Split(' ');
                        float    U         = float.Parse(subsubs[0], System.Globalization.CultureInfo.InvariantCulture);
                        float    V         = float.Parse(subsubs[1], System.Globalization.CultureInfo.InvariantCulture);

                        uint ID = uint.Parse(line.Split(' ')[1]);
                        if (!iter.MoveToPoint(ID - 1))
                        {
                            throw new Exception("Cannot localize point with number: " + ID.ToString());
                        }

                        iter.U = U;
                        iter.V = V;
                    }
                }
                File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2");
                if (removeOutput)
                {
                    File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m");
                }
            }
            catch (Exception)
            {
                File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2");
                File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m");
                throw;
            }
        }
        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;
            }
        }