// 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(); }
public void ExtractFeatures() { Filter = vtkDataSetSurfaceFilter.New(); Filter.SetInput(Grid); Filter.Update(); Faces = Filter.GetOutput(); vtkFeatureEdges FeatureEdges = vtkFeatureEdges.New(); FeatureEdges.SetInput(Filter.GetOutput()); FeatureEdges.Update(); FeatureEdges.BoundaryEdgesOn(); FeatureEdges.FeatureEdgesOn(); FeatureEdges.ManifoldEdgesOn(); FeatureEdges.NonManifoldEdgesOn(); // Change Edge color FeatureEdges.SetColoring(0); // Update FeatureEdges.Update(); vtkPolyDataMapper EdgeMapper = vtkPolyDataMapper.New(); EdgeMapper.SetInput(FeatureEdges.GetOutput()); EdgeMapper.ScalarVisibilityOff(); Edges.SetMapper(EdgeMapper); Edges.GetProperty().SetEdgeColor(0, 0, 0); Edges.GetProperty().SetColor(0.0, 0.0, 0.0); Edges.GetProperty().SetLineWidth((float)1.0); // Set default edge thickness Edges.SetVisibility(0); }
private void renderScene() { vtkCamera camera; if (toShow != null) { this.geometryPoints(); vtkPolyData polydata = vtkPolyData.New(); polydata.SetPoints(pontosVTK); vtkDelaunay2D del = vtkDelaunay2D.New(); del.AddInput(polydata); vtkPolyDataMapper mapMesh = vtkPolyDataMapper.New(); mapMesh.SetInput(del.GetOutput()); vtkActor meshActor = vtkActor.New(); meshActor.SetMapper(mapMesh); meshActor.GetProperty().SetColor(0.5d, 0.5d, 0d); windowVTK.AddRenderer(rendererVTK); rendererVTK.AddActor(meshActor); windowVTK.Render(); rendererVTK.Render(); meshActor.Render(rendererVTK, mapMesh); camera = rendererVTK.GetActiveCamera(); camera.Zoom(1.0d); rendererVTK.ResetCamera(); } }
public void ReplacePolyData(vtkPolyData polyData) { this.PolyData = polyData; _polyDataMapper.SetInput(polyData); _polyDataMapper.Modified(); }
public IVtkPreprocess SetMapper() { polyDataMapper = vtkPolyDataMapper.New(); polyDataMapper.SetInput(reader.GetOutput()); polyDataMapper.Update(); return(this); }
static private void init() { vtkSTLReader rdr = vtkSTLReader.New(); rdr.SetFileName("BODY-EXTRUDEUR-WADE.stl"); // Créer une géométrie sphérique /*vtkSphereSource sphere = vtkSphereSource.New(); * sphere.SetRadius(1.0); * sphere.SetThetaResolution(18); * sphere.SetPhiResolution(18);*/ // Transforme la géométrie en primitives graphiques (OpenGL dans notre cas) vtkPolyDataMapper map = vtkPolyDataMapper.New(); map.SetInput(rdr.GetOutput()); // L'acteur représente l'entitée géométrique. // Il permet de définir sa position, son orientation, sa couleur, etc. vtkActor aSphere = new vtkActor(); aSphere.SetMapper(map); aSphere.GetProperty().SetColor(0.8, 0.8, 0.8); // color blue // Nous créons un renderer qui va faire le rendu de notre entitée. vtkRenderer ren1 = vtkRenderer.New(); ren1.AddActor(aSphere); ren1.SetBackground(1, 1, 1); // background color white // Nous créons une fenêtre de rendu vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); renWin.SetSize(300, 300); // Nous créons un interactor qui permet de bouger la caméra. vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); // Nous lançons le rendu et l'interaction renWin.Render(); iren.Start(); ////// CLEANUP /////// rdr.Dispose(); map.Dispose(); aSphere.Dispose(); ren1.Dispose(); renWin.Dispose(); iren.Dispose(); }
public XmlPolyDataPackage(string vtpFile, vtkRenderer renderer) { //Console.WriteLine(string.Format("VTP文件 = {0}", vtpFile)); if (File.Exists(vtpFile)) { if (vtpFile.EndsWith(".vtp")) { //Console.WriteLine(string.Format("VTP文件 = {0}已存在", vtpFile)); reader = vtkXMLPolyDataReader.New(); reader.SetFileName(vtpFile); reader.Update(); PolyData = reader.GetOutput(); } else if (vtpFile.EndsWith(".stl")) { PolyData = VTKUtil.ReadSTLPolyData(vtpFile); } vtkCamera camera = vtkCamera.New(); var sortPolydata = new vtkDepthSortPolyData(); sortPolydata.SetInput(PolyData); sortPolydata.SetCamera(camera); sortPolydata.SetDirectionToFrontToBack(); sortPolydata.SetVector(1, 1, 1); sortPolydata.SetSortScalars(1); sortPolydata.Update(); _polyDataMapper = vtkPolyDataMapper.New(); _polyDataMapper.ScalarVisibilityOff(); _polyDataMapper.SetInput(sortPolydata.GetOutput()); _polyDataMapper.Update(); actor = vtkActor.New(); actor.SetMapper(_polyDataMapper); actor.GetProperty().SetColor(1, 1, 1); //marchingCubeActor.GetProperty().BackfaceCullingOn(); //marchingCubeActor.GetProperty().FrontfaceCullingOn(); //marchingCubeActor.GetProperty().BackfaceCullingOff(); // now, tell the renderer our actors renderer.AddActor(actor); this.renderer = renderer; } else { throw new Exception(string.Format("VTP文件 = {0}不存在。", vtpFile)); } //正面观(); }
/// <summary> /// 进行三维结构的转换 /// </summary> /// <param name="degree"></param> /// <param name="polyData"></param> /// <param name="info"></param> /// <returns></returns> private static vtkActor FormActor3D(float degree, vtkPolyData polyData, ModelingBaseInfo info) {//旋转拉伸一个截面, 先绕Z拉伸后旋转一定攻角,再平移 vtkActor actor = vtkActor.New(); vtkPolyData polydata = Extrude3DSection(degree, polyData, info); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(polyData); actor.SetMapper(mapper); return(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); }
/// <summary> /// Crée le nécessaire pour l'affichage du volume /// </summary> private void createVolumeObjects() { _volumeMapper = vtkPolyDataMapper.New(); _volumeMapper.SetInput(_stlReader.GetOutput()); _volumeActor = vtkActor.New(); //couleur du volume double[] rgb = colorToRGB(VolumeColor); _volumeActor.GetProperty().SetColor(rgb[0], rgb[1], rgb[2]); _volumeActor.SetMapper(_volumeMapper); }
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(); }
/// <summary> /// Crée un acteur pour l'objet fourni et l'ajoute au renderer /// </summary> /// <param name="polydata"></param> private void addActor(vtkPolyData polydata) { vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(polydata); vtkActor act = vtkActor.New(); act.SetMapper(mapper); _renderer.AddActor(act); }
//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); }
/// <summary> /// Crée le nécessaire pour l'affichage des arêtes /// </summary> private void createEdgeObjects() { _edgeExtractor = vtkExtractEdges.New(); _edgeExtractor.SetInput(_stlReader.GetOutput()); _edgeMapper = vtkPolyDataMapper.New(); _edgeMapper.SetInput(_edgeExtractor.GetOutput()); _edgeActor = vtkActor.New(); double[] rgb = colorToRGB(EdgeColor); //couleurs des aretes _edgeActor.GetProperty().SetColor(rgb[0], rgb[1], rgb[2]); _edgeActor.SetMapper(_edgeMapper); }
private void Point() { // 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 } }; // Create topology of the points (a vertex per point) vtkCellArray vertices = vtkCellArray.New(); int nPts = 3; int[] ids = new int[nPts]; for (int i = 0; i < nPts; i++) { ids[i] = 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.SetInput(pointPoly); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetPointSize(20); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.3, 0.2, 0.1); renderer.AddActor(actor); }
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 Polygon() { // Setup four points vtkPoints points = vtkPoints.New(); double c = Math.Cos(Math.PI / 6); // helper variable points.InsertNextPoint(0.0, -1.0, 0.0); points.InsertNextPoint(c, -0.5, 0.0); points.InsertNextPoint(c, 0.5, 0.0); points.InsertNextPoint(0.0, 1.0, 0.0); points.InsertNextPoint(-c, 0.5, 0.0); points.InsertNextPoint(-c, -0.5, 0.0); // Create the polygon vtkPolygon polygon = vtkPolygon.New(); polygon.GetPointIds().SetNumberOfIds(6); //make a six-sided figure polygon.GetPointIds().SetId(0, 0); polygon.GetPointIds().SetId(1, 1); polygon.GetPointIds().SetId(2, 2); polygon.GetPointIds().SetId(3, 3); polygon.GetPointIds().SetId(4, 4); polygon.GetPointIds().SetId(5, 5); // Add the polygon to a list of polygons vtkCellArray polygons = vtkCellArray.New(); polygons.InsertNextCell(polygon); // Create a PolyData vtkPolyData polygonPolyData = vtkPolyData.New(); polygonPolyData.SetPoints(points); polygonPolyData.SetPolys(polygons); // Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(polygonPolyData); 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); renderer.ResetCamera(); }
private void Frustum() { // Create a frustum. // in this example we need the renderer first to retrieve the active camera // in order to get camera's frustum planes vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); vtkCamera camera = renderer.GetActiveCamera(); double[] aspect = renderer.GetAspect(); double aspectRatio = aspect[0] / aspect[1]; // allocate memory for 24 unmanaged doubles int size = Marshal.SizeOf(typeof(double)) * 24; IntPtr ptr = Marshal.AllocHGlobal(size); camera.GetFrustumPlanes(aspectRatio, ptr); // in case we would need this values directly we could copy // the unmanaged double array to a managed array like so: // double[] planesArray = new double[24]; // Marshal.Copy(ptr, planesArray, 0, 24); // but fortunately we can forward the IntPtr directly to the function // SetFrustumPlanes() vtkPlanes planes = vtkPlanes.New(); planes.SetFrustumPlanes(ptr); // free unmanaged memory Marshal.FreeHGlobal(ptr); vtkFrustumSource frustumSource = vtkFrustumSource.New(); frustumSource.SetPlanes(planes); frustumSource.Update(); vtkPolyData frustum = frustumSource.GetOutput(); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(frustum); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); renderer.SetBackground(.2, .1, .3); // Background color dark purple renderer.AddActor(actor); renderer.ResetCamera(); }
public LinePackage(RendererPackage rendererPackage) { line = vtkLineSource.New(); line.SetResolution(100); vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New(); sphereMapper.SetInput(line.GetOutput()); _lineActor = vtkActor.New(); _lineActor.SetMapper(sphereMapper); rendererPackage.Renderer.AddActor(_lineActor); this._rendererPackage = rendererPackage; }
public void BasicVTKBuilderWithoutRunning(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys, ref vtkFloatArray scalars, ref vtkLookupTable Luk) { int pointsNum = 0; TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras); vtkPolyData profile = vtkPolyData.New(); profile.SetPoints(points); profile.SetPolys(polys); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); if (paras.RotateAngle == 0) { profile.GetCellData().SetScalars(scalars); mapper.SetInput(profile); } else { vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New(); profile.Update(); profile.GetCellData().SetScalars(scalars); //profile.GetPointData().SetScalars(scalars); refilter.SetInput(profile); refilter.SetResolution(50); refilter.SetAngle(paras.RotateAngle); refilter.SetTranslation(0); refilter.SetDeltaRadius(0); mapper.SetInputConnection(refilter.GetOutputPort()); } mapper.SetScalarRange(0, 5); mapper.SetLookupTable(Luk); actor.SetMapper(mapper); Luk.SetNumberOfTableValues(7); Luk.SetTableValue(0, 0, 1, 0, 1); // Luk.SetTableValue(1, 0, 0, 0.8, 1); //inner surface Luk.SetTableValue(2, 0, 1, 0, 1); // Luk.SetTableValue(3, 0, 0, 1, 1); Luk.SetTableValue(4, 0, 0, 0.8, 1); //insider Luk.SetTableValue(5, 0, 0.8, 0, 1); //outer surface Luk.Build(); }
public void SetPosition(double[] xyz1, double[] xyz2) { vtkPoints points = vtkPoints.New(); points.InsertPoint(0, xyz1[0], xyz1[1], xyz1[2]); points.InsertPoint(1, xyz2[0], xyz2[1], xyz2[2]); vtkCellArray lines = vtkCellArray.New(); lines.InsertNextCell(2); lines.InsertCellPoint(0); lines.InsertCellPoint(1); vtkPolyData profileData = new vtkPolyData(); profileData.SetPoints(points); profileData.SetLines(lines); profileData.SetVerts(lines); profileData.Update(); vtkCleanPolyData cleanFilter = new vtkCleanPolyData(); cleanFilter.SetInput(profileData); cleanFilter.Update(); vtkTubeFilter profileTubes = new vtkTubeFilter(); profileTubes.SetNumberOfSides(10); profileTubes.SetInput(cleanFilter.GetOutput()); //profileTubes.SetVaryRadiusToVaryRadiusByVector(); profileTubes.SetRadius(1); profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors"); //vtkPolyDataMapper profileMapper = new vtkPolyDataMapper(); //profileMapper.SetInputConnection(profileTubes.GetOutputPort()); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(profileTubes.GetOutput()); centerLineActor.SetMapper(mapper); centerLineActor.GetProperty().SetOpacity(0.5); }
public static void ShowPolydata(string airwayPath) { if (!File.Exists(airwayPath)) { MessageBox.Show("文件不存在!"); return; } vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.SetSize(600, 600); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); renWin.SetInteractor(iren); vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(interactorStyle); vtkRenderer renderer = vtkRenderer.New(); renderer.GradientBackgroundOn(); renderer.SetBackground(0, 0, 0); renderer.SetBackground2(0, 0, 1); renWin.AddRenderer(renderer); vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader(); reader.SetFileName(airwayPath); reader.Update(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.ScalarVisibilityOff(); mapper.SetInput(reader.GetOutput()); reader.Dispose(); vtkActor actor = new vtkActor(); actor.SetMapper(mapper); renderer.AddActor(actor); renWin.Render(); }
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); }
public XmlPolyDataPackage(vtkPolyData polyData, vtkRenderer renderer) { this.PolyData = polyData; _polyDataMapper = vtkPolyDataMapper.New(); _polyDataMapper.ScalarVisibilityOff(); _polyDataMapper.SetInput(PolyData); _polyDataMapper.Update(); actor = vtkActor.New(); actor.SetMapper(_polyDataMapper); //marchingCubeActor.GetProperty().BackfaceCullingOn(); //marchingCubeActor.GetProperty().FrontfaceCullingOn(); //marchingCubeActor.GetProperty().BackfaceCullingOff(); // now, tell the renderer our actors renderer.AddActor(actor); this.renderer = renderer; }
void ConstructActor(vtkPolyData polydata) { //vtkUnsignedCharArray colors = vtkUnsignedCharArray.New(); //colors.SetNumberOfComponents(3); //Console.WriteLine("pointnum:{0},linenum:{1},numPieces:{2},numstrips:{3}", polydata.GetNumberOfPoints(),polydata .GetNumberOfLines() // ,polydata .GetNumberOfPieces(),polydata .GetNumberOfPolys(),polydata .GetNumberOfStrips()); //int cellnum = polydata.GetNumberOfCells(); //colors.SetNumberOfTuples(cellnum); //for (int i = 0; i < cellnum; ++i) // colors.SetTuple3(i, m_defaultColor[0], m_defaultColor[1], m_defaultColor[2]); //polydata.GetCellData().SetScalars(colors); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); // mapper.SetScalarModeToUseCellData(); mapper.SetInput(polydata); // float[] color = { 23f, 23f, 100f }; m_defaultColor = ModelUtils.GetRandomColor01();//获取随机颜色 SetColor(m_defaultColor); this.SetMapper(mapper); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVmergeFilter(String [] argv) { //Prefix Content is: "" // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); ren2 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); renWin.AddRenderer((vtkRenderer)ren2); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // create pipeline[] //[] pl3d = new vtkPLOT3DReader(); pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); pl3d.SetScalarFunctionNumber((int)110); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); probeLine = new vtkLineSource(); probeLine.SetPoint1((double)1,(double)1,(double)29); probeLine.SetPoint2((double)16.5,(double)5,(double)31.7693); probeLine.SetResolution((int)500); probe = new vtkProbeFilter(); probe.SetInputConnection((vtkAlgorithmOutput)probeLine.GetOutputPort()); probe.SetSource((vtkDataObject)pl3d.GetOutput()); probeTube = new vtkTubeFilter(); probeTube.SetInput((vtkDataObject)probe.GetPolyDataOutput()); probeTube.SetNumberOfSides((int)5); probeTube.SetRadius((double).05); probeMapper = vtkPolyDataMapper.New(); probeMapper.SetInputConnection((vtkAlgorithmOutput)probeTube.GetOutputPort()); probeMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]); probeActor = new vtkActor(); probeActor.SetMapper((vtkMapper)probeMapper); displayLine = new vtkLineSource(); displayLine.SetPoint1((double)0,(double)0,(double)0); displayLine.SetPoint2((double)1,(double)0,(double)0); displayLine.SetResolution((int)probeLine.GetResolution()); displayMerge = new vtkMergeFilter(); displayMerge.SetGeometry((vtkDataSet)displayLine.GetOutput()); displayMerge.SetScalars((vtkDataSet)probe.GetPolyDataOutput()); displayWarp = new vtkWarpScalar(); displayWarp.SetInput((vtkDataObject)displayMerge.GetPolyDataOutput()); displayWarp.SetNormal((double)0,(double)1,(double)0); displayWarp.SetScaleFactor((double).000001); displayMapper = vtkPolyDataMapper.New(); displayMapper.SetInput((vtkPolyData)displayWarp.GetPolyDataOutput()); displayMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]); displayActor = new vtkActor(); displayActor.SetMapper((vtkMapper)displayMapper); outline = new vtkStructuredGridOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)probeActor); ren1.SetBackground((double)1,(double)1,(double)1); ren1.SetViewport((double)0,(double).25,(double)1,(double)1); ren2.AddActor((vtkProp)displayActor); ren2.SetBackground((double)0,(double)0,(double)0); ren2.SetViewport((double)0,(double)0,(double)1,(double).25); renWin.SetSize((int)300,(int)300); ren1.ResetCamera(); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297,(double)50); cam1.SetFocalPoint((double)8.88908,(double)0.595038,(double)29.3342); cam1.SetPosition((double)9.9,(double)-26,(double)41); cam1.SetViewUp((double)0.060772,(double)-0.319905,(double)0.945498); ren2.ResetCamera(); cam2 = ren2.GetActiveCamera(); cam2.ParallelProjectionOn(); cam2.SetParallelScale((double).15); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
static public vtkProp3D genRayActor(List <RayLineCluster> data) { vtkPoints points = vtkPoints.New(); vtkCellArray pLineCell = vtkCellArray.New(); vtkLine p1 = vtkLine.New(); int cout = 0; System.Windows.Forms.MessageBox.Show("cluster.start_radius:" + data.Count.ToString()); for (int i = 0; i < data.Count; i++) { RayLineCluster cluster = data[i]; if (i != data.Count - 1) { // 第一个的起点连第二次的起点 List <RayLine> rays_start = cluster.ray_cluster; List <RayLine> rays_end = data[i + 1].ray_cluster; for (int j = 0; j < rays_start.Count; j++) { points.InsertNextPoint(rays_start[j].start_point.x, rays_start[j].start_point.y, rays_start[j].start_point.z); points.InsertNextPoint(rays_end[j].start_point.x, rays_end[j].start_point.y, rays_end[j].start_point.z); p1.GetPointIds().SetId(0, cout++); p1.GetPointIds().SetId(1, cout++); pLineCell.InsertNextCell(p1); } } else { foreach (var line in cluster.ray_cluster) { points.InsertNextPoint(line.start_point.x, line.start_point.y, line.start_point.z); points.InsertNextPoint( line.start_point.x + 0.5 * line.normal_line.x, line.start_point.y + 0.5 * line.normal_line.y, line.start_point.z + 0.5 * line.normal_line.z); p1.GetPointIds().SetId(0, cout++); p1.GetPointIds().SetId(1, cout++); pLineCell.InsertNextCell(p1); } } } vtkPolyData pointsData = vtkPolyData.New(); pointsData.SetPoints(points); //获得网格模型中的几何数据:点集 pointsData.SetLines(pLineCell); vtkPolyDataMapper pointMapper = vtkPolyDataMapper.New(); pointMapper.SetInput(pointsData); pointMapper.Update(); vtkActor actor = vtkActor.New(); actor.SetMapper(pointMapper); actor.GetProperty().SetColor(1, 0, 0); return(actor); }
private void ColoredLines() { // Create three points. Join (Origin and P0) with a red line and // (Origin and P1) with a green line double[] origin = new double[] { 0.0, 0.0, 0.0 }; double[] p0 = new double[] { 1.0, 0.0, 0.0 }; double[] p1 = new double[] { 0.0, 1.0, 0.0 }; // Create a vtkPoints object and store the points in it vtkPoints pts = vtkPoints.New(); pts.InsertNextPoint(origin[0], origin[1], origin[2]); pts.InsertNextPoint(p0[0], p0[1], p0[2]); pts.InsertNextPoint(p1[0], p1[1], p1[2]); // Setup two colors - one for each line byte[] red = new byte[] { 255, 0, 0 }; byte[] green = new byte[] { 0, 255, 0 }; // Setup the colors array vtkUnsignedCharArray colors = vtkUnsignedCharArray.New(); colors.SetNumberOfComponents(3); colors.SetName("Colors"); // Add the colors we created to the colors array colors.InsertNextValue(red[0]); colors.InsertNextValue(red[1]); colors.InsertNextValue(red[2]); colors.InsertNextValue(green[0]); colors.InsertNextValue(green[1]); colors.InsertNextValue(green[2]); // Create the first line (between Origin and P0) vtkLine line0 = vtkLine.New(); line0.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints line0.GetPointIds().SetId(1, 1); //the second 1 is the index of P0 in the vtkPoints // Create the second line (between Origin and P1) vtkLine line1 = vtkLine.New(); line1.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints line1.GetPointIds().SetId(1, 2); //2 is the index of P1 in the vtkPoints // Create a cell array to store the lines in and add the lines to it vtkCellArray lines = vtkCellArray.New(); lines.InsertNextCell(line0); lines.InsertNextCell(line1); // Create a polydata to store everything in vtkPolyData linesPolyData = vtkPolyData.New(); // Add the points to the dataset linesPolyData.SetPoints(pts); // Add the lines to the dataset linesPolyData.SetLines(lines); // Color the lines - associate the first component (red) of the // colors array with the first component of the cell array (line 0) // and the second component (green) of the colors array with the // second component of the cell array (line 1) linesPolyData.GetCellData().SetScalars(colors); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(linesPolyData); // create an actor vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); RenderAddActor(actor); }
private void CapClip(string filePath) { // PolyData to process vtkPolyData polyData; if (filePath != null) { vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); reader.Update(); polyData = reader.GetOutput(); } else { // Create a sphere vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.SetThetaResolution(20); sphereSource.SetPhiResolution(11); vtkPlane plane = vtkPlane.New(); plane.SetOrigin(0, 0, 0); plane.SetNormal(1.0, -1.0, -1.0); vtkClipPolyData clipper = vtkClipPolyData.New(); clipper.SetInputConnection(sphereSource.GetOutputPort()); clipper.SetClipFunction(plane); clipper.SetValue(0); clipper.Update(); polyData = clipper.GetOutput(); } vtkDataSetMapper clipMapper = vtkDataSetMapper.New(); #if VTK_MAJOR_VERSION_5 clipMapper.SetInput(polyData); #else clipMapper.SetInputData(polyData); #endif vtkActor clipActor = vtkActor.New(); clipActor.SetMapper(clipMapper); clipActor.GetProperty().SetColor(1.0000, 0.3882, 0.2784); clipActor.GetProperty().SetInterpolationToFlat(); // Now extract feature edges vtkFeatureEdges boundaryEdges = vtkFeatureEdges.New(); #if VTK_MAJOR_VERSION_5 boundaryEdges.SetInput(polyData); #else boundaryEdges.SetInputData(polyData); #endif boundaryEdges.BoundaryEdgesOn(); boundaryEdges.FeatureEdgesOff(); boundaryEdges.NonManifoldEdgesOff(); boundaryEdges.ManifoldEdgesOff(); vtkStripper boundaryStrips = vtkStripper.New(); boundaryStrips.SetInputConnection(boundaryEdges.GetOutputPort()); boundaryStrips.Update(); // Change the polylines into polygons vtkPolyData boundaryPoly = vtkPolyData.New(); boundaryPoly.SetPoints(boundaryStrips.GetOutput().GetPoints()); boundaryPoly.SetPolys(boundaryStrips.GetOutput().GetLines()); vtkPolyDataMapper boundaryMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 boundaryMapper.SetInput(boundaryPoly); #else boundaryMapper.SetInputData(boundaryPoly); #endif vtkActor boundaryActor = vtkActor.New(); boundaryActor.SetMapper(boundaryMapper); boundaryActor.GetProperty().SetColor(0.8900, 0.8100, 0.3400); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.2, .3, .4); // add our actor to the renderer renderer.AddActor(clipActor); renderer.AddActor(boundaryActor); // Generate an interesting view // renderer.ResetCamera(); renderer.GetActiveCamera().Azimuth(30); renderer.GetActiveCamera().Elevation(30); renderer.GetActiveCamera().Dolly(1.2); renderer.ResetCameraClippingRange(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVfieldToPolyData(String [] argv) { //Prefix Content is: "" // This example demonstrates the reading of a field and conversion to PolyData[] // The output should be the same as polyEx.tcl.[] // get the interactor ui[] // Create a reader and write out the field[] reader = new vtkPolyDataReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/polyEx.vtk"); ds2do = new vtkDataSetToDataObjectFilter(); ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); try { channel = new StreamWriter("PolyField.vtk"); tryCatchError = "NOERROR"; } catch(Exception) {tryCatchError = "ERROR";} if(tryCatchError.Equals("NOERROR")) { channel.Close(); writer = new vtkDataObjectWriter(); writer.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort()); writer.SetFileName((string)"PolyField.vtk"); writer.Write(); // create pipeline[] //[] dor = new vtkDataObjectReader(); dor.SetFileName((string)"PolyField.vtk"); do2ds = new vtkDataObjectToDataSetFilter(); do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort()); do2ds.SetDataSetTypeToPolyData(); do2ds.SetPointComponent((int)0,(string)"Points",(int)0); do2ds.SetPointComponent((int)1,(string)"Points",(int)1); do2ds.SetPointComponent((int)2,(string)"Points",(int)2); do2ds.SetPolysComponent((string)"Polys",(int)0); fd2ad = new vtkFieldDataToAttributeDataFilter(); fd2ad.SetInput((vtkDataObject)do2ds.GetPolyDataOutput()); fd2ad.SetInputFieldToDataObjectField(); fd2ad.SetOutputAttributeDataToPointData(); fd2ad.SetScalarComponent((int)0,(string)"my_scalars",(int)0); mapper = vtkPolyDataMapper.New(); mapper.SetInput((vtkPolyData)fd2ad.GetPolyDataOutput()); mapper.SetScalarRange((double)((vtkDataSet)fd2ad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)fd2ad.GetOutput()).GetScalarRange()[1]); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); // Create the RenderWindow, Renderer and both Actors[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); ren1.AddActor((vtkProp)actor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)300,(int)300); ren1.ResetCamera(); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double).348,(double)17.43); cam1.SetPosition((double)2.92,(double)2.62,(double)-0.836); cam1.SetViewUp((double)-0.436,(double)-0.067,(double)-0.897); cam1.Azimuth((double)90); // render the image[] //[] renWin.Render(); File.Delete("PolyField.vtk"); } // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
//Parameters for building a model private void BasicVTKBuilder(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys, ref vtkFloatArray scalars, ref vtkLookupTable Luk, ref vtkActor2D actor2D) { int pointsNum = 0; TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras); vtkPolyData profile = vtkPolyData.New(); profile.SetPoints(points); profile.SetPolys(polys); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); if (paras.RotateAngle == 0) { profile.GetCellData().SetScalars(scalars); mapper.SetInput(profile); } else { vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New(); profile.Update(); profile.GetCellData().SetScalars(scalars); //profile.GetPointData().SetScalars(scalars); refilter.SetInput(profile); refilter.SetResolution(50); refilter.SetAngle(paras.RotateAngle); refilter.SetTranslation(0); refilter.SetDeltaRadius(0); mapper.SetInputConnection(refilter.GetOutputPort()); } mapper.SetScalarRange(TowerModelInstance.GetColorGenColorTableMinvalue(), TowerModelInstance.GetColorGenColorTableMaxValue()); actor.SetMapper(mapper); // This text property is for scalarBar vtkTextProperty textProperty = vtkTextProperty.New(); //textProperty.SetFontFamilyToCourier(); //textProperty.SetColor(1.0, 1.0, 0.5); textProperty.SetFontSize(10); vtkScalarBarActor scalarBar = vtkScalarBarActor.New(); scalarBar.SetLookupTable(mapper.GetLookupTable()); scalarBar.SetTitle("Color Table"); scalarBar.SetNumberOfLabels(TowerModelInstance.GetColorGenColorTableSize()); scalarBar.SetTitleTextProperty(textProperty); scalarBar.SetLabelTextProperty(textProperty); scalarBar.SetWidth(0.07); scalarBar.SetHeight(0.6); //scalarBar.SetDrawFrame(1); vtkLookupTable hueLut = vtkLookupTable.New(); hueLut.SetTableRange(TowerModelInstance.GetColorGenColorTableMinvalue(), TowerModelInstance.GetColorGenColorTableMaxValue()); hueLut.SetHueRange(0.667, 0); hueLut.SetSaturationRange(1, 1); hueLut.SetValueRange(1, 1); hueLut.SetNumberOfTableValues(TowerModelInstance.GetColorGenColorTableSize()); hueLut.Build(); mapper.SetLookupTable(hueLut); scalarBar.SetLookupTable(hueLut); // The actor links the data pipeline to the rendering subsystem actor2D = scalarBar; //actor.GetProperty().SetColor(0.388, 0.388, 0.388); }
static void Main(string[] args) { // // Next we create an instance of vtkConeSource and set some of its // properties. The instance of vtkConeSource "cone" is part of a visualization // pipeline (it is a source process object); it produces data (output type is // vtkPolyData) which other filters may process. // vtkConeSource cone = new vtkConeSource(); cone.SetHeight( 3.0f ); cone.SetRadius( 1.0f ); cone.SetResolution( 10 ); // // In this example we terminate the pipeline with a mapper process object. // (Intermediate filters such as vtkShrinkPolyData could be inserted in // between the source and the mapper.) We create an instance of // vtkPolyDataMapper to map the polygonal data into graphics primitives. We // connect the output of the cone souece to the input of this mapper. // vtkPolyDataMapper coneMapper = new vtkPolyDataMapper(); coneMapper.SetInput( cone.GetOutput() ); // // Create an actor to represent the cone. The actor orchestrates rendering of // the mapper's graphics primitives. An actor also refers to properties via a // vtkProperty instance, and includes an internal transformation matrix. We // set this actor's mapper to be coneMapper which we created above. // vtkActor coneActor = new vtkActor(); coneActor.SetMapper( coneMapper ); // // Create the Renderer and assign actors to it. A renderer is like a // viewport. It is part or all of a window on the screen and it is // responsible for drawing the actors it has. We also set the background // color here // vtkRenderer ren1 = new vtkRenderer(); ren1.AddActor( coneActor ); ren1.SetBackground( 0.1f, 0.2f, 0.4f ); // // Finally we create the render window which will show up on the screen // We put our renderer into the render window using AddRenderer. We also // set the size to be 300 pixels by 300 // vtkRenderWindow renWin = new vtkRenderWindow(); renWin.AddRenderer( ren1 ); renWin.SetSize( 300, 300 ); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(style); vtkBoxWidget boxWidget = new vtkBoxWidget(); boxWidget.SetInteractor(iren); boxWidget.SetPlaceFactor(1.25f); boxWidget.SetProp3D(coneActor); boxWidget.PlaceWidget(); boxWidget.AddObserver((uint) EventIds.InteractionEvent, new vtkDotNetCallback(myCallback)); boxWidget.On(); iren.Initialize(); iren.Start(); vtkWin32OpenGLRenderWindow win32win = vtkWin32OpenGLRenderWindow.SafeDownCast(renWin); if ( null != win32win ) win32win.Clean(); }
//切片模式_绘制 private void DrawMode_Slice() { int[] xyz = m_ImageData.GetDimensions(); double[] sp = m_ImageData.GetSpacing(); double[] pos = new double[] { m_XPos, m_YPos, m_ZPos }; #region -------------------XOY切片(垂直Z轴)------------------- m_ImageResliceXOY = vtkImageReslice.New(); m_ImageResliceXOY.SetInput(m_ImageData); m_ImageResliceXOY.SetResliceAxesDirectionCosines( 1, 0, 0, 0, 1, 0, 0, 0, 1 ); m_ImageResliceXOY.InterpolateOn(); m_ImageResliceXOY.SetInterpolationModeToNearestNeighbor(); m_ImageResliceXOY.SetResliceAxesOrigin(pos[0], pos[1], pos[2]); m_ImageResliceXOY.SetOutputDimensionality(2); m_ImageResliceXOY.Update(); m_TextureXOY = vtkTexture.New(); m_TextureXOY.InterpolateOff(); m_TextureXOY.SetInput(m_ImageResliceXOY.GetOutput()); m_TextureXOY.SetLookupTable(m_LookupTable); m_TextureXOY.MapColorScalarsThroughLookupTableOn(); //---------------------set plane position---------- m_PlaneSourceXOY = vtkPlaneSource.New(); m_PlaneSourceXOY.SetXResolution(xyz[0]); m_PlaneSourceXOY.SetYResolution(xyz[1]); m_PlaneSourceXOY.SetOrigin(0, 0, 0); m_PlaneSourceXOY.SetPoint1((xyz[0] - 1) * sp[0], 0, 0); m_PlaneSourceXOY.SetPoint2(0, (xyz[1] - 1) * sp[1], 0); m_PlaneSourceXOY.Push(pos[2]); //---------------------pipeline-------------------- m_PlaneMapperXOY = vtkPolyDataMapper.New(); m_PlaneMapperXOY.SetInput(m_PlaneSourceXOY.GetOutput()); m_ActorXOY = vtkActor.New(); m_ActorXOY.SetMapper(m_PlaneMapperXOY); m_ActorXOY.SetTexture(m_TextureXOY); #endregion #region -------------------XOZ切片(垂直Y轴)------------------- m_ImageResliceXOZ = vtkImageReslice.New(); m_ImageResliceXOZ.SetInput(m_ImageData); m_ImageResliceXOZ.SetResliceAxesDirectionCosines( 1, 0, 0, 0, 0, -1, 0, 1, 0 ); m_ImageResliceXOZ.InterpolateOn(); m_ImageResliceXOZ.SetInterpolationModeToNearestNeighbor(); m_ImageResliceXOZ.SetResliceAxesOrigin(pos[0], pos[1], pos[2]); m_ImageResliceXOZ.SetOutputDimensionality(2); m_ImageResliceXOZ.Update(); m_TextureXOZ = vtkTexture.New(); m_TextureXOZ.SetInput(m_ImageResliceXOZ.GetOutput()); m_TextureXOZ.SetLookupTable(m_LookupTable); m_TextureXOZ.MapColorScalarsThroughLookupTableOn(); //---------------------set plane position-------------------- m_PlaneSourceXOZ = vtkPlaneSource.New(); m_PlaneSourceXOZ.SetXResolution(xyz[0]); m_PlaneSourceXOZ.SetYResolution(xyz[2]); m_PlaneSourceXOZ.SetOrigin(0, 0, (xyz[2] - 1) * sp[2]); m_PlaneSourceXOZ.SetPoint1((xyz[0] - 1) * sp[0], 0, (xyz[2] - 1) * sp[2]); m_PlaneSourceXOZ.SetPoint2(0, 0, 0); m_PlaneSourceXOZ.Push(pos[1]); //---------------------pipeline------------------------------ m_PlaneMapperXOZ = vtkPolyDataMapper.New(); m_PlaneMapperXOZ.SetInput(m_PlaneSourceXOZ.GetOutput()); m_ActorXOZ = vtkActor.New(); m_ActorXOZ.SetMapper(m_PlaneMapperXOZ); m_ActorXOZ.SetTexture(m_TextureXOZ); #endregion #region -------------------YOZ切片(垂直X轴)------------------- m_ImageResliceYOZ = vtkImageReslice.New(); m_ImageResliceYOZ.SetInput(m_ImageData); m_ImageResliceYOZ.SetResliceAxesDirectionCosines( 0, 0, -1, 0, 1, 0, 1, 0, 0 ); m_ImageResliceYOZ.InterpolateOn(); m_ImageResliceYOZ.SetInterpolationModeToNearestNeighbor(); m_ImageResliceYOZ.SetResliceAxesOrigin(pos[0], pos[1], pos[2]); m_ImageResliceYOZ.SetOutputDimensionality(2); m_ImageResliceYOZ.Update(); m_TextureYOZ = vtkTexture.New(); m_TextureYOZ.SetInput(m_ImageResliceYOZ.GetOutput()); m_TextureYOZ.SetLookupTable(m_LookupTable); m_TextureYOZ.MapColorScalarsThroughLookupTableOn(); //---------------------set plane position-------------------- m_PlaneSourceYOZ = vtkPlaneSource.New(); m_PlaneSourceYOZ.SetXResolution(xyz[2]); m_PlaneSourceYOZ.SetYResolution(xyz[1]); m_PlaneSourceYOZ.SetOrigin(0, 0, (xyz[2] - 1) * sp[2]); m_PlaneSourceYOZ.SetPoint1(0, 0, 0); m_PlaneSourceYOZ.SetPoint2(0, (xyz[1] - 1) * sp[1], (xyz[2] - 1) * sp[2]); m_PlaneSourceYOZ.Push(pos[0]); //---------------------pipeline------------------------------ m_PlaneMapperYOZ = vtkPolyDataMapper.New(); m_PlaneMapperYOZ.SetInput(m_PlaneSourceYOZ.GetOutput()); m_ActorYOZ = vtkActor.New(); m_ActorYOZ.SetMapper(m_PlaneMapperYOZ); m_ActorYOZ.SetTexture(m_TextureYOZ); #endregion m_Renderer.AddActor(m_ActorXOY); m_Renderer.AddActor(m_ActorXOZ); m_Renderer.AddActor(m_ActorYOZ); }