public virtual void ReadModel(Cl3DModel p_mModel3D, string p_sFilePath)
 {
     if (m_sReaderFileExtension.Equals(p_mModel3D.ModelType))
     {
         try
         {
             Read(p_mModel3D, p_sFilePath);
         }
         catch (Exception)
         {
             p_mModel3D.ResetModel();
             throw;
         }
     }
     else
         throw new ArgumentException("Extension of file doesn't fit to reader object");
 }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            try
            {
                using (FileStream fs = File.OpenRead(p_sFilePath))
                {
                    try
                    {
                        BinaryReader ReaderBinary = new BinaryReader(fs);
                        ushort nRows = ReaderBinary.ReadUInt16();
                        ushort nCols = ReaderBinary.ReadUInt16();
                        double zMin = ReaderBinary.ReadDouble();

                        ushort len = ReaderBinary.ReadUInt16();

                        char[] imFile = ReaderBinary.ReadChars((int)len);

                        p_mModel3D.ModelExpression = p_mModel3D.ModelFileName.Substring(6);

                        uint dataLen = ReaderBinary.ReadUInt32();

                        uint oneRead = dataLen / 5;

                        double[] X = new double[oneRead];
                        double[] Y = new double[oneRead];
                        double[] Z = new double[oneRead];
                        double[] RangeX = new double[oneRead];
                        double[] RangeY = new double[oneRead];

                        for (int i = 0; i < oneRead; i++)
                            X[i] = ReaderBinary.ReadDouble();

                        for (int i = 0; i < oneRead; i++)
                            Y[i] = ReaderBinary.ReadDouble();

                        for (int i = 0; i < oneRead; i++)
                            Z[i] = ReaderBinary.ReadDouble();

                        for (int i = 0; i < oneRead; i++)
                            RangeX[i] = ReaderBinary.ReadDouble();

                        for (int i = 0; i < oneRead; i++)
                            RangeY[i] = ReaderBinary.ReadDouble();

                        Cl3DModel.Cl3DModelPointIterator[,] tabOfElements = new Cl3DModel.Cl3DModelPointIterator[nCols, nRows];

                        for (int i = 0; i < oneRead; i++)
                        {
                            if (X[i] != zMin && Y[i] != zMin && Z[i] != zMin && RangeX[i] != zMin && RangeY[i] != zMin)
                            {
                                int rangeX = (int)(RangeX[i] * nCols);
                                int rangeY = (int)(RangeY[i] * nRows);
                                if (tabOfElements[rangeX, rangeY] == null)
                                    tabOfElements[rangeX, rangeY] = p_mModel3D.AddPointToModel((float)X[i], (float)Y[i], (float)Z[i], rangeX, rangeY);
                                else
                                    throw new Exception("The element is set to current position");
                            }
                        }

                        for (int x = 0; x < nCols; x++)
                        {
                            for (int y = 0; y < nRows; y++)
                            {
                                if (tabOfElements[x, y] == null)
                                    continue;

                                if (x - 1 >= 0 && y + 1 < nRows && tabOfElements[x - 1, y + 1] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x - 1, y + 1]);

                                if (x - 1 >= 0 && tabOfElements[x - 1, y] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x - 1, y]);

                                if (x - 1 >= 0 && y - 1 >= 0 && tabOfElements[x - 1, y - 1] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x - 1, y - 1]);

                                if (y - 1 >= 0 && tabOfElements[x, y - 1] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x, y - 1]);

                                if (x + 1 < nCols && y - 1 >= 0 && tabOfElements[x + 1, y - 1] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x + 1, y - 1]);

                                if (x + 1 < nCols && tabOfElements[x + 1, y] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x + 1, y]);

                                if (x + 1 < nCols && y + 1 < nRows && tabOfElements[x + 1, y + 1] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x + 1, y + 1]);

                                if (y + 1 < nRows && tabOfElements[x, y + 1] != null)
                                    tabOfElements[x, y].AddNeighbor(tabOfElements[x, y + 1]);
                            }
                        }

                    }
                    catch (System.IO.EndOfStreamException)
                    {
                    }
                    fs.Close();
                }
            }
            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
            {
                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;
            }
        }
        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;
            }
        }
        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
            {
                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;
            }
        }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            try
            {
                using (FileStream fs = File.OpenRead(p_sFilePath))
                {
                    BinaryReader ReaderBinary = new BinaryReader(fs);
                    while (true)
                    {
                        try
                        {
                            short number = ReaderBinary.ReadInt16();
                            for (short i = 0; i < number; i++)
                            {
                                short X = ReaderBinary.ReadInt16();
                                short Y = ReaderBinary.ReadInt16();
                                short Z = ReaderBinary.ReadInt16();

                                p_mModel3D.AddPointToModel((float)X/10.0f, (float)Y/10.0f, (float)-Z/10.0f);
                            }
                        }
                        catch (System.IO.EndOfStreamException)
                        {
                            break;
                        }
                    }
                    fs.Close();
                }
            }
            catch (Exception e)
            {
                p_mModel3D.ResetModel();
                throw e;
            }
        }
        public override void Read(Cl3DModel p_mModel3D, string p_sFilePath)
        {
            Cl3DModel.Cl3DModelPointIterator MaxPoint = null;
            try
            {
                using (StreamReader FileStream = File.OpenText(p_sFilePath))
                {
                    int iTableWidth = 0;
                    int iTableHeight = 0;

                    #region HeaderParse

                    String header = "";
                    if ((header = FileStream.ReadLine()) != null) // Search for ROWS
                    {
                        string[] val = header.Split(' ');
                        if (val.Length != 2)
                            throw new Exception("Wrong file format");

                        if (!val[1].Equals("rows"))
                            throw new Exception("Wrong file format, cannot find 'rows'");

                        iTableHeight = Int32.Parse(val[0]);
                    }
                    else
                        throw new Exception("Wrong file format, file is to short");

                    if ((header = FileStream.ReadLine()) != null) // Search for COLUMNS
                    {
                        string[] val = header.Split(' ');
                        if (val.Length != 2)
                            throw new Exception("Wrong file format");

                        if (!val[1].Equals("columns"))
                            throw new Exception("Wrong file format, cannot find 'rows'");

                        iTableWidth = Int32.Parse(val[0]);
                    }
                    else
                        throw new Exception("Wrong file format, file is to short");

                    if ((header = FileStream.ReadLine()) != null)// Search for PIXELS
                    {
                        if (!header.StartsWith("pixels (flag X Y Z):"))
                            throw new Exception("Wrong file format, cannot find 'pixels (flag X Y Z):', only this flags are available");
                    }
                    else
                        throw new Exception("Wrong file format, file is to short");
                    #endregion

                    string sValidPixels = "";
                    string sX = "";
                    string sY = "";
                    string sZ = "";
                    if ((sValidPixels = FileStream.ReadLine()) == null)// Search for sValidPixels
                        throw new Exception("Wrong file format, file is to short, cannot get Valid Pixels line");

                    if ((sX = FileStream.ReadLine()) == null)// Search for X
                        throw new Exception("Wrong file format, file is to short, cannot get X line");

                    if ((sY = FileStream.ReadLine()) == null)// Search for Y
                        throw new Exception("Wrong file format, file is to short, cannot get Y line");

                    if ((sZ = FileStream.ReadLine()) == null)// Search for Z
                        throw new Exception("Wrong file format, file is to short, cannot get Z line");

                    FileStream.Close();

                    string[] sArrayPixels = sValidPixels.Remove(sValidPixels.Length - 1).Split(' ');
                    string[] sArrayX = sX.Remove(sX.Length - 1).Split(' ');
                    string[] sArrayY = sY.Remove(sY.Length - 1).Split(' ');
                    string[] sArrayZ = sZ.Remove(sZ.Length - 1).Split(' ');

                    float vectorLength = iTableWidth * iTableHeight;

                    if (sArrayX.Length != vectorLength ||
                        sArrayY.Length != vectorLength ||
                        sArrayZ.Length != vectorLength ||
                        sArrayPixels.Length != vectorLength)
                        throw new Exception("Arrays length are different");

                    int ax = 0;
                    int ay = 0;
                    Cl3DModel.Cl3DModelPointIterator[,] tabOfElements = new Cl3DModel.Cl3DModelPointIterator[iTableWidth, iTableHeight];
                    //p_mModel3D.ResetModel();
                    for (int i = 0; i < sArrayPixels.Length; i++)
                    {
                        if (ax == iTableWidth)
                        {
                            ax = 0;
                            ay++;
                        }

                        if (ax >= iTableWidth || ay >= iTableHeight)
                            throw new Exception("One of acces operators is bigger than should be");

                        if (sArrayPixels[i].Equals("1"))
                        {
                            string Xstring = sArrayX[i];//.Replace(".", ",");
                            string Ystring = sArrayY[i];//.Replace(".", ",");
                            string Zstring = sArrayZ[i];//.Replace(".", ",");

                            float x = System.Single.Parse(Xstring, System.Globalization.CultureInfo.InvariantCulture);
                            float y = System.Single.Parse(Ystring, System.Globalization.CultureInfo.InvariantCulture);
                            float z = System.Single.Parse(Zstring, System.Globalization.CultureInfo.InvariantCulture);

                            tabOfElements[ax,ay] = p_mModel3D.AddPointToModel(x, y, z, ax, ay);
                            if (MaxPoint == null)
                                MaxPoint = tabOfElements[ax, ay];
                            else if (tabOfElements[ax, ay].Z > MaxPoint.Z)
                                MaxPoint = tabOfElements[ax, ay];
                        }
                        ax++;
                    }
                    float minusX = MaxPoint.X;
                    float minusY = MaxPoint.Y;
                    float minusZ = MaxPoint.Z;
                    for (int x = 0; x < iTableWidth; x++)
                    {
                        for (int y = 0; y < iTableHeight; y++)
                        {
                            if (tabOfElements[x, y] == null)
                                continue;

                            if (x - 1 >= 0 && y + 1 < iTableHeight && tabOfElements[x - 1, y + 1] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x - 1, y + 1]);

                            if (x - 1 >= 0 && tabOfElements[x - 1, y] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x - 1, y]);

                            if (x - 1 >= 0 && y - 1 >= 0 && tabOfElements[x - 1, y - 1] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x - 1, y - 1]);

                            if (y - 1 >= 0 && tabOfElements[x, y - 1] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x, y - 1]);

                            if (x + 1 < iTableWidth && y - 1 >= 0 && tabOfElements[x + 1, y - 1] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x + 1, y - 1]);

                            if (x + 1 < iTableWidth && tabOfElements[x + 1, y] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x + 1, y]);

                            if (x + 1 < iTableWidth && y + 1 < iTableHeight && tabOfElements[x + 1, y + 1] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x + 1, y + 1]);

                            if (y + 1 < iTableHeight && tabOfElements[x, y + 1] != null)
                                tabOfElements[x, y].AddNeighbor(tabOfElements[x, y + 1]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                p_mModel3D.ResetModel();
                throw;
            }
        }