TriangleMeshIO.h 5.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//======================================================================================================================
//
//  This file is part of waLBerla. waLBerla is free software: you can 
//  redistribute it and/or modify it under the terms of the GNU General Public
//  License as published by the Free Software Foundation, either version 3 of 
//  the License, or (at your option) any later version.
//  
//  waLBerla is distributed in the hope that it will be useful, but WITHOUT 
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
//  for more details.
//  
//  You should have received a copy of the GNU General Public License along
//  with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file TriangleMeshIO.h
//! \ingroup geometry
//! \author Martin Bauer <martin.bauer@fau.de>
//! \brief Input/Output functions for mesh data structure in OBJ and POV format
//
//======================================================================================================================

#pragma once

#include <iostream>


namespace walberla {
namespace geometry {

   class TriangleMesh;

   /**
    * \brief Reads mesh from file
    *
    * Mesh format is detected by file ending.
    *
Jean-Noël Grad's avatar
Jean-Noël Grad committed
38
    * \param meshFilename  Filename of mesh. Supported formats are obj, pov and off. Format is detected
39
40
41
42
43
44
45
46
47
48
49
    *                  by file ending
    * \param mesh      object where the mesh is stored, if the given mesh is not
    *                  empty, all contents are cleared
    */
   void readMesh ( const std::string & meshFilename, TriangleMesh & mesh );

   /**
    * \brief writes a mesh to file
    *
    * Mesh format is detected by file ending.
    *
Jean-Noël Grad's avatar
Jean-Noël Grad committed
50
    * \param meshFilename  Filename of mesh. Supported formats are obj, pov and off. Format is detected
51
52
53
54
55
56
57
58
59
60
    *                  by file ending
    * \param mesh      object where the mesh is read from
    */
   void writeMesh ( const std::string & meshFilename, const TriangleMesh & mesh );

   /**
    * \brief Reads mesh from file on root process and broadcasts it to all other processes
    *
    * Mesh format is detected by file ending.
    *
Jean-Noël Grad's avatar
Jean-Noël Grad committed
61
    * \param meshFilename  Filename of mesh. Supported formats are obj, pov and off. Format is detected
62
63
64
65
66
67
68
69
70
71
72
73
74
    *                  by file ending
    * \param mesh      object where the mesh is stored, if the given mesh is not
    *                  empty, all contents are cleared
    */
   void readAndBroadcastMesh ( const std::string & meshFilename, TriangleMesh & mesh );



   /**
    * \brief writes a mesh to file on root process
    *
    * Mesh format is detected by file ending.
    *
Jean-Noël Grad's avatar
Jean-Noël Grad committed
75
    * \param meshFilename  Filename of mesh. Supported formats are obj, pov and off. Format is detected
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
    *                  by file ending
    * \param mesh      object where the mesh is read from
    */
   void writeMeshOnRoot ( const std::string & meshFilename, const TriangleMesh & mesh );


   /**
    * \brief Reads mesh from input stream in obj file format
    *
    *  Reads "v" (vertex) and "f" (face) entries only.
    *
    * \param is    input stream, to read from file use std::fstream
    * \param mesh  object where the mesh is stored, if the given mesh is not
    *              empty, all contents are cleared
    */
   void readMeshObj  (std::istream & is, TriangleMesh & mesh);


   /**
    * \brief Writes mesh to output stream in obj format
    *
    * Writes obj file with vertex, normal and face information
    *
    * \param os   the output stream. To write to file call with ofstream("filename.obj"))
    * \param mesh the mesh to write
    */
   void writeMeshObj (std::ostream & os, const TriangleMesh & mesh);


   /**
    * \brief Reads mesh from input stream in povray's mesh2 format
    *
    * Vertices, normals and faces are read.
    *
    * \param is    input stream, to read from file use std::fstream
    * \param mesh  object where the mesh is stored, if the given mesh is not
    *              empty, all contents are cleared
    */
   void readMeshPov  (std::istream & is, TriangleMesh & mesh, bool clear = true);


   /**
    * \brief Writes mesh in povray's mesh2 format
    *
    * Vertices, normals and faces are written.
    *
    * \param os   the output stream. To write to file call with ofstream("filename.dat")
    * \param mesh the mesh to write
    */
   void writeMeshPov (std::ostream & os, const TriangleMesh & mesh, size_t itemsPerLine = 5u, size_t itemsPerMesh = 0u);


    /**
    * \brief Reads mesh from input stream in Geomview Object File Format
    *
    *  Reads "v" (vertex) and "f" (face) entries only. Only triangular faces are supported.
    *  Colors are currently also not supported.
    *  Format details: http://people.sc.fsu.edu/~jburkardt/data/off/off.html
    *
    * \param is    input stream, to read from file use std::fstream
    * \param mesh  object where the mesh is stored, if the given mesh is not
    *              empty, all contents are cleared
    */
   void readMeshOff  (std::istream & is, TriangleMesh & mesh);


    /**
    * \brief Writes a mesh to an output stream in Geomview Object File Format
    *
    *  Writes vertices and faces only. Colors are not (yet) supported.
    *  Format details: http://people.sc.fsu.edu/~jburkardt/data/off/off.html
    *
    * \param os    the output stream. To write to file call with ofstream("filename.off")
    * \param mesh  the mesh to write
    */
   void writeMeshOff  ( std::ostream & os, const TriangleMesh & mesh );


    /**
    * \brief Writes a mesh to an output stream in VTK Poly Data format
    *
    *  Writes colors and vertex normals if available
    *  Format details: http://www.vtk.org/VTK/img/file-formats.pdf
    *
    * \param os    the output stream. To write to file call with ofstream("filename.vtp")
    * \param mesh  the mesh to write
    */
   void writeMeshVtp  ( std::ostream & os, const TriangleMesh & mesh );


} // namespace geometry
} // namespace walberla