7 #include "visuVTKAdaptor/SVectorField.hpp" 9 #include <fwData/Boolean.hpp> 10 #include <fwData/Color.hpp> 11 #include <fwData/Image.hpp> 12 #include <fwData/String.hpp> 13 #include <fwData/TransferFunction.hpp> 15 #include <fwDataTools/fieldHelper/Image.hpp> 16 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 18 #include <fwRenderVTK/vtk/fwVtkWindowLevelLookupTable.hpp> 20 #include <fwServices/macros.hpp> 22 #include <fwVtkIO/helper/TransferFunction.hpp> 23 #include <fwVtkIO/vtk.hpp> 26 #include <vtkArrowSource.h> 27 #include <vtkAssignAttribute.h> 28 #include <vtkGlyph3D.h> 29 #include <vtkGlyph3DMapper.h> 30 #include <vtkGlyphSource2D.h> 31 #include <vtkImageData.h> 32 #include <vtkMaskPoints.h> 33 #include <vtkPointData.h> 34 #include <vtkPolyDataMapper.h> 41 static const ::fwServices::IService::KeyType s_IMAGE_INPUT =
"image";
45 SVectorField::SVectorField() noexcept
47 m_imageData = vtkSmartPointer<vtkImageData>::New();
52 SVectorField::~SVectorField() noexcept
68 this->destroyPipeline();
75 ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_IMAGE_INPUT);
78 if (imageIsValid && image->getNumberOfComponents() == 3)
80 this->buildPipeline();
84 this->destroyPipeline();
97 void SVectorField::buildPipeline( )
99 ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_IMAGE_INPUT);
101 ::fwVtkIO::toVTKImage(image, m_imageData);
103 vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();
105 m_arrowSource = arrowSource;
107 vtkSmartPointer<vtkMaskPoints> ptMask = vtkSmartPointer<vtkMaskPoints>::New();
109 ptMask->SetInputData(m_imageData);
110 ptMask->SetOnRatio(1);
111 ptMask->RandomModeOn();
114 #ifndef USE_GPU_GLYPH 115 ptMask->SetMaximumNumberOfPoints(5000);
117 vtkSmartPointer<vtkGlyph3D> glyphFilter = vtkSmartPointer<vtkGlyph3D>::New();
118 glyphFilter->SetSourceConnection(m_arrowSource->GetOutputPort());
120 glyphFilter->ScalingOn();
122 glyphFilter->SetVectorModeToUseVector();
124 glyphFilter->OrientOn();
126 glyphFilter->SetInputConnection(ptMask->GetOutputPort());
128 glyphFilter->SetInputArrayToProcess( 1, m_imageData->GetInformation());
130 vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
131 vectorMapper->SetInputConnection(glyphFilter->GetOutputPort());
133 ptMask->SetMaximumNumberOfPoints(15000);
135 vtkSmartPointer<vtkGlyph3DMapper> vectorMapper = vtkSmartPointer<vtkGlyph3DMapper>::New();
136 vectorMapper->SetOrientationArray(vtkDataSetAttributes::SCALARS);
137 vectorMapper->SetSourceConnection(m_arrowSource->GetOutputPort());
138 vectorMapper->OrientOn();
139 vectorMapper->SetInputConnection(ptMask->GetOutputPort());
144 vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();
145 vectorActor->SetMapper(vectorMapper);
155 void SVectorField::destroyPipeline( )
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
This class is a helper to define the connections of a service and its data.
FWRENDERVTK_API void addToRenderer(vtkProp *prop)
Adds the vtkProp to the renderer.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
#define SLM_DEBUG(message)
FWRENDERVTK_API void removeAllPropFromRenderer()
Removes all the vtkProp from the renderer.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image's buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
This adaptor displays vector field contains in a fwData::Image.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Base class for VTK adaptors.