public void Parse3DGeometry(string folderdir)
        {
            string line;

            double firstV, secondV, thirdV;
            int firstF, secondF, thirdF;
            StreamReader sr = new StreamReader(folderdir);
            while (sr.Peek() > -1)
            {
                line = sr.ReadLine();
                if (line[0] == 'v')
                {
                    string[] parsedVertices = line.Split(' ');
                    firstV = Convert.ToDouble(parsedVertices[1]);
                    secondV = Convert.ToDouble(parsedVertices[2]);
                    thirdV = Convert.ToDouble(parsedVertices[3]);

                    Vertex myVertex = new Vertex { x = firstV, y = secondV, z = thirdV };
                    VertexList.Add(myVertex);

                }
                else if (line[0] == 'f')
                {
                    string[] parsedFaces = line.Split(' ');
                    firstF = Convert.ToInt32(parsedFaces[1]);
                    secondF = Convert.ToInt32(parsedFaces[2]);
                    thirdF = Convert.ToInt32(parsedFaces[3]);

                    Face myFace = new Face { firstIndex = firstF, secondIndex = secondF, thirdIndex = thirdF };
                    FaceList.Add(myFace);

                }
            }
            sr.Close();
        }
        public Displacement(Vertex sourceVertex, Vertex targetVertex)
        {
            x = targetVertex.x - sourceVertex.x;
            y = targetVertex.y - sourceVertex.y;
            z = targetVertex.z - sourceVertex.z;

            SourceVertex = sourceVertex;
            TargetVertex = targetVertex;
        }
        public List<Displacement> GetVertexListForMachineCoordinatesAsDisplacement()
        {
            List<Vertex> machineCoordinateList = ObjectGeomertyParser.VertexList;

            double maxXValue = Utility.FindMaxValue(machineCoordinateList, m => m.x);
            double minXValue = Utility.FindMinValue(machineCoordinateList, m => m.x);

            double maxYValue = Utility.FindMaxValue(machineCoordinateList, m => m.y);
            double minYValue = Utility.FindMinValue(machineCoordinateList, m => m.y);

            double maxZValue = Utility.FindMaxValue(machineCoordinateList, m => m.z);
            double minZValue = Utility.FindMinValue(machineCoordinateList, m => m.z);

            double xValueSpan = Math.Abs(maxXValue - minXValue);
            double yValueSpan = Math.Abs(maxYValue - minYValue);
            double zValueSpan = Math.Abs(maxZValue - minZValue);

            double percentXIndex = 160;
            double percentYIndex = 160; // Motor A
            double percentZIndex = 160;

            int step = 5;

            WriteVertexToFile(machineCoordinateList, "original_vertext2.txt");

            foreach (Vertex item in machineCoordinateList)
            {
                item.x = Math.Round(((item.x - minXValue) / xValueSpan) * percentXIndex);
               // item.x = Utility.GetDiscreteValue(item.x, step);
            }

            foreach (Vertex item in machineCoordinateList)
            {
                item.z = Math.Round(((item.z - minZValue) / zValueSpan) * percentZIndex);
                //item.z = Utility.GetDiscreteValue(item.z, step);
            }

            // Now further discretize x and z ccordinates, then order y accordingly as displacement

            foreach (Vertex item in machineCoordinateList)
            {
                item.y = 160 - Math.Round(((item.y - minYValue) / yValueSpan) * percentYIndex);
                //item.y = Utility.GetDiscreteValue(item.y, step);
            }

            WriteVertexToFile(machineCoordinateList, "normalised_vertext2.txt");

               // machineCoordinateList = machineCoordinateList.OrderBy(e => e.x).ThenBy(e => e.z).ThenBy(e => e.y).ToList<Vertex>();

               // WriteVertexToFile(machineCoordinateList, "ordered_vertext.txt");

            Vertex previousVertex = new Vertex() {x = 0, y = 0, z = 0};

            List<Displacement> displacementList = new List<Displacement>();

            foreach (Vertex vertex in machineCoordinateList)
            {
                Displacement currentDisplacement = new Displacement(previousVertex, vertex);
                previousVertex = vertex;
                displacementList.Add(currentDisplacement);
            }

              /* var orderedVertexList =  from m in machineCoordinateList
            orderby m.x, m.z descending, m.y
            select m;

            machineCoordinateList = orderedVertexList.ToList<Vertex>(); */

            StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\displacement1.txt");

            foreach (Displacement d in displacementList)
            {
                sw.WriteLine(d.Serialize());
            }

            sw.Close();

            return displacementList;
        }