From 6b37ae2b15eca92b3cacac0e113290eb28ccfa8b Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期一, 20 六月 2022 15:49:50 +0800
Subject: [PATCH] get pointclouds from client

---
 src/engine/MessageThreads.py |   93 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 71 insertions(+), 22 deletions(-)

diff --git a/src/engine/MessageThreads.py b/src/engine/MessageThreads.py
index d66975a..9775989 100644
--- a/src/engine/MessageThreads.py
+++ b/src/engine/MessageThreads.py
@@ -9,6 +9,7 @@
 from typing import List
 import numpy as np
 import cv2
+from tomlkit import value
 
 # # add python path of src to sys.path
 # src_path = os.path.join(__file__, *(['..'] * 2))
@@ -288,7 +289,7 @@
 
             # extracting the msg from queue
             msg = queue.get()
-            msg_pb = pb.PlyMessage()
+            msg_pb = pb.PlysMessage()
             msg_pb.ParseFromString(msg)
 
             # save the raw pb msg 
@@ -309,7 +310,7 @@
                 rows = ply.rows
                 cols = ply.cols
                 order = ply.order
-                dt = ply.d_types
+                dt = ply.dtype
 
                 # save the pointcloud array data
                 if (data_byte is None) | (len(data_byte) != data_legth):
@@ -317,7 +318,7 @@
                 else:
                     # frame the bytes to array
                     data_array = np.frombuffer(data_byte,dtype=dt)
-                    data_array = data_array.reshape(rows,cols)
+                    data_array = data_array.reshape(rows,cols,order=order)
                     # save the data with .ply format
                     filename = f"{msg_source}_{msg_timestamp}_pointcloud{id}"
                     write_ply(data_array,self.plysmsg_folder,filename)
@@ -354,27 +355,75 @@
                     source:str,
                     routing_key:str):
 
-        # constract a images message
-        imagesMsg = pb.ImagesMessage()
-        imagesMsg.source = source
-        curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
-        imagesMsg.timestamp = curr_time
+    # constract a images message
+    imagesMsg = pb.ImagesMessage()
+    imagesMsg.source = source
+    curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
+    imagesMsg.timestamp = curr_time
 
-        for img in images:
-            if img is not None:
-                success,image_encoded = cv2.imencode(".jpg",img)
-                if success:
-                    image_bytes = image_encoded.tobytes()
-                    image_length = len(image_bytes)
-                    # add the encoded image to msg
-                    image_item = imagesMsg.Image.add()
-                    image_item.length = image_length
-                    image_item.data = image_bytes
+    for img in images:
+        if img is not None:
+            success,image_encoded = cv2.imencode(".jpg",img)
+            if success:
+                image_bytes = image_encoded.tobytes()
+                image_length = len(image_bytes)
+                # add the encoded image to msg
+                image_item = imagesMsg.Image.add()
+                image_item.length = image_length
+                image_item.data = image_bytes
 
-        # converting the pb image msg to bytes
-        imageMsg_bytes = imagesMsg.SerializeToString()
-        # add the imageMsg to the queue
-        images_queue.put([routing_key,imageMsg_bytes])
+    # converting the pb image msg to bytes
+    imageMsg_bytes = imagesMsg.SerializeToString()
+    # add the imageMsg to the queue
+    images_queue.put([routing_key,imageMsg_bytes])
+
+def send_pointcloud_tool(pointclouds:queue.Queue,
+                        plys_queue:queue.Queue,
+                        source:str,
+                        routing_key:str):
+
+    # constract a plys message
+    plysMsg = pb.PlysMessage()
+    plysMsg.source = source
+    curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
+    plysMsg.timestamp = curr_time
+
+
+    run =True
+    while run:
+        while not pointclouds.empty():
+            
+            value = pointclouds.get()
+
+            if value is not False:
+                pointcloud = np.array(value)
+                # get the attributes of the PointCloudItem
+                rows = pointcloud.shape[0]
+                cols = pointcloud.shape[1]
+                order = "C"
+                dtype = str(pointcloud.dtype)
+                data = pointcloud.tobytes(order=order)
+                length = len(data)
+
+                # add the pointcloud to the msg
+                item  = plysMsg.Plydata.add()
+                item.length = length
+                item.rows = rows
+                item.cols = cols
+                item.order = order
+                item.dtype = dtype
+                item.data = data
+
+            else:
+                # converting the pb ply msg to bytes
+                plysMsg_bytes = plysMsg.SerializeToString()
+                # add the plysMsg to the queue
+                plys_queue.put([routing_key,plysMsg_bytes])
+
+                # end the outer while loop and triminate this function
+                run = False
+
+    
 
 
     

--
Gitblit v1.9.1