Пример #1
0
        public static List <List <double[]> > ReadPolyDataList(this string vtpFileName)
        {
            vtkPolyData polyData = ReadPolyData(vtpFileName);

            List <List <double[]> > ret = new List <List <double[]> >();

            for (int cellIdx = 0; cellIdx < polyData.GetNumberOfCells(); ++cellIdx)
            {
                List <double[]> list = new List <double[]>();
                ret.Add(list);

                vtkCell cell = polyData.GetCell(cellIdx);
                for (int i = 0; i < cell.GetNumberOfPoints(); ++i)
                {
                    list.Add(cell.GetPoints().GetPoint(i));
                }
            }

            polyData.Dispose();

            return(ret);
        }
Пример #2
0
        public bool Read_Poly_Data_File(string filename)
        {
            //Initalize VTK Reader
            vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();

            reader.SetFileName(filename);

            reader.Update();

            vtkPolyData polydata = reader.GetOutput();

            if (polydata == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Poly data Input");

                return(false);
            }

            // Read Point Coordinates
            int numPoints = (int)polydata.GetNumberOfPoints();

            List <Vector3d> point_dat = new List <Vector3d>();

            if (numPoints != 0)
            {
                double[] pt;

                for (int i = 0; i < numPoints; i++)
                {
                    pt = polydata.GetPoint(i);

                    point_dat.Add(new Vector3d((float)pt[0], (float)pt[1], (float)pt[2]));
                }
                if (this.vertex_data.ContainsKey("vertices"))
                {
                    this.vertex_data["vertices"] = point_dat;
                }
                else
                {
                    this.vertex_data.Add("vertices", point_dat);
                }
                Console.WriteLine("All points read in correctly!");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("---------------No Points existent");
            }

            // Read Point Indices
            int numpolydatacells = (int)polydata.GetNumberOfCells();

            vtkCell   polydataCell;
            vtkIdList pts;

            if (numpolydatacells != 0)
            {
                int counter = 0;
                cells.SetNumberOfCells(numpolydatacells);

                for (int i = 0; i < numpolydatacells; i++)
                {
                    polydataCell = polydata.GetCell(i);

                    int numCellPoints = (int)polydataCell.GetNumberOfPoints();
                    cells.InsertNextCell(polydataCell);

                    Vector3 trianglePoints = new Vector3();
                    if (numCellPoints == 3)
                    {
                        pts = polydataCell.GetPointIds();

                        int one   = (int)pts.GetId(0);
                        int two   = (int)pts.GetId(1);
                        int three = (int)pts.GetId(2);
                        //this.Get_Triangle(counter, pts);
                        trianglePoints = new Vector3(one, two, three);
                        counter++;
                    }
                    triangleList.Add(trianglePoints);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("---------------No Triangles existent");
            }

            // Read point data
            vtkPointData pointData = polydata.GetPointData();

            // Load point attributes
            this.Load_Point_Attributes(pointData);

            return(true);
        }