From 68c881c0d15e8f55d594b42741b8d1cf63714377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Tue, 23 Jul 2013 13:46:43 +0000 Subject: [PATCH] Fix casts in OBJ Writer git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@844 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Core/IO/writer/OBJWriter.cc | 30 +++++++++++++----------- src/OpenMesh/Core/IO/writer/OBJWriter.hh | 4 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/OpenMesh/Core/IO/writer/OBJWriter.cc b/src/OpenMesh/Core/IO/writer/OBJWriter.cc index 8150af9d..f348b53e 100644 --- a/src/OpenMesh/Core/IO/writer/OBJWriter.cc +++ b/src/OpenMesh/Core/IO/writer/OBJWriter.cc @@ -45,6 +45,7 @@ //STL #include +#include // OpenMesh #include @@ -123,9 +124,9 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt, std::stream //----------------------------------------------------------------------------- -int _OBJWriter_::getMaterial(OpenMesh::Vec3f _color) const +size_t _OBJWriter_::getMaterial(OpenMesh::Vec3f _color) const { - for (uint i=0; i < material_.size(); i++) + for (size_t i=0; i < material_.size(); i++) if(material_[i] == _color) return i; @@ -136,9 +137,9 @@ int _OBJWriter_::getMaterial(OpenMesh::Vec3f _color) const //----------------------------------------------------------------------------- -int _OBJWriter_::getMaterial(OpenMesh::Vec4f _color) const +size_t _OBJWriter_::getMaterial(OpenMesh::Vec4f _color) const { - for (uint i=0; i < materialA_.size(); i++) + for (size_t i=0; i < materialA_.size(); i++) if(materialA_[i] == _color) return i; @@ -160,22 +161,22 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const materialA_.clear(); //iterate over faces - for (int i=0, nF=_be.n_faces(); i (_be.colorA( FaceHandle(i) )); + cA = color_cast (_be.colorA( FaceHandle(int(i)) )); getMaterial(cA); }else{ //and without alpha - c = color_cast (_be.color( FaceHandle(i) )); + c = color_cast (_be.color( FaceHandle(int(i)) )); getMaterial(c); } } //write the materials if ( _opt.color_has_alpha() ) - for (uint i=0; i < materialA_.size(); i++){ + for (size_t i=0; i < materialA_.size(); i++){ _out << "newmtl " << "mat" << i << std::endl; _out << "Ka 0.5000 0.5000 0.5000" << std::endl; _out << "Kd " << materialA_[i][0] << materialA_[i][1] << materialA_[i][2] << std::endl;; @@ -183,7 +184,7 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const _out << "illum 1" << std::endl; } else - for (uint i=0; i < material_.size(); i++){ + for (size_t i=0; i < material_.size(); i++){ _out << "newmtl " << "mat" << i << std::endl; _out << "Ka 0.5000 0.5000 0.5000" << std::endl; _out << "Kd " << material_[i][0] << material_[i][1] << material_[i][2] << std::endl;; @@ -200,7 +201,8 @@ bool _OBJWriter_:: write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _precision) const { - unsigned int i, j, nV, nF, idx; + unsigned int nV, nF, idx; + size_t i, j; Vec3f v, n; Vec2f t; VertexHandle vh; @@ -268,7 +270,7 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec _out << "vt " << t[0] <<" "<< t[1] << std::endl; } - int lastMat = -1; + size_t lastMat = std::numeric_limits::max(); // we do not want to write seperators if we only write vertex indices bool onlyVertices = !_opt.check(Options::VertexTexCoord) @@ -279,15 +281,15 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec { if (useMatrial && _opt.check(Options::FaceColor) ){ - int material = -1; + size_t material = std::numeric_limits::max(); //color with alpha if ( _opt.color_has_alpha() ){ - cA = color_cast (_be.colorA( FaceHandle(i) )); + cA = color_cast (_be.colorA( FaceHandle(int(i)) )); material = getMaterial(cA); } else{ //and without alpha - c = color_cast (_be.color( FaceHandle(i) )); + c = color_cast (_be.color( FaceHandle(int(i)) )); material = getMaterial(c); } diff --git a/src/OpenMesh/Core/IO/writer/OBJWriter.hh b/src/OpenMesh/Core/IO/writer/OBJWriter.hh index 7090b239..12c80351 100644 --- a/src/OpenMesh/Core/IO/writer/OBJWriter.hh +++ b/src/OpenMesh/Core/IO/writer/OBJWriter.hh @@ -103,9 +103,9 @@ private: mutable std::vector< OpenMesh::Vec3f > material_; mutable std::vector< OpenMesh::Vec4f > materialA_; - int getMaterial(OpenMesh::Vec3f _color) const; + size_t getMaterial(OpenMesh::Vec3f _color) const; - int getMaterial(OpenMesh::Vec4f _color) const; + size_t getMaterial(OpenMesh::Vec4f _color) const; bool writeMaterial(std::ostream& _out, BaseExporter&, Options) const; -- GitLab