From b59781584831e859b314bd4e84d9e827bfac2dfb Mon Sep 17 00:00:00 2001 From: "T.Alderighi" Date: Tue, 8 May 2018 16:03:30 +0200 Subject: [PATCH] tet export --- wrap/io_tetramesh/export_tet.h | 117 +++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 wrap/io_tetramesh/export_tet.h diff --git a/wrap/io_tetramesh/export_tet.h b/wrap/io_tetramesh/export_tet.h new file mode 100644 index 00000000..145cddc8 --- /dev/null +++ b/wrap/io_tetramesh/export_tet.h @@ -0,0 +1,117 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2016 \/)\/ * +* 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. * +* * +****************************************************************************/ + +/** +@name Load and Save in Tetgen File format +*/ +//@{ + +#ifndef __VCGLIB_TETRAEXPORT_TET +#define __VCGLIB_TETRAEXPORT_TET + +#include + +#include + +namespace vcg { +namespace tetra { +namespace io { + + +template +class ExporterTET +{ +public: + typedef ::vcg::ply::PropDescriptor PropDescriptor ; + typedef typename SaveMeshType::VertexPointer VertexPointer; + typedef typename SaveMeshType::ScalarType ScalarType; + typedef typename SaveMeshType::VertexType VertexType; + typedef typename SaveMeshType::TetraType TetraType; + typedef typename SaveMeshType::TetraPointer TetraPointer; + typedef typename SaveMeshType::VertexIterator VertexIterator; + typedef typename SaveMeshType::TetraIterator TetraIterator; + + static bool Save(SaveMeshType &m, const char * filename) // V1.0 + { + FILE * eleFile; + FILE * nodeFile; + + const int DGT = vcg::tri::io::Precision::digits(); + + std::string eleName(filename); + std::string nodeName(filename); + + eleName.append(".ele"); + nodeName.append(".node"); + + eleFile = fopen(eleName.c_str() , "wb"); + if (eleFile == NULL) + return 1; + + nodeFile = fopen(nodeName.c_str() , "wb"); + if (nodeFile == NULL) + return 1; + + fprintf(eleFile, + "#VCG lib .ele generated file\n" + "#This file contains the tetra definition in accord to Tetgen file format\n"); + + fprintf(nodeFile, + "#VCG lib .node generated file\n" + "#This file contains the vertex definition in accord to Tetgen file format\n"); + + + fprintf(nodeFile, "%d 3 0 0\n", m.VN()); + int vi = 0; + SimpleTempData indices(m.vert); + + ForEachVertex(m, [&] (VertexType & v) { + indices[&v] = vi; + fprintf(nodeFile, "%d %g %g %g\n", vi++, double(v.P().X()), double(v.P().Y()), double(v.P().Z())); + }); + + fprintf(eleFile, "%d 4 0\n", m.TN()); + int ti = 0; + ForEachTetra(m, [&] (SaveMeshType::TetraType & t) { + fprintf(eleFile, "%d %d %d %d %d\n", ti++, indices[t.V(0)], indices[t.V(1)], indices[t.V(2)], indices[t.V(3)]); + }); + + + fclose(eleFile); + fclose(nodeFile); + + return 0; + } + + + + +}; // end class + + + +} // end namespace tetra +} // end namespace io +} // end namespace vcg + +#endif