public List <Vector3D> pointReader(vtkUnstructuredGrid unstructuredGrid) { var pointsList = new List <Vector3D>(); var points = unstructuredGrid.GetPoints(); for (int i = 0; i < points.GetNumberOfPoints(); i++) { if (points.GetPoint(i).Length < 3) { throw new Exception(String.Format("Point at position {0} does not contain a 3(xyz)-coordinate point", i)); } var vector = new Vector3D(points.GetPoint(i)[0], points.GetPoint(i)[1], points.GetPoint(i)[2]); pointsList.Add(vector); } return(pointsList); }
public static UnstructuredModel FromGrid(vtkUnstructuredGrid output, int numArrays) { var result = new UnstructuredModel { _Desc = DimensionDescription.FromPoints(output.GetPoints()), _Data = new List <PointData>() }; for (var i = 0; i < numArrays; ++i) { var pdata = PointData.FromArray((vtkFloatArray)output.GetPointData().GetArray(i)); pdata.DimensionDescription = result._Desc; result._Data.Add(pdata); } return(result); }
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); }