@@ -67,11 +67,13 @@ ArticulatedToolManager::ArticulatedToolManager()
6767 , d_handleFactor(initData(&d_handleFactor, SReal(1.0 ), " handleFactor" , " jaw speed factor." ))
6868 , d_outputPositions(initData(&d_outputPositions, " outputPositions" , " jaw positions." ))
6969 , d_isCutter(initData(&d_isCutter, false , " isCutter" , " if true, will draw slices BB, ray and intersected triangles" ))
70+ , d_cutMaxStep(initData(&d_cutMaxStep, int (10 ), " cutMaxStep" , " number of step before really cutting" ))
71+ , d_cutMode(initData(&d_cutMode, int (0 ), " cutMode" , " mode of cut (debug)" ))
7072 , d_isControlled(initData(&d_isControlled, false , " isControlled" , " if true, will draw slices BB, ray and intersected triangles" ))
7173 , d_drawContacts(initData(&d_drawContacts, false , " drawContacts" , " if true, will draw slices BB, ray and intersected triangles" ))
7274 , d_manageBurning(initData(&d_manageBurning, false , " manageBurning" , " if true, will draw slices BB, ray and intersected triangles" ))
7375 , m_vtexcoords(initData(&m_vtexcoords, " texcoords" , " coordinates of the texture" ))
74- {
76+ {
7577 this ->f_listening .setValue (true );
7678 m_idgrabed.clear ();
7779}
@@ -144,15 +146,24 @@ void ArticulatedToolManager::init()
144146 l_jawModel2->setTargetModel (l_targetModel.get ());
145147
146148
149+ m_cutCount = 0 ;
150+
151+ sofa::core::objectmodel::BaseObject::d_componentState.setValue (sofa::core::objectmodel::ComponentState::Valid);
152+ }
153+
154+
155+ void ArticulatedToolManager::bwdInit ()
156+ {
147157 if (d_manageBurning.getValue ())
148158 {
149159 TetrahedronSetTopologyContainer* tetraCon;
150160 l_targetModel->getContext ()->get (tetraCon);
151161
152162 m_vtexcoords.createTopologyHandler (tetraCon);
163+
164+ helper::WriteAccessor< Data<VecTexCoord> > texcoords = m_vtexcoords;
165+ texcoords.resize (tetraCon->getNbPoints ());
153166 }
154-
155- sofa::core::objectmodel::BaseObject::d_componentState.setValue (sofa::core::objectmodel::ComponentState::Valid);
156167}
157168
158169
@@ -232,16 +243,16 @@ bool ArticulatedToolManager::stopAction()
232243}
233244
234245
235- int ArticulatedToolManager::performSecondaryAction ()
246+ bool ArticulatedToolManager::performSecondaryAction ()
236247{
237248 m_performCut = true ;
238- return 0 ;
249+ return true ;
239250}
240251
241252
242253 void ArticulatedToolManager::performCut ()
243254{
244- msg_warning () << " performSecondaryAction()" ;
255+ // msg_warning() << "performSecondaryAction()";
245256 if (!d_isCutter.getValue ())
246257 return ;
247258
@@ -267,28 +278,25 @@ int ArticulatedToolManager::performSecondaryAction()
267278 idVGrab.insert (id);
268279 }
269280
270- if (m_cutCount < 10 )
281+ const int cutMax = d_cutMaxStep.getValue ();
282+ float invC = 1.0 / float (cutMax);
283+ if (m_cutCount < cutMax)
271284 {
272285
273286 helper::WriteAccessor< Data<VecTexCoord> > texcoords = m_vtexcoords;
274- if (texcoords.empty ())
275- {
276- helper::WriteAccessor< Data<VecTexCoord> > texcoords = m_vtexcoords;
277- texcoords.resize (tetraCon->getNbPoints ());
278- }
279-
280- float coef = float (m_cutCount + 1 ) / 10 .f ;
287+ float coef = float (m_cutCount) * invC;
281288 for (auto id : idVGrab)
282289 {
283290 texcoords[id][0 ] = coef;
284291 texcoords[id][1 ] = coef;
285292 }
293+ }
286294
295+ if (m_cutCount < cutMax * 2 ) {
287296 m_cutCount++;
288297 return ;
289298 }
290299
291-
292300 m_cutCount = 0 ;
293301
294302
@@ -323,11 +331,24 @@ int ArticulatedToolManager::performSecondaryAction()
323331 }
324332 }
325333
326- for (auto elem : tetraCounter)
334+ if (d_cutMode.getValue () == 0 )
335+ {
336+ for (auto elem : tetraCounter)
337+ {
338+ if (elem.second > 0 )
339+ {
340+ tetraIds.push_back (elem.first );
341+ }
342+ }
343+ }
344+ else
327345 {
328- if ( elem. second > 1 )
346+ for ( auto elem : tetraCounter )
329347 {
330- tetraIds.push_back (elem.first );
348+ if (elem.second > 1 )
349+ {
350+ tetraIds.push_back (elem.first );
351+ }
331352 }
332353 }
333354
@@ -341,10 +362,10 @@ int ArticulatedToolManager::performSecondaryAction()
341362 return ;
342363}
343364
344- int ArticulatedToolManager::stopSecondaryAction ()
365+ bool ArticulatedToolManager::stopSecondaryAction ()
345366{
346- msg_warning () << " stopSecondaryAction()" ;
347- return 0 ;
367+ // msg_warning() << "stopSecondaryAction()";
368+ return true ;
348369}
349370
350371
@@ -407,8 +428,8 @@ void ArticulatedToolManager::filterCollision()
407428 sofa::core::CollisionModel* collMod1 = it->first .first ;
408429 sofa::core::CollisionModel* collMod2 = it->first .second ;
409430
410- dmsg_warning () << " collMod1: " << collMod1->getTypeName () << " -> " << collMod1->getContext ()->getName ();
411- dmsg_warning () << " collMod2: " << collMod2->getTypeName () << " -> " << collMod2->getContext ()->getName ();
431+ // dmsg_warning() << "collMod1: " << collMod1->getTypeName() << " -> " << collMod1->getContext()->getName();
432+ // dmsg_warning() << "collMod2: " << collMod2->getTypeName() << " -> " << collMod2->getContext()->getName();
412433
413434
414435 // Get the number of contacts
@@ -467,10 +488,10 @@ void ArticulatedToolManager::filterCollision()
467488 info->normal = c.normal ;
468489 info->dist = c.value ;
469490
470- dmsg_info () << j << " contact: " << c.elem .first .getIndex () << " | " << c.elem .second .getIndex ()
471- << " -> " << " pA: " << c.point [0 ] << " pB: " << c.point [1 ]
472- << " | normal: " << c.normal << " d: " << c.value
473- << " | cDir: " << (c.point [1 ] - c.point [0 ]).normalized () << " d: " << (c.point [1 ] - c.point [0 ]).norm ();
491+ // dmsg_info() << j << " contact: " << c.elem.first.getIndex() << " | " << c.elem.second.getIndex()
492+ // << " -> " << " pA: " << c.point[0] << " pB: " << c.point[1]
493+ // << " | normal: " << c.normal << " d: " << c.value
494+ // << " | cDir: " << (c.point[1] - c.point[0]).normalized() << " d: " << (c.point[1] - c.point[0]).norm();
474495
475496 if (firstJaw)
476497 l_jawModel1->addContact (info);
0 commit comments