Commit 0c1647ba authored by Sylvain Thery's avatar Sylvain Thery

export vtu binary with attributes for 2/3 maps

parent 9238a53c
......@@ -93,144 +93,6 @@ template <typename PFP>
bool exportTrian(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, char* filename) ;
/**
* export the map into a VTU file (VTK unstructured grid xml format)
* @param map map to be exported
* @param position the position container
* @param filename filename of ply file
* @return true if ok
*/
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>
bool exportVTUBinary(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;
bool binaryMode;
std::ofstream f_tempoBin_out ;
template<typename T>
void addBinaryVertexAttributeScal(const VertexAttribute<T>& attrib, const std::string& vtkType, const std::string& name="");
template<typename T>
void addBinaryVertexAttributeVect(const VertexAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
void endBinaryVertexAttributes();
template<typename T>
void addBinaryFaceAttributeScal(const FaceAttribute<T>& attrib, const std::string& vtkType, const std::string& name="");
template<typename T>
void addBinaryFaceAttributeVect(const FaceAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
void endBinaryFaceAttributes();
bool binaryClose();
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, bool bin=false);
/**
* @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();
};
/**
* export the map into a PLYPTMgeneric file (K. Vanhoey generic format).
......
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 __EXPORT_VTU_H__
#define __EXPORT_VTU_H__
#include "Topology/generic/attributeHandler.h"
#include "Algo/Import/importFileTypes.h"
#include <stdint.h>
namespace CGoGN
{
namespace Algo
{
namespace Surface
{
namespace Export
{
/**
* simple export of the geometry of map into a VTU file (VTK unstructured grid xml format)
* @param map map to be exported
* @param position the position container
* @param filename filename of ply file
* @return true if ok
*/
template <typename PFP>
bool exportVTU(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename);
/**
* simple export of the geometry of map into a binary VTU file (VTK unstructured grid xml format)
* @param map map to be exported
* @param position the position container
* @param filename filename of ply file
* @return true if ok
*/
template <typename PFP>
bool exportVTUBinary(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);
/**
* class that allow the export of VTU file (ascii or binary)
* with vertex and face attributes
*/
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;
std::string m_filename;
bool binaryMode;
unsigned int offsetAppend;
FILE* f_tempoBin_out ;
template<typename T>
void addBinaryVertexAttribute(const VertexAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
template<typename T>
void addBinaryFaceAttribute(const FaceAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
bool binaryClose();
public:
VTUExporter(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position);
~VTUExporter();
/**
* @brief start writing header of vtu file
* @param filename
* @param bin true if binray mode wanted
* @return true if ok
*/
bool init(const char* filename, bool bin=false);
/**
* @brief add a vertex attribute
* @param attrib vertex attribute
* @param vtkType Float32/Int32/..
* @param nbComp number of components in attribute (if none computed from size of attribute divide bye the vtkType)
* @param name data name, if none then used attribute's name
*/
template<typename T>
void addVertexAttribute(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
* @param attrib vertex attribute
* @param vtkType Float32/Int32/..
* @param nbComp number of components in attribute (if none computed from size of attribute divide bye the vtkType)
* @param name data name, if none then used attribute's name
*/
template<typename T>
void addFaceAttribute(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 of not yet done)
* @return true if ok
*/
bool close();
};
} // namespace Export
} // Surface
namespace Volume
{
namespace Export
{
/**
* class that allow the export of VTU file (ascii or binary)
* with vertex and volume attributes
*/
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> tetras;
std::vector<unsigned int> hexas;
std::vector<Dart> bufferTetra;
std::vector<Dart> bufferHexa;
std::string m_filename;
bool binaryMode;
unsigned int offsetAppend;
FILE* f_tempoBin_out ;
template<typename T>
void addBinaryVertexAttribute(const VertexAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
template<typename T>
void addBinaryVolumeAttribute(const VolumeAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
bool binaryClose();
public:
VTUExporter(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position);
~VTUExporter();
/**
* @brief start writing header of vtu file
* @param filename
* @param bin true if binray mode wanted
* @return true if ok
*/
bool init(const char* filename, bool bin=false);
/**
* @brief add a vertex attribute
* @param attrib vertex attribute
* @param vtkType Float32/Int32/..
* @param nbComp number of components in attribute (if none computed from size of attribute divide bye the vtkType)
* @param name data name, if none then used attribute's name
*/
template<typename T>
void addVertexAttribute(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 volume attribute
* @param attrib vertex attribute
* @param vtkType Float32/Int32/..
* @param nbComp number of components in attribute (if none computed from size of attribute divide bye the vtkType)
* @param name data name, if none then used attribute's name
*/
template<typename T>
void addVolumeAttribute(const VolumeAttribute<T>& attrib, const std::string& vtkType, unsigned int nbComp=0, const std::string& name="");
/**
* @brief finish adding volume attributes data
*/
void endVolumeAttributes();
/**
* @brief finalize file writing & close (automatically called at destruction of not yet done)
* @return true if ok
*/
bool close();
};
} // namespace Export
} // Volume
} // namespace Algo
} // namespace CGoGN
#include "Algo/Export/exportVTU.hpp"
#endif
This diff is collapsed.
......@@ -33,7 +33,7 @@ namespace CGoGN
namespace Utils
{
void zlibWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstream& fout);
void zlibVTUWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstream& fout);
}
}
......
......@@ -26,17 +26,23 @@
#include "Utils/compress.h"
#include "zlib.h"
#include <iostream>
#include <vector>
#include <string.h>
namespace CGoGN
{
namespace Utils
{
void zlibWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstream& fout)
void zlibVTUWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstream& fout)
{
const int CHUNK=16384;
std::cout << "Compressor Block " << std::endl;
const int CHUNK=1024*256;
int level = 6; // compression level
unsigned char* out = new unsigned char[CHUNK];
z_stream strm;
strm.zalloc = Z_NULL;
......@@ -45,6 +51,13 @@ void zlibWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstr
int ret = deflateInit(&strm, level);
assert(ret == Z_OK);
unsigned char* bufferOut = new unsigned char[nbBytes];
unsigned char* ptrBufferOut = bufferOut;
std::vector<unsigned int> header;
header.reserve(1024);
header.resize(3);
unsigned char* ptrData = input;
int remain = nbBytes;
......@@ -52,28 +65,43 @@ void zlibWriteCompressed( unsigned char* input, unsigned int nbBytes, std::ofstr
{
strm.avail_in = std::min(remain,CHUNK); // taille buffer
strm.next_in = ptrData; // ptr buffer
do
{
strm.avail_out = CHUNK;
strm.next_out = out;
strm.next_out = ptrBufferOut;
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);
ptrBufferOut+=have;
header.push_back(have);
} while (strm.avail_out == 0);
remain -= CHUNK;
ptrData += CHUNK;
}
// assert(ret == Z_STREAM_END);
deflateEnd(&strm);
delete[] out;
header[0] = header.size()-3;
header[1] = CHUNK;
if (remain != 0)
header[2] = remain +CHUNK;
else header[2] = 0;
std::cout << "HEADER "<< std::endl;
for (unsigned int i=0; i<header.size(); ++i)
std::cout << header[i]<< std::endl;
fout.write((char*)&header[0], header.size()*sizeof(unsigned int));
fout.write((char*)bufferOut, ptrBufferOut - bufferOut);
std::cout << "DATA "<< ptrBufferOut - bufferOut << "bytes writen"<< std::endl;
delete[] bufferOut;
}
}
}
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