Commit 0b60aac8 authored by alexandre burton's avatar alexandre burton
Browse files

Merge branch...

Merge branch '38-example_client-restaurer-la-possibilite-d-afficher-un-modele-pour-faciliter-la-calib-avec-le-world' into 'master'

Resolve "example_client: restaurer la possibilité d'afficher un modèle (pour faciliter la calib avec le world)"

Closes #38

See merge request !3
parents 7277380a 8fcbd143
ofxAssimpModelLoader
ofxPoco
ofxIO
ofxMiniPID
......
{
"marqueurs": [
{
"id": 1,
"position": [0,0,0],
"dimension": [0.5,0.5,2]
},
{
"id": 2,
"position": [0,2,0],
"dimension": [0.5,0.5,2]
},
{
"id": 3,
"position": [0,-2,0],
"dimension": [0.5,0.5,2]
}
]
}
\ No newline at end of file
#
## Alias OBJ Material File
# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
newmtl _17
Ka 0.000000 0.000000 0.000000
Kd 0.321569 0.321569 0.321569
Ks 0.330000 0.330000 0.330000
d 0.360237
# Alias OBJ Model File
# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
# File units = millimeters
mtllib marqueurs_mesh.mtl
g Mesh1 jardin Model
usemtl _17
v -1330 290 0
vt 0 0
vn 0 0 -1
v -1000 290 0
vt 0 12.9921
v -1000 -290 0
vt -22.8346 12.9921
v -1330 -290 0
vt -22.8346 -4.26326e-14
f 1/1/1 2/2/1 3/3/1 4/4/1
vn -1.64071e-15 1 0
v -1330 290 440
vt 0 17.3228
v -1000 290 440
vt -12.9921 17.3228
vt -12.9921 0
f 1/1/2 5/5/2 6/6/2 2/7/2
vn -1 -6.22337e-16 0
vt 22.8346 0
v -1330 -290 440
vt 22.8346 17.3228
f 5/5/3 1/1/3 4/8/3 7/9/3
vt 12.9921 0
vn 1.64071e-15 -1 0
v -1000 -290 440
vt 12.9921 17.3228
vt -4.17533e-14 17.3228
vt -4.17533e-14 0
f 3/10/4 8/11/4 7/12/4 4/13/4
vt -22.8346 17.3228
vn 1 1.86701e-15 0
vt -22.8346 0
vt -2.43992e-15 0
vt -2.43992e-15 17.3228
f 8/14/5 3/15/5 2/16/5 6/17/5
vt 22.8346 12.9921
vn 0 0 1
vt 22.8346 -4.26326e-14
f 8/18/6 6/2/6 5/1/6 7/19/6
g Mesh2 court Model
v 1000 290 4.74829e-14
v 1330 290 4.74829e-14
v 1330 -290 4.74829e-14
v 1000 -290 4.74829e-14
f 9/1/1 10/2/1 11/3/1 12/4/1
v 1000 290 440
v 1330 290 440
f 9/1/2 13/5/2 14/6/2 10/7/2
v 1000 -290 440
f 13/5/3 9/1/3 12/8/3 15/9/3
v 1330 -290 440
f 11/10/4 16/11/4 15/12/4 12/13/4
f 16/14/5 11/15/5 10/16/5 14/17/5
f 16/18/6 14/2/6 13/1/6 15/19/6
#
## Alias OBJ Material File
# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
newmtl WOOD_LIGHT
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.800000 0.800000
Ks 0.330000 0.330000 0.330000
newmtl cstm_sound_tapis
Ka 0.000000 0.000000 0.000000
Kd 0.792157 0.792157 0.788235
Ks 0.330000 0.330000 0.330000
newmtl Chris_Hair
Ka 0.000000 0.000000 0.000000
Kd 0.278431 0.298039 0.290196
Ks 0.330000 0.330000 0.330000
newmtl Material_043
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.701961 0.458824
Ks 0.330000 0.330000 0.330000
newmtl Material_029
Ka 0.000000 0.000000 0.000000
Kd 0.066667 0.066667 0.066667
Ks 0.330000 0.330000 0.330000
newmtl Chris_Skin
Ka 0.000000 0.000000 0.000000
Kd 0.752941 0.643137 0.450980
Ks 0.330000 0.330000 0.330000
newmtl _Charcoal_
Ka 0.000000 0.000000 0.000000
Kd 0.137255 0.137255 0.137255
Ks 0.330000 0.330000 0.330000
newmtl _White_
Ka 0.000000 0.000000 0.000000
Kd 1.000000 1.000000 1.000000
Ks 0.330000 0.330000 0.330000
newmtl _DarkGray__0_000
Ka 0.000000 0.000000 0.000000
Kd 0.019608 0.019608 0.019608
Ks 0.330000 0.330000 0.330000
This diff is collapsed.
This diff is collapsed.
......@@ -23,6 +23,7 @@
// CLOUDLIB
#include "ofxCloudLib/ModelsManager.hpp"
#include "ofxCloudLib/ClientParameterGroups.hpp" // TODO rationaliser
#include "ofxCloudLib/Cropper.hpp"
#include "ofxCloudLib/OutliersFilter.hpp"
......@@ -150,7 +151,7 @@ class ofApp : public ofBaseApp
for (const auto &v : crop_mesh_.getVertices()) {
boundingbox_->push_back(pcl::PointXYZ(v.x * parameters_.enflure_, v.y * parameters_.enflure_, v.z * parameters_.enflure_));
}
std::cout << "loadé boundingbox avec " << boundingbox_->size() << " vertex" << std::endl;
std::cout << "loaded boundingbox avec " << boundingbox_->size() << " vertex" << std::endl;
hull_.setComputeAreaVolume(true);
hull_.setInputCloud(boundingbox_);
......@@ -201,6 +202,8 @@ class ofApp : public ofBaseApp
ofxOscParameterSync osc_sync_;
bool sync_active_ = false;
ofxCloudLib::ModelsManager models_manager_;
pcl::PointCloud<pcl::PointXYZ>::Ptr boundingbox_;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_inside_hull_;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_outside_hull_;
......
#ifndef Calibration_h
#define Calibration_h
#include "ofMain.h"
namespace ofxCloudLib
{
class Marqueur {
public:
Marqueur(size_t id, glm::vec3 position, glm::vec3 dimension) {
position_=position;
dimension_=dimension;
id_=id;
}
void draw() {
ofPushStyle();
ofPushMatrix();
ofDrawBox(position_, dimension_.x, dimension_.y, dimension_.z);
ofTranslate(position_);
ofDrawBitmapString("M"+ofToString(id_),0,0);
ofPopMatrix();
ofPopStyle();
}
glm::vec3 position_;
glm::vec3 dimension_;
size_t id_;
};
class Calibration {
public:
Calibration () {};
bool setup(std::string json_path) {
ofFile file(json_path);
if(file.exists()){
file >> js_;
for(auto & marqueur: js_["marqueurs"]){
marqueurs_.push_back(make_unique<Marqueur>(marqueur["id"],
glm::vec3(marqueur["position"][0], marqueur["position"][1], marqueur["position"][2]),
glm::vec3(marqueur["dimension"][0],marqueur["dimension"][1],marqueur["dimension"][2])));
}
return true;
} else {
std::cout << "Calibration: configuration non-existante: " << json_path << std::endl;
return false;
}
}
void draw() {
for (const auto & marqueur: marqueurs_) {
marqueur->draw();
}
}
std::vector<std::unique_ptr<Marqueur>> marqueurs_;
ofJson js_;
};
}
#endif /* Calibration_h */
......@@ -152,7 +152,7 @@ void ClientConnector::update()
string str = receive();
if (str.length() > 0) {
std::cout << "PROCESSING TCP STREAM FROM " << client_name_ << ":" << str << std::endl;
// std::cout << "PROCESSING TCP STREAM FROM " << client_name_ << ":" << str << std::endl;
boost::char_separator<char> sep(" ");
boost::tokenizer<boost::char_separator<char>> tokens(str, sep);
......@@ -161,7 +161,7 @@ void ClientConnector::update()
for (const auto &t : tokens) {
message.push_back(t);
std::cout << " tokens:" << t << std::endl;
// std::cout << " tokens:" << t << std::endl;
}
if (message.size() == 0) {
std::cout << "TCP erreur: message vide" << std::endl;
......@@ -220,7 +220,7 @@ void ClientConnector::update()
std::cout << "got TCP unknown msg from " << client_name_ << ":" << str
<< std::endl;
}
std::cout << "DONE PROCESSING TCP STREAM FROM " << client_name_ << std::endl;
// std::cout << "DONE PROCESSING TCP STREAM FROM " << client_name_ << std::endl;
}
} else {
delta_time_ = ofGetElapsedTimeMillis() - connect_time_;
......
......@@ -65,6 +65,8 @@ class CropFilter
{
index_ = i;
result_.reset(new pcl::PointCloud<pcl::PointXYZ>);
color_.setHsb((i/16.0)*255, 255, 128, 100);
}
void setup()
......@@ -82,16 +84,21 @@ class CropFilter
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(0, 255, 0, 128);
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(0, 255, 0, ofMap(get_fill(), 0, .25, 10, 50, true));
ofSetColor(c);
ofDrawBox(fillpos, fillsize.x, fillsize.y, fillsize.z);
}
if (parameters_.rms_ > 0) {
......@@ -170,6 +177,7 @@ class CropFilter
pcl::PointCloud<pcl::PointXYZ>::Ptr result_;
CropFilterParameterGroup parameters_;
glm::vec3 min_, max_;
ofColor color_;
size_t index_;
// char * rgbw_[4];
......@@ -206,7 +214,9 @@ class FilterManager
{
sender_ = sender;
rgbw_.allocate(num_filters * 4, 1, OF_IMAGE_COLOR_ALPHA);
artnet_.setup("192.168.94.62");
my_artnet_ip_= "192.168.94.62";
setup_artnet();
parameters_.setName("FilterManager");
parameters_.add(enabled_.set("enabled", true));
......@@ -217,6 +227,17 @@ class FilterManager
}
}
void setup_artnet() {
std::cout << "setting up artnet on " << my_artnet_ip_ << std::endl;
if (artnet_ != nullptr) {
std::cout << "...(stopping previous instance)..." << my_artnet_ip_ << std::endl;
artnet_->waitForThread();
artnet_.release();
}
artnet_=make_unique<ofxArtnet>();
artnet_->setup(my_artnet_ip_.c_str(),0,0);
}
void update(pcl::PointCloud<pcl::PointXYZ>::Ptr input_cloud)
{
ofxOscMessage m, m_height;
......@@ -254,7 +275,9 @@ class FilterManager
rgbw_.getPixels().getData()[filter->index_ * 4 + 3] = int(ofMap(amp, 0, 1, 0, 255, true));
}
}
artnet_.sendDmx("192.168.94.3", 0, 0, rgbw_.getPixels().getData(), 16);
if (artnet_->sendDmx("192.168.94.244", 0, 0, rgbw_.getPixels().getData(), 16) == -3) {
setup_artnet();
}
sender_->sendMessage(m);
sender_->sendMessage(m_height);
......@@ -303,7 +326,8 @@ class FilterManager
ofImage rgbw_;
private:
ofxArtnet artnet_;
std::string my_artnet_ip_;
std::unique_ptr<ofxArtnet> artnet_;
std::vector<CropFilter *> filters_;
ofxOscSender *sender_;
......
......@@ -27,7 +27,6 @@ class Cropper
void draw()
{
ofSetColor(0, 255, 0, 100);
ofNoFill();
ofSetBoxResolution(2);
......
......@@ -78,7 +78,6 @@ class Merger
scene_model_.disableMaterials();
scene_model_.disableTextures();
if (marqueurs_model_.hasMeshes()) {
std::cout << "marqueurs_model_ #meshes: " << marqueurs_model_.getNumMeshes() << std::endl;
}
......@@ -129,7 +128,7 @@ class Merger
ofSetColor(255, 255, 255, 100);
ofRotateDeg(-180, 1, 0, 0); // ceci aaligne le modele avec le cloud
ofRotateYDeg(90); // ceci aaligne le modele avec le cloud
// ofRotateXDeg(180); // ceci aaligne le modele avec le cloud
//git pu ofRotateXDeg(180); // ceci aaligne le modele avec le cloud
ofScale(250);
if (wireframe_models_) {
......
#ifndef MODELS_MANAGER_HPP
#define MODELS_MANAGER_HPP
#include "ofMain.h"
#include "ofxAssimpModelLoader.h"
namespace ofxCloudLib {
class ModelsManager {
public:
ModelsManager(){};
void setup(std::string scene_path, std::string marqueurs_path) {
parameters_.add(draw_marqueurs_.set("draw marqueurs",true));
parameters_.add(draw_scene_.set("draw scene",true));
parameters_.add(model_color_.set("couleur",ofColor::white, ofColor::black, ofColor::white));
parameters_.setName("Models");
scene_path_ = scene_path;
marqueurs_path_ = marqueurs_path;
model_material_.setAmbientColor(ofFloatColor(1.0, 1.0, 1.0, 1.0));
model_material_.setDiffuseColor(ofFloatColor(0.8, 0.8, 0.8, 1.0));
model_material_.setSpecularColor(ofFloatColor(0.8, 0.8, 0.8, 1.0));
model_material_.setShininess(10);
light_jardin_.setAreaLight(600, 400);
light_jardin_.setAmbientColor(ofFloatColor(0.5, 1, 0.5));
light_jardin_.setAttenuation(0.001, 0.001, 0.01);
light_jardin_.setDiffuseColor(ofFloatColor(.9, .4, .4));
light_jardin_.setSpecularColor(ofFloatColor(.5, .9, .5));
light_jardin_.setPosition(300, 0, 400);
light_court_.setAreaLight(600, 400);
light_court_.setAmbientColor(ofFloatColor(1.0, 1.0, 1.0));
light_court_.setAttenuation(.0001, 0.0001, 0.0001);
light_court_.setDiffuseColor(ofFloatColor(1., 1., 1.));
light_court_.setSpecularColor(ofFloatColor(1., 1., 1.));
light_court_.setPosition(-200, 0, 350);
reload_models();
}
void reload_models() {
std::cout << "MODELS MANAGER: reloading models " << marqueurs_path_ << " & "
<< scene_path_ << std::endl;
marqueurs_model_.setScaleNormalization(false);
marqueurs_model_.setScale(.1, .1, .1);
scene_model_.setScaleNormalization(false);
scene_model_.setScale(.1, .1, .1);
marqueurs_model_.loadModel(marqueurs_path_);
scene_model_.loadModel(scene_path_);
marqueurs_model_.setScaleNormalization(false);
marqueurs_model_.setScale(.1, .1, .1);
scene_model_.setScaleNormalization(false);
scene_model_.setScale(.1, .1, .1);
scene_model_.disableColors();
scene_model_.disableMaterials();
scene_model_.disableTextures();
marqueurs_model_.disableColors();
marqueurs_model_.disableMaterials();
marqueurs_model_.disableTextures();
if (marqueurs_model_.hasMeshes()) {
std::cout << "marqueurs_model_ #meshes: "
<< marqueurs_model_.getNumMeshes() << std::endl;
}
if (scene_model_.hasMeshes()) {
std::cout << "scene_model_ #meshes:" << scene_model_.getNumMeshes()
<< std::endl; // should not crash
}
}
void draw() {
bool wireframe_models_ = false;
ofPushStyle();
ofSetColor(model_color_);
ofEnableBlendMode(OF_BLENDMODE_ALPHA);
if (draw_scene_) {
ofPushMatrix();
// ofRotateDeg(-180, 1, 0, 0); // disque
// ofRotateDeg(180, 1, 0, 0);
// ofRotateYDeg(90); // ceci aligne le modele sketchup avec le
// cloud ??
// ofRotateXDeg(180); // ceci aligne le modele sketchup avec le cloud
ofRotateDeg(180, 1, 0, 0);
ofScale(2);
if (wireframe_models_) {
scene_model_.drawWireframe();
} else {
ofPushStyle();
ofEnableLighting();
light_jardin_.enable();
light_court_.enable();
model_material_.begin();
// scene_model_.drawFaces();
model_material_.end();
light_jardin_.disable();
light_court_.disable();
ofDisableLighting();
// ofSetColor(model_color_);
ofEnableBlendMode(OF_BLENDMODE_ADD);
scene_model_.drawWireframe();
ofPopStyle();
}
ofPopMatrix();
}
if (draw_marqueurs_) {
ofPushMatrix();
// ofSetColor(80, 80, 80, 80);
ofRotateDeg(-90, 1, 0, 0);
ofScale(.01);
if (wireframe_models_) {
marqueurs_model_.drawWireframe();
} else {
ofPushStyle();
ofEnableLighting();
light_jardin_.enable();
light_court_.enable();
model_material_.begin();
marqueurs_model_.drawFaces();
model_material_.end();
light_jardin_.disable();
light_court_.disable();
ofDisableLighting();
ofPopStyle();
// ofSetColor(255, 255, 255, 128);
ofEnableBlendMode(OF_BLENDMODE_ADD);
marqueurs_model_.drawWireframe();
}
ofPopMatrix();
ofSetColor(255, 255, 255, 150);
}
// if (draw_lights_) {
// light_jardin_.draw();
// light_court_.draw();
// }
ofPopStyle();
}
std::string scene_path_;
std::string marqueurs_path_;
ofxAssimpModelLoader scene_model_;
ofxAssimpModelLoader marqueurs_model_;
ofMaterial model_material_;
ofLight light_jardin_;
ofLight light_court_;
ofParameterGroup parameters_;
ofParameter<bool> draw_scene_;
ofParameter<bool> draw_marqueurs_;
ofParameter<ofColor> model_color_;
};
} // namespace ofxCloudLib
#endif // MODELS_MANAGER_HPP
......@@ -14,7 +14,7 @@ class ParsedParameterGroup : public ofParameterGroup
{
string name = e->getName();
boost::replace_all(name, " ", "&nbsp;");
std::cout << "stored " << name << std::endl;
// std::cout << "stored " << name << std::endl;
parameter_to_string_mapping_[e] = name;
string_to_parameter_mapping_[name] = e;
}
......
Supports Markdown
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