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); } }
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); }
private void DrawMesh() { #if USE_VTK var renderer = this.renderWindowControl.RenderWindow.GetRenderers().GetFirstRenderer(); if (this.actor != null) { renderer.RemoveActor(this.actor); this.actor.Dispose(); this.actor = null; } var points = vtkPoints.New(); points.SetNumberOfPoints(_mesh.VertexCount); int index = 0; foreach (var vertex in _mesh.Vertices()) { points.SetPoint(index++, vertex.x, vertex.y, vertex.z); } var triangles = vtkCellArray.New(); triangles.Allocate(triangles.EstimateSize(_mesh.TriangleCount, 3), _mesh.TriangleCount / 2); foreach (var triangle in _mesh.Triangles()) { vtkIdList verts = vtkIdList.New(); verts.InsertNextId(triangle.a); verts.InsertNextId(triangle.b); verts.InsertNextId(triangle.c); triangles.InsertNextCell(verts); } var polyData = vtkPolyData.New(); polyData.SetPoints(points); polyData.SetPolys(triangles); points.Dispose(); triangles.Dispose(); var mapper = vtkPolyDataMapper.New(); mapper.SetInput(polyData); actor = vtkActor.New(); actor.SetMapper(mapper); renderer.AddActor(actor); this.renderWindowControl.RenderWindow.Render(); #endif }
public vtkUnstructuredGrid VtkGrid(double x_offset = 0.0, double y_offset = 0.0, double z_offset = 0.0) { vtkUnstructuredGrid grid = vtkUnstructuredGrid.New(); // Points vtkPoints points = vtkPoints.New(); _nodes.ForEach(n => points.InsertNextPoint(n.X + x_offset, n.Y + y_offset, n.Z + z_offset)); grid.SetPoints(points); // Cells //vtkCellArray cellArray = vtkCellArray.New(); _elements.ForEach(e => { switch (e.ElementType) { case GmshMeshElementType.HEXA_8NODE: { vtkHexahedron hex = vtkHexahedron.New(); vtkIdList hexIDList = hex.GetPointIds(); for (int i = 0; i < e.NumberOfNodes; ++i) { hexIDList.SetId(i, e.Nodes[i] - 1); } grid.InsertNextCell(hex.GetCellType(), hex.GetPointIds()); } break; case GmshMeshElementType.TET_4NODE: { vtkTetra tet = vtkTetra.New(); vtkIdList tetIDList = tet.GetPointIds(); for (int i = 0; i < e.NumberOfNodes; ++i) { tetIDList.SetId(i, e.Nodes[i] - 1); } grid.InsertNextCell(tet.GetCellType(), tet.GetPointIds()); } break; case GmshMeshElementType.QUAD_4NODE: { vtkQuad quad = vtkQuad.New(); vtkIdList quadIDList = quad.GetPointIds(); for (int i = 0; i < e.NumberOfNodes; ++i) { quadIDList.SetId(i, e.Nodes[i] - 1); } grid.InsertNextCell(quad.GetCellType(), quad.GetPointIds()); } break; case GmshMeshElementType.TRIANGLE_3NODE: { vtkTriangle tri = vtkTriangle.New(); vtkIdList triIDList = tri.GetPointIds(); for (int i = 0; i < e.NumberOfNodes; ++i) { triIDList.SetId(i, e.Nodes[i] - 1); } grid.InsertNextCell(tri.GetCellType(), tri.GetPointIds()); } break; case GmshMeshElementType.PRISM_6NODE: default: break; } } ); return(grid); }
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); }