7 #include "vtkSimpleNegato/SRenderer.hpp" 9 #include <fwCom/Slot.hpp> 10 #include <fwCom/Slot.hxx> 11 #include <fwCom/Slots.hpp> 12 #include <fwCom/Slots.hxx> 14 #include <fwData/Image.hpp> 16 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 18 #include <fwServices/macros.hpp> 20 #include <fwVtkIO/vtk.hpp> 22 #include <vtkCellPicker.h> 23 #include <vtkCommand.h> 24 #include <vtkImageData.h> 25 #include <vtkLookupTable.h> 26 #include <vtkPolyDataMapper.h> 27 #include <vtkProperty.h> 28 #include <vtkRenderWindow.h> 29 #include <vtkSmartPointer.h> 40 static const ::fwCom::Slots::SlotKeyType s_REFRESH_SLOT =
"refresh";
42 static const std::string s_IMAGE_KEY =
"image";
48 m_bPipelineIsInit(false)
51 newSlot(s_REFRESH_SLOT, &SRenderer::refresh,
this);
75 m_interactorManager = ::fwRenderVTK::IVtkRenderWindowInteractorManager::createManager();
76 m_interactorManager->installInteractor( this->getContainer() );
78 m_bPipelineIsInit =
false;
81 m_render = vtkRenderer::New();
82 m_interactorManager->getInteractor()->GetRenderWindow()->AddRenderer(m_render);
91 if( m_render ==
nullptr )
98 m_negatoSagittal->Delete();
99 m_negatoFrontal->Delete();
100 m_negatoAxial->Delete();
104 SLM_ASSERT(
"m_render not instanced", m_render);
108 m_interactorManager->uninstallInteractor();
109 m_interactorManager.reset();
123 void SRenderer::refresh()
125 auto img = this->getInput< ::fwData::Image >(s_IMAGE_KEY);
126 SLM_ASSERT(
"'" + s_IMAGE_KEY +
"' key not found", img);
130 if(!m_bPipelineIsInit)
133 m_bPipelineIsInit =
true;
141 int axialIndex =
static_cast<int>(img->getSize()[2]/2);
142 int frontalIndex =
static_cast<int>(img->getSize()[1]/2);
143 int sagittalIndex =
static_cast<int>(img->getSize()[0]/2);
145 m_negatoAxial->SetSliceIndex( axialIndex );
146 m_negatoFrontal->SetSliceIndex( frontalIndex );
147 m_negatoSagittal->SetSliceIndex( sagittalIndex );
148 m_interactorManager->getInteractor()->Render();
154 void SRenderer::initVTKPipeline()
156 vtkSmartPointer< vtkImageData > vtkImg = vtkSmartPointer< vtkImageData >::New();
158 auto image = this->getInput< ::fwData::Image >(s_IMAGE_KEY);
159 SLM_ASSERT(
"'" + s_IMAGE_KEY +
"' key not found", image);
160 ::fwVtkIO::toVTKImage( image, vtkImg);
162 m_outline = vtkOutlineFilter::New();
163 m_outline->SetInputData(vtkImg);
165 vtkPolyDataMapper* outlineMapper = vtkPolyDataMapper::New();
166 outlineMapper->SetInputConnection(m_outline->GetOutputPort());
168 vtkActor* outlineActor = vtkActor::New();
169 outlineActor->SetMapper( outlineMapper);
171 vtkCellPicker* picker = vtkCellPicker::New();
172 picker->SetTolerance(0.005);
176 m_negatoSagittal = vtkImagePlaneWidget::New();
177 m_negatoSagittal->SetInteractor( m_interactorManager->getInteractor() );
178 m_negatoSagittal->SetKeyPressActivationValue(
'x');
179 m_negatoSagittal->SetPicker(picker);
180 m_negatoSagittal->GetPlaneProperty()->SetColor(1, 0, 0);
181 m_negatoSagittal->TextureInterpolateOn();
182 m_negatoSagittal->SetInputData(vtkImg);
183 m_negatoSagittal->SetPlaneOrientationToXAxes();
184 m_negatoSagittal->DisplayTextOn();
185 m_negatoSagittal->On();
186 m_negatoSagittal->InteractionOn();
188 m_negatoFrontal = vtkImagePlaneWidget::New();
189 m_negatoFrontal->SetInteractor( m_interactorManager->getInteractor() );
190 m_negatoFrontal->SetKeyPressActivationValue(
'y');
191 m_negatoFrontal->SetPicker(picker);
192 m_negatoFrontal->GetPlaneProperty()->SetColor(0, 1, 0);
193 m_negatoFrontal->TextureInterpolateOn();
194 m_negatoFrontal->SetInputData(vtkImg);
195 m_negatoFrontal->SetPlaneOrientationToYAxes();
196 m_negatoFrontal->SetLookupTable( m_negatoSagittal->GetLookupTable());
197 m_negatoFrontal->DisplayTextOn();
198 m_negatoFrontal->UpdatePlacement();
199 m_negatoFrontal->On();
201 m_negatoAxial = vtkImagePlaneWidget::New();
202 m_negatoAxial->SetInteractor( m_interactorManager->getInteractor() );
203 m_negatoAxial->SetKeyPressActivationValue(
'z');
204 m_negatoAxial->SetPicker(picker);
205 m_negatoAxial->GetPlaneProperty()->SetColor(0, 0, 1);
206 m_negatoAxial->TextureInterpolateOn();
207 m_negatoAxial->SetInputData(vtkImg);
208 m_negatoAxial->SetPlaneOrientationToZAxes();
209 m_negatoAxial->SetLookupTable( m_negatoSagittal->GetLookupTable());
210 m_negatoAxial->DisplayTextOn();
214 m_render->AddActor( outlineActor);
217 m_render->ResetCamera();
220 outlineActor->Delete();
221 outlineMapper->Delete();
226 void SRenderer::updateVTKPipeline()
228 auto image = this->getInput< ::fwData::Image >(s_IMAGE_KEY);
229 SLM_ASSERT(
"'" + s_IMAGE_KEY +
"' key not found", image);
231 vtkSmartPointer< vtkImageData > vtkImg = vtkSmartPointer< vtkImageData >::New();
232 ::fwVtkIO::toVTKImage( image, vtkImg);
234 m_outline->SetInputData(vtkImg);
235 m_negatoSagittal->SetInputData(vtkImg);
236 m_negatoFrontal->SetInputData(vtkImg);
237 m_negatoAxial->SetInputData(vtkImg);
This class is a helper to define the connections of a service and its data.
virtual VTKSIMPLENEGATO_API void stopping() override
Stopping method.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
virtual VTKSIMPLENEGATO_API void configuring() override
This method is used to configure the service.
virtual VTKSIMPLENEGATO_API ~SRenderer() noexcept
Destructor.
The namespace vtkSimpleNegato has a visualization service of medical image (fwData::Image).
Defines the service interface managing the rendering service for object.
VTKSIMPLENEGATO_API SRenderer() noexcept
Constructor.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual VTKSIMPLENEGATO_API void starting() override
Starting method.
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
virtual VTKSIMPLENEGATO_API void updating() override
Updating method.
virtual VTKSIMPLENEGATO_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image's buffer is added.
Service rendering a fwData::Image using VTK.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
This class defines an image.
FWGUI_API void initialize()
Initialize managers.