- added the functionality to read meshes from istreams with the STLReader

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@704 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Isaak Lim
2012-09-26 15:02:18 +00:00
parent e4ac38ce96
commit 7d50c6def6
4 changed files with 278 additions and 21 deletions

View File

@@ -4,10 +4,10 @@
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
* *
* OpenMesh is free software: you can redistribute it and/or modify *
* OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
\*===========================================================================*/
/*===========================================================================*\
* *
* *
* $Revision$ *
* $Date$ *
* *
@@ -69,7 +69,7 @@ namespace IO {
//-----------------------------------------------------------------------------
short int read_short(FILE* _in, bool _swap)
short int read_short(FILE* _in, bool _swap)
{
union u1 { short int s; unsigned char c[2]; } sc;
fread((char*)sc.c, 1, 2, _in);
@@ -81,7 +81,7 @@ short int read_short(FILE* _in, bool _swap)
//-----------------------------------------------------------------------------
int read_int(FILE* _in, bool _swap)
int read_int(FILE* _in, bool _swap)
{
union u2 { int i; unsigned char c[4]; } ic;
fread((char*)ic.c, 1, 4, _in);
@@ -96,7 +96,7 @@ int read_int(FILE* _in, bool _swap)
//-----------------------------------------------------------------------------
float read_float(FILE* _in, bool _swap)
float read_float(FILE* _in, bool _swap)
{
union u3 { float f; unsigned char c[4]; } fc;
fread((char*)fc.c, 1, 4, _in);
@@ -111,7 +111,7 @@ float read_float(FILE* _in, bool _swap)
//-----------------------------------------------------------------------------
double read_double(FILE* _in, bool _swap)
double read_double(FILE* _in, bool _swap)
{
union u4 { double d; unsigned char c[8]; } dc;
fread((char*)dc.c, 1, 8, _in);
@@ -124,11 +124,68 @@ double read_double(FILE* _in, bool _swap)
return dc.d;
}
//-----------------------------------------------------------------------------
short int read_short(std::istream& _in, bool _swap)
{
union u1 { short int s; unsigned char c[2]; } sc;
_in.read((char*)sc.c, 2);
if (_swap) std::swap(sc.c[0], sc.c[1]);
return sc.s;
}
//-----------------------------------------------------------------------------
int read_int(std::istream& _in, bool _swap)
{
union u2 { int i; unsigned char c[4]; } ic;
_in.read((char*)ic.c, 4);
if (_swap) {
std::swap(ic.c[0], ic.c[3]);
std::swap(ic.c[1], ic.c[2]);
}
return ic.i;
}
//-----------------------------------------------------------------------------
float read_float(std::istream& _in, bool _swap)
{
union u3 { float f; unsigned char c[4]; } fc;
_in.read((char*)fc.c, 4);
if (_swap) {
std::swap(fc.c[0], fc.c[3]);
std::swap(fc.c[1], fc.c[2]);
}
return fc.f;
}
//-----------------------------------------------------------------------------
double read_double(std::istream& _in, bool _swap)
{
union u4 { double d; unsigned char c[8]; } dc;
_in.read((char*)dc.c, 8);
if (_swap) {
std::swap(dc.c[0], dc.c[7]);
std::swap(dc.c[1], dc.c[6]);
std::swap(dc.c[2], dc.c[5]);
std::swap(dc.c[3], dc.c[4]);
}
return dc.d;
}
//-----------------------------------------------------------------------------
void write_short(short int _i, FILE* _out, bool _swap)
void write_short(short int _i, FILE* _out, bool _swap)
{
union u1 { short int s; unsigned char c[2]; } sc;
sc.s = _i;
@@ -140,7 +197,7 @@ void write_short(short int _i, FILE* _out, bool _swap)
//-----------------------------------------------------------------------------
void write_int(int _i, FILE* _out, bool _swap)
void write_int(int _i, FILE* _out, bool _swap)
{
union u2 { int i; unsigned char c[4]; } ic;
ic.i = _i;
@@ -155,7 +212,7 @@ void write_int(int _i, FILE* _out, bool _swap)
//-----------------------------------------------------------------------------
void write_float(float _f, FILE* _out, bool _swap)
void write_float(float _f, FILE* _out, bool _swap)
{
union u3 { float f; unsigned char c[4]; } fc;
fc.f = _f;
@@ -170,7 +227,7 @@ void write_float(float _f, FILE* _out, bool _swap)
//-----------------------------------------------------------------------------
void write_double(double _d, FILE* _out, bool _swap)
void write_double(double _d, FILE* _out, bool _swap)
{
union u4 { double d; unsigned char c[8]; } dc;
dc.d = _d;