Commit 412ca15a authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'master' of cgogn:~cgogn/CGoGN

parents 7522659d 2cf2e5ff
......@@ -298,7 +298,7 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<
do
{
std::getline (fp, ligne);
} while (ligne.size()==0);
} while (ligne.size() == 0);
std::stringstream oss(ligne);
oss >> m_nbVertices;
......@@ -344,10 +344,10 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<
} while (ligne.size() == 0);
std::stringstream oss(ligne);
int n;
unsigned int n;
oss >> n;
m_nbEdges.push_back(n);
for (int j=0;j<n; ++j)
for (unsigned int j = 0; j < n; ++j)
{
int index; // index du plongement
oss >> index;
......@@ -455,7 +455,7 @@ bool MeshTablesSurface<PFP>::importObj(const std::string& filename, std::vector<
unsigned int ind = 0;
while ( (ind<str.length()) && (str[ind]!='/'))
while ((ind<str.length()) && (str[ind]!='/'))
ind++;
if (ind > 0)
......
/*******************************************************************************
* 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 __IMPORT_MR_DAT__
#define __IMPORT_MR_DAT__
namespace CGoGN
{
namespace Algo
{
namespace Import
{
class QuadTreeNode
{
public:
unsigned int indices[3] ;
QuadTreeNode* children[4] ;
QuadTreeNode* parent ;
unsigned int level ;
QuadTreeNode()
{
for(unsigned int i = 0; i < 3; ++i)
indices[i] = -1 ;
for(unsigned int i = 0; i < 4; ++i)
children[i] = NULL ;
parent = NULL ;
level = 0 ;
}
~QuadTreeNode()
{
for(unsigned int i = 0; i < 4; ++i)
if(children[i] != NULL)
delete children[i] ;
}
void subdivide()
{
assert(!isSubdivided()) ;
for(unsigned int i = 0; i < 4; ++i)
{
children[i] = new QuadTreeNode() ;
children[i]->parent = this ;
children[i]->level = level + 1 ;
}
}
bool isSubdivided()
{
return children[0] != NULL ;
}
template <typename PFP>
void embed(typename PFP::MAP& map, Dart d, std::vector<unsigned int>& vID)
{
assert(map.getCurrentLevel() == level) ;
if(isSubdivided())
{
unsigned int v0 = vID[indices[0]] ;
unsigned int v1 = vID[indices[1]] ;
unsigned int v2 = vID[indices[2]] ;
Dart it = d ;
do
{
Dart next = map.phi1(it) ;
unsigned int emb = map.getEmbedding(VERTEX, it) ;
unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ;
map.incCurrentLevel() ;
Dart dd = map.phi1(next) ;
unsigned int oldEmb = map.getEmbedding(VERTEX, dd) ;
unsigned int newEmb = vID[children[0]->indices[idx]] ;
if(oldEmb == EMBNULL)
{
map.embedOrbit(VERTEX, dd, newEmb) ;
map.pushLevel() ;
for(unsigned int i = map.getCurrentLevel() + 1; i <= map.getMaxLevel(); ++i)
{
map.setCurrentLevel(i) ;
map.embedOrbit(VERTEX, dd, newEmb) ;
}
map.popLevel() ;
}
else
assert(oldEmb == newEmb) ;
map.decCurrentLevel() ;
it = next ;
} while(it != d) ;
map.incCurrentLevel() ;
Dart d0 = map.phi2(map.phi1(d)) ;
children[0]->embed<PFP>(map, d0, vID) ;
map.decCurrentLevel() ;
do
{
unsigned int emb = map.getEmbedding(VERTEX, it) ;
unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ;
map.incCurrentLevel() ;
children[idx+1]->embed<PFP>(map, it, vID) ;
map.decCurrentLevel() ;
it = map.phi1(it) ;
} while(it != d) ;
}
else
{
if(map.getCurrentLevel() < map.getMaxLevel())
std::cout << "adaptive subdivision not managed yet" << std::endl ;
}
}
void print()
{
std::cout << indices[0] << " " << indices[1] << " " << indices[2] << std::endl ;
if(isSubdivided())
{
for(unsigned int i = 0; i < 4; ++i)
children[i]->print() ;
}
}
} ;
class QuadTree
{
public:
std::vector<QuadTreeNode*> roots ;
std::vector<Dart> darts ;
std::vector<unsigned int> verticesID ;
~QuadTree()
{
for(unsigned int i = 0; i < roots.size(); ++i)
delete roots[i] ;
}
template <typename PFP>
void embed(typename PFP::MAP& map)
{
for(unsigned int i = 0; i < roots.size(); ++i)
roots[i]->embed<PFP>(map, darts[i], verticesID) ;
}
void print()
{
std::cout << "printing quadtree (" << roots.size() << " roots)" << std::endl ;
for(unsigned int i = 0; i < roots.size(); ++i)
{
std::cout << "root " << i << std::endl ;
roots[i]->print() ;
}
}
} ;
template <typename PFP>
bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, QuadTree& qt) ;
} // namespace Import
} // namespace Algo
} // namespace CGoGN
#include "Algo/Import/importMRDAT.hpp"
#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 *
* *
*******************************************************************************/
namespace CGoGN
{
namespace Algo
{
namespace Import
{
inline void nextNonEmptyLine(std::ifstream& fp, std::string& line)
{
do {
std::getline(fp, line) ;
} while (line.size() == 0) ;
}
template <typename PFP>
bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, QuadTree& qt)
{
AttributeHandler<typename PFP::VEC3> position = map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
if (!position.isValid())
position = map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ;
attrNames.push_back(position.name()) ;
AttributeContainer& container = map.getAttributeContainer(VERTEX) ;
// open file
std::ifstream fp(filename.c_str(), std::ios::in) ;
if (!fp.good())
{
CGoGNerr << "Unable to open file " << filename << CGoGNendl ;
return false ;
}
std::string line ;
nextNonEmptyLine(fp, line) ;
if (line.rfind("Multires data file") == std::string::npos)
{
CGoGNerr << "Problem reading MRDAT file" << CGoGNendl ;
CGoGNerr << line << CGoGNendl ;
return false ;
}
// read the depth
unsigned int depth ;
{
nextNonEmptyLine(fp, line) ;
std::stringstream oss(line) ;
std::string s ;
oss >> s ;
oss >> depth ;
}
std::cout << " MR depth -> " << depth << std::endl ;
// read vertices
nextNonEmptyLine(fp, line) ;
if (line.rfind("Vertices") == std::string::npos)
{
CGoGNerr << "Problem reading MRDAT file" << CGoGNendl ;
CGoGNerr << line << CGoGNendl ;
return false ;
}
std::cout << " Read vertices.." << std::flush ;
qt.roots.clear() ;
qt.darts.clear() ;
qt.verticesID.clear() ;
nextNonEmptyLine(fp, line) ;
while(line.rfind("Triangles") == std::string::npos)
{
std::stringstream oss(line) ;
unsigned int level ;
oss >> level ;
float x, y, z ;
oss >> x ;
oss >> y ;
oss >> z ;
typename PFP::VEC3 pos(x, y, z) ;
unsigned int id = container.insertLine() ;
position[id] = pos ;
qt.verticesID.push_back(id) ;
nextNonEmptyLine(fp, line) ;
}
std::cout << "..done (nb vertices -> " << qt.verticesID.size() << ")" << std::endl ;
std::cout << " Read triangles (build quadtree).." << std::flush ;
QuadTreeNode* current = NULL ;
unsigned int currentLevel = -1 ;
std::vector<unsigned int> lastNum ;
lastNum.resize(depth + 1) ;
nextNonEmptyLine(fp, line) ;
while(line.rfind("end") == std::string::npos)
{
std::stringstream oss(line) ;
std::string name ;
oss >> name ;
unsigned int num, root, idx0, idx1, idx2 ;
oss >> num ;
oss >> root ;
oss >> idx0 ;
oss >> idx1 ;
oss >> idx2 ;
if(root == 1)
{
assert(num == 0) ;
QuadTreeNode* n = new QuadTreeNode() ;
n->indices[0] = idx0 ;
n->indices[1] = idx1 ;
n->indices[2] = idx2 ;
qt.roots.push_back(n) ;
current = n ;
currentLevel = 0 ;
lastNum[0] = 0 ;
}
else
{
if(num == lastNum[currentLevel] + 1) // on lit un autre triangle du même niveau
{
current = current->parent->children[num] ;
}
else // on monte ou on descend d'un niveau
{
if(num == 0) // on subdivise le triangle courant
{
current->subdivide() ;
current = current->children[0] ;
++currentLevel ;
}
else // on remonte d'un niveau
{
assert(lastNum[currentLevel] == 3) ;
do
{
current = current->parent->parent->children[num] ;
--currentLevel ;
} while(lastNum[currentLevel] == 3) ;
}
}
current->indices[0] = idx0 ;
current->indices[1] = idx1 ;
current->indices[2] = idx2 ;
lastNum[currentLevel] = num ;
}
nextNonEmptyLine(fp, line) ;
}
std::cout << "..done" << std::endl ;
fp.close() ;
std::cout << " Create base level mesh.." << std::flush ;
AutoAttributeHandler< NoMathIONameAttribute< std::vector<Dart> > > vecDartsPerVertex(map, VERTEX, "incidents") ;
DartMarkerNoUnmark m(map) ;
unsigned nbf = qt.roots.size() ;
// for each root face
for(unsigned int i = 0; i < nbf; ++i)
{
Dart d = map.newFace(3, false) ;
qt.darts.push_back(d) ;
for (unsigned int j = 0; j < 3; ++j)
{
unsigned int idx = qt.roots[i]->indices[j] ;
unsigned int emb = qt.verticesID[idx] ;
FunctorSetEmb<typename PFP::MAP> fsetemb(map, VERTEX, emb) ;
map.foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb) ;
m.mark(d) ; // mark on the fly to unmark on second loop
vecDartsPerVertex[emb].push_back(d) ; // store incident darts for fast adjacency reconstruction
d = map.phi1(d) ;
}
}
// reconstruct neighbourhood between root faces
unsigned int nbBoundaryEdges = 0 ;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (m.isMarked(d))
{
// darts incident to end vertex of edge
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)] ;
unsigned int embd = map.getEmbedding(VERTEX, d) ;
Dart good_dart = NIL ;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{
if (map.getEmbedding(VERTEX, map.phi1(*it)) == embd)
good_dart = *it ;
}
if (good_dart != NIL)
{
map.sewFaces(d, good_dart, false) ;
m.unmarkOrbit(EDGE, d) ;
}
else
{
m.unmark(d) ;
++nbBoundaryEdges ;
}
}
}
if (nbBoundaryEdges > 0)
{
// map.closeMap() ;
CGoGNout << "Open mesh.. not managed yet.." << CGoGNendl ;
return false ;
}
std::cout << "..done" << std::endl ;
std::cout << " Create finer resolution levels.." << std::flush ;
for(unsigned int i = 0; i < depth; ++i)
map.addNewLevel(false) ;
std::cout << "..done" << std::endl ;
std::cout << " Embed finer resolution levels.." << std::flush ;
map.setCurrentLevel(0) ;
qt.embed<PFP>(map) ;
map.setCurrentLevel(map.getMaxLevel()) ;
std::cout << "..done" << std::endl ;
return true ;
}
} // namespace Import
} // namespace Algo
} // namespace CGoGN
......@@ -121,8 +121,8 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
if (nbBoundaryEdges > 0)
{
map.closeMap();
CGoGNout << "Map closed (" << nbBoundaryEdges << " boundary edges)" << CGoGNendl;
unsigned int nbH = map.closeMap();
CGoGNout << "Map closed (" << nbBoundaryEdges << " boundary edges / " << nbH << " holes)" << CGoGNendl;
// ensure bijection between topo and embedding
map.bijectiveOrbitEmbedding(VERTEX);
}
......@@ -130,7 +130,6 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
return true ;
}
template <typename PFP>
bool importMeshSToV(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts, float dist)
{
......
/*******************************************************************************
* 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 __IMPORTSVG_H__
#define __IMPORTSVG_H__
......@@ -35,12 +59,11 @@ bool importBB(const std::string& filename, std::vector<Geom::BoundingBox<typenam
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames);
} // namespace Import
}
}
} // namespace Algo
}
} // namespace CGoGN
#include "Algo/Import/importSvg.hpp"
......
/*******************************************************************************
* 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 <iostream>
#include "Geometry/bounding_box.h"
#include "Geometry/plane_3d.h"
......@@ -692,8 +716,8 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
return true ;
}
} //import
} // namespace Import
} //algo
} // namespace Algo
} //cgogn
} // namespace CGoGN
......@@ -46,10 +46,6 @@ Dart trianguleFace(typename PFP::MAP& map, Dart d)
if (map.phi1(d1) == d)
CGoGNout << "Warning: triangulation of a face with only two edges" << CGoGNendl;
std::cout << "d = " << d << std::endl;
std::cout << "map.phi1(d) = " << map.phi1(d) << std::endl;
std::cout << "map.phi_1(d) = " << map.phi_1(d) << std::endl;
map.splitFace(d, d1) ;
map.cutEdge(map.phi_1(d)) ;
Dart x = map.phi2(map.phi_1(d)) ;
......@@ -76,7 +72,7 @@ void trianguleFaces(typename PFP::MAP& map, EMBV& attributs, const FunctorSelect
Dart fit = cd ;
do
{
t.mark(fit);
t.skip(fit);
fit = map.phi2_1(fit);
} while(fit != cd);
}
......@@ -105,7 +101,7 @@ void trianguleFaces(
Dart fit = cd ;
do
{
t.mark(fit);
t.skip(fit);
fit = map.phi2_1(fit);
} while(fit != cd);
}
......