Skip to content

Commit

Permalink
[Backup] PoC work on burning+cutting directly inside the graspers
Browse files Browse the repository at this point in the history
  • Loading branch information
epernod committed Jan 24, 2025
1 parent efc82cc commit 3956b3c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 27 deletions.
93 changes: 66 additions & 27 deletions src/InfinyToolkit/InteractionTools/ArticulatedToolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ ArticulatedToolManager::ArticulatedToolManager()
, d_isCutter(initData(&d_isCutter, false, "isCutter", "if true, will draw slices BB, ray and intersected triangles"))
, d_isControlled(initData(&d_isControlled, false, "isControlled", "if true, will draw slices BB, ray and intersected triangles"))
, d_drawContacts(initData(&d_drawContacts, false, "drawContacts", "if true, will draw slices BB, ray and intersected triangles"))
, d_manageBurning(initData(&d_manageBurning, false, "manageBurning", "if true, will draw slices BB, ray and intersected triangles"))
, m_vtexcoords(initData(&m_vtexcoords, "texcoords", "coordinates of the texture"))
{
this->f_listening.setValue(true);
m_idgrabed.clear();
Expand Down Expand Up @@ -138,6 +140,15 @@ void ArticulatedToolManager::init()
l_jawModel1->setTargetModel(l_targetModel.get());
l_jawModel2->setTargetModel(l_targetModel.get());


if (d_manageBurning.getValue())
{
TetrahedronSetTopologyContainer* tetraCon;
l_targetModel->getContext()->get(tetraCon);

m_vtexcoords.createTopologyHandler(tetraCon);
}

sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
}

Expand Down Expand Up @@ -221,6 +232,7 @@ bool ArticulatedToolManager::stopAction()
int ArticulatedToolManager::performSecondaryAction()
{
m_performCut = true;
return 0;
}


Expand All @@ -230,8 +242,8 @@ int ArticulatedToolManager::performSecondaryAction()
if (!d_isCutter.getValue())
return;

sofa::type::vector<int> idGraps1 = l_jawModel1.get()->getRawContactModelIds();
sofa::type::vector<int> idGraps2 = l_jawModel2.get()->getRawContactModelIds();
sofa::type::vector<int> idVGrab1 = l_jawModel1.get()->getRawContactModelIds();
sofa::type::vector<int> idVGrab2 = l_jawModel2.get()->getRawContactModelIds();

// Detect all tetra on the cut path
TetrahedronSetTopologyContainer* tetraCon;
Expand All @@ -241,6 +253,43 @@ int ArticulatedToolManager::performSecondaryAction()
return;
}

std::set<int> idVGrab;
for (auto id : idVGrab1)
{
idVGrab.insert(id);
}

for (auto id : idVGrab2)
{
idVGrab.insert(id);
}

if (m_cutCount < 10)
{

helper::WriteAccessor< Data<VecTexCoord> > texcoords = m_vtexcoords;
if (texcoords.empty())
{
helper::WriteAccessor< Data<VecTexCoord> > texcoords = m_vtexcoords;
texcoords.resize(tetraCon->getNbPoints());
}

float coef = float(m_cutCount + 1) / 10.f;
for (auto id : idVGrab)
{
texcoords[id][0] = coef;
texcoords[id][1] = coef;
}

m_cutCount++;
return;
}


m_cutCount = 0;



TetrahedronSetTopologyModifier* tetraModif;
tetraCon->getContext()->get(tetraModif);

Expand All @@ -251,44 +300,34 @@ int ArticulatedToolManager::performSecondaryAction()

// First get all tetra that are on the first side
sofa::type::vector<sofa::core::topology::Topology::TetrahedronID> tetraIds;
for (auto id : idGraps1)
std::map< sofa::core::topology::Topology::TetrahedronID, int> tetraCounter;
for (auto id : idVGrab)
{
const BaseMeshTopology::TetrahedraAroundVertex& tetraAV = tetraCon->getTetrahedraAroundVertex(id);
for (int j = 0; j < tetraAV.size(); ++j)
{
int tetraId = tetraAV[j];
bool found = false;
for (int k = 0; k < tetraIds.size(); ++k)
if (tetraIds[k] == tetraId)
{
found = true;
break;
}

if (!found)
tetraIds.push_back(tetraId);
auto elem = tetraCounter.find(tetraId);
if (elem == tetraCounter.end()) // first time
{
tetraCounter[tetraId] = 1;
}
else
{
tetraCounter[tetraId] = elem->second + 1;
}
}
}

for (auto id : idGraps2)
for (auto elem : tetraCounter)
{
const BaseMeshTopology::TetrahedraAroundVertex& tetraAV = tetraCon->getTetrahedraAroundVertex(id);
for (int j = 0; j < tetraAV.size(); ++j)
if (elem.second > 1)
{
int tetraId = tetraAV[j];
bool found = false;
for (int k = 0; k < tetraIds.size(); ++k)
if (tetraIds[k] == tetraId)
{
found = true;
break;
}

if (!found)
tetraIds.push_back(tetraId);
tetraIds.push_back(elem.first);
}
}

std::cout << "tetra2Rmove: " << tetraIds << std::endl;

// remove springs first
Expand Down
7 changes: 7 additions & 0 deletions src/InfinyToolkit/InteractionTools/ArticulatedToolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class SOFA_INFINYTOOLKIT_API ArticulatedToolManager : public core::objectmodel::
using RigidCoord = sofa::defaulttype::RigidTypes::Coord;
using ContactVector = type::vector<core::collision::DetectionOutput>;

using TexCoord = sofa::type::Vec<2, float>;
using VecTexCoord = type::vector<TexCoord>;

protected:
ArticulatedToolManager();

Expand Down Expand Up @@ -108,6 +111,9 @@ class SOFA_INFINYTOOLKIT_API ArticulatedToolManager : public core::objectmodel::
Data<bool> d_isControlled;
Data<bool> d_drawContacts; ///< if true, draw the collision outputs

Data<bool> d_manageBurning; ///< if true, draw the collision outputs
core::topology::PointData< VecTexCoord > m_vtexcoords; ///< coordinates of the texture

protected:
// Buffer of points ids
sofa::type::vector <int> m_idgrabed;
Expand All @@ -118,6 +124,7 @@ class SOFA_INFINYTOOLKIT_API ArticulatedToolManager : public core::objectmodel::
BaseJawModel::SPtr m_jawModel2 = nullptr;

bool m_performCut = false;
int m_cutCount = 0;
};


Expand Down

0 comments on commit 3956b3c

Please sign in to comment.