Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for point clouds over flatbuffers #193

Merged
merged 54 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
36dab07
add grpc interface for point clouds
jarkenau Aug 12, 2022
55fd9c0
fix build error grpc fb service pointcloud
Mark-Niemeyer Aug 12, 2022
8f9163a
apply changed pointcloud fb-msg to other pkgs
Mark-Niemeyer Aug 15, 2022
7ad2fcf
update point_field fb message, due to name clashing
jarkenau Aug 29, 2022
1563b4c
WIP: point cloud iterator for fb
jarkenau Aug 30, 2022
3261cbe
add label with instances to fb point cloud
jarkenau Aug 30, 2022
84d4526
WIP: fb point cloud
jarkenau Sep 6, 2022
fe72315
refactor to only use reference where possible in hdf5 fb
jarkenau Sep 6, 2022
e037ca5
hdf5 fb write for point clouds compiling
jarkenau Sep 8, 2022
75aa12c
add fb to core conversions for point clouds
jarkenau Sep 9, 2022
a20c299
add service to write fb point clouds
jarkenau Sep 9, 2022
2dd979a
add flatbuffer point cloud service implementation
jarkenau Sep 12, 2022
42ced15
WIP first working fb point cloud example script
jarkenau Sep 13, 2022
0fbeb5f
write fb point clouds with general labels
jarkenau Sep 13, 2022
e8b9b58
add boudingBoxLabeled into fb point cloud script
jarkenau Sep 14, 2022
fb45b1d
refactor: fb point cloud example to use fb util
jarkenau Sep 14, 2022
ba9ddec
hdf5 fb point cloud read compiling
jarkenau Sep 15, 2022
db2ff37
read xyz of pointcloud2 in flatbuffers
jarkenau Sep 20, 2022
74954f0
add rgb and rgba read for flatbuffers point clouds
jarkenau Sep 21, 2022
4e1e982
fix: point cloud indicies on server startup
jarkenau Sep 21, 2022
e330e08
refactor hdf5 write of flatbuffer point clouds
jarkenau Sep 22, 2022
78e1351
add logging into hdf5 fb read of point cloud
jarkenau Sep 23, 2022
5e6d647
update logging in flatbuffers point cloud service
jarkenau Sep 23, 2022
fa11160
update logging in core fb point cloud
jarkenau Sep 23, 2022
35bbc62
read and write of points into hdf5 for flatbuffer point clouds
jarkenau Oct 4, 2022
fd7126d
read and write of rgb(a) to hdf5 from flatbuffer point clouds
jarkenau Oct 4, 2022
d1a40df
refactor flatbuffers hdf5 file access
jarkenau Oct 6, 2022
fc9938c
add read without data to flatbuffers point clouds
jarkenau Oct 6, 2022
34dba98
use hdf5 definitions from seerep-hdf5-core #183
jarkenau Oct 7, 2022
25d0a37
remove point cloud modifier for flatbuffers point cloud
jarkenau Oct 10, 2022
817500f
rename fb point cloud iterator
jarkenau Oct 10, 2022
75d4832
add docs in seerep-hdf5-fb for point clouds
jarkenau Oct 10, 2022
ab5bd5b
remove unused methods from hdfb-fb-pointcloud
jarkenau Oct 10, 2022
c46a765
update flatbuffers pointcloud2iterator
jarkenau Oct 10, 2022
3ade865
add docs to core-fb-pointcloud
jarkenau Oct 10, 2022
87dd1ea
remove temporary fix from core-fb-pointcloud
jarkenau Oct 10, 2022
0c2b42e
remove quaternion attributes from hdf5-core-point-cloud
jarkenau Oct 10, 2022
c997cc8
add docs to flatbuffers point cloud service
jarkenau Oct 11, 2022
7c30d32
fix: funcions call in hdf5-fb-point and hdf5-fb-image after rebase
jarkenau Oct 11, 2022
9b872b5
fix: general labels not in indicies for flatbuffer point clouds
jarkenau Oct 11, 2022
cc8f42d
update header and query in fb_util to use optional parameters
jarkenau Oct 11, 2022
5d1c8e7
fix: bounding box indecies for flatbuffer point clouds
jarkenau Oct 12, 2022
e4bb7bd
remove TODO in seerep-core-fb-conversions
jarkenau Oct 12, 2022
fdce344
add checks for empty flatbuffers message fields inside write function
jarkenau Oct 13, 2022
5ce375b
add null check in write of point field attributes
jarkenau Oct 17, 2022
02bc3aa
rename conversion functions in core-fb-conversion
jarkenau Oct 17, 2022
059ea30
separate calculation of rgba offset in hdf5-fb-pointcloud
jarkenau Oct 17, 2022
328d98b
add method for writing general attributs to the hdf5 data group in hd…
jarkenau Oct 17, 2022
03f6215
add hdf5 data set and data group accessors in hdf5-core-general
jarkenau Oct 18, 2022
8cba06a
add method to compute bounding box in hdf5-fb-pointcloud
jarkenau Oct 18, 2022
0764d5f
add methods to calculate multiple offsets for point clouds
jarkenau Oct 18, 2022
1b155b8
add precision for numpy output in point cloud examples
jarkenau Oct 18, 2022
f077a9f
refactor data group accessor method in hdf5-core-general
jarkenau Oct 18, 2022
c44fd92
fix write of rgba field in flatbuffers point cloud
jarkenau Oct 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import os
import struct
import sys

import flatbuffers
import numpy as np

np.set_printoptions(precision=7)
from fb import point_cloud_service_grpc_fb as pointCloudService
from fb.PointCloud2 import PointCloud2

script_dir = os.path.dirname(__file__)
util_dir = os.path.join(script_dir, '..')
sys.path.append(util_dir)
import util
import util_fb

channel = util.get_gRPC_channel()

stubPointCloud = pointCloudService.PointCloudServiceStub(channel)
builder = flatbuffers.Builder(1024)

PROJECTNAME = "testproject"
projectUuid = util_fb.getProject(builder, channel, PROJECTNAME)

if projectUuid is None:
print(f"Project: {PROJECTNAME} does not exist")
sys.exit()


builder = flatbuffers.Builder(1024)

timeMin = util_fb.createTimeStamp(builder, 1610549273, 0)
timeMax = util_fb.createTimeStamp(builder, 1938549273, 0)
timeInterval = util_fb.createTimeInterval(builder, timeMin, timeMax)

queryMsg = util_fb.createQuery(
builder,
projectUuids=[builder.CreateString(projectUuid)],
timeInterval=timeInterval,
labels=[builder.CreateString("BoundingBoxLabel0")],
)
builder.Finish(queryMsg)
buf = builder.Output()

for responseBuf in stubPointCloud.GetPointCloud2(bytes(buf)):
response = PointCloud2.GetRootAs(responseBuf)

print("---Header---")
print(f"Message UUID: {response.Header().UuidMsgs().decode('utf-8')}")
print(f"Project UUID: {response.Header().UuidProject().decode('utf-8')}")
print(f"Frame ID: {response.Header().FrameId().decode('utf-8')}")

print("---Point Fields---")
for i in range(response.FieldsLength()):
print(f"Field Name: {response.Fields(i).Name().decode('utf-8')}")
print(f"Datatype: {response.Fields(i).Datatype()}")
print(f"Offset: {response.Fields(i).Offset()}")
print(f"Count: {response.Fields(i).Count()}")

print("---Bounding Box Labels---")
for i in range(response.LabelsBbLength()):
print(f"Label {i}: {response.LabelsBb(i).LabelWithInstance().Label().decode('utf-8')}")
print(f"Instance {i}: {response.LabelsBb(i).LabelWithInstance().InstanceUuid().decode('utf-8')}")
print(
f"Bounding Box Min {i}: "
f"{response.LabelsBb(i).BoundingBox().PointMin().X()},"
f"{response.LabelsBb(i).BoundingBox().PointMin().Y()},"
f"{response.LabelsBb(i).BoundingBox().PointMin().Z()} "
f"(x,y,z)"
)
print(
f"Bounding Box Max {i}: "
f"{response.LabelsBb(i).BoundingBox().PointMax().X()},"
f"{response.LabelsBb(i).BoundingBox().PointMax().Y()},"
f"{response.LabelsBb(i).BoundingBox().PointMax().Z()} "
f"(x,y,z)"
)

print("---General Labels----")
for i in range(response.LabelsGeneralLength()):
print(f"Label {i}: {response.LabelsGeneral(i).Label().decode('utf-8')}")
print(f"Instance {i}: {response.LabelsGeneral(i).InstanceUuid().decode('utf-8')}")

print("---Data--")
if not response.DataIsNone():
rawData = response.DataAsNumpy()
data = [struct.unpack('f', rawData[i : i + 4]) for i in range(0, rawData.shape[0], 4)]
reshapedData = np.array(data).reshape(960, 1280, 4)
print(f"Data: {reshapedData}")
109 changes: 109 additions & 0 deletions examples/python/gRPC/pointcloud/gRPC_fb_sendPointCloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/user/bin/env python3

import os
import sys
import time
import uuid

import flatbuffers
import numpy as np

np.set_printoptions(precision=7)
from fb import PointCloud2
from fb import point_cloud_service_grpc_fb as pointCloudService

script_dir = os.path.dirname(__file__)
util_dir = os.path.join(script_dir, '..')
sys.path.append(util_dir)

import util
from util_fb import (
addToBoundingBoxLabeledVector,
addToGeneralLabelsVector,
addToPointFieldVector,
createBoundingBoxes,
createBoundingBoxesLabeled,
createHeader,
createLabelsWithInstance,
createPoint,
createPointFields,
createTimeStamp,
getOrCreateProject,
)

NUM_GENERAL_LABELS = 1
NUM_BB_LABELS = 1
NUM_POINT_CLOUDS = 1


def createPointCloud(builder, header, height=960, width=1280):
'''Creates a flatbuffers point cloud message'''
pointFields = createPointFields(builder, ['x', 'y', 'z', 'rgba'], 7, 4, 1)
pointFieldsVector = addToPointFieldVector(builder, pointFields)

# create general labels
labelsGeneral = createLabelsWithInstance(
builder,
["GeneralLabel" + str(i) for i in range(NUM_GENERAL_LABELS)],
[str(uuid.uuid4()) for _ in range(NUM_GENERAL_LABELS)],
)
labelsGeneralVector = addToGeneralLabelsVector(builder, labelsGeneral)

# create bounding box labels
boundingBoxes = createBoundingBoxes(
builder,
header,
[createPoint(builder, np.random.rand(), np.random.rand(), np.random.rand()) for _ in range(NUM_BB_LABELS)],
[createPoint(builder, np.random.rand(), np.random.rand(), np.random.rand()) for _ in range(NUM_BB_LABELS)],
)
labelWithInstances = createLabelsWithInstance(
builder,
["BoundingBoxLabel" + str(i) for i in range(NUM_BB_LABELS)],
[str(uuid.uuid4()) for _ in range(NUM_BB_LABELS)],
)
labelsBb = createBoundingBoxesLabeled(builder, labelWithInstances, boundingBoxes)
labelsBbVector = addToBoundingBoxLabeledVector(builder, labelsBb)

# Note: rgb field is float, for simplification
points = np.random.randn(height, width, 4).astype(np.float32)
print(f"Data: {points}")

pointsVector = builder.CreateByteVector(points.tobytes())

# add all data into the flatbuffers point cloud message
PointCloud2.Start(builder)
PointCloud2.AddHeader(builder, header)
PointCloud2.AddHeight(builder, points.shape[0])
PointCloud2.AddWidth(builder, points.shape[1])
PointCloud2.AddIsBigendian(builder, True)
PointCloud2.AddPointStep(builder, 16)
PointCloud2.AddRowStep(builder, points.shape[1] * 16)
PointCloud2.AddFields(builder, pointFieldsVector)
PointCloud2.AddData(builder, pointsVector)
PointCloud2.AddLabelsGeneral(builder, labelsGeneralVector)
PointCloud2.AddLabelsBb(builder, labelsBbVector)
return PointCloud2.End(builder)


def createPointClouds(projectUuid, numOf):
'''Creates numOf pointcloud2 messages as a generator function'''
theTime = int(time.time())
for i in range(numOf):
print(f"Send point cloud: {str(i+1)}")
builder = flatbuffers.Builder(1024)

timeStamp = createTimeStamp(builder, theTime + i)
header = createHeader(builder, timeStamp, "map", projectUuid)

pointCloudMsg = createPointCloud(builder, header)
builder.Finish(pointCloudMsg)
yield bytes(builder.Output())


channel = util.get_gRPC_channel()
stub = pointCloudService.PointCloudServiceStub(channel)
builder = flatbuffers.Builder(1024)

projectUuid = getOrCreateProject(builder, channel, "testproject")

responseBuf = stub.TransferPointCloud2(createPointClouds(projectUuid, NUM_POINT_CLOUDS))
7 changes: 6 additions & 1 deletion examples/python/gRPC/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def get_gRPC_channel(target="local"):
elif target == "local":
# server without certs
server = "localhost:9090"
channel = grpc.insecure_channel(server)
# set the max message size to 1GB (half the size of the server)
options = [
('grpc.max_send_message_length', 1 * 1024 * 1024 * 1024),
('grpc.max_receive_message_length', 1 * 1024 * 1024 * 1024),
]
channel = grpc.insecure_channel(server, options=options)

return channel
Loading