Example #1
0
        private static void CellEdges()
        {
            vtkTriangle triangle = vtkTriangle.New();

            triangle.GetPoints().SetPoint(0, 1.0, 0.0, 0.0);
            triangle.GetPoints().SetPoint(1, 0.0, 0.0, 0.0);
            triangle.GetPoints().SetPoint(2, 0.0, 1.0, 0.0);
            triangle.GetPointIds().SetId(0, 0);
            triangle.GetPointIds().SetId(1, 1);
            triangle.GetPointIds().SetId(2, 2);

            Console.WriteLine("The cell has " + triangle.GetNumberOfEdges() + " edges.");

            for (int i = 0; i < triangle.GetNumberOfEdges(); i++)
            {
                vtkCell edge = triangle.GetEdge(i);

                vtkIdList pointIdList = edge.GetPointIds();
                Console.WriteLine("Edge " + i + " has " + pointIdList.GetNumberOfIds() + " points.");

                for (int p = 0; p < pointIdList.GetNumberOfIds(); p++)
                {
                    Console.WriteLine("Edge " + i + " uses point " + pointIdList.GetId(p));
                }
            }
        }
        private static void IterateOverLines()
        {
            double[] origin = new double[] { 0.0, 0.0, 0.0 };
            double[,] p = new double[, ] {
                { 1.0, 0.0, 0.0 },
                { 0.0, 1.0, 0.0 },
                { 0.0, 1.0, 2.0 },
                { 1.0, 2.0, 3.0 }
            };

            // Create a vtkPoints object and store the points in it
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(origin[0], origin[1], origin[2]);
            for (int i = 0; i < 4; i++)
            {
                points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }

            // Create a cell array to store the lines in and add the lines to it
            vtkCellArray lines = vtkCellArray.New();

            // Create four lines
            for (int i = 0; i < 4; i++)
            {
                vtkLine line = vtkLine.New();
                line.GetPointIds().SetId(0, i);
                line.GetPointIds().SetId(1, i + 1);
                lines.InsertNextCell(line);
            }

            // Create a polydata to store everything in
            vtkPolyData linesPolyData = vtkPolyData.New();

            // Add the points to the dataset
            linesPolyData.SetPoints(points);

            // Add the lines to the dataset
            linesPolyData.SetLines(lines);

            Console.WriteLine("There are " + linesPolyData.GetNumberOfLines() + " lines.");
            linesPolyData.GetLines().InitTraversal();
            vtkIdList idList = vtkIdList.New();

            while (linesPolyData.GetLines().GetNextCell(idList) != 0)
            {
                Console.WriteLine("Line has " + idList.GetNumberOfIds() + " points.");

                for (int pointId = 0; pointId < idList.GetNumberOfIds(); pointId++)
                {
                    Console.Write(idList.GetId(pointId) + " ");
                }
                Console.Write(Environment.NewLine);
            }
        }
Example #3
0
        private int ImportCellIndices(int currentIndexNumber, vtkIdList cellIndices)
        {
            int numberOfIndices = cellIndices.GetNumberOfIds();

            for (int j = 0; j < numberOfIndices; j++)
            {
                Indices[currentIndexNumber] = cellIndices.GetId(j);
                currentIndexNumber         += 1;
            }
            return(currentIndexNumber);
        }
Example #4
0
        public void Read_Unstructured_Grid_File(string filename)
        {
            // Initalize VTK Reader
            vtkXMLUnstructuredGridReader reader = new vtkXMLUnstructuredGridReader();

            reader.SetFileName(filename);

            reader.Update();

            vtkUnstructuredGrid grid = reader.GetOutput();

            vtkCellArray data     = grid.GetCells();
            vtkIdList    idList   = vtkIdList.New();
            int          numCells = (int)data.GetNumberOfCells();

            if (numCells != 0)
            {
                if (grid.GetCellType(0) == 10)
                {
                    isTetra = true;
                    Console.WriteLine("Celltype is tetra");
                }
                else if (grid.GetCellType(0) == 5)
                {
                    isTetra = false;
                    Console.WriteLine("Celltype is triangle");
                }
                else
                {
                    Console.WriteLine("No valid celltype");
                }

                for (int i = 0; i < numCells; i++)
                {
                    long cellTypeID = grid.GetCellType(i);
                    // alle punkte durchlaufen und in eine Variable für jeden Punkt die anderen drei Punkte speichern
                    if (isTetra)
                    {
                        Vector4 tetraPoint = new Vector4();

                        grid.GetCellPoints(i, idList);
                        // ueber alle vier punkte iterieren und diese in extra liste für jeden Punkt speichern
                        for (int j = 0; j < 4; j++)
                        {
                            tetraPoint[j] = idList.GetId(j);
                        }

                        tetraPoints.Add(tetraPoint);
                    }
                    else if (!isTetra)
                    {
                        Vector3 triangle = new Vector3();

                        grid.GetCellPoints(i, idList);
                        // ueber alle drei punkte iterieren und diese in extra liste für jeden Punkt speichern
                        for (int j = 0; j < 3; j++)
                        {
                            triangle[j] = idList.GetId(j);
                        }
                        trianglePoints.Add(triangle);
                    }
                }
            }

            // Read Point Coordinates
            vtkPoints points = grid.GetPoints();

            int numPoints = (int)points.GetNumberOfPoints();

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

            if (numPoints != 0)
            {
                // Read Point Data
                double[] pt;
                for (int i = 0; i < numPoints; i++)
                {
                    pt = points.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");
            }

            vtkPointData pointData = grid.GetPointData();

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