Commit 2175919d authored by Sylvain Thery's avatar Sylvain Thery

export vtu

parent 923c0081
......@@ -103,6 +103,110 @@ bool exportTrian(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC
template <typename PFP>
bool exportVTU(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename);
template <typename PFP>
bool exportVTUCompressed(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename);
template <typename PFP>
class VTUExporter
{
protected:
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
typename PFP::MAP& m_map;
const VertexAttribute<typename PFP::VEC3>& m_position;
unsigned int nbtotal;
bool noPointData;
bool noCellData;
bool closed;
std::ofstream fout ;
std::vector<unsigned int> triangles;
std::vector<unsigned int> quads;
std::vector<unsigned int> others;
std::vector<unsigned int> others_begin;
std::vector<Dart> bufferTri;
std::vector<Dart> bufferQuad;
std::vector<Dart> bufferOther;
public:
VTUExporter(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position);
~VTUExporter();
/**
* @brief start writing header of vru file
* @param filename
* @return true if ok
*/
bool init(const char* filename);
/**
* @brief add a vertex attribute of type scalar
* @param attrib
* @param vtkType Float32/Int32
* @param name Data name if none then used Attribute's name
*/
template<typename T>
void addVertexAttributeScal(const VertexAttribute<T>& attrib, const std::string& vtkType, const std::string& name="");
/**
* @brief add a vertex attribute of type vector
* @param attrib
* @param vtkType Float32/Int32
* @param nbComp number components in attribute (if none comute for size of attribute)
* @param name Data name if none then used Attribute's name
*/
template<typename T>
void addVertexAttributeVect(const VertexAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
/**
* @brief finish adding vertex attributes data
*/
void endVertexAttributes();
/**
* @brief add a face attribute of type scalar
* @param attrib
* @param vtkType Float32/Int32
* @param name Data name if none then used Attribute's name
*/
template<typename T>
void addFaceAttributeScal(const FaceAttribute<T>& attrib, const std::string& vtkType, const std::string& name="");
/**
* @brief add a face aatribute of type vector
* @param attrib
* @param vtkType Float32/Int32
* @param nbComp number components in attribute (if none comute for size of attribute)
* @param name Data name if none then used Attribute's name
*/
template<typename T>
void addFaceAttributeVect(const FaceAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
/**
* @brief finish adding face attributes data
*/
void endFaceAttributes();
/**
* @brief finalize file writing & close (automatically called at destruction)
* @return true if ok
*/
bool close();
};
/**
......
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library 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 Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _CGOGN_COMPRESS_H_
#define _CGOGN_COMPRESS_H_
#include <fstream>
namespace CGoGN
{
namespace Utils
{
void zlibWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstream& fout);
}
}
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library 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 Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <cassert>
#include "Utils/compress.h"
#include "zlib.h"
namespace CGoGN
{
namespace Utils
{
void zlibWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstream& fout)
{
const int CHUNK=16384;
int level = 6; // compression level
unsigned char* out = new unsigned char[CHUNK];
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
int ret = deflateInit(&strm, level);
assert(ret == Z_OK);
unsigned char* ptrData = input;
int remain = nbBytes;
while (remain >0)
{
strm.avail_in = std::min(remain,CHUNK); // taille buffer
strm.next_in = ptrData; // ptr buffer
do
{
strm.avail_out = CHUNK;
strm.next_out = out;
if (remain>= CHUNK)
ret = deflate(&strm, 0);
else
ret = deflate(&strm, 1);
assert(ret != Z_STREAM_ERROR);
unsigned int have = CHUNK - strm.avail_out;
fout.write((char*)out, have);
} while (strm.avail_out == 0);
remain -= CHUNK;
ptrData += CHUNK;
}
// assert(ret == Z_STREAM_END);
deflateEnd(&strm);
delete[] out;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment