2009-07-29 15:44:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
2016-06-13 07:29:25 +02:00
|
|
|
* Copyright(C) 2004-2016 \/)\/ *
|
2009-07-29 15:44:00 +02:00
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
2014-02-13 16:52:17 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
2009-07-29 15:44:00 +02: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. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __VCGLIB_EXPORT_VMI
|
|
|
|
#define __VCGLIB_EXPORT_VMI
|
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
|
2009-07-29 15:44:00 +02:00
|
|
|
/*
|
2014-02-13 16:52:17 +01:00
|
|
|
VMI VCG Mesh Image.
|
|
|
|
The vmi image file consists of a header containing the description of the vertex and face type,
|
|
|
|
the length of vectors containing vertices of faces and the memory image of the object mesh as it is when
|
|
|
|
passed to the function Save(SaveMeshType m).
|
|
|
|
NOTE: THIS IS NOT A FILE FORMAT. IT IS ONLY USEFUL FOR DUMPING MESH IMAGES FOR DEBUG PURPOSE.
|
|
|
|
Example of use: say you are running a time consuming mesh processing and you want to save intermediate
|
|
|
|
state, but no file format support all the attributes you need in your vertex/face type.
|
|
|
|
NOTE2: At the present if you add members to your TriMesh these will NOT be saved. More precisely, this file and
|
|
|
|
import_vmi must be updated to reflect changes in vcg/complex/trimesh/base.h
|
|
|
|
*/
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2013-11-28 16:06:28 +01:00
|
|
|
#include <vcg/complex/complex.h>
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-07-29 15:44:00 +02:00
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
|
|
|
namespace io {
|
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
template <int N> struct PlaceHolderType{ char A[N];};
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2012-06-29 17:32:33 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
template <class SaveMeshType>
|
|
|
|
class ExporterVMI
|
|
|
|
{
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2012-06-29 17:32:33 +02:00
|
|
|
|
|
|
|
static char * & Out_mem(){static char * out_mem; return out_mem;}
|
|
|
|
static unsigned int & Out_mode(){static unsigned int out_mode = 0; return out_mode;}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned int & pos(){static unsigned int p = 0; return p;}
|
2013-09-23 13:07:30 +02:00
|
|
|
static int fwrite_sim(const void * , size_t size, size_t count){ pos() += size * count;return size * count; }
|
|
|
|
static int fwrite_mem(const void *src , size_t size, size_t count ){ memcpy(&Out_mem()[pos()],src,size*count); pos() += size * count;return size * count; }
|
2012-06-29 17:32:33 +02:00
|
|
|
|
|
|
|
|
2013-09-23 13:07:30 +02:00
|
|
|
static int WriteOut(const void * src, size_t size, size_t count){
|
2012-06-29 17:32:33 +02:00
|
|
|
switch(Out_mode()){
|
2013-09-23 13:07:30 +02:00
|
|
|
case 0: return fwrite_sim(src, size,count); break;
|
|
|
|
case 1: return fwrite_mem(src, size,count); break;
|
|
|
|
case 2: return fwrite(src, size,count, F() ); break;
|
2012-06-29 17:32:33 +02:00
|
|
|
}
|
2014-02-13 16:52:17 +01:00
|
|
|
assert(0);
|
|
|
|
return 0;
|
2012-06-29 17:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-23 13:07:30 +02:00
|
|
|
static void WriteString( const char * in) { unsigned int l = strlen(in); WriteOut(&l,4,1 ); WriteOut(in,1,l );}
|
2014-02-13 16:52:17 +01:00
|
|
|
static void WriteInt (const unsigned int i) { WriteOut(&i,1,4 );}
|
2012-06-29 17:32:33 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
static void WriteFloat( const float v) { WriteOut(&v,1,sizeof(float) );}
|
2010-02-19 18:34:38 +01:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
/* save Ocf Vertex Components */
|
|
|
|
template <typename OpenMeshType,typename CONT>
|
|
|
|
struct SaveVertexOcf{
|
2013-09-23 13:07:30 +02:00
|
|
|
SaveVertexOcf( const CONT & /*vert*/, bool only_header){
|
2014-02-13 16:52:17 +01:00
|
|
|
// do nothing, it is a std::vector
|
|
|
|
if(only_header){
|
|
|
|
WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_MARK_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
|
|
|
|
WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* partial specialization for vector_ocf */
|
|
|
|
template <typename MeshType>
|
|
|
|
struct SaveVertexOcf<MeshType, vertex::vector_ocf<typename MeshType::VertexType> >{
|
|
|
|
typedef typename MeshType::VertexType VertexType;
|
|
|
|
SaveVertexOcf( const vertex::vector_ocf<VertexType> & vert, bool only_header){
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-10-29 18:23:47 +01:00
|
|
|
if( VertexType::HasQualityOcf() && vert.IsQualityEnabled()){
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "HAS_VERTEX_QUALITY_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-10-29 18:23:47 +01:00
|
|
|
if( VertexType::HasColorOcf() && vert.IsColorEnabled()){
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "HAS_VERTEX_COLOR_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-10-29 18:23:47 +01:00
|
|
|
if( VertexType::HasNormalOcf() && vert.IsNormalEnabled()){
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "HAS_VERTEX_NORMAL_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2012-07-02 16:38:10 +02:00
|
|
|
if( VertexType::HasMarkOcf() && vert.IsMarkEnabled()){
|
2013-09-23 13:07:30 +02:00
|
|
|
WriteString( "HAS_VERTEX_MARK_OCF");
|
|
|
|
if(!only_header) WriteOut(&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size() );
|
|
|
|
}else WriteString( "NOT_HAS_VERTEX_MARK_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( VertexType::HasTexCoordOcf() && vert.IsTexCoordEnabled()){
|
|
|
|
WriteString( "HAS_VERTEX_TEXCOORD_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( VertexType::HasVFAdjacencyOcf() && vert.IsVFAdjacencyEnabled()){
|
|
|
|
WriteString( "HAS_VERTEX_VFADJACENCY_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( VertexType::HasCurvatureOcf() && vert.IsCurvatureEnabled()){
|
|
|
|
WriteString( "HAS_VERTEX_CURVATURE_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( VertexType::HasCurvatureDirOcf() && vert.IsCurvatureDirEnabled()){
|
|
|
|
WriteString( "HAS_VERTEX_CURVATUREDIR_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( VertexType::HasRadiusOcf() && vert.IsRadiusEnabled()){
|
|
|
|
WriteString( "HAS_VERTEX_RADIUS_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
}
|
|
|
|
};
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
/* save Ocf Face Components */
|
|
|
|
template <typename MeshType,typename CONT>
|
|
|
|
struct SaveFaceOcf{
|
2013-09-23 13:07:30 +02:00
|
|
|
SaveFaceOcf( const CONT & /*face*/, bool only_header){
|
2014-02-13 16:52:17 +01:00
|
|
|
// it is a std::vector
|
|
|
|
if(only_header){
|
|
|
|
WriteString( "NOT_HAS_FACE_QUALITY_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_COLOR_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_NORMAL_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_MARK_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
|
|
|
|
WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* partial specialization for vector_ocf */
|
|
|
|
template <typename MeshType>
|
|
|
|
struct SaveFaceOcf< MeshType, face::vector_ocf<typename MeshType::FaceType> >{
|
|
|
|
typedef typename MeshType::FaceType FaceType;
|
|
|
|
SaveFaceOcf( const face::vector_ocf<FaceType> & face, bool only_header){
|
|
|
|
|
|
|
|
if( FaceType::HasQualityOcf() && face.IsQualityEnabled()){
|
|
|
|
WriteString( "HAS_FACE_QUALITY_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.QV[0],sizeof(typename FaceType::QualityType),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_QUALITY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasColorOcf() && face.IsColorEnabled()){
|
|
|
|
WriteString( "HAS_FACE_COLOR_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.CV[0],sizeof(typename FaceType::ColorType),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_COLOR_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasNormalOcf() && face.IsNormalEnabled()){
|
|
|
|
WriteString( "HAS_FACE_NORMAL_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.NV[0],sizeof(typename FaceType::NormalType),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_NORMAL_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasMarkOcf() && face.IsMarkEnabled()){
|
|
|
|
WriteString( "HAS_FACE_MARK_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.MV[0],sizeof(typename FaceType::MarkType),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_MARK_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasWedgeTexCoordOcf() && face.IsWedgeTexCoordEnabled()){
|
|
|
|
WriteString( "HAS_FACE_WEDGETEXCOORD_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasFFAdjacencyOcf() && face.IsFFAdjacencyEnabled()){
|
|
|
|
WriteString( "HAS_FACE_FFADJACENCY_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasVFAdjacencyOcf() && face.IsVFAdjacencyEnabled()){
|
|
|
|
WriteString( "HAS_FACE_VFADJACENCY_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasWedgeColorOcf() && face.IsWedgeColorEnabled()){
|
|
|
|
WriteString( "HAS_FACE_WEDGECOLOR_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
|
2009-10-09 12:17:24 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if( FaceType::HasWedgeNormalOcf() && face.IsWedgeNormalEnabled()){
|
|
|
|
WriteString( "HAS_FACE_WEDGENORMAL_OCF");
|
2013-09-23 13:07:30 +02:00
|
|
|
if(!only_header) WriteOut(&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}else WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
|
|
|
|
}
|
|
|
|
};
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
|
2009-10-30 15:50:50 +01:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
static FILE *& F(){static FILE * f; return f;}
|
2009-10-09 12:17:24 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
typedef typename SaveMeshType::FaceContainer FaceContainer;
|
|
|
|
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
|
|
|
typedef typename SaveMeshType::VertContainer VertContainer;
|
|
|
|
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
|
|
|
typedef typename SaveMeshType::VertexType VertexType;
|
|
|
|
typedef typename SaveMeshType::FaceType FaceType;
|
2011-06-03 10:38:13 +02:00
|
|
|
typedef SimpleTempDataBase STDBv;
|
|
|
|
typedef SimpleTempDataBase STDBf;
|
2014-02-13 16:52:17 +01:00
|
|
|
// typedef typename SaveMeshType::Attribute <SaveMeshType::FaceContainer> STDBm;
|
|
|
|
|
|
|
|
/* save Ocf Components */
|
2009-10-09 12:17:24 +02:00
|
|
|
|
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
public:
|
2012-06-29 17:32:33 +02:00
|
|
|
|
2010-02-19 00:33:56 +01:00
|
|
|
static int Save(const SaveMeshType &m,const char * filename){
|
2012-06-29 17:32:33 +02:00
|
|
|
Out_mode() = 2;
|
|
|
|
F() = fopen(filename,"wb");
|
|
|
|
if(F()==NULL) return 1; // 1 is the error code for cant'open, see the ErrorMsg function
|
2012-07-02 16:38:10 +02:00
|
|
|
int res = Serialize(m);
|
2012-06-29 17:32:33 +02:00
|
|
|
fclose(F());
|
2012-07-02 16:38:10 +02:00
|
|
|
return res;
|
2012-06-29 17:32:33 +02:00
|
|
|
}
|
|
|
|
static int DumpToMem(const SaveMeshType &m,char * ptr){
|
|
|
|
Out_mode() = 1;
|
|
|
|
pos() = 0;
|
|
|
|
Out_mem() = ptr;
|
|
|
|
return Serialize(m);
|
|
|
|
}
|
|
|
|
static int BufferSize(const SaveMeshType &m){
|
|
|
|
Out_mode() = 0;
|
|
|
|
pos() = 0 ;
|
|
|
|
Serialize(m);
|
|
|
|
return pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int Serialize(const SaveMeshType &m){
|
2014-02-13 16:52:17 +01:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int vertSize,faceSize;
|
2010-02-19 00:33:56 +01:00
|
|
|
std::vector<std::string> nameF,nameV;
|
2014-02-13 16:52:17 +01:00
|
|
|
SaveMeshType::FaceType::Name(nameF);
|
|
|
|
SaveMeshType::VertexType::Name(nameV);
|
|
|
|
vertSize = m.vert.size();
|
|
|
|
faceSize = m.face.size();
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
/* write header */
|
|
|
|
WriteString( "FACE_TYPE");
|
|
|
|
WriteInt( nameF.size());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
for(i=0; i < nameF.size(); ++i) WriteString( nameF[i].c_str());
|
|
|
|
SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,true);
|
|
|
|
WriteString( "SIZE_VECTOR_FACES");
|
|
|
|
WriteInt( faceSize );
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "VERTEX_TYPE");
|
|
|
|
WriteInt( nameV.size());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
for(i=0; i < nameV.size(); ++i) WriteString( nameV[i].c_str());
|
|
|
|
SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,true);
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "SIZE_VECTOR_VERTS");
|
|
|
|
WriteInt( vertSize);
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "BOUNDING_BOX");
|
|
|
|
float float_value;
|
|
|
|
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.min[i]; WriteFloat( float_value);}
|
|
|
|
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.max[i]; WriteFloat( float_value);}
|
2010-02-19 18:34:38 +01:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "end_header");
|
|
|
|
/* end header */
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2012-07-02 16:38:10 +02:00
|
|
|
if(vertSize!=0){
|
2011-03-14 12:18:16 +01:00
|
|
|
void * offsetV = (void*) &m.vert[0];
|
2014-02-13 16:52:17 +01:00
|
|
|
/* write the address of the first vertex */
|
2013-09-23 13:07:30 +02:00
|
|
|
WriteOut(&offsetV,sizeof(void *),1 );
|
2014-02-13 16:52:17 +01:00
|
|
|
}
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if(faceSize!=0){
|
2011-03-14 12:18:16 +01:00
|
|
|
void * offsetF= (void*)&m.face[0];
|
2014-02-13 16:52:17 +01:00
|
|
|
/* write the address of the first face */
|
2013-09-23 13:07:30 +02:00
|
|
|
WriteOut(&offsetF,sizeof( void *),1 );
|
2014-02-13 16:52:17 +01:00
|
|
|
}
|
2012-07-02 16:38:10 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
/* save the object mesh */
|
2013-09-23 13:07:30 +02:00
|
|
|
WriteOut(&m.shot,sizeof(Shot<typename SaveMeshType::ScalarType>),1 );
|
|
|
|
WriteOut(&m.vn,sizeof(int),1 );
|
|
|
|
WriteOut(&m.fn,sizeof(int),1 );
|
|
|
|
WriteOut(&m.imark,sizeof(int),1 );
|
|
|
|
WriteOut(&m.bbox,sizeof(Box3<typename SaveMeshType::ScalarType>),1 );
|
|
|
|
WriteOut(&m.C(),sizeof(Color4b),1 );
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
unsigned int written;
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if(vertSize!=0){
|
|
|
|
/* save the vertices */
|
2013-09-23 13:07:30 +02:00
|
|
|
written = WriteOut((void*)&m.vert[0],sizeof(typename SaveMeshType::VertexType),m.vert.size() );
|
2014-02-13 16:52:17 +01:00
|
|
|
SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,false);
|
|
|
|
}
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2012-07-02 16:38:10 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
if(faceSize!=0){
|
|
|
|
/* save the faces */
|
2013-09-23 13:07:30 +02:00
|
|
|
written = WriteOut((void*)&m.face[0],sizeof(typename SaveMeshType::FaceType),faceSize );
|
2014-02-13 16:52:17 +01:00
|
|
|
SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,false);
|
|
|
|
|
|
|
|
}
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
/* save the attributes */
|
2009-10-07 14:45:49 +02:00
|
|
|
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
|
2009-07-29 15:44:00 +02:00
|
|
|
|
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
/* save the per vertex attributes */
|
|
|
|
{
|
|
|
|
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
|
|
|
|
unsigned int n_named_attr = 0;
|
|
|
|
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "N_PER_VERTEX_ATTRIBUTES"); WriteInt ( n_named_attr);
|
|
|
|
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai)
|
|
|
|
if(!(*ai)._name.empty())
|
|
|
|
{
|
|
|
|
STDBv * stdb = (STDBv *) (*ai)._handle;
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "PER_VERTEX_ATTR_NAME");
|
|
|
|
WriteString( (*ai)._name.c_str() );
|
|
|
|
|
|
|
|
WriteString( "PER_VERTEX_ATTR_SIZE");
|
|
|
|
WriteInt( stdb->SizeOf());
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2013-09-23 13:07:30 +02:00
|
|
|
WriteOut(stdb->DataBegin(),m.vert.size(),stdb->SizeOf() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
/* save the per face attributes */
|
|
|
|
{
|
|
|
|
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
|
|
|
|
unsigned int n_named_attr = 0;
|
|
|
|
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "N_PER_FACE_ATTRIBUTES");
|
|
|
|
WriteInt ( n_named_attr);
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai)
|
|
|
|
if(!(*ai)._name.empty())
|
|
|
|
{
|
|
|
|
STDBf * stdb = (STDBf *) (*ai)._handle;
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "PER_FACE_ATTR_NAME");
|
|
|
|
WriteString( (*ai)._name.c_str());
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "PER_FACE_ATTR_SIZE");
|
|
|
|
WriteInt( stdb->SizeOf());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2013-09-23 13:07:30 +02:00
|
|
|
WriteOut(stdb->DataBegin(),m.face.size(),stdb->SizeOf() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///* save the per mesh attributes */
|
|
|
|
{
|
|
|
|
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
|
|
|
|
unsigned int n_named_attr = 0;
|
|
|
|
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
|
|
|
|
WriteString( "N_PER_MESH_ATTRIBUTES"); WriteInt( n_named_attr);
|
|
|
|
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai)
|
|
|
|
if(!(*ai)._name.empty())
|
|
|
|
{
|
2011-06-03 11:02:48 +02:00
|
|
|
SimpleTempDataBase * handle = (SimpleTempDataBase *) (*ai)._handle ;
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
WriteString( "PER_MESH_ATTR_NAME");
|
|
|
|
WriteString( (*ai)._name.c_str());
|
|
|
|
|
|
|
|
WriteString( "PER_MESH_ATTR_SIZE");
|
|
|
|
WriteInt( handle->SizeOf());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2013-09-23 13:07:30 +02:00
|
|
|
WriteOut(handle->DataBegin(),1,handle->SizeOf() );
|
2014-02-13 16:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2014-02-13 16:52:17 +01:00
|
|
|
// fflush(F());
|
2010-02-19 00:33:56 +01:00
|
|
|
return 0;
|
2014-02-13 16:52:17 +01:00
|
|
|
}
|
2010-02-19 00:33:56 +01:00
|
|
|
static const char *ErrorMsg(int error)
|
|
|
|
{
|
|
|
|
static std::vector<std::string> off_error_msg;
|
|
|
|
if(off_error_msg.empty())
|
|
|
|
{
|
|
|
|
off_error_msg.resize(2 );
|
|
|
|
off_error_msg[0]="No errors";
|
|
|
|
off_error_msg[1]="Can't open file";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(error>1 || error<0) return "Unknown error";
|
|
|
|
else return off_error_msg[error].c_str();
|
|
|
|
}
|
2014-02-13 16:52:17 +01:00
|
|
|
}; // end class
|
2009-07-29 15:44:00 +02:00
|
|
|
|
|
|
|
} // end Namespace tri
|
|
|
|
} // end Namespace io
|
|
|
|
} // end Namespace vcg
|
|
|
|
|
|
|
|
#endif
|