Initial revision

This commit is contained in:
Lutz Kettner 1997-06-13 00:17:32 +00:00
parent 4a624ee866
commit 8a6dd5d1a4
8 changed files with 506 additions and 0 deletions

View File

@ -0,0 +1,54 @@
/* Segment_generator_prog1.C */
/* ------------------------------- */
/* CGAL example program for the generic segment generator. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Segment_generator.h>
#include <CGAL/ncopy.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
typedef CGAL_Cartesian<double> R;
typedef CGAL_Point_2<R> Point;
typedef CGAL_Segment_2<R> Segment;
int main()
{
/* Create test segment set. Prepare a vector for 200 segments. */
vector<Segment> segs;
segs.reserve(200);
/* Prepare point generator for the horizontal segment, length 200. */
typedef CGAL_Random_points_on_segment_2<Point> P1;
P1 p1( Point(-100,0), Point(100,0));
/* Prepare point generator for random points on circle, radius 250. */
typedef CGAL_Random_points_on_circle_2<Point> P2;
P2 p2( 250);
/* Create 200 segments. */
CGAL_Segment_generator<Segment, P1, P2> g( p1, p2);
CGAL_ncopy( g, 200, back_inserter( segs));
/* Visualize segments. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(512, 512);
W.init(-256.0, 255.0, -256.0);
W << CGAL_BLACK;
for( vector<Segment>::iterator i = segs.begin(); i != segs.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}

View File

@ -0,0 +1,67 @@
/* Segment_generator_prog2.C */
/* ------------------------------- */
/* CGAL example program for the generic segment generator */
/* using precomputed point locations. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Segment_generator.h>
#include <CGAL/ncopy.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
typedef CGAL_Cartesian<double> R;
typedef CGAL_Point_2<R> Point;
typedef CGAL_Segment_2<R> Segment;
int main()
{
/* Prepare two point vectors for the precomputed points. */
vector<Point> p1, p2;
p1.reserve(100);
p2.reserve(100);
/* Create points for a horizontal like fan. */
CGAL_points_on_segment_2( Point(-250, -50), Point(-250, 50),
50, back_inserter( p1));
CGAL_points_on_segment_2( Point( 250,-250), Point( 250,250),
50, back_inserter( p2));
/* Create points for a vertical like fan. */
CGAL_points_on_segment_2( Point( -50,-250), Point( 50,-250),
50, back_inserter( p1));
CGAL_points_on_segment_2( Point(-250, 250), Point( 250, 250),
50, back_inserter( p2));
/* Create test segment set. Prepare a vector for 100 segments. */
vector<Segment> segs;
segs.reserve(100);
/* Create both fans at once from the precomputed points. */
typedef vector<Point>::iterator I;
I i1 = p1.begin();
I i2 = p2.begin();
CGAL_Segment_generator<Segment,I,I> g( i1, i2);
CGAL_ncopy( g, 100, back_inserter( segs));
/* Visualize segments. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(512, 512);
W.init(-256.0, 255.0, -256.0);
W << CGAL_BLACK;
for( vector<Segment>::iterator i = segs.begin(); i != segs.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}

View File

@ -0,0 +1,64 @@
/* generators_prog1.C */
/* ------------------------------- */
/* CGAL example program for point generators. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/ncopy.h>
#include <CGAL/random_selection.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
typedef CGAL_Cartesian<double> R;
typedef CGAL_Point_2<R> Point;
int main()
{
/* Create test point set. Prepare a vector for 1000 points. */
vector<Point> points;
points.reserve(1000);
/* Create 600 points within a disc of radius 150. */
CGAL_Random_points_in_disc_2<Point> g( 150.0);
CGAL_ncopy( g, 600, back_inserter( points));
/* Create 200 points from a 15 x 15 grid. */
CGAL_points_on_square_grid_2( 500.0, 200, back_inserter(points),(Point*)0);
/* Select 100 points randomly and append them at the end of */
/* the current vector of points. */
CGAL_random_selection( points.begin(), points.end(), 100,
back_inserter( points));
/* Create 100 points that are collinear to two randomly chosen */
/* points and append them to the current vector of points. */
CGAL_random_collinear_points_2( points.begin(), points.end(), 100,
back_inserter( points));
/* Check that we have really created 1000 points. */
assert( points.size() == 1000);
/* Use a random permutation to hide the creation history */
/* of the point set. */
random_shuffle( points.begin(), points.end(), CGAL_random);
/* Visualize point set. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(512, 512);
W.init(-256.0, 255.0, -256.0);
W << CGAL_BLACK;
for( vector<Point>::iterator i = points.begin(); i != points.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}

View File

@ -0,0 +1,68 @@
/* generators_prog2.C */
/* ------------------------------- */
/* CGAL example program for point generators creating integer points. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
typedef CGAL_Cartesian<int> R;
typedef CGAL_Point_2<R> Point;
/* Provide your own CGAL_build_point function. */
inline
Point& CGAL_build_point( double x, double y, Point& p) {
p = Point( int(x), int(y));
return p;
}
#include <CGAL/point_generators_2.h>
#include <CGAL/ncopy.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
int main()
{
/* Create test point set. Prepare a vector for 400 points. */
vector<Point> points;
points.reserve(400);
/* Create 250 points from a 16 x 16 grid. Note that the double */
/* arithmetic _is_ sufficient to produce exact integer grid points. */
/* The distance between neighbors is 34 pixel = 510 / 15. */
CGAL_points_on_square_grid_2( 510.0, 250, back_inserter(points),(Point*)0);
/* Lower, left corner. */
assert( points[0].x() == -255);
assert( points[0].y() == -255);
/* Upper, right corner. Note that 6 points are missing to fill the grid. */
assert( points[249].x() == 255 - 6 * 34);
assert( points[249].y() == 255);
/* Create 250 points within a disc of radius 150. */
CGAL_Random_points_in_disc_2<Point> g( 150.0);
CGAL_ncopy( g, 250, back_inserter( points));
/* Check that we have really created 500 points. */
assert( points.size() == 500);
/* Visualize point set. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(524, 524);
W.init(-262.0, 261.0, -262.0);
W << CGAL_BLACK;
for( vector<Point>::iterator i = points.begin(); i != points.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}

View File

@ -0,0 +1,54 @@
/* Segment_generator_prog1.C */
/* ------------------------------- */
/* CGAL example program for the generic segment generator. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Segment_generator.h>
#include <CGAL/ncopy.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
typedef CGAL_Cartesian<double> R;
typedef CGAL_Point_2<R> Point;
typedef CGAL_Segment_2<R> Segment;
int main()
{
/* Create test segment set. Prepare a vector for 200 segments. */
vector<Segment> segs;
segs.reserve(200);
/* Prepare point generator for the horizontal segment, length 200. */
typedef CGAL_Random_points_on_segment_2<Point> P1;
P1 p1( Point(-100,0), Point(100,0));
/* Prepare point generator for random points on circle, radius 250. */
typedef CGAL_Random_points_on_circle_2<Point> P2;
P2 p2( 250);
/* Create 200 segments. */
CGAL_Segment_generator<Segment, P1, P2> g( p1, p2);
CGAL_ncopy( g, 200, back_inserter( segs));
/* Visualize segments. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(512, 512);
W.init(-256.0, 255.0, -256.0);
W << CGAL_BLACK;
for( vector<Segment>::iterator i = segs.begin(); i != segs.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}

View File

@ -0,0 +1,67 @@
/* Segment_generator_prog2.C */
/* ------------------------------- */
/* CGAL example program for the generic segment generator */
/* using precomputed point locations. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Segment_generator.h>
#include <CGAL/ncopy.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
typedef CGAL_Cartesian<double> R;
typedef CGAL_Point_2<R> Point;
typedef CGAL_Segment_2<R> Segment;
int main()
{
/* Prepare two point vectors for the precomputed points. */
vector<Point> p1, p2;
p1.reserve(100);
p2.reserve(100);
/* Create points for a horizontal like fan. */
CGAL_points_on_segment_2( Point(-250, -50), Point(-250, 50),
50, back_inserter( p1));
CGAL_points_on_segment_2( Point( 250,-250), Point( 250,250),
50, back_inserter( p2));
/* Create points for a vertical like fan. */
CGAL_points_on_segment_2( Point( -50,-250), Point( 50,-250),
50, back_inserter( p1));
CGAL_points_on_segment_2( Point(-250, 250), Point( 250, 250),
50, back_inserter( p2));
/* Create test segment set. Prepare a vector for 100 segments. */
vector<Segment> segs;
segs.reserve(100);
/* Create both fans at once from the precomputed points. */
typedef vector<Point>::iterator I;
I i1 = p1.begin();
I i2 = p2.begin();
CGAL_Segment_generator<Segment,I,I> g( i1, i2);
CGAL_ncopy( g, 100, back_inserter( segs));
/* Visualize segments. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(512, 512);
W.init(-256.0, 255.0, -256.0);
W << CGAL_BLACK;
for( vector<Segment>::iterator i = segs.begin(); i != segs.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}

View File

@ -0,0 +1,64 @@
/* generators_prog1.C */
/* ------------------------------- */
/* CGAL example program for point generators. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/ncopy.h>
#include <CGAL/random_selection.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
typedef CGAL_Cartesian<double> R;
typedef CGAL_Point_2<R> Point;
int main()
{
/* Create test point set. Prepare a vector for 1000 points. */
vector<Point> points;
points.reserve(1000);
/* Create 600 points within a disc of radius 150. */
CGAL_Random_points_in_disc_2<Point> g( 150.0);
CGAL_ncopy( g, 600, back_inserter( points));
/* Create 200 points from a 15 x 15 grid. */
CGAL_points_on_square_grid_2( 500.0, 200, back_inserter(points),(Point*)0);
/* Select 100 points randomly and append them at the end of */
/* the current vector of points. */
CGAL_random_selection( points.begin(), points.end(), 100,
back_inserter( points));
/* Create 100 points that are collinear to two randomly chosen */
/* points and append them to the current vector of points. */
CGAL_random_collinear_points_2( points.begin(), points.end(), 100,
back_inserter( points));
/* Check that we have really created 1000 points. */
assert( points.size() == 1000);
/* Use a random permutation to hide the creation history */
/* of the point set. */
random_shuffle( points.begin(), points.end(), CGAL_random);
/* Visualize point set. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(512, 512);
W.init(-256.0, 255.0, -256.0);
W << CGAL_BLACK;
for( vector<Point>::iterator i = points.begin(); i != points.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}

View File

@ -0,0 +1,68 @@
/* generators_prog2.C */
/* ------------------------------- */
/* CGAL example program for point generators creating integer points. */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
typedef CGAL_Cartesian<int> R;
typedef CGAL_Point_2<R> Point;
/* Provide your own CGAL_build_point function. */
inline
Point& CGAL_build_point( double x, double y, Point& p) {
p = Point( int(x), int(y));
return p;
}
#include <CGAL/point_generators_2.h>
#include <CGAL/ncopy.h>
#include <CGAL/IO/Window_stream.h> /* only for visualization used */
int main()
{
/* Create test point set. Prepare a vector for 400 points. */
vector<Point> points;
points.reserve(400);
/* Create 250 points from a 16 x 16 grid. Note that the double */
/* arithmetic _is_ sufficient to produce exact integer grid points. */
/* The distance between neighbors is 34 pixel = 510 / 15. */
CGAL_points_on_square_grid_2( 510.0, 250, back_inserter(points),(Point*)0);
/* Lower, left corner. */
assert( points[0].x() == -255);
assert( points[0].y() == -255);
/* Upper, right corner. Note that 6 points are missing to fill the grid. */
assert( points[249].x() == 255 - 6 * 34);
assert( points[249].y() == 255);
/* Create 250 points within a disc of radius 150. */
CGAL_Random_points_in_disc_2<Point> g( 150.0);
CGAL_ncopy( g, 250, back_inserter( points));
/* Check that we have really created 500 points. */
assert( points.size() == 500);
/* Visualize point set. Can be omitted, see example programs */
/* in the CGAL source code distribution. */
CGAL_Window_stream W(524, 524);
W.init(-262.0, 261.0, -262.0);
W << CGAL_BLACK;
for( vector<Point>::iterator i = points.begin(); i != points.end(); i++)
W << *i;
/* Wait for program termination. */
char c;
cout << " Type any character to continue: " << endl;
cin >> c;
cout << " done" << endl;
return 0;
}