7 #include "vtkSimpleMesh/SSimpleMeshDeformation.hpp" 9 #include <fwCom/Signal.hxx> 10 #include <fwCom/Slots.hxx> 12 #include <fwData/Mesh.hpp> 13 #include <fwData/mt/ObjectReadLock.hpp> 14 #include <fwData/mt/ObjectReadToWriteLock.hpp> 16 #include <fwDataTools/Mesh.hpp> 18 #include <fwServices/macros.hpp> 19 #include <fwServices/registry/ActiveWorkers.hpp> 30 const ::fwCom::Slots::SlotKeyType SSimpleMeshDeformation::s_START_DEFORMATION_SLOT =
"startDeformation";
31 const ::fwCom::Slots::SlotKeyType SSimpleMeshDeformation::s_STOP_DEFORMATION_SLOT =
"stopDeformation";
33 static const std::string s_MESH_KEY =
"mesh";
56 ::fwThread::Timer::TimeDurationType duration = std::chrono::milliseconds(200);
59 m_timer->setDuration(duration);
81 auto mesh = this->getInOut< ::fwData::Mesh >(s_MESH_KEY);
84 if ( mesh->getNumberOfPoints() > 0 )
88 this->computeDeformation(m_mesh, m_transformMesh);
95 copyMesh(m_transformMesh, mesh);
100 ::fwData::Mesh::VertexModifiedSignalType::sptr sig;
112 auto mesh = this->getInOut< ::fwData::Mesh >(s_MESH_KEY);
114 meshIsLoaded = mesh->getNumberOfPoints() > 0;
119 this->initMeshBackup();
121 if (!m_timer->isRunning())
132 if (m_timer->isRunning())
135 m_transformMesh.reset();
142 void SSimpleMeshDeformation::copyMesh( const ::fwData::Mesh::sptr& src, const ::fwData::Mesh::sptr& dest )
const 151 void SSimpleMeshDeformation::computeDeformation (
152 const ::fwData::Mesh::sptr& refMesh,
153 const ::fwData::Mesh::sptr& transformMesh,
154 float deformationPercent )
156 SLM_ASSERT(
"Deformation range must be equal to [0,1]", 0 <= deformationPercent && deformationPercent <= 1 );
158 const float maxDeformation = 15/100.0f;
159 const float center = 2/3.0f;
164 ::fwData::Mesh::PointsMultiArrayType points = meshHelper.
getPoints();
165 ::fwData::Mesh::PointsMultiArrayType pointsTransform = transformMeshHelper.
getPoints();
166 ::fwData::Mesh::PointColorsMultiArrayType colorTransform = transformMeshHelper.
getPointColors();
168 size_t nbPts = refMesh->getNumberOfPoints();
171 float ymin = points[0][1];
172 float ymax = points[0][1];
173 for(
size_t i = 0; i != nbPts; ++i)
175 const float val = points[i][1];
180 else if ( val > ymax )
187 float sizeRef = ymax-ymin;
188 float yref = sizeRef * center + ymin;
189 float strafe = maxDeformation * sizeRef;
190 float currentStrafe = deformationPercent * strafe;
192 for(
size_t i = 0; i < nbPts; ++i )
194 float y = points[i][1];
197 float val = ( yref - y ) / ( yref - ymin ) * currentStrafe;
198 pointsTransform[i][1] = y - val;
199 colorTransform[i][0] = 255;
200 colorTransform[i][1] =
static_cast<fwData::Mesh::ColorValueType
>(255 - 255 * ( val / strafe ));
201 colorTransform[i][2] =
static_cast<fwData::Mesh::ColorValueType
>(255 - 255 * ( val / strafe ));
205 colorTransform[i][0] = 255;
206 colorTransform[i][1] = 255;
207 colorTransform[i][2] = 255;
216 void SSimpleMeshDeformation::computeDeformation(
217 const ::fwData::Mesh::sptr& refMesh,
218 const ::fwData::Mesh::sptr& transformMesh )
222 m_currentDeformation += m_currentIncrement;
223 if ( m_currentDeformation == 100 )
225 m_currentIncrement = -step;
227 else if ( m_currentDeformation == 0 )
229 m_currentIncrement = step;
231 this->computeDeformation( refMesh, transformMesh, m_currentDeformation/100.0f );
236 void SSimpleMeshDeformation::initMeshBackup()
238 SLM_WARN_IF(
"Data already init", m_transformMesh || m_mesh);
239 if (!m_mesh && !m_transformMesh)
241 m_currentIncrement = 0;
242 m_currentDeformation = 0;
244 auto mesh = this->getInOut< ::fwData::Mesh >(s_MESH_KEY);
249 mesh->allocatePointColors( ::fwData::Mesh::RGB );
#define SLM_TRACE_FUNC()
Trace contextual function signature.
A helper to lock object on upgradable mode.
FWCORE_API void stop()
Stop the timer. stop() will not reset the timer.
A helper to lock object on read mode.
#define OSLM_INFO(message)
FWCORE_API::fwCore::HiResClock::HiResClockType getElapsedTimeInMilliSec()
This interface defines control service API. Does nothing particularly, can be considered as a default...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_API::fwData::Object::sptr copy(const ::fwData::Object::csptr &source)
return a copy of the source. if source is a null pointer, return a null pointer.
The namespace vtkSimpleMesh contains a service which renders one mesh (fwData::Mesh).
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VERTEX_MODIFIED_SIG
Key in m_signals map of signal m_sigVertexModified.
FWCORE_API void reset(::fwCore::HiResClock::HiResClockType initial_value=0.)
Reset the timer and leave it in the same state it was (started or stopped).
FWCORE_API void start()
Start the timer.
std::shared_ptr< ::fwThread::Worker > m_associatedWorker
Associated worker.
Data holding a geometric structure composed of points, lines, triangles, quads or polygons...
#define SLM_WARN_IF(message, cond)