public static int Main(string[] args) { string VTK_DATA_ROOT = vtkGDCMTesting.GetVTKDataRoot(); vtkVolume16Reader reader = vtkVolume16Reader.New(); reader.SetDataDimensions(64, 64); reader.SetDataByteOrderToLittleEndian(); reader.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter"); reader.SetImageRange(1, 93); reader.SetDataSpacing(3.2, 3.2, 1.5); vtkImageCast cast = vtkImageCast.New(); cast.SetInput(reader.GetOutput()); cast.SetOutputScalarTypeToUnsignedChar(); // By default this is creating a Multiframe Grayscale Word Secondary Capture Image Storage vtkGDCMImageWriter writer = vtkGDCMImageWriter.New(); writer.SetFileName("headsq.dcm"); writer.SetInput(reader.GetOutput()); // cast -> Multiframe Grayscale Byte Secondary Capture Image Storage // writer.SetInput( cast.GetOutput() ); writer.SetFileDimensionality(3); writer.Write(); return(0); }
/// <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> A Set Method for Static Variables </summary> public static void Setv16(vtkVolume16Reader toSet) { v16 = toSet; }
/// <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(); }
private void MarchingSquares() { // Path to vtk data must be set as an environment variable // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0" vtkTesting test = vtkTesting.New(); string root = test.GetDataRoot(); vtkVolume16Reader v16 = vtkVolume16Reader.New(); v16.SetDataDimensions(64, 64); v16.GetOutput().SetOrigin(0.0, 0.0, 0.0); v16.SetDataByteOrderToLittleEndian(); v16.SetFilePrefix(System.IO.Path.Combine(root, @"Data\headsq\quarter")); v16.SetImageRange(1, 93); v16.SetDataSpacing(3.2, 3.2, 1.5); v16.Update(); vtkMergePoints myLocator = vtkMergePoints.New(); vtkMarchingSquares isoXY = vtkMarchingSquares.New(); #if VTK_MAJOR_VERSION_5 isoXY.SetInputConnection(v16.GetOutputPort()); #else isoXY.SetInputData(v16); #endif isoXY.GenerateValues(2, 600, 1200); isoXY.SetImageRange(0, 32, 32, 63, 45, 45); isoXY.SetLocator(myLocator); vtkPolyDataMapper isoXYMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 isoXYMapper.SetInputConnection(isoXY.GetOutputPort()); #else isoXYMapper.SetInputData(isoXY); #endif isoXYMapper.SetScalarRange(600, 1200); vtkActor isoXYActor = vtkActor.New(); isoXYActor.SetMapper(isoXYMapper); vtkMarchingSquares isoYZ = vtkMarchingSquares.New(); #if VTK_MAJOR_VERSION_5 isoYZ.SetInputConnection(v16.GetOutputPort()); #else isoYZ.SetInputData(v16); #endif isoYZ.GenerateValues(2, 600, 1200); isoYZ.SetImageRange(32, 32, 32, 63, 46, 92); vtkPolyDataMapper isoYZMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 isoYZMapper.SetInputConnection(isoYZ.GetOutputPort()); #else isoYZMapper.SetInputData(isoYZ); #endif isoYZMapper.SetScalarRange(600, 1200); vtkActor isoYZActor = vtkActor.New(); isoYZActor.SetMapper(isoYZMapper); vtkMarchingSquares isoXZ = vtkMarchingSquares.New(); #if VTK_MAJOR_VERSION_5 isoXZ.SetInputConnection(v16.GetOutputPort()); #else isoXZ.SetInputData(v16); #endif isoXZ.GenerateValues(2, 600, 1200); isoXZ.SetImageRange(0, 32, 32, 32, 0, 46); vtkPolyDataMapper isoXZMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 isoXZMapper.SetInputConnection(isoXZ.GetOutputPort()); #else isoXZMapper.SetInputData(isoXZ); #endif isoXZMapper.SetScalarRange(600, 1200); vtkActor isoXZActor = vtkActor.New(); isoXZActor.SetMapper(isoXZMapper); vtkOutlineFilter outline = vtkOutlineFilter.New(); #if VTK_MAJOR_VERSION_5 outline.SetInputConnection(v16.GetOutputPort()); #else outline.SetInputData(v16); #endif vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 outlineMapper.SetInputConnection(outline.GetOutputPort()); #else outlineMapper.SetInputData(outline); #endif vtkActor outlineActor = vtkActor.New(); outlineActor.SetMapper(outlineMapper); outlineActor.VisibilityOff(); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(1.0, 1.0, 1.0); //Add the actors to the renderer, set the background and size renderer.AddActor(outlineActor); renderer.AddActor(isoXYActor); renderer.AddActor(isoYZActor); renderer.AddActor(isoXZActor); renderer.GetActiveCamera().SetPosition(324.368, 284.266, -19.3293); renderer.GetActiveCamera().SetFocalPoint(73.5683, 120.903, 70.7309); renderer.GetActiveCamera().SetViewAngle(30); renderer.GetActiveCamera().SetViewUp(-0.304692, -0.0563843, -0.950781); }