Commit 3d3eff3d authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~untereiner/CGoGN

parents 235c12d8 324560fb
......@@ -57,6 +57,8 @@
#include "Utils/cgognStream.h"
#include "Utils/drawer.h"
#include "Algo/Modelisation/primitives3d.h"
#include <string>
#include <sstream>
......
......@@ -3,6 +3,7 @@
#include "Topology/generic/attributeHandler.h"
#include "Utils/cgognStream.h"
#include "Algo/Geometry/normal.h"
namespace CGoGN
{
......@@ -45,7 +46,7 @@ void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, typename PFP::T
unsigned int nb=0;
Dart dd=d;
do {
traite.markOrbit(DART,dd);
traite.mark(dd);
dd = map.phi1(dd);
nb++;
} while(dd!=d);
......@@ -69,6 +70,104 @@ void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, typename PFP::T
out << "}" << std::endl;
}
template <typename PFP>
void export3MeshPlainSmooth(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue())
{
typedef typename PFP::VEC3 VEC3;
out << "#declare " << meshName << "= mesh2 {" << std::endl;
unsigned int nbDarts = map.getNbDarts() ;
//vector containing the degree of faces
std::vector<unsigned int> facesSize ;
//vector containing the list of index of vertices
std::vector<std::vector<unsigned int> > facesIdx ;
facesSize.reserve(nbDarts/3) ;
facesIdx.reserve(nbDarts/3) ;
//map : attribute place / index in declaration (for vertices and normals)
std::map<unsigned int, unsigned int> vIndex ;
//index : start from 0 and increase (used to ignore the gaps potentially present in the container)
unsigned int vCpt = 0 ;
//remember the attribute lines
std::vector<unsigned int> vertices ;
std::vector<VEC3> normals ;
vertices.reserve(nbDarts/6) ;
normals.reserve(nbDarts/6) ;
CellMarker markV(map, VERTEX) ;
DartMarker markF(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(good(d) && !markF.isMarked(d) && map.phi3(d)==d)
{
markF.markOrbit(FACE, d) ;
std::vector<unsigned int> fidx ;
fidx.reserve(4) ;
Dart dd = d ;
do
{
unsigned int vNum = map.getEmbedding(VERTEX, dd) ;
if(!markV.isMarked(dd))
{
markV.mark(dd) ;
VEC3 norm = Algo::Geometry::vertexBorderNormal<PFP>(map,dd,position);
vIndex[vNum] = vCpt++ ;
vertices.push_back(vNum) ;
normals.push_back(norm) ;
}
fidx.push_back(vIndex[vNum]) ;
dd = map.phi1(dd) ;
} while(dd != d) ;
facesSize.push_back(map.faceDegree(d)) ;
facesIdx.push_back(fidx) ;
}
}
//export all vertices
out << "vertex_vectors {" << std::endl;
out << vertices.size() << "," << std::endl;
for(unsigned int i = 0; i < vertices.size(); ++i)
{
const VEC3& v = position[vertices[i]] ;
out << "<" << v[0] << ", " << v[1] << ", " << v[2] << ">"<< std::endl ;
}
out << "}" << std::endl;
//export all normals
out << "normal_vectors {" << std::endl;
out << normals.size() << "," << std::endl;
for(unsigned int i = 0; i < normals.size(); ++i)
{
const VEC3& v = normals[i];
out << "<" << v[0] << ", " << v[1] << ", " << v[2] << ">"<< std::endl ;
}
out << "}" << std::endl;
//export all faces
out << "face_indices {" << std::endl;
out << facesSize.size() << "," << std::endl;
for(unsigned int i = 0; i < facesSize.size(); ++i)
{
out << "<" << facesIdx[i][0];
for(unsigned int j = 1; j < facesIdx[i].size(); ++j)
out << ", " << facesIdx[i][j] ;
out << ">" << std::endl ;
}
out << "}" << std::endl;
out << "}" << std::endl;
}
template <typename PFP>
void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue())
{
......@@ -134,7 +233,8 @@ bool exportScenePov(typename PFP::MAP& map, typename PFP::TVEC3& position, const
out << "global_settings {" << std::endl;
out << "radiosity {" << std::endl;
out << "pretrace_start 0.08 pretrace_end 0.04" << std::endl;
out << "count 100 nearest_count 10 error_bound 0.15 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1 adc_bailout 0.01/2 normal off media off} max_trace_level 255}" << std::endl;
out << "count 100 nearest_count 10 error_bound 0.15 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1 adc_bailout 0.01/2 normal off media off}" << std::endl;
out << "max_trace_level 255}" << std::endl;
Algo::ExportPov::exportMeshPlain<PFP>(out,map,position,"myMesh",good);
......@@ -147,6 +247,51 @@ bool exportScenePov(typename PFP::MAP& map, typename PFP::TVEC3& position, const
return true;
}
template <typename PFP>
bool exportScenePovSmooth(typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& filename, typename PFP::VEC3 cameraPos, typename PFP::VEC3 cameraLook, typename PFP::VEC3 translate, float angle_X, float angle_Y, float angle_Z,const FunctorSelect& good = SelectorTrue())
{
std::ofstream out(filename.c_str(), std::ios::out);
if (!out.good()) {
CGoGNerr << "(export) Unable to open file " << filename << CGoGNendl;
return false;
}
float angleX = angle_X;
float angleY = angle_Y;
float angleZ = angle_Z;
//define the camera position
out << "camera { location <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> look_at <" << cameraLook[0] << "," << cameraLook[1] << "," << cameraLook[2] <<">}" << std::endl;
//set a "infinite" plane
// out << "plane { y, -1 pigment { color rgb 1 } }" << std::endl;
//set a sky sphere
out << "sphere { <0, 0, 0>, 5000";
out << "texture{ pigment { color rgb <1, 1, 1>} finish { ambient 1 diffuse 0 } } }" << std::endl;
//put some lights
out << "light_source { <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> color rgb 0.45}" << std::endl;
//set a high quality rendering
out << "global_settings {" << std::endl;
// out << "radiosity {" << std::endl;
// out << "pretrace_start 0.08 pretrace_end 0.04" << std::endl;
// out << "count 300 nearest_count 10 error_bound 0.15 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1 adc_bailout 0.01/2 normal off media off}" << std::endl;
out << "max_trace_level 60}" << std::endl;
Algo::ExportPov::export3MeshPlainSmooth<PFP>(out,map,position,"myMesh",good);
out << "object {myMesh" << std::endl;
out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl;
out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl;
out << "double_illuminate" << std::endl;
out << "texture{ pigment{ color rgb <0.5,1.0,0.5>} finish { ambient 0.5 roughness 0.2 } } }" << std::endl;
out.close();
return true;
}
}
}
......
......@@ -39,12 +39,18 @@ namespace Geometry
template <typename PFP>
typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
typename PFP::VEC3 newellNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position);
template <typename PFP>
typename PFP::VEC3 faceNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
typename PFP::VEC3 vertexBorderNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
void computeNormalFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& face_normal, const FunctorSelect& select = SelectorTrue(), unsigned int thread = 0) ;
......
......@@ -116,6 +116,40 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P
return N ;
}
template <typename PFP>
typename PFP::VEC3 vertexBorderNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
assert(map.dimension() == 3);
typedef typename PFP::VEC3 VEC3 ;
VEC3 N(0) ;
std::vector<Dart> faces;
CellMarker f(map,FACE);
FunctorStore fs(faces);
map.foreach_dart_of_oriented_vertex(d,fs);
for(std::vector<Dart>::iterator it = faces.begin() ; it != faces.end() ; ++it)
{
if(!f.isMarked(*it) && map.phi3(*it)==*it)
{
f.mark(*it);
VEC3 n = faceNormal<PFP>(map, *it, position);
if(!n.hasNan())
{
VEC3 v1 = vectorOutOfDart<PFP>(map, *it, position);
VEC3 v2 = vectorOutOfDart<PFP>(map, map.phi_1(*it), position);
n *= convexFaceArea<PFP>(map, *it, position) / (v1.norm2() * v2.norm2());
N += n ;
}
}
}
N.normalize() ;
return N ;
}
template <typename PFP>
void computeNormalFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& face_normal, const FunctorSelect& select, unsigned int thread)
{
......
......@@ -36,11 +36,11 @@ namespace Algo
namespace IHM
{
template<typename T> class AttributeHandler_IHM ;
//template<typename T> class AttributeHandler_IHM ;
class ImplicitHierarchicalMap3 : public EmbeddedMap3
{
template<typename T> friend class AttributeHandler_IHM ;
//template<typename T> friend class AttributeHandler_IHM ;
public:
unsigned int m_curLevel ;
......@@ -65,11 +65,11 @@ public:
* ATTRIBUTES MANAGEMENT *
***************************************************/
template <typename T>
AttributeHandler_IHM<T> addAttribute(unsigned int orbit, const std::string& nameAttr) ;
//template <typename T>
//AttributeHandler_IHM<T> addAttribute(unsigned int orbit, const std::string& nameAttr) ;
template <typename T>
AttributeHandler_IHM<T> getAttribute(unsigned int orbit, const std::string& nameAttr) ;
//template <typename T>
//AttributeHandler_IHM<T> getAttribute(unsigned int orbit, const std::string& nameAttr) ;
/***************************************************
......@@ -117,15 +117,6 @@ public:
virtual bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread = 0) ;
/****************************************************
* EMBEDDED FUNCTIONS *
****************************************************/
// virtual void cutEdge(Dart d);
//
// virtual void splitFace(Dart d, Dart e);
//
// virtual void sewVolumes(Dart d, Dart e);
/***************************************************
* LEVELS MANAGEMENT *
***************************************************/
......@@ -278,42 +269,42 @@ public:
bool coarsenNeighborhoodLevelDiffersByOne(Dart d);
} ;
template <typename T>
class AttributeHandler_IHM : public AttributeHandler<T>
{
public:
typedef T DATA_TYPE ;
AttributeHandler_IHM() : AttributeHandler<T>()
{}
AttributeHandler_IHM(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T>(m, amv)
{}
AttributeMultiVector<T>* getDataVector() const
{
return AttributeHandler<T>::getDataVector() ;
}
bool isValid() const
{
return AttributeHandler<T>::isValid() ;
}
T& operator[](Dart d) ;
const T& operator[](Dart d) const ;
T& operator[](unsigned int a)
{
return AttributeHandler<T>::operator[](a) ;
}
const T& operator[](unsigned int a) const
{
return AttributeHandler<T>::operator[](a) ;
}
} ;
//template <typename T>
//class AttributeHandler_IHM : public AttributeHandler<T>
//{
//public:
// typedef T DATA_TYPE ;
//
// AttributeHandler_IHM() : AttributeHandler<T>()
// {}
//
// AttributeHandler_IHM(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T>(m, amv)
// {}
//
// AttributeMultiVector<T>* getDataVector() const
// {
// return AttributeHandler<T>::getDataVector() ;
// }
//
// bool isValid() const
// {
// return AttributeHandler<T>::isValid() ;
// }
//
// T& operator[](Dart d) ;
//
// const T& operator[](Dart d) const ;
//
// T& operator[](unsigned int a)
// {
// return AttributeHandler<T>::operator[](a) ;
// }
//
// const T& operator[](unsigned int a) const
// {
// return AttributeHandler<T>::operator[](a) ;
// }
//} ;
} //namespace IHM
......
......@@ -31,37 +31,37 @@ namespace Algo
namespace IHM
{
/***************************************************
* ATTRIBUTES MANAGEMENT *
***************************************************/
template <typename T>
AttributeHandler_IHM<T> ImplicitHierarchicalMap3::addAttribute(unsigned int orbit, const std::string& nameAttr)
{
bool addNextLevelCell = false ;
if(!isOrbitEmbedded(orbit))
addNextLevelCell = true ;
AttributeHandler<T> h = Map3::addAttribute<T>(orbit, nameAttr) ;
if(addNextLevelCell)
{
AttributeContainer& cellCont = m_attribs[orbit] ;
AttributeMultiVector<unsigned int>* amv = cellCont.addAttribute<unsigned int>("nextLevelCell") ;
m_nextLevelCell[orbit] = amv ;
for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i))
amv->operator[](i) = EMBNULL ;
}
return AttributeHandler_IHM<T>(this, h.getDataVector()) ;
}
template <typename T>
AttributeHandler_IHM<T> ImplicitHierarchicalMap3::getAttribute(unsigned int orbit, const std::string& nameAttr)
{
AttributeHandler<T> h = Map2::getAttribute<T>(orbit, nameAttr) ;
return AttributeHandler_IHM<T>(this, h.getDataVector()) ;
}
///***************************************************
// * ATTRIBUTES MANAGEMENT *
// ***************************************************/
//
//template <typename T>
//AttributeHandler_IHM<T> ImplicitHierarchicalMap3::addAttribute(unsigned int orbit, const std::string& nameAttr)
//{
// bool addNextLevelCell = false ;
// if(!isOrbitEmbedded(orbit))
// addNextLevelCell = true ;
//
// AttributeHandler<T> h = Map3::addAttribute<T>(orbit, nameAttr) ;
//
// if(addNextLevelCell)
// {
// AttributeContainer& cellCont = m_attribs[orbit] ;
// AttributeMultiVector<unsigned int>* amv = cellCont.addAttribute<unsigned int>("nextLevelCell") ;
// m_nextLevelCell[orbit] = amv ;
// for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i))
// amv->operator[](i) = EMBNULL ;
// }
//
// return AttributeHandler_IHM<T>(this, h.getDataVector()) ;
//}
//
//template <typename T>
//AttributeHandler_IHM<T> ImplicitHierarchicalMap3::getAttribute(unsigned int orbit, const std::string& nameAttr)
//{
// AttributeHandler<T> h = Map2::getAttribute<T>(orbit, nameAttr) ;
// return AttributeHandler_IHM<T>(this, h.getDataVector()) ;
//}
/***************************************************
* MAP TRAVERSAL *
......@@ -363,98 +363,6 @@ inline bool ImplicitHierarchicalMap3::foreach_dart_of_cc(Dart d, FunctorType& f,
return foreach_dart_of_oriented_volume(d, f) ;
}
/**************************************************
* EMBEDDED FUNCTIONS *
**************************************************/
//void ImplicitHierarchicalMap3::cutEdge(Dart d)
//{
// Dart dd = phi2(d) ;
// EmbeddedMap3<Map3>::cutEdge(d);
//
// //
// //mise a jour de l'id d'arrete sur chaque moitie d'arete
// //
// unsigned int eId;
//
// //Test si id existe
// if(m_edgeId[d] == EMBNULL)
// {
// eId = getNewEdgeId();
// }
// else
// {
// eId = getEdgeId(d) ;
// }
//
// //tour de la 1ere moitie de l'arete avec modification
// Dart e = d;
// do
// {
// m_edgeId[e] = eId; //cas ou l'arete n'est pas du tout plonge
// m_edgeId[Map3::phi2(e)] = eId;
//
// e = Map3::alpha2(e);
// } while(e != d);
//
//
// e = dd;
// do
// {
// m_edgeId[e] = eId;
// m_edgeId[Map3::phi2(e)] = eId;
//
// e = Map3::alpha2(e);
// } while(e != dd);
//
//
// //
// //mise a jour de l'id de face sur chaque brin de chaque moitie d'arete
// //
//
//}
//
//void ImplicitHierarchicalMap3::splitFace(Dart d, Dart e)
//{
// //
// //Verification que les brins precedents ceux que l'on split n'ont pas le meme id
// //
// if(m_edgeId[d] == m_edgeId[Map3::phi_1(d)])
// {
// unsigned int eId = getNewEdgeId() ;
//
// Dart e = d;
// do
// {
// m_edgeId[e] = eId; //cas ou l'arete n'est pas du tout plonge
// m_edgeId[Map3::phi2(e)] = eId;
//
// e = Map3::alpha2(e);
// } while(e != d);
// }
//
// EmbeddedMap3<Map3>::splitFace(d,e);
//
// //
// //creation d'un id d'arete sur la nouvelle arete
// //
//
// unsigned int eId = getNewEdgeId() ;
// Dart a =Map3:: phi_1(d);
//
// do
// {
// m_edgeId[a] = eId;
// m_edgeId[Map3::phi2(a)] = eId;
//
// a = Map3::alpha2(a);
// } while(a != Map3::phi_1(d));
//
//}
//
//void ImplicitHierarchicalMap3::sewVolumes(Dart d, Dart e)
//{
//
//}
/***************************************************
* LEVELS MANAGEMENT *
......@@ -615,67 +523,67 @@ inline unsigned int ImplicitHierarchicalMap3::edgeLevel(Dart d)
return r;
}
/***************************************************
* ATTRIBUTE HANDLER *
***************************************************/
template <typename T>
T& AttributeHandler_IHM<T>::operator[](Dart d)
{
ImplicitHierarchicalMap3* m = reinterpret_cast<ImplicitHierarchicalMap3*>(this->m_map) ;
assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;
unsigned int orbit = this->getOrbit() ;
unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
unsigned int index = m->getEmbedding(orbit, d) ;
if(index == EMBNULL)
{
index = m->embedNewCell(orbit, d) ;
m->m_nextLevelCell[orbit]->operator[](index) = EMBNULL ;
}
AttributeContainer& cont = m->getAttributeContainer(orbit) ;
unsigned int step = 0 ;
while(step < nbSteps)
{
step++ ;
unsigned int nextIdx = m->m_nextLevelCell[orbit]->operator[](index) ;
if (nextIdx == EMBNULL)
{
nextIdx = m->newCell(orbit) ;
m->copyCell(orbit, nextIdx, index) ;
m->m_nextLevelCell[orbit]->operator[](index) = nextIdx ;
m->m_nextLevelCell[orbit]->operator[](nextIdx) = EMBNULL ;
cont.refLine(index) ;
}
index = nextIdx ;
}
return this->m_attrib->operator[](index);
}
template <typename T>
const T& AttributeHandler_IHM<T>::operator[](Dart d) const
{
ImplicitHierarchicalMap3* m = reinterpret_cast<ImplicitHierarchicalMap3*>(this->m_map) ;
assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;
unsigned int orbit = this->getOrbit() ;
unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
unsigned int index = m->getEmbedding(orbit, d) ;
unsigned int step = 0 ;
while(step < nbSteps)
{
step++ ;
unsigned int next = m->m_nextLevelCell[orbit]->operator[](index) ;
if(next != EMBNULL) index = next ;
else break ;
}
return this->m_attrib->operator[](index);
}
///***************************************************
// * ATTRIBUTE HANDLER *
// ***************************************************/
//
//template <typename T>
//T& AttributeHandler_IHM<T>::operator[](Dart d)
//{
// ImplicitHierarchicalMap3* m = reinterpret_cast<ImplicitHierarchicalMap3*>(this->m_map) ;
// assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
// assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;
//
// unsigned int orbit = this->getOrbit() ;