44 #define FILEOFFPLUGIN_C 48 #include <OpenMesh/Core/Utils/color_cast.hh> 49 #include <OpenMesh/Core/Geometry/VectorT.hh> 53 template<
class MeshT >
61 if(_mesh.has_vertex_texcoords2D() && (userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS) ) {
66 if(_mesh.has_vertex_colors() && (userWriteOptions_ & OFFImporter::VERTEXCOLOR) ) {
71 if(_mesh.has_vertex_normals() && (userWriteOptions_ & OFFImporter::VERTEXNORMAL) ) {
79 if(userWriteOptions_ & OFFImporter::BINARY) {
92 _out <<
"# %% BEGIN OPENFLIPPER_COMMENT %%" << std::endl;
94 std::string commentLine;
95 while (std::getline(comment, commentLine)) {
96 _out <<
"# " << commentLine << std::endl;
98 _out <<
"# %% END OPENFLIPPER_COMMENT %%" << std::endl;
106 if(userWriteOptions_ & OFFImporter::BINARY) {
109 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0)
110 _out.precision(savePrecision_->value());
118 template<
class MeshT >
121 typename MeshT::Point p;
122 typename MeshT::Normal n;
126 typename MeshT::VertexIter vit = _mesh.vertices_begin();
127 typename MeshT::VertexIter end_vit = _mesh.vertices_end();
130 _out << _mesh.n_vertices() <<
" " << _mesh.n_faces() <<
" " << _mesh.n_edges();
133 for(; vit != end_vit; ++vit) {
138 p = _mesh.point(*vit);
139 _out << p[0] <<
" " << p[1] <<
" " << p[2];
142 if(_mesh.has_vertex_normals() && (userWriteOptions_ & OFFImporter::VERTEXNORMAL)) {
143 n = _mesh.normal(*vit);
144 _out <<
" " << n[0] <<
" " << n[1] <<
" " << n[2];
150 if(_mesh.has_vertex_colors() && (userWriteOptions_ & OFFImporter::VERTEXCOLOR)) {
152 _out <<
" " << std::showpoint << c[0] <<
" " << std::showpoint << c[1] <<
" " << std::showpoint << c[2] <<
" " << std::showpoint << c[3];
156 if(_mesh.has_vertex_texcoords2D() && (userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS)) {
157 t = _mesh.texcoord2D(*vit);
158 _out <<
" " << t[0] <<
" " << t[1];
162 typename MeshT::FaceIter fit = _mesh.faces_begin();
163 typename MeshT::FaceIter end_fit = _mesh.faces_end();
164 typename MeshT::FaceVertexIter fvit;
167 for(; fit != end_fit; ++fit) {
172 _out << _mesh.valence(*fit);
175 fvit = _mesh.fv_iter(*fit);
178 for(;fvit.is_valid(); ++fvit) {
179 _out <<
" " << fvit->idx();
183 if(_mesh.has_face_colors() && (userWriteOptions_ & OFFImporter::FACECOLOR ) ) {
185 _out <<
" " << std::showpoint << c[0] <<
" " << std::showpoint << c[1] <<
" " << std::showpoint << c[2];
187 if(userWriteOptions_ & OFFImporter::COLORALPHA) _out <<
" " << std::showpoint << c[3];
196 template<
class MeshT >
204 typename MeshT::VertexIter vit = _mesh.vertices_begin();
205 typename MeshT::VertexIter end_vit = _mesh.vertices_end();
208 writeValue(_out, (uint)_mesh.n_vertices() );
209 writeValue(_out, (uint)_mesh.n_faces() );
210 writeValue(_out, (uint)_mesh.n_edges() );
213 for(; vit != end_vit; ++vit) {
216 p = _mesh.point(*vit);
217 writeValue(_out, p[0]);
218 writeValue(_out, p[1]);
219 writeValue(_out, p[2]);
222 if(_mesh.has_vertex_normals() && (userWriteOptions_ & OFFImporter::VERTEXNORMAL)) {
223 n = _mesh.normal(*vit);
224 writeValue(_out, n[0]);
225 writeValue(_out, n[1]);
226 writeValue(_out, n[2]);
232 if(_mesh.has_vertex_colors() && (userWriteOptions_ & OFFImporter::VERTEXCOLOR)) {
234 writeValue(_out, c[0]);
235 writeValue(_out, c[1]);
236 writeValue(_out, c[2]);
240 if(_mesh.has_vertex_texcoords2D() && (userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS)) {
241 t = _mesh.texcoord2D(*vit);
242 writeValue(_out, t[0]);
243 writeValue(_out, t[1]);
247 typename MeshT::FaceIter fit = _mesh.faces_begin();
248 typename MeshT::FaceIter end_fit = _mesh.faces_end();
249 typename MeshT::FaceVertexIter fvit;
252 for(; fit != end_fit; ++fit) {
255 writeValue(_out, _mesh.valence(*fit));
258 fvit = _mesh.fv_iter(*fit);
261 for(;fvit.is_valid(); ++fvit) {
262 writeValue(_out, fvit->idx());
266 if(_mesh.has_face_colors() && (userWriteOptions_ & OFFImporter::FACECOLOR)) {
269 if(userWriteOptions_ & OFFImporter::COLORALPHA) writeValue(_out, (uint)4);
270 else writeValue(_out, (uint)3);
274 writeValue(_out, c[0]);
275 writeValue(_out, c[1]);
276 writeValue(_out, c[2]);
278 if(userWriteOptions_ & OFFImporter::COLORALPHA) writeValue(_out, c[3]);
const QString getAllCommentsFlat() const
bool writeBinaryData(std::ostream &_out, MeshT &_mesh)
Write binary mesh data to file.
bool writeASCIIData(std::ostream &_out, MeshT &_mesh)
Write ASCII mesh data to file.
Add 2D texture coordinates (vertices, halfedges)
bool writeMesh(std::ostream &_out, MeshT &_mesh, BaseObject &_baseObj)
Writer function.