Main MRPT website > C++ reference for MRPT 1.9.9
KMeans.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "base-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/kmeans.h>
13 
14 // This file is just a stub for the k-means++ library so MRPT users don't need
15 // to include those headers too.
16 
17 // Include the kmeans++ library, by David Arthur (darthur@gmail.com), 2009:
18 #include "kmeans++/KMeans.h"
19 
20 using namespace std;
21 using namespace mrpt;
22 using namespace mrpt::math;
23 using namespace mrpt::utils;
24 
25 namespace mrpt
26 {
27 namespace math
28 {
29 namespace detail
30 {
31 /* -------------------------------------------
32  internal_kmeans
33  ------------------------------------------- */
34 template <>
36  const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k,
37  const size_t dims, const double* points, const size_t attempts,
38  double* out_center, int* out_assignments)
39 {
40  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
41  return RunKMeans(
42  nPoints, k, dims, const_cast<double*>(points), attempts, out_center,
43  out_assignments);
44 }
45 
46 template <>
48  const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k,
49  const size_t dims, const float* points, const size_t attempts,
50  float* out_center, int* out_assignments)
51 {
52  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
53  std::vector<double> points_d(nPoints * dims);
54  std::vector<double> centers_d(k * dims);
55  // Convert: float -> double
56  for (size_t i = 0; i < nPoints * dims; i++) points_d[i] = double(points[i]);
57 
58  const double ret = RunKMeans(
59  nPoints, k, dims, &points_d[0], attempts, &centers_d[0],
60  out_assignments);
61 
62  // Convert: double -> float
63  if (out_center)
64  for (size_t i = 0; i < k * dims; i++)
65  out_center[i] = float(centers_d[i]);
66 
67  return ret;
68 }
69 }
70 }
71 }
Scalar RunKMeans(int n, int k, int d, Scalar *points, int attempts, Scalar *ret_centers, int *ret_assignment)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
STL namespace.
double internal_kmeans< float >(const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k, const size_t dims, const float *points, const size_t attempts, float *out_center, int *out_assignments)
Definition: KMeans.cpp:47
GLsizei const GLfloat * points
Definition: glext.h:5339
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double internal_kmeans< double >(const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k, const size_t dims, const double *points, const size_t attempts, double *out_center, int *out_assignments)
Definition: KMeans.cpp:35



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019