Commit 45f74840 authored by Sylvain Thery's avatar Sylvain Thery

update Volumic I/O

parent 89e3f3c0
......@@ -52,6 +52,18 @@ template <typename PFP>
bool exportNAS(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename) ;
/**
* 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
*/
template <typename PFP>
bool exportVTU(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename) ;
/**
* export the map into a .msh (gmesh file)
* @param the_map map to be exported
......
This diff is collapsed.
......@@ -110,7 +110,7 @@ template <typename PFP>
bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenameNode, const std::string& filenameELE, std::vector<std::string>& attrNames);
template <typename PFP>
bool importTet(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f, bool invertTetra=false);
bool importTet(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
template <typename PFP>
bool importMoka(typename PFP::MAP& the_gmap, const std::string& filename, std::vector<std::string>& attrNames);
......@@ -118,6 +118,13 @@ bool importMoka(typename PFP::MAP& the_gmap, const std::string& filename, std::v
template <typename PFP>
bool importTs(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
template <typename PFP>
bool importMSH(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
template <typename PFP>
bool importVTU(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
} // Import
} // Volume
......@@ -134,6 +141,8 @@ bool importTs(typename PFP::MAP& the_map, const std::string& filename, std::vect
#include "Algo/Import/importMoka.hpp"
#include "Algo/Import/importTs.hpp"
#include "Algo/Import/importNodeEle.hpp"
#include "Algo/Import/importMSH.hpp"
#include "Algo/Import/importVTU.hpp"
#include "Algo/Import/importChoupi.hpp"
......
......@@ -151,7 +151,7 @@ namespace Volume
namespace Import
{
enum ImportType { UNKNOWNVOLUME , TET, OFF, TS, MOKA, NODE};
enum ImportType { UNKNOWNVOLUME , TET, OFF, TS, MOKA, NODE, MSH, VTU, NAS};
template <typename PFP>
class MeshTablesVolume
......
This diff is collapsed.
......@@ -530,11 +530,29 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector
if ((filename.rfind(".ts") != std::string::npos) || (filename.rfind(".TS") != std::string::npos))
kind = TS;
if ((filename.rfind(".msh") != std::string::npos) || (filename.rfind(".MSH") != std::string::npos))
kind = MSH;
if ((filename.rfind(".vtu") != std::string::npos) || (filename.rfind(".VTU") != std::string::npos))
kind = VTU;
if ((filename.rfind(".nas") != std::string::npos) || (filename.rfind(".NAS") != std::string::npos))
kind = NAS;
switch (kind)
{
case TET:
return importTet<PFP>(map, filename, attrNames, 1.0f);
break;
case MSH:
return importMSH<PFP>(map, filename, attrNames, 1.0f);
break;
case VTU:
return importVTU<PFP>(map, filename, attrNames, 1.0f);
break;
case OFF:
{
size_t pos = filename.rfind(".");
......
......@@ -23,6 +23,8 @@
*******************************************************************************/
#include "Algo/Modelisation/polyhedron.h"
#include "Geometry/orientation.h"
#include <vector>
namespace CGoGN
......@@ -105,8 +107,10 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
//Reading vertices
//Remaining lines: [point #] [x] [y] [z] [optional attributes] [optional boundary marker]
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
// std::vector<unsigned int> verticesID;
// verticesID.reserve(m_nbVertices);
std::map<unsigned int,unsigned int> verticesMapID;
for(unsigned int i = 0 ; i < m_nbVertices ; ++i)
{
......@@ -130,14 +134,13 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
unsigned int id = container.insertLine();
position[id] = pos;
verticesID.push_back(id);
// verticesID.push_back(id);
verticesMapID.insert(std::pair<unsigned int, unsigned int>(idv,id));
}
std::vector<std::vector<Dart> > vecDartPtrEmb;
vecDartPtrEmb.reserve(m_nbVertices);
DartMarkerNoUnmark m(map) ;
bool invertVol=false;
//Read and embed tetrahedra TODO
for(unsigned i = 0; i < m_nbVolumes ; ++i)
{
......@@ -152,30 +155,52 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
Dart d = Surface::Modelisation::createTetrahedron<PFP>(map,false);
Geom::Vec4ui pt;
// oss >> pt[0];
// --(pt[0]);
// oss >> pt[1];
// --(pt[1]);
// oss >> pt[2];
// --(pt[2]);
// oss >> pt[3];
// --(pt[3]);
oss >> pt[1];
--(pt[1]);
oss >> pt[2];
--(pt[2]);
oss >> pt[3];
--(pt[3]);
oss >> pt[0];
--(pt[0]);
//regions ?
//oss >> nbe;
// test orientation of first tetra
if (i==0)
{
oss >> pt[0];
oss >> pt[1];
oss >> pt[2];
oss >> pt[3];
typename PFP::VEC3 P = position[verticesMapID[pt[0]]];
typename PFP::VEC3 A = position[verticesMapID[pt[1]]];
typename PFP::VEC3 B = position[verticesMapID[pt[2]]];
typename PFP::VEC3 C = position[verticesMapID[pt[3]]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
{
invertVol=true;
unsigned int ui=pt[0];
pt[0] = pt[3];
pt[3] = pt[2];
pt[2] = pt[1];
pt[1] = ui;
}
}
else
{
if (invertVol)
{
oss >> pt[1];
oss >> pt[2];
oss >> pt[3];
oss >> pt[0];
}
else
{
oss >> pt[0];
oss >> pt[1];
oss >> pt[2];
oss >> pt[3];
}
}
// Embed three vertices
for(unsigned int j = 0 ; j < 3 ; ++j)
{
FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesID[pt[2-j]]);
FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesMapID[pt[2-j]]);
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb);
//store darts per vertices to optimize reconstruction
......@@ -183,7 +208,7 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
do
{
m.mark(dd) ;
vecDartsPerVertex[pt[2-j]].push_back(dd);
vecDartsPerVertex[verticesMapID[pt[2-j]]].push_back(dd);
dd = map.phi1(map.phi2(dd));
} while(dd != d);
......@@ -194,7 +219,7 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
//Embed the last vertex
d = map.phi_1(map.phi2(d));
FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesID[pt[3]]);
FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesMapID[pt[3]]);
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb);
//store darts per vertices to optimize reconstruction
......@@ -202,7 +227,7 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
do
{
m.mark(dd) ;
vecDartsPerVertex[pt[3]].push_back(dd);
vecDartsPerVertex[verticesMapID[pt[3]]].push_back(dd);
dd = map.phi1(map.phi2(dd));
} while(dd != d);
......
......@@ -37,14 +37,24 @@ namespace Import
{
struct MaterialOBJ
class MaterialOBJ
{
public:
MaterialOBJ():textureDiffuse(NULL){}
~MaterialOBJ()
{
if (textureDiffuse!=NULL)
delete textureDiffuse;
}
std::string name;
Geom::Vec3f ambiantColor;
Geom::Vec3f diffuseColor;
Geom::Vec3f specularColor;
float shininess;
// TODO add textures info
Geom::Vec3f transparentFilter;
float transparency;
Utils::Texture<2,Geom::Vec3uc>* textureDiffuse;
};
......@@ -60,12 +70,16 @@ protected:
/// vector of group name
std::vector<std::string> m_groupNames;
std::vector<std::string> m_groupMaterialNames;
std::vector<int> m_groupMaterialID;
/// vector of material names
std::vector<std::string> m_materialNames;
std::map<std::string,int> m_materialNames;
/// vector of material struct
std::vector<MaterialOBJ> m_materials;
// std::vector<MaterialOBJ> m_materials;
/// read face line with different indices v v/t v//n v/t/n
short readObjLine(std::stringstream& oss, std::vector<unsigned int>& indices);
......@@ -136,6 +150,8 @@ public:
*/
bool import(const std::string& filename, std::vector<std::string>& attrNames);
// Faire un handler ?
/**
* @brief getNormal
......@@ -176,7 +192,7 @@ public:
* @brief read materials from files
* @param filename name of file
*/
void readMaterials(const std::string& filename);
void readMaterials(const std::string& filename, std::vector<MaterialOBJ>& materials);
/**
* @brief create simple VBO for separated triangles
......
......@@ -36,6 +36,7 @@ namespace Surface
namespace Import
{
template <typename PFP>
OBJModel<PFP>::OBJModel(typename PFP::MAP& map):
m_map(map),
......@@ -69,12 +70,6 @@ inline Geom::Vec2f OBJModel<PFP>::getTexCoord(Dart d)
}
template <typename PFP>
std::vector<std::string>& OBJModel<PFP>::getMaterialNames()
{
return m_materialNames;
}
template <typename PFP>
void OBJModel<PFP>::setPositionAttribute(VertexAttribute<Geom::Vec3f> position)
{
......@@ -97,9 +92,9 @@ void OBJModel<PFP>::setTexCoordAttribute(VertexAttribute<Geom::Vec2f>texcoord)
template <typename PFP>
void OBJModel<PFP>::readMaterials(const std::string& filename)
void OBJModel<PFP>::readMaterials(const std::string& filename, std::vector<MaterialOBJ>& materials)
{
m_materials.resize(m_materialNames.size());
materials.reserve(m_materialNames.size());
// open file
std::ifstream fp(filename.c_str());
......@@ -110,6 +105,7 @@ void OBJModel<PFP>::readMaterials(const std::string& filename)
}
std::vector<MaterialOBJ>::iterator mit;
std::string ligne;
std::string tag;
fp >> tag;
......@@ -118,7 +114,8 @@ void OBJModel<PFP>::readMaterials(const std::string& filename)
std::getline (fp, ligne);
if (tag == "newmtl")
{
std::vector<std::string>::iterator it = std::find(m_materialNames.begin(), m_materialNames.end(), ligne);
std::map<std::string,int>::iterator it = m_materialNames.find(ligne);
if (it == m_materialNames.end())
{
CGoGNerr << "Skipping material "<< ligne << CGoGNendl;
......@@ -130,8 +127,20 @@ void OBJModel<PFP>::readMaterials(const std::string& filename)
}
else
{
CGoGNerr << "Reading material "<< ligne << CGoGNendl;
mit = m_materials.begin() + (it - m_materialNames.begin());
CGoGNout << "Reading material "<< ligne << CGoGNendl;
if (materials.empty())
{
materials.resize(1);
mit = materials.begin();
}
else
{
materials.resize(materials.size()+1);
++mit;
}
it->second = (mit-materials.begin());
mit->name = ligne;
}
}
else
......@@ -160,6 +169,17 @@ void OBJModel<PFP>::readMaterials(const std::string& filename)
{
oss >> mit->shininess;
}
if (tag == "Tf")
{
oss >> mit->transparentFilter[0];
oss >> mit->transparentFilter[1];
oss >> mit->transparentFilter[2];
}
if ((tag == "Tr") || (tag == "d"))
{
oss >> mit->transparency;
}
if (tag == "map_Ka") // ambiant texture
{
......@@ -167,7 +187,12 @@ void OBJModel<PFP>::readMaterials(const std::string& filename)
}
if (tag == "map_Kd") // diffuse texture
{
CGoGNerr << tag << " not yet supported in OBJ material reading" << CGoGNendl;
mit->textureDiffuse = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
std::string tname;
oss >> tname;
mit->textureDiffuse->load(tname);
CGoGNout << "Loading texture "<< tname << CGoGNendl;
}
if (tag == "map_d") // opacity texture
{
......@@ -204,6 +229,8 @@ bool OBJModel<PFP>::generateBrowsers(std::vector<MapBrowser*>& browsers)
{
MapBrowser* MBptr = new MapBrowserLinked(m_map,links);
browsers.push_back(MBptr);
// std::string& matName = m_materialNames[i];
m_groupMaterialID[i]= m_materialNames[m_groupMaterialNames[i]];
}
for (Dart d=m_map.begin(); d!=m_map.end(); m_map.next(d))
......@@ -706,7 +733,8 @@ bool OBJModel<PFP>::import( const std::string& filename, std::vector<std::string
CGoGNerr << "problem reading OBJ, waiting for usemtl get "<< buf << CGoGNendl;
}
fp >> buf;
m_materialNames.push_back(buf);
m_materialNames.insert(std::pair<std::string,int>(buf,-1));
m_groupMaterialNames.push_back(buf);
currentGroup++;
}
......
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include "Algo/Modelisation/polyhedron.h"
#include "Geometry/orientation.h"
#include <vector>
namespace CGoGN
......@@ -38,7 +39,7 @@ namespace Import
{
template <typename PFP>
bool importTet(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor, bool invertTetra)
bool importTet(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor)
{
typedef typename PFP::VEC3 VEC3;
......@@ -102,6 +103,8 @@ bool importTet(typename PFP::MAP& map, const std::string& filename, std::vector<
DartMarkerNoUnmark m(map) ;
unsigned int invertTetra = 0;
//Read and embed all tetrahedrons
for(unsigned int i = 0; i < m_nbVolumes ; ++i)
{
......@@ -119,6 +122,31 @@ bool importTet(typename PFP::MAP& map, const std::string& filename, std::vector<
Dart d = Surface::Modelisation::createTetrahedron<PFP>(map,false);
Geom::Vec4ui pt;
if (i==0)
{
oss >> pt[0];
oss >> pt[1];
oss >> pt[2];
oss >> pt[3];
typename PFP::VEC3 P = position[verticesID[pt[0]]];
typename PFP::VEC3 A = position[verticesID[pt[1]]];
typename PFP::VEC3 B = position[verticesID[pt[2]]];
typename PFP::VEC3 C = position[verticesID[pt[3]]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
{
invertTetra=1;
unsigned int ui=pt[1];
pt[1] = pt[2];
pt[2] = ui;
}
}
oss >> pt[0];
oss >> pt[1+invertTetra];
oss >> pt[2-invertTetra];
......
......@@ -23,7 +23,7 @@
*******************************************************************************/
#include "Algo/Modelisation/polyhedron.h"
#include "Geometry/orientation.h"
#include <vector>
namespace CGoGN
......@@ -128,6 +128,18 @@ bool importTs(typename PFP::MAP& map, const std::string& filename, std::vector<s
oss >> pt[1];
oss >> pt[2];
oss >> pt[3];
typename PFP::VEC3 P = position[verticesID[pt[0]]];
typename PFP::VEC3 A = position[verticesID[pt[1]]];
typename PFP::VEC3 B = position[verticesID[pt[2]]];
typename PFP::VEC3 C = position[verticesID[pt[3]]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
{
unsigned int ui=pt[1];
pt[1] = pt[2];
pt[2] = ui;
}
//if regions are defined use this number
oss >> nbe; //ignored here
......
This diff is collapsed.
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