mirror of https://github.com/CGAL/cgal
Use enum in SNC_point_locator to avoid object casts
This commit is contained in:
parent
ddce635de2
commit
69562405f5
|
|
@ -230,14 +230,17 @@ public:
|
||||||
return this->shoot(ray, null_handle, mask);
|
return this->shoot(ray, null_handle, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SOLUTION { is_vertex_, is_edge_, is_facet_ };
|
||||||
|
|
||||||
virtual Object_handle shoot(const Ray_3& ray, Vertex_handle ray_source_vertex, int mask=255) const {
|
virtual Object_handle shoot(const Ray_3& ray, Vertex_handle ray_source_vertex, int mask=255) const {
|
||||||
CGAL_NEF_TIMER(rs_t.start());
|
CGAL_NEF_TIMER(rs_t.start());
|
||||||
CGAL_assertion( initialized);
|
CGAL_assertion( initialized);
|
||||||
_CGAL_NEF_TRACEN( "shooting: "<<ray);
|
_CGAL_NEF_TRACEN( "shooting: "<<ray);
|
||||||
Object_handle result;
|
|
||||||
Vertex_handle v;
|
SOLUTION solution;
|
||||||
Halfedge_handle e;
|
Vertex_handle v_res;
|
||||||
Halffacet_handle f;
|
Halfedge_handle e_res;
|
||||||
|
Halffacet_handle f_res;
|
||||||
bool hit = false;
|
bool hit = false;
|
||||||
Point_3 eor = CGAL::ORIGIN; // 'end of ray', the latest ray's hit point
|
Point_3 eor = CGAL::ORIGIN; // 'end of ray', the latest ray's hit point
|
||||||
|
|
||||||
|
|
@ -258,7 +261,8 @@ public:
|
||||||
if( hit && !Segment_3( ray.source(), eor).has_on(v->point()))
|
if( hit && !Segment_3( ray.source(), eor).has_on(v->point()))
|
||||||
continue;
|
continue;
|
||||||
eor = v->point();
|
eor = v->point();
|
||||||
result = make_object(v);
|
v_res = v;
|
||||||
|
solution = is_vertex_;
|
||||||
hit = true;
|
hit = true;
|
||||||
_CGAL_NEF_TRACEN("the vertex becomes the new hit object");
|
_CGAL_NEF_TRACEN("the vertex becomes the new hit object");
|
||||||
}
|
}
|
||||||
|
|
@ -283,7 +287,8 @@ public:
|
||||||
if( !candidate_provider->is_point_in_node( q, n))
|
if( !candidate_provider->is_point_in_node( q, n))
|
||||||
continue;
|
continue;
|
||||||
eor = q;
|
eor = q;
|
||||||
result = make_object(e);
|
e_res = e;
|
||||||
|
solution = is_edge_;
|
||||||
hit = true;
|
hit = true;
|
||||||
_CGAL_NEF_TRACEN("the edge becomes the new hit object");
|
_CGAL_NEF_TRACEN("the edge becomes the new hit object");
|
||||||
}
|
}
|
||||||
|
|
@ -307,7 +312,8 @@ public:
|
||||||
if( !candidate_provider->is_point_in_node( q, n))
|
if( !candidate_provider->is_point_in_node( q, n))
|
||||||
continue;
|
continue;
|
||||||
eor = q;
|
eor = q;
|
||||||
result = make_object(f);
|
f_res = f;
|
||||||
|
solution = is_facet_;
|
||||||
hit = true;
|
hit = true;
|
||||||
_CGAL_NEF_TRACEN("the facet becomes the new hit object");
|
_CGAL_NEF_TRACEN("the facet becomes the new hit object");
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +324,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_NEF_TIMER(rs_t.stop());
|
CGAL_NEF_TIMER(rs_t.stop());
|
||||||
return result;
|
switch (solution) {
|
||||||
|
case is_vertex_: return make_object(v_res);
|
||||||
|
case is_edge_: return make_object(e_res);
|
||||||
|
case is_facet_: return make_object(f_res);
|
||||||
|
}
|
||||||
|
return Object_handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Object_handle locate( const Point_3& p) const {
|
virtual Object_handle locate( const Point_3& p) const {
|
||||||
|
|
@ -360,7 +371,7 @@ public:
|
||||||
|
|
||||||
CGAL_assertion( initialized);
|
CGAL_assertion( initialized);
|
||||||
_CGAL_NEF_TRACEN( "locate "<<p);
|
_CGAL_NEF_TRACEN( "locate "<<p);
|
||||||
Object_handle result;
|
SOLUTION solution;
|
||||||
|
|
||||||
Node_handle n = candidate_provider->locate_node_containing(p);
|
Node_handle n = candidate_provider->locate_node_containing(p);
|
||||||
typename Vertex_list::const_iterator vi = n->vertices_begin();
|
typename Vertex_list::const_iterator vi = n->vertices_begin();
|
||||||
|
|
@ -388,7 +399,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
v = closest;
|
v = closest;
|
||||||
result = make_object(v);
|
Vertex_handle v_res;
|
||||||
|
Halfedge_handle e_res;
|
||||||
|
Halffacet_handle f_res;
|
||||||
|
v_res = v;
|
||||||
|
solution = is_vertex_;
|
||||||
|
|
||||||
Segment_3 s(p,v->point());
|
Segment_3 s(p,v->point());
|
||||||
Point_3 ip;
|
Point_3 ip;
|
||||||
|
|
@ -404,7 +419,8 @@ public:
|
||||||
}
|
}
|
||||||
if((e->source() != v) && (e->twin()->source() != v) && SNC_intersection::does_intersect_internally(s, ss, ip)) {
|
if((e->source() != v) && (e->twin()->source() != v) && SNC_intersection::does_intersect_internally(s, ss, ip)) {
|
||||||
s = Segment_3(p, normalized(ip));
|
s = Segment_3(p, normalized(ip));
|
||||||
result = make_object(e);
|
e_res = e;
|
||||||
|
solution = is_edge_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,15 +450,16 @@ public:
|
||||||
|
|
||||||
if( (! v_vertex_of_f) && SNC_intersection::does_intersect_internally(s,f,ip) ) {
|
if( (! v_vertex_of_f) && SNC_intersection::does_intersect_internally(s,f,ip) ) {
|
||||||
s = Segment_3(p, normalized(ip));
|
s = Segment_3(p, normalized(ip));
|
||||||
result = make_object(f);
|
f_res = f;
|
||||||
|
solution = is_facet_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( CGAL::assign( v, result)) {
|
if( solution == is_vertex_) {
|
||||||
_CGAL_NEF_TRACEN("vertex hit, obtaining volume..." << v->point());
|
_CGAL_NEF_TRACEN("vertex hit, obtaining volume..." << v_res->point());
|
||||||
|
|
||||||
//CGAL_warning("altered code in SNC_point_locator");
|
//CGAL_warning("altered code in SNC_point_locator");
|
||||||
SM_point_locator L(&*v);
|
SM_point_locator L(&*v_res);
|
||||||
Object_handle so = L.locate(s.source()-s.target(), true);
|
Object_handle so = L.locate(s.source()-s.target(), true);
|
||||||
SFace_handle sf;
|
SFace_handle sf;
|
||||||
if(CGAL::assign(sf,so))
|
if(CGAL::assign(sf,so))
|
||||||
|
|
@ -450,16 +467,16 @@ public:
|
||||||
CGAL_error_msg( "wrong handle type");
|
CGAL_error_msg( "wrong handle type");
|
||||||
return Object_handle();
|
return Object_handle();
|
||||||
|
|
||||||
} else if( CGAL::assign( f, result)) {
|
} else if( solution == is_facet_) {
|
||||||
_CGAL_NEF_TRACEN("facet hit, obtaining volume...");
|
_CGAL_NEF_TRACEN("facet hit, obtaining volume...");
|
||||||
if(f->plane().oriented_side(p) == ON_NEGATIVE_SIDE)
|
if(f_res->plane().oriented_side(p) == ON_NEGATIVE_SIDE)
|
||||||
f = f->twin();
|
f_res = f_res->twin();
|
||||||
return make_object(f->incident_volume());
|
return make_object(f_res->incident_volume());
|
||||||
} else if( CGAL::assign(e, result)) {
|
} else if( solution == is_edge_) {
|
||||||
SM_decorator SD(&*e->source());
|
SM_decorator SD(&*e_res->source());
|
||||||
if( SD.is_isolated(e))
|
if( SD.is_isolated(e_res))
|
||||||
return make_object(e->incident_sface()->volume());
|
return make_object(e_res->incident_sface()->volume());
|
||||||
return make_object(get_visible_facet(e,Ray_3(s.source(),s.to_vector()))->incident_volume());
|
return make_object(get_visible_facet(e_res,Ray_3(s.source(),s.to_vector()))->incident_volume());
|
||||||
}
|
}
|
||||||
CGAL_error_msg( "wrong handle type");
|
CGAL_error_msg( "wrong handle type");
|
||||||
return Object_handle();
|
return Object_handle();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue