Skip to content

Commit bd308d6

Browse files
committed
std vector interface
1 parent c42ba18 commit bd308d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+807
-424
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ elseif (UNIX)
160160
endif ()
161161

162162
find_package(CUDA REQUIRED)
163+
enable_language(CUDA)
163164
if(NOT CMAKE_CUDA_ARCHITECTURES)
164165
set(CMAKE_CUDA_ARCHITECTURES 86)
165166
endif()

src/cupoch/geometry/down_sample.cu

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ std::shared_ptr<PointCloud> PointCloud::SelectByMask(
167167
return output;
168168
}
169169

170+
std::shared_ptr<PointCloud> PointCloud::SelectByIndex(
171+
const std::vector<size_t> &indices, bool invert) const {
172+
return SelectByIndex(utility::device_vector<size_t>(indices), invert);
173+
}
174+
175+
std::shared_ptr<PointCloud> PointCloud::SelectByMask(
176+
const std::vector<bool> &mask, bool invert) const {
177+
return SelectByMask(utility::device_vector<bool>(mask), invert);
178+
}
179+
170180
std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
171181
float voxel_size) const {
172182
auto output = std::make_shared<PointCloud>();

src/cupoch/geometry/geometry_utils.cu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ const utility::device_vector<Eigen::Vector3f>& ConvertVector3fVectorRef(const Ge
6969
}
7070
}
7171

72+
const std::vector<Eigen::Vector3f> ConvertVector3fStdVector(const Geometry &geometry) {
73+
switch (geometry.GetGeometryType()) {
74+
case Geometry::GeometryType::PointCloud:
75+
return ((const PointCloud &)geometry).GetPoints();
76+
case Geometry::GeometryType::TriangleMesh:
77+
return ((const TriangleMesh &)geometry).GetVertices();
78+
case Geometry::GeometryType::Image:
79+
case Geometry::GeometryType::Unspecified:
80+
default:
81+
utility::LogWarning(
82+
"[KDTreeFlann::SetGeometry] Unsupported Geometry type.");
83+
throw std::runtime_error(
84+
"[KDTreeFlann::SetGeometry] Unsupported Geometry type.");
85+
}
86+
}
87+
7288
void ResizeAndPaintUniformColor(utility::device_vector<Eigen::Vector3f> &colors,
7389
const size_t size,
7490
const Eigen::Vector3f &color) {

src/cupoch/geometry/geometry_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace cupoch {
2727
namespace geometry {
2828

2929
const utility::device_vector<Eigen::Vector3f>& ConvertVector3fVectorRef(const Geometry &geometry);
30+
const std::vector<Eigen::Vector3f> ConvertVector3fStdVector(const Geometry &geometry);
3031

3132
/// Get Rotation Matrix from XYZ RotationType.
3233
Eigen::Matrix3f GetRotationMatrixFromXYZ(const Eigen::Vector3f &rotation);

src/cupoch/geometry/graph.cu

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ Graph<Dim>::Graph(const Graph &other)
177177
is_directed_(other.is_directed_) {}
178178

179179
template <int Dim>
180-
thrust::host_vector<int> Graph<Dim>::GetEdgeIndexOffsets() const {
181-
thrust::host_vector<int> edge_index_offsets = edge_index_offsets_;
180+
std::vector<int> Graph<Dim>::GetEdgeIndexOffsets() const {
181+
std::vector<int> edge_index_offsets(edge_index_offsets_.size());
182+
copy_device_to_host(edge_index_offsets_, edge_index_offsets);
182183
return edge_index_offsets;
183184
}
184185

@@ -189,8 +190,9 @@ void Graph<Dim>::SetEdgeIndexOffsets(
189190
}
190191

191192
template <int Dim>
192-
thrust::host_vector<float> Graph<Dim>::GetEdgeWeights() const {
193-
thrust::host_vector<float> edge_weights = edge_weights_;
193+
std::vector<float> Graph<Dim>::GetEdgeWeights() const {
194+
std::vector<float> edge_weights(edge_weights_.size());
195+
copy_device_to_host(edge_weights_, edge_weights);
194196
return edge_weights;
195197
}
196198

@@ -390,6 +392,18 @@ Graph<Dim> &Graph<Dim>::AddEdges(
390392
return AddEdges(d_edges, d_weights, lazy_add);
391393
}
392394

395+
template <int Dim>
396+
Graph<Dim> &Graph<Dim>::AddEdges(
397+
const std::vector<Eigen::Vector2i> &edges,
398+
const std::vector<float> &weights,
399+
bool lazy_add) {
400+
utility::device_vector<Eigen::Vector2i> d_edges(edges.size());
401+
copy_host_to_device(edges, d_edges);
402+
utility::device_vector<float> d_weights(weights.size());
403+
copy_host_to_device(weights, d_weights);
404+
return AddEdges(d_edges, d_weights, lazy_add);
405+
}
406+
393407
template <int Dim>
394408
Graph<Dim> &Graph<Dim>::RemoveEdge(const Eigen::Vector2i &edge) {
395409
bool has_colors = this->HasColors();
@@ -510,6 +524,13 @@ Graph<Dim> &Graph<Dim>::RemoveEdges(
510524
return RemoveEdges(d_edges);
511525
}
512526

527+
template <int Dim>
528+
Graph<Dim> &Graph<Dim>::RemoveEdges(const std::vector<Eigen::Vector2i> &edges) {
529+
utility::device_vector<Eigen::Vector2i> d_edges(edges.size());
530+
copy_host_to_device(edges, d_edges);
531+
return RemoveEdges(d_edges);
532+
}
533+
513534
template <int Dim>
514535
Graph<Dim> &Graph<Dim>::PaintEdgeColor(const Eigen::Vector2i &edge,
515536
const Eigen::Vector3f &color) {
@@ -574,6 +595,15 @@ Graph<Dim> &Graph<Dim>::PaintEdgesColor(
574595
return PaintEdgesColor(d_edges, color);
575596
}
576597

598+
template <int Dim>
599+
Graph<Dim> &Graph<Dim>::PaintEdgesColor(
600+
const std::vector<Eigen::Vector2i> &edges,
601+
const Eigen::Vector3f &color) {
602+
utility::device_vector<Eigen::Vector2i> d_edges(edges.size());
603+
copy_host_to_device(edges, d_edges);
604+
return PaintEdgesColor(d_edges, color);
605+
}
606+
577607
template <int Dim>
578608
Graph<Dim> &Graph<Dim>::PaintNodeColor(int node, const Eigen::Vector3f &color) {
579609
if (!HasNodeColors()) {
@@ -602,6 +632,14 @@ Graph<Dim> &Graph<Dim>::PaintNodesColor(const thrust::host_vector<int> &nodes,
602632
return PaintNodesColor(d_nodes, color);
603633
}
604634

635+
template <int Dim>
636+
Graph<Dim> &Graph<Dim>::PaintNodesColor(const std::vector<int> &nodes,
637+
const Eigen::Vector3f &color) {
638+
utility::device_vector<int> d_nodes(nodes.size());
639+
copy_host_to_device(nodes, d_nodes);
640+
return PaintNodesColor(d_nodes, color);
641+
}
642+
605643
template <int Dim>
606644
Graph<Dim> &Graph<Dim>::SetEdgeWeightsFromDistance() {
607645
edge_weights_.resize(this->lines_.size());

src/cupoch/geometry/graph.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class Graph : public LineSet<Dim> {
5555
Graph(const Graph &other);
5656
~Graph();
5757

58-
thrust::host_vector<int> GetEdgeIndexOffsets() const;
58+
std::vector<int> GetEdgeIndexOffsets() const;
5959
void SetEdgeIndexOffsets(
6060
const thrust::host_vector<int> &edge_index_offsets);
61-
thrust::host_vector<float> GetEdgeWeights() const;
61+
std::vector<float> GetEdgeWeights() const;
6262
void SetEdgeWeights(const thrust::host_vector<float> &edge_weights);
6363

6464
bool HasWeights() const {
@@ -97,11 +97,15 @@ class Graph : public LineSet<Dim> {
9797
const utility::pinned_host_vector<float> &weights =
9898
utility::pinned_host_vector<float>(),
9999
bool lazy_add = false);
100+
Graph<Dim> &AddEdges(const std::vector<Eigen::Vector2i> &edges,
101+
const std::vector<float> &weights = std::vector<float>(),
102+
bool lazy_add = false);
100103

101104
Graph<Dim> &RemoveEdge(const Eigen::Vector2i &edge);
102105
Graph<Dim> &RemoveEdges(
103106
const utility::device_vector<Eigen::Vector2i> &edges);
104107
Graph<Dim> &RemoveEdges(const thrust::host_vector<Eigen::Vector2i> &edges);
108+
Graph<Dim> &RemoveEdges(const std::vector<Eigen::Vector2i> &edges);
105109

106110
Graph<Dim> &PaintEdgeColor(const Eigen::Vector2i &edge,
107111
const Eigen::Vector3f &color);
@@ -111,12 +115,17 @@ class Graph : public LineSet<Dim> {
111115
Graph<Dim> &PaintEdgesColor(
112116
const thrust::host_vector<Eigen::Vector2i> &edges,
113117
const Eigen::Vector3f &color);
118+
Graph<Dim> &PaintEdgesColor(
119+
const std::vector<Eigen::Vector2i> &edges,
120+
const Eigen::Vector3f &color);
114121

115122
Graph<Dim> &PaintNodeColor(int node, const Eigen::Vector3f &color);
116123
Graph<Dim> &PaintNodesColor(const utility::device_vector<int> &nodes,
117124
const Eigen::Vector3f &color);
118125
Graph<Dim> &PaintNodesColor(const thrust::host_vector<int> &nodes,
119126
const Eigen::Vector3f &color);
127+
Graph<Dim> &PaintNodesColor(const std::vector<int> &nodes,
128+
const Eigen::Vector3f &color);
120129

121130
Graph<Dim> &SetEdgeWeightsFromDistance();
122131
Graph<Dim> &SetEdgeWeights(const utility::device_vector<Eigen::Vector2i> &edges, float weight);

src/cupoch/geometry/image.cu

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,19 @@ Eigen::Vector2f Image::GetCenter() const {
389389
return Eigen::Vector2f(width_ / 2, height_ / 2);
390390
}
391391

392-
thrust::host_vector<uint8_t> Image::GetData() const {
393-
thrust::host_vector<uint8_t> data = data_;
392+
std::vector<uint8_t> Image::GetData() const {
393+
std::vector<uint8_t> data(data_.size());
394+
copy_device_to_host(data_, data);
394395
return data;
395396
}
396397

397398
void Image::SetData(const thrust::host_vector<uint8_t> &data) { data_ = data; }
398399

400+
void Image::SetData(const std::vector<uint8_t> &data) {
401+
data_.resize(data.size());
402+
copy_host_to_device(data, data_);
403+
}
404+
399405
bool Image::TestImageBoundary(float u,
400406
float v,
401407
float inner_margin /* = 0.0 */) const {
@@ -519,6 +525,13 @@ std::shared_ptr<Image> Image::FilterHorizontal(
519525
return output;
520526
}
521527

528+
std::shared_ptr<Image> Image::FilterHorizontal(
529+
const std::vector<float> &kernel) const {
530+
utility::device_vector<float> d_kernel(kernel.size());
531+
copy_host_to_device(kernel, d_kernel);
532+
return FilterHorizontal(d_kernel);
533+
}
534+
522535
std::shared_ptr<Image> Image::Filter(Image::FilterType type) const {
523536
auto output = std::make_shared<Image>();
524537
if (num_of_channels_ != 1 || bytes_per_channel_ != 4) {

src/cupoch/geometry/image.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ class Image : public GeometryBaseNoTrans2D {
8585
Eigen::Vector2f GetMaxBound() const override;
8686
Eigen::Vector2f GetCenter() const override;
8787

88-
thrust::host_vector<uint8_t> GetData() const;
88+
std::vector<uint8_t> GetData() const;
8989
void SetData(const thrust::host_vector<uint8_t> &data);
90+
void SetData(const std::vector<uint8_t> &data);
9091

9192
/// \brief Test if coordinate `(u, v)` is located in the inner_marge of the
9293
/// image.
@@ -171,6 +172,9 @@ class Image : public GeometryBaseNoTrans2D {
171172
std::shared_ptr<Image> FilterHorizontal(
172173
const utility::device_vector<float> &kernel) const;
173174

175+
std::shared_ptr<Image> FilterHorizontal(
176+
const std::vector<float> &kernel) const;
177+
174178
std::shared_ptr<Image> BilateralFilter(int diameter,
175179
float sigma_color,
176180
float sigma_space) const;

src/cupoch/geometry/laserscanbuffer.cu

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ LaserScanBuffer::LaserScanBuffer(const LaserScanBuffer& other)
137137
max_angle_(other.max_angle_),
138138
origins_(other.origins_) {}
139139

140-
thrust::host_vector<float> LaserScanBuffer::GetRanges() const {
141-
thrust::host_vector<float> ranges;
140+
std::vector<float> LaserScanBuffer::GetRanges() const {
141+
std::vector<float> ranges;
142142
if (top_ == bottom_) {
143143
return ranges;
144144
}
@@ -161,8 +161,8 @@ thrust::host_vector<float> LaserScanBuffer::GetRanges() const {
161161
}
162162
}
163163

164-
thrust::host_vector<float> LaserScanBuffer::GetIntensities() const {
165-
thrust::host_vector<float> intensities;
164+
std::vector<float> LaserScanBuffer::GetIntensities() const {
165+
std::vector<float> intensities;
166166
if (top_ == bottom_) {
167167
return intensities;
168168
}
@@ -303,6 +303,11 @@ template LaserScanBuffer& LaserScanBuffer::AddRanges(
303303
const Eigen::Matrix4f& transformation,
304304
const thrust::host_vector<float>& intensities);
305305

306+
template LaserScanBuffer& LaserScanBuffer::AddRanges(
307+
const std::vector<float>& ranges,
308+
const Eigen::Matrix4f& transformation,
309+
const std::vector<float>& intensities);
310+
306311

307312
class ContainerLikePtr {
308313
public:

src/cupoch/geometry/laserscanbuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class LaserScanBuffer : public GeometryBase3D {
4848
~LaserScanBuffer();
4949
LaserScanBuffer(const LaserScanBuffer &other);
5050

51-
thrust::host_vector<float> GetRanges() const;
52-
thrust::host_vector<float> GetIntensities() const;
51+
std::vector<float> GetRanges() const;
52+
std::vector<float> GetIntensities() const;
5353

5454
LaserScanBuffer &Clear() override;
5555
bool IsEmpty() const override;

0 commit comments

Comments
 (0)