// Draw poly data: earth demo private void earthToolStripMenuItem_Click(object sender, EventArgs e) { vtkEarthSource source = new vtkEarthSource(); vtkPolyDataMapper map = vtkPolyDataMapper.New(); vtkPolyData poly = new vtkPolyData(); vtkActor actor = new vtkActor(); vtkPoints pts = new vtkPoints(); vtkCellArray strip = new vtkCellArray(); // 定义三个点 pts.InsertNextPoint(0, 0, 0); pts.InsertNextPoint(1, 0, 0); pts.InsertNextPoint(1, 1, 0); // 定义一个单元 strip.InsertCellPoint(3); strip.InsertNextCell(0); strip.InsertNextCell(1); strip.InsertNextCell(2); // 定义vtkPolyData为点集 poly.SetPoints(pts); poly.SetVerts(strip);// 用SetVerts函数定义点, Verts即Vertices(顶点,Vertex的复数) // 定义mapper map.SetInput(poly); map.SetInput(source.GetOutput()); actor.SetMapper(map); m_Renderer.SetBackground(.5, .5, 1); imgPropList.Add(actor); m_Renderer.AddActor(actor); //Rerender the screen m_RenderWindow.Render(); m_Renderer.Render(); }
internal void CreatePolydata(ref vtkPolyData polydata) { vtkPoints points = vtkPoints.New(); points.InsertNextPoint(this.origin[0], this.origin[1], this.origin[2]); float[] x = new float[3]; float[] y = new float[3]; float[] z = new float[3]; Add(this.origin, this.xDirection, ref x); Add(this.origin, this.yDirection, ref y); Add(this.origin, this.zDirection, ref z); points.InsertNextPoint(x[0], x[1], x[2]); points.InsertNextPoint(y[0], y[1], y[2]); points.InsertNextPoint(z[0], z[1], z[2]); polydata.SetPoints(points); vtkVertexGlyphFilter vertexGlyphFilter = vtkVertexGlyphFilter.New(); #if VTK_MAJOR_VERSION_5 vertexGlyphFilter.AddInput(polydata); #else vertexGlyphFilter.AddInputData(polydata); #endif vertexGlyphFilter.Update(); polydata.ShallowCopy(vertexGlyphFilter.GetOutput()); }
private static void NullPoint() { vtkPoints points = vtkPoints.New(); points.InsertNextPoint(1, 1, 1); points.InsertNextPoint(2, 2, 2); points.InsertNextPoint(3, 3, 3); vtkPolyData polydata = vtkPolyData.New(); polydata.SetPoints(points); vtkFloatArray floatArray = vtkFloatArray.New(); floatArray.SetNumberOfValues(3); floatArray.SetNumberOfComponents(1); floatArray.SetName("FloatArray"); for (int i = 0; i < 3; i++) { floatArray.SetValue(i, 2); } polydata.GetPointData().AddArray(floatArray); vtkIntArray intArray = vtkIntArray.New(); intArray.SetNumberOfValues(3); intArray.SetNumberOfComponents(1); intArray.SetName("IntArray"); for (int i = 0; i < 3; i++) { intArray.SetValue(i, 2); } polydata.GetPointData().AddArray(intArray); Console.WriteLine("PointIdx x y z " + "floatArray" + " " + "intArray"); Console.WriteLine("----------------------------------------"); for (int i = 0; i < 3; i++) { double[] p = polydata.GetPoint(i); vtkFloatArray pointsFloatArray = vtkFloatArray.SafeDownCast(polydata.GetPointData().GetArray("FloatArray")); vtkIntArray pointsIntArray = vtkIntArray.SafeDownCast(polydata.GetPointData().GetArray("IntArray")); Console.WriteLine(" " + i + " " + p[0] + " " + p[1] + " " + p[2] + " " + pointsFloatArray.GetValue(i) + " " + pointsIntArray.GetValue(i)); } polydata.GetPointData().NullPoint(1); polydata.Modified(); Console.WriteLine(""); for (int i = 0; i < 3; i++) { double[] p = polydata.GetPoint(i); vtkFloatArray pointsFloatArray = vtkFloatArray.SafeDownCast(polydata.GetPointData().GetArray("FloatArray")); vtkIntArray pointsIntArray = vtkIntArray.SafeDownCast(polydata.GetPointData().GetArray("IntArray")); Console.WriteLine(" " + i + " " + p[0] + " " + p[1] + " " + p[2] + " " + pointsFloatArray.GetValue(i) + " " + pointsIntArray.GetValue(i)); } }
private void PolygonIntersection() { // Create a square in the XY plane vtkPoints points = vtkPoints.New(); points.InsertNextPoint(0.0, 0.0, 0.0); points.InsertNextPoint(1.0, 0.0, 0.0); points.InsertNextPoint(1.0, 1.0, 0.0); points.InsertNextPoint(0.0, 1.0, 0.0); // Create the polygon vtkPolygon polygon = vtkPolygon.New(); polygon.GetPoints().DeepCopy(points); polygon.GetPointIds().SetNumberOfIds(4); // 4 corners of the square polygon.GetPointIds().SetId(0, 0); polygon.GetPointIds().SetId(1, 1); polygon.GetPointIds().SetId(2, 2); polygon.GetPointIds().SetId(3, 3); // our line to intersect the polygon with double[] p1 = new double[] { 0.1, 0, -1.0 }; double[] p2 = new double[] { 0.1, 0, 1.0 }; double tolerance = 0.001; // Outputs // t must be initalized cause it is passed by reference (that's a c# convention) double t = 0.0; // Parametric coordinate of intersection (0 (corresponding to p1) to 1 (corresponding to p2)) double[] x = new double[] { 0.0, 0.0, 0.0 }; double[] coords = new double[] { 0.0, 0.0, 0.0 }; // subId must be initialized cause it is passed by reference (that's a c# convention) int subId = 0; IntPtr pP1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3); IntPtr pP2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3); IntPtr pX = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3); IntPtr pCoords = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3); Marshal.Copy(p1, 0, pP1, 3); Marshal.Copy(p2, 0, pP2, 3); // next two lines are not necessarely needed, but I prefer to initialize ref parameter (in those a result is passed back) Marshal.Copy(x, 0, pX, 3); Marshal.Copy(coords, 0, pCoords, 3); // see vtkCell API for a detailed description of this function int iD = polygon.IntersectWithLine(pP1, pP2, tolerance, ref t, pX, pCoords, ref subId); // Copy result back to our managed arrays Marshal.Copy(pX, x, 0, 3); Marshal.Copy(pCoords, coords, 0, 3); Console.WriteLine("intersected? " + iD);; Console.WriteLine("intersection: " + x[0] + " " + x[1] + " " + x[2]); Marshal.FreeHGlobal(pP1); Marshal.FreeHGlobal(pP2); Marshal.FreeHGlobal(pX); Marshal.FreeHGlobal(pCoords); // nothing to visualize }
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 void DrawTriangle() { //创建点数据 vtkPoints points = vtkPoints.New(); points.InsertNextPoint(1.0, 0.0, 0.0); points.InsertNextPoint(0.0, 1.0, 0.0); points.InsertNextPoint(0.0, 0.0, 0.0); //每两个坐标之间分别创建一条线 //SetId()的第一个参数是线段的端点ID,第二参数是连接的的点的ID vtkLine line0 = vtkLine.New(); line0.GetPointIds().SetId(0, 0); line0.GetPointIds().SetId(1, 1); vtkLine line1 = vtkLine.New(); line1.GetPointIds().SetId(0, 1); line1.GetPointIds().SetId(1, 2); vtkLine line2 = vtkLine.New(); line2.GetPointIds().SetId(0, 2); line2.GetPointIds().SetId(1, 0); //创建单元数组,用于存储以上创建的线段 vtkCellArray lines = vtkCellArray.New(); lines.InsertNextCell(line0); lines.InsertNextCell(line1); lines.InsertNextCell(line2); //将点和线加入数据集中,前者定义数据集的几何结构,后者定义拓扑结构 //创建vtkPolyData类型的数据,是一种数据集 vtkPolyData polyData = vtkPolyData.New(); //将创建的点数据加入vtkPolyData数据里 polyData.SetPoints(points); //点数据定义了polydata数据集的几何结构。 polyData.SetLines(lines); //定义拓扑结构 //显示数据 vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputData(polyData); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetColor(1.0, 0.0, 0.0); vtkRenderWindow renWin = myRenderWindowControl.RenderWindow; vtkRenderer renderer = renWin.GetRenderers().GetFirstRenderer(); renderer.SetBackground(1.0, 1.0, 1.0); renderer.AddActor(actor); }
static void AlignFrames(Frame sourceFrame, Frame targetFrame, ref vtkTransform transform) { // This function takes two frames and finds the matrix M between them. vtkLandmarkTransform landmarkTransform = vtkLandmarkTransform.New(); // Setup source points vtkPoints sourcePoints = vtkPoints.New(); sourcePoints.InsertNextPoint( sourceFrame.Origin[0], sourceFrame.Origin[1], sourceFrame.Origin[2]); float[] sourceX = new float[3]; float[] sourceY = new float[3]; float[] sourceZ = new float[3]; Add(sourceFrame.Origin, sourceFrame.XDirection, ref sourceX); Add(sourceFrame.Origin, sourceFrame.YDirection, ref sourceY); Add(sourceFrame.Origin, sourceFrame.ZDirection, ref sourceZ); sourcePoints.InsertNextPoint(sourceX[0], sourceX[1], sourceX[2]); sourcePoints.InsertNextPoint(sourceY[0], sourceY[1], sourceY[2]); sourcePoints.InsertNextPoint(sourceZ[0], sourceZ[1], sourceZ[2]); // Setup target points vtkPoints targetPoints = vtkPoints.New(); targetPoints.InsertNextPoint(targetFrame.Origin[0], targetFrame.Origin[1], targetFrame.Origin[2]); float[] targetX = new float[3]; float[] targetY = new float[3]; float[] targetZ = new float[3]; Add(targetFrame.Origin, targetFrame.XDirection, ref targetX); Add(targetFrame.Origin, targetFrame.YDirection, ref targetY); Add(targetFrame.Origin, targetFrame.ZDirection, ref targetZ); targetPoints.InsertNextPoint(targetX[0], targetX[1], targetX[2]); targetPoints.InsertNextPoint(targetY[0], targetY[1], targetY[2]); targetPoints.InsertNextPoint(targetZ[0], targetZ[1], targetZ[2]); landmarkTransform.SetSourceLandmarks(sourcePoints); landmarkTransform.SetTargetLandmarks(targetPoints); landmarkTransform.SetModeToRigidBody(); landmarkTransform.Update(); vtkMatrix4x4 M = landmarkTransform.GetMatrix(); transform.SetMatrix(M); }
//private vtkActor DrawVehicleID(float curX, float ySign) //{ // // Create text // vtkVectorText textSource = new vtkVectorText(); // textSource.SetText("Hello"); // textSource.Update(); // // Visualize // vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); // mapper.SetInputConnection(textSource.GetOutputPort()); // vtkActor textActor = vtkActor.New(); // textActor.SetScale(Constants.INDICATOR_TEXT_SIZE_X, Constants.INDICATOR_TEXT_SIZE_Y, 1); // double[] bounds = textActor.GetXRange(); // Console.WriteLine(bounds[0]); // Console.WriteLine(bounds[1]); // double halfSize = (bounds[1] - bounds[0]) / 2d; // textActor.SetPosition(curX - halfSize, Constants.INDICATOR_LINE_OFFSET * ySign, 0); // textActor.SetMapper(mapper); // textActor.GetProperty().SetColor(1, 0, 0); // return textActor; //} private vtkActor DrawLineSector(float startX, float yOffset, float size, Color color, float deltaY) { float topY = yOffset + Constants.TUBE_DEFAULT_HALFSIZE_Y; float botY = yOffset - Constants.TUBE_DEFAULT_HALFSIZE_Y; if (deltaY > 0) { topY += deltaY; } else { botY += deltaY; } vtkPoints points = new vtkPoints(); points.InsertNextPoint(startX, botY, 0.0); points.InsertNextPoint(startX + size, botY, 0.0); points.InsertNextPoint(startX + size, topY, 0.0); points.InsertNextPoint(startX, topY, 0.0); vtkPolygon rectangle = new vtkPolygon(); rectangle.GetPointIds().SetNumberOfIds(4); rectangle.GetPointIds().SetId(0, 0); rectangle.GetPointIds().SetId(1, 1); rectangle.GetPointIds().SetId(2, 2); rectangle.GetPointIds().SetId(3, 3); vtkCellArray polygons = new vtkCellArray(); polygons.InsertNextCell(rectangle); vtkPolyData polygonPolyData = new vtkPolyData(); polygonPolyData.SetPoints(points); polygonPolyData.SetPolys(polygons); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(polygonPolyData); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetColor(color.r, color.g, color.b); return(actor); }
private void Vertex() { vtkPoints points = vtkPoints.New(); points.InsertNextPoint(0, 0, 0); vtkVertex vertex = vtkVertex.New(); vertex.GetPointIds().SetId(0, 0); vtkCellArray vertices = vtkCellArray.New(); vertices.InsertNextCell(vertex); vtkPolyData polydata = vtkPolyData.New(); polydata.SetPoints(points); polydata.SetVerts(vertices); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(polydata.GetProducerPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetPointSize(10); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); // Add the actor to the scene renderer.AddActor(actor); }
public void WriteVTP(string filePath, List <Vector3d> point_data, List <Vector3> cellPointsList, Dictionary <String, vtkDataArray> scalar_dataArray, List <String> arrayNames) { vtkPoints points = vtkPoints.New(); for (int i = 0; i < point_data.Count(); i++) { points.InsertNextPoint(point_data[i].X, point_data[i].Y, point_data[i].Z); } vtkPolyData polyData = vtkPolyData.New(); polyData.SetPoints(points); vtkCellArray cellArrayOne = vtkCellArray.New(); for (int i = 0; i < cellPointsList.Count(); i++) { vtkTetra tetra = vtkTetra.New(); tetra.GetPointIds().SetId(0, (long)cellPointsList[i][0]); tetra.GetPointIds().SetId(1, (long)cellPointsList[i][1]); tetra.GetPointIds().SetId(2, (long)cellPointsList[i][2]); tetra.GetPointIds().SetId(3, (long)cellPointsList[i][2]); cellArrayOne.InsertNextCell(tetra); } polyData.SetPolys(cellArrayOne); int numberOfScalarData = scalar_dataArray.Count(); for (int i = 0; i < numberOfScalarData; i++) { scalar_dataArray.TryGetValue(arrayNames[i], out vtkDataArray scalars); polyData.GetPointData().AddArray(scalars); } vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New(); // add file ending if it is not existent string suffix = (".vtp"); if (!(filePath.EndsWith(suffix))) { filePath += suffix; } writer.SetFileName(filePath); writer.SetInput(polyData); writer.Write(); // Read and display file for verification that it was written correctly vtkXMLStructuredGridReader reader = vtkXMLStructuredGridReader.New(); if (reader.CanReadFile(filePath) == 0) { //MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK); return; } Console.WriteLine("VTP file was writen and is saved at {0}", filePath); }
private void SelectPointClick(vtkObject sender, vtkObjectEventArgs e) { if (ModelLoaded == true && SelectionMode == true) { int[] clickPos = Inter.GetEventPosition(); vtkPointPicker PointPicker = vtkPointPicker.New(); PointPicker.SetTolerance(0.05); PointPicker.Pick(clickPos[0], clickPos[1], 0, Viewport); vtkPoints points = Faces.GetPoints(); double[] PickPosition = PointPicker.GetPickPosition(); for (int j = 0; j < points.GetNumberOfPoints(); j++) { if (Math.Abs(points.GetPoint(j)[0] - PickPosition[0]) < 1e-6 && Math.Abs(points.GetPoint(j)[1] - PickPosition[1]) < 1e-6 && Math.Abs(points.GetPoint(j)[2] - PickPosition[2]) < 1e-6) { SelectionPoints.InsertNextPoint(PickPosition[0], PickPosition[1], PickPosition[2]); break; } } SelectionGlyph = vtkGlyph3D.New(); SelectionGlyph.SetInput(SelectionPolyData); SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort()); SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort()); SelectionActor.SetMapper(SelectionMapper); // Refresh Viewport Refresh(); } }
public void AddNode(Node node) { int index = m_points.InsertNextPoint(node.Cor.X, node.Cor.Y, node.Cor.Z); m_idsNodesFEM2Vtk.Add(node.NodeId, index); m_idsNodesVtk2FEM.Add(index, node.NodeId); }
static public vtkPolyData ArrayList2PolyData(int type, List <Point3D> centers, double[] trueScale, double[] centroidScale , double[] scale, int clock, int clock_y, int clock_x)//ArrayList转成可视化PolyData { vtkPolyData polydata = new vtkPolyData(); vtkPoints SourcePoints = new vtkPoints(); vtkCellArray SourceVertices = new vtkCellArray(); int[] pid = new int[1]; if (type == 1) { for (int i = 0; i < centers.Count; i++) { //if (!centers[i].isFilter) //{ //pid[0] = SourcePoints.InsertNextPoint(centers[i].tmp_X, centers[i].tmp_Y, centers[i].tmp_Z); pid[0] = SourcePoints.InsertNextPoint(centers[i].tmp_X, centers[i].tmp_Y, 0); SourceVertices.InsertNextCell(1, pid); //} } } polydata.SetPoints(SourcePoints); //把点导入的polydata中去 polydata.SetVerts(SourceVertices); return(polydata); }
private void DrawMesh(CMshTriangleMesherDouble aMesher, vtkUnstructuredGrid anUnstructuredGrid) { vtkPoints points = vtkPoints.New(); for (int i = 0; i < aMesher.mesh().nbNodes(); ++i) { int aNodeId = aMesher.mesh().nodeId(i); var aNode = aMesher.mesh().node(aNodeId); points.InsertNextPoint(aNode.x(), aNode.y(), aNode.z()); } anUnstructuredGrid.SetPoints(points); for (int i = 0; i < aMesher.mesh().nbElements(); ++i) { int anElementId = aMesher.mesh().elementId(i); var anElement = aMesher.mesh().element(anElementId); if (anElement.elementType() == EElementType.ET_TRIANGLE) { var aTriangle = vtkTriangle.New(); aTriangle.GetPointIds().SetId(0, aMesher.mesh().nodeIndex(anElement.nodeId(0))); aTriangle.GetPointIds().SetId(1, aMesher.mesh().nodeIndex(anElement.nodeId(1))); aTriangle.GetPointIds().SetId(2, aMesher.mesh().nodeIndex(anElement.nodeId(2))); anUnstructuredGrid.InsertNextCell(aTriangle.GetCellType(), aTriangle.GetPointIds()); } } }
static public void DrawMesh(CMshBasicMesherDouble aMesher, vtkUnstructuredGrid anUnstructuredGrid) { vtkPoints sPoints = vtkPoints.New(); for (int i = 0; i < aMesher.mesh().nbNodes(); ++i) { int aNodeId = aMesher.mesh().nodeId(i); var aNode = aMesher.mesh().node(aNodeId); sPoints.InsertNextPoint(aNode.x(), aNode.y(), aNode.z()); } anUnstructuredGrid.SetPoints(sPoints); for (int i = 0; i < aMesher.mesh().nbElements(); ++i) { int anElementId = aMesher.mesh().elementId(i); var anElement = aMesher.mesh().element(anElementId); if (anElement.elementType() == EElementType.ET_TETRAHEDRON) { var aTetrahedron = vtkTetra.New(); aTetrahedron.GetPointIds().SetId(0, aMesher.mesh().nodeIndex(anElement.nodeId(0))); aTetrahedron.GetPointIds().SetId(1, aMesher.mesh().nodeIndex(anElement.nodeId(1))); aTetrahedron.GetPointIds().SetId(2, aMesher.mesh().nodeIndex(anElement.nodeId(2))); aTetrahedron.GetPointIds().SetId(3, aMesher.mesh().nodeIndex(anElement.nodeId(3))); anUnstructuredGrid.InsertNextCell(aTetrahedron.GetCellType(), aTetrahedron.GetPointIds()); } } }
private void Hexahedron() { // Setup the coordinates of eight points // (faces must be in counter clockwise order as viewed from the outside) double[,] p = new double[, ] { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 1.0, 0.0, 1.0 }, { 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0 } }; // Create the points vtkPoints points = vtkPoints.New(); for (int i = 0; i < 8; i++) { points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]); } // Create a hexahedron from the points vtkHexahedron hex = vtkHexahedron.New(); for (int i = 0; i < 8; i++) { hex.GetPointIds().SetId(i, i); } // Add the hexahedron to a cell array vtkCellArray hexs = vtkCellArray.New(); hexs.InsertNextCell(hex); // Add the points and hexahedron to an unstructured grid vtkUnstructuredGrid uGrid = vtkUnstructuredGrid.New(); uGrid.SetPoints(points); uGrid.InsertNextCell(hex.GetCellType(), hex.GetPointIds()); // Visualize vtkDataSetMapper mapper = vtkDataSetMapper.New(); mapper.SetInput(uGrid); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetLineWidth(4); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); renderer.ResetCamera(); }
private void TriangleStrip() { vtkPoints points = vtkPoints.New(); points.InsertNextPoint(0, 0, 0); points.InsertNextPoint(0, 1, 0); points.InsertNextPoint(1, 0, 0); points.InsertNextPoint(1.5, 1, 0); vtkTriangleStrip triangleStrip = vtkTriangleStrip.New(); triangleStrip.GetPointIds().SetNumberOfIds(4); triangleStrip.GetPointIds().SetId(0, 0); triangleStrip.GetPointIds().SetId(1, 1); triangleStrip.GetPointIds().SetId(2, 2); triangleStrip.GetPointIds().SetId(3, 3); vtkCellArray cells = vtkCellArray.New(); cells.InsertNextCell(triangleStrip); // Create a polydata to store everything in vtkPolyData polyData = vtkPolyData.New(); // Add the points to the dataset polyData.SetPoints(points); // Add the strip to the dataset polyData.SetStrips(cells); //Create an actor and mapper vtkDataSetMapper mapper = vtkDataSetMapper.New(); mapper.SetInput(polyData); vtkActor actor = vtkActor.New(); actor.GetProperty().SetRepresentationToWireframe(); actor.SetMapper(mapper); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); }
private void Triangle() { // Create a triangle vtkPoints points = vtkPoints.New(); points.InsertNextPoint(1.0, 0.0, 0.0); points.InsertNextPoint(0.0, 0.0, 0.0); points.InsertNextPoint(0.0, 1.0, 0.0); vtkTriangle triangle = vtkTriangle.New(); triangle.GetPointIds().SetId(0, 0); triangle.GetPointIds().SetId(1, 1); triangle.GetPointIds().SetId(2, 2); // Create a cell array to store the triangle in and add the triangle to it vtkCellArray cells = vtkCellArray.New(); cells.InsertNextCell(triangle); // Create a polydata to store everything in vtkPolyData polyData = vtkPolyData.New(); // Add the points to the dataset polyData.SetPoints(points); // Add the quad to the dataset polyData.SetPolys(cells); //Create an actor and mapper vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(polyData); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); }
private void PolyLine() { // Create five points double[,] p = new double[, ] { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 1.0, 2.0 }, { 0.0, 3.0, 3.0 } }; // Create the points vtkPoints points = vtkPoints.New(); for (int i = 0; i < 5; i++) { points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]); } vtkPolyLine polyLine = vtkPolyLine.New(); polyLine.GetPointIds().SetNumberOfIds(5); for (int i = 0; i < 5; i++) { polyLine.GetPointIds().SetId(i, i); } // Create a cell array to store the lines in and add the lines to it vtkCellArray cells = vtkCellArray.New(); cells.InsertNextCell(polyLine); // Create a polydata to store everything in vtkPolyData polyData = vtkPolyData.New(); // Add the points to the dataset polyData.SetPoints(points); // Add the lines to the dataset polyData.SetLines(cells); //Create an actor and mapper vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(polyData); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); }
private void LongLine() { // Create five points double[,] p = new double[, ] { { 0.0, 0.0, 0.0 }, { 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(); for (int i = 0; i < 5; 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(); 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); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(linesPolyData); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetLineWidth(4); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); renderer.ResetCamera(); }
private void DrawPoint() { // Create the geometry of the points (the coordinate) vtkPoints points = vtkPoints.New(); double[,] p = new double[, ] { { 1.0, 2.0, 3.0 }, { 3.0, 1.0, 2.0 }, { 2.0, 3.0, 1.0 }, { 1.0, 3.0, 3.0 } }; // Create topology of the points (a vertex per point) vtkCellArray vertices = vtkCellArray.New(); int nPts = 4; int[] ids = new int[nPts]; for (int i = 0; i < nPts; i++) { ids[i] = (int)points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]); } int size = Marshal.SizeOf(typeof(int)) * nPts; IntPtr pIds = Marshal.AllocHGlobal(size); Marshal.Copy(ids, 0, pIds, nPts); vertices.InsertNextCell(nPts, pIds); Marshal.FreeHGlobal(pIds); // Create a polydata object vtkPolyData pointPoly = vtkPolyData.New(); // Set the points and vertices we created as the geometry and topology of the polydata pointPoly.SetPoints(points); pointPoly.SetVerts(vertices); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputData(pointPoly); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetPointSize(10); vtkRenderWindow renderWindow = myRenderWindowControl.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.3, 0.2, 0.1); renderer.AddActor(actor); }
//vtkPoints points = vtkPoints.New(); //points.InsertNextPoint(0.0, 0.0, 0.0); //points.InsertNextPoint(200.0, 0.0, 0.0); //points.InsertNextPoint(200.0, 200.0, 0.0); //points.InsertNextPoint(0.0, 200.0, 0.0); //points.InsertNextPoint(0.0, 0.0, 0.0); //vtkPolygon polygon = vtkPolygon.New(); //polygon.GetPointIds().SetNumberOfIds(5); //for (int i = 0; i < 5; i++) //{ // polygon.GetPointIds().SetId(i, i); //} public vtkActor2D AddMarkerLine(double[] startCoords, double[] endCoords, Color color) { vtkPoints points = vtkPoints.New(); points.InsertNextPoint(startCoords[0], startCoords[1], 0.0); points.InsertNextPoint(endCoords[0], endCoords[1], 0.0); vtkPolyLine line = vtkPolyLine.New(); line.GetPointIds().SetNumberOfIds(2); for (int i = 0; i < 2; i++) { line.GetPointIds().SetId(i, i); } vtkCellArray cellArray = vtkCellArray.New(); cellArray.InsertNextCell(line); vtkPolyData polyData = vtkPolyData.New(); polyData.SetPoints(points); polyData.SetLines(cellArray); vtkPolyDataMapper2D mapper = vtkPolyDataMapper2D.New(); mapper.SetInputData(polyData); vtkActor2D actor = vtkActor2D.New(); actor.SetMapper(mapper); actor.GetProperty().SetOpacity((float)color.A / 255); actor.GetProperty().SetColor((float)color.R / 255, (float)color.G / 255, (float)color.B / 255); _markerLayerRenderer.AddActor(actor); return(actor); }
public static vtkMatrix4x4 GetTranform(double[] soucePoint1, double[] soucePoint2, double[] soucePoint3, double[] targetPoint1, double[] targetPoint2, double[] targetPoint3) { vtkPoints sourcePoints = new vtkPoints(); sourcePoints.InsertNextPoint(soucePoint1[0], soucePoint1[1], soucePoint1[2]); sourcePoints.InsertNextPoint(soucePoint2[0], soucePoint2[1], soucePoint2[2]); sourcePoints.InsertNextPoint(soucePoint3[0], soucePoint3[1], soucePoint3[2]); vtkPoints targetPoints = new vtkPoints(); targetPoints.InsertNextPoint(targetPoint1[0], targetPoint1[1], targetPoint1[2]); targetPoints.InsertNextPoint(targetPoint2[0], targetPoint2[1], targetPoint2[2]); targetPoints.InsertNextPoint(targetPoint3[0], targetPoint3[1], targetPoint3[2]); vtkLandmarkTransform landmark = new vtkLandmarkTransform(); landmark.SetSourceLandmarks(sourcePoints); landmark.SetTargetLandmarks(targetPoints); landmark.Update(); return(landmark.GetMatrix()); }
private void Quad() { double[,] p = new double[, ] { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 } }; // Create the points vtkPoints points = vtkPoints.New(); for (int i = 0; i < 4; i++) { points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]); } vtkQuad quad = vtkQuad.New(); quad.GetPointIds().SetNumberOfIds(4); for (int i = 0; i < 4; i++) { quad.GetPointIds().SetId(i, i); } // Create a cell array to store the quad in and add the quad to it vtkCellArray cells = vtkCellArray.New(); cells.InsertNextCell(quad); // Create a polydata to store everything in vtkPolyData polyData = vtkPolyData.New(); // Add the points to the dataset polyData.SetPoints(points); // Add the quad to the dataset polyData.SetPolys(cells); //Create an actor and mapper vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(polyData); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); RenderAddActor(actor); }
private void Pyramid() { vtkPoints points = vtkPoints.New(); double[,] p = new double[, ] { { 1.0, 1.0, 1.0 }, { -1.0, 1.0, 1.0 }, { -1.0, -1.0, 1.0 }, { 1.0, -1.0, 1.0 }, { 0.0, 0.0, 0.0 } }; for (int i = 0; i < 5; i++) { points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]); } vtkPyramid pyramid = vtkPyramid.New(); for (int i = 0; i < 5; i++) { pyramid.GetPointIds().SetId(i, i); } vtkCellArray cells = vtkCellArray.New(); cells.InsertNextCell(pyramid); vtkUnstructuredGrid ug = vtkUnstructuredGrid.New(); ug.SetPoints(points); ug.InsertNextCell(pyramid.GetCellType(), pyramid.GetPointIds()); //Create an actor and mapper vtkDataSetMapper mapper = vtkDataSetMapper.New(); mapper.SetInput(ug); vtkActor actor = vtkActor.New(); actor.RotateX(105.0); actor.RotateZ(-36.0); actor.SetMapper(mapper); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); renderer.ResetCamera(); }
public void WriteStructuredGrid(string filePath, List <Vector3d> point_data, Dictionary <String, vtkDataArray> scalar_dataArray, List <String> arrayNames, int numberOfPoints, int[] dimensions) { vtkPoints points = vtkPoints.New(); for (int i = 0; i < numberOfPoints; i++) { points.InsertNextPoint(point_data[i].X, point_data[i].Y, point_data[i].Z); } vtkStructuredGrid structuredGrid = vtkStructuredGrid.New(); structuredGrid.SetDimensions(dimensions[0], dimensions[1], dimensions[2]); structuredGrid.SetPoints(points); int numberOfScalarData = scalar_dataArray.Count(); for (int i = 0; i < numberOfScalarData; i++) { scalar_dataArray.TryGetValue(arrayNames[i], out vtkDataArray scalars); structuredGrid.GetPointData().AddArray(scalars); } // add file ending if it is not existent string suffix = (".vts"); if (!(filePath.EndsWith(suffix))) { filePath += suffix; } // Write file vtkXMLStructuredGridWriter writer = vtkXMLStructuredGridWriter.New(); writer.SetFileName(filePath); writer.SetInput(structuredGrid); writer.Write(); // Read and display file for verification that it was written correctly vtkXMLStructuredGridReader reader = vtkXMLStructuredGridReader.New(); if (reader.CanReadFile(filePath) == 0) { //MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK); return; } Console.WriteLine("VTU file was writen and is saved at {0}", filePath); }
static public void DrawMesh(CMshTetrahedronMesherDouble aMesher, vtkUnstructuredGrid anUnstructuredGrid, vtkRenderer aRenderer) { vtkPoints sPoints = vtkPoints.New(); for (int i = 0; i < aMesher.mesh().nbNodes(); ++i) { int aNodeId = aMesher.mesh().nodeId(i); var aNode = aMesher.mesh().node(aNodeId); sPoints.InsertNextPoint(aNode.x(), aNode.y(), aNode.z()); } anUnstructuredGrid.SetPoints(sPoints); for (int i = 0; i < aMesher.mesh().nbElements(); ++i) { int anElementId = aMesher.mesh().elementId(i); var anElement = aMesher.mesh().element(anElementId); if (anElement.elementType() == EElementType.ET_TETRAHEDRON) { var aTetrahedron = vtkTetra.New(); aTetrahedron.GetPointIds().SetId(0, aMesher.mesh().nodeIndex(anElement.nodeId(0))); aTetrahedron.GetPointIds().SetId(1, aMesher.mesh().nodeIndex(anElement.nodeId(1))); aTetrahedron.GetPointIds().SetId(2, aMesher.mesh().nodeIndex(anElement.nodeId(2))); aTetrahedron.GetPointIds().SetId(3, aMesher.mesh().nodeIndex(anElement.nodeId(3))); anUnstructuredGrid.InsertNextCell(aTetrahedron.GetCellType(), aTetrahedron.GetPointIds()); } } // add actor to the renderer var aMeshActor = vtkActor.New(); aRenderer.AddActor(aMeshActor); var aMeshMapper = vtkDataSetMapper.New(); aMeshMapper.SetInput(anUnstructuredGrid); aMeshActor.SetMapper(aMeshMapper); aMeshActor.GetProperty().SetRepresentationToWireframe(); }
public void ReadPointIntoObject(RenderWindowControl renderWindowControl, List <nvmPointModel> listPointModel) { vtkUnsignedCharArray colors = vtkUnsignedCharArray.New(); colors.SetNumberOfComponents(3); colors.SetName("Colors"); vtkPoints points = vtkPoints.New(); foreach (var point in listPointModel) { colors.InsertNextValue(byte.Parse(point.color.X.ToString(), CultureInfo.InvariantCulture)); colors.InsertNextValue(byte.Parse(point.color.Y.ToString(), CultureInfo.InvariantCulture)); colors.InsertNextValue(byte.Parse(point.color.Z.ToString(), CultureInfo.InvariantCulture)); points.InsertNextPoint( double.Parse(point.position.X.ToString(), CultureInfo.InvariantCulture), double.Parse(point.position.Y.ToString(), CultureInfo.InvariantCulture), double.Parse(point.position.Z.ToString(), CultureInfo.InvariantCulture)); } vtkPolyData polydata = vtkPolyData.New(); polydata.SetPoints(points); polydata.GetPointData().SetScalars(colors); vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New(); glyphFilter.SetInputConnection(polydata.GetProducerPort()); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(glyphFilter.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetPointSize(2); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(actor); renderer.ResetCamera(); }
static public vtkAlgorithmOutput calcRestriction(CompontData data) { //calculation::RayTracing rayTracing(this); Restriction rest = (Restriction)data.restriction; if (rest == null) { return(null); } // 调后台生成光线 TBTfront.Ant ant = new TBTfront.Ant(); List <TBTfront.CompontParam> list_data = new List <TBTfront.CompontParam>(); list_data.Add(rest); list_data.Add(data); List <TBTfront.RayLineCluster> rayline_list = new List <TBTfront.RayLineCluster>(); RayLineCluster rayline_cluster = new RayLineCluster(); CalcOption opt = new CalcOption(); opt.is_ign_non_intersection = true; opt.is_ign_restriction = true; ant.clacLight(list_data, rayline_cluster, rayline_list, opt); rayline_cluster = rayline_list[2]; vtkPoints points = vtkPoints.New(); foreach (var ray in rayline_cluster.ray_cluster) { points.InsertNextPoint(ray.start_point.x, ray.start_point.y, ray.start_point.z); } vtkPolyData polyData = vtkPolyData.New(); polyData.SetPoints(points); vtkDelaunay2D delaunay = vtkDelaunay2D.New(); delaunay.SetInput(polyData); delaunay.Update(); return(delaunay.GetOutputPort()); }
public void VTKLabelGetter(ref vtkPoints pointsrc, ref vtkStringArray strArr, ref vtkCellArray cellArr, FormParas paras, WorkSpaceClass WorkSpaceInstance) { Models.HeatDoublers hdlist = WorkSpaceInstance.HeatDoublerInstances; //MessageBox.Show(hdlist.listSize.ToString()); strArr.SetNumberOfValues(hdlist.listSize); strArr.SetName("111"); for (int i = 0; i < hdlist.listSize; i++) { pointsrc.InsertNextPoint(hdlist.list[i].X, 0, -hdlist.list[i].Y); strArr.SetValue(i, hdlist.list[i].Name); //MessageBox.Show(hdlist.list[i].Name); cellArr.InsertNextCell(1); cellArr.InsertCellPoint(i); } }