Main MRPT website > C++ reference for MRPT 1.5.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 <> BASE_IMPEXP
36  const bool use_kmeansplusplus_method,
37  const size_t nPoints,
38  const size_t k,
39  const size_t dims,
40  const double *points,
41  const size_t attempts,
42  double* out_center,
43  int *out_assignments)
44  {
45  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
46  return RunKMeans(nPoints,k,dims,const_cast<double*>(points),attempts,out_center,out_assignments);
47  }
48 
49  template <> BASE_IMPEXP
51  const bool use_kmeansplusplus_method,
52  const size_t nPoints,
53  const size_t k,
54  const size_t dims,
55  const float *points,
56  const size_t attempts,
57  float* out_center,
58  int *out_assignments)
59  {
60  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
61  std::vector<double> points_d(nPoints*dims);
62  std::vector<double> centers_d(k*dims);
63  // Convert: float -> double
64  for (size_t i=0;i<nPoints*dims;i++)
65  points_d[i] = double(points[i]);
66 
67  const double ret = RunKMeans(nPoints,k,dims,&points_d[0],attempts,&centers_d[0],out_assignments);
68 
69  // Convert: double -> float
70  if (out_center)
71  for (size_t i=0;i<k*dims;i++)
72  out_center[i] = float(centers_d[i]);
73 
74  return ret;
75  }
76 
77  }
78  }
79 }
80 
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.
Definition: zip.h:16
STL namespace.
GLsizei const GLfloat * points
Definition: glext.h:4797
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.
BASE_IMPEXP 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:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
BASE_IMPEXP 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.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020