/usr/include/CGAL/Min_ellipse_2.h is in libcgal-dev 4.7-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | // Copyright (c) 1997-2001
// ETH Zurich (Switzerland). 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
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// 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) : Sven Schoenherr <sven@inf.ethz.ch>, Bernd Gaertner
#ifndef CGAL_MIN_ELLIPSE_2_H
#define CGAL_MIN_ELLIPSE_2_H
#include <CGAL/Optimisation/basic.h>
#include <CGAL/Random.h>
#include <list>
#include <vector>
#include <algorithm>
#include <iostream>
namespace CGAL {
// Class declaration
// =================
template < class Traits_ >
class Min_ellipse_2;
// Class interface
// ===============
template < class Traits_ >
class Min_ellipse_2 {
public:
// types
typedef Traits_ Traits;
typedef typename Traits_::Point Point;
typedef typename Traits_::Ellipse Ellipse;
typedef typename std::list<Point>::const_iterator Point_iterator;
typedef const Point * Support_point_iterator;
/**************************************************************************
WORKAROUND: Some compilers are unable to match member functions defined
outside the class template. Therefore, all member functions are implemented
in the class interface.
// creation
template < class InputIterator >
Min_ellipse_2( InputIterator first,
InputIterator last,
bool randomize = false,
Random& random = default_random,
const Traits& traits = Traits());
Min_ellipse_2( const Traits& traits = Traits());
Min_ellipse_2( const Point& p,
const Traits& traits = Traits());
Min_ellipse_2( Point p,
Point q,
const Traits& traits = Traits());
Min_ellipse_2( const Point& p1,
const Point& p2,
const Point& p3,
const Traits& traits = Traits());
Min_ellipse_2( const Point& p1,
const Point& p2,
const Point& p3,
const Point& p4,
const Traits& traits = Traits());
Min_ellipse_2( const Point& p1,
const Point& p2,
const Point& p3,
const Point& p4,
const Point& p5,
const Traits& traits = Traits());
~Min_ellipse_2( );
// access functions
int number_of_points ( ) const;
int number_of_support_points( ) const;
Point_iterator points_begin( ) const;
Point_iterator points_end ( ) const;
Support_point_iterator support_points_begin( ) const;
Support_point_iterator support_points_end ( ) const;
const Point& support_point( int i) const;
const Ellipse& ellipse( ) const;
// predicates
CGAL::Bounded_side bounded_side( const Point& p) const;
bool has_on_bounded_side ( const Point& p) const;
bool has_on_boundary ( const Point& p) const;
bool has_on_unbounded_side ( const Point& p) const;
bool is_empty ( ) const;
bool is_degenerate( ) const;
// modifiers
void insert( const Point& p);
void insert( const Point* first,
const Point* last );
void insert( std::list<Point>::const_iterator first,
std::list<Point>::const_iterator last );
void insert( std::istream_iterator<Point,std::ptrdiff_t> first,
std::istream_iterator<Point,std::ptrdiff_t> last );
void clear( );
// validity check
bool is_valid( bool verbose = false, int level = 0) const;
// miscellaneous
const Traits& traits( ) const;
**************************************************************************/
private:
// private data members
Traits tco; // traits class object
std::list<Point> points; // doubly linked list of points
int n_support_points; // number of support points
Point* support_points; // array of support points
// copying and assignment not allowed!
Min_ellipse_2( const Min_ellipse_2<Traits_>&);
Min_ellipse_2<Traits_>& operator = ( const Min_ellipse_2<Traits_>&);
// ============================================================================
// Class implementation
// ====================
public:
// Access functions and predicates
// -------------------------------
// #points and #support points
inline
std::size_t
number_of_points( ) const
{
return( points.size());
}
inline
std::size_t
number_of_support_points( ) const
{
return( n_support_points);
}
// is_... predicates
inline
bool
is_empty( ) const
{
return( number_of_support_points() == 0);
}
inline
bool
is_degenerate( ) const
{
return( number_of_support_points() < 3);
}
// access to points and support points
inline
Point_iterator
points_begin( ) const
{
return( points.begin());
}
inline
Point_iterator
points_end( ) const
{
return( points.end());
}
inline
Support_point_iterator
support_points_begin( ) const
{
return( support_points);
}
inline
Support_point_iterator
support_points_end( ) const
{
return( support_points+n_support_points);
}
// random access for support points
inline
const Point&
support_point( std::size_t i) const
{
CGAL_optimisation_precondition(i < number_of_support_points());
return( support_points[ i]);
}
// ellipse
inline
const Ellipse&
ellipse( ) const
{
return( tco.ellipse);
}
// in-ellipse test predicates
inline
CGAL::Bounded_side
bounded_side( const Point& p) const
{
return( tco.ellipse.bounded_side( p));
}
inline
bool
has_on_bounded_side( const Point& p) const
{
return( tco.ellipse.has_on_bounded_side( p));
}
inline
bool
has_on_boundary( const Point& p) const
{
return( tco.ellipse.has_on_boundary( p));
}
inline
bool
has_on_unbounded_side( const Point& p) const
{
return( tco.ellipse.has_on_unbounded_side( p));
}
private:
// Private member functions
// ------------------------
// compute_ellipse
inline
void
compute_ellipse( )
{
switch ( n_support_points) {
case 5:
tco.ellipse.set( support_points[ 0],
support_points[ 1],
support_points[ 2],
support_points[ 3],
support_points[ 4]);
break;
case 4:
tco.ellipse.set( support_points[ 0],
support_points[ 1],
support_points[ 2],
support_points[ 3]);
break;
case 3:
tco.ellipse.set( support_points[ 0],
support_points[ 1],
support_points[ 2]);
break;
case 2:
tco.ellipse.set( support_points[ 0], support_points[ 1]);
break;
case 1:
tco.ellipse.set( support_points[ 0]);
break;
case 0:
tco.ellipse.set( );
break;
default:
CGAL_optimisation_assertion( ( n_support_points >= 0) &&
( n_support_points <= 5) ); }
}
void
me( const Point_iterator& last, int n_sp)
{
// compute ellipse through support points
n_support_points = n_sp;
compute_ellipse();
if ( n_sp == 5) return;
// test first n points
typename std::list<Point>::iterator point_iter = points.begin();
for ( ; last != point_iter; ) {
const Point& p = *point_iter;
// p not in current ellipse?
if ( has_on_unbounded_side( p)) {
// recursive call with p as additional support point
support_points[ n_sp] = p;
me( point_iter, n_sp+1);
// move current point to front
points.splice( points.begin(), points, point_iter++); }
else
++point_iter; }
}
public:
// Constructors
// ------------
// STL-like constructor (member template)
template < class InputIterator >
Min_ellipse_2( InputIterator first,
InputIterator last,
bool randomize
#if !defined(_MSC_VER) || _MSC_VER > 1300
= false
#endif
,
Random& random = default_random,
const Traits& traits = Traits())
: tco( traits)
{
// allocate support points' array
support_points = new Point[ 5];
// range of points not empty?
if ( first != last) {
// store points
if ( randomize) {
// shuffle points at random
std::vector<Point> v( first, last);
std::random_shuffle( v.begin(), v.end(), random);
std::copy( v.begin(), v.end(),
std::back_inserter( points)); }
else
std::copy( first, last, std::back_inserter( points)); }
// compute me
me( points.end(), 0);
}
// default constructor
inline
Min_ellipse_2( const Traits& traits = Traits())
: tco( traits), n_support_points( 0)
{
// allocate support points' array
support_points = new Point[ 5];
// initialize ellipse
tco.ellipse.set();
CGAL_optimisation_postcondition( is_empty());
}
// constructor for one point
inline
Min_ellipse_2( const Point& p, const Traits& traits = Traits())
: tco( traits), points( 1, p), n_support_points( 1)
{
// allocate support points' array
support_points = new Point[ 5];
// initialize ellipse
support_points[ 0] = p;
tco.ellipse.set( p);
CGAL_optimisation_postcondition( is_degenerate());
}
// constructor for two points
// This was const Point& but then Intel 7.0/.net2003 messes it up
// with the constructor taking an iterator range
inline
Min_ellipse_2( Point p1, Point p2,
const Traits& traits = Traits())
: tco( traits)
{
// allocate support points' array
support_points = new Point[ 5];
// store points
points.push_back( p1);
points.push_back( p2);
// compute me
me( points.end(), 0);
CGAL_optimisation_postcondition( is_degenerate());
}
// constructor for three points
inline
Min_ellipse_2( const Point& p1, const Point& p2, const Point& p3,
const Traits& traits = Traits())
: tco( traits)
{
// allocate support points' array
support_points = new Point[ 5];
// store points
points.push_back( p1);
points.push_back( p2);
points.push_back( p3);
// compute me
me( points.end(), 0);
}
// constructor for four points
inline
Min_ellipse_2( const Point& p1, const Point& p2,
const Point& p3, const Point& p4,
const Traits& traits = Traits())
: tco( traits)
{
// allocate support points' array
support_points = new Point[ 5];
// store points
points.push_back( p1);
points.push_back( p2);
points.push_back( p3);
points.push_back( p4);
// compute me
me( points.end(), 0);
}
// constructor for five points
inline
Min_ellipse_2( const Point& p1, const Point& p2, const Point& p3,
const Point& p4, const Point& p5,
const Traits& traits = Traits())
: tco( traits)
{
// allocate support points' array
support_points = new Point[ 5];
// store points
points.push_back( p1);
points.push_back( p2);
points.push_back( p3);
points.push_back( p4);
points.push_back( p5);
// compute me
me( points.end(), 0);
}
// Destructor
// ----------
inline
~Min_ellipse_2( )
{
// free support points' array
delete[] support_points;
}
// Modifiers
// ---------
void
insert( const Point& p)
{
// p not in current ellipse?
if ( has_on_unbounded_side( p)) {
// p new support point
support_points[ 0] = p;
// recompute me
me( points.end(), 1);
// store p as the first point in list
points.push_front( p); }
else
// append p to the end of the list
points.push_back( p);
}
template < class InputIterator >
void
insert( InputIterator first, InputIterator last)
{
for ( ; first != last; ++first)
insert( *first);
}
void
clear( )
{
points.erase( points.begin(), points.end());
n_support_points = 0;
tco.ellipse.set();
}
// Validity check
// --------------
bool
is_valid( bool verbose = false, int level = 0) const
{
using namespace std;
CGAL::Verbose_ostream verr( verbose);
verr << endl;
verr << "CGAL::Min_ellipse_2<Traits>::" << endl;
verr << "is_valid( true, " << level << "):" << endl;
verr << " |P| = " << number_of_points()
<< ", |S| = " << number_of_support_points() << endl;
// containment check (a)
verr << " a) containment check..." << flush;
Point_iterator point_iter;
for ( point_iter = points_begin();
point_iter != points_end();
++point_iter)
if ( has_on_unbounded_side( *point_iter))
return( CGAL::_optimisation_is_valid_fail( verr,
"ellipse does not contain all points"));
verr << "passed." << endl;
// support set checks (b)+(c) (not yet implemented)
// alternative support set check
verr << " +) support set check..." << flush;
Support_point_iterator support_point_iter;
for ( support_point_iter = support_points_begin();
support_point_iter != support_points_end();
++support_point_iter)
if ( ! has_on_boundary( *support_point_iter))
return( CGAL::_optimisation_is_valid_fail( verr,
"ellipse does not have all \
support points on the boundary"));
verr << "passed." << endl;
verr << " object is valid!" << endl;
return( true);
}
// Miscellaneous
// -------------
inline
const Traits&
traits( ) const
{
return( tco);
}
};
// Function declarations
// =====================
// I/O
// ---
template < class Traits_ >
std::ostream&
operator << ( std::ostream& os, const Min_ellipse_2<Traits_>& me);
template < class Traits_ >
std::istream&
operator >> ( std::istream& is, Min_ellipse_2<Traits_>& me);
} //namespace CGAL
#include <CGAL/Min_ellipse_2/Min_ellipse_2_impl.h>
#endif // CGAL_MIN_ELLIPSE_2_H
// ===== EOF ==================================================================
|