Commit 03d927ea authored by artificiel's avatar artificiel
Browse files

CloudPlayerThread: buffer de 4 cloud/meshes pour eviter backlog

parent e0d22154
......@@ -8,6 +8,7 @@
namespace ofxCloudLib
{
#define NUM_CLOUD_BUFFERS 4
class CloudPlayerThread : public ofThread
{
public:
......@@ -56,20 +57,19 @@ class CloudPlayerThread : public ofThread
startThread();
}
pcl::PointCloud<pcl::PointXYZ> &get_cloud()
{
return cloud_;
}
pcl::PointCloud<pcl::PointXYZ> &get_cloud() { return cloud_[ready_cloud_buffer_]; }
void update_cloud()
{
new_cloud_ = false;
while (recorded_.tryReceive(cloud_)) {
new_cloud_ = true;
while (recorded_.tryReceive(cloud_[(ready_cloud_buffer_ + 1) % NUM_CLOUD_BUFFERS])) {
new_cloud_ = true;
ready_cloud_buffer_ = (ready_cloud_buffer_ + 1) % NUM_CLOUD_BUFFERS;
}
if (new_cloud_) {
// ofLogNotice("CloudPlayerThread") << "safe cloud data with " << cloud_.size() << " points";
ofLogNotice("CloudPlayerThread") << "safe cloud data with " << cloud_[ready_cloud_buffer_].size() << " points";
}
}
......@@ -77,17 +77,18 @@ class CloudPlayerThread : public ofThread
{
new_mesh_ = false;
while (recorded_mesh_.tryReceive(mesh_)) {
while (recorded_mesh_.tryReceive(mesh_[(ready_mesh_buffer_ + 1) % NUM_CLOUD_BUFFERS])) {
new_mesh_ = true;
ready_mesh_buffer_ = (ready_mesh_buffer_ + 1) % NUM_CLOUD_BUFFERS;
}
if (new_mesh_) {
// ofLogNotice("CloudPlayerThread") << "safe mesh data with " << mesh_.getNumVertices() << " vertices";
ofLogNotice("CloudPlayerThread") << "safe mesh data with " << mesh_[ready_mesh_buffer_].getNumVertices() << " vertices";
}
}
bool is_cloud_new() { return new_cloud_; }
bool is_mesh_new() { return new_mesh_; }
ofMesh &get_mesh() { return mesh_; }
ofMesh &get_mesh() { return mesh_[ready_mesh_buffer_]; }
float offset_x_, offset_z_;
......@@ -125,10 +126,7 @@ class CloudPlayerThread : public ofThread
// recorded_mesh_.close();
ofLogNotice("CloudPlayerThread") << "stopping the thread";
stop_thread_ = false;
stopThread();
ofLogNotice("CloudPlayerThread") << "thread stopped";
return;
......@@ -140,7 +138,6 @@ class CloudPlayerThread : public ofThread
if (now > (decodingFenceTimestamp - ((1000. / 60.) / 2.))) {
// devrait maintenir le modulo de la soustraction pour ne pas accumuler l'erreur (mais pas super grave)
lastDecodingTimestamp = now;
......@@ -176,7 +173,7 @@ class CloudPlayerThread : public ofThread
previousCloudTimestamp = status_ms;
decodingFenceTimestamp = now + delay;
// ofLogNotice("CloudPlayerThread") << decoded_frames_ << " with " << output_cloud_->size() << " points from " << filename_to_decode << " with interval: " << delay;
ofLogNotice("CloudPlayerThread") << decoded_frames_ << " with " << output_cloud_->size() << " points from " << filename_to_decode << " with interval: " << delay;
ofMesh mesh;
for (unsigned int qq = 0; qq < output_cloud_->size(); qq++) {
......@@ -215,10 +212,13 @@ class CloudPlayerThread : public ofThread
size_t decoded_frames_ = 0;
size_t total_frames_ = 0;
size_t ready_cloud_buffer_ = 0;
size_t ready_mesh_buffer_ = 0;
pcl::PointCloud<pcl::PointXYZ>::Ptr output_cloud_;
ofMesh mesh_;
pcl::PointCloud<pcl::PointXYZ> cloud_;
ofMesh mesh_[NUM_CLOUD_BUFFERS];
pcl::PointCloud<pcl::PointXYZ> cloud_[NUM_CLOUD_BUFFERS];
pcl::io::OctreePointCloudCompression<pcl::PointXYZ> *octree_coder_;
ofThreadChannel<pcl::PointCloud<pcl::PointXYZ>> recorded_;
ofThreadChannel<ofMesh> recorded_mesh_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment