2005-11-12 19:34:17 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
2016-06-13 07:29:25 +02:00
|
|
|
* Copyright(C) 2004-2016 \/)\/ *
|
2005-11-12 19:34:17 +01:00
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2008-04-15 12:38:12 +02:00
|
|
|
Revision 1.6 2006/11/04 14:01:00 granzuglia
|
|
|
|
fixed bug: &(*filename.end()) ---> &(*filename.rbegin())
|
|
|
|
|
2006-11-04 15:01:00 +01:00
|
|
|
Revision 1.5 2006/07/09 05:32:15 cignoni
|
|
|
|
Uncommented obj export. Now obj saving is enabled by default
|
|
|
|
|
2006-07-09 07:32:15 +02:00
|
|
|
Revision 1.4 2006/03/29 08:14:20 corsini
|
|
|
|
Add LoadMask to OFF importer
|
|
|
|
|
2006-03-29 10:14:20 +02:00
|
|
|
Revision 1.3 2006/02/16 19:28:36 fmazzant
|
|
|
|
transfer of Export_3ds.h, Export_obj.h, Io_3ds_obj_material.h from Meshlab to vcg
|
|
|
|
|
2006-02-16 20:28:36 +01:00
|
|
|
Revision 1.2 2006/01/13 15:47:42 cignoni
|
|
|
|
Uniformed return type to the style of Open. Now every export function returns 0 in case of success.
|
|
|
|
|
2006-01-13 16:47:43 +01:00
|
|
|
Revision 1.1 2005/11/12 18:34:17 cignoni
|
|
|
|
Initial Commit
|
|
|
|
|
2005-11-12 19:34:17 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __VCGLIB_TRIMESH_GENERIC_EXPORT
|
|
|
|
#define __VCGLIB_TRIMESH_GENERIC_EXPORT
|
|
|
|
|
|
|
|
#include <wrap/io_trimesh/export_ply.h>
|
|
|
|
#include <wrap/io_trimesh/export_stl.h>
|
|
|
|
#include <wrap/io_trimesh/export_off.h>
|
|
|
|
#include <wrap/io_trimesh/export_dxf.h>
|
2006-07-09 07:32:15 +02:00
|
|
|
#include <wrap/io_trimesh/export_obj.h>
|
2005-11-12 19:34:17 +01:00
|
|
|
|
|
|
|
#include <locale>
|
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
|
|
|
namespace io {
|
|
|
|
|
|
|
|
/**
|
|
|
|
This class encapsulate a filter for automatically importing meshes by guessing
|
|
|
|
the right filter according to the extension
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <class OpenMeshType>
|
|
|
|
class Exporter
|
|
|
|
{
|
|
|
|
private:
|
2006-02-16 20:28:36 +01:00
|
|
|
enum KnownTypes { KT_UNKNOWN, KT_PLY, KT_STL, KT_DXF, KT_OFF, KT_OBJ};
|
2005-11-12 19:34:17 +01:00
|
|
|
static int &LastType()
|
|
|
|
{
|
|
|
|
static int lastType= KT_UNKNOWN;
|
|
|
|
return lastType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
// simple aux function that returns true if a given file has a given extesnion
|
|
|
|
static bool FileExtension(std::string filename, std::string extension)
|
|
|
|
{
|
|
|
|
std::locale loc1 ;
|
2006-11-04 15:01:00 +01:00
|
|
|
std::use_facet<std::ctype<char> > ( loc1 ).tolower(&*filename.begin(),&(*filename.rbegin()));
|
|
|
|
std::use_facet<std::ctype<char> > ( loc1 ).tolower(&*extension.begin(),&(*extension.rbegin()));
|
2005-11-12 19:34:17 +01:00
|
|
|
std::string end=filename.substr(filename.length()-extension.length(),extension.length());
|
|
|
|
return end==extension;
|
|
|
|
}
|
|
|
|
// Open Mesh
|
|
|
|
static int Save(OpenMeshType &m, const char *filename, CallBackPos *cb=0)
|
2006-01-13 16:47:43 +01:00
|
|
|
{
|
|
|
|
return Save(m,filename,0,cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open Mesh
|
|
|
|
static int Save(OpenMeshType &m, const char *filename, const int mask, CallBackPos *cb=0)
|
2005-11-12 19:34:17 +01:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if(FileExtension(filename,"ply"))
|
|
|
|
{
|
2006-01-13 16:47:43 +01:00
|
|
|
err = ExporterPLY<OpenMeshType>::Save(m,filename,mask);
|
2005-11-12 19:34:17 +01:00
|
|
|
LastType()=KT_PLY;
|
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"stl"))
|
|
|
|
{
|
|
|
|
err = ExporterSTL<OpenMeshType>::Save(m,filename);
|
|
|
|
LastType()=KT_STL;
|
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"off"))
|
|
|
|
{
|
2008-04-15 12:38:12 +02:00
|
|
|
err = ExporterOFF<OpenMeshType>::Save(m,filename,mask);
|
2005-11-12 19:34:17 +01:00
|
|
|
LastType()=KT_OFF;
|
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"dxf"))
|
|
|
|
{
|
|
|
|
err = ExporterDXF<OpenMeshType>::Save(m,filename);
|
|
|
|
LastType()=KT_DXF;
|
|
|
|
}
|
2006-02-16 20:28:36 +01:00
|
|
|
else if(FileExtension(filename,"obj"))
|
|
|
|
{
|
2006-07-09 07:32:15 +02:00
|
|
|
err = ExporterOBJ<OpenMeshType>::Save(m,filename,mask,cb);
|
|
|
|
LastType()=KT_OBJ;
|
2006-02-16 20:28:36 +01:00
|
|
|
}
|
2005-11-12 19:34:17 +01:00
|
|
|
else {
|
|
|
|
err=1;
|
|
|
|
LastType()=KT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *ErrorMsg(int error)
|
|
|
|
{
|
|
|
|
switch(LastType())
|
|
|
|
{
|
|
|
|
case KT_PLY : return ExporterPLY<OpenMeshType>::ErrorMsg(error); break;
|
|
|
|
case KT_STL : return ExporterSTL<OpenMeshType>::ErrorMsg(error); break;
|
|
|
|
case KT_OFF : return ExporterOFF<OpenMeshType>::ErrorMsg(error); break;
|
|
|
|
case KT_DXF : return ExporterDXF<OpenMeshType>::ErrorMsg(error); break;
|
2006-07-09 07:32:15 +02:00
|
|
|
case KT_OBJ : return ExporterOBJ<OpenMeshType>::ErrorMsg(error); break;
|
2005-11-12 19:34:17 +01:00
|
|
|
}
|
|
|
|
return "Unknown type";
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // end class
|
|
|
|
} // end Namespace tri
|
|
|
|
} // end Namespace io
|
|
|
|
} // end Namespace vcg
|
|
|
|
|
|
|
|
#endif
|