/// <summary> /// move forward to next slice /// </summary> private void MoveForwardSlice() { Debug.WriteLine(_Slice.ToString()); if (_Slice < _MaxSlice) { _Slice += 1; _ImageViewer.SetSlice(_Slice); _SliceStatusMapper.SetInput("Slice No " + (_Slice + 1).ToString() + "/" + (_MaxSlice + 1).ToString()); _ImageViewer.Render(); } }
/* * In this function, first need to build the color table, * and then add the text */ public void VTKInfoBuilder(ref vtkActor2D actor) { vtkActor2D colorTextActor = new vtkActor2D(); vtkTextMapper colorText = new vtkTextMapper(); colorTextActor.SetMapper(colorText); //Generate the string: string outPutChartString = ""; outPutChartString += "[Model Details]\n"; outPutChartString += "Phase: " + WorkSpaceInstance.Env.GetModelGeneratingPhase() + "\n"; outPutChartString += "ModelType: " + WorkSpaceInstance.Env.GetModelTypeString() + "\n"; outPutChartString += "Model Name: " + WorkSpaceInstance.Env.GetCurrentTowerModelName() + "\n"; outPutChartString += "\n"; outPutChartString += "Min: " + TowerModelInstance.GetColorGenColorTableMinvalue().ToString() + " Max: " + TowerModelInstance.GetColorGenColorTableMaxValue().ToString() + "\n"; colorText.SetInput(outPutChartString); colorText.GetTextProperty().SetFontSize(12); colorText.GetTextProperty().SetFontFamilyToArial(); //colorText.GetTextProperty().SetColor(225, 39, 39); colorTextActor.SetDisplayPosition(20, 50); actor = colorTextActor; }
private void Subdivision(string filePath) { vtkPolyData originalMesh; if (filePath != null) { vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); // Subdivision filters only work on triangles vtkTriangleFilter triangles = vtkTriangleFilter.New(); triangles.SetInputConnection(reader.GetOutputPort()); triangles.Update(); originalMesh = triangles.GetOutput(); } else { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); originalMesh = sphereSource.GetOutput(); } Debug.WriteLine("Before subdivision"); Debug.WriteLine(" There are " + originalMesh.GetNumberOfPoints() + " points."); Debug.WriteLine(" There are " + originalMesh.GetNumberOfPolys() + " triangles."); int numberOfViewports = 3; vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; this.Size = new System.Drawing.Size(200 * numberOfViewports + 12, 252); this.Text += " - Subdivision"; Random rnd = new Random(2); int numberOfSubdivisions = 2; // Create one text property for all vtkTextProperty textProperty = vtkTextProperty.New(); textProperty.SetFontSize(14); textProperty.SetJustificationToCentered(); for (int i = 0; i < numberOfViewports; i++) { // Note: Here we create a superclass pointer (vtkPolyDataAlgorithm) so that we can easily instantiate different // types of subdivision filters. Typically you would not want to do this, but rather create the pointer to be the type // filter you will actually use, e.g. // <vtkLinearSubdivisionFilter> subdivisionFilter = <vtkLinearSubdivisionFilter>.New(); vtkPolyDataAlgorithm subdivisionFilter; switch (i) { case 0: subdivisionFilter = vtkLinearSubdivisionFilter.New(); ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; case 1: subdivisionFilter = vtkLoopSubdivisionFilter.New(); ((vtkLoopSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; case 2: subdivisionFilter = vtkButterflySubdivisionFilter.New(); ((vtkButterflySubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; default: subdivisionFilter = vtkLinearSubdivisionFilter.New(); ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; } #if VTK_MAJOR_VERSION_5 subdivisionFilter.SetInputConnection(originalMesh.GetProducerPort()); #else subdivisionFilter.SetInputData(originalMesh); #endif subdivisionFilter.Update(); vtkRenderer renderer = vtkRenderer.New(); renderWindow.AddRenderer(renderer); renderer.SetViewport((float)i / numberOfViewports, 0, (float)(i + 1) / numberOfViewports, 1); renderer.SetBackground(.2 + rnd.NextDouble() / 8, .3 + rnd.NextDouble() / 8, .4 + rnd.NextDouble() / 8); vtkTextMapper textMapper = vtkTextMapper.New(); vtkActor2D textActor = vtkActor2D.New(); textMapper.SetInput(subdivisionFilter.GetClassName()); textMapper.SetTextProperty(textProperty); textActor.SetMapper(textMapper); textActor.SetPosition(100, 16); //Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(subdivisionFilter.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); renderer.AddActor(actor); renderer.AddActor(textActor); renderer.ResetCamera(); } renderWindow.Render(); }
private void ReadDICOMSeries() { // 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(); // Read all the DICOM files in the specified directory. // Caution: folder "DicomTestImages" don't exists by default in the standard vtk data folder // sample data are available at http://www.vtk.org/Wiki/images/1/12/VTK_Examples_StandardFormats_Input_DicomTestImages.zip //string folder = Path.Combine(root, @"Data\DicomTestImages"); string folder = @"provaDicom/" + studyUID; Console.WriteLine(folder); vtkDICOMImageReader reader = vtkDICOMImageReader.New(); reader.SetDirectoryName(folder); reader.Update(); // Visualize _ImageViewer = vtkImageViewer2.New(); _ImageViewer.SetInputConnection(reader.GetOutputPort()); // get range of slices (min is the first index, max is the last index) _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice); Debug.WriteLine("slices range from : " + _MinSlice.ToString() + " to " + _MaxSlice.ToString()); // slice status message vtkTextProperty sliceTextProp = vtkTextProperty.New(); sliceTextProp.SetFontFamilyToCourier(); sliceTextProp.SetFontSize(20); sliceTextProp.SetVerticalJustificationToBottom(); sliceTextProp.SetJustificationToLeft(); _SliceStatusMapper = vtkTextMapper.New(); _SliceStatusMapper.SetInput("Slice No " + (_Slice + 1).ToString() + "/" + (_MaxSlice + 1).ToString()); _SliceStatusMapper.SetTextProperty(sliceTextProp); vtkActor2D sliceStatusActor = vtkActor2D.New(); sliceStatusActor.SetMapper(_SliceStatusMapper); sliceStatusActor.SetPosition(15, 10); // usage hint message vtkTextProperty usageTextProp = vtkTextProperty.New(); usageTextProp.SetFontFamilyToCourier(); usageTextProp.SetFontSize(14); usageTextProp.SetVerticalJustificationToTop(); usageTextProp.SetJustificationToLeft(); vtkTextMapper usageTextMapper = vtkTextMapper.New(); usageTextMapper.SetInput("Slice with mouse wheel\nor Up/Down-Key"); usageTextMapper.SetTextProperty(usageTextProp); vtkActor2D usageTextActor = vtkActor2D.New(); usageTextActor.SetMapper(usageTextMapper); usageTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay(); usageTextActor.GetPositionCoordinate().SetValue(0.05, 0.95); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New(); // NOTA:non funziona la rotellina del mouse per cambiare slice <-------------------------------------- // l'errore รจ causato dalla funzione DicomCFindRequest(della sorgente di FellowOak) //in QueryFellowOak.cs, in particolare dal costruttore // DicomCFindRequest(DicomQueryRetrieveLevel level) // interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt); // interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt); renderWindow.GetInteractor().SetInteractorStyle(interactorStyle); renderWindow.GetRenderers().InitTraversal(); vtkRenderer ren; while ((ren = renderWindow.GetRenderers().GetNextItem()) != null) { ren.SetBackground(0.0, 0.0, 0.0); } _ImageViewer.SetRenderWindow(renderWindow); _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor); _ImageViewer.GetRenderer().AddActor2D(usageTextActor); _ImageViewer.SetSlice(_MinSlice); _ImageViewer.Render(); }
private void ReadDICOMSeries() { // 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(); // Read all the DICOM files in the specified directory. // Caution: folder "DicomTestImages" don't exists by default in the standard vtk data folder // sample data are available at http://www.vtk.org/Wiki/images/1/12/VTK_Examples_StandardFormats_Input_DicomTestImages.zip string folder = Path.Combine(root, @"Data\DicomTestImages"); vtkDICOMImageReader reader = vtkDICOMImageReader.New(); reader.SetDirectoryName(folder); reader.Update(); // Visualize _ImageViewer = vtkImageViewer2.New(); _ImageViewer.SetInputConnection(reader.GetOutputPort()); // get range of slices (min is the first index, max is the last index) _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice); Debug.WriteLine("slices range from : " + _MinSlice.ToString() + " to " + _MaxSlice.ToString()); // slice status message vtkTextProperty sliceTextProp = vtkTextProperty.New(); sliceTextProp.SetFontFamilyToCourier(); sliceTextProp.SetFontSize(20); sliceTextProp.SetVerticalJustificationToBottom(); sliceTextProp.SetJustificationToLeft(); _SliceStatusMapper = vtkTextMapper.New(); _SliceStatusMapper.SetInput("Slice No " + ( _Slice + 1 ).ToString() + "/" + ( _MaxSlice + 1 ).ToString()); _SliceStatusMapper.SetTextProperty(sliceTextProp); vtkActor2D sliceStatusActor = vtkActor2D.New(); sliceStatusActor.SetMapper(_SliceStatusMapper); sliceStatusActor.SetPosition(15, 10); // usage hint message vtkTextProperty usageTextProp = vtkTextProperty.New(); usageTextProp.SetFontFamilyToCourier(); usageTextProp.SetFontSize(14); usageTextProp.SetVerticalJustificationToTop(); usageTextProp.SetJustificationToLeft(); vtkTextMapper usageTextMapper = vtkTextMapper.New(); usageTextMapper.SetInput("Slice with mouse wheel\nor Up/Down-Key"); usageTextMapper.SetTextProperty(usageTextProp); vtkActor2D usageTextActor = vtkActor2D.New(); usageTextActor.SetMapper(usageTextMapper); usageTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay(); usageTextActor.GetPositionCoordinate().SetValue(0.05, 0.95); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New(); interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt); interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt); renderWindow.GetInteractor().SetInteractorStyle(interactorStyle); renderWindow.GetRenderers().InitTraversal(); vtkRenderer ren; while(( ren = renderWindow.GetRenderers().GetNextItem() ) != null) ren.SetBackground(0.0, 0.0, 0.0); _ImageViewer.SetRenderWindow(renderWindow); _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor); _ImageViewer.GetRenderer().AddActor2D(usageTextActor); _ImageViewer.SetSlice(_MinSlice); _ImageViewer.Render(); }