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

Assimp support and GridIn::read_assimp. #5095

Merged
merged 8 commits into from Sep 21, 2017

Conversation

luca-heltai
Copy link
Member

@luca-heltai luca-heltai commented Sep 16, 2017

Added support for the Open Asset Library (http://assimp.sourceforge.net/).

This can be used by invoking the (new) GridIn::read_assimp() function, that translates one of the graphical formats supported by Assimp into a deal.II compatible grid.

The most reliable format so far is the Wavefront .obj format, to which most opensource graphical softwares can export to (Blender, for example, can http://www.blender.org).

As soon as I find the time, I'll make a video tutorial using Blender to create a complex Triangulation<2,3> grid that exploits some of the (many) functionalities of Blender.

@davydden
Copy link
Contributor

As soon as I find the time, I'll make a video tutorial using Blender to create a complex Triangulation<2,3> grid that exploits some of the (many) functionalities of Blender.

looking forward to that, i used Blender some 10 years ago as a 3dmax like rendering program.

* the given index will be extracted, otherwise all meshes which are
* present in the file will be used to generate the Triangulation.
*
* This function can only be used to read two-dimensional meshes (possibly
Copy link
Contributor

Choose a reason for hiding this comment

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

pity

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if .obj supports volume information... so far I could only make it work with surface one. I know it's a pity, but there is a lot of BEM and shell models that would benefit from this anyway. :)

*
* This function can only be used to read two-dimensional meshes (possibly
* embedded in three dimensions), as this is the only format supported
* by the supported graphical formats.
Copy link
Contributor

Choose a reason for hiding this comment

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

supported by the supported

maybe reword

* `ignore_unsupported_element_types`, all the other element types are simply
* ignored by this algorithm. If your mesh contains a mixture of triangles
* and quadrilaterals, for example, only the quadrilaterals will be
* extracted. Careful that your mesh may not make any sense if you are mixing
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe: Careful that Your mesh...

@luca-heltai
Copy link
Member Author

/run_tests

@tjhei
Copy link
Member

tjhei commented Sep 18, 2017

/run_tests

/run-tests (with a dash)

* @ref GlossBoundaryIndicator "this"
* glossary entry for more information).
* boundary ids to cells or faces (see @ref GlossMaterialId "this" and @ref
* GlossBoundaryIndicator "this" glossary entry for more information).
Copy link
Member

Choose a reason for hiding this comment

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

Can you undo the change in formatting?

* `ignore_unsupported_element_types`, all the other element types are simply
* ignored by this algorithm. If your mesh contains a mixture of triangles
* and quadrilaterals, for example, only the quadrilaterals will be
* extracted. Your mesh may not make any sense if you are mixing compatible
Copy link
Member

Choose a reason for hiding this comment

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

To avoid confusing between the use of "your mesh" in this sentence and the one in the previous sentence, how about writing "The resulting mesh (as represented in the Triangulation object) may not make ..." in the second sentence?

DEAL_II_ENABLE_EXTRA_DIAGNOSTICS

#undef AI_CONFIG_PP_RVC_FLAGS
#define AI_CONFIG_PP_RVC_FLAGS \
Copy link
Member

Choose a reason for hiding this comment

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

could this be done with a local variable in the function that uses it, instead of a global preprocessor define?

// Only good for surface grids.
AssertThrow(dim<3, ExcImpossibleInDim(dim));

// Create an istance of the Importer class
Copy link
Member

Choose a reason for hiding this comment

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

-> instance

Assimp::Importer importer;

// And have it read the given file with some postprocessing
const aiScene *scene = importer.ReadFile( filename.c_str(),
Copy link
Member

Choose a reason for hiding this comment

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

are you creating a memory leak here? Or is the memory managed by the importer object?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is managed by the importer object:

Create an object of this class and call ReadFile() to import a file. If the import succeeds, the function returns a pointer to the imported data. The data remains property of the object, it is intended to be accessed read-only. The imported data will be destroyed along with the Importer object. If the import fails, ReadFile() returns a NULL pointer. In this case you can retrieve a human-readable error description be calling GetErrorString(). You can call ReadFile() multiple times with a single Importer instance. Actually, constructing Importer objects involves quite many allocations and may take some time, so it's better to reuse them as often as possible.

std::stringstream s;
s << "Incompatible mesh " << m
<< "/" << scene->mNumMeshes;
AssertThrow(ignore_unsupported_types, ExcMessage(s.str()));
Copy link
Member

Choose a reason for hiding this comment

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

same here

<< m << " has " << mFaces[i].mNumIndices
<< " vertices. We expected only "
<< GeometryInfo<dim>::vertices_per_cell;
AssertThrow(ignore_unsupported_types, ExcMessage(s.str()));
Copy link
Member

Choose a reason for hiding this comment

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

same here

}
cells.resize(valid_cell);

// The vertices are added all at once. Cells are check for
Copy link
Member

Choose a reason for hiding this comment

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

-> checked

"functions, instead."));
return;

case tecplot:
read_tecplot (in);
return;

case assimp:
Assert(false, ExcMessage("There is no read_assimp(istream &) function. "
"Use the read_netcdf)(string &filename, ...) "
Copy link
Member

Choose a reason for hiding this comment

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

-> read_assimp

@@ -2820,14 +3000,20 @@ void GridIn<dim, spacedim>::read (std::istream &in,

case netcdf:
Assert(false, ExcMessage("There is no read_netcdf(istream &) function. "
"Use the read(_netcdf)(string &filename) "
"Use the read_netcdf)(string &filename) "
Copy link
Member

Choose a reason for hiding this comment

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

remove the stray closing parenthesis

@luca-heltai
Copy link
Member Author

ping @bangerth

@bangerth bangerth merged commit b313294 into dealii:master Sep 21, 2017
@bangerth
Copy link
Member

This new additional external dependency also still needs an entry in readme.html. Can you please put that on your list as well?

@davydden
Copy link
Contributor

@luca-heltai btw, the up-to-date homepage is http://www.assimp.org

PATH_SUFFIXES lib${LIB_SUFFIX} lib64 lib
)

SET(ASSIMP_INC "${ASSIMP_DIR}/include")
Copy link
Member

Choose a reason for hiding this comment

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

@luca-heltai The include directory does not need to be ${ASSIMP_DIR}/include. I will make a pull request (later today) to clean up this file.

@luca-heltai luca-heltai deleted the assimp-detection branch December 18, 2019 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants