Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add material surface mesh reader #1677

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
Action instead of Appeveyor (David Coeurjolly,
[#1689](https://github.com/DGtal-team/DGtal/pull/1689))

- *IO*
- Add reading material indices in SurfaceMeshReader::readOBJ
(Jacques-Olivier Lachaud, [#1677](https://github.com/DGtal-team/DGtal/pull/1677))


## Bug fixes
- *General*
- Missing `boost/next_prior.hpp` includes in ReverseIterator, Melkman and Convex
Expand Down
15 changes: 14 additions & 1 deletion src/DGtal/io/readers/SurfaceMeshReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ namespace DGtal
typedef typename SurfaceMesh::Index Index;
typedef typename SurfaceMesh::Vertices Vertices;
typedef typename SurfaceMesh::Faces Faces;

typedef std::vector<int> Materials;

/// Checks that every index in \a indices are different from the others.
/// @param indices a vector of integer indices
/// @return 'true' iff the integer indices are all pairwise different.
Expand All @@ -97,6 +98,18 @@ namespace DGtal
/// created mesh is ok.
static
bool readOBJ( std::istream & input, SurfaceMesh & smesh );

/// Reads an input file as an OBJ file format and outputs the
/// corresponding surface mesh.
///
/// @param[in,out] input the input stream where the OBJ file is read.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @param[in,out] input the input stream where the OBJ file is read.
/// @param[in,out] input the input stream from which the OBJ file is read.

?

/// @param[out] smesh the output surface mesh.
/// @param[out] materials a vector containing the material of each face (an index).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @param[out] materials a vector containing the material of each face (an index).
/// @param[out] materials a vector containing the material of each face (an index, may be empty)

If there is no material info, an empty vector is retuned, right ?

///
/// @return 'true' if both reading the input stream was ok and the
/// created mesh is ok.
static
bool readOBJ( std::istream & input, SurfaceMesh & smesh, Materials& materials );
};

} // namespace DGtal
Expand Down
16 changes: 16 additions & 0 deletions src/DGtal/io/readers/SurfaceMeshReader.ih
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ template <typename TRealPoint, typename TRealVector>
bool
DGtal::SurfaceMeshReader<TRealPoint, TRealVector>::
readOBJ( std::istream & input, SurfaceMesh & smesh )
{
Materials materials;
return readOBJ( input, smesh, materials );
}
//-----------------------------------------------------------------------------
template <typename TRealPoint, typename TRealVector>
bool
DGtal::SurfaceMeshReader<TRealPoint, TRealVector>::
readOBJ( std::istream & input, SurfaceMesh & smesh, Materials& materials )
{
std::vector<RealPoint> vertices;
std::vector<RealVector> normals;
Expand All @@ -77,6 +86,7 @@ readOBJ( std::istream & input, SurfaceMesh & smesh )
RealVector n;
std::getline( input, linestr );
Index l = 0;
int mat = 0; // current material
for ( ; input.good() && ! input.eof(); std::getline( input, linestr ), l++ )
{
if ( linestr.empty() ) continue; // skip empty line
Expand All @@ -89,6 +99,11 @@ readOBJ( std::istream & input, SurfaceMesh & smesh )
} else if ( keyword == "vn" ) {
lineinput >> n[ 0 ] >> n[ 1 ] >> n[ 2 ];
normals.push_back( n );
} else if ( keyword == "usemtl" ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please reformat with the ˋ{`on single lines?

std::string strmat;
std::operator>>( lineinput, strmat ); // lineinput >> keyword;
auto matinfo = split( strmat, '_' );
mat = matinfo.size() >= 2 ? std::stoi( matinfo[ 1 ] ) : 0;
} else if ( keyword == "f" ) {
std::vector< Index > face, face_normals;
while ( ! lineinput.eof() ) {
Expand All @@ -109,6 +124,7 @@ readOBJ( std::istream & input, SurfaceMesh & smesh )
{
faces.push_back( face );
faces_normals_idx.push_back( face_normals );
materials.push_back( mat );
}
}
// Weird: necessary to clear them.
Expand Down
Loading