7 #include "visuVTKAdaptor/STransform.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 12 #include <fwData/Boolean.hpp> 13 #include <fwData/Material.hpp> 14 #include <fwData/mt/ObjectReadLock.hpp> 15 #include <fwData/mt/ObjectWriteLock.hpp> 16 #include <fwData/Reconstruction.hpp> 17 #include <fwData/TransformationMatrix3D.hpp> 19 #include <fwServices/macros.hpp> 21 #include <vtkCommand.h> 22 #include <vtkMatrix4x4.h> 23 #include <vtkRenderWindowInteractor.h> 24 #include <vtkTransform.h> 35 cb->m_adaptor = adaptor;
49 virtual void Execute( ::vtkObject* pCaller,
unsigned long,
void* )
62 const ::fwServices::IService::KeyType STransform::s_TM3D_INOUT =
"tm3d";
66 STransform::STransform() noexcept :
74 STransform::~STransform() noexcept
76 if( m_transformCommand )
78 m_transformCommand->Delete();
80 m_transformCommand =
nullptr;
85 void STransform::configuring()
87 this->configureParams();
89 const ConfigType config = this->getConfigTree().get_child(
"config.<xmlattr>");
91 m_parentId = config.get< std::string >(
"parent",
"");
96 void STransform::starting()
100 if(!m_transformId.empty())
102 m_renderService.lock()->getOrAddVtkTransform(m_transformId);
104 if(!m_parentId.empty())
106 m_parentTransform = m_renderService.lock()->getOrAddVtkTransform(m_parentId);
110 this->getTransform()->AddObserver( ::vtkCommand::ModifiedEvent, m_transformCommand );
115 void STransform::updateFromVtk()
117 vtkTransform* vtkTrf = this->getTransform();
119 vtkTrf->RemoveObserver( m_transformCommand );
120 ::fwData::TransformationMatrix3D::sptr trf = this->getInOut< ::fwData::TransformationMatrix3D >(s_TM3D_INOUT);
121 SLM_ASSERT(
"matrix '" + s_TM3D_INOUT +
"' is not defined", trf);
123 vtkMatrix4x4* mat =
nullptr;
125 if(m_parentTransform)
128 mat = vtkTrf->GetConcatenatedTransform(0)->GetMatrix();
132 mat = vtkTrf->GetMatrix();
137 for(
int lt = 0; lt < 4; lt++)
139 for(
int ct = 0; ct < 4; ct++)
141 trf->setCoefficient(static_cast<size_t>(lt), static_cast<size_t>(ct), mat->GetElement(lt, ct));
152 vtkTrf->AddObserver( ::vtkCommand::ModifiedEvent, m_transformCommand );
157 void STransform::updating()
159 vtkTransform* vtkTrf = this->getTransform();
161 vtkTrf->RemoveObserver( m_transformCommand );
162 ::fwData::TransformationMatrix3D::sptr trf = this->getInOut< ::fwData::TransformationMatrix3D >(s_TM3D_INOUT);
163 SLM_ASSERT(
"matrix '" + s_TM3D_INOUT +
"' is not defined", trf);
165 vtkMatrix4x4* mat = vtkMatrix4x4::New();
169 for(
int lt = 0; lt < 4; lt++)
171 for(
int ct = 0; ct < 4; ct++)
173 mat->SetElement(lt, ct, trf->getCoefficient(static_cast<size_t>(lt), static_cast<size_t>(ct)));
178 if(m_parentTransform)
180 vtkTrf->PostMultiply();
181 vtkTrf->SetMatrix( mat );
182 vtkTrf->Concatenate( m_parentTransform );
186 vtkTrf->SetMatrix(mat);
190 vtkTrf->AddObserver( ::vtkCommand::ModifiedEvent, m_transformCommand );
192 this->setVtkPipelineModified();
193 this->requestRender();
198 void STransform::setTransform(vtkTransform* t)
200 if ( m_transform != t )
204 m_transform->Delete();
208 t->Register(
nullptr);
216 vtkTransform* STransform::getTransform()
218 vtkTransform* t = m_transform;
221 t = this->IAdaptor::getTransform();
228 void STransform::swapping()
235 void STransform::stopping()
237 this->getTransform()->RemoveObserver(m_transformCommand);
This class is a helper to define the connections of a service and its data.
Class allowing to block a Connection.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
A helper to lock object on read mode.
A helper to lock object on exclusive mode.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Base class for VTK adaptors.