turn int to std::size_t when it is possible

This commit is contained in:
Sébastien Loriot 2013-12-13 15:10:31 +01:00
parent 172c6d4592
commit 61c91a1971
21 changed files with 200 additions and 197 deletions

View File

@ -286,7 +286,7 @@ void Polyhedron_demo_mesh_segmentation_plugin::check_and_set_ids(Polyhedron* pol
Polyhedron::Facet_iterator a_facet = polyhedron->facets_begin();
Polyhedron::Facet_iterator another_facet = ++polyhedron->facets_begin();
if(a_facet->id() != another_facet->id()) { return; } // ids are OK
int facet_id = 0;
std::size_t facet_id = 0;
for(Polyhedron::Facet_iterator facet_it = polyhedron->facets_begin();
facet_it != polyhedron->facets_end(); ++facet_it, ++facet_id)
{
@ -302,7 +302,7 @@ void Polyhedron_demo_mesh_segmentation_plugin::colorize_sdf(
{
Polyhedron* polyhedron = item->polyhedron();
color_vector.clear();
int patch_id = 0;
std::size_t patch_id = 0;
for(Polyhedron::Facet_iterator facet_it = polyhedron->facets_begin();
facet_it != polyhedron->facets_end(); ++facet_it, ++patch_id)
{
@ -326,15 +326,15 @@ void Polyhedron_demo_mesh_segmentation_plugin::colorize_segmentation(
{
Polyhedron* polyhedron = item->polyhedron();
color_vector.clear();
int max_segment = 0;
std::size_t max_segment = 0;
for(Polyhedron::Facet_iterator facet_it = polyhedron->facets_begin();
facet_it != polyhedron->facets_end(); ++facet_it)
{
int segment_id = segment_ids[facet_it];
std::size_t segment_id = segment_ids[facet_it];
facet_it->set_patch_id(segment_id);
max_segment = (std::max)(max_segment, segment_id);
}
for(int i = 0; i <= max_segment; ++i)
for(std::size_t i = 0; i <= max_segment; ++i)
{
QColor aColor = color_map_segmentation[(max_segment - i) % color_map_segmentation.size()];
color_vector.push_back(aColor);

View File

@ -32,7 +32,7 @@ int main()
// It is possible to compute the raw SDF values and post-process them using
// the following lines:
// const int number_of_rays = 25; // cast 25 rays per facet
// const std::size_t number_of_rays = 25; // cast 25 rays per facet
// const double cone_angle = 2.0 / 3.0 * CGAL_PI; // set cone opening-angle
// CGAL::sdf_values(mesh, sdf_property_map, cone_angle, number_of_rays, false);
// std::pair<double, double> min_max_sdf =

View File

@ -30,13 +30,13 @@ int main()
CGAL::sdf_values(mesh, sdf_property_map);
// create a property-map for segment-ids
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
Facet_int_map internal_segment_map;
boost::associative_property_map<Facet_int_map> segment_property_map(internal_segment_map);
// segment the mesh using default parameters for number of levels, and smoothing lambda
// Any other scalar values can be used instead of using SDF values computed using the CGAL function
int number_of_segments = CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map);
std::size_t number_of_segments = CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map);
std::cout << "Number of segments: " << number_of_segments << std::endl;
// print segment-ids
@ -47,7 +47,7 @@ int main()
}
std::cout << std::endl;
const int number_of_clusters = 4; // use 4 clusters in soft clustering
const std::size_t number_of_clusters = 4; // use 4 clusters in soft clustering
const double smoothing_lambda = 0.3; // importance of surface features, suggested to be in-between [0,1]
// Note that we can use the same SDF values (sdf_property_map) over and over again for segmentation.

View File

@ -22,12 +22,12 @@ int main()
}
// create a property-map for segment-ids
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
Facet_int_map internal_segment_map;
boost::associative_property_map<Facet_int_map> segment_property_map(internal_segment_map);
// calculate SDF values and segment the mesh using default parameters.
int number_of_segments = CGAL::segmentation_via_sdf_values(mesh, segment_property_map);
std::size_t number_of_segments = CGAL::segmentation_via_sdf_values(mesh, segment_property_map);
std::cout << "Number of segments: " << number_of_segments << std::endl;

View File

@ -45,7 +45,7 @@ int main()
}
// assign id field for each facet
int facet_id = 0;
std::size_t facet_id = 0;
for(Polyhedron::Facet_iterator facet_it = mesh.facets_begin();
facet_it != mesh.facets_end(); ++facet_it, ++facet_id) {
facet_it->id() = facet_id;
@ -65,8 +65,8 @@ int main()
std::cout << std::endl;
// create a property-map for segment-ids
std::vector<int> segment_ids(mesh.size_of_facets());
Facet_with_id_pmap<int> segment_property_map(segment_ids);
std::vector<std::size_t> segment_ids(mesh.size_of_facets());
Facet_with_id_pmap<std::size_t> segment_property_map(segment_ids);
CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map);

View File

@ -165,10 +165,11 @@ public:
* and as output it returns final labeling of vertices (i.e. assigned cluster-id to each facet)
* @return result of energy function
*/
double operator()(const std::vector<std::pair<int, int> >& edges,
double operator()(const std::vector<std::pair<std::size_t, std::size_t> >&
edges,
const std::vector<double>& edge_weights,
const std::vector<std::vector<double> >& probability_matrix,
std::vector<int>& labels) const {
std::vector<std::size_t>& labels) const {
const double tolerance = 1e-10;
double min_cut = (std::numeric_limits<double>::max)();
@ -185,7 +186,7 @@ public:
bool success;
do {
success = false;
int alpha = 0;
std::size_t alpha = 0;
for(std::vector<std::vector<double> >::const_iterator it =
probability_matrix.begin();
@ -217,12 +218,12 @@ public:
// For E-Smooth
// add edge between every vertex,
std::vector<double>::const_iterator weight_it = edge_weights.begin();
for(std::vector<std::pair<int, int> >::const_iterator edge_it = edges.begin();
edge_it != edges.end();
for(std::vector<std::pair<std::size_t, std::size_t> >::const_iterator edge_it =
edges.begin(); edge_it != edges.end();
++edge_it, ++weight_it) {
Vertex_descriptor v1 = inserted_vertices[edge_it->first],
v2 = inserted_vertices[edge_it->second];
int label_1 = labels[edge_it->first], label_2 = labels[edge_it->second];
std::size_t label_1 = labels[edge_it->first], label_2 = labels[edge_it->second];
if(label_1 == label_2) {
if(label_1 != alpha) {
add_edge_and_reverse(v1, v2, *weight_it, *weight_it, graph);
@ -315,8 +316,8 @@ private:
typedef Traits::edge_iterator Edge_iterator;
void
add_edge_and_reverse(int v1 , int v2, double w1, double w2,
std::vector<std::pair<int, int> >& edge_map,
add_edge_and_reverse(std::size_t v1 , std::size_t v2, double w1, double w2,
std::vector<std::pair<std::size_t, std::size_t> >& edge_map,
std::vector<EdgeP>& edge_weights) const {
edge_map.push_back(std::make_pair(v1, v2));
EdgeP p1;
@ -339,10 +340,11 @@ public:
* and as output it returns final labeling of vertices (i.e. assigned cluster-id to each facet)
* @return result of energy function
*/
double operator()(const std::vector<std::pair<int, int> >& edges,
double operator()(const std::vector<std::pair<std::size_t, std::size_t> >&
edges,
const std::vector<double>& edge_weights,
const std::vector<std::vector<double> >& probability_matrix,
std::vector<int>& labels) const {
std::vector<std::size_t>& labels) const {
const double tolerance = 1e-10;
double min_cut = (std::numeric_limits<double>::max)();
@ -358,19 +360,19 @@ public:
bool success;
do {
success = false;
int alpha = 0;
std::size_t alpha = 0;
for(std::vector<std::vector<double> >::const_iterator it =
probability_matrix.begin();
it != probability_matrix.end(); ++it, ++alpha) {
std::vector<std::pair<int, int> > edge_map;
std::vector<std::pair<std::size_t, std::size_t> > edge_map;
std::vector<EdgeP> edge_map_weights;
edge_map.reserve(labels.size() *
8); // there is no way to know exact edge count, it is a heuristic value
edge_map_weights.reserve(labels.size() * 8);
int cluster_source = 0;
int cluster_sink = 1;
std::size_t cluster_source = 0;
std::size_t cluster_sink = 1;
Timer timer;
timer.start();
@ -384,29 +386,29 @@ public:
(std::numeric_limits<double>::max)()
: probability_matrix[labels[vertex_i]][vertex_i];
add_edge_and_reverse(cluster_source, static_cast<int>(vertex_i) + 2,
source_weight, 0.0, edge_map, edge_map_weights);
add_edge_and_reverse(static_cast<int>(vertex_i) + 2, cluster_sink, sink_weight,
0.0, edge_map, edge_map_weights);
add_edge_and_reverse(cluster_source, vertex_i + 2, source_weight, 0.0, edge_map,
edge_map_weights);
add_edge_and_reverse(vertex_i + 2, cluster_sink, sink_weight, 0.0, edge_map,
edge_map_weights);
}
vertex_creation_time += timer.time();
timer.reset();
// For E-Smooth
// add edge between every vertex,
int num_vert = static_cast<int>(labels.size()) + 2;
std::size_t num_vert = labels.size() + 2;
std::vector<double>::const_iterator weight_it = edge_weights.begin();
for(std::vector<std::pair<int, int> >::const_iterator edge_it = edges.begin();
edge_it != edges.end();
for(std::vector<std::pair<std::size_t, std::size_t> >::const_iterator edge_it =
edges.begin(); edge_it != edges.end();
++edge_it, ++weight_it) {
int v1 = edge_it->first + 2, v2 = edge_it->second + 2;
int label_1 = labels[edge_it->first], label_2 = labels[edge_it->second];
std::size_t v1 = edge_it->first + 2, v2 = edge_it->second + 2;
std::size_t label_1 = labels[edge_it->first], label_2 = labels[edge_it->second];
if(label_1 == label_2) {
if(label_1 != alpha) {
add_edge_and_reverse(v1, v2, *weight_it, *weight_it, edge_map,
edge_map_weights);
}
} else {
int inbetween = num_vert++;
std::size_t inbetween = num_vert++;
double w1 = (label_1 == alpha) ? 0 : *weight_it;
double w2 = (label_2 == alpha) ? 0 : *weight_it;
@ -524,10 +526,11 @@ public:
* and as output it returns final labeling of vertices
* @return result of energy function
*/
double operator()(const std::vector<std::pair<int, int> >& edges,
double operator()(const std::vector<std::pair<std::size_t, std::size_t> >&
edges,
const std::vector<double>& edge_weights,
const std::vector<std::vector<double> >& probability_matrix,
std::vector<int>& labels) const {
std::vector<std::size_t>& labels) const {
const double tolerance = 1e-10;
double min_cut = (std::numeric_limits<double>::max)();
@ -541,7 +544,7 @@ public:
bool success;
do {
success = false;
int alpha = 0;
std::size_t alpha = 0;
for(std::vector<std::vector<double> >::const_iterator it =
probability_matrix.begin();
it != probability_matrix.end(); ++it, ++alpha) {
@ -567,12 +570,12 @@ public:
// For E-Smooth
// add edge between every vertex,
std::vector<double>::const_iterator weight_it = edge_weights.begin();
for(std::vector<std::pair<int, int> >::const_iterator edge_it = edges.begin();
edge_it != edges.end();
for(std::vector<std::pair<std::size_t, std::size_t> >::const_iterator edge_it =
edges.begin(); edge_it != edges.end();
++edge_it, ++weight_it) {
MaxFlow::Graph::node_id v1 = inserted_vertices[edge_it->first];
MaxFlow::Graph::node_id v2 = inserted_vertices[edge_it->second];
int label_1 = labels[edge_it->first], label_2 = labels[edge_it->second];
std::size_t label_1 = labels[edge_it->first], label_2 = labels[edge_it->second];
if(label_1 == label_2) {
if(label_1 != alpha) {
graph.add_edge(v1, v2, *weight_it, *weight_it);

View File

@ -64,12 +64,12 @@ public:
* - weight (proportional to distance from disk center)
*/
template<class OutputIterator>
void operator()(int number_of_points,
void operator()(std::size_t number_of_points,
OutputIterator out_it) const {
const double golden_ratio = 3.0 - std::sqrt(5.0);
if(uniform) {
for(int i = 0; i < number_of_points; ++i) {
for(std::size_t i = 0; i < number_of_points; ++i) {
double Q = i * golden_ratio * CGAL_PI;
double R = std::sqrt(static_cast<double>(i) / number_of_points);
double weight = exp(-0.5 * (std::pow(R / CGAL_ANGLE_ST_DEV_DIVIDER, 2)));
@ -79,7 +79,7 @@ public:
const double custom_power =
1.0; // it determines how much sampling is biased to center
// for uniform result one can use 0.5 (i.e. sqrt)
for(int i = 0; i < number_of_points; ++i) {
for(std::size_t i = 0; i < number_of_points; ++i) {
double Q = i * golden_ratio * CGAL_PI;
double R = std::pow(static_cast<double>(i) / number_of_points, custom_power);
// use uniform weigths, since we already give importance to locations that are close to center.
@ -134,14 +134,14 @@ public:
* Note: returned samples size = \f$ \lfloor \sqrt {number\_of\_points} \rfloor ^ 2 \f$
*/
template<class OutputIterator>
void operator()(int number_of_points,
void operator()(std::size_t number_of_points,
OutputIterator out_it) const {
const int number_of_points_sqrt = static_cast<int>(std::sqrt(
static_cast<double>(number_of_points)));
const std::size_t number_of_points_sqrt = static_cast<std::size_t>(std::sqrt(
static_cast<double>(number_of_points)));
// use cone_angle / 3 as one standard deviation while weighting.
for(int i = 1; i <= number_of_points_sqrt; ++i)
for(int j = 1; j <= number_of_points_sqrt; ++j) {
for(std::size_t i = 1; i <= number_of_points_sqrt; ++i)
for(std::size_t j = 1; j <= number_of_points_sqrt; ++j) {
double w1 = static_cast<double>(i) / number_of_points_sqrt;
double w2 = static_cast<double>(j) / number_of_points_sqrt;
double R = w1;
@ -197,15 +197,15 @@ public:
* Note: returned samples size = \f$ \lfloor \sqrt {number\_of\_points} \rfloor ^ 2 \f$
*/
template<class OutputIterator>
void operator()(int number_of_points,
void operator()(std::size_t number_of_points,
OutputIterator out_it) const {
const int number_of_points_sqrt = static_cast<int>(std::sqrt(
static_cast<double>(number_of_points)));
const std::size_t number_of_points_sqrt = static_cast<std::size_t>(std::sqrt(
static_cast<double>(number_of_points)));
const double fraction = (number_of_points_sqrt == 1) ? 0.0
: 2.0 / (number_of_points_sqrt -1);
for(int i = 0; i < number_of_points_sqrt; ++i)
for(int j = 0; j < number_of_points_sqrt; ++j) {
for(std::size_t i = 0; i < number_of_points_sqrt; ++i)
for(std::size_t j = 0; j < number_of_points_sqrt; ++j) {
double w1 = -1 + i * fraction;
double w2 = -1 + j * fraction;
double R, Q;

View File

@ -91,7 +91,7 @@ private:
std::vector<std::vector<double> > responsibility_matrix;
double threshold;
int maximum_iteration;
std::size_t maximum_iteration;
Initialization_types init_type;
@ -116,9 +116,9 @@ public:
Expectation_maximization(std::size_t number_of_centers,
const std::vector<double>& data,
Initialization_types init_type = PLUS_INITIALIZATION,
int number_of_runs = CGAL_DEFAULT_NUMBER_OF_RUN,
std::size_t number_of_runs = CGAL_DEFAULT_NUMBER_OF_RUN,
double threshold = CGAL_DEFAULT_THRESHOLD,
int maximum_iteration = CGAL_DEFAULT_MAXIMUM_ITERATION )
std::size_t maximum_iteration = CGAL_DEFAULT_MAXIMUM_ITERATION )
:
final_likelihood(-(std::numeric_limits<double>::max)()), points(data),
responsibility_matrix(std::vector<std::vector<double> >(number_of_centers,
@ -152,12 +152,12 @@ public:
* Fills data_center by the id of the center which has maximum responsibility.
* @param[out] data_centers
*/
void fill_with_center_ids(std::vector<int>& data_centers) {
void fill_with_center_ids(std::vector<std::size_t>& data_centers) {
data_centers.reserve(points.size());
for(std::vector<double>::iterator point_it = points.begin();
point_it != points.end(); ++point_it) {
double max_likelihood = 0.0;
int max_center = -1, center_counter = 0;
std::size_t max_center = -1, center_counter = 0;
for(std::vector<Gaussian_center>::iterator center_it = centers.begin();
center_it != centers.end(); ++center_it, ++center_counter) {
double likelihood = center_it->probability_with_coef(*point_it);
@ -203,16 +203,16 @@ private:
}
// calculate deviation
std::vector<int> member_count(centers.size(), 0);
std::vector<std::size_t> member_count(centers.size(), 0);
for(std::vector<double>::iterator it = points.begin(); it!= points.end();
++it) {
int closest_center = 0;
std::size_t closest_center = 0;
double min_distance = std::abs(centers[0].mean - *it);
for(std::size_t i = 1; i < centers.size(); ++i) {
double distance = std::abs(centers[i].mean - *it);
if(distance < min_distance) {
min_distance = distance;
closest_center = static_cast<int>(i);
closest_center = i;
}
}
member_count[closest_center]++;
@ -338,7 +338,7 @@ private:
*/
double calculate_clustering() {
double likelihood = -(std::numeric_limits<double>::max)(), prev_likelihood;
int iteration_count = 0;
std::size_t iteration_count = 0;
double is_converged = false;
while(!is_converged && iteration_count++ < maximum_iteration) {
prev_likelihood = likelihood;
@ -360,7 +360,7 @@ private:
* @see calculate_clustering()
*/
void calculate_clustering_with_multiple_run(std::size_t number_of_centers,
int number_of_run) {
std::size_t number_of_run) {
std::vector<Gaussian_center> max_centers;
while(number_of_run-- > 0) {

View File

@ -45,7 +45,7 @@ public:
*/
template<class ValuePropertyMap>
void operator()(const Polyhedron& mesh,
int window_size,
std::size_t window_size,
ValuePropertyMap values,
boost::optional<double> spatial_parameter = boost::optional<double>(),
boost::optional<double> range_parameter = boost::optional<double>()
@ -65,7 +65,7 @@ public:
for(Facet_const_iterator facet_it = mesh.facets_begin();
facet_it != mesh.facets_end(); ++facet_it) {
std::map<Facet_const_handle, int> neighbors;
std::map<Facet_const_handle, std::size_t> neighbors;
NeighborSelector()(facet_it, window_size,
neighbors); // gather neighbors in the window
double current_sdf_value = values[facet_it];
@ -74,8 +74,8 @@ public:
if(!range_parameter) {
// calculate deviation for range weighting.
double deviation = 0.0;
for(typename std::map<Facet_const_handle, int>::iterator it = neighbors.begin();
it != neighbors.end(); ++it) {
for(typename std::map<Facet_const_handle, std::size_t>::iterator it =
neighbors.begin(); it != neighbors.end(); ++it) {
deviation += std::pow(values[it->first] - current_sdf_value, 2);
}
deviation = std::sqrt(deviation / neighbors.size());
@ -92,8 +92,8 @@ public:
// smooth
double total_sdf_value = 0.0, total_weight = 0.0;
for(typename std::map<Facet_const_handle, int>::iterator it = neighbors.begin();
it != neighbors.end(); ++it) {
for(typename std::map<Facet_const_handle, std::size_t>::iterator it =
neighbors.begin(); it != neighbors.end(); ++it) {
double spatial_weight = gaussian_function(it->second, spatial_parameter_actual);
double range_weight = gaussian_function(values[it->first] - current_sdf_value,
range_parameter_actual);
@ -135,7 +135,7 @@ public:
*/
template<class ValuePropertyMap>
void operator()(const Polyhedron& mesh,
int window_size,
std::size_t window_size,
ValuePropertyMap values) const {
typedef typename Polyhedron::Facet_const_handle Facet_const_handle;
typedef typename Polyhedron::Facet_const_iterator Facet_const_iterator;
@ -144,14 +144,14 @@ public:
smoothed_values.reserve(mesh.size_of_facets());
for(Facet_const_iterator facet_it = mesh.facets_begin();
facet_it != mesh.facets_end(); ++facet_it) {
std::map<Facet_const_handle, int> neighbors;
std::map<Facet_const_handle, std::size_t> neighbors;
NeighborSelector()(facet_it, window_size,
neighbors); // gather neighbors in the window
std::vector<double> neighbor_values;
neighbor_values.reserve(neighbors.size());
for(typename std::map<Facet_const_handle, int>::iterator it = neighbors.begin();
it != neighbors.end(); ++it) {
for(typename std::map<Facet_const_handle, std::size_t>::iterator it =
neighbors.begin(); it != neighbors.end(); ++it) {
neighbor_values.push_back(values[it->first]);
}
// Find median.
@ -183,22 +183,22 @@ struct No_filtering {
*/
template<class Polyhedron,class ValuePropertyMap>
void operator()(const Polyhedron& /* mesh */,
int /* window_size */,
std::size_t /* window_size */,
ValuePropertyMap /* values */) const {
}
};
/** @brief A filter that applies the filter passed as template parameter several times. */
template <class Filter, int nb_iterations = 5>
template <class Filter, std::size_t nb_iterations = 5>
struct Iterative_filter : public Filter {
/**
* empty implementation of required operator.
*/
template<class Polyhedron,class ValuePropertyMap>
void operator()(const Polyhedron& mesh ,
int window_size ,
std::size_t window_size ,
ValuePropertyMap values ) const {
for (int i=0; i<nb_iterations; ++i)
for (std::size_t i=0; i<nb_iterations; ++i)
Filter::operator()(mesh, window_size, values);
}
};
@ -219,9 +219,9 @@ public:
* @param[out] neighbors visited facets and their distances to root facet
*/
void operator()(Facet_const_handle facet,
int max_level,
std::map<Facet_const_handle, int>& neighbors) const {
typedef std::pair<Facet_const_handle, int> Facet_level_pair;
std::size_t max_level,
std::map<Facet_const_handle, std::size_t>& neighbors) const {
typedef std::pair<Facet_const_handle, std::size_t> Facet_level_pair;
std::queue<Facet_level_pair> facet_queue;
facet_queue.push(Facet_level_pair(facet, 0));
@ -272,9 +272,9 @@ public:
* @param[out] neighbors visited facets and their distances to root facet
*/
void operator()(Facet_const_handle facet,
int max_level,
std::map<Facet_const_handle, int>& neighbors) const {
typedef std::pair<Facet_const_handle, int> Facet_level_pair;
std::size_t max_level,
std::map<Facet_const_handle, std::size_t>& neighbors) const {
typedef std::pair<Facet_const_handle, std::size_t> Facet_level_pair;
std::queue<Facet_level_pair> facet_queue;
facet_queue.push(Facet_level_pair(facet, 0));

View File

@ -103,7 +103,7 @@ public:
// say, "distance_square" -> [ 0.1, 0.2, 0.3, 0.0, 0.2 ... ]
// then distance_square_cumulative -> [ 0.1, 0.3, 0.6, 0.6, 0.8 ... ]
std::size_t initial_index = random.get_int(0,
static_cast<int>(points.size())); // [0, points size)
points.size()); // [0, points size)
centers.push_back(points[initial_index]);
for(std::size_t i = 1; i < number_of_centers; ++i) {
@ -149,8 +149,8 @@ class K_means_point
{
public:
double data; /**< Location of the point */
int center_id; /**< Closest center to the point */
K_means_point(double data, int center_id = -1) : data(data),
std::size_t center_id; /**< Closest center to the point */
K_means_point(double data, std::size_t center_id = -1) : data(data),
center_id(center_id) {
}
@ -171,7 +171,7 @@ public:
double mean; /**< Mean of the center */
private:
double new_mean;
int new_number_of_points;
std::size_t new_number_of_points;
bool empty;
public:
@ -231,12 +231,12 @@ public:
inline bool K_means_point::calculate_new_center(std::vector<K_means_center>&
centers)
{
int new_center_id = 0;
std::size_t new_center_id = 0;
double min_distance = std::abs(centers[0].mean - data);
for(std::size_t i = 1; i < centers.size(); ++i) {
double new_distance = std::abs(centers[i].mean - data);
if(new_distance < min_distance) {
new_center_id = static_cast<int>(i);
new_center_id = i;
min_distance = new_distance;
}
}
@ -264,7 +264,7 @@ public:
private:
std::vector<K_means_center> centers;
std::vector<K_means_point> points;
int maximum_iteration;
std::size_t maximum_iteration;
Initialization_types init_type;
@ -287,8 +287,8 @@ public:
K_means_clustering(std::size_t number_of_centers,
const std::vector<double>& data,
Initialization_types init_type = PLUS_INITIALIZATION,
int number_of_run = CGAL_DEFAULT_NUMBER_OF_RUN,
int maximum_iteration = CGAL_DEFAULT_MAXIMUM_ITERATION)
std::size_t number_of_run = CGAL_DEFAULT_NUMBER_OF_RUN,
std::size_t maximum_iteration = CGAL_DEFAULT_MAXIMUM_ITERATION)
:
points(data.begin(), data.end()),
maximum_iteration(maximum_iteration),
@ -305,7 +305,7 @@ public:
* Fills data_center by the id of the closest center for each point.
* @param[out] data_centers
*/
void fill_with_center_ids(std::vector<int>& data_centers) {
void fill_with_center_ids(std::vector<std::size_t>& data_centers) {
data_centers.reserve(points.size());
for(std::vector<K_means_point>::iterator point_it = points.begin();
point_it != points.end(); ++point_it) {
@ -367,7 +367,7 @@ private:
* Iterates until convergence occurs (i.e. no point changes its center) or maximum iteration limit is reached.
*/
void calculate_clustering() {
int iteration_count = 0;
std::size_t iteration_count = 0;
bool any_center_changed = true;
while(any_center_changed && iteration_count++ < maximum_iteration) {
any_center_changed = iterate();
@ -382,7 +382,7 @@ private:
* @see calculate_clustering(), within_cluster_sum_of_squares()
*/
void calculate_clustering_with_multiple_run(std::size_t number_of_centers,
int number_of_run) {
std::size_t number_of_run) {
std::vector<K_means_center> min_centers;
double error = (std::numeric_limits<double>::max)();
while(number_of_run-- > 0) {

View File

@ -182,7 +182,7 @@ public:
InputIterator facet_begin,
InputIterator facet_end,
double cone_angle,
int number_of_rays,
std::size_t number_of_rays,
FacetValueMap sdf_values,
DiskSampling disk_sampler) const {
Disk_samples_list disk_samples;
@ -208,7 +208,7 @@ public:
InputIterator facet_begin,
InputIterator facet_end,
double cone_angle,
int number_of_rays,
std::size_t number_of_rays,
FacetValueMap sdf_values) const {
calculate_sdf_values(facet_begin, facet_end, cone_angle, number_of_rays,
sdf_values, Default_sampler());
@ -228,7 +228,7 @@ public:
SkipPrimitiveFunctor skip,
FirstIntersectionVisitor visitor,
double cone_angle,
int number_of_rays,
std::size_t number_of_rays,
bool accept_if_acute) const {
return calculate_sdf_value_of_point(center, normal, skip, visitor, cone_angle,
number_of_rays, accept_if_acute,
@ -245,7 +245,7 @@ public:
SkipPrimitiveFunctor skip,
FirstIntersectionVisitor visitor,
double cone_angle,
int number_of_rays,
std::size_t number_of_rays,
bool accept_if_acute,
DiskSampling disk_sampler) const {
Disk_samples_list disk_samples;
@ -466,7 +466,7 @@ private:
std::vector<std::pair<double, double> >& ray_distances) const {
// pair first -> distance, second -> weight
const int accepted_ray_count = static_cast<int>(ray_distances.size());
const std::size_t accepted_ray_count = ray_distances.size();
if(accepted_ray_count == 0) {
return 0.0;
} else if(accepted_ray_count == 1) {
@ -474,7 +474,7 @@ private:
}
/* Calculate median sdf */
const int half_ray_count = accepted_ray_count / 2;
const std::size_t half_ray_count = accepted_ray_count / 2;
std::nth_element(ray_distances.begin(), ray_distances.begin() + half_ray_count,
ray_distances.end());
double median_sdf = ray_distances[half_ray_count].first;

View File

@ -78,7 +78,7 @@ public:
typename Facet::Halfedge_around_facet_const_circulator facet_circulator =
facet_it->facet_begin();
double total_neighbor_sdf = 0.0;
int nb_valid_neighbors = 0;
std::size_t nb_valid_neighbors = 0;
do {
if(!facet_circulator->opposite()->is_border()) {
double neighbor_sdf = sdf_values[facet_circulator->opposite()->facet()];
@ -152,9 +152,9 @@ public:
* - 8000-18000 -> 3
* - ...
*/
int get_window_size(const Polyhedron& mesh) {
std::size_t get_window_size(const Polyhedron& mesh) {
double facet_sqrt = std::sqrt(mesh.size_of_facets() / 2000.0);
return static_cast<int>(facet_sqrt) + 1;
return static_cast<std::size_t>(facet_sqrt) + 1;
}
};
@ -227,7 +227,7 @@ public:
// Use these two functions together
template <class SDFPropertyMap>
std::pair<double, double>
calculate_sdf_values(double cone_angle, int number_of_rays,
calculate_sdf_values(double cone_angle, std::size_t number_of_rays,
SDFPropertyMap sdf_pmap, bool postprocess_req) {
// calculate sdf values
SDF_calculation_class sdf_calculator(mesh, false, true, traits);
@ -241,9 +241,9 @@ public:
}
template <class FacetSegmentMap, class SDFPropertyMap>
int partition(std::size_t number_of_centers, double smoothing_lambda,
SDFPropertyMap sdf_pmap, FacetSegmentMap segment_pmap,
bool clusters_to_segments) {
std::size_t partition(std::size_t number_of_centers, double smoothing_lambda,
SDFPropertyMap sdf_pmap, FacetSegmentMap segment_pmap,
bool clusters_to_segments) {
smoothing_lambda = (std::max)(0.0, smoothing_lambda); // min zero
smoothing_lambda *=
CGAL_SMOOTHING_LAMBDA_MULTIPLIER; // scale it into meaningful range for graph-cut
@ -256,7 +256,7 @@ public:
Expectation_maximization fitter(number_of_centers, sdf_values,
Expectation_maximization::K_MEANS_INITIALIZATION, 1);
std::vector<int> labels;
std::vector<std::size_t> labels;
fitter.fill_with_center_ids(labels);
std::vector<std::vector<double> > probability_matrix;
@ -264,14 +264,14 @@ public:
log_normalize_probability_matrix(probability_matrix);
// calculating edge weights
std::vector<std::pair<int, int> > edges;
std::vector<std::pair<std::size_t, std::size_t> > edges;
std::vector<double> edge_weights;
calculate_and_log_normalize_dihedral_angles(smoothing_lambda, edges,
edge_weights);
// apply graph cut
GraphCut()(edges, edge_weights, probability_matrix, labels);
std::vector<int>::iterator label_it = labels.begin();
std::vector<std::size_t>::iterator label_it = labels.begin();
for(Facet_const_iterator facet_it = mesh.facets_begin();
facet_it != mesh.facets_end();
++facet_it, ++label_it) {
@ -279,8 +279,8 @@ public:
}
if(clusters_to_segments) {
// assign a segment id for each facet
int number_of_segments = assign_segments(number_of_centers, sdf_pmap,
segment_pmap);
std::size_t number_of_segments = assign_segments(number_of_centers, sdf_pmap,
segment_pmap);
return number_of_segments;
}
return number_of_centers;
@ -361,14 +361,14 @@ private:
* @param[out] edge_weights calculated weight for each edge in @a edges
*/
void calculate_and_log_normalize_dihedral_angles(double smoothing_lambda,
std::vector<std::pair<int, int> >& edges,
std::vector<std::pair<std::size_t, std::size_t> >& edges,
std::vector<double>& edge_weights) const {
// associate each facet with an id
// important note: ids should be compatible with iteration order of facets:
// [0 <- facet_begin(),...., size_of_facets() -1 <- facet_end()]
// Why ? it is send to graph cut algorithm where other data associated with facets are also sorted according to iteration order.
std::map<Facet_const_handle, int> facet_index_map;
int facet_index = 0;
std::map<Facet_const_handle, std::size_t> facet_index_map;
std::size_t facet_index = 0;
for(Facet_const_iterator facet_it = mesh.facets_begin();
facet_it != mesh.facets_end();
++facet_it, ++facet_index) {
@ -376,14 +376,14 @@ private:
}
const double epsilon = 5e-6;
// edges and their weights. pair<int, int> stores facet-id pairs (see above) (may be using boost::tuple can be more suitable)
// edges and their weights. pair<std::size_t, std::size_t> stores facet-id pairs (see above) (may be using boost::tuple can be more suitable)
for(Edge_const_iterator edge_it = mesh.edges_begin();
edge_it != mesh.edges_end(); ++edge_it) {
if(edge_it->is_border_edge()) {
continue; // if edge does not contain two neighbor facets then do not include it in graph-cut
}
const int index_f1 = facet_index_map[edge_it->facet()];
const int index_f2 = facet_index_map[edge_it->opposite()->facet()];
const std::size_t index_f1 = facet_index_map[edge_it->facet()];
const std::size_t index_f2 = facet_index_map[edge_it->opposite()->facet()];
edges.push_back(std::make_pair(index_f1, index_f2));
double angle = calculate_dihedral_angle_of_edge(edge_it);
@ -418,15 +418,15 @@ private:
*
* @param number_of_clusters cluster-ids in @a segments should be between [0, number_of_clusters -1]
* @param sdf_values `ReadablePropertyMap` with `Polyhedron::Facet_const_handle` as key and `double` as value type
* @param[in, out] segments `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `int` as value type.
* @param[in, out] segments `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `std::size_t` as value type.
* @return number of segments
*/
template<class SegmentPropertyMap, class SDFProperyMap>
int assign_segments(int number_of_clusters, SDFProperyMap sdf_values,
SegmentPropertyMap segments) {
std::size_t assign_segments(std::size_t number_of_clusters,
SDFProperyMap sdf_values, SegmentPropertyMap segments) {
// assign a segment-id to each facet
int segment_id = number_of_clusters;
std::vector<std::pair<int, double> > segments_with_average_sdf_values;
std::size_t segment_id = number_of_clusters;
std::vector<std::pair<std::size_t, double> > segments_with_average_sdf_values;
for(Facet_const_iterator facet_it = mesh.facets_begin();
facet_it != mesh.facets_end(); ++facet_it) {
@ -443,21 +443,21 @@ private:
// sort segments according to their average sdf value
sort(segments_with_average_sdf_values.begin(),
segments_with_average_sdf_values.end(),
Sort_pairs_with_second<std::pair<int, double> >());
Sort_pairs_with_second<std::pair<std::size_t, double> >());
// map each segment-id to its new sorted index
std::vector<int> segment_id_to_sorted_id_map(
std::vector<std::size_t> segment_id_to_sorted_id_map(
segments_with_average_sdf_values.size());
for(std::size_t index = 0; index < segments_with_average_sdf_values.size();
++index) {
int segment_id = segments_with_average_sdf_values[index].first -
number_of_clusters;
segment_id_to_sorted_id_map[segment_id] = static_cast<int>(index);
std::size_t segment_id = segments_with_average_sdf_values[index].first -
number_of_clusters;
segment_id_to_sorted_id_map[segment_id] = index;
}
// make one-pass on facets. First make segment-id zero based by subtracting number_of_clusters
// . Then place its sorted index to pmap
for(Facet_const_iterator facet_it = mesh.facets_begin();
facet_it != mesh.facets_end(); ++facet_it) {
int segment_id = segments[facet_it] - number_of_clusters;
std::size_t segment_id = segments[facet_it] - number_of_clusters;
segments[facet_it] = segment_id_to_sorted_id_map[segment_id];
}
return segment_id - number_of_clusters;
@ -469,21 +469,21 @@ private:
* @param facet root facet
* @param segment_id segment-id of root facet
* @param sdf_values `ReadablePropertyMap` with `Polyhedron::Facet_const_handle` as key and `double` as value type
* @param[in, out] segments `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `int` as value type.
* @param[in, out] segments `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `std::size_t` as value type.
* @return average sdf value for segment
*/
template<class SegmentPropertyMap, class SDFProperyMap>
double
breadth_first_traversal(Facet_const_handle root, int segment_id,
breadth_first_traversal(Facet_const_handle root, std::size_t segment_id,
SDFProperyMap sdf_values, SegmentPropertyMap segments) {
std::queue<Facet_const_handle> facet_queue;
facet_queue.push(root);
int prev_segment_id = segments[root];
std::size_t prev_segment_id = segments[root];
segments[root] = segment_id;
double total_sdf_value = sdf_values[root];
int visited_facet_count = 1;
std::size_t visited_facet_count = 1;
while(!facet_queue.empty()) {
Facet_const_handle facet = facet_queue.front();

View File

@ -23,7 +23,7 @@ std::pair<double, double>
sdf_values( const Polyhedron& polyhedron,
SDFPropertyMap sdf_values_map,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
std::size_t number_of_rays = 25,
bool postprocess = true,
GeomTraits traits = GeomTraits())
{
@ -66,7 +66,7 @@ std::pair<double, double>
sdf_values( const Polyhedron& polyhedron,
SDFPropertyMap sdf_values_map,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
std::size_t number_of_rays = 25,
bool postprocess = true,
GeomTraits traits = GeomTraits())
{
@ -131,7 +131,7 @@ sdf_values_postprocessing(const Polyhedron& polyhedron,
*
* @tparam Polyhedron a %CGAL polyhedron
* @tparam SDFPropertyMap a `ReadablePropertyMap` with `Polyhedron::Facet_const_handle` as key and `double` as value type
* @tparam SegmentPropertyMap a `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `int` as value type
* @tparam SegmentPropertyMap a `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `std::size_t` as value type
* @tparam GeomTraits a model of SegmentationGeomTraits
*
* @param polyhedron surface mesh corresponding to the SDF values
@ -150,11 +150,11 @@ template <class Polyhedron, class SDFPropertyMap, class SegmentPropertyMap,
= typename Polyhedron::Traits
#endif
>
int
std::size_t
segmentation_from_sdf_values( const Polyhedron& polyhedron,
SDFPropertyMap sdf_values_map,
SegmentPropertyMap segment_ids,
int number_of_clusters = 5,
std::size_t number_of_clusters = 5,
double smoothing_lambda = 0.26,
bool output_cluster_ids = false,
GeomTraits traits = GeomTraits())
@ -172,12 +172,12 @@ template < bool Fast_sdf_calculation_mode, class Polyhedron,
= typename Polyhedron::Traits
#endif
>
int
std::size_t
segmentation_via_sdf_values(const Polyhedron& polyhedron,
SegmentPropertyMap segment_ids,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
int number_of_clusters = 5,
std::size_t number_of_rays = 25,
std::size_t number_of_clusters = 5,
double smoothing_lambda = 0.26,
bool output_cluster_ids = false,
GeomTraits traits = GeomTraits())
@ -214,7 +214,7 @@ segmentation_via_sdf_values(const Polyhedron& polyhedron,
* @pre @a number_of_clusters > 0
*
* @tparam Polyhedron a %CGAL polyhedron
* @tparam SegmentPropertyMap a `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `int` as value type
* @tparam SegmentPropertyMap a `ReadWritePropertyMap` with `Polyhedron::Facet_const_handle` as key and `std::size_t` as value type
* @tparam GeomTraits a model of SegmentationGeomTraits
*
* @param polyhedron surface mesh on which SDF values are computed
@ -233,12 +233,12 @@ template < class Polyhedron, class SegmentPropertyMap, class GeomTraits
= typename Polyhedron::Traits
#endif
>
int
std::size_t
segmentation_via_sdf_values(const Polyhedron& polyhedron,
SegmentPropertyMap segment_ids,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
int number_of_clusters = 5,
std::size_t number_of_rays = 25,
std::size_t number_of_clusters = 5,
double smoothing_lambda = 0.26,
bool output_cluster_ids = false,
GeomTraits traits = GeomTraits())
@ -255,7 +255,7 @@ std::pair<double, double>
sdf_values(const Polyhedron& polyhedron,
SDFPropertyMap sdf_values_map,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
std::size_t number_of_rays = 25,
bool postprocess = true,
typename Polyhedron::Traits traits = typename Polyhedron::Traits())
{
@ -268,7 +268,7 @@ std::pair<double, double>
sdf_values( const Polyhedron& polyhedron,
SDFPropertyMap sdf_values_map,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
std::size_t number_of_rays = 25,
bool postprocess = true,
typename Polyhedron::Traits traits = typename Polyhedron::Traits())
{
@ -277,11 +277,11 @@ sdf_values( const Polyhedron& polyhedron,
}
template <class Polyhedron, class SDFPropertyMap, class SegmentPropertyMap>
int
std::size_t
segmentation_from_sdf_values(const Polyhedron& polyhedron,
SDFPropertyMap sdf_values_map,
SegmentPropertyMap segment_ids,
int number_of_clusters = 5,
std::size_t number_of_clusters = 5,
double smoothing_lambda = 0.26,
bool output_cluster_ids = false,
typename Polyhedron::Traits traits = typename Polyhedron::Traits())
@ -292,12 +292,12 @@ segmentation_from_sdf_values(const Polyhedron& polyhedron,
}
template <bool Fast_sdf_calculation_mode, class Polyhedron, class SegmentPropertyMap>
int
std::size_t
segmentation_via_sdf_values(const Polyhedron& polyhedron,
SegmentPropertyMap segment_ids,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
int number_of_clusters = 5,
std::size_t number_of_rays = 25,
std::size_t number_of_clusters = 5,
double smoothing_lambda = 0.26,
bool output_cluster_ids = false,
typename Polyhedron::Traits traits = typename Polyhedron::Traits())
@ -308,12 +308,12 @@ segmentation_via_sdf_values(const Polyhedron& polyhedron,
}
template <class Polyhedron, class SegmentPropertyMap>
int
std::size_t
segmentation_via_sdf_values(const Polyhedron& polyhedron,
SegmentPropertyMap segment_ids,
double cone_angle = 2.0 / 3.0 * CGAL_PI,
int number_of_rays = 25,
int number_of_clusters = 5,
std::size_t number_of_rays = 25,
std::size_t number_of_clusters = 5,
double smoothing_lambda = 0.26,
bool output_cluster_ids = false,
typename Polyhedron::Traits traits = typename Polyhedron::Traits())

View File

@ -7,8 +7,8 @@ typedef boost::tuple<double, double, double> boost_tuple;
void print(const std::vector<boost_tuple>& samples)
{
const int map_size = 31;
const int map_size_2 = 45;
const std::size_t map_size = 31;
const std::size_t map_size_2 = 45;
std::vector<std::vector<bool> > sample_map(map_size, std::vector<bool>(map_size_2, false));
for(std::vector<boost_tuple>::const_iterator sample_it = samples.begin();
@ -18,13 +18,13 @@ void print(const std::vector<boost_tuple>& samples)
double y = (sample_it->get<1>() +1)/2;
x *= (map_size-1);
y *= (map_size_2-1);
int x_c = static_cast<int>(x + 0.49);
int y_c = static_cast<int>(y + 0.49);
std::size_t x_c = static_cast<std::size_t>(x + 0.49);
std::size_t y_c = static_cast<std::size_t>(y + 0.49);
sample_map[x_c][y_c] = true;
}
for(int i = 0; i < map_size; ++i)
for(std::size_t i = 0; i < map_size; ++i)
{
for(int j = 0; j < map_size_2; ++j)
for(std::size_t j = 0; j < map_size_2; ++j)
{
if(sample_map[i][j]){ std::cout << "*"; }
else { std::cout << " "; }

View File

@ -29,16 +29,16 @@ int main(void)
{
boost::variate_generator<boost::mt19937&, boost::normal_distribution<double> > var_nor(engine, *it);
for(int i = 0; i < 300; ++i) { data.push_back(var_nor()); }
for(std::size_t i = 0; i < 300; ++i) { data.push_back(var_nor()); }
}
// calculate closest center (using above gauissians) for each generated points
// we will compare it with gmm fitting results
// also we might want to compute mixing coef for each center and select centers according to mixing_coef * prob(data)
std::vector<int> data_centers;
std::vector<std::size_t> data_centers;
for(std::vector<double>::iterator it = data.begin(); it != data.end(); ++it)
{
int center_id = -1, center_counter = 0;;
std::size_t center_id = -1, center_counter = 0;;
double min_distance = (std::numeric_limits<double>::max)();
for(std::vector< boost::normal_distribution<double> >::iterator dis_it = distributions.begin();
dis_it != distributions.end(); ++dis_it, ++center_counter)
@ -60,8 +60,8 @@ int main(void)
gmm_fitters.push_back(E_M(distributions.size(), data, E_M::RANDOM_INITIALIZATION));
gmm_fitters.push_back(E_M(distributions.size(), data, E_M::K_MEANS_INITIALIZATION));
std::vector< std::vector<int> > calculated_centers(gmm_fitters.size());
std::vector< std::vector<int> >::iterator calc_centers_it = calculated_centers.begin();
std::vector< std::vector<std::size_t> > calculated_centers(gmm_fitters.size());
std::vector< std::vector<std::size_t> >::iterator calc_centers_it = calculated_centers.begin();
for(std::vector<E_M>::iterator it = gmm_fitters.begin(); it != gmm_fitters.end(); ++it, ++calc_centers_it)
{
it->fill_with_center_ids(*calc_centers_it);
@ -69,12 +69,12 @@ int main(void)
std::cout << "Compare results of EM with 'expected' (but be aware, it is not optimal result in terms of likelihood)" << std::endl;
std::cout << "Another words a clustering which has higher likelihood can result in worse score in here" << std::endl;
for(std::vector< std::vector<int> >::iterator calc_centers_it = calculated_centers.begin();
for(std::vector< std::vector<std::size_t> >::iterator calc_centers_it = calculated_centers.begin();
calc_centers_it != calculated_centers.end(); ++calc_centers_it)
{
int true_count = 0;
std::vector<int>::iterator calculated_it = calc_centers_it->begin();
for(std::vector<int>::iterator it = data_centers.begin(); it != data_centers.end(); ++it, ++calculated_it)
std::size_t true_count = 0;
std::vector<std::size_t>::iterator calculated_it = calc_centers_it->begin();
for(std::vector<std::size_t>::iterator it = data_centers.begin(); it != data_centers.end(); ++it, ++calculated_it)
{
if( (*it) == (*calculated_it) ) { ++true_count; }
}

View File

@ -39,10 +39,10 @@ int main(void)
std::cout << "Calculation time (fast traversal off): *** " << timer.time() << std::endl;
timer.reset();
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
Facet_int_map internal_segment_map;
// calculate SDF values and segment the mesh using default parameters.
int number_of_segments = CGAL::segmentation_via_sdf_values(mesh,
std::size_t number_of_segments = CGAL::segmentation_via_sdf_values(mesh,
boost::associative_property_map<Facet_int_map>(internal_segment_map));
std::cout << "Number of segments: " << number_of_segments << std::endl;
std::cout << "Calculation time (fast traversal on): *** " << timer.time() << std::endl;

View File

@ -30,15 +30,15 @@ int main(void)
{
boost::variate_generator<boost::mt19937&, boost::normal_distribution<double> > var_nor(engine, *it);
for(int i = 0; i < 300; ++i) { data.push_back(var_nor()); }
for(std::size_t i = 0; i < 300; ++i) { data.push_back(var_nor()); }
}
// calculate closest center (using above gauissians) for each generated points
// we will compare it with k-means results
std::vector<int> data_centers;
std::vector<std::size_t> data_centers;
for(std::vector<double>::iterator it = data.begin(); it != data.end(); ++it)
{
int center_id = -1, center_counter = 0;;
std::size_t center_id = -1, center_counter = 0;;
double min_distance = (std::numeric_limits<double>::max)();
for(std::vector< boost::normal_distribution<double> >::iterator dis_it = distributions.begin();
dis_it != distributions.end(); ++dis_it, ++center_counter)
@ -59,8 +59,8 @@ int main(void)
k_means.push_back(K_means(distributions.size(), data, K_means::PLUS_INITIALIZATION));
k_means.push_back(K_means(distributions.size(), data, K_means::RANDOM_INITIALIZATION));
std::vector< std::vector<int> > calculated_centers(k_means.size());
std::vector< std::vector<int> >::iterator calc_centers_it = calculated_centers.begin();
std::vector< std::vector<std::size_t> > calculated_centers(k_means.size());
std::vector< std::vector<std::size_t> >::iterator calc_centers_it = calculated_centers.begin();
for(std::vector<K_means>::iterator it = k_means.begin(); it != k_means.end(); ++it, ++calc_centers_it)
{
it->fill_with_center_ids(*calc_centers_it);
@ -68,12 +68,12 @@ int main(void)
std::cout << "Compare results of k-means with 'expected' (but be aware, it is not optimal result in terms of within-cluster error)" << std::endl;
std::cout << "Another words a clustering which has smaller within-cluster error can result in worse score in here" << std::endl;
for(std::vector< std::vector<int> >::iterator calc_centers_it = calculated_centers.begin();
for(std::vector< std::vector<std::size_t> >::iterator calc_centers_it = calculated_centers.begin();
calc_centers_it != calculated_centers.end(); ++calc_centers_it)
{
int true_count = 0;
std::vector<int>::iterator calculated_it = calc_centers_it->begin();
for(std::vector<int>::iterator it = data_centers.begin(); it != data_centers.end(); ++it, ++calculated_it)
std::size_t true_count = 0;
std::vector<std::size_t>::iterator calculated_it = calc_centers_it->begin();
for(std::vector<std::size_t>::iterator it = data_centers.begin(); it != data_centers.end(); ++it, ++calculated_it)
{
if( (*it) == (*calculated_it) ) { ++true_count; }
}

View File

@ -9,26 +9,26 @@ typedef CGAL::internal::K_means_clustering K_means;
int main(void)
{
for(int init_type = 0; init_type < 2; ++init_type)
for(std::size_t init_type = 0; init_type < 2; ++init_type)
{
K_means::Initialization_types init_type_enum = init_type == 0 ? K_means::RANDOM_INITIALIZATION :
K_means::PLUS_INITIALIZATION;
// Test case: number of points equals to number of clusters
// and all points are unique
for(int center_size = 1; center_size < 100; ++center_size)
for(std::size_t center_size = 1; center_size < 100; ++center_size)
{
// unique point generate
std::vector<double> points;
for(int i = 0; i < center_size; ++i) {
for(std::size_t i = 0; i < center_size; ++i) {
points.push_back(i);
}
// test kmeans, expected result: each point has its own cluster
K_means kmeans(center_size, points, init_type_enum);
std::vector<int> center_ids;
std::vector<std::size_t> center_ids;
kmeans.fill_with_center_ids(center_ids);
for(int i = 0; i < center_size -1; ++i) {
for(std::size_t i = 0; i < center_size -1; ++i) {
if(center_ids[i] >= center_ids[i +1]) // center ids are ordered according to mean
{ // and since points are generated ascendingly ...
std::string init_type_s = init_type_enum == K_means::RANDOM_INITIALIZATION ? "Random " :

View File

@ -28,11 +28,11 @@ int main(void)
std::pair<double, double> min_max_sdf = CGAL::sdf_values(mesh, sdf_property_map);
std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl;
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
Facet_int_map internal_segment_map;
boost::associative_property_map<Facet_int_map> segment_property_map(internal_segment_map);
int nb_segments = CGAL::segmentation_from_sdf_values(
std::size_t nb_segments = CGAL::segmentation_from_sdf_values(
mesh, sdf_property_map, segment_property_map);
if(nb_segments != 3)

View File

@ -30,11 +30,11 @@ int main(void)
std::pair<double, double> min_max_sdf = CGAL::sdf_values(mesh, sdf_property_map);
std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl;
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
Facet_int_map internal_segment_map;
boost::associative_property_map<Facet_int_map> segment_property_map(internal_segment_map);
int nb_segments = CGAL::segmentation_from_sdf_values(
std::size_t nb_segments = CGAL::segmentation_from_sdf_values(
mesh, sdf_property_map, segment_property_map);
if(nb_segments != 3)

View File

@ -22,12 +22,12 @@ int main()
}
// create a property-map for segment-ids
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
Facet_int_map internal_segment_map;
boost::associative_property_map<Facet_int_map> segment_property_map(internal_segment_map);
// calculate SDF values and segment the mesh using default parameters.
int number_of_segments = CGAL::segmentation_via_sdf_values(mesh, segment_property_map);
std::size_t number_of_segments = CGAL::segmentation_via_sdf_values(mesh, segment_property_map);
std::cout << "Number of segments: " << number_of_segments << std::endl;