Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ void BarycentricMapperRegularGridTopology<In,Out>::apply ( typename Out::VecCoor
{
out.resize( m_map.size() );

// the resolution of the grid read once (getHexaCopy(Index) reads the Data)
const auto& n = this->m_fromTopology->d_n.getValue();
for ( unsigned int i=0; i<m_map.size(); i++ )
{
const topology::container::grid::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[i].in_index );
const topology::container::grid::RegularGridTopology::Hexa cube = RegularGridTopology::getHexaCopy ( n, this->m_map[i].in_index );

const Real fx = m_map[i].baryCoords[0];
const Real fy = m_map[i].baryCoords[1];
Expand All @@ -127,9 +129,10 @@ void BarycentricMapperRegularGridTopology<In,Out>::applyJ ( typename Out::VecDer
{
out.resize( m_map.size() );

const auto& n = this->m_fromTopology->d_n.getValue();
for( size_t index=0 ; index< out.size() ; ++index)
{
const topology::container::grid::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index );
const topology::container::grid::RegularGridTopology::Hexa cube = RegularGridTopology::getHexaCopy ( n, this->m_map[index].in_index );

const Real fx = m_map[index].baryCoords[0];
const Real fy = m_map[index].baryCoords[1];
Expand All @@ -148,10 +151,11 @@ void BarycentricMapperRegularGridTopology<In,Out>::applyJ ( typename Out::VecDer
template <class In, class Out>
void BarycentricMapperRegularGridTopology<In,Out>::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in )
{
const auto& n = this->m_fromTopology->d_n.getValue();
for( size_t index=0 ; index<in.size() ; ++index)
{
const typename Out::DPos v = Out::getDPos(in[index]);
const topology::container::grid::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index );
const topology::container::grid::RegularGridTopology::Hexa cube = RegularGridTopology::getHexaCopy ( n, this->m_map[index].in_index );

const OutReal fx = ( OutReal ) m_map[index].baryCoords[0];
const OutReal fy = ( OutReal ) m_map[index].baryCoords[1];
Expand Down Expand Up @@ -185,11 +189,12 @@ const sofa::linearalgebra::BaseMatrix* BarycentricMapperRegularGridTopology<In,O
else
m_matrixJ->clear();

const auto& n = this->m_fromTopology->d_n.getValue();
for ( size_t i=0; i<m_map.size(); i++ )
{
const int out = int(i);

const topology::container::grid::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[i].in_index );
const topology::container::grid::RegularGridTopology::Hexa cube = RegularGridTopology::getHexaCopy ( n, this->m_map[i].in_index );

const Real fx = ( Real ) m_map[i].baryCoords[0];
const Real fy = ( Real ) m_map[i].baryCoords[1];
Expand Down Expand Up @@ -219,10 +224,11 @@ void BarycentricMapperRegularGridTopology<In,Out>::draw (const core::visual::Vi
{
std::vector< Vec3 > points;

const auto& n = this->m_fromTopology->d_n.getValue();
for ( unsigned int i=0; i<m_map.size(); i++ )
{

const topology::container::grid::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[i].in_index );
const topology::container::grid::RegularGridTopology::Hexa cube = RegularGridTopology::getHexaCopy ( n, this->m_map[i].in_index );

const Real fx = m_map[i].baryCoords[0];
const Real fy = m_map[i].baryCoords[1];
Expand Down Expand Up @@ -256,6 +262,7 @@ template <class In, class Out>
void BarycentricMapperRegularGridTopology<In,Out>::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in )
{
typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end();
const auto& n = this->m_fromTopology->d_n.getValue();

for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt)
{
Expand All @@ -271,7 +278,7 @@ void BarycentricMapperRegularGridTopology<In,Out>::applyJT ( typename In::Matrix
unsigned int indexIn = colIt.index();
InDeriv data = (InDeriv) Out::getDPos(colIt.val());

const topology::container::grid::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[indexIn].in_index );
const topology::container::grid::RegularGridTopology::Hexa cube = RegularGridTopology::getHexaCopy ( n, this->m_map[indexIn].in_index );

const OutReal fx = (OutReal) m_map[indexIn].baryCoords[0];
const OutReal fy = (OutReal) m_map[indexIn].baryCoords[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ void GridTopology::computePointList()

GridTopology::Index GridTopology::getIndex( int i, int j, int k ) const
{
const auto& n = d_n.getValue();
return Index(n[0]* ( n[1]*k + j ) + i);
return getIndex(d_n.getValue(), i, j, k);
}


Expand Down Expand Up @@ -380,21 +379,28 @@ sofa::type::Vec3 GridTopology::getPointInGrid(int i, int j, int k) const

GridTopology::Hexa GridTopology::getHexaCopy(Index i)
{
const auto& n = d_n.getValue();
return getHexaCopy(d_n.getValue(), i);
}

GridTopology::Hexa GridTopology::getHexahedron(int x, int y, int z)
{
return getHexahedron(d_n.getValue(), x, y, z);
}

GridTopology::Hexa GridTopology::getHexaCopy(const type::Vec3i& n, Index i)
{
const int x = i%(n[0]-1); i/=(n[0]-1);
const int y = i%(n[1]-1); i/=(n[1]-1);
const int z = int(i);
return getHexahedron(x,y,z);
return getHexahedron(n, x, y, z);
}

GridTopology::Hexa GridTopology::getHexahedron(int x, int y, int z)
GridTopology::Hexa GridTopology::getHexahedron(const type::Vec3i& n, int x, int y, int z)
{

return Hexa(point(x ,y ,z ),point(x+1,y ,z ),
point(x+1,y+1,z ),point(x ,y+1,z ),
point(x ,y ,z+1),point(x+1,y ,z+1),
point(x+1,y+1,z+1),point(x ,y+1,z+1));
return Hexa(getIndex(n, x ,y ,z ),getIndex(n, x+1,y ,z ),
getIndex(n, x+1,y+1,z ),getIndex(n, x ,y+1,z ),
getIndex(n, x ,y ,z+1),getIndex(n, x+1,y ,z+1),
getIndex(n, x+1,y+1,z+1),getIndex(n, x ,y+1,z+1));
}

GridTopology::Quad GridTopology::getQuadCopy(Index i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ using MeshTopology::getHexahedron;

/// Get the one-dimensional index of a grid point given its @param i @param j @param k indices
Index getIndex( int i, int j, int k ) const;
/// Get the one-dimensional index of the point @param i @param j @param k of a grid of resolution @param n
static Index getIndex( const type::Vec3i& n, int i, int j, int k ) { return Index(n[0]* ( n[1]*k + j ) + i); }

/// Overwrite from @sa MeshTopology::hasPos always @return bool true
bool hasPos() const override { return true; }
Expand Down Expand Up @@ -170,6 +172,10 @@ using MeshTopology::getHexahedron;

Hexa getHexahedron(int x, int y, int z);
Hexa getHexaCopy(Index i);
/// Get the hexahedron of the cell @param x @param y @param z of a grid of resolution @param n
static Hexa getHexahedron(const type::Vec3i& n, int x, int y, int z);
/// Get the hexahedron of index @param i of a grid of resolution @param n
static Hexa getHexaCopy(const type::Vec3i& n, Index i);
Quad getQuadCopy(Index i);

/// Get Point index in Grid, will call method @sa getIndex
Expand Down
29 changes: 29 additions & 0 deletions examples/Benchmark/Performance/BarycentricMapping_regulargrid.scn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<Node name="root" gravity="0 0 0" dt="0.01">

<Node name="plugins">
<RequiredPlugin pluginName="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshOBJLoader] -->
<RequiredPlugin pluginName="Sofa.GL.Component.Rendering3D"/> <!-- Needed to use components [OglModel] -->
<RequiredPlugin pluginName="Sofa.Component.IntegrationScheme.Forward"/> <!-- Needed to use components [EulerExplicitIntegrationScheme] -->
<RequiredPlugin pluginName="Sofa.Component.Mapping.Linear"/> <!-- Needed to use components [BarycentricMapping] -->
<RequiredPlugin pluginName="Sofa.Component.Mass"/> <!-- Needed to use components [UniformMass] -->
<RequiredPlugin pluginName="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
<RequiredPlugin pluginName="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [RegularGridTopology] -->
</Node>

<DefaultAnimationLoop computeBoundingBox="false" />
<MeshOBJLoader name="meshLoader" triangulate="true" filename="mesh/raptor_35kp.obj" />

<Node name="grid">
<EulerExplicitIntegrationScheme />
<RegularGridTopology name="topology" n="22 38 82" min="-2.1 -0.3 -9.2" max="2.1 7.1 7.0" />
<MechanicalObject name="DOFs" template="Vec3" />
<UniformMass totalMass="1.0" />

<Node name="Visualization">
<OglModel name="VisualModel" src="@../../meshLoader" />
<BarycentricMapping input="@../DOFs" output="@VisualModel" />
</Node>
</Node>

</Node>
Loading