Skip to content

Commit

Permalink
[IO] Rename Data (#4679)
Browse files Browse the repository at this point in the history
* [IO] Rename Data

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.h

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.cpp

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* Update Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyContainer.cpp

Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshTrianLoader.cpp

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/OffSequenceLoader.cpp

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshTrianLoader.h

Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>

* Update Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/MultilevelHexahedronSetTopologyContainer.cpp

Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>

* Update Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.h

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VoxelGridLoader.cpp

Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshTrianLoader.cpp

Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.h

Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>

* Update Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VoxelGridLoader.cpp

Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>

* [IO] clean coding

* [IO] fix error

* [IO] Fix typo

---------

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>
Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>
  • Loading branch information
3 people committed May 13, 2024
1 parent 425a748 commit 4d425cd
Show file tree
Hide file tree
Showing 18 changed files with 370 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ int GridMeshCreatorClass = core::RegisterObject("Procedural creation of a two-di


GridMeshCreator::GridMeshCreator(): MeshLoader()
, resolution( initData(&resolution,Vec2i(2,2),"resolution","Number of vertices in each direction"))
, trianglePattern( initData(&trianglePattern,2,"trianglePattern","0: no triangles, 1: alternate triangles, 2: upward triangles, 3: downward triangles"))
, d_resolution(initData(&d_resolution, Vec2i(2, 2), "resolution", "Number of vertices in each direction"))
, d_trianglePattern(initData(&d_trianglePattern, 2, "trianglePattern", "0: no triangles, 1: alternate triangles, 2: upward triangles, 3: downward triangles"))
{
// doLoad() is called only if d_filename is modified
// but this loader in particular does not require a filename (refactoring would be needed)
// we force d_filename to be dirty to trigger the callback, thus calling doLoad()
d_filename.setDirtyValue();

d_filename.setReadOnly(true);

resolution.setParent(&d_resolution);
trianglePattern.setParent(&d_trianglePattern);
}

void GridMeshCreator::doClearBuffers()
Expand Down Expand Up @@ -87,7 +90,7 @@ void GridMeshCreator::insertQuad(unsigned a, unsigned b, unsigned c, unsigned d)
bool GridMeshCreator::doLoad()
{
auto my_positions = getWriteOnlyAccessor(d_positions);
const unsigned numX = resolution.getValue()[0], numY=resolution.getValue()[1];
const unsigned numX = d_resolution.getValue()[0], numY=d_resolution.getValue()[1];

// Warning: Vertex creation order must be consistent with method vert.
for(unsigned y=0; y<numY; y++)
Expand All @@ -100,15 +103,15 @@ bool GridMeshCreator::doLoad()

uniqueEdges.clear();

if( trianglePattern.getValue()==0 ) // quads
if(d_trianglePattern.getValue() == 0 ) // quads
for(unsigned y=0; y<numY-1; y++ )
{
for(unsigned x=0; x<numX-1; x++ )
{
insertQuad( vert(x,y), vert(x+1,y), vert(x+1,y+1), vert(x,y+1) );
}
}
else if( trianglePattern.getValue()==1 ) // alternate
else if(d_trianglePattern.getValue() == 1 ) // alternate
for(unsigned y=0; y<numY-1; y++ )
{
for(unsigned x=0; x<numX-1; x++ )
Expand All @@ -125,7 +128,7 @@ bool GridMeshCreator::doLoad()
}
}
}
else if( trianglePattern.getValue()==2 ) // upward
else if(d_trianglePattern.getValue() == 2 ) // upward
for(unsigned y=0; y<numY-1; y++ )
{
for(unsigned x=0; x<numX-1; x++ )
Expand All @@ -134,7 +137,7 @@ bool GridMeshCreator::doLoad()
insertTriangle( vert(x,y), vert(x+1,y+1), vert(x,y+1) ) ;
}
}
else if( trianglePattern.getValue()==3 ) // downward
else if(d_trianglePattern.getValue() == 3 ) // downward
for(unsigned y=0; y<numY-1; y++ )
{
for(unsigned x=0; x<numX-1; x++ )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,23 @@ class SOFA_COMPONENT_IO_MESH_API GridMeshCreator : public sofa::core::loader::Me
virtual std::string type() { return "This object is procedurally created"; }
bool canLoad() override { return true; }
bool doLoad() override; ///< create the grid
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data< type::Vec2i > resolution;

Data< type::Vec2i > resolution; ///< Number of vertices in each direction
Data< int > trianglePattern; ///< 0: no triangles, 1: alternate triangles, 2: upward triangles, 3: downward triangles.
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data< int > trianglePattern;



Data< type::Vec2i > d_resolution; ///< Number of vertices in each direction
Data< int > d_trianglePattern; ///< 0: no triangles, 1: alternate triangles, 2: upward triangles, 3: downward triangles.

protected:
GridMeshCreator();

void doClearBuffers() override;
///< index of a vertex, given its integer coordinates (between 0 and resolution) in the plane.
unsigned vert( unsigned x, unsigned y) { return x + y*resolution.getValue()[0]; }
unsigned vert( unsigned x, unsigned y) { return x + y * d_resolution.getValue()[0]; }

// To avoid edge redundancy, we insert the edges to a set, an then dump the set. Edge (a,b) is considered equal to (b,a), so only one of them is inserted
std::set<Edge> uniqueEdges; ///< edges without redundancy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ static int MeshSTLLoaderClass = core::RegisterObject("Loader for the STL file fo

//Base VTK Loader
MeshSTLLoader::MeshSTLLoader() : MeshLoader()
, _headerSize(initData(&_headerSize, 80u, "headerSize","Size of the header binary file (just before the number of facet)."))
, _forceBinary(initData(&_forceBinary, false, "forceBinary","Force reading in binary mode. Even in first keyword of the file is solid."))
, d_headerSize(initData(&d_headerSize, 80u, "headerSize", "Size of the header binary file (just before the number of facet)."))
, d_forceBinary(initData(&d_forceBinary, false, "forceBinary", "Force reading in binary mode. Even in first keyword of the file is solid."))
, d_mergePositionUsingMap(initData(&d_mergePositionUsingMap, true, "mergePositionUsingMap","Since positions are duplicated in a STL, they have to be merged. Using a map to do so will temporarily duplicate memory but should be more efficient. Disable it if memory is really an issue."))
{
_headerSize.setParent(&d_headerSize);
_forceBinary.setParent(&d_forceBinary);

}


Expand All @@ -69,7 +72,7 @@ bool MeshSTLLoader::doLoad()
}

bool ret = false;
if( _forceBinary.getValue() )
if( d_forceBinary.getValue() )
ret = this->readBinarySTL(filename); // -- Reading binary file
else
{
Expand Down Expand Up @@ -134,7 +137,7 @@ bool MeshSTLLoader::readBinarySTL(const char *filename)

// Skipping header file
char buffer[256];
dataFile.read(buffer, _headerSize.getValue());
dataFile.read(buffer, d_headerSize.getValue());

uint32_t nbrFacet;
dataFile.read(reinterpret_cast<char*>(&nbrFacet), 4);
Expand All @@ -153,7 +156,7 @@ bool MeshSTLLoader::readBinarySTL(const char *filename)
// restore pos in file
dataFile.seekg(pos);
// check for length
assert( length >= _headerSize.getValue() + 4 + nbrFacet * (12 /*normal*/ + 3 * 12 /*points*/ + 2 /*attribute*/ ) );
assert(length >= d_headerSize.getValue() + 4 + nbrFacet * (12 /*normal*/ + 3 * 12 /*points*/ + 2 /*attribute*/ ) );
}
#endif

Expand Down
12 changes: 10 additions & 2 deletions Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ class SOFA_COMPONENT_IO_MESH_API MeshSTLLoader : public sofa::core::loader::Mesh

public:
//Add Data here
Data <unsigned int> _headerSize; ///< Size of the header binary file (just before the number of facet).
Data <bool> _forceBinary; ///< Force reading in binary mode. Even in first keyword of the file is solid.
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data <bool> _forceBinary;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data <unsigned int> _headerSize;



Data <unsigned int> d_headerSize; ///< Size of the header binary file (just before the number of facet).
Data <bool> d_forceBinary; ///< Force reading in binary mode. Even in first keyword of the file is solid.
Data <bool> d_mergePositionUsingMap; ///< Since positions are duplicated in a STL, they have to be merged. Using a map to do so will temporarily duplicate memory but should be more efficient. Disable it if memory is really an issue.

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ int MeshTrianLoaderClass = core::RegisterObject("Specific mesh loader for trian
;

MeshTrianLoader::MeshTrianLoader() : MeshLoader()
, p_trian2(initData(&p_trian2,(bool)false,"trian2","Set to true if the mesh is a trian2 format."))
, neighborTable(initData(&neighborTable,"neighborTable","Table of neighborhood triangle indices for each triangle."))
, edgesOnBorder(initData(&edgesOnBorder,"edgesOnBorder","List of edges which are on the border of the mesh loaded."))
, trianglesOnBorderList(initData(&trianglesOnBorderList,"trianglesOnBorderList","List of triangle indices which are on the border of the mesh loaded."))
, d_trian2(initData(&d_trian2, (bool)false, "trian2", "Set to true if the mesh is a trian2 format."))
, d_neighborTable(initData(&d_neighborTable, "neighborTable", "Table of neighborhood triangle indices for each triangle."))
, d_edgesOnBorder(initData(&d_edgesOnBorder, "edgesOnBorder", "List of edges which are on the border of the mesh loaded."))
, d_trianglesOnBorderList(initData(&d_trianglesOnBorderList, "trianglesOnBorderList", "List of triangle indices which are on the border of the mesh loaded."))
{
neighborTable.setPersistent(false);
edgesOnBorder.setPersistent(false);
trianglesOnBorderList.setPersistent(false);
d_neighborTable.setPersistent(false);
d_edgesOnBorder.setPersistent(false);
d_trianglesOnBorderList.setPersistent(false);

p_trian2.setParent(&d_trian2);
neighborTable.setParent(&d_neighborTable);
edgesOnBorder.setParent(&d_edgesOnBorder);
trianglesOnBorderList.setParent(&d_trianglesOnBorderList);

}


Expand All @@ -68,7 +74,7 @@ bool MeshTrianLoader::doLoad()
}

// -- Reading file
if (p_trian2.getValue())
if (d_trian2.getValue())
fileRead = this->readTrian2 (filename);
else
fileRead = this->readTrian (filename);
Expand All @@ -79,12 +85,12 @@ bool MeshTrianLoader::doLoad()

void MeshTrianLoader::doClearBuffers()
{
neighborTable.beginEdit()->clear();
neighborTable.endEdit();
edgesOnBorder.beginEdit()->clear();
edgesOnBorder.endEdit();
trianglesOnBorderList.beginEdit()->clear();
trianglesOnBorderList.endEdit();
d_neighborTable.beginEdit()->clear();
d_neighborTable.endEdit();
d_edgesOnBorder.beginEdit()->clear();
d_edgesOnBorder.endEdit();
d_trianglesOnBorderList.beginEdit()->clear();
d_trianglesOnBorderList.endEdit();
}


Expand Down Expand Up @@ -119,9 +125,9 @@ bool MeshTrianLoader::readTrian (const char* filename)
dataFile >> nbTriangles; //Loading number of Triangle

auto my_triangles = getWriteOnlyAccessor(d_triangles);
auto my_neighborTable = getWriteOnlyAccessor(neighborTable);
auto my_edgesOnBorder = getWriteOnlyAccessor(edgesOnBorder);
auto my_trianglesOnBorderList = getWriteOnlyAccessor(trianglesOnBorderList);
auto my_neighborTable = getWriteOnlyAccessor(d_neighborTable);
auto my_edgesOnBorder = getWriteOnlyAccessor(d_edgesOnBorder);
auto my_trianglesOnBorderList = getWriteOnlyAccessor(d_trianglesOnBorderList);

for (unsigned int i=0; i<nbTriangles; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,22 @@ class SOFA_COMPONENT_IO_MESH_API MeshTrianLoader : public sofa::core::loader::Me

public:
//Add specific Data here:
Data <bool> p_trian2; ///< Set to true if the mesh is a trian2 format.
Data <type::vector< type::fixed_array <int,3> > > neighborTable; ///< Table of neighborhood triangle indices for each triangle.
Data <type::vector< type::vector<unsigned int> > > edgesOnBorder; ///< List of edges which are on the border of the mesh loaded.
Data <type::vector<unsigned int> > trianglesOnBorderList; ///< List of triangle indices which are on the border of the mesh loaded.
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data <bool> p_trian2;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data <type::vector< type::fixed_array <int,3> > > neighborTable;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data <type::vector< type::vector<unsigned int> > > edgesOnBorder;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data <type::vector<unsigned int> > trianglesOnBorderList;

Data <bool> d_trian2; ///< Set to true if the mesh is a trian2 format.
Data <type::vector< type::fixed_array <int,3> > > d_neighborTable; ///< Table of neighborhood triangle indices for each triangle.
Data <type::vector< type::vector<unsigned int> > > d_edgesOnBorder; ///< List of edges which are on the border of the mesh loaded.
Data <type::vector<unsigned int> > d_trianglesOnBorderList; ///< List of triangle indices which are on the border of the mesh loaded.
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ int OffSequenceLoaderClass = core::RegisterObject("Read and load an .off file at

OffSequenceLoader::OffSequenceLoader()
: MeshOffLoader()
, nbFiles( initData(&nbFiles,(int)1,"nbOfFiles","number of files in the sequence") )
, stepDuration( initData(&stepDuration,0.04,"stepDuration","how long each file is loaded") )
, d_nbFiles(initData(&d_nbFiles, (int)1, "nbOfFiles", "number of files in the sequence") )
, d_stepDuration(initData(&d_stepDuration, 0.04, "stepDuration", "how long each file is loaded") )
, firstIndex(0) , currentIndex(0)
{
this->f_listening.setValue(true);
Expand All @@ -57,6 +57,10 @@ OffSequenceLoader::OffSequenceLoader()
d_polygonsGroups.setDisplayed(false);
d_tetrahedraGroups.setDisplayed(false);
d_hexahedraGroups.setDisplayed(false);

nbFiles.setParent(&d_nbFiles);
stepDuration.setParent(&d_stepDuration);

}


Expand Down Expand Up @@ -97,10 +101,10 @@ void OffSequenceLoader::handleEvent(sofa::core::objectmodel::Event* event)
//load the next file at the beginning of animation step and if the current file duration is over
if (simulation::AnimateBeginEvent::checkEventType(event))
{
if ( (currentIndex-firstIndex)*stepDuration.getValue() <= this->getContext()->getTime())
if ((currentIndex-firstIndex) * d_stepDuration.getValue() <= this->getContext()->getTime())
{
currentIndex++;
if (currentIndex < firstIndex+nbFiles.getValue())
if (currentIndex < firstIndex + d_nbFiles.getValue())
{
std::ostringstream os;
os << currentIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ class SOFA_COMPONENT_IO_MESH_API OffSequenceLoader : public MeshOffLoader
void clear();

private:
/// the number of files in the sequences
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<int> nbFiles;
/// duration each file must be loaded
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<double> stepDuration;


/// the number of files in the sequences
Data<int> d_nbFiles;
/// duration each file must be loaded
Data<double> d_stepDuration;

/// index of the first file
int firstIndex;
/// index of the current read file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ int StringMeshCreatorClass = core::RegisterObject("Procedural creation of a one-


StringMeshCreator::StringMeshCreator(): MeshLoader()
, resolution( initData(&resolution,(unsigned)2,"resolution","Number of vertices"))
, d_resolution(initData(&d_resolution, (unsigned)2, "resolution", "Number of vertices"))
{
addUpdateCallback("updateResolution", {&resolution}, [this](const core::DataTracker& )
addUpdateCallback("updateResolution", {&d_resolution}, [this](const core::DataTracker& )
{
if(load())
{
Expand All @@ -50,6 +50,8 @@ StringMeshCreator::StringMeshCreator(): MeshLoader()
return sofa::core::objectmodel::ComponentState::Invalid;

}, {&d_positions, &d_edges});

resolution.setParent(&d_resolution);
}

void StringMeshCreator::doClearBuffers()
Expand All @@ -64,7 +66,7 @@ bool StringMeshCreator::doLoad()
auto my_positions = sofa::helper::getWriteOnlyAccessor(d_positions);
auto my_edges = sofa::helper::getWriteOnlyAccessor(d_edges);

const unsigned numX = resolution.getValue();
const unsigned numX = d_resolution.getValue();

// Warning: Vertex creation order must be consistent with method vert.
for(unsigned x=0; x<numX; x++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ namespace sofa::component::io::mesh
class SOFA_COMPONENT_IO_MESH_API StringMeshCreator : public sofa::core::loader::MeshLoader
{
public:
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data< unsigned > resolution;

SOFA_CLASS(StringMeshCreator,sofa::core::loader::MeshLoader);
virtual std::string type() { return "This object is procedurally created"; }
bool canLoad() override { return true; }
bool doLoad() override; ///< create the string

Data< unsigned > resolution; ///< Number of vertices (more than 1)
Data< unsigned > d_resolution; ///< Number of vertices (more than 1)

protected:
StringMeshCreator();
Expand Down

0 comments on commit 4d425cd

Please sign in to comment.