1 #ifndef CGAL_SURFACE_MESH_SEGMENTATION_DISK_SAMPLERS_H
2 #define CGAL_SURFACE_MESH_SEGMENTATION_DISK_SAMPLERS_H
8 #include <CGAL/number_type_basic.h>
10 #define CGAL_ANGLE_ST_DEV_DIVIDER 3.0
47 template<
class Tuple,
bool uniform = false>
48 class Vogel_disk_sampling
60 template<
class OutputIterator>
61 void operator()(
int number_of_points,
63 OutputIterator out_it)
const
65 const double golden_ratio = 3.0 - std::sqrt(5.0);
69 const double length_of_normal = 1.0 / tan(cone_angle / 2.0);
70 const double angle_st_dev = cone_angle / CGAL_ANGLE_ST_DEV_DIVIDER;
71 for(
int i = 0; i < number_of_points; ++i)
73 double Q = i * golden_ratio * CGAL_PI;
74 double R = std::sqrt(static_cast<double>(i) / number_of_points);
75 double angle = atan(R / length_of_normal);
76 double weight = exp(-0.5 * (std::pow(angle / angle_st_dev, 2)));
77 *out_it++ = Tuple(R * cos(Q), R * sin(Q), weight);
82 const double custom_power = 1.0;
84 for(
int i = 0; i < number_of_points; ++i)
86 double Q = i * golden_ratio * CGAL_PI;
87 double R = std::pow(static_cast<double>(i) / number_of_points, custom_power);
89 *out_it++ = Tuple(R * cos(Q), R * sin(Q), 1.0);
125 template<
class Tuple>
126 class Polar_disk_sampling
140 template<
class OutputIterator>
141 void operator()(
int number_of_points,
143 OutputIterator out_it)
const
145 const int number_of_points_sqrt =
static_cast<int>(std::sqrt(
146 static_cast<double>(number_of_points)));
147 const double length_of_normal = 1.0 / tan(cone_angle / 2.0);
149 const double angle_st_dev = cone_angle / CGAL_ANGLE_ST_DEV_DIVIDER;
151 for(
int i = 1; i <= number_of_points_sqrt; ++i)
152 for(
int j = 1; j <= number_of_points_sqrt; ++j)
154 double w1 =
static_cast<double>(i) / number_of_points_sqrt;
155 double w2 =
static_cast<double>(j) / number_of_points_sqrt;
157 double Q = 2 * w2 * CGAL_PI;
158 double angle = atan(R / length_of_normal);
159 double weight = exp(-0.5 * (pow(angle / angle_st_dev, 2)));
160 *out_it++ = Tuple(R * cos(Q), R * sin(Q), weight);
193 template<
class Tuple>
194 class Concentric_disk_sampling
208 template<
class OutputIterator>
209 void operator()(
int number_of_points,
211 OutputIterator out_it)
const
213 const int number_of_points_sqrt =
static_cast<int>(std::sqrt(
214 static_cast<double>(number_of_points)));
215 const double length_of_normal = 1.0 / tan(cone_angle / 2.0);
216 const double fraction = (number_of_points_sqrt == 1) ? 0.0
217 : 2.0 / (number_of_points_sqrt -1);
219 const double angle_st_dev = cone_angle / CGAL_ANGLE_ST_DEV_DIVIDER;
221 for(
int i = 0; i < number_of_points_sqrt; ++i)
222 for(
int j = 0; j < number_of_points_sqrt; ++j)
224 double w1 = -1 + i * fraction;
225 double w2 = -1 + j * fraction;
227 if(w1 == 0 && w2 == 0)
233 if(w1 > w2) { R = w1; Q = (w2 / w1); }
234 else { R = w2; Q = (2 - w1 / w2); }
238 if(w1 < w2) { R = -w1; Q = (4 + w2 / w1); }
239 else { R = -w2; Q = (6 - w1 / w2); }
241 Q *= (CGAL_PI / 4.0);
242 double angle = atan(R / length_of_normal);
243 double weight = exp(-0.5 * (pow(angle / angle_st_dev, 2)));
244 *out_it++ = Tuple(R * cos(Q), R * sin(Q), weight);
252 #undef CGAL_ANGLE_ST_DEV_DIVIDER
253 #endif //CGAL_SURFACE_MESH_SEGMENTATION_DISK_SAMPLERS_H