50 #define FILEOFFPLUGIN_C 54 #include <OpenMesh/Core/Utils/color_cast.hh> 55 #include <OpenMesh/Core/Geometry/VectorT.hh> 59 template<
class MeshT >
67 if(_mesh.has_vertex_texcoords2D() && (userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS) ) {
72 if(_mesh.has_vertex_colors() && (userWriteOptions_ & OFFImporter::VERTEXCOLOR) ) {
77 if(_mesh.has_vertex_normals() && (userWriteOptions_ & OFFImporter::VERTEXNORMAL) ) {
85 if(userWriteOptions_ & OFFImporter::BINARY) {
98 _out <<
"# %% BEGIN OPENFLIPPER_COMMENT %%" << std::endl;
100 std::string commentLine;
101 while (std::getline(comment, commentLine)) {
102 _out <<
"# " << commentLine << std::endl;
104 _out <<
"# %% END OPENFLIPPER_COMMENT %%" << std::endl;
112 if(userWriteOptions_ & OFFImporter::BINARY) {
115 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0)
116 _out.precision(savePrecision_->value());
124 template<
class MeshT >
127 typename MeshT::Point p;
132 typename MeshT::VertexIter vit = _mesh.vertices_begin();
133 typename MeshT::VertexIter end_vit = _mesh.vertices_end();
136 _out << _mesh.n_vertices() <<
" " << _mesh.n_faces() <<
" " << _mesh.n_edges();
139 for(; vit != end_vit; ++vit) {
144 p = _mesh.point(*vit);
145 _out << p[0] <<
" " << p[1] <<
" " << p[2];
148 if(_mesh.has_vertex_normals() && (userWriteOptions_ & OFFImporter::VERTEXNORMAL)) {
149 n = _mesh.normal(*vit);
150 _out <<
" " << n[0] <<
" " << n[1] <<
" " << n[2];
156 if(_mesh.has_vertex_colors() && (userWriteOptions_ & OFFImporter::VERTEXCOLOR)) {
158 _out <<
" " << std::showpoint << c[0] <<
" " << std::showpoint << c[1] <<
" " << std::showpoint << c[2] <<
" " << std::showpoint << c[3];
162 if(_mesh.has_vertex_texcoords2D() && (userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS)) {
163 t = _mesh.texcoord2D(*vit);
164 _out <<
" " << t[0] <<
" " << t[1];
168 typename MeshT::FaceIter fit = _mesh.faces_begin();
169 typename MeshT::FaceIter end_fit = _mesh.faces_end();
170 typename MeshT::FaceVertexIter fvit;
173 for(; fit != end_fit; ++fit) {
178 _out << _mesh.valence(*fit);
181 fvit = _mesh.fv_iter(*fit);
184 for(;fvit.is_valid(); ++fvit) {
185 _out <<
" " << fvit->idx();
189 if(_mesh.has_face_colors() && (userWriteOptions_ & OFFImporter::FACECOLOR ) ) {
191 _out <<
" " << std::showpoint << c[0] <<
" " << std::showpoint << c[1] <<
" " << std::showpoint << c[2];
193 if(userWriteOptions_ & OFFImporter::COLORALPHA) _out <<
" " << std::showpoint << c[3];
202 template<
class MeshT >
210 typename MeshT::VertexIter vit = _mesh.vertices_begin();
211 typename MeshT::VertexIter end_vit = _mesh.vertices_end();
214 writeValue(_out, (uint)_mesh.n_vertices() );
215 writeValue(_out, (uint)_mesh.n_faces() );
216 writeValue(_out, (uint)_mesh.n_edges() );
219 for(; vit != end_vit; ++vit) {
222 p = _mesh.point(*vit);
223 writeValue(_out, p[0]);
224 writeValue(_out, p[1]);
225 writeValue(_out, p[2]);
228 if(_mesh.has_vertex_normals() && (userWriteOptions_ & OFFImporter::VERTEXNORMAL)) {
229 n = _mesh.normal(*vit);
230 writeValue(_out, n[0]);
231 writeValue(_out, n[1]);
232 writeValue(_out, n[2]);
238 if(_mesh.has_vertex_colors() && (userWriteOptions_ & OFFImporter::VERTEXCOLOR)) {
240 writeValue(_out, c[0]);
241 writeValue(_out, c[1]);
242 writeValue(_out, c[2]);
246 if(_mesh.has_vertex_texcoords2D() && (userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS)) {
247 t = _mesh.texcoord2D(*vit);
248 writeValue(_out, t[0]);
249 writeValue(_out, t[1]);
253 typename MeshT::FaceIter fit = _mesh.faces_begin();
254 typename MeshT::FaceIter end_fit = _mesh.faces_end();
255 typename MeshT::FaceVertexIter fvit;
258 for(; fit != end_fit; ++fit) {
261 writeValue(_out, _mesh.valence(*fit));
264 fvit = _mesh.fv_iter(*fit);
267 for(;fvit.is_valid(); ++fvit) {
268 writeValue(_out, fvit->idx());
272 if(_mesh.has_face_colors() && (userWriteOptions_ & OFFImporter::FACECOLOR)) {
275 if(userWriteOptions_ & OFFImporter::COLORALPHA) writeValue(_out, (uint)4);
276 else writeValue(_out, (uint)3);
280 writeValue(_out, c[0]);
281 writeValue(_out, c[1]);
282 writeValue(_out, c[2]);
284 if(userWriteOptions_ & OFFImporter::COLORALPHA) writeValue(_out, c[3]);
bool writeMesh(std::ostream &_out, MeshT &_mesh, BaseObject &_baseObj)
Writer function.
Add normals to mesh item (vertices/faces)
bool writeBinaryData(std::ostream &_out, MeshT &_mesh)
Write binary mesh data to file.
const QString getAllCommentsFlat() const
bool writeASCIIData(std::ostream &_out, MeshT &_mesh)
Write ASCII mesh data to file.
Add 2D texture coordinates (vertices, halfedges)