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(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVlabeledContours(String [] argv) { //Prefix Content is: "" // demonstrate labeling of contour with scalar value[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Read a slice and contour it[] v16 = new vtkVolume16Reader(); v16.SetDataDimensions((int)64,(int)64); v16.GetOutput().SetOrigin((double)0.0,(double)0.0,(double)0.0); v16.SetDataByteOrderToLittleEndian(); v16.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter"); v16.SetImageRange((int)45,(int)45); v16.SetDataSpacing((double)3.2,(double)3.2,(double)1.5); iso = new vtkContourFilter(); iso.SetInputConnection((vtkAlgorithmOutput)v16.GetOutputPort()); iso.GenerateValues((int)6,(double)500,(double)1150); iso.Update(); numPts = iso.GetOutput().GetNumberOfPoints(); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); isoMapper.ScalarVisibilityOn(); isoMapper.SetScalarRange((double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[1]); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); // Subsample the points and label them[] mask = new vtkMaskPoints(); mask.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); mask.SetOnRatio((int)(numPts/50)); mask.SetMaximumNumberOfPoints((int)50); mask.RandomModeOn(); // Create labels for points - only show visible points[] visPts = new vtkSelectVisiblePoints(); visPts.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort()); visPts.SetRenderer((vtkRenderer)ren1); ldm = new vtkLabeledDataMapper(); ldm.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort()); // ldm SetLabelFormat "%g"[] ldm.SetLabelModeToLabelScalars(); tprop = ldm.GetLabelTextProperty(); tprop.SetFontFamilyToArial(); tprop.SetFontSize((int)10); tprop.SetColor((double)1,(double)0,(double)0); contourLabels = new vtkActor2D(); contourLabels.SetMapper((vtkMapper2D)ldm); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor2D((vtkProp)isoActor); ren1.AddActor2D((vtkProp)contourLabels); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)500,(int)500); renWin.Render(); ren1.GetActiveCamera().Zoom((double)1.5); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVlabeledContours(String [] argv) { //Prefix Content is: "" // demonstrate labeling of contour with scalar value[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Read a slice and contour it[] v16 = new vtkVolume16Reader(); v16.SetDataDimensions((int)64, (int)64); v16.GetOutput().SetOrigin((double)0.0, (double)0.0, (double)0.0); v16.SetDataByteOrderToLittleEndian(); v16.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter"); v16.SetImageRange((int)45, (int)45); v16.SetDataSpacing((double)3.2, (double)3.2, (double)1.5); iso = new vtkContourFilter(); iso.SetInputConnection((vtkAlgorithmOutput)v16.GetOutputPort()); iso.GenerateValues((int)6, (double)500, (double)1150); iso.Update(); numPts = iso.GetOutput().GetNumberOfPoints(); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); isoMapper.ScalarVisibilityOn(); isoMapper.SetScalarRange((double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[1]); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); // Subsample the points and label them[] mask = new vtkMaskPoints(); mask.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); mask.SetOnRatio((int)(numPts / 50)); mask.SetMaximumNumberOfPoints((int)50); mask.RandomModeOn(); // Create labels for points - only show visible points[] visPts = new vtkSelectVisiblePoints(); visPts.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort()); visPts.SetRenderer((vtkRenderer)ren1); ldm = new vtkLabeledDataMapper(); ldm.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort()); // ldm SetLabelFormat "%g"[] ldm.SetLabelModeToLabelScalars(); tprop = ldm.GetLabelTextProperty(); tprop.SetFontFamilyToArial(); tprop.SetFontSize((int)10); tprop.SetColor((double)1, (double)0, (double)0); contourLabels = new vtkActor2D(); contourLabels.SetMapper((vtkMapper2D)ldm); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor2D((vtkProp)isoActor); ren1.AddActor2D((vtkProp)contourLabels); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)500, (int)500); renWin.Render(); ren1.GetActiveCamera().Zoom((double)1.5); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
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); }