added points_on_square_grid_3

This commit is contained in:
Susan Hert 2002-03-11 16:39:04 +00:00
parent 19b2e1e8b4
commit ddd5da11d9
7 changed files with 148 additions and 6 deletions

View File

@ -1,5 +1,8 @@
Generator Package: Release changes:
---------------------------------------------------------------------
2.48 (11 Mar 2002)
- added point_on_square_grid_3 generator function
2.48 (7 Mar 2002)
- added return statement in demo to get rid of warning

View File

@ -23,6 +23,9 @@ generators_prog1.C
generators_prog2.C
generates 500 points with integer coordinates
generators_prog3.C
generates 125 3D points with integer coordinates
random_poly_manual_demo.C
program presented in reference manual that generates a random
polygon from 50 points drawn at random from a square

View File

@ -41,6 +41,7 @@ all: \
Triangle_generator_prog2$(EXE_EXT) \
generators_prog1$(EXE_EXT) \
generators_prog2$(EXE_EXT) \
generators_prog3$(EXE_EXT) \
random_poly_manual_demo$(EXE_EXT) \
random_polygons_demo$(EXE_EXT) \
rcs_demo$(EXE_EXT) \
@ -64,6 +65,9 @@ generators_prog1$(EXE_EXT): generators_prog1$(OBJ_EXT)
generators_prog2$(EXE_EXT): generators_prog2$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)generators_prog2 generators_prog2$(OBJ_EXT) $(LDFLAGS)
generators_prog3$(EXE_EXT): generators_prog3$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)generators_prog3 generators_prog3$(OBJ_EXT) $(LDFLAGS)
random_poly_manual_demo$(EXE_EXT): random_poly_manual_demo$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)random_poly_manual_demo random_poly_manual_demo$(OBJ_EXT) $(LDFLAGS)
@ -83,6 +87,7 @@ clean: \
Triangle_generator_prog2.clean \
generators_prog1.clean \
generators_prog2.clean \
generators_prog3.clean \
random_poly_manual_demo.clean \
random_polygons_demo.clean \
rcs_demo.clean \

View File

@ -538,6 +538,37 @@ include local type declarations including \ccc{value_type}, denoted by
\ccTexHtml{\\}{}
\ccc{Join_input_iterator_1}.
% +------------------------------------------------------------------------+
\subsection{Point Generators as Functions}
\lcTex{\ccIndexSubsubitemBegin[c]{generator}{3D point}{as function}}
\ccHeading{Grid Points}
\ccThree{OutputIterator}{rand}{}
\lcTex{\ccIndexSubsubitem[c]{generator}{3D point}{on grid}}
Grid points are generated by functions that write to output iterators.
\def\ccLongParamLayout{\ccTrue}
\ccFunction{template <class OutputIterator, Creator creator>
OutputIterator
points_on_square_grid_3( double a, std::size_t n,
OutputIterator o,
Creator creator =
Creator_uniform_3<double,P>);}
{ creates the first $n$ points on the regular $m \times m \times m$ grid
where $m = \lceil n^{1/3} \rceil$ within the cube
$[-a,a]\times [-a,a] \times [-a,a]$. Returns the value of $o$ after
inserting the $n$ points.
\ccPrecond \ccc{Creator} must be a function object accepting three
\ccc{double} values $x, y$ and $z$ and returning an initialized point
\ccc{(x,y,z)} of type \ccc{P}. Predefined implementations for these
creators like the default can be found in
Section~\ref{sectionCreatorFunctionObjects}. The
\ccc{OutputIterator} must accept values of type \ccc{P}. If the
\ccc{OutputIterator} has a \ccc{value_type} the default
initializer of the \ccc{creator} can be used. \ccc{P} is set to
the \ccc{value_type} in this case.}
\def\ccLongParamLayout{\ccFalse}
% +------------------------------------------------------------------------+
%\newpage

View File

@ -538,6 +538,37 @@ include local type declarations including \ccc{value_type}, denoted by
\ccTexHtml{\\}{}
\ccc{Join_input_iterator_1}.
% +------------------------------------------------------------------------+
\subsection{Point Generators as Functions}
\lcTex{\ccIndexSubsubitemBegin[c]{generator}{3D point}{as function}}
\ccHeading{Grid Points}
\ccThree{OutputIterator}{rand}{}
\lcTex{\ccIndexSubsubitem[c]{generator}{3D point}{on grid}}
Grid points are generated by functions that write to output iterators.
\def\ccLongParamLayout{\ccTrue}
\ccFunction{template <class OutputIterator, Creator creator>
OutputIterator
points_on_square_grid_3( double a, std::size_t n,
OutputIterator o,
Creator creator =
Creator_uniform_3<double,P>);}
{ creates the first $n$ points on the regular $m \times m \times m$ grid
where $m = \lceil n^{1/3} \rceil$ within the cube
$[-a,a]\times [-a,a] \times [-a,a]$. Returns the value of $o$ after
inserting the $n$ points.
\ccPrecond \ccc{Creator} must be a function object accepting three
\ccc{double} values $x, y$ and $z$ and returning an initialized point
\ccc{(x,y,z)} of type \ccc{P}. Predefined implementations for these
creators like the default can be found in
Section~\ref{sectionCreatorFunctionObjects}. The
\ccc{OutputIterator} must accept values of type \ccc{P}. If the
\ccc{OutputIterator} has a \ccc{value_type} the default
initializer of the \ccc{creator} can be used. \ccc{P} is set to
the \ccc{value_type} in this case.}
\def\ccLongParamLayout{\ccFalse}
% +------------------------------------------------------------------------+
%\newpage

View File

@ -142,6 +142,61 @@ generate_point() {
d_range * ( 2 * _rnd.get_double() - 1.0));
}
template <class OutputIterator, class Creator>
OutputIterator
points_on_square_grid_3( double a, std::size_t n,
OutputIterator o, Creator creator)
{
if (n == 0)
return o;
int m = int(CGAL_CLIB_STD::ceil(std::sqrt(std::sqrt(n))));
while (m*m*m < n) m++;
double base = -a; // Left and bottom boundary.
double step = 2*a/(m-1);
int j = 0;
int k = 0;
double px = base;
double py = base;
double pz = base;
*o++ = creator( px, py, pz);
for (std::size_t i = 1; i < n; i++) {
j++;
if ( j == m) {
k++;
if ( k == m) {
py = base;
px = base;
pz = pz + step;
k = 0;
}
else {
px = base;
py = py + step;
}
j = 0;
} else {
px = px + step;
}
*o++ = creator( px, py, pz);
}
return o;
}
template <class OutputIterator>
OutputIterator
points_on_square_grid_3( double a, std::size_t n, OutputIterator o)
{
typedef std::iterator_traits<OutputIterator> ITraits;
typedef typename ITraits::value_type P;
return points_on_square_grid_3(a, n, o, Creator_uniform_3<double,P>());
}
CGAL_END_NAMESPACE
#endif // CGAL_POINT_GENERATORS_3_H //
// EOF //

View File

@ -65,7 +65,13 @@ void test_point_generators_2() {
CGAL::copy_n( g4, 100, std::back_inserter(points));
CGAL::copy_n( g5, 50, std::back_inserter(points));
CGAL::copy_n( g5a, 50, std::back_inserter(points));
points_on_square_grid_2( 50.0, (std::size_t)100,
points_on_square_grid_2( 50.0, (std::size_t)1,
std::back_inserter(points), Creator());
points_on_square_grid_2( 50.0, (std::size_t)2,
std::back_inserter(points), Creator());
points_on_square_grid_2( 50.0, (std::size_t)3,
std::back_inserter(points), Creator());
points_on_square_grid_2( 50.0, (std::size_t)94,
std::back_inserter(points), Creator());
points_on_segment_2( Point_2(-100, 100), Point_2( 100,-100),
(std::size_t)100, std::back_inserter(points));
@ -102,17 +108,25 @@ void test_point_generators_3() {
/* Create test point set. */
std::vector<Point_3> points;
points.reserve(400);
Random_points_in_sphere_3<Point_3,Creator> g1( 100.0);
points.reserve(500);
Random_points_in_sphere_3<Point_3,Creator> g1( 100.0);
CGAL::copy_n( g1, 100, std::back_inserter(points));
Random_points_on_sphere_3<Point_3,Creator> g2( 100.0);
Random_points_in_cube_3<Point_3,Creator> g3( 100.0);
Random_points_on_sphere_3<Point_3,Creator> g2( 100.0);
Random_points_in_cube_3<Point_3,Creator> g3( 100.0);
CGAL::copy_n( g2, 100, std::back_inserter(points));
CGAL::copy_n( g3, 100, std::back_inserter(points));
points_on_square_grid_3( 50.0, (std::size_t)1,
std::back_inserter(points), Creator());
points_on_square_grid_3( 50.0, (std::size_t)2,
std::back_inserter(points), Creator());
points_on_square_grid_3( 50.0, (std::size_t)3,
std::back_inserter(points), Creator());
points_on_square_grid_3( 50.0, (std::size_t)94,
std::back_inserter(points), Creator());
random_selection( points.begin(), points.end(), 100,
std::back_inserter(points));
CGAL_assertion( points.size() == 400);
CGAL_assertion( points.size() == 500);
for ( std::vector<Point_3>::iterator i = points.begin();
i != points.end(); i++){
CGAL_assertion( i->x() <= 100);