-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
JacquesOlivierLachaud
wants to merge
14
commits into
DGtal-team:master
Choose a base branch
from
JacquesOlivierLachaud:AddMaterialSurfaceMeshReader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ee327f2
Add reading materials in SurfaceMeshReader::readOBJ
JacquesOlivierLachaud 51a154d
Merge branch 'master' of github.com:DGtal-team/DGtal into AddMaterial…
JacquesOlivierLachaud 1b722e4
Fix ChangeLog
JacquesOlivierLachaud b7c516b
Merge branch 'master' of github.com:DGtal-team/DGtal into AddMaterial…
JacquesOlivierLachaud 352e362
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo a6d53d3
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo f757a0e
Merge branch 'master' into AddMaterialSurfaceMeshReader
JacquesOlivierLachaud 9cca769
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo 0ce7039
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo 3e500d7
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo 618573c
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo dd510a3
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo 93cf550
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo 56a75c0
Merge branch 'master' into AddMaterialSurfaceMeshReader
dcoeurjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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. | ||||||
|
@@ -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. | ||||||
/// @param[out] smesh the output surface mesh. | ||||||
/// @param[out] materials a vector containing the material of each face (an index). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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" ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() ) { | ||
|
@@ -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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?