| 208 | |
| 209 | |
| 210 | void Pointcloud::subSampleRandom(unsigned int num_samples, Pointcloud& sample_cloud) { |
| 211 | point3d_collection samples; |
| 212 | // visual studio does not support random_sample_n and neither does libc++ |
| 213 | #if defined(_MSC_VER) || defined(_LIBCPP_VERSION) |
| 214 | samples.reserve(this->size()); |
| 215 | samples.insert(samples.end(), this->begin(), this->end()); |
| 216 | #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201103L) || __cplusplus >= 201103L) |
| 217 | std::random_device r; |
| 218 | std::mt19937 urbg(r()); |
| 219 | std::shuffle(samples.begin(), samples.end(), urbg); |
| 220 | #else |
| 221 | std::random_shuffle(samples.begin(), samples.end()); |
| 222 | #endif |
| 223 | samples.resize(num_samples); |
| 224 | #else |
| 225 | random_sample_n(begin(), end(), std::back_insert_iterator<point3d_collection>(samples), num_samples); |
| 226 | for (unsigned int i=0; i<samples.size(); i++) { |
| 227 | sample_cloud.push_back(samples[i]); |
| 228 | } |
| 229 | #endif |
| 230 | } |
| 231 | |
| 232 | |
| 233 | void Pointcloud::writeVrml(std::string filename){ |