revert r52901-52902 (moving predicate from AABB_tree to Intersections_3)

This commit is contained in:
Stéphane Tayeb 2009-11-10 16:57:37 +00:00
parent 112a16d947
commit 12d4519a2b
16 changed files with 0 additions and 2895 deletions

1
.gitattributes vendored
View File

@ -1336,7 +1336,6 @@ Interpolation/doc_tex/Interpolation/nn_coords.ipe -text svneol=unset#application
Interpolation/doc_tex/Interpolation/nn_coords.pdf -text svneol=unset#application/pdf
Interpolation/doc_tex/Interpolation/nn_coords.xml svneol=native#text/xml
Intersections_2/include/CGAL/Circle_2_Line_2_intersection.h -text
Intersections_3/include/CGAL/Triangle_3_line_3_intersection.h -text
Interval_skip_list/doc_tex/Interval_skip_list/query.png -text
Interval_skip_list/examples/Interval_skip_list/isl_terrain.pts -text
Jet_fitting_3/clean_tree.csh eol=lf

View File

@ -1,39 +0,0 @@
// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland).
// Copyright (c) 2009 GeometryFactory (France)
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Laurent Rineau, Camille Wormser, Jane Tournois, Pierre Alliez
#ifndef CGAL_BBOX_3_BBOX_3_DO_INTERSECT_H
#define CGAL_BBOX_3_BBOX_3_DO_INTERSECT_H
// Turn off Visual C++ warning
#ifdef _MSC_VER
#pragma warning ( disable : 4003 )
#endif
CGAL_BEGIN_NAMESPACE
bool do_intersect(const CGAL::Bbox_3& c,
const CGAL::Bbox_3& bbox)
{
return CGAL::do_overlap(c, bbox);
}
CGAL_END_NAMESPACE
#endif // CGAL_BBOX_3_BBOX_3_DO_INTERSECT_H

View File

@ -1,149 +0,0 @@
// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez
#ifndef CGAL_BBOX_3_LINE_3_DO_INTERSECT_H
#define CGAL_BBOX_3_LINE_3_DO_INTERSECT_H
#include <CGAL/Line_3.h>
#include <CGAL/Bbox_3.h>
// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf
CGAL_BEGIN_NAMESPACE
namespace internal {
template <class K>
bool do_intersect(const typename K::Line_3& line,
const CGAL::Bbox_3& bbox,
const K&)
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector;
const Point source = line.point(0);
Point parameters[2];
parameters[0] = Point(bbox.xmin(), bbox.ymin(), bbox.zmin());
parameters[1] = Point(bbox.xmax(), bbox.ymax(), bbox.zmax());
const Vector direction = line.to_vector();
// We don't care about values
FT tmin(0.0);
FT tmax(0.0);
bool is_dx_null = false;
bool is_dy_null = false;
if ( ! CGAL_NTS is_zero(direction.x()) )
{
FT inv_direction_x = FT(1)/direction.x();
const int sign_x = inv_direction_x < FT(0);
tmin = (parameters[sign_x].x() - source.x()) * inv_direction_x;
tmax = (parameters[1-sign_x].x() - source.x()) * inv_direction_x;
}
else
{
// premature exit if x value of line is outside bbox
if ( source.x() < parameters[0].x() || source.x() > parameters[1].x() )
return false;
is_dx_null = true;
}
if ( ! CGAL_NTS is_zero(direction.y()) )
{
FT inv_direction_y = FT(1)/direction.y();
const int sign_y = inv_direction_y < FT(0);
const FT tymin = (parameters[sign_y].y() - source.y()) * inv_direction_y;
const FT tymax = (parameters[1-sign_y].y() - source.y()) * inv_direction_y;
if ( !is_dx_null )
{
if(tmin > tymax || tymin > tmax)
return false;
if(tymin > tmin)
tmin = tymin;
if(tymax < tmax)
tmax = tymax;
}
else
{
tmin = tymin;
tmax = tymax;
}
}
else
{
// premature exit if y value of line is outside bbox
if ( source.y() < parameters[0].y() || source.y() > parameters[1].y() )
return false;
is_dy_null = true;
}
if ( ! CGAL_NTS is_zero(direction.z()) )
{
FT inv_direction_z = FT(1)/direction.z();
const int sign_z = inv_direction_z < FT(0);
FT tzmin = (parameters[sign_z].z() - source.z()) * inv_direction_z;
FT tzmax = (parameters[1-sign_z].z() - source.z()) * inv_direction_z;
if( (!is_dx_null || !is_dy_null) && (tmin > tzmax || tzmin > tmax) )
return false;
}
else
{
// premature exit if z value of line is outside bbox
if ( source.z() < parameters[0].z() || source.z() > parameters[1].z() )
return false;
}
return true;
}
} // namespace internal
template <class K>
bool do_intersect(const CGAL::Line_3<K>& line,
const CGAL::Bbox_3& bbox)
{
return typename K::Do_intersect_3()(line, bbox);
}
template <class K>
bool do_intersect(const CGAL::Bbox_3& bbox,
const CGAL::Line_3<K>& line)
{
return typename K::Do_intersect_3()(line, bbox);
}
CGAL_END_NAMESPACE
#endif // CGAL_BBOX_3_LINE_3_DO_INTERSECT_H

View File

@ -1,101 +0,0 @@
// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez
#ifndef CGAL_BBOX_3_PLANE_3_DO_INTERSECT_H
#define CGAL_BBOX_3_PLANE_3_DO_INTERSECT_H
#include <CGAL/Plane_3.h>
#include <CGAL/Bbox_3.h>
// Opcode like
CGAL_BEGIN_NAMESPACE
namespace internal {
template <class K>
void get_min_max(const typename K::Vector_3& p,
const CGAL::Bbox_3& bbox,
typename K::Point_3& p_min,
typename K::Point_3& p_max)
{
if(p.x() > 0) {
if(p.y() > 0) {
if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin());
p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax());}
else { p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax());
p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin());}
}
else {
if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin());
p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax());}
else { p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax());
p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin());}
}
}
else {
if(p.y() > 0) {
if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin());
p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax());}
else { p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax());
p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin());}
}
else {
if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin());
p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax());}
else { p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax());
p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin());}
}
}
}
template <class K>
bool do_intersect(const typename K::Plane_3& plane,
const CGAL::Bbox_3& bbox,
const K&)
{
typename K::Point_3 p_max, p_min;
get_min_max<K>(plane.orthogonal_vector(), bbox, p_min, p_max);
return ! (plane.oriented_side(p_max) == ON_NEGATIVE_SIDE ||
plane.oriented_side(p_min) == ON_POSITIVE_SIDE);
}
} // namespace internal
template <class K>
bool do_intersect(const CGAL::Plane_3<K>& plane,
const CGAL::Bbox_3& bbox)
{
return typename K::Do_intersect_3()(plane, bbox);
}
template <class K>
bool do_intersect(const CGAL::Bbox_3& bbox,
const CGAL::Plane_3<K>& plane)
{
return typename K::Do_intersect_3()(plane, bbox);
}
CGAL_END_NAMESPACE
#endif // CGAL_BBOX_3_PLANE_3_DO_INTERSECT_H

View File

@ -1,170 +0,0 @@
// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez
#ifndef CGAL_BBOX_3_RAY_3_DO_INTERSECT_H
#define CGAL_BBOX_3_RAY_3_DO_INTERSECT_H
#include <CGAL/Ray_3.h>
// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf
CGAL_BEGIN_NAMESPACE
namespace internal {
template <class K>
bool do_intersect(const typename K::Ray_3& ray,
const CGAL::Bbox_3& bbox,
const K&)
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector;
Point parameters[2];
parameters[0] = Point(bbox.xmin(), bbox.ymin(), bbox.zmin());
parameters[1] = Point(bbox.xmax(), bbox.ymax(), bbox.zmax());
const Point source = ray.source();
if((parameters[0].x() <= source.x()) && (source.x() <= parameters[1].x()) &&
(parameters[0].y() <= source.y()) && (source.y() <= parameters[1].y()) &&
(parameters[0].z() <= source.z()) && (source.z() <= parameters[1].z()))
return true;
const Vector direction = ray.to_vector();
FT tmin(0.0);
FT tmax(0.0);
bool is_dx_null = false;
bool is_dy_null = false;
if ( ! CGAL_NTS is_zero(direction.x()) )
{
FT inv_direction_x = FT(1)/direction.x();
const int sign_x = inv_direction_x < FT(0);
tmin = (parameters[sign_x].x() - source.x()) * inv_direction_x;
tmax = (parameters[1-sign_x].x() - source.x()) * inv_direction_x;
// premature exit
if(tmax < FT(0))
return false;
if(tmin < FT(0))
tmin = FT(0);
}
else
{
// premature exit if x value of ray is outside bbox
if ( source.x() < parameters[0].x() || source.x() > parameters[1].x() )
return false;
is_dx_null = true;
}
if ( ! CGAL_NTS is_zero(direction.y()) )
{
FT inv_direction_y = FT(1)/direction.y();
const int sign_y = inv_direction_y < FT(0);
const FT tymin = (parameters[sign_y].y() - source.y()) * inv_direction_y;
const FT tymax = (parameters[1-sign_y].y() - source.y()) * inv_direction_y;
if ( !is_dx_null )
{
if(tmin > tymax || tymin > tmax)
return false;
if(tymin > tmin)
tmin = tymin;
if(tymax < tmax)
tmax = tymax;
}
else
{
if(tymax < FT(0))
return false;
tmin = tymin;
tmax = tymax;
if(tmin < FT(0))
tmin = FT(0);
}
}
else
{
// premature exit if y value of ray is outside bbox
if ( source.y() < parameters[0].y() || source.y() > parameters[1].y() )
return false;
is_dy_null = true;
}
if ( ! CGAL_NTS is_zero(direction.z()) )
{
FT inv_direction_z = FT(1)/direction.z();
const int sign_z = inv_direction_z < FT(0);
FT tzmin = (parameters[sign_z].z() - source.z()) * inv_direction_z;
FT tzmax = (parameters[1-sign_z].z() - source.z()) * inv_direction_z;
if ( !is_dx_null || !is_dy_null )
{
if (tmin > tzmax || tzmin > tmax)
return false;
}
else
{
if ( tzmax < FT(0) )
return false;
}
}
else
{
// premature exit if z value of ray is outside bbox
if ( source.z() < parameters[0].z() || source.z() > parameters[1].z() )
return false;
}
return true;
}
} // namespace internal
template <class K>
bool do_intersect(const CGAL::Ray_3<K>& ray,
const CGAL::Bbox_3& bbox)
{
return typename K::Do_intersect_3()(ray, bbox);
}
template <class K>
bool do_intersect(const CGAL::Bbox_3& bbox,
const CGAL::Ray_3<K>& ray)
{
return typename K::Do_intersect_3(ray, bbox);
}
CGAL_END_NAMESPACE
#endif // CGAL_BBOX_3_RAY_3_DO_INTERSECT_H

View File

@ -1,149 +0,0 @@
// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez
#ifndef CGAL_BBOX_3_SEGMENT_3_DO_INTERSECT_H
#define CGAL_BBOX_3_SEGMENT_3_DO_INTERSECT_H
#include <CGAL/Segment_3.h>
#include <CGAL/Bbox_3.h>
// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf
CGAL_BEGIN_NAMESPACE
namespace internal {
template <class K>
bool do_intersect(const typename K::Segment_3& segment,
const CGAL::Bbox_3& bbox,
const K&)
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector;
typedef typename K::Segment_3 Segment;
Point parameters[2];
parameters[0] = Point(bbox.xmin(), bbox.ymin(), bbox.zmin());
parameters[1] = Point(bbox.xmax(), bbox.ymax(), bbox.zmax());
const Point source = segment.source();
const Point target = segment.target();
const Vector direction = target - source;
FT tmin(0.0);
FT tmax(1.0);
if ( ! CGAL_NTS is_zero(direction.x()) )
{
FT inv_direction_x = FT(1)/direction.x();
const int sign_x = inv_direction_x < FT(0);
tmin = (parameters[sign_x].x() - source.x()) * inv_direction_x;
tmax = (parameters[1-sign_x].x() - source.x()) * inv_direction_x;
// premature exit
if(tmax < FT(0) || tmin > FT(1))
return false;
if(tmin < FT(0))
tmin = FT(0);
if(tmax > FT(1))
tmax = FT(1);
}
else
{
// premature exit if x value of segment is outside bbox
if ( source.x() < parameters[0].x() || source.x() > parameters[1].x() )
return false;
}
if ( ! CGAL_NTS is_zero(direction.y()) )
{
FT inv_direction_y = FT(1)/direction.y();
const int sign_y = inv_direction_y < FT(0);
const FT tymin = (parameters[sign_y].y() - source.y()) * inv_direction_y;
const FT tymax = (parameters[1-sign_y].y() - source.y()) * inv_direction_y;
if(tmin > tymax || tymin > tmax)
return false;
if(tymin > tmin)
tmin = tymin;
if(tymax < tmax)
tmax = tymax;
}
else
{
// premature exit if y value of segment is outside bbox
if ( source.y() < parameters[0].y() || source.y() > parameters[1].y() )
return false;
}
if ( ! CGAL_NTS is_zero(direction.z()) )
{
FT inv_direction_z = FT(1)/direction.z();
const int sign_z = inv_direction_z < FT(0);
FT tzmin = (parameters[sign_z].z() - source.z()) * inv_direction_z;
FT tzmax = (parameters[1-sign_z].z() - source.z()) * inv_direction_z;
if(tmin > tzmax || tzmin > tmax)
return false;
}
else
{
// premature exit if z value of segment is outside bbox
if ( source.z() < parameters[0].z() || source.z() > parameters[1].z() )
return false;
}
return true;
}
template <class K>
bool do_intersect(const CGAL::Bbox_3& bbox,
const typename K::Segment_3& segment,
const K& k)
{
return do_intersect(segment, bbox, k);
}
} // namespace internal
template <class K>
bool do_intersect(const CGAL::Segment_3<K>& segment,
const CGAL::Bbox_3& bbox)
{
return typename K::Do_intersect_3()(segment, bbox);
}
template <class K>
bool do_intersect(const CGAL::Bbox_3& bbox,
const CGAL::Segment_3<K>& segment)
{
return typename K::Do_intersect_3()(segment, bbox);
}
CGAL_END_NAMESPACE
#endif // CGAL_BBOX_3_SEGMENT_3_DO_INTERSECT_H

View File

@ -1,116 +0,0 @@
// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez
#ifndef CGAL_BBOX_3_SPHERE_3_DO_INTERSECT_H
#define CGAL_BBOX_3_SPHERE_3_DO_INTERSECT_H
#include <CGAL/Sphere_3.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/number_utils.h>
CGAL_BEGIN_NAMESPACE
namespace internal {
template <class K>
bool do_intersect(const typename K::Sphere_3& sphere,
const CGAL::Bbox_3& bbox,
const K&)
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point;
FT d = FT(0);
FT distance = FT(0);
Point center = sphere.center();
if(center.x() < (FT)bbox.xmin())
{
d = (FT)bbox.xmin() - center.x();
distance += d * d;
}
else if(center.x() > (FT)bbox.xmax())
{
d = center.x() - (FT)bbox.xmax();
distance += d * d;
}
if(center.y() < (FT)bbox.ymin())
{
d = (FT)bbox.ymin() - center.y();
distance += d * d;
}
else if(center.y() > (FT)bbox.ymax())
{
d = center.y() - (FT)bbox.ymax();
distance += d * d;
}
if(center.z() < (FT)bbox.zmin())
{
d = (FT)bbox.zmin() - center.z();
distance += d * d;
}
else if(center.z() > (FT)bbox.zmax())
{
d = center.z() - (FT)bbox.zmax();
distance += d * d;
}
// For unknown reason this causes a syntax error on VC2005
// but compiles fine on Linux and MAC
//int i;
//for(i = 0; i < 3; ++i)
//{
// if(center[i] < (FT)bbox.min(i))
// {
// d = (FT)bbox.min(i) - center[i];
// distance += d * d;
// }
// else if(center[i] > (FT)bbox.max(i))
// {
// d = center[i] - (FT)bbox.max(i);
// distance += d * d;
// }
//}
return distance <= sphere.squared_radius();
}
} // namespace internal
template <class K>
bool do_intersect(const CGAL::Sphere_3<K>& sphere,
const CGAL::Bbox_3& bbox)
{
return typename K::Do_intersect_3()(sphere, bbox);
}
template <class K>
bool do_intersect(const CGAL::Bbox_3& bbox,
const CGAL::Sphere_3<K>& sphere)
{
return typename K::Do_intersect_3()(sphere, bbox);
}
CGAL_END_NAMESPACE
#endif // CGAL_BBOX_3_SPHERE_3_DO_INTERSECT_H

View File

@ -1,282 +0,0 @@
// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez
#ifndef CGAL_BBOX_3_TRIANGLE_3_DO_INTERSECT_H
#define CGAL_BBOX_3_TRIANGLE_3_DO_INTERSECT_H
#include <CGAL/Triangle_3.h>
#include <CGAL/Bbox_3.h>
// Fast Triangle-Cuboid intersection test, following Tomas Akenine-Moeller description.
// The code looks slightly different from his code because we avoid the translation at
// a minimal cost (and we use C++ ;).
#include <CGAL/number_utils.h>
#include "Bbox_3_plane_3_do_intersect.h"
CGAL_BEGIN_NAMESPACE
namespace internal {
template <class K>
inline
bool do_bbox_intersect(const typename K::Triangle_3& triangle,
const CGAL::Bbox_3& bbox)
{
const typename K::Point_3& p = triangle.vertex(0);
const typename K::Point_3& q = triangle.vertex(1);
const typename K::Point_3& r = triangle.vertex(2);
for(int i = 0; i < 3; ++i) {
if(p[i] <= q[i]) {
if(q[i] <= r[i]) { // pqr
if(bbox.max(i) < p[i] || bbox.min(i) > r[i])
return false;
}
else {
if(p[i] <= r[i]) { // prq
if(bbox.max(i) < p[i] || bbox.min(i) > q[i])
return false;
}
else { // rpq
if(bbox.max(i) < r[i] || bbox.min(i) > q[i])
return false;
}
}
}
else {
if(p[i] <= r[i]) { // qpr
if(bbox.max(i) < q[i] || bbox.min(i) > r[i])
return false;
}
else {
if(q[i] <= r[i]) { // qrp
if(bbox.max(i) < q[i] || bbox.min(i) > p[i])
return false;
}
else { // rqp
if(bbox.max(i) < r[i] || bbox.min(i) > p[i])
return false;
}
}
}
}
return true;
}
// AXE is the axe such that p is orthogonal to it.
// if you do not know it, or if it does not exist,
// use get_min_max without the AXE template parameter
// available in _plane_is_cuboid_do_intersect.h
template <class K, int AXE>
inline
void get_min_max(const typename K::FT& px,
const typename K::FT& py,
const typename K::FT& pz,
const CGAL::Bbox_3& c,
typename K::Point_3& p_min,
typename K::Point_3& p_max)
{
if(AXE == 0 || px > 0) {
if(AXE == 1 || py > 0) {
if(AXE == 2 || pz > 0) {
p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmin());
p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmax());
}
else {
p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmax());
p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmin());
}
}
else {
if(AXE == 2 || pz > 0) {
p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmin());
p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmax());
}
else {
p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmax());
p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmin());
}
}
}
else {
if(AXE == 1 || py > 0) {
if(AXE == 2 || pz > 0) {
p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmin());
p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmax());
}
else {
p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmax());
p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmin());
}
}
else {
if(AXE == 2 || pz > 0) {
p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmin());
p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmax());
}
else {
p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmax());
p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmin());
}
}
}
}
template <class K, int AXE, int SIDE>
inline
typename K::FT
do_axis_intersect_aux(const typename K::FT& alpha,
const typename K::FT& beta,
const typename K::Vector_3* sides)
{
switch ( AXE )
{
case 0:
return -sides[SIDE].z()*alpha + sides[SIDE].y()*beta;
case 1:
return sides[SIDE].z()*alpha - sides[SIDE].x()*beta;
case 2:
return -sides[SIDE].y()*alpha + sides[SIDE].x()*beta;
default:
CGAL_kernel_assertion(false);
return typename K::FT(0.);
}
}
template <class K, int AXE, int SIDE>
inline
bool do_axis_intersect(const typename K::Triangle_3& triangle,
const typename K::Vector_3* sides,
const CGAL::Bbox_3& bbox)
{
const typename K::Point_3& j = triangle.vertex(SIDE);
const typename K::Point_3& k = triangle.vertex((SIDE+2)%3);
typename K::Point_3 p_min, p_max;
get_min_max<K, AXE>(AXE==0? 0: AXE==1? sides[SIDE].z(): -sides[SIDE].y(),
AXE==0? -sides[SIDE].z(): AXE==1? 0: sides[SIDE].x(),
AXE==0? sides[SIDE].y(): AXE==1? -sides[SIDE].x(): 0,
bbox, p_min, p_max);
switch ( AXE )
{
case 0:
// t_max >= t_min
if ( do_axis_intersect_aux<K,AXE,SIDE>(k.y()-j.y(), k.z()-j.z(), sides) >= 0 )
{
return ( do_axis_intersect_aux<K,AXE,SIDE>(p_min.y()-k.y(), p_min.z()-k.z(), sides) <= 0
|| do_axis_intersect_aux<K,AXE,SIDE>(p_max.y()-j.y(), p_max.z()-j.z(), sides) >= 0 );
}
else
{
return ( do_axis_intersect_aux<K,AXE,SIDE>(p_min.y()-j.y(), p_min.z()-j.z(), sides) <= 0
|| do_axis_intersect_aux<K,AXE,SIDE>(p_max.y()-k.y(), p_max.z()-k.z(), sides) >= 0 );
}
break;
case 1:
// t_max >= t_min
if ( do_axis_intersect_aux<K,AXE,SIDE>(k.x()-j.x(), k.z()-j.z(), sides) >= 0 )
{
return ( do_axis_intersect_aux<K,AXE,SIDE>(p_min.x()-k.x(), p_min.z()-k.z(), sides) <= 0
|| do_axis_intersect_aux<K,AXE,SIDE>(p_max.x()-j.x(), p_max.z()-j.z(), sides) >= 0 );
}
else
{
return ( do_axis_intersect_aux<K,AXE,SIDE>(p_min.x()-j.x(), p_min.z()-j.z(), sides) <= 0
|| do_axis_intersect_aux<K,AXE,SIDE>(p_max.x()-k.x(), p_max.z()-k.z(), sides) >= 0 );
}
break;
case 2:
// t_max >= t_min
if ( do_axis_intersect_aux<K,AXE,SIDE>(k.x()-j.x(), k.y()-j.y(), sides) >= 0 )
{
return ( do_axis_intersect_aux<K,AXE,SIDE>(p_min.x()-k.x(), p_min.y()-k.y(), sides) <= 0
|| do_axis_intersect_aux<K,AXE,SIDE>(p_max.x()-j.x(), p_max.y()-j.y(), sides) >= 0 );
}
else
{
return ( do_axis_intersect_aux<K,AXE,SIDE>(p_min.x()-j.x(), p_min.y()-j.y(), sides) <= 0
|| do_axis_intersect_aux<K,AXE,SIDE>(p_max.x()-k.x(), p_max.y()-k.y(), sides) >= 0 );
}
break;
default:
// Should not happen
CGAL_kernel_assertion(false);
return false;
}
}
// assumes that the intersection with the supporting plane has
// already been checked.
template <class K>
bool do_intersect(const typename K::Triangle_3& triangle,
const CGAL::Bbox_3& bbox,
const K&)
{
if(! do_bbox_intersect<K>(triangle, bbox))
return false;
typename K::Vector_3 sides[3];
sides[0] = triangle[1] - triangle[0];
sides[1] = triangle[2] - triangle[1];
sides[2] = triangle[0] - triangle[2];
if(! do_axis_intersect<K,0,0>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,0,1>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,0,2>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,1,0>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,1,1>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,1,2>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,2,0>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,2,1>(triangle, sides, bbox))
return false;
if(! do_axis_intersect<K,2,2>(triangle, sides, bbox))
return false;
return true;
}
} // namespace internal
template <class K>
bool do_intersect(const CGAL::Triangle_3<K>& triangle,
const CGAL::Bbox_3& bbox)
{
return typename K::Do_intersect_3()(triangle, bbox);
}
template <class K>
bool do_intersect(const CGAL::Bbox_3& bbox,
const CGAL::Triangle_3<K>& triangle)
{
return typename K::Do_intersect_3()(triangle, bbox);
}
CGAL_END_NAMESPACE
#endif // CGAL_BBOX_3_TRIANGLE_3_DO_INTERSECT_H

View File

@ -1,419 +0,0 @@
// Copyright (c) 2009 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Stéphane Tayeb
//
//******************************************************************************
// File Description :
//
//******************************************************************************
#ifndef CGAL_TRIANGLE_3_LINE_3_INTERSECTION_H
#define CGAL_TRIANGLE_3_LINE_3_INTERSECTION_H
#include <CGAL/kernel_basic.h>
#include <CGAL/intersections.h>
namespace CGAL {
namespace internal {
template <class K>
Object
t3l3_intersection_coplanar_aux(const typename K::Point_3& a,
const typename K::Point_3& b,
const typename K::Point_3& c,
const typename K::Line_3& l,
const bool negative_side,
const K& k)
{
// This function is designed to clip pq into the triangle abc.
// Point configuration should be as follows
//
// +q
// | +a
// |
// +c | +b
// |
// +p
//
// We know that c is isolated on the negative side of pq
typedef typename K::Point_3 Point_3;
typename K::Intersect_3 intersection =
k.intersect_3_object();
typename K::Construct_line_3 line =
k.construct_line_3_object();
typename K::Construct_segment_3 segment =
k.construct_segment_3_object();
// Let's get the intersection points
Object l_bc_obj = intersection(l,line(b,c));
const Point_3* l_bc = object_cast<Point_3>(&l_bc_obj);
if ( NULL == l_bc )
{
CGAL_kernel_assertion(false);
return Object();
}
Object l_ca_obj = intersection(l,line(c,a));
const Point_3* l_ca = object_cast<Point_3>(&l_ca_obj);
if ( NULL == l_ca )
{
CGAL_kernel_assertion(false);
return Object();
}
if ( negative_side )
return make_object(segment(*l_bc, *l_ca));
else
return make_object(segment(*l_ca, *l_bc));
}
template <class K>
Object
intersection_coplanar(const typename K::Triangle_3 &t,
const typename K::Line_3 &l,
const K & k )
{
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ;
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ;
typedef typename K::Point_3 Point_3;
typename K::Construct_point_on_3 point_on =
k.construct_point_on_3_object();
typename K::Construct_vertex_3 vertex_on =
k.construct_vertex_3_object();
typename K::Coplanar_orientation_3 coplanar_orientation =
k.coplanar_orientation_3_object();
typename K::Construct_line_3 line =
k.construct_line_3_object();
typename K::Construct_segment_3 segment =
k.construct_segment_3_object();
const Point_3 & p = point_on(l,0);
const Point_3 & q = point_on(l,1);
const Point_3 & A = vertex_on(t,0);
const Point_3 & B = vertex_on(t,1);
const Point_3 & C = vertex_on(t,2);
int k0 = 0;
int k1 = 1;
int k2 = 2;
// Determine the orientation of the triangle in the common plane
if (coplanar_orientation(A,B,C) != POSITIVE)
{
// The triangle is not counterclockwise oriented
// swap two vertices.
std::swap(k1,k2);
}
const Point_3& a = vertex_on(t,k0);
const Point_3& b = vertex_on(t,k1);
const Point_3& c = vertex_on(t,k2);
// Test whether the segment's supporting line intersects the
// triangle in the common plane
const Orientation pqa = coplanar_orientation(p,q,a);
const Orientation pqb = coplanar_orientation(p,q,b);
const Orientation pqc = coplanar_orientation(p,q,c);
switch ( pqa ) {
// -----------------------------------
// pqa POSITIVE
// -----------------------------------
case POSITIVE:
switch ( pqb ) {
case POSITIVE:
switch ( pqc ) {
case POSITIVE:
// the triangle lies in the positive halfspace
// defined by the segment's supporting line.
return Object();
case NEGATIVE:
// c is isolated on the negative side
return t3l3_intersection_coplanar_aux(a,b,c,l,true,k);
case COLLINEAR:
return make_object(c);
}
case NEGATIVE:
if ( POSITIVE == pqc )
// b is isolated on the negative side
return t3l3_intersection_coplanar_aux(c,a,b,l,true,k);
else
// a is isolated on the positive side (here mb c could be use as
// an endpoint instead of computing an intersection is some cases)
return t3l3_intersection_coplanar_aux(b,c,a,l,false,k);
case COLLINEAR:
switch ( pqc ) {
case POSITIVE:
return make_object(b);
case NEGATIVE:
// a is isolated on the positive side (here mb b could be use as
// an endpoint instead of computing an intersection)
return t3l3_intersection_coplanar_aux(b,c,a,l,false,k);
case COLLINEAR:
// b,c,p,q are aligned, [p,q]&[b,c] have the same direction
return make_object(segment(b,c));
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
// -----------------------------------
// pqa NEGATIVE
// -----------------------------------
case NEGATIVE:
switch ( pqb ) {
case POSITIVE:
if ( POSITIVE == pqc )
// a is isolated on the negative side
return t3l3_intersection_coplanar_aux(b,c,a,l,true,k);
else
// b is isolated on the positive side (here mb c could be use as
// an endpoint instead of computing an intersection, in some cases)
return t3l3_intersection_coplanar_aux(c,a,b,l,false,k);
case NEGATIVE:
switch ( pqc ) {
case POSITIVE:
// c is isolated on the positive side
return t3l3_intersection_coplanar_aux(a,b,c,l,false,k);
case NEGATIVE:
// the triangle lies in the negative halfspace
// defined by the segment's supporting line.
return Object();
case COLLINEAR:
return make_object(c);
}
case COLLINEAR:
switch ( pqc ) {
case POSITIVE:
// a is isolated on the negative side (here mb b could be use as
// an endpoint instead of computing an intersection)
return t3l3_intersection_coplanar_aux(b,c,a,l,true,k);
case NEGATIVE:
return make_object(b);
case COLLINEAR:
// b,c,p,q are aligned, [p,q]&[c,b] have the same direction
return make_object(segment(c,b));
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
// -----------------------------------
// pqa COLLINEAR
// -----------------------------------
case COLLINEAR:
switch ( pqb ) {
case POSITIVE:
switch ( pqc ) {
case POSITIVE:
return make_object(a);
case NEGATIVE:
// b is isolated on the positive side (here mb a could be use as
// an endpoint instead of computing an intersection)
return t3l3_intersection_coplanar_aux(c,a,b,l,false,k);
case COLLINEAR:
// a,c,p,q are aligned, [p,q]&[c,a] have the same direction
return make_object(segment(c,a));
}
case NEGATIVE:
switch ( pqc ) {
case POSITIVE:
// b is isolated on the negative side (here mb a could be use as
// an endpoint instead of computing an intersection)
return t3l3_intersection_coplanar_aux(c,a,b,l,true,k);
case NEGATIVE:
return make_object(a);
case COLLINEAR:
// a,c,p,q are aligned, [p,q]&[a,c] have the same direction
return make_object(segment(a,c));
}
case COLLINEAR:
switch ( pqc ) {
case POSITIVE:
// a,b,p,q are aligned, [p,q]&[a,b] have the same direction
return make_object(segment(a,b));
case NEGATIVE:
// a,b,p,q are aligned, [p,q]&[b,a] have the same direction
return make_object(segment(b,a));
case COLLINEAR:
// case pqc == COLLINEAR is impossible since the triangle is
// assumed to be non flat
CGAL_kernel_assertion(false);
return Object();
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
default:// should not happen.
CGAL_kernel_assertion(false);
return Object();
}
}
template <class K>
Object
intersection(const typename K::Triangle_3 &t,
const typename K::Line_3 &l,
const K& k)
{
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ;
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ;
typedef typename K::Point_3 Point_3;
typename K::Construct_point_on_3 point_on =
k.construct_point_on_3_object();
typename K::Construct_vertex_3 vertex_on =
k.construct_vertex_3_object();
typename K::Orientation_3 orientation =
k.orientation_3_object();
typename K::Coplanar_orientation_3 coplanar_orientation =
k.coplanar_orientation_3_object();
typename K::Intersect_3 intersection =
k.intersect_3_object();
const Point_3 & a = vertex_on(t,0);
const Point_3 & b = vertex_on(t,1);
const Point_3 & c = vertex_on(t,2);
const Point_3 & p = point_on(l,0);
const Point_3 & q = point_on(l,1);
if ( ( orientation(a,b,c,p) != COPLANAR )
|| ( orientation(a,b,c,q) != COPLANAR ) )
{
const Orientation pqab = orientation(p,q,a,b);
const Orientation pqbc = orientation(p,q,b,c);
switch ( pqab ) {
case POSITIVE:
if ( pqbc != NEGATIVE && orientation(p,q,c,a) != NEGATIVE )
return intersection(l,t.supporting_plane());
else
return Object();
case NEGATIVE:
if ( pqbc != POSITIVE && orientation(p,q,c,a) != POSITIVE )
return intersection(l,t.supporting_plane());
else
return Object();
case COPLANAR:
switch ( pqbc ) {
case POSITIVE:
if ( orientation(p,q,c,a) != NEGATIVE )
return intersection(l,t.supporting_plane());
else
return Object();
case NEGATIVE:
if ( orientation(p,q,c,a) != POSITIVE )
return intersection(l,t.supporting_plane());
else
return Object();
case COPLANAR: // pqa or pqb or pqc are collinear
return intersection(l,t.supporting_plane());
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
}
// Coplanar case
return intersection_coplanar(t,l,k);
}
template <class K>
Object
intersection(const typename K::Line_3 &l,
const typename K::Triangle_3 &t,
const K& k)
{
return internal::intersection(t,l,k);
}
} // end namespace internal
template <class K>
inline
Object
intersection(const Triangle_3<K> &t, const Line_3<K> &l)
{
return typename K::Intersect_3()(t,l);
}
template <class K>
inline
Object
intersection(const Line_3<K> &l, const Triangle_3<K> &t)
{
return typename K::Intersect_3()(t,l);
}
} // end namespace CGAL
#endif // CGAL_TRIANGLE_3_LINE_3_INTERSECTION_H

View File

@ -1,187 +0,0 @@
// Copyright (c) 2003 INRIA Sophia-Antipolis (France).
// Copyright (c) 2009 GeometryFactory (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); 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; version 2.1 of the License.
// See the file LICENSE.LGPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Adapted from <CGAL/Triangle_3_Plane_3_do_intersect.h>
//
// Author(s) : Philippe Guigue, Laurent Rineau
#ifndef CGAL_TRIANGLE_3_PLANE_3_INTERSECTION_H
#define CGAL_TRIANGLE_3_PLANE_3_INTERSECTION_H
#include <CGAL/Plane_3.h>
#include <CGAL/Triangle_3.h>
namespace CGAL {
namespace internal {
template <class K>
inline
typename K::Point_3
inter_plane_triangle_3_aux(const typename K::Point_3 &p1,
const typename K::RT & f1,
const typename K::Point_3 &p2,
const typename K::RT & f2)
{
return typename K::Point_3(f2 * p1.x() - f1 * p2.x(),
f2 * p1.y() - f1 * p2.y(),
f2 * p1.z() - f1 * p2.z(),
f2 - f1);
}
template <class K>
Object
intersection(const typename K::Plane_3 &plane,
const typename K::Triangle_3 &triangle,
const K& k)
{
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(triangle)) ;
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(plane)) ;
typedef typename K::Point_3 Point_3;
typedef typename K::Segment_3 Segment_3;
typedef typename K::Object_3 Object_3;
typedef typename K::RT RT;
typedef typename Sgn<RT>::result_type SignRT;
typename K::Construct_vertex_3 vertex_on =
k.construct_vertex_3_object();
//typename K::Oriented_side_3 oriented_side =
//k.oriented_side_3_object(); // PA: never used
typename K::Construct_segment_3 segment =
k.construct_segment_3_object();
typename K::Construct_object_3 make_object =
k.construct_object_3_object();
const Point_3& t0 = vertex_on(triangle,0);
const Point_3& t1 = vertex_on(triangle,1);
const Point_3& t2 = vertex_on(triangle,2);
const RT f0 = plane.a()*t0.hx() + plane.b()*t0.hy()
+ plane.c()*t0.hz() + wmult_hw((K*)0, plane.d(), t0);
const RT f1 = plane.a()*t1.hx() + plane.b()*t1.hy()
+ plane.c()*t1.hz() + wmult_hw((K*)1, plane.d(), t1);
const RT f2 = plane.a()*t2.hx() + plane.b()*t2.hy()
+ plane.c()*t2.hz() + wmult_hw((K*)2, plane.d(), t2);
const SignRT s0 = CGAL_NTS sign(f0);
const SignRT s1 = CGAL_NTS sign(f1);
const SignRT s2 = CGAL_NTS sign(f2);
if(s0 == ZERO) {
if(s1 == ZERO) {
if(s2 == ZERO) {
// all zero
return make_object(triangle);
}
else {
// s0, s1 zero
return make_object(segment(t0, t1));
}
}
else if(s2 == ZERO) {
// s0, s2 zero
return make_object(segment(t0, t2));
}
else {
// s0 zero
return make_object(t0);
}
}
else {
if(s1 == ZERO) {
if(s2 == ZERO) {
// s1, s2 zero
return make_object(segment(t1, t2));
}
else {
// s1 zero
return make_object(t1);
}
}
else if( s2 == ZERO ) {
// s2 zero
return make_object(t2);
}
else {
// all non-zero
if(s0 == s1) {
if(s0 == s2) {
return Object_3();
}
else {
// s0 and s1 on same side, s2 different
return make_object(segment(inter_plane_triangle_3_aux<K>(t0, f0,
t2, f2),
inter_plane_triangle_3_aux<K>(t1, f1,
t2, f2)));
}
}
else if(s0 == s2) {
// s0 and s2 on same side, s1 different
return make_object(segment(inter_plane_triangle_3_aux<K>(t1, f1,
t2, f2),
inter_plane_triangle_3_aux<K>(t1, f1,
t0, f0)));
}
else {
// s1 and s2 on same side, s0 different
return make_object(segment(inter_plane_triangle_3_aux<K>(t0, f0,
t2, f2),
inter_plane_triangle_3_aux<K>(t0, f0,
t1, f1)));
}
}
}
} // end function internal::intersection(Plane, Triangle)
template <class K>
inline
Object
intersection(const typename K::Triangle_3 &triangle,
const typename K::Plane_3 &plane,
const K& k)
{
return intersection(plane, triangle, k);
}
} // end namespace internal
template <class K>
inline
Object
intersection(const Plane_3<K> &plane, const Triangle_3<K> &triangle)
{
return typename K::Intersect_3()(plane, triangle);
}
template <class K>
inline
Object
intersection(const Triangle_3<K> &triangle, const Plane_3<K> &plane)
{
return typename K::Intersect_3()(plane, triangle);
}
} // end namespace CGAL
#endif // CGAL_TRIANGLE_3_PLANE_3_INTERSECTION_H

View File

@ -1,166 +0,0 @@
// Copyright (c) 2009 GeometryFactory (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Laurent Rineau
#ifndef CGAL_TRIANGLE_3_RAY_3_INTERSECTION_H
#define CGAL_TRIANGLE_3_RAY_3_INTERSECTION_H
#include <CGAL/kernel_basic.h>
#include <CGAL/intersections.h>
namespace CGAL {
namespace internal {
template <class K>
Object
intersection_triangle_ray_aux(const typename K::Ray_3 &r,
const typename K::Segment_3 &s,
const K& k)
{
typedef typename K::Point_3 Point_3;
typename K::Has_on_3 has_on = k.has_on_3_object();
typename K::Construct_object_3 make_object = k.construct_object_3_object();
typename K::Construct_direction_3 direction = k.construct_direction_3_object();
typename K::Construct_segment_3 make_segment = k.construct_segment_3_object();
// typename K::Compare_xyz_3 compare = k.compare_xyz_3_object(); // PA: never used
typename K::Equal_3 equal = k.equal_3_object();
const Point_3& p = r.source();
const Point_3& q1 = s.source();
const Point_3& q2 = s.target();
if ( ! has_on(s,p) )
return make_object(s);
if ( equal(p,q1) || equal(p,q2) )
return make_object(p);
if ( direction(r) == direction(s) )
return make_object(make_segment(p,q2));
else
return make_object(make_segment(p,q1));
}
template <class K>
Object
intersection(const typename K::Triangle_3 &t,
const typename K::Ray_3 &r,
const K& k)
{
typedef typename K::Point_3 Point_3;
typedef typename K::Segment_3 Segment_3;
typedef typename K::Object_3 Object_3;
typedef typename K::Ray_3 Ray_3;
typedef typename K::Line_3 Line_3;
if ( !CGAL::do_intersect(t, r) )
return Object_3();
// TOFIX: here we assume that we have already tested
// do_intersect between the triangle and the ray
const Object intersection = CGAL::intersection(t.supporting_plane(),
r);
// intersection is either a point, either a ray
// if it is a ray, then we need to clip it to a segment
if ( const Ray_3* ray = object_cast<Ray_3>(&intersection))
{
typename K::Intersect_3 intersect = k.intersect_3_object();
typename K::Construct_line_3 f_line = k.construct_line_3_object();
typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object();
typename K::Construct_object_3 make_object = k.construct_object_3_object();
typename K::Construct_segment_3 f_segment = k.construct_segment_3_object();
typename K::Has_on_3 has_on = k.has_on_3_object();
const Point_3& t0 = vertex_on(t,0);
const Point_3& t1 = vertex_on(t,1);
const Point_3& t2 = vertex_on(t,2);
const Line_3 l01 = f_line(t0,t1);
const Line_3 l02 = f_line(t0,t2);
const Line_3 l12 = f_line(t1,t2);
const Segment_3 s01 = f_segment(t0,t1);
const Segment_3 s02 = f_segment(t0,t2);
const Segment_3 s12 = f_segment(t1,t2);
const Line_3 lr = ray->supporting_line();
const Object_3 inter_01 = intersect(l01,lr);
const Object_3 inter_02 = intersect(l02,lr);
const Object_3 inter_12 = intersect(l12,lr);
const Point_3* p01 = object_cast<Point_3>(&inter_01);
const Point_3* p02 = object_cast<Point_3>(&inter_02);
const Point_3* p12 = object_cast<Point_3>(&inter_12);
if ( p01 && has_on(s01, *p01) )
{
if ( p02 && has_on(s02, *p02) )
return intersection_triangle_ray_aux(*ray, f_segment(*p01,*p02), k);
else if ( p12 && has_on(s12, *p12) )
return intersection_triangle_ray_aux(*ray, f_segment(*p01,*p12), k);
else
return make_object(*p01);
}
else if ( p02 && has_on(s02, *p02) )
{
if ( p12 && has_on(s12, *p12) )
return intersection_triangle_ray_aux(*ray, f_segment(*p02,*p12), k);
else
return make_object(*p02);
}
else if ( p12 && has_on(s12, *p12) )
{
return make_object(*p12);
}
// should not happen
CGAL_kernel_assertion(false);
return Object_3();
}
else
return intersection;
}
} // end namespace internal
template <class K>
inline
Object
intersection(const Triangle_3<K> &t, const Ray_3<K> &r)
{
return typename K::Intersect_3()(t, r);
}
template <class K>
inline
Object
intersection(const Ray_3<K> &r, const Triangle_3<K> &t)
{
return typename K::Intersect_3()(t, r);
}
} // end namespace CGAL
#endif // CGAL_TRIANGLE_3_RAY_3_INTERSECTION_H

View File

@ -1,542 +0,0 @@
// Copyright (c) 2009 GeometryFactory (France), INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Laurent Rineau, Stephane Tayeb
//
//******************************************************************************
// File Description : Implements triangle_3 segment_3 intersection construction.
//
// This implementation is adapted from Triangle_3_Segment_3_do_intersect.h.
//******************************************************************************
#ifndef CGAL_TRIANGLE_3_SEGMENT_3_INTERSECTION_H
#define CGAL_TRIANGLE_3_SEGMENT_3_INTERSECTION_H
#include <CGAL/kernel_basic.h>
#include <CGAL/intersections.h>
namespace CGAL {
namespace internal {
template <class K>
Object
t3s3_intersection_coplanar_aux(const typename K::Point_3& a,
const typename K::Point_3& b,
const typename K::Point_3& c,
const typename K::Point_3& p,
const typename K::Point_3& q,
const bool negative_side,
const K& k)
{
// This function is designed to clip pq into the triangle abc.
// Point configuration should be as follows
//
// +q
// | +a
// |
// +c | +b
// |
// +p
//
// We know that c is isolated on the negative side of pq, but we don't know
// p position wrt [bc]&[ca] and q position wrt [bc]&[ca]
typedef typename K::Point_3 Point_3;
typename K::Coplanar_orientation_3 coplanar_orientation =
k.coplanar_orientation_3_object();
typename K::Intersect_3 intersection =
k.intersect_3_object();
typename K::Construct_line_3 line =
k.construct_line_3_object();
typename K::Construct_segment_3 segment =
k.construct_segment_3_object();
const Orientation bcq = coplanar_orientation(b,c,q);
const Orientation cap = coplanar_orientation(c,a,p);
if ( NEGATIVE == bcq || NEGATIVE == cap )
return Object();
else if ( COLLINEAR == bcq )
// q is inside [c,b], p is outside t (because of pqc)
return make_object(q);
else if ( COLLINEAR == cap )
// p is inside [c,a], q is outside t (because of pqc)
return make_object(p);
else // bcq == POSITIVE && cap == POSITIVE
{
// Here we know the intersection is not empty
// Let's get the intersection points
Point_3 p_side_end_point(p);
if ( NEGATIVE == coplanar_orientation(b,c,p) )
{
Object obj = intersection(line(p,q),line(b,c));
const Point_3* p_temp = object_cast<Point_3>(&obj);
if ( NULL != p_temp )
p_side_end_point = *p_temp;
}
Point_3 q_side_end_point(q);
if ( NEGATIVE == coplanar_orientation(c,a,q) )
{
Object obj = intersection(line(p,q),line(c,a));
const Point_3* p_temp = object_cast<Point_3>(&obj);
if ( NULL != p_temp )
q_side_end_point = *p_temp;
}
if ( negative_side )
return make_object(segment(p_side_end_point, q_side_end_point));
else
return make_object(segment(q_side_end_point, p_side_end_point));
}
}
template <class K>
Object
t3s3_intersection_coplanar_aux(const typename K::Point_3& a,
const typename K::Point_3& b,
const typename K::Point_3& p,
const typename K::Point_3& q,
const K& k)
{
// Builds resulting segment of intersection of [a,b] and [p,q]
// Precondition: [a,b] and [p,q] have the same direction
typename K::Construct_segment_3 segment =
k.construct_segment_3_object();
typename K::Collinear_are_ordered_along_line_3 collinear_ordered =
k.collinear_are_ordered_along_line_3_object();
// possible orders: [p,a,b,q], [p,a,q,b], [a,p,b,q], [a,p,q,b]
if ( collinear_ordered(p,a,q) )
{
// p is before a
if ( collinear_ordered(p,b,q) )
return make_object(segment(a,b));
else
return make_object(segment(a,q));
}
else
{
// p is after a
if ( collinear_ordered(p,b,q) )
return make_object(segment(p,b));
else
return make_object(segment(p,q));
}
}
template <class K>
Object
intersection_coplanar(const typename K::Triangle_3 &t,
const typename K::Segment_3 &s,
const K & k )
{
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ;
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ;
typedef typename K::Point_3 Point_3;
typename K::Construct_point_on_3 point_on =
k.construct_point_on_3_object();
typename K::Construct_vertex_3 vertex_on =
k.construct_vertex_3_object();
typename K::Coplanar_orientation_3 coplanar_orientation =
k.coplanar_orientation_3_object();
typename K::Collinear_are_ordered_along_line_3 collinear_ordered =
k.collinear_are_ordered_along_line_3_object();
typename K::Construct_line_3 line =
k.construct_line_3_object();
typename K::Construct_segment_3 segment =
k.construct_segment_3_object();
const Point_3 & p = point_on(s,0);
const Point_3 & q = point_on(s,1);
const Point_3 & A = vertex_on(t,0);
const Point_3 & B = vertex_on(t,1);
const Point_3 & C = vertex_on(t,2);
int k0 = 0;
int k1 = 1;
int k2 = 2;
// Determine the orientation of the triangle in the common plane
if (coplanar_orientation(A,B,C) != POSITIVE)
{
// The triangle is not counterclockwise oriented
// swap two vertices.
std::swap(k1,k2);
}
const Point_3& a = vertex_on(t,k0);
const Point_3& b = vertex_on(t,k1);
const Point_3& c = vertex_on(t,k2);
// Test whether the segment's supporting line intersects the
// triangle in the common plane
const Orientation pqa = coplanar_orientation(p,q,a);
const Orientation pqb = coplanar_orientation(p,q,b);
const Orientation pqc = coplanar_orientation(p,q,c);
switch ( pqa ) {
// -----------------------------------
// pqa POSITIVE
// -----------------------------------
case POSITIVE:
switch ( pqb ) {
case POSITIVE:
switch ( pqc ) {
case POSITIVE:
// the triangle lies in the positive halfspace
// defined by the segment's supporting line.
return Object();
case NEGATIVE:
// c is isolated on the negative side
return t3s3_intersection_coplanar_aux(a,b,c,p,q,true,k);
case COLLINEAR:
if ( collinear_ordered(p,c,q) ) // c is inside [p,q]
return make_object(c);
else
return Object();
}
case NEGATIVE:
if ( POSITIVE == pqc )
// b is isolated on the negative side
return t3s3_intersection_coplanar_aux(c,a,b,p,q,true,k);
else
// a is isolated on the positive side
return t3s3_intersection_coplanar_aux(b,c,a,q,p,false,k);
case COLLINEAR:
switch ( pqc ) {
case POSITIVE:
if ( collinear_ordered(p,b,q) ) // b is inside [p,q]
return make_object(b);
else
return Object();
case NEGATIVE:
// a is isolated on the positive side
return t3s3_intersection_coplanar_aux(b,c,a,q,p,false,k);
case COLLINEAR:
// b,c,p,q are aligned, [p,q]&[b,c] have the same direction
return t3s3_intersection_coplanar_aux(b,c,p,q,k);
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
// -----------------------------------
// pqa NEGATIVE
// -----------------------------------
case NEGATIVE:
switch ( pqb ) {
case POSITIVE:
if ( POSITIVE == pqc )
// a is isolated on the negative side
return t3s3_intersection_coplanar_aux(b,c,a,p,q,true,k);
else
// b is isolated on the positive side
return t3s3_intersection_coplanar_aux(c,a,b,q,p,false,k);
case NEGATIVE:
switch ( pqc ) {
case POSITIVE:
// c is isolated on the positive side
return t3s3_intersection_coplanar_aux(a,b,c,q,p,false,k);
case NEGATIVE:
// the triangle lies in the negative halfspace
// defined by the segment's supporting line.
return Object();
case COLLINEAR:
if ( collinear_ordered(p,c,q) ) // c is inside [p,q]
return make_object(c);
else
return Object();
}
case COLLINEAR:
switch ( pqc ) {
case POSITIVE:
// a is isolated on the negative side
return t3s3_intersection_coplanar_aux(b,c,a,p,q,true,k);
case NEGATIVE:
if ( collinear_ordered(p,b,q) ) // b is inside [p,q]
return make_object(b);
else
return Object();
case COLLINEAR:
// b,c,p,q are aligned, [p,q]&[c,b] have the same direction
return t3s3_intersection_coplanar_aux(c,b,p,q,k);
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
// -----------------------------------
// pqa COLLINEAR
// -----------------------------------
case COLLINEAR:
switch ( pqb ) {
case POSITIVE:
switch ( pqc ) {
case POSITIVE:
if ( collinear_ordered(p,a,q) ) // a is inside [p,q]
return make_object(a);
else
return Object();
case NEGATIVE:
// b is isolated on the positive side
return t3s3_intersection_coplanar_aux(c,a,b,q,p,false,k);
case COLLINEAR:
// a,c,p,q are aligned, [p,q]&[c,a] have the same direction
return t3s3_intersection_coplanar_aux(c,a,p,q,k);
}
case NEGATIVE:
switch ( pqc ) {
case POSITIVE:
// b is isolated on the negative side
return t3s3_intersection_coplanar_aux(c,a,b,p,q,true,k);
case NEGATIVE:
if ( collinear_ordered(p,a,q) ) // a is inside [p,q]
return make_object(a);
else
return Object();
case COLLINEAR:
// a,c,p,q are aligned, [p,q]&[a,c] have the same direction
return t3s3_intersection_coplanar_aux(a,c,p,q,k);
}
case COLLINEAR:
switch ( pqc ) {
case POSITIVE:
// a,b,p,q are aligned, [p,q]&[a,b] have the same direction
return t3s3_intersection_coplanar_aux(a,b,p,q,k);
case NEGATIVE:
// a,b,p,q are aligned, [p,q]&[b,a] have the same direction
return t3s3_intersection_coplanar_aux(b,a,p,q,k);
case COLLINEAR:
// case pqc == COLLINEAR is impossible since the triangle is
// assumed to be non flat
CGAL_kernel_assertion(false);
return Object();
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
default:// should not happen.
CGAL_kernel_assertion(false);
return Object();
}
}
template <class K>
Object
intersection(const typename K::Triangle_3 &t,
const typename K::Segment_3 &s,
const K & k)
{
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ;
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ;
typedef typename K::Point_3 Point_3;
typename K::Construct_point_on_3 point_on =
k.construct_point_on_3_object();
typename K::Construct_vertex_3 vertex_on =
k.construct_vertex_3_object();
typename K::Orientation_3 orientation =
k.orientation_3_object();
typename K::Intersect_3 intersection =
k.intersect_3_object();
const Point_3 & a = vertex_on(t,0);
const Point_3 & b = vertex_on(t,1);
const Point_3 & c = vertex_on(t,2);
const Point_3 & p = point_on(s,0);
const Point_3 & q = point_on(s,1);
const Orientation abcp = orientation(a,b,c,p);
const Orientation abcq = orientation(a,b,c,q);
switch ( abcp ) {
case POSITIVE:
switch ( abcq ) {
case POSITIVE:
// the segment lies in the positive open halfspaces defined by the
// triangle's supporting plane
return Object();
case NEGATIVE:
// p sees the triangle in counterclockwise order
if ( orientation(p,q,a,b) != POSITIVE
&& orientation(p,q,b,c) != POSITIVE
&& orientation(p,q,c,a) != POSITIVE )
return intersection(s,t.supporting_plane());
else
return Object();
case COPLANAR:
// q belongs to the triangle's supporting plane
// p sees the triangle in counterclockwise order
if ( orientation(p,q,a,b) != POSITIVE
&& orientation(p,q,b,c) != POSITIVE
&& orientation(p,q,c,a) != POSITIVE )
return make_object(q);
else
return Object();
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
case NEGATIVE:
switch ( abcq ) {
case POSITIVE:
// q sees the triangle in counterclockwise order
if ( orientation(q,p,a,b) != POSITIVE
&& orientation(q,p,b,c) != POSITIVE
&& orientation(q,p,c,a) != POSITIVE )
return intersection(s,t.supporting_plane());
else
return Object();
case NEGATIVE:
// the segment lies in the negative open halfspaces defined by the
// triangle's supporting plane
return Object();
case COPLANAR:
// q belongs to the triangle's supporting plane
// p sees the triangle in clockwise order
if ( orientation(q,p,a,b) != POSITIVE
&& orientation(q,p,b,c) != POSITIVE
&& orientation(q,p,c,a) != POSITIVE )
return make_object(q);
else
return Object();
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
case COPLANAR: // p belongs to the triangle's supporting plane
switch ( abcq ) {
case POSITIVE:
// q sees the triangle in counterclockwise order
if ( orientation(q,p,a,b) != POSITIVE
&& orientation(q,p,b,c) != POSITIVE
&& orientation(q,p,c,a) != POSITIVE )
return make_object(p);
else
return Object();
case NEGATIVE:
// q sees the triangle in clockwise order
if ( orientation(p,q,a,b) != POSITIVE
&& orientation(p,q,b,c) != POSITIVE
&& orientation(p,q,c,a) != POSITIVE )
return make_object(p);
else
return Object();
case COPLANAR:
// the segment is coplanar with the triangle's supporting plane
// we test whether the segment intersects the triangle in the common
// supporting plane
return intersection_coplanar(t,s,k);
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
default: // should not happen.
CGAL_kernel_assertion(false);
return Object();
}
}
template <class K>
inline
Object
intersection(const typename K::Segment_3 &s,
const typename K::Triangle_3 &t,
const K & k)
{
return internal::intersection(t,s,k);
}
} // end namespace internal
template <class K>
inline
Object
intersection(const Triangle_3<K> &t, const Segment_3<K> &s)
{
return typename K::Intersect_3()(t, s);
}
template <class K>
inline
Object
intersection(const Segment_3<K> &s, const Triangle_3<K> &t)
{
return typename K::Intersect_3()(t, s);
}
} // end namespace CGAL
#endif // CGAL_TRIANGLE_3_SEGMENT_3_INTERSECTION_H

View File

@ -26,7 +26,6 @@
#define CGAL_INTERSECTION_3_H
#include <CGAL/intersection_3_1.h>
#include <CGAL/Triangle_3_Line_3_do_intersect.h>
#include <CGAL/Triangle_3_Plane_3_do_intersect.h>
#include <CGAL/Triangle_3_Point_3_do_intersect.h>
@ -34,17 +33,6 @@
#include <CGAL/Triangle_3_Segment_3_do_intersect.h>
#include <CGAL/Triangle_3_Tetrahedron_3_do_intersect.h>
#include <CGAL/Triangle_3_Triangle_3_do_intersect.h>
#include <CGAL/Triangle_3_line_3_intersection.h>
#include <CGAL/Triangle_3_ray_3_intersection.h>
#include <CGAL/Triangle_3_segment_3_intersection.h>
#include <CGAL/Triangle_3_plane_3_intersection.h>
#include <CGAL/Bbox_3_line_3_do_intersect.h>
#include <CGAL/Bbox_3_ray_3_do_intersect.h>
#include <CGAL/Bbox_3_segment_3_do_intersect.h>
#include <CGAL/Bbox_3_sphere_3_do_intersect.h>
#include <CGAL/Bbox_3_plane_3_do_intersect.h>
#include <CGAL/Bbox_3_triangle_3_do_intersect.h>
#include <CGAL/Bbox_3_bbox_3_do_intersect.h>
#endif // CGAL_INTERSECTION_3_H

View File

@ -1,37 +0,0 @@
# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.
project( Intersections_3_example )
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
if ( COMMAND cmake_policy )
cmake_policy( SET CMP0003 NEW )
endif()
find_package(CGAL QUIET COMPONENTS Core )
if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} )
include( CGAL_CreateSingleSourceCGALProgram )
include_directories (BEFORE ../../include)
create_single_source_cgal_program( "bbox_3_do_intersect_test.cpp" )
create_single_source_cgal_program( "circle_other.cpp" )
create_single_source_cgal_program( "line_line.cpp" )
create_single_source_cgal_program( "test_intersections_3.cpp" )
create_single_source_cgal_program( "triangle_3_intersection_test.cpp" )
create_single_source_cgal_program( "triangle_other.cpp" )
else()
message(STATUS "This program requires the CGAL library, and will not be compiled.")
endif()

View File

@ -1,186 +0,0 @@
// Copyright (c) 2009 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Stephane Tayeb
//
//******************************************************************************
// File Description :
//
//******************************************************************************
#include <string>
#include <CGAL/Cartesian.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
template <class T>
bool test_aux(const T& t,
const std::string& name,
const CGAL::Bbox_3& bbox,
bool expected)
{
bool b = CGAL::do_intersect(t,bbox);
if ( b != expected )
std::cout << "ERROR: do_intersect(" << name
<< ") did not answer the expected result !" << std::endl;
return (b == expected);
}
template <class K>
bool test()
{
// types
typedef typename K::FT FT;
typedef typename K::Line_3 Line;
typedef typename K::Point_3 Point;
typedef typename K::Segment_3 Segment;
typedef typename K::Ray_3 Ray;
typedef typename K::Line_3 Line;
CGAL::Bbox_3 bbox(1.0,1.0,1.0,10.0,50.0,100.0);
Point p1(FT(0.), FT(0.), FT(0.));
Point p2(FT(0.), FT(100.), FT(100.));
Point p3(FT(100.), FT(0.), FT(100.));
Point p4(FT(100.), FT(100.), FT(0.));
Point p5(FT(0.), FT(0.), FT(100.));
Point p6(FT(100.), FT(100.), FT(100.));
Point p7(FT(-1.), FT(-1.), FT(-1.));
Point pA(FT(5.), FT(0.), FT(0.));
Point pB(FT(5.), FT(10.), FT(100.));
Point pC(FT(5.), FT(10.), FT(-1.));
Point pE(FT(5.), FT(10.), FT(0.));
Segment s12(p1,p2);
Segment s13(p1,p3);
Segment s14(p1,p4);
Segment s15(p1,p5);
Segment s16(p1,p6);
Segment s17(p1,p7);
Segment s71(p7,p1);
Segment sAB(pA,pB);
Segment sBA(pB,pA);
Segment sBC(pB,pC);
Segment sCE(pC,pE);
Segment sEC(pE,pC);
bool b = test_aux(s12,"s12",bbox,false);
b &= test_aux(s13,"s13",bbox,false);
b &= test_aux(s14,"s14",bbox,false);
b &= test_aux(s15,"s15",bbox,false);
b &= test_aux(s16,"s16",bbox,true);
b &= test_aux(s17,"s17",bbox,false);
b &= test_aux(s71,"s71",bbox,false);
b &= test_aux(sAB,"sAB",bbox,true);
b &= test_aux(sBA,"sBA",bbox,true);
b &= test_aux(sBC,"sBC",bbox,true);
b &= test_aux(sCE,"sCE",bbox,false);
b &= test_aux(sEC,"sEC",bbox,false);
Ray r12(p1,p2);
Ray r13(p1,p3);
Ray r14(p1,p4);
Ray r15(p1,p5);
Ray r16(p1,p6);
Ray r17(p1,p7);
Ray r71(p7,p1);
Ray rAB(pA,pB);
Ray rBA(pB,pA);
Ray rBC(pB,pC);
Ray rCE(pC,pE);
Ray rEC(pE,pC);
b &= test_aux(r12,"r12",bbox,false);
b &= test_aux(r13,"r13",bbox,false);
b &= test_aux(r14,"r14",bbox,false);
b &= test_aux(r15,"r15",bbox,false);
b &= test_aux(r16,"r16",bbox,true);
b &= test_aux(r17,"r17",bbox,false);
b &= test_aux(r71,"r71",bbox,true);
b &= test_aux(rAB,"rAB",bbox,true);
b &= test_aux(rBA,"rBA",bbox,true);
b &= test_aux(rBC,"rBC",bbox,true);
b &= test_aux(rCE,"rCE",bbox,true);
b &= test_aux(rEC,"rEC",bbox,false);
Line l12(p1,p2);
Line l13(p1,p3);
Line l14(p1,p4);
Line l15(p1,p5);
Line l16(p1,p6);
Line l17(p1,p7);
Line l71(p7,p1);
Line lAB(pA,pB);
Line lBA(pB,pA);
Line lBC(pB,pC);
Line lCE(pC,pE);
Line lEC(pE,pC);
b &= test_aux(l12,"l12",bbox,false);
b &= test_aux(l13,"l13",bbox,false);
b &= test_aux(l14,"l14",bbox,false);
b &= test_aux(l15,"l15",bbox,false);
b &= test_aux(l16,"l16",bbox,true);
b &= test_aux(l17,"l17",bbox,true);
b &= test_aux(l71,"l71",bbox,true);
b &= test_aux(lAB,"lAB",bbox,true);
b &= test_aux(lBA,"lBA",bbox,true);
b &= test_aux(lBC,"lBC",bbox,true);
b &= test_aux(lCE,"lCE",bbox,true);
b &= test_aux(lEC,"lEC",bbox,true);
return b;
}
int main()
{
std::cout << "Testing with Simple_cartesian<float>..." << std::endl ;
bool b = test<CGAL::Simple_cartesian<float> >();
std::cout << "Testing with Simple_cartesian<double>..." << std::endl ;
b &= test<CGAL::Simple_cartesian<double> >();
std::cout << "Testing with Cartesian<float>..." << std::endl ;
b &= test<CGAL::Cartesian<float> >();
std::cout << "Testing with Cartesian<double>..." << std::endl ;
b &= test<CGAL::Cartesian<double> >();
std::cout << "Testing with Exact_predicates_inexact_constructions_kernel..." << std::endl ;
b &= test<CGAL::Exact_predicates_inexact_constructions_kernel>();
std::cout << "Testing with Exact_predicates_exact_constructions_kernel..." << std::endl ;
b &= test<CGAL::Exact_predicates_exact_constructions_kernel>();
if ( b )
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}

View File

@ -1,339 +0,0 @@
// Copyright (c) 2009 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Stephane Tayeb
//
//******************************************************************************
// File Description :
//
//******************************************************************************
#include <string>
#include <CGAL/Cartesian.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
template <class Triangle, class Query, class Result>
bool test_aux(const Triangle t,
const Query& q,
const std::string& name,
const Result& expected)
{
CGAL::Object object = CGAL::intersection(t,q);
const Result* pr = CGAL::object_cast<Result>(&object);
if ( (NULL != pr) && (expected == *pr) )
{
return true;
}
else
{
std::cout << "ERROR: intersection(" << name
<< ") did not answer the expected result !";
if ( NULL != pr )
std::cout << " (answer: ["<< *pr << "])";
std::cout << std::endl;
}
return false;
}
template <class K>
bool test()
{
// types
typedef typename K::FT FT;
typedef typename K::Line_3 Line;
typedef typename K::Point_3 Point;
typedef typename K::Segment_3 Segment;
typedef typename K::Ray_3 Ray;
typedef typename K::Line_3 Line;
typedef typename K::Triangle_3 Triangle;
/* -------------------------------------
// Test data is something like that (in t supporting plane)
// Triangle is (p1,p2,p3)
//
// +E +1
// / \
// +C 6+ +8 +4 +B
// / 9++7 \
// 3+-------+5--+2
//
// +F +A
------------------------------------- */
Point p1(FT(1.), FT(0.), FT(0.));
Point p2(FT(0.), FT(1.), FT(0.));
Point p3(FT(0.), FT(0.), FT(1.));
Triangle t(p1,p2,p3);
// Edges of t
Segment s12(p1,p2);
Segment s21(p2,p1);
Segment s13(p1,p3);
Segment s23(p2,p3);
Segment s32(p3,p2);
Segment s31(p3,p1);
bool b = test_aux(t,s12,"t-s12",s12);
b &= test_aux(t,s21,"t-s21",s21);
b &= test_aux(t,s13,"t-s13",s13);
b &= test_aux(t,s23,"t-s23",s23);
// Inside points
Point p4(FT(0.5), FT(0.5), FT(0.));
Point p5(FT(0.), FT(0.75), FT(0.25));
Point p6(FT(0.5), FT(0.), FT(0.5));
Point p7(FT(0.25), FT(0.625), FT(0.125));
Point p8(FT(0.5), FT(0.25), FT(0.25));
Segment s14(p1,p4);
Segment s41(p4,p1);
Segment s24(p2,p4);
Segment s42(p4,p2);
Segment s15(p1,p5);
Segment s25(p2,p5);
Segment s34(p3,p4);
Segment s35(p3,p5);
Segment s36(p3,p6);
Segment s45(p4,p5);
Segment s16(p1,p6);
Segment s26(p2,p6);
Segment s62(p6,p2);
Segment s46(p4,p6);
Segment s48(p4,p8);
Segment s56(p5,p6);
Segment s65(p6,p5);
Segment s64(p6,p4);
Segment s17(p1,p7);
Segment s67(p6,p7);
Segment s68(p6,p8);
Segment s86(p8,p6);
Segment s78(p7,p8);
Segment s87(p8,p7);
b &= test_aux(t,s14,"t-s14",s14);
b &= test_aux(t,s41,"t-s41",s41);
b &= test_aux(t,s24,"t-s24",s24);
b &= test_aux(t,s42,"t-s42",s42);
b &= test_aux(t,s15,"t-s15",s15);
b &= test_aux(t,s25,"t-s25",s25);
b &= test_aux(t,s34,"t-s34",s34);
b &= test_aux(t,s35,"t-s35",s35);
b &= test_aux(t,s36,"t-s36",s36);
b &= test_aux(t,s45,"t-s45",s45);
b &= test_aux(t,s16,"t-s16",s16);
b &= test_aux(t,s26,"t-s26",s26);
b &= test_aux(t,s62,"t-s62",s62);
b &= test_aux(t,s46,"t-s46",s46);
b &= test_aux(t,s65,"t-s65",s65);
b &= test_aux(t,s64,"t-s64",s64);
b &= test_aux(t,s48,"t-s48",s48);
b &= test_aux(t,s56,"t-s56",s56);
b &= test_aux(t,s17,"t-t17",s17);
b &= test_aux(t,s67,"t-t67",s67);
b &= test_aux(t,s68,"t-s68",s68);
b &= test_aux(t,s86,"t-s86",s86);
b &= test_aux(t,s78,"t-t78",s78);
b &= test_aux(t,s87,"t-t87",s87);
// Outside points (in triangle plane)
Point pA(FT(-0.5), FT(1.), FT(0.5));
Point pB(FT(0.5), FT(1.), FT(-0.5));
Point pC(FT(0.5), FT(-0.5), FT(1.));
Point pE(FT(1.), FT(-1.), FT(1.));
Point pF(FT(-1.), FT(0.), FT(2.));
Segment sAB(pA,pB);
Segment sBC(pB,pC);
Segment s2E(p2,pE);
Segment sE2(pE,p2);
Segment s2A(p2,pA);
Segment s6E(p6,pE);
Segment sB8(pB,p8);
Segment sC8(pC,p8);
Segment s8C(p8,pC);
Segment s1F(p1,pF);
Segment sF6(pF,p6);
b &= test_aux(t,sAB,"t-sAB",p2);
b &= test_aux(t,sBC,"t-sBC",s46);
b &= test_aux(t,s2E,"t-s2E",s26);
b &= test_aux(t,sE2,"t-sE2",s62);
b &= test_aux(t,s2A,"t-s2A",p2);
b &= test_aux(t,s6E,"t-s6E",p6);
b &= test_aux(t,sB8,"t-sB8",s48);
b &= test_aux(t,sC8,"t-sC8",s68);
b &= test_aux(t,s8C,"t-s8C",s86);
b &= test_aux(t,s1F,"t-s1F",s13);
b &= test_aux(t,sF6,"t-sF6",s36);
// Outside triangle plane
Point pa(FT(0.), FT(0.), FT(0.));
Point pb(FT(2.), FT(0.), FT(0.));
Point pc(FT(1.), FT(0.), FT(1.));
Point pe(FT(1.), FT(0.5), FT(0.5));
Segment sab(pa,pb);
Segment sac(pa,pc);
Segment sae(pa,pe);
Segment sa8(pa,p8);
Segment sb2(pb,p2);
b &= test_aux(t,sab,"t-sab",p1);
b &= test_aux(t,sac,"t-sac",p6);
b &= test_aux(t,sae,"t-sae",p8);
b &= test_aux(t,sa8,"t-sa8",p8);
b &= test_aux(t,sb2,"t-sb2",p2);
// -----------------------------------
// Line queries
// -----------------------------------
// Edges of t
Line l12(p1,p2);
Line l21(p2,p1);
Line l13(p1,p3);
Line l23(p2,p3);
b &= test_aux(t,l12,"t-l12",s12);
b &= test_aux(t,l21,"t-l21",s21);
b &= test_aux(t,l13,"t-l13",s13);
b &= test_aux(t,l23,"t-l23",s23);
// In triangle
Point p9_(FT(0.), FT(0.5), FT(0.5));
Point p9(FT(0.25), FT(0.375), FT(0.375));
Line l14(p1,p4);
Line l41(p4,p1);
Line l24(p2,p4);
Line l42(p4,p2);
Line l15(p1,p5);
Line l25(p2,p5);
Line l34(p3,p4);
Line l35(p3,p5);
Line l36(p3,p6);
Line l45(p4,p5);
Line l16(p1,p6);
Line l26(p2,p6);
Line l62(p6,p2);
Line l46(p4,p6);
Line l48(p4,p8);
Line l56(p5,p6);
Line l47(p4,p7);
Line l89(p8,p9);
Line l86(p8,p6);
Line l68(p6,p8);
Segment s89_res(p1,p9_);
b &= test_aux(t,l14,"t-l14",s12);
b &= test_aux(t,l41,"t-l41",s21);
b &= test_aux(t,l24,"t-l24",s21);
b &= test_aux(t,l42,"t-l42",s12);
b &= test_aux(t,l15,"t-l15",s15);
b &= test_aux(t,l25,"t-l25",s23);
b &= test_aux(t,l34,"t-l34",s34);
b &= test_aux(t,l35,"t-l35",s32);
b &= test_aux(t,l36,"t-l36",s31);
b &= test_aux(t,l45,"t-l45",s45);
b &= test_aux(t,l16,"t-l16",s13);
b &= test_aux(t,l26,"t-l26",s26);
b &= test_aux(t,l62,"t-l62",s62);
b &= test_aux(t,l46,"t-l46",s46);
b &= test_aux(t,l48,"t-l48",s46);
b &= test_aux(t,l56,"t-l56",s56);
b &= test_aux(t,l47,"t-l47",s45);
b &= test_aux(t,l89,"t-t89",s89_res);
b &= test_aux(t,l68,"t-l68",s64);
b &= test_aux(t,l86,"t-l86",s46);
// Outside points (in triangle plane)
Line lAB(pA,pB);
Line lBC(pB,pC);
Line l2E(p2,pE);
Line lE2(pE,p2);
Line l2A(p2,pA);
Line l6E(p6,pE);
Line lB8(pB,p8);
Line lC8(pC,p8);
Line l8C(p8,pC);
Line l1F(p1,pF);
Line lF6(pF,p6);
b &= test_aux(t,lAB,"t-lAB",p2);
b &= test_aux(t,lBC,"t-lBC",s46);
b &= test_aux(t,l2E,"t-l2E",s26);
b &= test_aux(t,lE2,"t-lE2",s62);
b &= test_aux(t,l2A,"t-l2A",p2);
b &= test_aux(t,l6E,"t-l6E",s26);
b &= test_aux(t,lB8,"t-lB8",s46);
b &= test_aux(t,lC8,"t-lC8",s64);
b &= test_aux(t,l8C,"t-l8C",s46);
b &= test_aux(t,l1F,"t-l1F",s13);
b &= test_aux(t,lF6,"t-lF6",s31);
// Outside triangle plane
Line lab(pa,pb);
Line lac(pa,pc);
Line lae(pa,pe);
Line la8(pa,p8);
Line lb2(pb,p2);
b &= test_aux(t,lab,"t-lab",p1);
b &= test_aux(t,lac,"t-lac",p6);
b &= test_aux(t,lae,"t-lae",p8);
b &= test_aux(t,la8,"t-la8",p8);
b &= test_aux(t,lb2,"t-lb2",p2);
return b;
}
int main()
{
std::cout << "Testing with Simple_cartesian<float>..." << std::endl ;
bool b = test<CGAL::Simple_cartesian<float> >();
std::cout << "Testing with Simple_cartesian<double>..." << std::endl ;
b &= test<CGAL::Simple_cartesian<double> >();
std::cout << "Testing with Cartesian<float>..." << std::endl ;
b &= test<CGAL::Cartesian<float> >();
std::cout << "Testing with Cartesian<double>..." << std::endl ;
b &= test<CGAL::Cartesian<double> >();
std::cout << "Testing with Exact_predicates_inexact_constructions_kernel..." << std::endl ;
b &= test<CGAL::Exact_predicates_inexact_constructions_kernel>();
std::cout << "Testing with Exact_predicates_exact_constructions_kernel..." << std::endl ;
b &= test<CGAL::Exact_predicates_exact_constructions_kernel>();
if ( b )
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}