9 #include "visuVTKAdaptor/SPlaneList.hpp" 11 #include "visuVTKAdaptor/SPlane.hpp" 13 #include <fwCom/Signal.hpp> 14 #include <fwCom/Signal.hxx> 15 #include <fwCom/Slot.hpp> 16 #include <fwCom/Slot.hxx> 17 #include <fwCom/Slots.hpp> 18 #include <fwCom/Slots.hxx> 20 #include <fwData/Boolean.hpp> 21 #include <fwData/Plane.hpp> 22 #include <fwData/PlaneList.hpp> 24 #include <fwServices/macros.hpp> 27 #include <vtkAssemblyNode.h> 28 #include <vtkAssemblyPath.h> 29 #include <vtkCellPicker.h> 30 #include <vtkCommand.h> 31 #include <vtkPolyDataMapper.h> 32 #include <vtkRenderer.h> 33 #include <vtkRenderWindowInteractor.h> 40 static const ::fwCom::Signals::SignalKeyType s_SELECTED_SIG =
"selected";
42 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SELECTION_SLOT =
"updateSelection";
43 static const ::fwCom::Slots::SlotKeyType s_UPDATE_PLANES_SLOT =
"updatePlanes";
44 static const ::fwCom::Slots::SlotKeyType s_SHOW_PLANES_SLOT =
"showPlanes";
46 static const ::fwServices::IService::KeyType s_PLANES_INOUT =
"planes";
50 void notifyDeletePlane( ::fwData::PlaneList::sptr planeList, ::fwData::Plane::sptr plane )
54 sig->asyncEmit(plane);
70 m_picker( vtkCellPicker::New() ),
71 m_propCollection( vtkPropCollection::New() )
75 m_picker->PickFromListOn();
76 m_picker->SetTolerance(0.001);
86 m_propCollection->Delete();
87 m_propCollection = NULL;
94 m_picker->InitializePickList();
95 m_propCollection->RemoveAllItems();
97 m_propCollection->InitTraversal();
101 while ( (prop = m_propCollection->GetNextProp()) )
103 m_picker->AddPickList(prop);
109 virtual void Execute( vtkObject* caller,
unsigned long eventId,
void*)
114 if ( eventId == vtkCommand::RightButtonPressEvent )
116 std::copy(pos, pos+1, m_lastPos);
117 m_display[0] = pos[0];
118 m_display[1] = pos[1];
120 this->fillPickList();
121 if (m_picker->Pick( m_display, m_service->
getRenderer() ) )
123 if(getSelectedPlane())
129 m_pickedPlane.reset();
133 else if ( eventId == vtkCommand::RightButtonReleaseEvent &&
134 std::equal(pos, pos+1, m_lastPos) && !m_pickedPlane.expired() )
137 ::fwData::Plane::sptr planeBackup(m_pickedPlane);
140 SLM_ASSERT(
"PlaneList '" + s_PLANES_INOUT +
"' is missing", planeList);
142 planeList->getPlanes().erase
144 std::find( planeList->getPlanes().begin(), planeList->getPlanes().end(), m_pickedPlane.lock())
146 notifyDeletePlane(planeList, planeBackup);
151 bool getSelectedPlane()
154 vtkPropCollection* propc = m_picker->GetActors();
157 propc->InitTraversal();
158 while ( (prop = propc->GetNextProp()) )
163 m_pickedPlane = planeAdaptor->getInOut<
::fwData::Plane >(SPlane::s_PLANE_INOUT);
166 SLM_ASSERT(
"PlaneList '" + s_PLANES_INOUT +
"' is missing", planeList);
168 if(!planeList->getPlanes().empty())
170 ::fwData::PlaneList::PlaneListContainer::iterator itr = std::find(
171 planeList->getPlanes().begin(), planeList->getPlanes().end(), m_pickedPlane.lock());
172 if(itr != planeList->getPlanes().end() )
186 vtkPropCollection* m_propCollection;
189 ::fwData::Plane::wptr m_pickedPlane;
195 SPlaneList::SPlaneList() noexcept :
196 m_rightButtonCommand(
nullptr),
197 m_planeCollectionId(
"")
200 newSlot(s_UPDATE_PLANES_SLOT, &SPlaneList::updatePlanes,
this);
201 newSlot(s_SHOW_PLANES_SLOT, &SPlaneList::showPlanes,
this);
203 newSignal< SelectedignalType >(s_SELECTED_SIG);
208 SPlaneList::~SPlaneList() noexcept
216 this->configureParams();
218 const ConfigType config = this->getConfigTree().get_child(
"config.<xmlattr>");
220 this->setPlaneCollectionId( config.get(
"planecollection",
"") );
229 m_rightButtonCommand = vtkPlaneDeleteCallBack::New(
this);
230 this->getInteractor()->AddObserver(
"RightButtonPressEvent", m_rightButtonCommand, 1 );
231 this->getInteractor()->AddObserver(
"RightButtonReleaseEvent", m_rightButtonCommand, 1 );
240 ::fwData::PlaneList::sptr planeList = this->getInOut< ::fwData::PlaneList >(s_PLANES_INOUT);
241 SLM_ASSERT(
"PlaneList '" + s_PLANES_INOUT +
"' is missing", planeList);
243 bool showPlanes = planeList->getField(
"ShowPlanes", ::fwData::Boolean::New(
true))->value();
246 for(const ::fwData::Plane::sptr& plane : planeList->getPlanes())
249 auto servicePlane = this->registerService< ::fwRenderVTK::IAdaptor>(
"::visuVTKAdaptor::SPlane");
250 servicePlane->registerInOut(plane, SPlane::s_PLANE_INOUT,
true);
252 servicePlane->setRenderService(this->getRenderService());
253 servicePlane->setRendererId(this->getRendererId());
254 servicePlane->setPickerId(this->getPickerId());
256 if (!m_planeCollectionId.empty())
258 SPlane::dynamicCast(servicePlane)->setVtkPlaneCollection( this->getVtkObject(m_planeCollectionId) );
260 servicePlane->start();
263 s_UPDATE_SELECTION_SLOT);
270 void SPlaneList::updatePlanes()
274 this->setVtkPipelineModified();
275 this->requestRender();
280 void SPlaneList::showPlanes(
bool visible)
287 this->setVtkPipelineModified();
288 this->requestRender();
295 auto subServices = this->getRegisteredServices();
296 for (const ::fwServices::IService::wptr& adaptor: subServices)
298 SPlane::sptr planeAdaptor = SPlane::dynamicCast(adaptor.lock());
300 if (planeAdaptor->getInOut< ::
fwData::Plane >(SPlane::s_PLANE_INOUT) == plane)
302 planeAdaptor->selectPlane(
true);
306 planeAdaptor->selectPlane(
false);
310 auto sig = this->signal< SelectedignalType >(s_SELECTED_SIG);
311 sig->asyncEmit(plane);
318 if ( m_rightButtonCommand )
320 this->getInteractor()->RemoveObserver(m_rightButtonCommand);
321 m_rightButtonCommand->Delete();
322 m_rightButtonCommand = 0;
324 m_planeConnections.disconnect();
326 this->unregisterServices();
FWRENDERVTK_API vtkRenderWindowInteractor * getInteractor()
Returns the render interactor.
This class is a helper to define the connections of a service and its data.
void updateSelection(::fwData::Plane::sptr plane)
Slot: Update plane selection.
This class defines a plane defined by tree points.
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
FWRENDERVTK_API IAdaptor::sptr getAssociatedAdaptor(vtkProp *prop, int depth)
Returns the adaptor associated to the vtkProp.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_PLANE_REMOVED_SIG
Signal emitted when a plane is added.
static VISUVTKADAPTOR_APIconst::fwCom::Signals::SignalKeyType s_INTERACTION_STARTED_SIG
Type of signal when plane interaction is started (store current plane)
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRENDERVTK_API void getAllSubProps(vtkPropCollection *propc, int depth=-1)
Gets all the vtkProp associated to this adaptor.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
This class defines a list of planes.
std::shared_ptr< DATATYPE > getInOut(const KeyType &key) const
Return the inout object at the given key. Asserts if the data is not of the right type...
Represents a list of Plane that can be interacted with 3 points.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
Base class for VTK adaptors.