Commit 802b0310 authored by Sylvain Thery's avatar Sylvain Thery

add I/O binary volume format

parent 3893b6c9
......@@ -45,7 +45,6 @@ namespace Export
* @param the_map map to be exported
* @param position the position container
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
template <typename PFP>
......@@ -56,7 +55,6 @@ bool exportNAS(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
* export the map into a vtu file (vtk unstructured grid)
* @param the_map map to be exported
* @param position the position container
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
......@@ -69,7 +67,6 @@ bool exportVTU(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
* @param the_map map to be exported
* @param position the position container
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
template <typename PFP>
......@@ -81,7 +78,6 @@ bool exportMSH(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
* @param the_map map to be exported
* @param position the position container
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
template <typename PFP>
......@@ -93,13 +89,21 @@ bool exportTet(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
* @param the_map map to be exported
* @param position the position container
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
template <typename PFP>
bool exportNodeEle(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename) ;
/**
* export in binary volume file (nb_vert,nb_tetra,nb_hexa, vertices, tetra, hexa)
* @param the_map map to be exported
* @param position the position container
* @param filename filename of ply file
*/
template <typename PFP>
bool exportVolBinGz(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename);
} // namespace Export
}
......
......@@ -200,9 +200,6 @@ bool exportVTU(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
VertexAutoAttribute<unsigned int> indices(map,"indices_vert");
unsigned int count=0;
for (unsigned int i = position.begin(); i != position.end(); position.next(i))
{
......@@ -646,6 +643,158 @@ bool exportNodeEle(typename PFP::MAP& map, const VertexAttribute<typename PFP::V
}
template <typename PFP>
bool exportVolBinGz(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
// open file
// std::ofstream fout ;
// fout.open(filename, std::ios::out) ;
ogzstream fout(filename, std::ios::out|std::ios::binary);
if (!fout.good())
{
CGoGNerr << "Unable to open file " << filename << CGoGNendl ;
return false ;
}
VertexAutoAttribute<unsigned int> indices(map,"indices_vert");
std::vector<typename PFP::VEC3> bufposi;
bufposi.reserve(position.nbElements());
unsigned int count=0;
for (unsigned int i = position.begin(); i != position.end(); position.next(i))
{
const VEC3& P = position[i];
bufposi.push_back(P);
// fout << count << " " << P[0]<< " " << P[1]<< " " << P[2] << std::endl;
indices[i] = count++;
}
if (count != bufposi.size())
CGoGNerr << "Warning problem wrong nbElements in position attributes ?" << CGoGNendl;
std::vector<unsigned int> hexa;
std::vector<unsigned int> tetra;
hexa.reserve(2048);
tetra.reserve(2048);
TraversorW<MAP> trav(map) ;
for(Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
unsigned int degree = 0 ;
Traversor3WV<typename PFP::MAP> twv(map, d) ;
for(Dart it = twv.begin(); it != twv.end(); it = twv.next())
{
degree++;
}
if (degree == 8)
{
//CAS HEXAEDRIQUE (ordre 2 quad superposes, le premier en CW)
Dart e = d;
hexa.push_back(indices[e]);
e = map.phi1(e);
hexa.push_back(indices[e]);
e = map.phi1(e);
hexa.push_back(indices[e]);
e = map.phi1(e);
hexa.push_back(indices[e]);
e = map.template phi<2112>(e);
hexa.push_back(indices[e]);
e = map.phi1(e);
hexa.push_back(indices[e]);
e = map.phi1(e);
hexa.push_back(indices[e]);
e = map.phi1(e);
hexa.push_back(indices[e]);
// hexa.push_back(indices[e]);
// e = map.phi1(e);
// hexa.push_back(indices[e]);
// e = map.phi1(e);
// hexa.push_back(indices[e]);
// e = map.phi1(e);
// hexa.push_back(indices[e]);
// Dart f = map.template phi<21121>(d);
// hexa.push_back(indices[f]);
// f = map.phi_1(f);
// hexa.push_back(indices[f]);
// f = map.phi_1(f);
// hexa.push_back(indices[f]);
// f = map.phi_1(f);
// hexa.push_back(indices[f]);
}
if (degree == 4)
{
//CAS TETRAEDRIQUE
Dart e = d;
tetra.push_back(indices[e]);
e = map.phi1(e);
tetra.push_back(indices[e]);
e = map.phi1(e);
tetra.push_back(indices[e]);
e = map.template phi<211>(e);
tetra.push_back(indices[e]);
}
}
unsigned int nbhexa = hexa.size()/8;
unsigned int nbtetra = tetra.size()/4;
unsigned int buffer[3];
buffer[0] = position.nbElements();
buffer[1] = nbtetra;
buffer[2] = nbhexa;
fout.write((char*)(buffer),3*sizeof(unsigned int));
// write positions
fout.write((char*)(&(bufposi[0])),sizeof(VEC3)*bufposi.size());
// write tetra indices if necessary
if (nbtetra != 0)
{
long int nbo = (long int)&(tetra.back()) -(long int)&(tetra.front());
nbo /= sizeof(unsigned int);
if (nbo != (long int)(tetra.size()-1))
CGoGNerr << "Memory vector problem"<< CGoGNendl;
else
fout.write((char*)(&(tetra[0])),sizeof(unsigned int)*tetra.size());
}
// write hexa indices if necessary
if (nbhexa!=0)
{
long int nbo = (long int)&(hexa.back()) -(long int)&(hexa.front());
nbo /= sizeof(unsigned int);
if (nbo != (long int)(hexa.size()-1))
CGoGNerr << "Memory vector problem"<< CGoGNendl;
else
fout.write((char*)(&(hexa[0])),sizeof(unsigned int)*hexa.size());
}
fout.close();
return true;
}
} // namespace Export
}
......
......@@ -127,6 +127,10 @@ bool importVTU(typename PFP::MAP& the_map, const std::string& filename, std::vec
template <typename PFP>
bool importNAS(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
template <typename PFP>
bool importVBGZ(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
} // Import
......@@ -147,6 +151,8 @@ bool importNAS(typename PFP::MAP& the_map, const std::string& filename, std::vec
#include "Algo/Import/importMSH.hpp"
#include "Algo/Import/importVTU.hpp"
#include "Algo/Import/importNAS.hpp"
#include "Algo/Import/importVBGZ.hpp"
#include "Algo/Import/importChoupi.hpp"
......
......@@ -151,7 +151,7 @@ namespace Volume
namespace Import
{
enum ImportType { UNKNOWNVOLUME , TET, OFF, TS, MOKA, NODE, MSH, VTU, NAS};
enum ImportType { UNKNOWNVOLUME , TET, OFF, TS, MOKA, NODE, MSH, VTU, NAS, VBGZ};
template <typename PFP>
class MeshTablesVolume
......
......@@ -539,6 +539,9 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector
if ((filename.rfind(".nas") != std::string::npos) || (filename.rfind(".NAS") != std::string::npos))
kind = NAS;
if ((filename.rfind(".volbgz") != std::string::npos) || (filename.rfind(".VOLBGZ") != std::string::npos))
kind = VBGZ;
switch (kind)
{
......@@ -556,6 +559,11 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector
return importNAS<PFP>(map, filename, attrNames, 1.0f);
break;
case VBGZ:
return importVBGZ<PFP>(map, filename, attrNames, 1.0f);
break;
case OFF:
{
size_t pos = filename.rfind(".");
......
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