Commit 859cec83 authored by artificiel's avatar artificiel
Browse files

CropFilter: debut de l'integration cylindrique

parent 992069f0
......@@ -2,6 +2,8 @@
#ifndef CLOUDLIB_CROPFILTER_HPP_
#define CLOUDLIB_CROPFILTER_HPP_
#include "ofxTimeMeasurements.h"
#include "ofxCloudLib/ParsedParameterGroup.hpp"
#include "ofxGui.h"
#include "ofxOsc.h"
......@@ -61,16 +63,11 @@ class CropFilterParameterGroup : public ofxCloudLib::ParsedParameterGroup
class CropFilter
{
public:
CropFilter(int i)
CropFilter(int i, int total = 8)
{
index_ = i;
result_.reset(new pcl::PointCloud<pcl::PointXYZ>);
color_.setHsb((i / 8.0) * 255, 255, 215, 255);
}
void setup()
{
color_.setHsb((float(i) / float(total)) * 255, 255, 128, 200);
}
float get_fill()
......@@ -88,81 +85,40 @@ class CropFilter
ofPopStyle();
}
void draw()
{
glm::vec3 size = parameters_.dim_.get();
//,a glm::vec3 fillsize = parameters_.dim_.get() * glm::vec3(1, get_fill(), 1);
// glm::vec3 fillpos = parameters_.pos_.get() - glm::vec3(0, (size.y * (1.0 - get_fill())) / 2, 0);
ofPushStyle();
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofDisableDepthTest();
if (parameters_.enabled_) {
ofSetColor(color_);
ofNoFill();
ofDrawBox(parameters_.pos_, size.x, size.y, size.z);
ofFill();
auto c = color_;
c.a = ofMap(get_fill(), 0, .25, 10, 50, true);
if (parameters_.count_ > 0) {
glm::vec3 fillsize = parameters_.dim_.get() * glm::vec3(1, get_fill(), 1);
glm::vec3 fillpos = parameters_.pos_.get() - glm::vec3(0, (size.y * (1.0 - get_fill())) / 2, 0);
ofSetColor(c);
ofDrawBox(fillpos, fillsize.x, fillsize.y, fillsize.z);
}
if (parameters_.rms_ > 0) {
glm::vec3 fillsize = parameters_.dim_.get() * glm::vec3(1, parameters_.rms_, 1);
glm::vec3 fillpos = parameters_.pos_.get() - glm::vec3(0, (size.y * (1.0 - parameters_.rms_)) / 2, 0);
ofSetColor(255, 0, 0, ofMap(parameters_.rms_, 0, .25, 10, 150, true));
ofDrawBox(fillpos, fillsize.x, fillsize.y, fillsize.z);
}
if (parameters_.state_) {
ofSetColor(color_);
} else {
auto c = color_;
c.a = 128;
ofSetColor(color_);
}
ofDrawBox(parameters_.pos_->x,0,parameters_.pos_->z, size.x, .01, size.z);
} else {
ofSetColor(200, 200, 200, 128);
ofNoFill();
ofDrawBox(parameters_.pos_, size.x, size.y, size.z);
ofFill();
}
ofPopStyle();
}
virtual void draw() = 0;
virtual bool apply_rule(pcl::PointXYZ &p) = 0;
void perform(pcl::PointCloud<pcl::PointXYZ>::Ptr input_cloud)
{
if (parameters_.enabled_) {
if (parameters_.enabled_ && input_cloud->size() > 0) {
result_->clear();
parameters_.height_ = 0;
float new_height = 0;
// apply_rule from here
// perhaps only on param_changes? (setup_rules()?)
min_ = parameters_.pos_.get() - (parameters_.dim_.get() / 2);
max_ = parameters_.pos_.get() + (parameters_.dim_.get() / 2);
// end perhaps
parameters_.height_ = 0;
float new_height = 0;
for (int i = 0; i < input_cloud->size(); i++) {
auto p = input_cloud->points[i];
if (apply_rule(p)) {
result_->push_back(p);
// perhaps another loop outside apply_rule?
if (p.y > new_height) new_height = ofMap(p.y, min_.y, max_.y, 0, 1, true);
}
}
// end apply_rule
if (new_height > parameters_.height_) {
parameters_.height_ = new_height;
} else {
parameters_.height_ = new_height * parameters_.slide_down_ +
parameters_.height_ * (1.0 - parameters_.slide_down_);
parameters_.height_ = new_height * parameters_.slide_down_ + parameters_.height_ * (1.0 - parameters_.slide_down_);
}
if (!parameters_.state_) {
......@@ -205,7 +161,55 @@ class CropFilter
class CropBoxFilter : public CropFilter
{
public:
CropBoxFilter(int i) : CropFilter(i){};
CropBoxFilter(int i, int total = 8) : CropFilter(i, total){};
void draw() override
{
glm::vec3 size = parameters_.dim_.get();
ofPushStyle();
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofDisableDepthTest();
if (parameters_.enabled_) {
ofSetColor(color_);
ofNoFill();
ofDrawBox(parameters_.pos_, size.x, size.y, size.z);
ofFill();
auto c = color_;
c.a = ofMap(get_fill(), 0, .25, 10, 50, true);
if (parameters_.count_ > 0) {
glm::vec3 fillsize = parameters_.dim_.get() * glm::vec3(1, get_fill(), 1);
glm::vec3 fillpos = parameters_.pos_.get() - glm::vec3(0, (size.y * (1.0 - get_fill())) / 2, 0);
ofSetColor(c);
ofDrawBox(fillpos, fillsize.x, fillsize.y, fillsize.z);
}
if (parameters_.rms_ > 0) {
glm::vec3 fillsize = parameters_.dim_.get() * glm::vec3(1, parameters_.rms_, 1);
glm::vec3 fillpos = parameters_.pos_.get() - glm::vec3(0, (size.y * (1.0 - parameters_.rms_)) / 2, 0);
ofSetColor(255, 0, 0, ofMap(parameters_.rms_, 0, .25, 10, 150, true));
ofDrawBox(fillpos, fillsize.x, fillsize.y, fillsize.z);
}
if (parameters_.state_) {
ofSetColor(color_);
} else {
auto c = color_;
c.a = 128;
ofSetColor(color_);
}
ofDrawBox(parameters_.pos_->x, 0, parameters_.pos_->z, size.x, .01, size.z);
} else {
ofSetColor(200, 200, 200, 128);
ofNoFill();
ofDrawBox(parameters_.pos_, size.x, size.y, size.z);
ofFill();
}
ofPopStyle();
}
bool apply_rule(pcl::PointXYZ &p) override
{
......@@ -217,10 +221,59 @@ class CropBoxFilter : public CropFilter
class CropCylinderFilter : public CropFilter
{
public:
CropCylinderFilter(int i) : CropFilter(i){};
CropCylinderFilter(int i, int total = 8) : CropFilter(i, total){};
void draw() override
{
glm::vec3 size = parameters_.dim_.get();
ofPushStyle();
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofDisableDepthTest();
if (parameters_.enabled_) {
ofSetColor(color_);
ofNoFill();
ofDrawBox(parameters_.pos_, size.x, size.y, size.z);
ofFill();
auto c = color_;
c.a = ofMap(get_fill(), 0, .25, 10, 50, true);
if (parameters_.count_ > 0) {
glm::vec3 fillsize = parameters_.dim_.get() * glm::vec3(1, get_fill(), 1);
glm::vec3 fillpos = parameters_.pos_.get() - glm::vec3(0, (size.y * (1.0 - get_fill())) / 2, 0);
ofSetColor(c);
ofDrawBox(fillpos, fillsize.x, fillsize.y, fillsize.z);
}
if (parameters_.rms_ > 0) {
glm::vec3 fillsize = parameters_.dim_.get() * glm::vec3(1, parameters_.rms_, 1);
glm::vec3 fillpos = parameters_.pos_.get() - glm::vec3(0, (size.y * (1.0 - parameters_.rms_)) / 2, 0);
ofSetColor(255, 0, 0, ofMap(parameters_.rms_, 0, .25, 10, 150, true));
ofDrawBox(fillpos, fillsize.x, fillsize.y, fillsize.z);
}
if (parameters_.state_) {
ofSetColor(color_);
} else {
auto c = color_;
c.a = 128;
ofSetColor(color_);
}
ofDrawCylinder(parameters_.pos_->x, parameters_.pos_->y, parameters_.pos_->z, size.x, size.z);
} else {
ofSetColor(200, 200, 200, 128);
ofNoFill();
ofDrawBox(parameters_.pos_, size.x, size.y, size.z);
ofFill();
}
ofPopStyle();
}
bool apply_rule(pcl::PointXYZ &p) override
{
// THIS FOR BOX!
return (p.x > min_[0] && p.y > min_[1] && p.z > min_[2] &&
p.x < max_[0] && p.y < max_[1] && p.z < max_[2]);
}
......@@ -236,8 +289,11 @@ class FilterManager
parameters_.setName("FilterManager");
parameters_.add(enabled_.set("enabled", true));
for (size_t i = 0; i < num_filters; i++) {
filters_.push_back(new CropBoxFilter(i));
// TODO: figure out parametrisation of type (same type for all manager?)
filters_.push_back(new CropCylinderFilter(i));
filters_.back()->parameters_.setName("Filter #" + ofToString(i));
parameters_.add(filters_.back()->parameters_);
}
......@@ -260,35 +316,43 @@ class FilterManager
void update(pcl::PointCloud<pcl::PointXYZ>::Ptr input_cloud)
{
ofxOscMessage m, m_height;
m.setAddress("/filter_manager/counts");
m_height.setAddress("/filter_manager/height");
for (const auto &filter : filters_) {
filter->perform(input_cloud);
if (filter->parameters_.state_ != filter->parameters_.newstate_) {
ofxOscMessage m2;
m2.setAddress("/filter_manager/event/state");
m2.addIntArg(filter->index_);
m2.addIntArg(filter->parameters_.newstate_);
sender_->sendMessage(m2);
filter->parameters_.state_ = filter->parameters_.newstate_;
// // exception hard-codee: si une zone ext est released avant la int, releasera la int
// if (filter->index_ > =8 && filter->parameters_.state_ == false) {
// filters_[filter->index_-1].newstate_ = false;
// }
}
// m.addIntArg(filter->parameters_.count_);
m.addFloatArg(filter->get_fill());
m_height.addFloatArg(filter->parameters_.height_);
if (enabled_) {
TS_START("FilterManager::update()");
ofxOscMessage m, m_height;
m.setAddress("/filter_manager/counts");
m_height.setAddress("/filter_manager/height");
for (const auto &filter : filters_) {
filter->perform(input_cloud);
if (filter->parameters_.state_ != filter->parameters_.newstate_) {
excitated_ = true;
ofxOscMessage m2;
m2.setAddress("/filter_manager/event/state");
m2.addIntArg(filter->index_);
m2.addIntArg(filter->parameters_.newstate_);
sender_->sendMessage(m2);
filter->parameters_.state_ = filter->parameters_.newstate_;
// // exception hard-codee: si une zone ext est released avant la int, releasera la int
// if (filter->index_ > =8 && filter->parameters_.state_ == false) {
// filters_[filter->index_-1].newstate_ = false;
// }
}
sender_->sendMessage(m);
sender_->sendMessage(m_height);
// m.addIntArg(filter->parameters_.count_);
if (excitated_) {
m.addFloatArg(filter->get_fill());
m_height.addFloatArg(filter->parameters_.height_);
}
}
// sender_->sendMessage(m);
// sender_->sendMessage(m_height);
TS_STOP("FilterManager::update()");
}
}
void process_osc(ofxOscMessage &m)
{
if (m.getAddress() == "/filter_manager/filter/set") {
......@@ -316,11 +380,19 @@ class FilterManager
}
std::vector<CropFilter *> &get_filters() { return filters_; }
void draw()
{
ofPushMatrix();
ofPopStyle();
ofEnableLighting();
for (const auto &filter : filters_) {
filter->draw();
}
ofDisableLighting();
ofPopStyle();
ofPopMatrix();
}
void draw_floor(size_t index, ofColor color, float size, std::string label)
......@@ -337,6 +409,7 @@ class FilterManager
ofxPanel zones_gui_;
private:
bool excitated_ = false;
std::vector<CropFilter *> filters_;
ofxOscSender *sender_;
};
......
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