private void ReadMetaImage() { // 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(); string filePath = System.IO.Path.Combine(root, @"Data\foot\foot.mha"); vtkMetaImageReader reader = vtkMetaImageReader.New(); if (reader.CanReadFile(filePath) == 0) { MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK); return; } reader.SetFileName(filePath); reader.Update(); vtkImageActor actor = vtkImageActor.New(); actor.SetInput(reader.GetOutput()); // Visualize vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); }
private vtkImageActor GetMapImage() { string filePath = this.folderPath + "\\map.jpg"; vtkImageData imageData; //Read the image vtkJPEGReader jpegReader = new vtkJPEGReader(); if (jpegReader.CanReadFile(filePath) == 0) { Console.WriteLine("ERROR"); return(null); } jpegReader.SetFileName(filePath); jpegReader.Update(); imageData = jpegReader.GetOutput(); //imageData.SetExtent(0, 1236, 0, 870, 0, 0); //imageData.SetSpacing(1236, 870, 0.01); imageData.SetOrigin(0, 0, 0); vtkImageActor imageActor = new vtkImageActor(); imageActor.SetInput(imageData); imageActor.SetScale(1f / horizontalRes); double[] bounds = imageActor.GetBounds(); return(imageActor); }
void RenderSlicer() { //Create all the objects for the pipeline vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); vtkImageActor iactor = vtkImageActor.New(); vtkImageClip clip = vtkImageClip.New(); vtkContourFilter contour = vtkContourFilter.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); vtkInteractorStyleImage style = vtkInteractorStyleImage.New(); vtkRenderer renderer = renderWindowControl2.RenderWindow.GetRenderers().GetFirstRenderer(); //Read the Image reader.SetFileName(m_FileName); //Go through the visulization pipeline iactor.SetInput(reader.GetOutput()); renderer.AddActor(iactor); reader.Update(); int[] extent = reader.GetOutput().GetWholeExtent(); iactor.SetDisplayExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); clip.SetInputConnection(reader.GetOutputPort()); clip.SetOutputWholeExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); contour.SetInputConnection(clip.GetOutputPort()); contour.SetValue(0, 100); mapper.SetInputConnection(contour.GetOutputPort()); mapper.SetScalarVisibility(1); //Go through the graphics pipeline actor.SetMapper(mapper); actor.GetProperty().SetColor(0, 1, 0); renderer.AddActor(actor); //Give a new style to the interactor //vtkRenderWindowInteractor iren = renderWindowControl2.RenderWindow.GetInteractor(); //iren.SetInteractorStyle(style); //Update global variables this.trackBar1.Maximum = extent[5]; this.trackBar1.Minimum = extent[4]; //this.Interactor = iren; this.m_SliceRenderWindow = renderWindowControl2.RenderWindow; this.m_SliceRenderer = renderer; this.m_SliceClip = clip; this.m_SliceImageActor = iactor; renderer.ResetCamera(); this.m_SliceRenderer.ResetCameraClippingRange(); this.m_SliceRenderWindow.Render(); }
private void WriteMetaImage() { // 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(); string filePath = System.IO.Path.Combine(root, @"Data\test_mha.mhd"); string filePathRaw = System.IO.Path.Combine(root, @"Data\test_mha.raw"); // Create an image vtkImageMandelbrotSource source = vtkImageMandelbrotSource.New(); source.Update(); vtkImageCast castFilter = vtkImageCast.New(); castFilter.SetOutputScalarTypeToUnsignedChar(); castFilter.SetInputConnection(source.GetOutputPort()); castFilter.Update(); vtkMetaImageWriter writer = vtkMetaImageWriter.New(); writer.SetInputConnection(castFilter.GetOutputPort()); writer.SetFileName(filePath); writer.SetRAWFileName(filePathRaw); writer.Write(); // Read and display file for verification that it was written correctly vtkMetaImageReader reader = vtkMetaImageReader.New(); if (reader.CanReadFile(filePath) == 0) { MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK); return; } reader.SetFileName(filePath); reader.Update(); vtkImageActor actor = vtkImageActor.New(); actor.SetInput(reader.GetOutput()); // Visualize vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); }
//wizualizacja 3d ----------------------------------------------------------------- public Visualization3D(RenderWindowControl window, vtkDICOMImageReader dicomReader) { this.window = window; this.dicomReader = dicomReader; this.presetMapper = new PresetMapper(); vtkRenderer renderer = window.RenderWindow.GetRenderers().GetFirstRenderer(); vtkSmartVolumeMapper mapper = vtkSmartVolumeMapper.New(); vol = vtkVolume.New(); vtkLookupTable bwLut = vtkLookupTable.New(); bwLut.SetTableRange(0, 2000); bwLut.SetSaturationRange(0, 0); bwLut.SetHueRange(0, 0); bwLut.SetValueRange(0, 1); bwLut.Build(); //effective built vtkImageMapToColors sagittalColors = vtkImageMapToColors.New(); sagittalColors.SetInputConnection(dicomReader.GetOutputPort()); sagittalColors.SetLookupTable(bwLut); sagittalColors.Update(); vtkImageActor sagittal = vtkImageActor.New(); sagittal.SetInput(sagittalColors.GetOutput()); sagittal.SetDisplayExtent(117, 117, 0, 173, 1, 180); vtkImageReslice reslicer = vtkImageReslice.New(); reslicer.SetResliceAxesDirectionCosines(1, 0, 0, 2, 0, 0, 0, 0, 0); mapper.SetInputConnection(dicomReader.GetOutputPort()); this.setColorFunction(); this.setOpacityFunction(); this.setGradientOpacity(); vol.SetMapper(mapper); renderer.AddActor(sagittal); renderer.AddVolume(vol); }
private void ReadDEM() { // 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(); string filePath = System.IO.Path.Combine(root, @"Data\SainteHelens.dem"); vtkDEMReader reader = vtkDEMReader.New(); reader.SetFileName(filePath); reader.Update(); vtkLookupTable lut = vtkLookupTable.New(); lut.SetHueRange(0.6, 0); lut.SetSaturationRange(1.0, 0); lut.SetValueRange(0.5, 1.0); double[] range = reader.GetOutput().GetScalarRange(); lut.SetTableRange(range[0], range[1]); // Visualize vtkImageMapToColors mapColors = vtkImageMapToColors.New(); mapColors.SetLookupTable(lut); mapColors.SetInputConnection(reader.GetOutputPort()); // Create an actor vtkImageActor actor = vtkImageActor.New(); actor.SetInput(mapColors.GetOutput()); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.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); }
/// <summary> /// Application Constructor /// </summary> public Form1() { InitializeComponent(); //Initialize the loading graphic System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream stream = ass.GetManifestResourceStream(ass.GetName().Name + ".logo.png"); //Read in the logo as a stream System.Drawing.Image img = Image.FromStream(stream); //Convert the System.Drawing.Image to Kitware.VTK.ImageData vtkImageData idata = vtkImageData.FromImage(img); logoActor = vtkImageActor.New(); logoActor.SetInputConnection(idata); logoRenderer = vtkRenderer.New(); logoRenderer.AddActor(logoActor); //Look at the center of the logo instead of the default bottom right corner logoActor.SetOrigin((idata.GetDimensions()[0] / 2), (idata.GetDimensions()[1] / 2), 0); vtkCamera cam = logoRenderer.GetActiveCamera(); cam.SetFocalPoint(logoActor.GetCenter()[0], logoActor.GetCenter()[1], logoActor.GetCenter()[2]); cam.SetPosition(logoActor.GetCenter()[0], logoActor.GetCenter()[1], 900); }
/// <summary> /// Application Constructor /// </summary> public Form1() { InitializeComponent(); //Initialize the loading graphic System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream stream = ass.GetManifestResourceStream(ass.GetName().Name + ".logo.png"); //Read in the logo as a stream System.Drawing.Image img = Image.FromStream(stream); //Convert the System.Drawing.Image to Kitware.VTK.ImageData vtkImageData idata = vtkImageData.FromImage(img); logoActor = vtkImageActor.New(); logoActor.SetInput(idata); logoRenderer = vtkRenderer.New(); logoRenderer.AddActor(logoActor); //Look at the center of the logo instead of the default bottom right corner logoActor.SetOrigin((idata.GetDimensions()[0] / 2), (idata.GetDimensions()[1] / 2), 0); vtkCamera cam = logoRenderer.GetActiveCamera(); cam.SetFocalPoint(logoActor.GetCenter()[0], logoActor.GetCenter()[1], logoActor.GetCenter()[2]); cam.SetPosition(logoActor.GetCenter()[0], logoActor.GetCenter()[1], 900); }
private void RenderDEM() { vtkDEMReader reader = vtkDEMReader.New(); reader.SetFileName(m_FileName); reader.Update(); vtkLookupTable lut = vtkLookupTable.New(); lut.SetHueRange(0.6, 0); lut.SetSaturationRange(1.0, 0); lut.SetValueRange(0.5, 1.0); double[] range = reader.GetOutput().GetScalarRange(); lut.SetTableRange(range[0], range[1]); // Visualize vtkImageMapToColors mapColors = vtkImageMapToColors.New(); mapColors.SetLookupTable(lut); mapColors.SetInputConnection(reader.GetOutputPort()); // Create an actor vtkImageActor actor = vtkImageActor.New(); actor.SetInput(mapColors.GetOutput()); // add our actor to the renderer m_Renderer.AddActor(actor); imgPropList.Add(actor); m_Renderer.ResetCamera(); //Rerender the screen m_RenderWindow.Render(); m_Renderer.Render(); }
void RenderSlicer() { //Create all the objects for the pipeline vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); vtkImageActor iactor = vtkImageActor.New(); vtkImageClip clip = vtkImageClip.New(); vtkContourFilter contour = vtkContourFilter.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); vtkInteractorStyleImage style = vtkInteractorStyleImage.New(); vtkRenderer renderer = renderWindowControl2.RenderWindow.GetRenderers().GetFirstRenderer(); //Read the Image reader.SetFileName(m_FileName); //Go through the visulization pipeline iactor.SetInput(reader.GetOutput()); renderer.AddActor(iactor); reader.Update(); int[] extent = reader.GetOutput().GetWholeExtent(); iactor.SetDisplayExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); clip.SetInputConnection(reader.GetOutputPort()); clip.SetOutputWholeExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); contour.SetInputConnection(clip.GetOutputPort()); contour.SetValue(0, 100); mapper.SetInputConnection(contour.GetOutputPort()); mapper.SetScalarVisibility(1); //Go through the graphics pipeline actor.SetMapper(mapper); actor.GetProperty().SetColor(0, 1, 0); renderer.AddActor(actor); //Give a new style to the interactor //vtkRenderWindowInteractor iren = renderWindowControl2.RenderWindow.GetInteractor(); //iren.SetInteractorStyle(style); //Update global variables this.trackBar1.Maximum = extent[5]; this.trackBar1.Minimum = extent[4]; //this.Interactor = iren; this.m_SliceRenderWindow = renderWindowControl2.RenderWindow; this.m_SliceRenderer = renderer; this.m_SliceClip = clip; this.m_SliceImageActor = iactor; renderer.ResetCamera(); }
public static int Main(string[] args) { vtkTesting testHelper = vtkTesting.New(); for (int cc = 0; cc < args.Length; cc++) { //testHelper.AddArguments(argc,const_cast<const char **>(argv)); //System.Console.Write( "args: " + args[cc] + "\n" ); testHelper.AddArgument(args[cc]); } if (testHelper.IsFlagSpecified("-D") != 0) { string VTK_DATA_ROOT = vtkGDCMTesting.GetVTKDataRoot(); if (VTK_DATA_ROOT != null) { //System.Console.Write( "VTK_DATA_ROOT: " + VTK_DATA_ROOT + "\n" ); testHelper.SetDataRoot(VTK_DATA_ROOT); testHelper.AddArgument("-D"); testHelper.AddArgument(VTK_DATA_ROOT); } } string dataRoot = testHelper.GetDataRoot(); string filename = dataRoot; filename += "/Data/mr.001"; vtkDirectory dir = vtkDirectory.New(); if (dir.FileIsDirectory(dataRoot) == 0) { filename = vtkGDCMTesting.GetGDCMDataRoot() + "/test.acr"; } //System.Console.Write( "dataRoot: " + dataRoot + "\n" ); System.Console.Write("filename being used is: " + filename + "\n"); vtkGDCMImageReader reader = vtkGDCMImageReader.New(); vtkStringArray array = vtkStringArray.New(); array.InsertNextValue(filename); reader.SetFileNames(array); reader.Update(); System.Console.Write(reader.GetOutput()); vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New(); vtkRenderer ren1 = vtkRenderer.New(); vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); vtkImageActor actor = vtkImageActor.New(); vtkImageMapToWindowLevelColors coronalColors = vtkImageMapToWindowLevelColors.New(); coronalColors.SetInput(reader.GetOutput()); actor.SetInput(coronalColors.GetOutput()); ren1.AddActor(actor); iren.SetRenderWindow(renWin); iren.Initialize(); renWin.Render(); int retVal = testHelper.IsInteractiveModeSpecified(); if (retVal != 0) { iren.Start(); } return(0); }
static public vtkProp3D genFieldActor(FieldBase data) { int N_width = data.Ex.Count; int M_depth = data.Ex.Count; double ds = data.ds_x; double width = N_width * ds; double depth = M_depth * ds; vtkImageData img = vtkImageData.New(); img.SetDimensions(N_width, M_depth, 1); img.SetSpacing(0.01 * ds / 0.01, 0.01 * ds / 0.01, 1); img.SetScalarTypeToDouble(); img.SetNumberOfScalarComponents(1); double max = -100000000, min = 0; List <List <Complex> > tempEH = null; int content = 1; bool isPhs = false; bool isLinear = true; const double dB_RABNGE = 60; switch (content) { case 0: tempEH = data.Ex; break; case 1: tempEH = data.Ey; break; case 2: tempEH = data.Ez; break; case 3: tempEH = data.Hx; break; case 4: tempEH = data.Hy; break; case 5: tempEH = data.Hz; break; default: break; } double[] data_tmp = new double[M_depth * N_width]; int count = 0; for (int j = 0; j < M_depth; j++) { for (int i = 0; i < N_width; i++) { double tempD; Complex temp; temp = tempEH[i][j]; if (isPhs) { if (temp.real != 0) { tempD = Math.Atan2(temp.imag, temp.real); } else { tempD = 0; } } else { tempD = Math.Pow((temp.real * temp.real + temp.imag * temp.imag), 0.5); } if (!isLinear && !isPhs) { tempD = 20 * Math.Log(tempD + 0.000000001); if (min > tempD) { min = tempD; } if (max < tempD) { max = tempD; } } else { if (max < tempD) { max = tempD; } if (min > tempD) { min = tempD; } } data_tmp[count++] = tempD; } } //ptr = img.GetScalarPointer(); vtkLookupTable colorTable = vtkLookupTable.New(); if (!isLinear && !isPhs) { min = max - dB_RABNGE; } if (!isPhs) { for (int i = 0; i < N_width * M_depth * 1; i++) { data_tmp[i] = max - data_tmp[i]; } colorTable.SetRange(0, max - min); } else { colorTable.SetRange(min, max); } IntPtr ptr = img.GetScalarPointer(); System.Runtime.InteropServices.Marshal.Copy(data_tmp, 0, ptr, M_depth * N_width); colorTable.Build(); vtkImageMapToColors colorMap = vtkImageMapToColors.New(); colorMap.SetInput(img); colorMap.SetLookupTable(colorTable); colorMap.Update(); vtkTransform transform = vtkTransform.New(); transform.Translate(data.coordinate.pos.x, data.coordinate.pos.y, data.coordinate.pos.z); transform.RotateWXYZ(data.coordinate.rotate_theta, data.coordinate.rotate_axis.x, data.coordinate.rotate_axis.y, data.coordinate.rotate_axis.z); transform.Translate(-width / 2, -depth / 2, 0); vtkImageActor actor = vtkImageActor.New(); actor.SetInput(colorMap.GetOutput()); actor.SetUserTransform(transform); return(actor); }
/// <summary> /// Display the render window with the slice in it /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void renderWindowControl1_Load(object sender, EventArgs e) { //Get the name of the Unsigned Char volume that you want to load fileName = "../../../head.vti"; //Create all the objects for the pipeline vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); vtkImageActor iactor = vtkImageActor.New(); vtkImageClip clip = vtkImageClip.New(); vtkContourFilter contour = vtkContourFilter.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); vtkInteractorStyleImage style = vtkInteractorStyleImage.New(); vtkRenderer renderer = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer(); //Read the Image reader.SetFileName(fileName); //Go through the visulization pipeline iactor.SetInputData(reader.GetOutput()); renderer.AddActor(iactor); reader.Update(); int[] extent = reader.GetOutput().GetExtent(); iactor.SetDisplayExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); clip.SetInputConnection(reader.GetOutputPort()); clip.SetOutputWholeExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); contour.SetInputConnection(clip.GetOutputPort()); contour.SetValue(0, 100); mapper.SetInputConnection(contour.GetOutputPort()); mapper.SetScalarVisibility(1); //Go through the graphics pipeline actor.SetMapper(mapper); actor.GetProperty().SetColor(0, 1, 0); renderer.AddActor(actor); //Give a new style to the interactor vtkRenderWindowInteractor iren = renderWindowControl1.RenderWindow.GetInteractor(); iren.SetInteractorStyle(style); //Add new events to the interactor style style.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(iren_LeftButtonPressEvt); style.LeftButtonReleaseEvt += new vtkObject.vtkObjectEventHandler(iren_LeftButtonReleaseEvt); style.MouseMoveEvt += new vtkObject.vtkObjectEventHandler(iren_MouseMoveEvt); //Update global variables this.trackBar1.Maximum = extent[5]; this.trackBar1.Minimum = extent[4]; this.Interactor = iren; this.RenderWindow = renderWindowControl1.RenderWindow; this.Renderer = renderer; this.Clip = clip; this.ImageActor = iactor; }
/// <summary> /// Display the render window with the slice in it /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void renderWindowControl1_Load(object sender, EventArgs e) { //Get the name of the Unsigned Char volume that you want to load fileName = "../../../head.vti"; //Create all the objects for the pipeline vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); vtkImageActor iactor = vtkImageActor.New(); vtkImageClip clip = vtkImageClip.New(); vtkContourFilter contour = vtkContourFilter.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); vtkInteractorStyleImage style = vtkInteractorStyleImage.New(); vtkRenderer renderer = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer(); //Read the Image reader.SetFileName(fileName); //Go through the visulization pipeline iactor.SetInput(reader.GetOutput()); renderer.AddActor(iactor); reader.Update(); int[] extent = reader.GetOutput().GetWholeExtent(); iactor.SetDisplayExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); clip.SetInputConnection(reader.GetOutputPort()); clip.SetOutputWholeExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); contour.SetInputConnection(clip.GetOutputPort()); contour.SetValue(0, 100); mapper.SetInputConnection(contour.GetOutputPort()); mapper.SetScalarVisibility(1); //Go through the graphics pipeline actor.SetMapper(mapper); actor.GetProperty().SetColor(0, 1, 0); renderer.AddActor(actor); //Give a new style to the interactor vtkRenderWindowInteractor iren = renderWindowControl1.RenderWindow.GetInteractor(); iren.SetInteractorStyle(style); //Add new events to the interactor style style.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(iren_LeftButtonPressEvt); style.LeftButtonReleaseEvt += new vtkObject.vtkObjectEventHandler(iren_LeftButtonReleaseEvt); style.MouseMoveEvt += new vtkObject.vtkObjectEventHandler(iren_MouseMoveEvt); //Update global variables this.trackBar1.Maximum = extent[5]; this.trackBar1.Minimum = extent[4]; this.Interactor = iren; this.RenderWindow = renderWindowControl1.RenderWindow; this.Renderer = renderer; this.Clip = clip; this.ImageActor = iactor; }