Commit dd53beba authored by artificiel's avatar artificiel
Browse files

CloudPlayerThread: instance stack au lieu de pointeur dans Channel

parent 635f93a1
......@@ -18,14 +18,16 @@ class CloudPlayerThread : public ofThread
pcl::io::HIGH_RES_OFFLINE_COMPRESSION_WITH_COLOR,
false, .01, .01, false, 1, 1,
static_cast<unsigned char>(4));
}
~CloudPlayerThread()
{
recorded_.close();
waitForThread(true);
output_cloud_.reset(new pcl::PointCloud<pcl::PointXYZ>);
}
// ~CloudPlayerThread()
// {
// recorded_.close();
// waitForThread(true);
// }
bool setup(std::string playback_path)
{
playback_path_ = playback_path;
......@@ -53,7 +55,7 @@ class CloudPlayerThread : public ofThread
startThread();
}
pcl::PointCloud<pcl::PointXYZ>::Ptr get_cloud()
pcl::PointCloud<pcl::PointXYZ> &get_cloud()
{
return cloud_;
}
......@@ -66,7 +68,7 @@ class CloudPlayerThread : public ofThread
new_cloud_ = true;
}
if (new_cloud_) {
// std::cout << "cloud data available with " << cloud_->size() << " points" << std::endl;
// ofLogNotice("CloudPlayerThread") << "safe cloud data with " << cloud_.size() << " points";
}
}
......@@ -78,14 +80,14 @@ class CloudPlayerThread : public ofThread
new_mesh_ = true;
}
if (new_mesh_) {
// std::cout << "mesh data available with " << mesh_.getNumVertices() << " vertices" << std::endl;
// ofLogNotice("CloudPlayerThread") << "safe mesh data with " << mesh_.getNumVertices() << " vertices";
}
}
bool is_cloud_new() { return new_cloud_; }
bool is_mesh_new() { return new_mesh_; }
ofMesh &get_mesh() { return mesh_; }
float offset_x_, offset_z_;
void stop()
......@@ -102,21 +104,22 @@ class CloudPlayerThread : public ofThread
void threadedFunction()
{
ofLogNotice("CloudPlayerThread") << "thread started";
decodingFenceTimestamp = 0;
while (1) {
if (stop_thread_) {
stop_thread_ = false;
ofLogNotice("CloudPlayerThread") << "thread stopped";
return;
}
auto sysnow = std::chrono::system_clock::now();
auto duration = sysnow.time_since_epoch();
uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
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;
......@@ -133,12 +136,10 @@ class CloudPlayerThread : public ofThread
cloudfile.seekg(0);
cloudfile.unsetf(ios_base::skipws);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;
cloud.reset(new pcl::PointCloud<pcl::PointXYZ>);
octree_coder_->decodePointCloud(cloudfile, cloud);
octree_coder_->decodePointCloud(cloudfile, output_cloud_);
struct stat st;
// int ierr = stat(filename_to_decode, &st);
stat(filename_to_decode, &st);
uint64_t status_ms = st.st_ctime * 1000 + st.st_ctim.tv_nsec / 1000000;
......@@ -147,38 +148,38 @@ class CloudPlayerThread : public ofThread
} else {
delay = status_ms - previousCloudTimestamp;
}
// std::cout << "DECODEUR: unforced delay =" << delay << std::endl;
delay = 50;
previousCloudTimestamp = status_ms;
decodingFenceTimestamp = now + delay;
//ofLogNotice("CloudPlayerThread") << decoded_frames_ << " with " << cloud->size() << " points from " << filename_to_decode << " with interval: " << delay;
data_available_ = true;
// ofLogNotice("CloudPlayerThread") << decoded_frames_ << " with " << output_cloud_->size() << " points from " << filename_to_decode << " with interval: " << delay;
ofMesh mesh;
for (unsigned int qq = 0; qq < cloud->size(); qq++) {
mesh.addVertex(ofPoint(cloud->points[qq].x + offset_x_,
cloud->points[qq].y,
cloud->points[qq].z + offset_z_));
for (unsigned int qq = 0; qq < output_cloud_->size(); qq++) {
mesh.addVertex(ofPoint(output_cloud_->points[qq].x + offset_x_,
output_cloud_->points[qq].y,
output_cloud_->points[qq].z + offset_z_));
}
recorded_.send(std::move(cloud));
// recorded_.send(cloud);
// recorded_mesh_.send(mesh);
recorded_.send(std::move(*output_cloud_));
recorded_mesh_.send(std::move(mesh));
}
cloudfile.close();
} else {
// std::cout << "DECODEUR: sleep" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
// std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
}
uint64_t lastDecodingTimestamp = 0;
uint64_t previousCloudTimestamp = 0;
uint64_t decodingFenceTimestamp;
uint64_t decodingFenceTimestamp = 0;
uint64_t delay;
std::string filename_;
......@@ -187,15 +188,16 @@ class CloudPlayerThread : public ofThread
bool new_cloud_ = false;
bool is_setup_ = false;
bool stop_thread_ = false;
bool data_available_ = false;
size_t decoded_frames_ = 0;
size_t total_frames_ = 0;
pcl::PointCloud<pcl::PointXYZ>::Ptr output_cloud_;
ofMesh mesh_;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_;
pcl::PointCloud<pcl::PointXYZ> cloud_;
pcl::io::OctreePointCloudCompression<pcl::PointXYZ> *octree_coder_;
ofThreadChannel<pcl::PointCloud<pcl::PointXYZ>::Ptr> recorded_;
ofThreadChannel<pcl::PointCloud<pcl::PointXYZ>> recorded_;
ofThreadChannel<ofMesh> recorded_mesh_;
};
} // namespace ofxCloudLib
......
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