public void VTKDrawEdgesModel(ref vtkPoints points, ref vtkCellArray strips, FormParas paras) { int cnt = 0; for (int i = 0; i < NodeListSize; i++) { points.InsertPoint(cnt, NodeList[i].Node_Coord[0], 0, -NodeList[i].Node_Coord[1]); cnt++; } foreach (ListElemBase elem in ElemList) { for (int i = 0; i < 8; i++) { strips.InsertNextCell(2); if (i != 7) { strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[i]] - 1); strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[i + 1]] - 1); } else { strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[i]] - 1); strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[0]] - 1); } } } }
void Test() { foreach (var actor in m_actorDict.Keys) { int xmin = 0; int xlength = 1000; int xmax = xmin + xlength; int ymin = 0; int ylength = 1000; int ymax = ymin + ylength; int[] pos = { xmin, xmin + xlength, ymin, ymin + ylength }; #region RECT vtkPoints pts = vtkPoints.New(); pts.InsertPoint(0, xmin, ymin, 0); pts.InsertPoint(1, xmax, ymin, 0); pts.InsertPoint(2, xmax, ymax, 0); pts.InsertPoint(3, xmin, ymax, 0); vtkCellArray rect = vtkCellArray.New(); rect.InsertNextCell(5); rect.InsertCellPoint(0); rect.InsertCellPoint(1); rect.InsertCellPoint(2); rect.InsertCellPoint(3); rect.InsertCellPoint(0); vtkPolyData selectRect = vtkPolyData.New(); selectRect.SetPoints(pts); selectRect.SetLines(rect); vtkPolyDataMapper2D rectMapper = vtkPolyDataMapper2D.New(); rectMapper.SetInput(selectRect); vtkActor2D rectActor = vtkActor2D.New(); rectActor.SetMapper(rectMapper); m_render.AddActor(rectActor); #endregion vtkIdFilter ids = vtkIdFilter.New(); ids.SetInput(actor.GetMapper().GetInput()); //ids.SetInputConnection( actor.GetMapper().GetOutputPort()); ids.PointIdsOn(); ids.FieldDataOn(); vtkSelectVisiblePoints visPts = vtkSelectVisiblePoints.New(); visPts.SetInput(ids.GetOutput()); visPts.SetRenderer(m_render); visPts.SelectInvisibleOn(); visPts.SelectionWindowOn(); //visPts.SelectInvisibleOff(); visPts.SetSelection(pos[0], pos[1], pos[2], pos[3]); vtkLabeledDataMapper labelMapper = vtkLabeledDataMapper.New(); labelMapper.SetInputConnection(visPts.GetOutputPort()); // labelMapper.SetInput(visPts.GetInput()); labelMapper.SetLabelModeToLabelFieldData(); vtkActor2D actor2d = vtkActor2D.New(); actor2d.SetMapper(labelMapper); m_render.AddActor(actor2d); } m_render.Render(); }
// 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 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 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); } }
public static vtkPolyData Create(List <double[]> xyz1, double radius) { vtkPoints points = new vtkPoints(); for (int index = 0; index < xyz1.Count; index++) { double[] doubles = xyz1[index]; points.InsertPoint(index, doubles[0], doubles[1], doubles[2]); } vtkCellArray lines = new vtkCellArray(); lines.InsertNextCell(xyz1.Count); for (int index = 0; index < xyz1.Count; index++) { lines.InsertCellPoint(index); } 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(radius); profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors"); return(profileTubes.GetOutput()); }
public VTKDataModel(SimulationModel sm) { simModel = sm; int numCells = sm.Cells.Count; cellIDs = vtkIntArray.New(); cellIDs.SetNumberOfComponents(1); cellIDs.SetNumberOfValues(numCells); cellIDs.SetName(cellIdsArrayName); cellTypes = vtkIntArray.New(); cellTypes.SetNumberOfComponents(1); cellTypes.SetNumberOfValues(numCells); cellTypes.SetName(cellTypeArrayName); points = vtkPoints.New(); points.SetNumberOfPoints(numCells); verts = vtkCellArray.New(); verts.Allocate(verts.EstimateSize(1, numCells), 1000); verts.InsertNextCell(numCells); foreach (MotileCell cell in sm.Cells) { int i = cell.CellId; int c = cell.CellType; double[] p = cell.Position; points.SetPoint(i, p[0], p[1], p[2]); cellIDs.SetValue(i, i); cellTypes.SetValue(i, c); verts.InsertCellPoint(i); } poly = vtkPolyData.New(); poly.SetPoints(points); poly.SetVerts(verts); poly.GetPointData().AddArray(cellIDs); poly.GetPointData().AddArray(cellTypes); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVclosedSplines(String [] argv) { //Prefix Content is: "" // get the interactor ui[] // Now create the RenderWindow, Renderer and Interactor[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); math = new vtkMath(); numberOfInputPoints = 30; aKSplineX = new vtkKochanekSpline(); aKSplineX.ClosedOn(); aKSplineY = new vtkKochanekSpline(); aKSplineY.ClosedOn(); aKSplineZ = new vtkKochanekSpline(); aKSplineZ.ClosedOn(); aCSplineX = new vtkCardinalSpline(); aCSplineX.ClosedOn(); aCSplineY = new vtkCardinalSpline(); aCSplineY.ClosedOn(); aCSplineZ = new vtkCardinalSpline(); aCSplineZ.ClosedOn(); // add some points[] inputPoints = new vtkPoints(); x = -1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)0,(double)x); aKSplineY.AddPoint((double)0,(double)y); aKSplineZ.AddPoint((double)0,(double)z); aCSplineX.AddPoint((double)0,(double)x); aCSplineY.AddPoint((double)0,(double)y); aCSplineZ.AddPoint((double)0,(double)z); inputPoints.InsertPoint((int)0,(double)x,(double)y,(double)z); x = 1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)1,(double)x); aKSplineY.AddPoint((double)1,(double)y); aKSplineZ.AddPoint((double)1,(double)z); aCSplineX.AddPoint((double)1,(double)x); aCSplineY.AddPoint((double)1,(double)y); aCSplineZ.AddPoint((double)1,(double)z); inputPoints.InsertPoint((int)1,(double)x,(double)y,(double)z); x = 1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)2,(double)x); aKSplineY.AddPoint((double)2,(double)y); aKSplineZ.AddPoint((double)2,(double)z); aCSplineX.AddPoint((double)2,(double)x); aCSplineY.AddPoint((double)2,(double)y); aCSplineZ.AddPoint((double)2,(double)z); inputPoints.InsertPoint((int)2,(double)x,(double)y,(double)z); x = -1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)3,(double)x); aKSplineY.AddPoint((double)3,(double)y); aKSplineZ.AddPoint((double)3,(double)z); aCSplineX.AddPoint((double)3,(double)x); aCSplineY.AddPoint((double)3,(double)y); aCSplineZ.AddPoint((double)3,(double)z); inputPoints.InsertPoint((int)3,(double)x,(double)y,(double)z); inputData = new vtkPolyData(); inputData.SetPoints((vtkPoints)inputPoints); balls = new vtkSphereSource(); balls.SetRadius((double).04); balls.SetPhiResolution((int)10); balls.SetThetaResolution((int)10); glyphPoints = new vtkGlyph3D(); glyphPoints.SetInput((vtkDataObject)inputData); glyphPoints.SetSource((vtkPolyData)balls.GetOutput()); glyphMapper = vtkPolyDataMapper.New(); glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort()); glyph = new vtkActor(); glyph.SetMapper((vtkMapper)glyphMapper); glyph.GetProperty().SetDiffuseColor((double) 1.0000, 0.3882, 0.2784 ); glyph.GetProperty().SetSpecular((double).3); glyph.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)glyph); Kpoints = new vtkPoints(); Cpoints = new vtkPoints(); profileKData = new vtkPolyData(); profileCData = new vtkPolyData(); numberOfInputPoints = 5; numberOfOutputPoints = 100; offset = 1.0; //method moved fit(); lines = new vtkCellArray(); lines.InsertNextCell((int)numberOfOutputPoints); i = 0; while((i) < numberOfOutputPoints) { lines.InsertCellPoint((int)i); i = i + 1; } profileKData.SetPoints((vtkPoints)Kpoints); profileKData.SetLines((vtkCellArray)lines); profileCData.SetPoints((vtkPoints)Cpoints); profileCData.SetLines((vtkCellArray)lines); profileKTubes = new vtkTubeFilter(); profileKTubes.SetNumberOfSides((int)8); profileKTubes.SetInput((vtkDataObject)profileKData); profileKTubes.SetRadius((double).01); profileKMapper = vtkPolyDataMapper.New(); profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort()); profileK = new vtkActor(); profileK.SetMapper((vtkMapper)profileKMapper); profileK.GetProperty().SetDiffuseColor((double) 0.8900, 0.8100, 0.3400 ); profileK.GetProperty().SetSpecular((double).3); profileK.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileK); profileCTubes = new vtkTubeFilter(); profileCTubes.SetNumberOfSides((int)8); profileCTubes.SetInput((vtkDataObject)profileCData); profileCTubes.SetRadius((double).01); profileCMapper = vtkPolyDataMapper.New(); profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort()); profileC = new vtkActor(); profileC.SetMapper((vtkMapper)profileCMapper); profileC.GetProperty().SetDiffuseColor((double) 0.2000, 0.6300, 0.7900 ); profileC.GetProperty().SetSpecular((double).3); profileC.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileC); ren1.ResetCamera(); ren1.GetActiveCamera().Dolly((double)1.5); ren1.ResetCameraClippingRange(); renWin.SetSize((int)300,(int)300); // render the image[] //[] iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //method moved //method moved //method moved //method moved //method moved //method moved //deleteAllVTKObjects(); }
/********************************************* * VTK functions: * DrawModel -- Basic function to draw model * DrawEdgesModel -- Add grids to the model * LabelGetter -- Add label to the model *********************************************/ public int VTKDrawModel(ref vtkPoints points, ref vtkCellArray strips, ref vtkFloatArray scalars, ref int pointsNum, FormParas paras) { // The following routine is built for general purpose for (int i = 0; i < NodeList.Count(); i++) { points.InsertPoint(i, NodeList[i].Node_Coord[0], 0, -NodeList[i].Node_Coord[1]); } pointsNum = NodeList.Count(); if (paras.StageID != -1) { scalars.SetNumberOfValues(ElemList.Count()); } int cnt = 0; double MAX_R = 0; double MAX_R_VALUE = 0; int MAX_ELEM_NUM = 0; foreach (ListElemBase elem in ElemList) { strips.InsertNextCell(8); if (paras.StageID == -1) { scalars.InsertNextValue(elem.Elem_Modeltype[0]); } else { if (IfElemToPropertyKeyExists(elem.Elem_Number)) { scalars.SetValue(cnt, (float)GetElemToProperty(elem.Elem_Number)); } else { scalars.SetValue(cnt, 0); } //MessageBox.Show(((float)GetElemToProperty(elem.Elem_Number)).ToString()); } for (int i = 0; i < 8; i++) { int NodeId = elem.Elem_Nodes[i]; int NodePosInPointsArray = GetNodePositionInNodeListFromNodeId(NodeId); strips.InsertCellPoint(NodePosInPointsArray); if (paras.StageID != -1) { if (NodeList[NodePosInPointsArray].Node_Coord[0] > MAX_R) { MAX_R = NodeList[NodePosInPointsArray].Node_Coord[0]; if (IfElemToPropertyKeyExists(elem.Elem_Number)) { MAX_R_VALUE = GetElemToProperty(elem.Elem_Number); } else { MAX_R_VALUE = 0; } MAX_ELEM_NUM = elem.Elem_Number; } } } cnt++; } //MessageBox.Show(MAX_R.ToString() + ' ' + MAX_R_VALUE.ToString() + ' ' + MAX_ELEM_NUM.ToString()); return(1); }
private void BandedPolyDataContourFilter() { vtkPoints pts = vtkPoints.New(); pts.InsertPoint(0, 0, 0, 0); pts.InsertPoint(1, 0, 1, 0); pts.InsertPoint(2, 0, 2, 0); pts.InsertPoint(3, 1, 0, 0); pts.InsertPoint(4, 1, 1, 0); pts.InsertPoint(5, 1, 2, 0); pts.InsertPoint(6, 2, 0, 0); pts.InsertPoint(7, 2, 2, 0); pts.InsertPoint(8, 3, 0, 0); pts.InsertPoint(9, 3, 1, 0); pts.InsertPoint(10, 3, 2, 0); pts.InsertPoint(11, 4, 0, 0); pts.InsertPoint(12, 6, 0, 0); pts.InsertPoint(13, 5, 2, 0); pts.InsertPoint(14, 7, 0, 0); pts.InsertPoint(15, 9, 0, 0); pts.InsertPoint(16, 7, 2, 0); pts.InsertPoint(17, 9, 2, 0); pts.InsertPoint(18, 10, 0, 0); pts.InsertPoint(19, 12, 0, 0); pts.InsertPoint(20, 10, 1, 0); pts.InsertPoint(21, 12, 1, 0); pts.InsertPoint(22, 10, 2, 0); pts.InsertPoint(23, 12, 2, 0); pts.InsertPoint(24, 10, 3, 0); pts.InsertPoint(25, 12, 3, 0); vtkCellArray polys = vtkCellArray.New(); polys.InsertNextCell(4); polys.InsertCellPoint(14); polys.InsertCellPoint(15); polys.InsertCellPoint(17); polys.InsertCellPoint(16); polys.InsertNextCell(3); polys.InsertCellPoint(11); polys.InsertCellPoint(12); polys.InsertCellPoint(13); vtkFloatArray scalars = vtkFloatArray.New(); scalars.SetNumberOfTuples(26); scalars.SetTuple1(0, 0); scalars.SetTuple1(1, 50); scalars.SetTuple1(2, 100); scalars.SetTuple1(3, 0); scalars.SetTuple1(4, 50); scalars.SetTuple1(5, 100); scalars.SetTuple1(6, 10); scalars.SetTuple1(7, 90); scalars.SetTuple1(8, 10); scalars.SetTuple1(9, 50); scalars.SetTuple1(10, 90); scalars.SetTuple1(11, 10); scalars.SetTuple1(12, 40); scalars.SetTuple1(13, 100); scalars.SetTuple1(14, 0); scalars.SetTuple1(15, 60); scalars.SetTuple1(16, 40); scalars.SetTuple1(17, 100); scalars.SetTuple1(18, 0); scalars.SetTuple1(19, 25); scalars.SetTuple1(20, 25); scalars.SetTuple1(21, 50); scalars.SetTuple1(22, 50); scalars.SetTuple1(23, 75); scalars.SetTuple1(24, 75); scalars.SetTuple1(25, 100); vtkPolyData polyData = vtkPolyData.New(); polyData.SetPoints(pts); polyData.SetPolys(polys); polyData.GetPointData().SetScalars(scalars); vtkBandedPolyDataContourFilter bf = vtkBandedPolyDataContourFilter.New(); #if VTK_MAJOR_VERSION_5 bf.SetInput(polyData); #else bf.SetInputData(polyData); #endif bf.GenerateValues(3, 25, 75); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(bf.GetOutputPort()); mapper.SetScalarModeToUseCellData(); mapper.SetScalarRange(0, 4); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // 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(actor); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVclosedSplines(String [] argv) { //Prefix Content is: "" // get the interactor ui[] // Now create the RenderWindow, Renderer and Interactor[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); math = new vtkMath(); numberOfInputPoints = 30; aKSplineX = new vtkKochanekSpline(); aKSplineX.ClosedOn(); aKSplineY = new vtkKochanekSpline(); aKSplineY.ClosedOn(); aKSplineZ = new vtkKochanekSpline(); aKSplineZ.ClosedOn(); aCSplineX = new vtkCardinalSpline(); aCSplineX.ClosedOn(); aCSplineY = new vtkCardinalSpline(); aCSplineY.ClosedOn(); aCSplineZ = new vtkCardinalSpline(); aCSplineZ.ClosedOn(); // add some points[] inputPoints = new vtkPoints(); x = -1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)0, (double)x); aKSplineY.AddPoint((double)0, (double)y); aKSplineZ.AddPoint((double)0, (double)z); aCSplineX.AddPoint((double)0, (double)x); aCSplineY.AddPoint((double)0, (double)y); aCSplineZ.AddPoint((double)0, (double)z); inputPoints.InsertPoint((int)0, (double)x, (double)y, (double)z); x = 1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)1, (double)x); aKSplineY.AddPoint((double)1, (double)y); aKSplineZ.AddPoint((double)1, (double)z); aCSplineX.AddPoint((double)1, (double)x); aCSplineY.AddPoint((double)1, (double)y); aCSplineZ.AddPoint((double)1, (double)z); inputPoints.InsertPoint((int)1, (double)x, (double)y, (double)z); x = 1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)2, (double)x); aKSplineY.AddPoint((double)2, (double)y); aKSplineZ.AddPoint((double)2, (double)z); aCSplineX.AddPoint((double)2, (double)x); aCSplineY.AddPoint((double)2, (double)y); aCSplineZ.AddPoint((double)2, (double)z); inputPoints.InsertPoint((int)2, (double)x, (double)y, (double)z); x = -1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)3, (double)x); aKSplineY.AddPoint((double)3, (double)y); aKSplineZ.AddPoint((double)3, (double)z); aCSplineX.AddPoint((double)3, (double)x); aCSplineY.AddPoint((double)3, (double)y); aCSplineZ.AddPoint((double)3, (double)z); inputPoints.InsertPoint((int)3, (double)x, (double)y, (double)z); inputData = new vtkPolyData(); inputData.SetPoints((vtkPoints)inputPoints); balls = new vtkSphereSource(); balls.SetRadius((double).04); balls.SetPhiResolution((int)10); balls.SetThetaResolution((int)10); balls.Update(); glyphPoints = new vtkGlyph3D(); glyphPoints.SetInputData((vtkDataObject)inputData); glyphPoints.SetSourceData((vtkPolyData)balls.GetOutput()); glyphMapper = vtkPolyDataMapper.New(); glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort()); glyph = new vtkActor(); glyph.SetMapper((vtkMapper)glyphMapper); glyph.GetProperty().SetDiffuseColor((double)1.0000, 0.3882, 0.2784); glyph.GetProperty().SetSpecular((double).3); glyph.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)glyph); Kpoints = new vtkPoints(); Cpoints = new vtkPoints(); profileKData = new vtkPolyData(); profileCData = new vtkPolyData(); numberOfInputPoints = 5; numberOfOutputPoints = 100; offset = 1.0; //method moved fit(); lines = new vtkCellArray(); lines.InsertNextCell((int)numberOfOutputPoints); i = 0; while ((i) < numberOfOutputPoints) { lines.InsertCellPoint((int)i); i = i + 1; } profileKData.SetPoints((vtkPoints)Kpoints); profileKData.SetLines((vtkCellArray)lines); profileCData.SetPoints((vtkPoints)Cpoints); profileCData.SetLines((vtkCellArray)lines); profileKTubes = new vtkTubeFilter(); profileKTubes.SetNumberOfSides((int)8); profileKTubes.SetInputData((vtkDataObject)profileKData); profileKTubes.SetRadius((double).01); profileKMapper = vtkPolyDataMapper.New(); profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort()); profileK = new vtkActor(); profileK.SetMapper((vtkMapper)profileKMapper); profileK.GetProperty().SetDiffuseColor((double)0.8900, 0.8100, 0.3400); profileK.GetProperty().SetSpecular((double).3); profileK.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileK); profileCTubes = new vtkTubeFilter(); profileCTubes.SetNumberOfSides((int)8); profileCTubes.SetInputData((vtkDataObject)profileCData); profileCTubes.SetRadius((double).01); profileCMapper = vtkPolyDataMapper.New(); profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort()); profileC = new vtkActor(); profileC.SetMapper((vtkMapper)profileCMapper); profileC.GetProperty().SetDiffuseColor((double)0.2000, 0.6300, 0.7900); profileC.GetProperty().SetSpecular((double).3); profileC.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileC); ren1.ResetCamera(); ren1.GetActiveCamera().Dolly((double)1.5); ren1.ResetCameraClippingRange(); renWin.SetSize((int)300, (int)300); // render the image[] //[] iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //method moved //method moved //method moved //method moved //method moved //method moved //deleteAllVTKObjects(); }
public void SetPosition(List <double[]> xyz1) { if (_points == null) { this._xyz = xyz1; _points = vtkPoints.New(); for (int index = 0; index < xyz1.Count; index++) { double[] doubles = xyz1[index]; _points.InsertPoint(index, doubles[0], doubles[1], doubles[2]); } _lines = vtkCellArray.New(); _lines.InsertNextCell(xyz1.Count); for (int index = 0; index < xyz1.Count; index++) { _lines.InsertCellPoint(index); } _profileData = vtkPolyData.New(); _profileData.SetPoints(_points); _profileData.SetLines(_lines); _profileData.SetVerts(_lines); _profileData.Update(); _cleanFilter = vtkCleanPolyData.New(); _cleanFilter.SetInput(_profileData); _cleanFilter.Update(); _profileTubes = vtkTubeFilter.New(); _profileTubes.CappingOn(); _profileTubes.SetNumberOfSides(10); _profileTubes.SetInput(_cleanFilter.GetOutput()); //profileTubes.SetVaryRadiusToVaryRadiusByVector(); _profileTubes.SetRadius(radius); _profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors"); //vtkPolyDataMapper profileMapper = new vtkPolyDataMapper(); //profileMapper.SetInputConnection(profileTubes.GetOutputPort()); PolyData = _profileTubes.GetOutput(); _mapper = vtkPolyDataMapper.New(); _mapper.SetInput(_profileTubes.GetOutput()); centerLineActor.SetMapper(_mapper); centerLineActor.GetProperty().SetOpacity(0.5); } else { vtkPoints _newpoints = vtkPoints.New(); for (int index = 0; index < xyz1.Count; index++) { double[] doubles = xyz1[index]; _newpoints.InsertPoint(index, doubles[0], doubles[1], doubles[2]); } vtkCellArray _newlines = vtkCellArray.New(); _newlines.InsertNextCell(xyz1.Count); for (int index = 0; index < xyz1.Count; index++) { _newlines.InsertCellPoint(index); } _profileData.SetPoints(_newpoints); _profileData.SetLines(_newlines); _profileData.SetVerts(_newlines); _profileData.Update(); _profileTubes.SetRadius(radius); _points.Dispose(); _lines.Dispose(); _points = _newpoints; _lines = _newlines; _points.Modified(); _mapper.Modified(); } }
void Test2() { int xmin = 0; int xlength = 1000; int xmax = xmin + xlength; int ymin = 0; int ylength = 1000; int ymax = ymin + ylength; #region 定义显示的rectActor vtkPoints pts = vtkPoints.New(); pts.InsertPoint(0, xmin, ymin, 0); pts.InsertPoint(1, xmax, ymin, 0); pts.InsertPoint(2, xmax, ymax, 0); pts.InsertPoint(3, xmin, ymax, 0); vtkCellArray rect = vtkCellArray.New(); rect.InsertNextCell(5); rect.InsertCellPoint(0); rect.InsertCellPoint(1); rect.InsertCellPoint(2); rect.InsertCellPoint(3); rect.InsertCellPoint(0); vtkPolyData selectRect = vtkPolyData.New(); selectRect.SetPoints(pts); selectRect.SetLines(rect); vtkPolyDataMapper2D rectMapper = vtkPolyDataMapper2D.New(); rectMapper.SetInput(selectRect); vtkActor2D rectActor = vtkActor2D.New(); rectActor.SetMapper(rectMapper); #endregion vtkSphereSource sphere = vtkSphereSource.New(); vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New(); sphereMapper.SetInputConnection(sphere.GetOutputPort()); // sphereMapper.SetImmediateModeRendering(1); vtkActor sphereActor = vtkActor.New(); sphereActor.SetMapper(sphereMapper); vtkIdFilter ids = vtkIdFilter.New(); ids.SetInputConnection(sphere.GetOutputPort()); ids.PointIdsOn(); ids.CellIdsOn(); ids.FieldDataOn(); #region 设置要显示的点的及其label vtkSelectVisiblePoints visPts = vtkSelectVisiblePoints.New(); visPts.SetInputConnection(ids.GetOutputPort()); visPts.SetRenderer(m_render); visPts.SelectionWindowOn(); visPts.SetSelection(xmin, xmin + xlength, ymin, ymin + ylength); vtkLabeledDataMapper pointsMapper = vtkLabeledDataMapper.New(); pointsMapper.SetInputConnection(visPts.GetOutputPort()); pointsMapper.SetLabelModeToLabelFieldData(); pointsMapper.GetLabelTextProperty().SetColor(0, 255, 0); pointsMapper.GetLabelTextProperty().BoldOff(); vtkActor2D pointLabels = vtkActor2D.New(); pointLabels.SetMapper(pointsMapper); #endregion #region 设置要显示的cell的id及其label vtkCellCenters cc = vtkCellCenters.New(); cc.SetInputConnection(ids.GetOutputPort()); vtkSelectVisiblePoints visCells = vtkSelectVisiblePoints.New(); visCells.SetInputConnection(cc.GetOutputPort()); visCells.SetRenderer(m_render); visCells.SelectionWindowOn(); visCells.SetSelection(xmin, xmin + xlength, ymin, ymin + ylength); ///显示每个Cell的id vtkLabeledDataMapper cellMapper = vtkLabeledDataMapper.New(); cellMapper.SetInputConnection(visCells.GetOutputPort()); cellMapper.SetLabelModeToLabelFieldData(); cellMapper.GetLabelTextProperty().SetColor(255, 0, 0); vtkActor2D cellLabels = vtkActor2D.New(); cellLabels.SetMapper(cellMapper); #endregion m_render.AddActor(sphereActor); m_render.AddActor2D(rectActor); m_render.AddActor2D(pointLabels); // m_render.AddActor2D(cellLabels); }