new removal working

This commit is contained in:
Daniel Russel 2007-08-08 22:51:59 +00:00
parent 393fb82dab
commit 0f1020ac47
5 changed files with 103 additions and 209 deletions

View File

@ -14,7 +14,7 @@
#include <boost/utility.hpp>
#include <map>
#include <set>
#include <boost/array.hpp>
//#include <boost/array.hpp>
#include <boost/foreach.hpp>
CGAL_AOS3_BEGIN_INTERNAL_NAMESPACE
@ -320,7 +320,7 @@ public:
hc->set_face(inf_);
hc->vertex()->set_halfedge(hc);
hc=hc->next();
} while (hc != h1->next());
} while (hc != inside);
} else {
h1->opposite()->vertex()->set_halfedge(Halfedge_handle());
}
@ -341,6 +341,8 @@ public:
}
void delete_component(Vertex_handle vh) {
std::cout << "Deleting component from ";
write(vh, std::cout) << std::endl;
--num_components_;
std::vector<Vertex_handle> stack;
std::set<Vertex_handle, Handle_compare> vertices;
@ -352,7 +354,7 @@ public:
Vertex_handle vhc= stack.back();
stack.pop_back();
if (vhc->halfedge() != Halfedge_handle()) {
Halfedge_handle h= vhc->halfedge();
Halfedge_handle h= vhc->halfedge()->opposite();
do {
if (edges.find(h) == edges.end()
&& edges.find(h->opposite()) == edges.end() ) {
@ -362,21 +364,25 @@ public:
vertices.insert(h->vertex());
stack.push_back(h->vertex());
}
if (faces.find(h->face()) == faces.end()) {
if (faces.find(h->face()) == faces.end() && h->face() != inf_) {
faces.insert(h->face());
}
h=h->next()->opposite();
} while (h != vhc->halfedge());
h=h->opposite()->next();
} while (h != vhc->halfedge()->opposite());
}
} while (!stack.empty());
// hds_.vertices_erase(_1)
std::cout << "Deleting: \n";
BOOST_FOREACH(Vertex_handle v, vertices) {
hds_.vertices_erase(v);
write(v, std::cout) << std::endl;
hds_.vertices_erase(v);
}
BOOST_FOREACH(Halfedge_handle h, edges){
write(h, std::cout) << std::endl;
hds_.edges_erase(h);
}
BOOST_FOREACH(Face_handle f, faces){
write(f, std::cout) << std::endl;
hds_.faces_erase(f);
}
write(std::cout);
@ -390,6 +396,11 @@ public:
}
void delete_circle(Vertex_handle v) {
halfedges_[v->point().key().input_index()]=Halfedge_handle();
delete_component(v);
}
void audit(bool extra_vertices=false) const ;
@ -426,10 +437,10 @@ public:
Halfedge_handle a_halfedge(Curve::Key k) const;
// a halfedge on the rule pointing to the extremal vertex
Halfedge_handle rule_halfedge(Curve::Key k, Rule_direction i) const;
// Halfedge_handle rule_halfedge(Curve::Key k, Rule_direction i) const;
// a halfedge on the circle pointing to the extremal vertex (inside)
Halfedge_handle extremum_halfedge(Curve::Key k, Rule_direction i) const;
//Halfedge_handle extremum_halfedge(Curve::Key k, Rule_direction i) const;
// insert the vertex so that h->opposite points to it
Halfedge_handle insert_vertex( Point p, Halfedge_handle h);
@ -449,15 +460,15 @@ public:
typedef boost::array<Halfedge_handle, 4> Halfedge_quad;
//typedef boost::array<Halfedge_handle, 4> Halfedge_quad;
const Halfedge_quad& halfedges(CGAL_AOS3_TYPENAME Curve::Key k) const {
/*const Halfedge_handle halfedges(CGAL_AOS3_TYPENAME Curve::Key k) const {
return halfedges_[k.input_index()];
}
Halfedge_quad& halfedges(CGAL_AOS3_TYPENAME Curve::Key k) {
return halfedges_[k.input_index()];
}
}*/
void set_number_of_spheres(unsigned int i) {
CGAL_assertion(halfedges_.size() <=i);
halfedges_.resize(i);
@ -473,7 +484,7 @@ private:
//void new_target(Curve::Key k, Halfedge_handle tar[]);
void set_extremum_halfedge(Halfedge_handle h);
void set_halfedge(Halfedge_handle h);
/*Halfedge_handle split_face(Halfedge_handle o, Halfedge_handle d,
@ -538,7 +549,7 @@ private:
Face_handle inf_;
mutable std::vector<Curve> errors_;
//std::vector<Vertex_handle> targets_;
std::vector<Halfedge_quad> halfedges_;
std::vector<Halfedge_handle> halfedges_;
int num_components_;
// for new_face when constructing things

View File

@ -32,45 +32,17 @@ Combinatorial_cross_section CGAL_AOS3_TARG::hds() {
CGAL_AOS3_TEMPLATE
CGAL_AOS3_TYPENAME Combinatorial_cross_section CGAL_AOS3_TARG::Halfedge_handle
Combinatorial_cross_section CGAL_AOS3_TARG::a_halfedge(Curve::Key k) const {
CGAL_precondition(halfedges_[k.input_index()][0]== Halfedge_handle()
|| halfedges_[k.input_index()][0]->curve().is_inside());
return halfedges_[k.input_index()][0];
CGAL_precondition(halfedges_[k.input_index()]== Halfedge_handle()
|| halfedges_[k.input_index()]->curve().is_inside()
&& halfedges_[k.input_index()]->curve().key() == k);
return halfedges_[k.input_index()];
}
CGAL_AOS3_TEMPLATE
CGAL_AOS3_TYPENAME Combinatorial_cross_section CGAL_AOS3_TARG::Halfedge_handle
Combinatorial_cross_section CGAL_AOS3_TARG::rule_halfedge(Curve::Key k, Rule_direction i) const {
Halfedge_handle h= halfedges_[k.input_index()][i.index()]->opposite()->prev();
CGAL_assertion(h->vertex()->point().is_sphere_extremum());
CGAL_assertion(h->curve().key() == k);
CGAL_assertion(h->curve().is_rule());
return h;
}
CGAL_AOS3_TEMPLATE
CGAL_AOS3_TYPENAME Combinatorial_cross_section CGAL_AOS3_TARG::Halfedge_handle
Combinatorial_cross_section CGAL_AOS3_TARG::extremum_halfedge(Curve::Key k, Rule_direction i) const {
Halfedge_handle h= halfedges_[k.input_index()][i.index()];
CGAL_assertion(h->vertex()->point().is_sphere_extremum());
CGAL_assertion(h->curve().key() == k);
CGAL_assertion(!h->curve().is_rule());
return h;
}
CGAL_AOS3_TEMPLATE
void
Combinatorial_cross_section CGAL_AOS3_TARG::set_extremum_halfedge(Halfedge_handle h){
Curve::Key k= h->curve().key();
Rule_direction i= h->vertex()->point().sphere_extremum_index();
std::cout << "Setting extremum for " << k << "(" << k.input_index() <<") dir " << i
<< " to ";
write(h, std::cout) << std::endl;
//CGAL_precondition(h->curve().key() ==k);
CGAL_precondition(h->curve().is_arc());
CGAL_precondition(h->vertex()->point().is_sphere_extremum());
CGAL_precondition(h->opposite()->prev()->curve().is_rule());
halfedges_[k.input_index()][i.index()] = h;
Combinatorial_cross_section CGAL_AOS3_TARG::set_halfedge(Halfedge_handle h){
halfedges_[h->curve().key().input_index()] = h;
}
CGAL_AOS3_TEMPLATE
@ -78,7 +50,7 @@ CGAL_AOS3_TYPENAME Combinatorial_cross_section CGAL_AOS3_TARG::Halfedge_handle
Combinatorial_cross_section CGAL_AOS3_TARG::next_edge_on_rule(Halfedge_handle h) const {
CGAL_precondition(h->curve().is_rule());
if (!h->vertex()->point().is_rule_rule()) return Halfedge_handle();
int deg = degree(h->vertex());
//int deg = degree(h->vertex());
Halfedge_handle r= h->next();
do {
if (r->curve().constant_coordinate() == h->curve().constant_coordinate()) {
@ -214,7 +186,7 @@ Combinatorial_cross_section CGAL_AOS3_TARG::remove_vertex(Halfedge_handle h) {
write(nh->opposite(), std::cout) << std::endl;
if (nh->opposite()->vertex()->point().is_sphere_extremum()
&& nh->curve().is_arc() && !nh->curve().is_inside()) {
set_extremum_halfedge(nh->opposite());
halfedges_[nh->curve().key().input_index()] =(nh->opposite());
}
h->set_vertex(Vertex_handle());
delete_edge(h);
@ -390,7 +362,7 @@ Combinatorial_cross_section CGAL_AOS3_TARG::insert_vertex_in_edge_unsafe(Halfedg
if (k->curve().is_arc() && k->vertex()->point().is_sphere_extremum()
&& k->curve().is_inside()) {
set_extremum_halfedge(k);
halfedges_[k->curve().key().input_index()]= k;
std::cout << "Updated sphere halfedge to ";
write(k, std::cout) << std::endl;
} else {
@ -485,6 +457,9 @@ Combinatorial_cross_section CGAL_AOS3_TARG::unpinch_bl(Halfedge_handle a, Halfed
CGAL_AOS3_TEMPLATE
void Combinatorial_cross_section CGAL_AOS3_TARG::connect(Halfedge_handle a, Halfedge_handle b) {
std::cout << "connecting ";
write(a, std::cout) << " to ";
write(b, std::cout) << std::endl;
a->set_next(b);
b->set_prev(a);
}
@ -514,11 +489,9 @@ Combinatorial_cross_section CGAL_AOS3_TARG::new_circle(Curve::Key k,
vs[2]=new_halfedge(Curve(k, Curve::LB_ARC));
vs[3]=new_halfedge(Curve(k, Curve::RB_ARC));
halfedges_[k.index()][0]= vs[3]->opposite();
halfedges_[k.index()][1]= vs[0]->opposite();
halfedges_[k.index()][2]= vs[1]->opposite();
halfedges_[k.index()][3]= vs[2]->opposite();
if (halfedges_.size() <=static_cast<unsigned int>(k.input_index())) halfedges_.resize(k.input_index()+1);
halfedges_[k.input_index()]=vs[3]->opposite();
Halfedge_handle ivs[4];
for (unsigned int i=0; i< 4; ++i) {
vs[i]->set_vertex(vhs[i]);
@ -823,11 +796,8 @@ Combinatorial_cross_section CGAL_AOS3_TARG::remove_target(Halfedge_handle ts[4],
hds_.edges_erase(ts[i]);
}
}*/
halfedges_[k.input_index()][0]= Halfedge_handle();
halfedges_[k.input_index()][1]= Halfedge_handle();
halfedges_[k.input_index()][2]= Halfedge_handle();
halfedges_[k.input_index()][3]= Halfedge_handle();
halfedges_[k.input_index()]= Halfedge_handle();
return f;
}
@ -1109,25 +1079,21 @@ void Combinatorial_cross_section CGAL_AOS3_TARG::audit(bool extra_vertices) cons
std::cout << "Auditing halfedge map..." << std::flush;
//CGAL_assertion(halfedges_.size() == t_.number_of_spheres());
for (unsigned int i=0; i< halfedges_.size(); ++i){
for (unsigned int j=0; j<4; ++j) {
if (halfedges_[i][0] != Halfedge_handle()) {
CGAL_assertion(halfedges_[i][j]->curve().key() == Curve::Key(i));
CGAL_assertion(halfedges_[i][j]->curve().is_inside());
CGAL_assertion(halfedges_[i][j]->vertex()->point().is_sphere_extremum());
CGAL_assertion(halfedges_[i][j]->vertex()->point().sphere_extremum_index()==Rule_direction(j));
if (!halfedges_[i][j]->opposite()->prev()->curve().is_rule()) {
std::cerr << "Error in sphere halfedge for " << i << " at " << j
<< " have ";
write(halfedges_[i][j], std::cerr) << " not rule is ";
write(halfedges_[i][j]->opposite()->prev(), std::cerr)
<< std::endl;
CGAL_assertion(halfedges_[i][j]->opposite()->prev()->curve().is_rule());
}
//CGAL_assertion(halfedges_[i][j]->opposite()->prev()->curve().key()==T::Key(i));
} else {
CGAL_assertion(halfedges_[i][j] == Halfedge_handle());
if (halfedges_[i] != Halfedge_handle()) {
CGAL_assertion(halfedges_[i]->curve().key() == Curve::Key(i));
CGAL_assertion(halfedges_[i]->curve().is_inside());
CGAL_assertion(halfedges_[i]->vertex()->point().is_sphere_extremum());
if (!halfedges_[i]->opposite()->prev()->curve().is_rule()) {
std::cerr << "Error in sphere halfedge for " << i
<< " have ";
write(halfedges_[i], std::cerr) << " not rule is ";
write(halfedges_[i]->opposite()->prev(), std::cerr)
<< std::endl;
CGAL_assertion(halfedges_[i]->opposite()->prev()->curve().is_rule());
}
}
//CGAL_assertion(halfedges_[i][j]->opposite()->prev()->curve().key()==T::Key(i));
}
}
for (Halfedge_const_iterator vit= halfedges_begin();
@ -1135,7 +1101,7 @@ void Combinatorial_cross_section CGAL_AOS3_TARG::audit(bool extra_vertices) cons
if (vit->curve().key() != Curve::Key::target_key()) {
if (vit->curve().is_arc()) {
Curve::Key k= vit->curve().key();
CGAL_assertion(halfedges_[k.input_index()][0]
CGAL_assertion(halfedges_[k.input_index()]
!= Halfedge_handle());
}
}
@ -1407,11 +1373,9 @@ void Combinatorial_cross_section CGAL_AOS3_TARG::set_curve(Halfedge_handle h, Cu
CGAL_AOS3_TEMPLATE
void Combinatorial_cross_section CGAL_AOS3_TARG::delete_edge(Halfedge_handle h) {
#ifndef NDEBUG
for (unsigned int i=0; i< halfedges_.size(); ++i) {
for (unsigned int j=0; j< 4; ++j) {
CGAL_assertion(halfedges_[i][j]!=h);
CGAL_assertion(halfedges_[i][j]!=h->opposite());
}
if (h->curve().key().is_input()) {
CGAL_assertion(halfedges_[h->curve().key().input_index()]!=h);
CGAL_assertion(halfedges_[h->curve().key().input_index()]!=h->opposite());
}
h->curve() = Curve();
h->opposite()->curve() = Curve();

View File

@ -80,8 +80,8 @@ void Cross_section_initializer CGAL_AOS3_TARG::operator()(CGAL_AOS3_TYPENAME Tra
&& it->curve().is_inside()) {
CGAL_AOS3_TYPENAME CS::Halfedge_handle fit= cs_.next_edge_on_curve(it);
if (fit->curve() != it->curve()) {
int ai= (it->curve().arc_index()+1)%4;
cs_.halfedges(it->curve().key())[ai]=it;
//int ai= (it->curve().arc_index()+1)%4;
cs_.halfedges_[it->curve().key().input_index()]=it;
}
}
}

View File

@ -428,23 +428,31 @@ protected:
}
void clean_up_vertex(const CGAL_AOS3_TYPENAME Traits::Event_point_3 &,
void clean_up_vertex(const CGAL_AOS3_TYPENAME Traits::Event_point_3 &t,
CGAL_AOS3_TYPENAME CS::Vertex_handle vh) {
if (cs_.is_redundant(vh)) {
cs_.remove_vertex(vh->halfedge());
}
if (vh->point().is_sphere_extremum()) {
CGAL_AOS3_TYPENAME Traits::Sphere_3_key k= vh->point().sphere_key();
CGAL_AOS3_TYPENAME CS::Halfedge_handle rule, c= vh->halfedge();
CGAL_AOS3_TYPENAME CS::Halfedge_handle rule, arc, c= vh->halfedge();
do {
if (c->curve().is_rule() && c->curve().key() == k) {
rule= c;
break;
}
if (!c->curve().is_rule()) {
arc= c;
}
c= c->next()->opposite();
} while (c != vh->halfedge());
if (rule == CGAL_AOS3_TYPENAME CS::Halfedge_handle()) {
CGAL_assertion(0);
if (arc->curve().is_inside()) arc=arc->opposite();
CGAL_AOS3_TYPENAME CS::Curve rule= CS::Curve::make_rule(arc->curve().key(),
vh->point().sphere_extremum_index());
CGAL_AOS3_TYPENAME CS::Halfedge_handle ovh
= find_rule_vertex(t, arc->face(),
rule);
cs_.split_face(rule, cs_.find_halfedge(vh, arc->face()), ovh);
}
}

View File

@ -13,9 +13,9 @@ class Irrational_cross_section_removal: public Irrational_cross_section CGAL_AOS
typedef Irrational_cross_section_removal CGAL_AOS3_TARG This;
typedef Irrational_cross_section CGAL_AOS3_TARG P;
typedef Combinatorial_cross_section CGAL_AOS3_TARG CS;
//typedef Cross_section_events CGAL_AOS3_TARG CSE;
//typedef CGAL_AOS3_TYPENAME CS::Halfedge_handle Halfedge_handle;
//typedef CGAL_AOS3_TYPENAME CS::Face_handle Face_handle;
// typedef Cross_section_events CGAL_AOS3_TARG CSE;
// typedef CGAL_AOS3_TYPENAME CS::Halfedge_handle Halfedge_handle;
// typedef CGAL_AOS3_TYPENAME CS::Face_handle Face_handle;
public:
@ -26,126 +26,37 @@ public:
P::cs_.audit();
//T::Key k= f->halfedge()->curve().key();
CGAL_AOS3_TYPENAME CS::Face_handle f;
f= P::cs_.a_halfedge(k)->face();
// check correctness of f
CGAL_AOS3_TYPENAME CS::Halfedge_handle rules[4];
CGAL_AOS3_TYPENAME CS::Halfedge_handle h=f->halfedge();
int deg=0;
do {
++deg;
CGAL_assertion(h->curve().key()==k);
CGAL_assertion(h->curve().is_arc());
CGAL_assertion(h->curve().is_inside());
/*Halfedge_handle rule= h->opposite()->next();
int index= rule->curve().rule_index();*/
/*CGAL_assertion(rules[index]
== Halfedge_handle());
rules[index] =rule;*/
h= h->next();
} while (h != f->halfedge());
CGAL_assertion(deg==4);
CGAL_AOS3_TYPENAME CS::Vertex_handle vertices[4];
{
CGAL_AOS3_TYPENAME CS::Halfedge_handle h=P::cs_.a_halfedge(k);
int deg=0;
do {
++deg;
CGAL_assertion(h->vertex()->point().is_sphere_extremum());
int i= h->vertex()->point().sphere_extremum_index().index();
rules[i]= h->opposite()->prev()->opposite();
P::roll_back_rule(P::tr_.sphere_events(k).second, rules[i]);
vertices[i]= h->opposite()->prev()->opposite()->vertex();
P::cs_.write(vertices[i], std::cout) << " is vertex " << i << std::endl;
h= h->next();
} while (h != P::cs_.a_halfedge(k));
CGAL_assertion(deg==4);
}
// roll in each until I have a target in a face
CGAL_AOS3_TYPENAME Traits::Sphere_3_key keys[4];
//Halfedge_handle vs[4];
for (unsigned int i=0; i< 4; ++i){
rules[i]= P::cs_.rule_halfedge(k,Rule_direction(i))->opposite();
//keys[i]= P::roll_back_rule(tr_.sphere_events(k).second, rules[i]);
/*if (keys[i].is_valid()) {
vs[i]= rules[i]->opposite()->prev();
CGAL_assertion(vs[i]->vertex() == rules[i]->vertex());
}*/
//P::cse_.clean_edge(rules[i]);
}
//Qt_examiner_viewer_2 *qt= new Qt_examiner_viewer_2();
//*qt_debug_examiner_viewer_2__ << Layer(0);
//draw_rz(qt_debug_examiner_viewer_2__, CGAL::to_double(sim_->current_time()) + .1);
//qt_debug_examiner_viewer_2__->show_everything();
//qt_debug_examiner_viewer_2__->show();
//*qt_debug_examiner_viewer_2__ << std::flush;
for (unsigned int i=0; i< 4; ++i){
CGAL_AOS3_TYPENAME CS::Halfedge_handle hi= P::cs_.rule_halfedge(k,
CGAL_AOS3_TYPENAME CS::Rule_direction(i))->next();
/*if (sds_.event(hi) != Event_key()) {
std::cerr << "ERROR " << sds_.event(hi)
<< " on edge ";
sds_.write(hi, std::cerr);
std::cerr << std::endl;
}*/
//P::cse_.clean_edge(hi->opposite()->prev());
CGAL_AOS3_TYPENAME CS::Vertex_handle iv= rules[0]->opposite()->vertex();
CGAL_AOS3_TYPENAME CS::Face_handle f= P::cs_.snip_out(rules, rules+4);
P::cs_.delete_circle(iv);
for (unsigned int i=0; i< 4; ++i) {
P::clean_up_vertex(P::tr_.sphere_events(k).second, vertices[i]);
}
//P::cse_.check_merged_faces(P::cs_.rule_halfedge(k, Rule_direction(0))->face(),
//P::cs_.rule_halfedge(k, Rule_direction(2))->face());
//P::cse_.check_merged_faces(P::cs_.rule_halfedge(k, Rule_direction(1))->face(),
// P::cs_.rule_halfedge(k, Rule_direction(3))->face());
//return Face_handle();
CGAL_AOS3_TYPENAME CS::Halfedge_handle vertices[4];
// HERE
//CGAL_AOS3_TYPENAME CS::Face_handle fr= P::cs_.remove_target(rules, vertices);
// I guess I don't actually have to extend the rules any more
// it doesn't make anything invalid and makes the structure simpler.
// Unless there is only halfedge between the two circles
bool has_split=false;
for (unsigned int i=0; i< 4; ++i){
if (keys[i].is_valid()) {
Rule_direction rd((i+2)%4);
CGAL_AOS3_TYPENAME CS::Curve c=CGAL_AOS3_TYPENAME CS::Curve::make_rule(keys[i], rd);
//CGAL_assertion(vertices[i]->vertex()->point().is_sphere_rule());
CGAL_AOS3_TYPENAME CS::Halfedge_handle hv;
if (!has_split) {
CGAL_assertion(vertices[rd.index()] != CGAL_AOS3_TYPENAME CS::Halfedge_handle());
std::cout << "using orphaned extremum "
<< vertices[i]->vertex()->point()
<< " " << vertices[rd.index()]->vertex()->point() << std::endl;
// I need to handle this
hv= vertices[rd.index()];
//vertices[(i+2)%4]=Halfedge_handle();
keys[rd.index()]= CGAL_AOS3_TYPENAME Traits::Sphere_3_key();
has_split=true;
} else {
std::cout << "Fixing orphaned extremum "
<< vertices[i]->vertex()->point() << std::endl;
// I need to handle this
// I could just insert it in the new edge since I know it goes there
hv= P::find_rule_vertex(P::tr_.sphere_events(k).second, vertices[i]->face(),c);
//vertices[i]->vertex()->point().replace_rule(c);
}
CGAL_AOS3_TYPENAME CS::Halfedge_handle nh;
if (i==0 || i == 3) {
nh=cs_.split_face(c, hv,vertices[i]);
} else {
nh=cs_.split_face(c, vertices[i], hv);
}
//cse_.check_edge_collapse(nh);
}
}
for (unsigned int i=0; i< 4; ++i){
/*if (P::cse_.check_remove_vertex(vertices[i]) != vertices[i]) {
if (P::cs_.is_redundant(h->vertex())
|| P::cs_.is_redundant(h->opposite()->vertex())) {
// skipping since it is adjacent to another vertex which will be removed
// seems like there should be a better way
std::cout << "Skipping ephemeral edge ";
P::cs_.write(h, std::cout);
std::cout << std::endl;
} else {
//P::cse_.check_edge_collapse(h);
}
}*/
}
//P::cse_.check_reduced_face(fr);
//audit();
return f;
}