本文主要是介绍vtkImageData融合显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 效果图:
- 源码:
效果图:
源码:
#include <vtkImageData.h>
#include <vtkImageMapper.h>
#include <vtkImageResliceMapper.h>
#include <vtkImageSlice.h>
#include <vtkInteractorStyleImage.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkDICOMImageReader.h>
#include <vtkImageProperty.h>
#include <vtkImageBlend.h>
#include <vtkSliderRepresentation2D.h>
#include <vtkSliderWidget.h>class SliderCallbackN1 : public vtkCommand
{
public:static SliderCallbackN1* New(){return new SliderCallbackN1;}virtual void Execute(vtkObject* caller, unsigned long, void*){vtkSliderWidget* sliderWidget = reinterpret_cast<vtkSliderWidget*>(caller);double value = static_cast<vtkSliderRepresentation2D*>(sliderWidget->GetRepresentation())->GetValue();if(this->imgBlender){this->imgBlender->SetOpacity(0, value);this->imgBlender->SetOpacity(1, 1.0-value);}}SliderCallbackN1() : imgBlender(0){}vtkImageBlend* imgBlender;
};int main(int, char*[])
{vtkNew<vtkRenderer> renderer;// Setup render window.vtkNew<vtkRenderWindow> renderWindow;renderWindow->SetSize(300, 300);renderWindow->AddRenderer(renderer);renderWindow->SetWindowName("ImageSlice");// Setup render window interactor.vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;vtkNew<vtkInteractorStyleImage> style;renderWindowInteractor->SetInteractorStyle(style);// Render and start interaction.renderWindowInteractor->SetRenderWindow(renderWindow);vtkNew<vtkNamedColors> colors;std::string inputFilename1 = "./drr_2.dcm";vtkNew<vtkDICOMImageReader> reader1;reader1->SetFileName(inputFilename1.c_str());reader1->Update();vtkImageData* image1 = reader1->GetOutput();std::string inputFilename2 = "./drr_9.dcm";vtkNew<vtkDICOMImageReader> reader2;reader2->SetFileName(inputFilename2.c_str());reader2->Update();vtkImageData* image2 = reader2->GetOutput();vtkNew<vtkImageBlend> imgBlender;imgBlender->SetOpacity(0, 0.5);imgBlender->SetOpacity(1, 0.5);imgBlender->AddInputData(image1);imgBlender->AddInputData(image2);vtkNew<vtkImageResliceMapper> imageResliceMapper;imageResliceMapper->SetInputConnection(imgBlender->GetOutputPort());vtkNew<vtkImageSlice> imageSlice;imageSlice->SetMapper(imageResliceMapper);imageSlice->GetProperty()->SetColorLevel(32768);imageSlice->GetProperty()->SetColorWindow(65536);double tubeWidth(.008);double sliderLength(.008);double titleHeight(.04);double labelHeight(.04);vtkNew<vtkSliderRepresentation2D> sliderRepN1;sliderRepN1->SetMinimumValue(0.0);sliderRepN1->SetMaximumValue(1.0);sliderRepN1->SetValue(0.5);sliderRepN1->SetTitleText("Opacity");sliderRepN1->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedDisplay();sliderRepN1->GetPoint1Coordinate()->SetValue(.1, .1);sliderRepN1->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedDisplay();sliderRepN1->GetPoint2Coordinate()->SetValue(.9, .1);sliderRepN1->SetTubeWidth(tubeWidth);sliderRepN1->SetSliderLength(sliderLength);sliderRepN1->SetTitleHeight(titleHeight);sliderRepN1->SetLabelHeight(labelHeight);vtkNew<vtkSliderWidget> sliderWidgetN1;sliderWidgetN1->SetInteractor(renderWindowInteractor);sliderWidgetN1->SetRepresentation(sliderRepN1);sliderWidgetN1->SetAnimationModeToAnimate();sliderWidgetN1->EnabledOn();vtkNew<SliderCallbackN1> callbackN1;callbackN1->imgBlender = imgBlender;sliderWidgetN1->AddObserver(vtkCommand::InteractionEvent, callbackN1);// Setup renderers.renderer->AddViewProp(imageSlice);renderer->ResetCamera();renderer->SetBackground(colors->GetColor3d("NavajoWhite").GetData());renderWindow->Render();renderWindowInteractor->Initialize();renderWindowInteractor->Start();return EXIT_SUCCESS;
}
这篇关于vtkImageData融合显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!