visual hull with indexes

This commit is contained in:
Peter Hachenberger 2008-07-14 18:52:08 +00:00
parent 6388e9579f
commit ece33a9fe5
1 changed files with 82 additions and 6 deletions

View File

@ -7,6 +7,7 @@
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
#include <CGAL/Modifier_base.h>
#include <CGAL/Nef_3/SNC_indexed_items.h>
CGAL_BEGIN_NAMESPACE
@ -22,7 +23,10 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
typedef typename SNC_structure::SM_decorator SM_decorator;
typedef typename SNC_structure::Vertex_handle Vertex_handle;
typedef typename SNC_structure::SHalfedge_handle SHalfedge_handle;
typedef typename SNC_structure::SVertex_iterator SVertex_iterator;
typedef typename SNC_structure::SHalfedge_around_sface_circulator
SHalfedge_around_sface_circulator;
typedef typename SNC_structure::Point_3 Point_3;
typedef typename SNC_structure::Plane_3 Plane_3;
typedef typename SNC_structure::Vector_3 Vector_3;
@ -35,6 +39,10 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
Plane_3 cut;
SNC_structure* sncp;
std::list<std::list<Point_3> > polygon_list;
int vbase;
int voffset;
int ebase;
int eoffset;
private:
Plane_3 find_cutoff_plane() {
@ -83,11 +91,58 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
return Plane_3();
}
void add_camera_indexes(SHalfedge_handle se) {
SHalfedge_around_sface_circulator sfc(se), send(sfc);
CGAL_For_all(sfc, send) {
sfc->source()->set_index(vbase+voffset);
++voffset;
sfc->set_index(ebase+eoffset);
sfc->twin()->set_index(ebase+eoffset+1);
eoffset+=2;
}
}
template<typename Distance>
void add_opposite_indexes(SHalfedge_handle se,
Distance spoints, bool outer) {
SHalfedge_around_sface_circulator sfc(se);
if(spoints > 0) {
sfc->source()->set_index(vbase+voffset+spoints-1);
--voffset;
} else
sfc->source()->set_index(vbase+voffset);
if(outer) {
sfc->set_index(ebase+eoffset);
sfc->twin()->set_index(ebase+eoffset+1);
} else {
sfc->set_index(ebase+eoffset+1);
sfc->twin()->set_index(ebase+eoffset);
}
--sfc;
sfc->source()->set_index(vbase);
if(spoints > 0) {
sfc->set_index(ebase+2*spoints-2);
sfc->twin()->set_index(ebase+2*spoints-1);
} else {
sfc->set_index(ebase);
sfc->twin()->set_index(ebase+1);
ebase+=2;
eoffset-=2;
}
--sfc;
++vbase;
sfc->source()->set_index(vbase+voffset);
sfc->set_index(ebase);
sfc->twin()->set_index(ebase+1);
}
public:
visual_hull_creator(Point_3 min, Point_3 max, Point_3 position,
std::list<std::list<Point_3> > p) :
room_min(min), room_max(max), c_pos(position), polygon_list(p) { }
room_min(min), room_max(max),
c_pos(position), polygon_list(p),
vbase(Index_generator::get_unique_index()),
voffset(0), ebase(vbase), eoffset(0) {}
void operator()(SNC_structure& snc) {
@ -105,12 +160,18 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
add_inner_cycle_to_camera(li->begin(), li->end());
}
for(li=polygon_list.begin(); li!=polygon_list.end(); ++li)
for(li=polygon_list.begin(); li!=polygon_list.end(); ++li) {
if(li==polygon_list.begin()) {
create_outer_cycles_opposites(li->begin(), li->end());
} else {
create_inner_cycles_opposites(li->begin(), li->end());
}
++voffset;
ebase+=2;
eoffset-=2;
}
while(Index_generator::get_unique_index() < ebase + 2);
}
template<typename Forward_iterator>
@ -124,7 +185,9 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
spoints.push_back(Sphere_point(*si-camera->point()));
}
C.add_outer_sedge_cycle(camera, spoints.begin(), spoints.end(),false);
SHalfedge_handle se =
C.add_outer_sedge_cycle(camera, spoints.begin(), spoints.end(), false);
add_camera_indexes(se);
}
template<typename Forward_iterator>
@ -158,7 +221,12 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
bool orient(CGAL::orientation(*si_prev,
*si,
*si_next,camera->point()) == CGAL::POSITIVE);
C.add_outer_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(),orient);
SHalfedge_handle se =
C.add_outer_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(), orient);
if(si == points_on_plane.begin())
add_opposite_indexes(se, points_on_plane.size(), true);
else
add_opposite_indexes(se, 0, true);
++si_prev;
if(si_prev==points_on_plane.end()) si_prev=points_on_plane.begin();
}
@ -175,7 +243,9 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
spoints.push_back(Sphere_point(*si-camera->point()));
}
C.add_inner_sedge_cycle(camera, spoints.begin(), spoints.end(),false,true);
SHalfedge_handle se =
C.add_inner_sedge_cycle(camera, spoints.begin(), spoints.end(),false,true);
add_camera_indexes(se);
}
template<typename Forward_iterator>
@ -209,7 +279,13 @@ class visual_hull_creator : public CGAL::Modifier_base<SNC_> {
bool orient(CGAL::orientation(*si_prev,
*si,
*si_next,camera->point()) == CGAL::NEGATIVE);
C.add_inner_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(),orient,false);
SHalfedge_handle se =
C.add_inner_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(),orient,false);
if(si == points_on_plane.begin())
add_opposite_indexes(se, points_on_plane.size(), false);
else
add_opposite_indexes(se, 0, false);
++si_prev;
if(si_prev==points_on_plane.end()) si_prev=points_on_plane.begin();
}