Difference between revisions of "Realistic 3D models"

From Medusa: Coordinate Free Mehless Method implementation
Jump to: navigation, search
Line 13: Line 13:
 
PLY, OFF and STL files can also be read with Matlab, but require (short) external functions, available at [https://www.mathworks.com/matlabcentral/fileexchange/46540-geometry-processing-package], see Function/IO. These return a list of vertices and faces, that can be plotted with <code>patch</code> or <code>trisurf</code> after constructing the triangulation.
 
PLY, OFF and STL files can also be read with Matlab, but require (short) external functions, available at [https://www.mathworks.com/matlabcentral/fileexchange/46540-geometry-processing-package], see Function/IO. These return a list of vertices and faces, that can be plotted with <code>patch</code> or <code>trisurf</code> after constructing the triangulation.
  
Obtaining models can be somewhat difficult, as this files are often used to store general 3D objects for rendering. Here is a list of common 3D models (not all of which are polyhedrons): [https://github.com/alecjacobson/common-3d-test-models https://github.com/alecjacobson/common-3d-test-models]. Specifically, an altered Stanford bunny model (made watertight) in OFF format can be found here [https://github.com/OpenGP/OpenGP/blob/master/data/bunny.off] Googling with keywords "polyhedron", "watertight", "closed", "OFF" or "PLY" might help.
+
Obtaining models can be somewhat difficult, as this files are often used to store general 3D objects for rendering. Here is a list of common 3D models (not all of which are polyhedrons): [https://github.com/alecjacobson/common-3d-test-models https://github.com/alecjacobson/common-3d-test-models]. Specifically, an altered Stanford bunny model (made watertight) in OFF format can be found here [https://github.com/OpenGP/OpenGP/blob/master/data/bunny.off]. Googling with keywords "polyhedron", "watertight", "closed", "OFF" or "PLY" might help.
 
General models (often STL files) can be downloaded from [https://grabcad.com/ https://grabcad.com/] (after registering).
 
General models (often STL files) can be downloaded from [https://grabcad.com/ https://grabcad.com/] (after registering).
  
 
== Working with 3D models in Medusa ==
 
== Working with 3D models in Medusa ==
 +
 +
We assume that an OFF file has been successfully obtained, in this example we will use the <code>bunny.off</code> file from [https://github.com/OpenGP/OpenGP/blob/master/data/bunny.off https://github.com/OpenGP/OpenGP/blob/master/data/bunny.off]. To work with Medusa, we can make a generic <code>PolyhedronShape</code>, that can also be used with other existing shapes (translations, boolean operations, etc).

Revision as of 17:11, 9 November 2020

Medusa is not meant to deal with complex 3D geometry - we support balls, cuboids, and their differences, unions, translations and rotations. More general 2D shapes can be described by polygons, which are also included in Medusa. For more general 3D objects, the geometric algorithms become more complex and it makes sense to leverage third-party libraries.

Formats, software, and other resources

A good library in c++ is CGAL ([1]), that we can use to work with polyhedrons: https://doc.cgal.org/latest/Polyhedron/index.html CGAL can usually be installed with apt-get install libcgal-dev or similar. The Qt dependency is not necessary, but can be useful for easier visualization without exporting to an external program.

Polyhedrons are solid bodies with polygonal faces, and their surface forms a closed mesh. CGAL can work also with surfaces meshes that are not closed, but for PDE solving in 3D bodies, we assume them to be closed (or watertight). Polyhedron data is usually stored in a separate file with many different formats available. Some of the formats actually store the polyhedron data (including how faces are connected) and some only store the faces. By default, CGAL reads OFF files [2], and these files can also be easily viewd by geomview [3], also trivially installable on most Linux systems.

Other formats include STL, PLY and OBJ, and other proprietary formats. Some of these formats are more appropriate than others. Notably STL, while very common, can be problematic, as it does not include connections between faces, bit only a list of triangles, from which the polyhedron must first be reconstructed. This can be done directly in CGAL by using CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh, through an intermediate program, like Meshlab https://www.meshlab.net/, or through an online converter, such as https://cadcook.com/ply-off/. Note that it is not necessary that any of these conversions work, since STL file can represent an object with holes in the surface mesh or other degenerated objects. PLY files on the other hand do represent surface meshes, and can be read in CGAL (or easily converted to OFF) [4]. Similar hold for OBJ files, although, these files can contain many other types of objects besides polygon meshes. CGAL includes readers and writers for OFF, PLY, OBJ and STL formats [5], and the default cin >> operator expects an OFF file. Further demos for polyhedron IO are available in the CGAL repo [6].

PLY, OFF and STL files can also be read with Matlab, but require (short) external functions, available at [7], see Function/IO. These return a list of vertices and faces, that can be plotted with patch or trisurf after constructing the triangulation.

Obtaining models can be somewhat difficult, as this files are often used to store general 3D objects for rendering. Here is a list of common 3D models (not all of which are polyhedrons): https://github.com/alecjacobson/common-3d-test-models. Specifically, an altered Stanford bunny model (made watertight) in OFF format can be found here [8]. Googling with keywords "polyhedron", "watertight", "closed", "OFF" or "PLY" might help. General models (often STL files) can be downloaded from https://grabcad.com/ (after registering).

Working with 3D models in Medusa

We assume that an OFF file has been successfully obtained, in this example we will use the bunny.off file from https://github.com/OpenGP/OpenGP/blob/master/data/bunny.off. To work with Medusa, we can make a generic PolyhedronShape, that can also be used with other existing shapes (translations, boolean operations, etc).