2009-07-29 15:44:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* 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 $
|
|
|
|
Revision 1.1 2007/02/14 01:20:37 ganovelli
|
|
|
|
working draft of VCG Mesh Image importer and exporter. Does not consider optional attributes. The mesh atributes are only vn and fn (no bbox, texture coordiantes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __VCGLIB_EXPORT_VMI
|
|
|
|
#define __VCGLIB_EXPORT_VMI
|
|
|
|
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-07-29 15:44:00 +02: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-10-08 17:44:59 +02:00
|
|
|
#include <vcg/simplex/face/component.h>
|
|
|
|
#include <vcg/simplex/face/component_ocf.h>
|
|
|
|
#include <vcg/simplex/vertex/component.h>
|
|
|
|
#include <vcg/simplex/vertex/component_ocf.h>
|
|
|
|
|
2009-07-29 15:44:00 +02:00
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
|
|
|
namespace io {
|
|
|
|
|
|
|
|
template <int N> struct PlaceHolderType{ char A[N];};
|
|
|
|
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-30 15:50:50 +01:00
|
|
|
template <class SaveMeshType>
|
|
|
|
class ExporterVMI
|
|
|
|
{
|
|
|
|
|
|
|
|
static void WriteString(FILE *f,const char * in) { unsigned int l = strlen(in); fwrite(&l,4,1,f); fwrite(in,1,l,f);}
|
|
|
|
static void WriteInt(FILE *f,const unsigned int i) { fwrite(&i,1,4,f);}
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2010-02-19 18:34:38 +01:00
|
|
|
static void WriteFloat(FILE *f,const float v) { fwrite(&v,1,sizeof(float),f);}
|
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
/* save Ocf Vertex Components */
|
2009-10-09 12:17:24 +02:00
|
|
|
template <typename OpenMeshType,typename CONT>
|
2009-10-08 17:44:59 +02:00
|
|
|
struct SaveVertexOcf{
|
2009-11-18 00:34:46 +01:00
|
|
|
SaveVertexOcf(FILE*f, const CONT & /*vert*/, bool only_header){
|
2009-10-08 17:44:59 +02:00
|
|
|
// do nothing, it is a std::vector
|
2009-10-30 15:07:51 +01:00
|
|
|
if(only_header){
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_QUALITY_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_COLOR_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_NORMAL_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_MARK_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_TEXCOORD_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_VFADJACENCY_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_CURVATURE_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_CURVATUREDIR_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_VERTEX_RADIUS_OCF");
|
|
|
|
}
|
2009-10-08 17:44:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* partial specialization for vector_ocf */
|
2009-10-09 12:17:24 +02:00
|
|
|
template <typename MeshType>
|
|
|
|
struct SaveVertexOcf<MeshType, vertex::vector_ocf<typename MeshType::VertexType> >{
|
|
|
|
typedef typename MeshType::VertexType VertexType;
|
2009-10-30 15:07:51 +01:00
|
|
|
SaveVertexOcf(FILE * f,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()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_QUALITY_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"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()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_COLOR_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"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()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_NORMAL_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_VERTEX_NORMAL_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-10-29 18:23:47 +01:00
|
|
|
if( VertexType::HasMarkOcf() && vert.IsMarkEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_MARK_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_VERTEX_MARK_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( VertexType::HasTexCoordOcf() && vert.IsTexCoordEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_TEXCOORD_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_VERTEX_TEXCOORD_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( VertexType::HasVFAdjacencyOcf() && vert.IsVFAdjacencyEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_VFADJACENCY_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_VERTEX_VFADJACENCY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( VertexType::HasCurvatureOcf() && vert.IsCurvatureEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_CURVATURE_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_VERTEX_CURVATURE_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( VertexType::HasCurvatureDirOcf() && vert.IsCurvatureDirEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_CURVATUREDIR_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_VERTEX_CURVATUREDIR_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( VertexType::HasRadiusOcf() && vert.IsRadiusEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_VERTEX_RADIUS_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_VERTEX_RADIUS_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* save Ocf Face Components */
|
2009-10-09 12:17:24 +02:00
|
|
|
template <typename MeshType,typename CONT>
|
2009-10-08 17:44:59 +02:00
|
|
|
struct SaveFaceOcf{
|
2009-11-18 00:34:46 +01:00
|
|
|
SaveFaceOcf(FILE * f,const CONT & /*face*/, bool only_header){
|
2009-10-30 15:07:51 +01:00
|
|
|
// it is a std::vector
|
|
|
|
if(only_header){
|
|
|
|
WriteString(f,"NOT_HAS_FACE_QUALITY_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_COLOR_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_NORMAL_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_MARK_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_WEDGETEXCOORD_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_FFADJACENCY_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_VFADJACENCY_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_WEDGECOLOR_OCF");
|
|
|
|
WriteString(f,"NOT_HAS_FACE_WEDGENORMAL_OCF");
|
|
|
|
}
|
2009-10-08 17:44:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* partial specialization for vector_ocf */
|
2009-10-09 12:17:24 +02:00
|
|
|
template <typename MeshType>
|
|
|
|
struct SaveFaceOcf< MeshType, face::vector_ocf<typename MeshType::FaceType> >{
|
|
|
|
typedef typename MeshType::FaceType FaceType;
|
2009-10-30 15:07:51 +01:00
|
|
|
SaveFaceOcf(FILE * f,const face::vector_ocf<FaceType> & face, bool only_header){
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasFaceQualityOcf() && face.IsQualityEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_QUALITY_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.QV[0],sizeof(typename FaceType::QualityType),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_QUALITY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasFaceColorOcf() && face.IsColorEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_COLOR_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.CV[0],sizeof(typename FaceType::ColorType),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_COLOR_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasFaceNormalOcf() && face.IsNormalEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_NORMAL_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.NV[0],sizeof(typename FaceType::NormalType),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_NORMAL_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasFaceMarkOcf() && face.IsMarkEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_MARK_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.MV[0],sizeof(typename FaceType::MarkType),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_MARK_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasWedgeTexCoordOcf() && face.IsWedgeTexEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_WEDGETEXCOORD_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_WEDGETEXCOORD_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasFFAdjacencyOcf() && face.IsFFAdjacencyEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_FFADJACENCY_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_FFADJACENCY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasVFAdjacencyOcf() && face.IsVFAdjacencyEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_VFADJACENCY_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_VFADJACENCY_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
|
|
|
|
if( FaceType::HasWedgeColorOcf() && face.IsWedgeColorEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_WEDGECOLOR_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_WEDGECOLOR_OCF");
|
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
if( FaceType::HasWedgeNormalOcf() && face.IsWedgeNormalEnabled()){
|
2009-10-09 12:17:24 +02:00
|
|
|
WriteString(f,"HAS_FACE_WEDGENORMAL_OCF");
|
2009-10-30 15:07:51 +01:00
|
|
|
if(!only_header) fwrite(&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size(),f);
|
2009-10-09 12:17:24 +02:00
|
|
|
}else WriteString(f,"NOT_HAS_FACE_WEDGENORMAL_OCF");
|
2009-10-08 17:44:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-30 15:50:50 +01:00
|
|
|
|
2009-10-09 12:17:24 +02:00
|
|
|
static FILE *& F(){static FILE * f; return f;}
|
|
|
|
|
|
|
|
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;
|
|
|
|
typedef SimpleTempDataBase<typename SaveMeshType::VertContainer> STDBv;
|
|
|
|
typedef SimpleTempDataBase<typename SaveMeshType::FaceContainer> STDBf;
|
|
|
|
// typedef typename SaveMeshType::Attribute <SaveMeshType::FaceContainer> STDBm;
|
|
|
|
|
|
|
|
/* save Ocf Components */
|
|
|
|
|
|
|
|
|
2009-10-30 15:07:51 +01:00
|
|
|
public:
|
2010-02-19 00:33:56 +01:00
|
|
|
static int Save(const SaveMeshType &m,const char * filename){
|
2009-07-29 15:44:00 +02:00
|
|
|
unsigned int i;
|
2009-10-08 17:44:59 +02:00
|
|
|
unsigned int vertSize,faceSize;
|
|
|
|
F() = fopen(filename,"wb");
|
2010-02-19 00:33:56 +01:00
|
|
|
if(F()==NULL) return 1; // 1 is the error code for cant'open, see the ErrorMsg function
|
|
|
|
std::vector<std::string> nameF,nameV;
|
2009-07-29 15:44:00 +02:00
|
|
|
SaveMeshType::FaceType::Name(nameF);
|
|
|
|
SaveMeshType::VertexType::Name(nameV);
|
|
|
|
vertSize = m.vert.size();
|
|
|
|
faceSize = m.face.size();
|
|
|
|
|
|
|
|
/* write header */
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"FACE_TYPE");
|
|
|
|
WriteInt(F(),nameF.size());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
for(i=0; i < nameF.size(); ++i) WriteString(F(),nameF[i].c_str());
|
2009-10-30 15:07:51 +01:00
|
|
|
SaveFaceOcf<SaveMeshType,FaceContainer>(F(),m.face,true);
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"SIZE_VECTOR_FACES");
|
|
|
|
WriteInt(F(), faceSize );
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"VERTEX_TYPE");
|
|
|
|
WriteInt(F(),nameV.size());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
for(i=0; i < nameV.size(); ++i) WriteString(F(),nameV[i].c_str());
|
2009-10-30 15:07:51 +01:00
|
|
|
SaveVertexOcf<SaveMeshType,VertContainer>(F(),m.vert,true);
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"SIZE_VECTOR_VERTS");
|
|
|
|
WriteInt(F(),vertSize);
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2010-02-19 18:34:38 +01:00
|
|
|
WriteString(F(),"BOUNDING_BOX");
|
|
|
|
float float_value;
|
|
|
|
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.min[i]; WriteFloat(F(),float_value);}
|
|
|
|
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.max[i]; WriteFloat(F(),float_value);}
|
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"end_header");
|
2009-10-30 15:07:51 +01:00
|
|
|
/* end header */
|
2009-07-29 15:44:00 +02:00
|
|
|
|
|
|
|
if(vertSize!=0){
|
2011-03-14 12:18:16 +01:00
|
|
|
void * offsetV = (void*) &m.vert[0];
|
2009-07-29 15:44:00 +02:00
|
|
|
/* write the address of the first vertex */
|
2011-03-14 12:18:16 +01:00
|
|
|
fwrite(&offsetV,sizeof(void *),1,F());
|
2009-07-29 15:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(faceSize!=0){
|
2011-03-14 12:18:16 +01:00
|
|
|
void * offsetF= (void*)&m.face[0];
|
2009-07-29 15:44:00 +02:00
|
|
|
/* write the address of the first face */
|
2011-03-14 12:18:16 +01:00
|
|
|
fwrite(&offsetF,sizeof( void *),1,F());
|
2009-07-29 15:44:00 +02:00
|
|
|
}
|
|
|
|
/* save the object mesh */
|
2009-10-08 17:44:59 +02:00
|
|
|
fwrite(&m.shot,sizeof(Shot<typename SaveMeshType::ScalarType>),1,F());
|
|
|
|
fwrite(&m.vn,sizeof(int),1,F());
|
|
|
|
fwrite(&m.fn,sizeof(int),1,F());
|
|
|
|
fwrite(&m.imark,sizeof(int),1,F());
|
|
|
|
fwrite(&m.bbox,sizeof(Box3<typename SaveMeshType::ScalarType>),1,F());
|
|
|
|
fwrite(&m.C(),sizeof(Color4b),1,F());
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-07 14:45:49 +02:00
|
|
|
unsigned int written;
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-07-29 15:44:00 +02:00
|
|
|
if(vertSize!=0){
|
|
|
|
/* save the vertices */
|
2009-10-08 17:44:59 +02:00
|
|
|
written = fwrite((void*)&m.vert[0],sizeof(typename SaveMeshType::VertexType),m.vert.size(),F());
|
2009-07-29 15:44:00 +02:00
|
|
|
assert(written==m.vert.size());
|
2009-10-30 15:07:51 +01:00
|
|
|
SaveVertexOcf<SaveMeshType,VertContainer>(F(),m.vert,false);
|
2009-07-29 15:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(faceSize!=0){
|
|
|
|
/* save the faces */
|
2009-10-08 17:44:59 +02:00
|
|
|
written = fwrite((void*)&m.face[0],sizeof(typename SaveMeshType::FaceType),faceSize,F());
|
2009-07-29 15:44:00 +02:00
|
|
|
assert(written==m.face.size());
|
2009-10-08 17:44:59 +02:00
|
|
|
|
2009-10-30 15:07:51 +01:00
|
|
|
SaveFaceOcf<SaveMeshType,FaceContainer>(F(),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
|
|
|
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-08 17:44:59 +02: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
|
|
|
|
|
|
|
/* save the per vertex attributes */
|
2009-10-07 14:45:49 +02:00
|
|
|
{
|
|
|
|
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-07-29 15:44:00 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"N_PER_VERTEX_ATTRIBUTES"); WriteInt (F(),n_named_attr);
|
2009-10-07 14:45:49 +02:00
|
|
|
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai)
|
|
|
|
if(!(*ai)._name.empty())
|
|
|
|
{
|
|
|
|
STDBv * stdb = (STDBv *) (*ai)._handle;
|
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"PER_VERTEX_ATTR_NAME");
|
|
|
|
WriteString(F(),(*ai)._name.c_str() );
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"PER_VERTEX_ATTR_SIZE");
|
|
|
|
WriteInt(F(),stdb->SizeOf());
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
fwrite(stdb->DataBegin(),m.vert.size(),stdb->SizeOf(),F());
|
2009-10-07 14:45:49 +02: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-09 15:48:52 +02:00
|
|
|
WriteString(F(),"N_PER_FACE_ATTRIBUTES");
|
|
|
|
WriteInt (F(),n_named_attr);
|
2009-10-07 14:45:49 +02:00
|
|
|
|
|
|
|
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai)
|
|
|
|
if(!(*ai)._name.empty())
|
|
|
|
{
|
|
|
|
STDBf * stdb = (STDBf *) (*ai)._handle;
|
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"PER_FACE_ATTR_NAME");
|
|
|
|
WriteString(F(),(*ai)._name.c_str());
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"PER_FACE_ATTR_SIZE");
|
|
|
|
WriteInt(F(),stdb->SizeOf());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
fwrite(stdb->DataBegin(),m.face.size(),stdb->SizeOf(),F());
|
2009-10-07 14:45:49 +02: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();
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"N_PER_MESH_ATTRIBUTES"); WriteInt(F(),n_named_attr);
|
2009-10-07 14:45:49 +02:00
|
|
|
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai)
|
|
|
|
if(!(*ai)._name.empty())
|
|
|
|
{
|
|
|
|
AttributeBase * handle = (AttributeBase *) (*ai)._handle ;
|
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"PER_MESH_ATTR_NAME");
|
|
|
|
WriteString(F(),(*ai)._name.c_str());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-09 15:48:52 +02:00
|
|
|
WriteString(F(),"PER_MESH_ATTR_SIZE");
|
|
|
|
WriteInt(F(),handle->SizeOf());
|
2009-10-07 14:45:49 +02:00
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
fwrite(handle->DataBegin(),1,handle->SizeOf(),F());
|
2009-10-07 14:45:49 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-29 15:44:00 +02:00
|
|
|
|
2009-10-08 17:44:59 +02:00
|
|
|
// fflush(F());
|
|
|
|
fclose(F());
|
2010-02-19 00:33:56 +01:00
|
|
|
return 0;
|
2009-07-29 15:44:00 +02: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();
|
|
|
|
}
|
2009-07-29 15:44:00 +02:00
|
|
|
}; // end class
|
|
|
|
|
|
|
|
} // end Namespace tri
|
|
|
|
} // end Namespace io
|
|
|
|
} // end Namespace vcg
|
|
|
|
|
|
|
|
#endif
|