Skip to content

Commit

Permalink
[Mapping.Linear] Replace a few beginEdit by accessors (#4363)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger committed Dec 17, 2023
1 parent f8653f1 commit 7b1ffe2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
Expand Up @@ -32,15 +32,14 @@ BarycentricMapperEdgeSetTopology<In,Out>::BarycentricMapperEdgeSetTopology(sofa:
{}

template <class In, class Out>
typename BarycentricMapperEdgeSetTopology<In, Out>::Index BarycentricMapperEdgeSetTopology<In,Out>::addPointInLine ( const Index edgeIndex, const SReal* baryCoords )
auto BarycentricMapperEdgeSetTopology<In,Out>::addPointInLine ( const Index edgeIndex, const SReal* baryCoords ) -> Index
{
type::vector<MappingData>& vectorData = *(d_map.beginEdit());
vectorData.resize ( d_map.getValue().size() +1 );
d_map.endEdit();
MappingData& data = *vectorData.rbegin();
auto vectorData = sofa::helper::getWriteAccessor(d_map);
MappingData data;
data.in_index = edgeIndex;
data.baryCoords[0] = ( Real ) baryCoords[0];
return Size(d_map.getValue().size()-1);
data.baryCoords[0] = static_cast<Real>(baryCoords[0]);
vectorData->emplace_back(data);
return static_cast<Index>(vectorData.size() - 1u);
}

template <class In, class Out>
Expand Down
Expand Up @@ -50,32 +50,31 @@ template <class In, class Out>
typename BarycentricMapperHexahedronSetTopology<In, Out>::Index
BarycentricMapperHexahedronSetTopology<In,Out>::addPointInCube ( const Index cubeIndex, const SReal* baryCoords )
{
type::vector<MappingData>& vectorData = *(d_map.beginEdit());
vectorData.resize ( d_map.getValue().size() +1 );
MappingData& data = *vectorData.rbegin();
d_map.endEdit();
auto vectorData = sofa::helper::getWriteAccessor(d_map);
MappingData data;
data.in_index = cubeIndex;
data.baryCoords[0] = ( Real ) baryCoords[0];
data.baryCoords[1] = ( Real ) baryCoords[1];
data.baryCoords[2] = ( Real ) baryCoords[2];
return (int)d_map.getValue().size()-1;
data.baryCoords[0] = static_cast<Real>(baryCoords[0]);
data.baryCoords[1] = static_cast<Real>(baryCoords[1]);
data.baryCoords[2] = static_cast<Real>(baryCoords[2]);
vectorData->emplace_back(data);
return static_cast<Index>(vectorData.size() - 1u);
}


template <class In, class Out>
typename BarycentricMapperHexahedronSetTopology<In, Out>::Index
BarycentricMapperHexahedronSetTopology<In,Out>::setPointInCube ( const Index pointIndex, const Index cubeIndex, const SReal* baryCoords )
{
if ( pointIndex >= d_map.getValue().size() )
auto vectorData = sofa::helper::getWriteAccessor(d_map);

if ( pointIndex >= vectorData.size() )
return sofa::InvalidID;

type::vector<MappingData>& vectorData = *(d_map.beginEdit());
MappingData& data = vectorData[pointIndex];
data.in_index = cubeIndex;
data.baryCoords[0] = ( Real ) baryCoords[0];
data.baryCoords[1] = ( Real ) baryCoords[1];
data.baryCoords[2] = ( Real ) baryCoords[2];
d_map.endEdit();
data.baryCoords[0] = static_cast<Real>(baryCoords[0]);
data.baryCoords[1] = static_cast<Real>(baryCoords[1]);
data.baryCoords[2] = static_cast<Real>(baryCoords[2]);

if(cubeIndex == sofa::InvalidID)
m_invalidIndex.insert(pointIndex);
Expand Down
Expand Up @@ -307,12 +307,11 @@ void BarycentricMapping<TIn, TOut>::applyJ (const core::MechanicalParams * mpara
{
SOFA_UNUSED(mparams);

typename Out::VecDeriv* out = _out.beginEdit();
if (d_mapper != nullptr)
{
d_mapper->applyJ(*out, in.getValue());
auto outWriteAccessor = sofa::helper::getWriteAccessor(_out);
d_mapper->applyJ(outWriteAccessor.wref(), in.getValue());
}
_out.endEdit();
}


Expand All @@ -323,8 +322,8 @@ void BarycentricMapping<TIn, TOut>::applyJT (const core::MechanicalParams * mpar

if (d_mapper != nullptr)
{
d_mapper->applyJT(*out.beginEdit(), in.getValue());
out.endEdit();
auto outWriteAccessor = sofa::helper::getWriteAccessor(out);
d_mapper->applyJT(outWriteAccessor.wref(), in.getValue());
}
}

Expand Down Expand Up @@ -376,8 +375,8 @@ void BarycentricMapping<TIn, TOut>::applyJT(const core::ConstraintParams * cpara

if (d_mapper!=nullptr )
{
d_mapper->applyJT(*out.beginEdit(), in.getValue());
out.endEdit();
auto outWriteAccessor = sofa::helper::getWriteAccessor(out);
d_mapper->applyJT(outWriteAccessor.wref(), in.getValue());
}
}

Expand Down

0 comments on commit 7b1ffe2

Please sign in to comment.