Skip to content

Commit 52f94bd

Browse files
committed
[backup] save new behavior of grasper with cutter. Need to clean the code as soon as demo has been validated
1 parent 7d41eae commit 52f94bd

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

src/InfinyToolkit/InteractionTools/ArticulatedToolManager.cpp

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/InfinyToolkit/InteractionTools/ArticulatedToolManager.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class SOFA_INFINYTOOLKIT_API ArticulatedToolManager : public core::objectmodel::
5454

5555
public:
5656
virtual void init() override;
57+
58+
/// Sofa API init method of the component
59+
void bwdInit() override;
5760
int testModels();
5861

5962
const sofa::type::vector< int >& vertexIdsInBroadPhase() { return m_idBroadPhase; }
@@ -70,8 +73,8 @@ class SOFA_INFINYTOOLKIT_API ArticulatedToolManager : public core::objectmodel::
7073
int performAction();
7174
bool stopAction();
7275

73-
int performSecondaryAction();
74-
int stopSecondaryAction();
76+
bool performSecondaryAction();
77+
bool stopSecondaryAction();
7578

7679
void closeTool();
7780
void openTool();
@@ -108,6 +111,8 @@ class SOFA_INFINYTOOLKIT_API ArticulatedToolManager : public core::objectmodel::
108111

109112
Data <type::vector<RigidCoord> > d_outputPositions;
110113
Data<bool> d_isCutter;
114+
Data<int> d_cutMaxStep;
115+
Data<int> d_cutMode;
111116
Data<bool> d_isControlled;
112117
Data<bool> d_drawContacts; ///< if true, draw the collision outputs
113118

@@ -124,6 +129,7 @@ class SOFA_INFINYTOOLKIT_API ArticulatedToolManager : public core::objectmodel::
124129
BaseJawModel::SPtr m_jawModel2 = nullptr;
125130

126131
bool m_performCut = false;
132+
127133
int m_cutCount = 0;
128134
};
129135

0 commit comments

Comments
 (0)