Commit 68c881c0 authored by Jan Möbius's avatar Jan Möbius
Browse files

Fix casts in OBJ Writer

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@844 fdac6126-5c0c-442c-9429-916003d36597
parent 6e62de90
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
//STL //STL
#include <fstream> #include <fstream>
#include <limits>
// OpenMesh // OpenMesh
#include <OpenMesh/Core/System/config.h> #include <OpenMesh/Core/System/config.h>
...@@ -123,9 +124,9 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt, std::stream ...@@ -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) if(material_[i] == _color)
return i; return i;
...@@ -136,9 +137,9 @@ int _OBJWriter_::getMaterial(OpenMesh::Vec3f _color) const ...@@ -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) if(materialA_[i] == _color)
return i; return i;
...@@ -160,22 +161,22 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -160,22 +161,22 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
materialA_.clear(); materialA_.clear();
//iterate over faces //iterate over faces
for (int i=0, nF=_be.n_faces(); i<nF; ++i) for (size_t i=0, nF=_be.n_faces(); i<nF; ++i)
{ {
//color with alpha //color with alpha
if ( _opt.color_has_alpha() ){ if ( _opt.color_has_alpha() ){
cA = color_cast<OpenMesh::Vec4f> (_be.colorA( FaceHandle(i) )); cA = color_cast<OpenMesh::Vec4f> (_be.colorA( FaceHandle(int(i)) ));
getMaterial(cA); getMaterial(cA);
}else{ }else{
//and without alpha //and without alpha
c = color_cast<OpenMesh::Vec3f> (_be.color( FaceHandle(i) )); c = color_cast<OpenMesh::Vec3f> (_be.color( FaceHandle(int(i)) ));
getMaterial(c); getMaterial(c);
} }
} }
//write the materials //write the materials
if ( _opt.color_has_alpha() ) 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 << "newmtl " << "mat" << i << std::endl;
_out << "Ka 0.5000 0.5000 0.5000" << 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;; _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 ...@@ -183,7 +184,7 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
_out << "illum 1" << std::endl; _out << "illum 1" << std::endl;
} }
else 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 << "newmtl " << "mat" << i << std::endl;
_out << "Ka 0.5000 0.5000 0.5000" << 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;; _out << "Kd " << material_[i][0] << material_[i][1] << material_[i][2] << std::endl;;
...@@ -200,7 +201,8 @@ bool ...@@ -200,7 +201,8 @@ bool
_OBJWriter_:: _OBJWriter_::
write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _precision) const 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; Vec3f v, n;
Vec2f t; Vec2f t;
VertexHandle vh; VertexHandle vh;
...@@ -268,7 +270,7 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec ...@@ -268,7 +270,7 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec
_out << "vt " << t[0] <<" "<< t[1] << std::endl; _out << "vt " << t[0] <<" "<< t[1] << std::endl;
} }
int lastMat = -1; size_t lastMat = std::numeric_limits<std::size_t>::max();
// we do not want to write seperators if we only write vertex indices // we do not want to write seperators if we only write vertex indices
bool onlyVertices = !_opt.check(Options::VertexTexCoord) bool onlyVertices = !_opt.check(Options::VertexTexCoord)
...@@ -279,15 +281,15 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec ...@@ -279,15 +281,15 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec
{ {
if (useMatrial && _opt.check(Options::FaceColor) ){ if (useMatrial && _opt.check(Options::FaceColor) ){
int material = -1; size_t material = std::numeric_limits<std::size_t>::max();
//color with alpha //color with alpha
if ( _opt.color_has_alpha() ){ if ( _opt.color_has_alpha() ){
cA = color_cast<OpenMesh::Vec4f> (_be.colorA( FaceHandle(i) )); cA = color_cast<OpenMesh::Vec4f> (_be.colorA( FaceHandle(int(i)) ));
material = getMaterial(cA); material = getMaterial(cA);
} else{ } else{
//and without alpha //and without alpha
c = color_cast<OpenMesh::Vec3f> (_be.color( FaceHandle(i) )); c = color_cast<OpenMesh::Vec3f> (_be.color( FaceHandle(int(i)) ));
material = getMaterial(c); material = getMaterial(c);
} }
......
...@@ -103,9 +103,9 @@ private: ...@@ -103,9 +103,9 @@ private:
mutable std::vector< OpenMesh::Vec3f > material_; mutable std::vector< OpenMesh::Vec3f > material_;
mutable std::vector< OpenMesh::Vec4f > materialA_; 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; bool writeMaterial(std::ostream& _out, BaseExporter&, Options) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment