2004-11-29 09:12:10 +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 \/)\/ *
|
2004-11-29 09:12:10 +01:00
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
2008-10-15 10:02:14 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
2004-11-29 09:12:10 +01:00
|
|
|
* 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 $
|
2007-03-08 13:21:26 +01:00
|
|
|
Revision 1.11 2006/03/29 09:27:07 cignoni
|
|
|
|
Added managemnt of non critical errors
|
|
|
|
|
2006-03-29 11:27:07 +02:00
|
|
|
Revision 1.10 2006/03/29 08:16:31 corsini
|
|
|
|
Minor change in LoadMask
|
|
|
|
|
2006-03-29 10:16:31 +02:00
|
|
|
Revision 1.9 2006/03/27 07:17:49 cignoni
|
|
|
|
Added generic LoadMask
|
|
|
|
|
2006-03-27 09:17:49 +02:00
|
|
|
Revision 1.8 2006/03/07 13:19:29 cignoni
|
|
|
|
First Release with OBJ import support
|
|
|
|
|
2006-03-07 14:19:29 +01:00
|
|
|
Revision 1.7 2006/02/28 14:50:00 corsini
|
|
|
|
Fix comments
|
|
|
|
|
2006-02-28 15:50:00 +01:00
|
|
|
Revision 1.6 2006/02/10 16:14:53 corsini
|
|
|
|
Fix typo
|
|
|
|
|
2006-02-10 17:14:53 +01:00
|
|
|
Revision 1.5 2006/02/10 08:14:32 cignoni
|
|
|
|
Refactored import. No more duplicated code
|
|
|
|
|
2006-02-10 09:14:32 +01:00
|
|
|
Revision 1.4 2006/02/09 16:04:45 corsini
|
|
|
|
Expose load mask
|
|
|
|
|
2006-02-09 17:04:45 +01:00
|
|
|
Revision 1.3 2006/01/11 10:37:45 cignoni
|
|
|
|
Added use of Callback
|
|
|
|
|
2006-01-11 11:37:45 +01:00
|
|
|
Revision 1.2 2005/01/26 22:43:19 cignoni
|
|
|
|
Add std:: to stl containers
|
|
|
|
|
2005-01-26 23:43:19 +01:00
|
|
|
Revision 1.1 2004/11/29 08:12:10 cignoni
|
|
|
|
Initial Update
|
|
|
|
|
2004-11-29 09:12:10 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __VCGLIB_IMPORT
|
|
|
|
#define __VCGLIB_IMPORT
|
|
|
|
|
2006-03-07 14:19:29 +01:00
|
|
|
#include <wrap/io_trimesh/import_obj.h>
|
2004-11-29 09:12:10 +01:00
|
|
|
#include <wrap/io_trimesh/import_ply.h>
|
|
|
|
#include <wrap/io_trimesh/import_stl.h>
|
|
|
|
#include <wrap/io_trimesh/import_off.h>
|
2009-10-29 18:18:46 +01:00
|
|
|
#include <wrap/io_trimesh/import_vmi.h>
|
2004-11-29 09:12:10 +01:00
|
|
|
|
|
|
|
#include <locale>
|
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
|
|
|
namespace io {
|
|
|
|
|
2008-10-15 10:02:14 +02:00
|
|
|
/**
|
|
|
|
This class encapsulate a filter for automatically importing meshes by guessing
|
2004-11-29 09:12:10 +01:00
|
|
|
the right filter according to the extension
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <class OpenMeshType>
|
|
|
|
class Importer
|
|
|
|
{
|
|
|
|
private:
|
2009-10-29 18:18:46 +01:00
|
|
|
enum KnownTypes { KT_UNKNOWN, KT_PLY, KT_STL, KT_OFF, KT_OBJ, KT_VMI };
|
2004-11-29 09:12:10 +01:00
|
|
|
static int &LastType()
|
|
|
|
{
|
|
|
|
static int lastType= KT_UNKNOWN;
|
|
|
|
return lastType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2016-11-24 11:59:50 +01:00
|
|
|
enum ImporterError {
|
|
|
|
E_NOERROR =0 // No error =0 is the standard for ALL the imported files.
|
|
|
|
};
|
2004-11-29 09:12:10 +01:00
|
|
|
// simple aux function that returns true if a given file has a given extesnion
|
2016-02-24 06:57:27 +01:00
|
|
|
static bool FileExtension(std::string filename, std::string extension)
|
2004-11-29 09:12:10 +01:00
|
|
|
{
|
2016-02-24 06:57:27 +01:00
|
|
|
std::transform(filename.begin(), filename.end(), filename.begin(), ::tolower);
|
|
|
|
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
2005-01-26 23:43:19 +01:00
|
|
|
std::string end=filename.substr(filename.length()-extension.length(),extension.length());
|
2004-11-29 09:12:10 +01:00
|
|
|
return end==extension;
|
|
|
|
}
|
2011-03-21 18:20:38 +01:00
|
|
|
// Open Mesh, returns 0 on success.
|
2004-11-29 09:12:10 +01:00
|
|
|
static int Open(OpenMeshType &m, const char *filename, CallBackPos *cb=0)
|
|
|
|
{
|
2006-02-28 15:50:00 +01:00
|
|
|
int dummymask = 0;
|
2006-02-10 09:14:32 +01:00
|
|
|
return Open(m,filename,dummymask,cb);
|
2004-11-29 09:12:10 +01:00
|
|
|
}
|
|
|
|
|
2011-03-21 18:20:38 +01:00
|
|
|
/// Open Mesh and fills the load mask (the load mask must be initialized first); returns 0 on success.
|
2006-02-09 17:04:45 +01:00
|
|
|
static int Open(OpenMeshType &m, const char *filename, int &loadmask, CallBackPos *cb=0)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if(FileExtension(filename,"ply"))
|
|
|
|
{
|
|
|
|
err = ImporterPLY<OpenMeshType>::Open(m, filename, loadmask, cb);
|
|
|
|
LastType()=KT_PLY;
|
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"stl"))
|
|
|
|
{
|
|
|
|
err = ImporterSTL<OpenMeshType>::Open(m, filename, loadmask, cb);
|
|
|
|
LastType()=KT_STL;
|
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"off"))
|
|
|
|
{
|
|
|
|
err = ImporterOFF<OpenMeshType>::Open(m, filename, loadmask, cb);
|
|
|
|
LastType()=KT_OFF;
|
|
|
|
}
|
2006-03-07 14:19:29 +01:00
|
|
|
else if(FileExtension(filename,"obj"))
|
|
|
|
{
|
|
|
|
err = ImporterOBJ<OpenMeshType>::Open(m, filename, loadmask, cb);
|
|
|
|
LastType()=KT_OBJ;
|
|
|
|
}
|
2009-10-29 18:18:46 +01:00
|
|
|
else if(FileExtension(filename,"vmi"))
|
|
|
|
{
|
|
|
|
err = ImporterVMI<OpenMeshType>::Open(m, filename, loadmask, cb);
|
|
|
|
LastType()=KT_VMI;
|
|
|
|
}
|
2006-03-07 14:19:29 +01:00
|
|
|
else {
|
2006-02-09 17:04:45 +01:00
|
|
|
err=1;
|
|
|
|
LastType()=KT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-03-29 11:27:07 +02:00
|
|
|
static bool ErrorCritical(int error)
|
|
|
|
{
|
|
|
|
switch(LastType())
|
|
|
|
{
|
|
|
|
case KT_PLY : return (error>0); break;
|
|
|
|
case KT_STL : return (error>0); break;
|
|
|
|
case KT_OFF : return (error>0); break;
|
|
|
|
case KT_OBJ : return ImporterOBJ<OpenMeshType>::ErrorCritical(error); break;
|
|
|
|
}
|
|
|
|
|
2008-10-15 10:02:14 +02:00
|
|
|
return true;
|
2006-03-29 11:27:07 +02:00
|
|
|
}
|
|
|
|
|
2004-11-29 09:12:10 +01:00
|
|
|
static const char *ErrorMsg(int error)
|
|
|
|
{
|
|
|
|
switch(LastType())
|
|
|
|
{
|
|
|
|
case KT_PLY : return ImporterPLY<OpenMeshType>::ErrorMsg(error); break;
|
|
|
|
case KT_STL : return ImporterSTL<OpenMeshType>::ErrorMsg(error); break;
|
|
|
|
case KT_OFF : return ImporterOFF<OpenMeshType>::ErrorMsg(error); break;
|
2006-03-29 11:27:07 +02:00
|
|
|
case KT_OBJ : return ImporterOBJ<OpenMeshType>::ErrorMsg(error); break;
|
2009-10-29 18:18:46 +01:00
|
|
|
case KT_VMI : return ImporterVMI<OpenMeshType>::ErrorMsg(error); break;
|
2004-11-29 09:12:10 +01:00
|
|
|
}
|
2008-10-15 10:02:14 +02:00
|
|
|
return "Unknown type";
|
2004-11-29 09:12:10 +01:00
|
|
|
}
|
|
|
|
|
2006-03-27 09:17:49 +02:00
|
|
|
static bool LoadMask(const char * filename, int &mask)
|
|
|
|
{
|
2006-03-29 10:16:31 +02:00
|
|
|
bool err;
|
|
|
|
|
2006-03-27 09:17:49 +02:00
|
|
|
if(FileExtension(filename,"ply"))
|
|
|
|
{
|
|
|
|
err = ImporterPLY<OpenMeshType>::LoadMask(filename, mask);
|
|
|
|
LastType()=KT_PLY;
|
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"stl"))
|
|
|
|
{
|
|
|
|
mask = Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX;
|
2006-03-29 10:16:31 +02:00
|
|
|
err = true;
|
|
|
|
LastType()=KT_STL;
|
2006-03-27 09:17:49 +02:00
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"off"))
|
|
|
|
{
|
|
|
|
mask = Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX;
|
2006-03-29 10:16:31 +02:00
|
|
|
err = ImporterOFF<OpenMeshType>::LoadMask(filename, mask);
|
2006-03-27 09:17:49 +02:00
|
|
|
LastType()=KT_OFF;
|
|
|
|
}
|
|
|
|
else if(FileExtension(filename,"obj"))
|
|
|
|
{
|
|
|
|
err = ImporterOBJ<OpenMeshType>::LoadMask(filename, mask);
|
|
|
|
LastType()=KT_OBJ;
|
|
|
|
}
|
2008-10-15 10:02:14 +02:00
|
|
|
else
|
2006-03-29 10:16:31 +02:00
|
|
|
{
|
|
|
|
err = false;
|
2006-03-27 09:17:49 +02:00
|
|
|
LastType()=KT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2004-11-29 09:12:10 +01:00
|
|
|
}; // end class
|
|
|
|
} // end Namespace tri
|
|
|
|
} // end Namespace io
|
|
|
|
} // end Namespace vcg
|
|
|
|
|
|
|
|
#endif
|