Skip to content

Commit 52781be

Browse files
authored
Merge pull request #760 from JuliaRobotics/21Q4/pcl/pointcloud2
adding PCL PointCloud (Julia) types
2 parents b2d9b36 + 7bcc3ac commit 52781be

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ julia = "1.4"
8080

8181
[extras]
8282
AprilTags = "f0fec3d5-a81e-5a6a-8c28-d2b34f3659de"
83+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
8384
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
8485
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
8586
RoMEPlotting = "238d586b-a4bf-555c-9891-eda6fc5e55a2"
@@ -88,4 +89,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8889
ZMQ = "c2297ded-f4af-51ae-bb23-16f91089e4e1"
8990

9091
[targets]
91-
test = ["Test", "PyCall", "RobotOS", "ZMQ", "AprilTags", "Images"]
92+
test = ["AprilTags", "Colors", "Images", "PyCall", "RobotOS", "Test", "ZMQ"]

src/3rdParty/_PCL/_PCL.jl

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""
2+
Software License Agreement (BSD License)
3+
4+
Point Cloud Library (PCL) - www.pointclouds.org
5+
Copyright (c) 2010, Willow Garage, Inc.
6+
Copyright (c) 2012-, Open Perception, Inc.
7+
8+
All rights reserved.
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions
12+
are met:
13+
14+
* Redistributions of source code must retain the above copyright
15+
notice, this list of conditions and the following disclaimer.
16+
* Redistributions in binary form must reproduce the above
17+
copyright notice, this list of conditions and the following
18+
disclaimer in the documentation and/or other materials provided
19+
with the distribution.
20+
* Neither the name of the copyright holder(s) nor the names of its
21+
contributors may be used to endorse or promote products derived
22+
from this software without specific prior written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
POSSIBILITY OF SUCH DAMAGE.
36+
"""
37+
38+
@info "Caesar.jl is loading (but not exporting) tools requiring Colors.jl; e.g. Caesar._PCL"
39+
40+
module _PCL
41+
42+
using DocStringExtensions
43+
using StaticArrays
44+
using ..Colors
45+
46+
## hold off on exports, users can in the mean-time use/import via e.g. _PCL.PointXYZ
47+
# export PointT, PointXYZ, PointXYZRGB, PointXYZRGBA
48+
# export PCLHeader, PointCloud
49+
50+
abstract type PointT end
51+
52+
"""
53+
$TYPEDEF
54+
55+
See https://pointclouds.org/documentation/point__types_8hpp_source.html
56+
"""
57+
Base.@kwdef struct PointXYZ{C <: Colorant, T <: Number} <: PointT
58+
color::C = RGBA(1,1,1,1)
59+
data::SVector{4,T} = SVector(0,0,0,Float32(1))
60+
end
61+
62+
# Construct helpers nearest to PCL
63+
PointXYZRGBA( x::Real=0, y::Real=0, z::Real=Float32(1);
64+
r::Real=1,g::Real=1,b::Real=1, alpha::Real=1,
65+
color::Colorant=RGBA(r,g,b,alpha),
66+
pos=SA[x,y,z], data=SA[pos...,1] ) = PointXYZ(;color,data)
67+
#
68+
PointXYZRGB( x::Real=0, y::Real=0, z::Real=Float32(1);
69+
r::Real=1,g::Real=1,b::Real=1,
70+
color::Colorant=RGB(r,g,b),
71+
pos=SA[x,y,z], data=SA[pos...,1] ) = PointXYZ(;color,data)
72+
#
73+
74+
function Base.getproperty(p::PointXYZ, f::Symbol)
75+
if f == :x
76+
return getfield(p, :data)[1]
77+
elseif f == :y
78+
return getfield(p, :data)[2]
79+
elseif f == :z
80+
return getfield(p, :data)[3]
81+
elseif f == :r
82+
return getfield(p, :color).r
83+
elseif f == :g
84+
return getfield(p, :color).g
85+
elseif f == :b
86+
return getfield(p, :color).b
87+
elseif f == :alpha
88+
return getfield(p, :color).alpha
89+
elseif f == :data || f == :pos
90+
return getfield(p, :data)
91+
elseif f == :color || f == :rgb
92+
return getfield(p, :color)
93+
end
94+
error("PointXYZ has no field $f")
95+
end
96+
97+
98+
"""
99+
$TYPEDEF
100+
101+
See https://pointclouds.org/documentation/structpcl_1_1_p_c_l_header.html
102+
"""
103+
Base.@kwdef struct PCLHeader
104+
seq::UInt32 = UInt32(0)
105+
stamp::UInt64 = UInt64(0)
106+
frame_id::String = ""
107+
end
108+
109+
Base.@kwdef struct PointCloud
110+
header::PCLHeader = PCLHeader()
111+
""" vector of points representing the point cloud """
112+
points::Vector{<:PointT} = Vector{PointXYZ{RGBA{Colors.FixedPointNumbers.N0f8}, Float32}}()
113+
end
114+
115+
116+
117+
end

src/Caesar.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function __init__()
9292
include("images/ScanMatcherPose2.jl")
9393
include("images/ScatterAlignPose2.jl")
9494
end
95+
@require Colors="5ae59095-9a9b-59fe-a467-6f913c188581" include("3rdParty/_PCL/_PCL.jl")
9596
@require Distributed="8ba89e20-285c-5b6f-9357-94700520ee1b" include("images/DistributedUtils.jl")
9697
end
9798

0 commit comments

Comments
 (0)