cloud.h 1.78 KB
Newer Older
Alexander Liao's avatar
Alexander Liao committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Author: Peiyuan Liao (alexander_liao@outlook.com)
//


# pragma once

#include <ATen/ATen.h>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>

#include <time.h>


template<typename scalar_t>
struct PointCloud
{
23
	std::vector<std::vector<scalar_t>*> pts;
Alexander Liao's avatar
Alexander Liao committed
24
25
26

	void set(std::vector<scalar_t> new_pts, int dim){

27
		std::vector<std::vector<scalar_t>*> temp(new_pts.size()/dim);
28
		for(size_t i=0; i < new_pts.size(); i++){
Alexander Liao's avatar
Alexander Liao committed
29
			if(i%dim == 0){
30
				std::vector<scalar_t>* point = new std::vector<scalar_t>(dim);
31

32
				for (size_t j = 0; j < (size_t)dim; j++) {
33
					(*point)[j]=new_pts[i+j];
Alexander Liao's avatar
Alexander Liao committed
34
35
36
37
38
39
40
				}
				temp[i/dim] = point;
			}
		}

		pts = temp;
	}
41
42
43
44
	void set_batch(std::vector<scalar_t> new_pts, size_t begin, long size, int dim){
		std::vector<std::vector<scalar_t>*> temp(size);
		for(size_t i=0; i < (size_t)size; i++){
			std::vector<scalar_t>* point = new std::vector<scalar_t>(dim);
45
			for (size_t j = 0; j < (size_t)dim; j++) {
46
					(*point)[j] = new_pts[dim*(begin+i)+j];
Alexander Liao's avatar
Alexander Liao committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
			}

			temp[i] = point;

		}
		pts = temp;
	}

	// Must return the number of data points
	inline size_t kdtree_get_point_count() const { return pts.size(); }

	// Returns the dim'th component of the idx'th point in the class:
	inline scalar_t kdtree_get_pt(const size_t idx, const size_t dim) const
	{
61
		return (*pts[idx])[dim];
Alexander Liao's avatar
Alexander Liao committed
62
63
64
65
66
67
68
69
70
71
	}

	// Optional bounding-box computation: return false to default to a standard bbox computation loop.
	//   Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again.
	//   Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds)
	template <class BBOX>
	bool kdtree_get_bbox(BBOX& /* bb */) const { return false; }


};