Commit 9ad68434 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Merge cgogn:~cgogn/CGoGN

parents 5b6aea82 627a0a0d
......@@ -49,6 +49,8 @@
#include "Algo/Render/GL2/topo3Render.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/cgognStream.h"
#include "Utils/drawer.h"
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __ALGO_BOOLEANOPERATOR_VERTICES_H__
#define __ALGO_BOOLEANOPERATOR_VERTICES_H__
#include "Geometry/basic.h"
#include "Geometry/inclusion.h"
#include "Geometry/orientation.h"
namespace CGoGN
{
namespace Algo
{
namespace BooleanOperator
{
template <typename PFP>
void mergeVertex(typename PFP::MAP& map, const typename PFP::TVEC3& positions, Dart d, Dart e);
template <typename PFP>
void mergeVertices(typename PFP::MAP& map, const typename PFP::TVEC3& positions);
}
}
}
#include "mergeVertices.hpp"
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
namespace CGoGN
{
namespace Algo
{
namespace BooleanOperator
{
template <typename PFP>
void mergeVertex(typename PFP::MAP& map, const typename PFP::TVEC3& positions, Dart d, Dart e)
{
assert(Geom::arePointsEquals(positions[d],positions[e]) && !map.sameVertex(d,e));
Dart dd;
do
{
dd = map.alpha1(d);
map.removeEdgeFromVertex(dd);
Dart ee = e;
do
{
if(Geom::testOrientation2D(positions[map.phi1(dd)],positions[ee],positions[map.phi1(ee)])!=Geom::RIGHT
&& Geom::testOrientation2D(positions[map.phi1(dd)],positions[ee],positions[map.phi1(map.alpha1(ee))])==Geom::RIGHT)
{
break;
}
ee = map.alpha1(ee);
} while(ee != e);
map.insertEdgeInVertex(ee,dd);
} while(dd!=d);
}
template <typename PFP>
void mergeVertices(typename PFP::MAP& map, const typename PFP::TVEC3& positions)
{
for(Dart d = map.begin() ; d != map.end() ; map.next(d))
{
CellMarker vM(map,VERTEX);
vM.mark(d);
for(Dart dd = map.begin() ; dd != map.end() ; map.next(dd))
{
if(!vM.isMarked(dd))
{
vM.mark(dd);
if(Geom::arePointsEquals(positions[d],positions[dd]))
{
mergeVertex<PFP>(map,positions,d,dd);
}
}
}
}
}
}
}
}
......@@ -95,7 +95,7 @@ void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TV
if(position[dd][0]!=position[map.phi1(dd)][0] || position[dd][1]!=position[map.phi1(dd)][1] || position[dd][2]!=position[map.phi1(dd)][2]) {
out << "cylinder{ " << std::endl;
out << "<" << position[dd][0] << "," << position[dd][2] << "," << position[dd][1] << ">," << std::endl;
out << "<" << position[map.phi1(dd)][0] << "," << position[map.phi1(dd)][2] << "," << position[map.phi1(dd)][1] << ">, 0.5" << std::endl;
out << "<" << position[map.phi1(dd)][0] << "," << position[map.phi1(dd)][2] << "," << position[map.phi1(dd)][1] << ">, 1.5" << std::endl;
out << "}" << std::endl;
}
dd = map.phi1(dd);
......
......@@ -24,6 +24,7 @@
#include "Algo/Geometry/normal.h"
#include "Algo/Geometry/centroid.h"
#include "intersection.h"
#include <limits>
......@@ -44,10 +45,10 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P
const float SMALL_NUM = std::numeric_limits<typename PFP::REAL>::min() * 5.0f;
VEC3 p1 = position[d];
VEC3 n = faceNormal<PFP>(map, d, position);
VEC3 n = faceNormal<PFP>(map,d,position);
VEC3 w0 = P - p1;
float a = -(n * w0);
float b = n * Dir;
float a = -(n*w0);
float b = n*Dir;
if (fabs(b) < SMALL_NUM)
return false;
......
......@@ -240,34 +240,37 @@ inline void ImplicitHierarchicalMap3::next(Dart& d)
inline bool ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
{
DartMarkerStore mv(*this); // Lock a marker
DartMarkerStore mv(*this,thread); // Lock a marker
bool found = false; // Last functor return value
std::list<Dart> darts_list; //Darts that are traversed
darts_list.push_back(d); //Start with the dart d
std::list<Dart>::iterator darts;
std::vector<Dart> darts_list; //Darts that are traversed
darts_list.reserve(50);
darts_list.push_back(d); //Start with the dart d
mv.mark(d);
for(darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
for(std::vector<Dart>::iterator darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
{
Dart dc = *darts;
//add phi21 and phi23 successor if they are not marked yet
Dart d2 = phi2(dc);
Dart d21 = phi1(d2); // turn in volume
Dart d23 = phi3(d2); // change volume
if(!mv.isMarked(d21))
if(d2 != dc)
{
darts_list.push_back(d21);
mv.mark(d21);
}
Dart d21 = phi1(d2); // turn in volume
Dart d23 = phi3(d2); // change volume
if((d23!=d2) && !mv.isMarked(d23))
{
darts_list.push_back(d23);
mv.mark(d23);
if(!mv.isMarked(d21))
{
darts_list.push_back(d21);
mv.mark(d21);
}
if((d23!=d2) && !mv.isMarked(d23))
{
darts_list.push_back(d23);
mv.mark(d23);
}
}
found = f(dc);
......
......@@ -62,6 +62,15 @@ void coarsenFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
template <typename PFP>
void coarsenVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
/***********************************************************************************
* Raffinement
***********************************************************************************/
/*
* Un brin de la face oppose aux faces a spliter
*/
template <typename PFP>
void splitVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position);
/*******************************************************
*
*/
......
......@@ -85,7 +85,9 @@ void subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
++degree;
p += position[it] ;
if(!map.edgeIsSubdivided(it)) // first cut the edges (if they are not already)
{
Algo::IHM::subdivideEdge<PFP>(map, it, position) ; // and compute the degree of the face
}
it = map.phi1(it) ;
} while(it != old) ;
p /= typename PFP::REAL(degree) ;
......@@ -94,38 +96,38 @@ void subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
Dart res;
if(degree == 3 && sType == S_TRI) //subdiviser une face triangulaire
{
Dart dd = map.phi1(old) ;
Dart e = map.phi1(map.phi1(dd)) ;
map.splitFace(dd, e) ; // insert a new edge
unsigned int id = map.getNewEdgeId() ;
map.setEdgeId(map.phi_1(dd), id, EDGE) ; // set the edge id of the inserted edge to the next available id
unsigned int idface = map.getFaceId(old);
map.setFaceId(dd, idface, FACE) ;
map.setFaceId(e, idface, FACE) ;
dd = e ;
e = map.phi1(map.phi1(dd)) ;
map.splitFace(dd, e) ;
id = map.getNewEdgeId() ;
map.setEdgeId(map.phi_1(dd), id, EDGE) ;
map.setFaceId(dd, idface, FACE) ;
map.setFaceId(e, idface, FACE) ;
dd = e ;
e = map.phi1(map.phi1(dd)) ;
map.splitFace(dd, e) ;
id = map.getNewEdgeId() ;
map.setEdgeId(map.phi_1(dd), id, EDGE) ;
map.setFaceId(dd, idface, FACE) ;
map.setFaceId(e, idface, FACE) ;
}
else
{
// if(degree == 3 && sType == S_TRI) //subdiviser une face triangulaire
// {
// Dart dd = map.phi1(old) ;
// Dart e = map.phi1(map.phi1(dd)) ;
// map.splitFace(dd, e) ; // insert a new edge
// unsigned int id = map.getNewEdgeId() ;
// map.setEdgeId(map.phi_1(dd), id, EDGE) ; // set the edge id of the inserted edge to the next available id
//
// unsigned int idface = map.getFaceId(old);
// map.setFaceId(dd, idface, FACE) ;
// map.setFaceId(e, idface, FACE) ;
//
// dd = e ;
// e = map.phi1(map.phi1(dd)) ;
// map.splitFace(dd, e) ;
// id = map.getNewEdgeId() ;
// map.setEdgeId(map.phi_1(dd), id, EDGE) ;
//
// map.setFaceId(dd, idface, FACE) ;
// map.setFaceId(e, idface, FACE) ;
//
// dd = e ;
// e = map.phi1(map.phi1(dd)) ;
// map.splitFace(dd, e) ;
// id = map.getNewEdgeId() ;
// map.setEdgeId(map.phi_1(dd), id, EDGE) ;
//
// map.setFaceId(dd, idface, FACE) ;
// map.setFaceId(e, idface, FACE) ;
// }
// else
// {
Dart dd = map.phi1(old) ;
map.splitFace(dd, map.phi1(map.phi1(dd))) ;
......@@ -162,7 +164,7 @@ void subdivideFace(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
dd = map.phi2(map.phi1(dd));
}
while(dd != ne);
}
// }
map.setCurrentLevel(cur) ;
}
......@@ -173,12 +175,14 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
assert(map.getDartLevel(d) <= map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
assert(!map.volumeIsSubdivided(d) || !"Trying to subdivide an already subdivided volume") ;
unsigned int vLevel = map.volumeLevel(d) ;
Dart old = map.volumeOldestDart(d) ;
unsigned int vLevel = map.volumeLevel(d);
Dart old = map.volumeOldestDart(d);
unsigned int cur = map.getCurrentLevel();
map.setCurrentLevel(vLevel);
unsigned int cur = map.getCurrentLevel() ;
map.setCurrentLevel(vLevel) ; // go to the level of the face to subdivide its edges
std::cout << "vLevel = " << vLevel << std::endl;
/*
* au niveau du volume courant i
......@@ -187,7 +191,8 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
*/
DartMarkerStore mf(map); // Lock a face marker to save one dart per face
DartMarkerStore mv(map); // Lock a vertex marker to compute volume center
//DartMarkerStore mv(map); // Lock a vertex marker to compute volume center
CellMarker mv(map, VERTEX);
typename PFP::VEC3 volCenter;
unsigned count = 0 ;
......@@ -212,9 +217,10 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
//compute volume centroid
if(!mv.isMarked(e))
{
//mv.markOrbit(VERTEX, e);
mv.mark(e);
volCenter += position[e];
++count;
mv.markOrbit(VERTEX, e);
oldEdges.push_back(e);
}
......@@ -240,6 +246,7 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
std::vector<std::pair<Dart,Dart> > subdividedfaces;
subdividedfaces.reserve(25);
int i = 0;
//First step : subdivide edges and faces
//creates a i+1 edge level and i+1 face level
for (std::vector<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
......@@ -248,12 +255,24 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
//if needed subdivide face
if(!map.faceIsSubdivided(d))
{
++i;
Algo::IHM::subdivideFace<PFP>(map, d, position);
}
std::cout << "CHECK FACES " << std::endl;
map.check();
//save a dart from the subdivided face
unsigned int cur = map.getCurrentLevel() ;
unsigned int fLevel = map.faceLevel(d) + 1; //puisque dans tous les cas, la face est subdivisee
map.setCurrentLevel(map.getMaxLevel());
Dart old = map.faceOldestDart(d);
std::cout << " Oldest dart Face = " << old << std::endl;
unsigned int fLevel = map.faceLevel(old); //puisque dans tous les cas, la face est subdivisee
std::cout << "FACE LEVEL = " << fLevel << std::endl;
map.setCurrentLevel(fLevel) ;
......@@ -269,6 +288,8 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
map.setCurrentLevel(cur);
}
map.setCurrentLevel(vLevel + 1) ; // go to the next level to perform volume subdivision
std::vector<Dart> newEdges; //save darts from inner edges
......@@ -280,21 +301,33 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
Dart e = *edge;
Dart f1 = map.phi1(*edge);
int i = 0;
do
{
map.unsewFaces(map.phi1(map.phi1(e)));
std::cout << "corner #" << i << " degree = " << map.faceDegree(e) << std::endl;
if(map.phi2(map.phi1(map.phi1(e))) != map.phi1(map.phi1(e)))
map.unsewFaces(map.phi1(map.phi1(e)));
//TODO utile ?
//if(map.phi2(map.phi1(e)) != map.phi1(e))
if(map.phi2(map.phi1(e)) != map.phi1(e))
map.unsewFaces(map.phi1(e));
++i;
e = map.phi2(map.phi_1(e));
}
while(e != *edge);
map.closeHole(f1);
std::cout << "CHECK CLOSE HOLE " << std::endl;
map.check();
std::cout << "corner degree = " << i << std::endl;
std::cout << "face degree = " << map.faceDegree(map.phi2(f1)) << std::endl;
// if(map.faceDegree(map.phi2(f1)) > 6)
// return Dart::nil();
Dart old = map.phi2(map.phi1(e));
Dart dd = map.phi1(map.phi1(old)) ;
map.splitFace(old,dd) ;
......@@ -362,6 +395,8 @@ Dart subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positi
map.setCurrentLevel(cur) ;
std::cout << std::endl;
return subdividedfaces.begin()->first;
}
......@@ -740,10 +775,81 @@ void coarsenVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position
}
/***********************************************************************************
* Raffinement
***********************************************************************************/
template <typename PFP>
void splitVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position)
{
assert(map.getDartLevel(d) <= map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
assert(!map.volumeIsSubdivided(d) || !"Trying to subdivide an already subdivided volume") ;
unsigned int cur = map.getCurrentLevel() ;
unsigned int vLevel = map.volumeLevel(d) ;
map.setCurrentLevel(vLevel) ;
// first cut the edges (if they are not already)
Dart t = d;
do
{
if(!map.edgeIsSubdivided(map.phi1(map.phi2(t))))
Algo::IHM::subdivideEdge<PFP>(map, map.phi1(map.phi2(t)), position) ;
t = map.phi1(t);
}
while(t != d);
unsigned int fLevel = map.faceLevel(map.phi1(d));
map.setCurrentLevel(fLevel+1) ; // go to the level of the face to subdivide its edges
Dart neighboordVolume = map.phi1(map.phi1(map.phi2(d)));
//map.setCurrentLevel(cur) ; // go to the next level to perform volume subdivision
//Split the faces and open the midlle
do
{
Dart t2 = map.phi2(t);
unsigned int fLevel = map.faceLevel(t2) ;
map.setCurrentLevel(fLevel+1) ; // go to the level of the face to subdivide its edges
Dart face2 = map.phi1(map.phi1(t2));
map.splitFace(map.phi_1(t2), face2);
map.unsewFaces(map.phi1(map.phi1(t2)));
//id de face pour les 2 nouveaux brins
unsigned int idface = map.getFaceId(t2);
map.setFaceId(map.phi1(map.phi1(t2)), idface, DART);
map.setFaceId(map.phi_1(face2), idface, DART);
t = map.phi1(t);
}
while(t != d);
//close the middle to create volumes & sew them
map.setCurrentLevel(vLevel + 1) ; // go to the next level to perform volume subdivision
map.closeHole(map.phi1(map.phi1(map.phi2(d))));
map.closeHole(map.phi_1(neighboordVolume));
map.sewVolumes(map.phi2(map.phi1(map.phi1(map.phi2(d)))), map.phi2(map.phi_1(neighboordVolume)));
unsigned int idface = map.getNewFaceId();
map.setFaceId(map.phi2(map.phi_1(neighboordVolume)), idface, FACE);
do
{
Dart t211 = map.phi1(map.phi1(map.phi2(t)));
unsigned int idedge = map.getNewEdgeId();
map.setEdgeId(t211, idedge, EDGE);
t = map.phi1(t);
}
while(t != d);
map.setCurrentLevel(cur) ;
}
/*************************************************************************************
*
*/
template <typename PFP>
void subdivideVolume(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& position, SubdivideType sType)
{
......
#ifndef __AHEM_H__
#define __AHEM_H__
#include <string>
#ifdef _WIN32
typedef __int8 stInt8;
typedef __int16 stInt16;
typedef __int32 stInt32;
typedef __int64 stInt64;
typedef unsigned __int8 stUInt8;
typedef unsigned __int16 stUInt16;
typedef unsigned __int32 stUInt32;
typedef unsigned __int64 stUInt64;
#else
#include <stdint.h>
typedef int8_t stInt8;
typedef int16_t stInt16;
typedef int32_t stInt32;
typedef int64_t stInt64;
typedef uint8_t stUInt8;
typedef uint16_t stUInt16;
typedef uint32_t stUInt32;
typedef uint64_t stUInt64;
#endif
#ifdef _WIN32
#include <InitGuid.h>
#define DEFINE_GUID_INFUNC(name, dw, w0, w1, b0, b1, b2, b3, b4, b5, b6, b7) static const GUID name = { dw, w0, w1, { b0, b1, b2, b3, b4, b5, b6, b7 } }
#else
#include <uuid/uuid.h>
#define DEFINE_GUID(name, dw, w0, w1, b0, b1, b2, b3, b4, b5, b6, b7) UUID_DEFINE(name, dw & 0xff, (dw >> 8) & 0xff, (dw >> 16) & 0xff, (dw >> 24) & 0xff, w0 & 0xff, (w0 >> 8) & 0xff, w1 & 0xff, (w1 >> 8) & 0xff, b0, b1, b2, b3, b4, b5, b6, b7)
#define DEFINE_GUID_INFUNC DEFINE_GUID
typedef uuid_t GUID;
#endif