Skip to content

Commit

Permalink
[update] remove ofxGui dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
LAPTOP-IA7I9L7L\hiroy committed Apr 16, 2019
1 parent a002a70 commit 0b5dd46
Show file tree
Hide file tree
Showing 30 changed files with 272 additions and 121 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,33 @@ example/recorder/icon.rc
example/recorder/recorder.vcxproj.user
example/recorder/recorder.vcxproj
example/recorder/obj/
*.sln
*.vcxproj
*.filters
*.user
*.rc
example/aligned_example/.vs/
*.pdb
*.lib
*.ilk
*.exp
*.exe
example/aligned_example/bin/fmodexL64.dll
example/aligned_example/bin/fmodex64.dll
example/aligned_example/bin/FreeImage.dll
example/aligned_example/obj/
example/playback_example/.vs/
example/playback_example/bin/fmodexL64.dll
example/playback_example/bin/fmodex64.dll
example/playback_example/bin/FreeImage.dll
example/playback_example/obj/
example/recorder_example/.vs/
example/recorder_example/bin/fmodexL64.dll
example/recorder_example/bin/fmodex64.dll
example/recorder_example/bin/FreeImage.dll
example/recorder_example/obj/
example/simple_example/.vs/
example/simple_example/bin/fmodexL64.dll
example/simple_example/bin/fmodex64.dll
example/simple_example/bin/FreeImage.dll
example/simple_example/obj/
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
ofxGui
ofxLibRealSense2P
File renamed without changes.
File renamed without changes.
File renamed without changes.
80 changes: 80 additions & 0 deletions example/aligned_example/src/ofApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
realsense.setupDevice(0);
//setup different resolution
realsense.enableDepth(1280, 720);
realsense.enableColor(640, 480);
realsense.startStream();

//align depth and color pixel size
realsense.setAligned(true);
}

//--------------------------------------------------------------
void ofApp::update(){
realsense.update();
}

//--------------------------------------------------------------
void ofApp::draw(){
//pixel size is aligned even if it setup different resolution!
realsense.drawDepth(0, 0);
realsense.drawColor(640, 0);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "ofMain.h"
#include "ofxLibRealSense2P.h"
#include "ofxGui.h"

class ofApp : public ofBaseApp{

Expand All @@ -22,7 +21,7 @@ class ofApp : public ofBaseApp{
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

ofxLibRealSense2P realsense;
ofxPanel gui;


};
3 changes: 0 additions & 3 deletions example/playback/bin/data/record.bag

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
ofxGui
ofxLibRealSense2P
Empty file.
Binary file added example/playback_example/bin/realsense2.dll
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ void ofApp::setup(){
realsense.enableDepth(640, 480);
realsense.enableColor(640, 480);
realsense.startStream();

//align depth and color pixel size
realsense.setAligned(true);

panel.setup();
panel.add(realsense.setupGUI());
}

//--------------------------------------------------------------
Expand All @@ -23,7 +17,6 @@ void ofApp::update(){
void ofApp::draw(){
realsense.drawColor(0,0);
realsense.drawDepth(realsense.getColorWidth(), 0);
panel.draw();
}

//--------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "ofMain.h"
#include "ofxLibRealSense2P.h"
#include "ofxGui.h"

class ofApp : public ofBaseApp{

Expand All @@ -23,6 +22,5 @@ class ofApp : public ofBaseApp{
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofxLibRealSense2P realsense;
ofxPanel panel;

};
1 change: 1 addition & 0 deletions example/recorder_example/addons.make
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ofxLibRealSense2P
Binary file added example/recorder_example/bin/realsense2.dll
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ void ofApp::setup(){
realsense.enableDepth(640, 480);
realsense.enableColor(640, 480);
realsense.startStream();

gui.setup();
gui.add(realsense.setupGUI());
}

//--------------------------------------------------------------
Expand All @@ -24,7 +21,6 @@ void ofApp::draw(){
realsense.drawColor(realsense.getDepthWidth(), 0);
ofPopMatrix();
ofDrawBitmapStringHighlight("fps:" + ofToString(ofGetFrameRate(), 2), ofGetWidth() - 160, ofGetHeight() - 20);
gui.draw();
}

//--------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "ofMain.h"
#include "ofxLibRealSense2P.h"
#include "ofxGui.h"

class ofApp : public ofBaseApp{

Expand All @@ -24,5 +23,4 @@ class ofApp : public ofBaseApp{
void gotMessage(ofMessage msg);

ofxLibRealSense2P realsense;
ofxPanel gui;
};
8 changes: 0 additions & 8 deletions example/simple/icon.rc

This file was deleted.

File renamed without changes.
Binary file added example/simple_example/bin/realsense2.dll
Binary file not shown.
13 changes: 13 additions & 0 deletions example/simple_example/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "ofMain.h"
#include "ofApp.h"

//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ void ofApp::setup(){
realsense.enableColor(640, 480);
realsense.startStream();

gui.setup();
gui.add(realsense.setupGUI());
gui.setup(guiUtils.setupGUI(&realsense));
}

//--------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions example/simple_example/src/ofApp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "ofMain.h"
#include "ofxLibRealSense2P.h"
#include "ofxLRS2/GuiUtils.h"
#include "ofxGui.h"

class ofApp : public ofBaseApp{

public:
void setup();
void update();
void draw();

void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

ofxLibRealSense2P realsense;
GuiUtils guiUtils;
ofxPanel gui;
};
4 changes: 2 additions & 2 deletions src/ofxLRS2/Filter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <librealsense2/rs.hpp>
#include "ofxGui.h"
#include <librealsense2/rs.hpp>
#include "ofMain.h"

namespace ofxlibrealsense2p
{
Expand Down
84 changes: 84 additions & 0 deletions src/ofxLRS2/GuiUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "GuiUtils.h"



GuiUtils::GuiUtils()
{
}


GuiUtils::~GuiUtils()
{
}

ofParameterGroup& GuiUtils::setupGUI(ofxLibRealSense2P* realsense)
{
rs2::sensor sensor = realsense->rs2device.query_sensors()[realsense->deviceId];
rs2::option_range orExp = sensor.get_option_range(RS2_OPTION_EXPOSURE);
rs2::option_range orGain = sensor.get_option_range(RS2_OPTION_GAIN);
rs2::option_range orMinDist = realsense->rs2colorizer.get_option_range(RS2_OPTION_MIN_DISTANCE);
rs2::option_range orMaxDist = realsense->rs2colorizer.get_option_range(RS2_OPTION_MAX_DISTANCE);

_D400Params.setName("D400_" + realsense->rs2config.getDeviceSerial());
_D400Params.add(_autoExposure.set("Auto exposure", (bool)sensor.get_option(RS2_OPTION_EXPOSURE)));
_D400Params.add(_enableEmitter.set("Emitter", (bool)sensor.get_option(RS2_OPTION_EMITTER_ENABLED)));
_D400Params.add(_irExposure.set("IR Exposure", orExp.def, orExp.min, 26000));
_D400Params.add(_depthMin.set("Min Depth", orMinDist.def, orMinDist.min, orMinDist.max));
_D400Params.add(_depthMax.set("Max Depth", orMaxDist.def, orMaxDist.min, orMaxDist.max));

for (auto filter : realsense->filters)
{
ofParameterGroup group;
group.setName(filter->getFilterName());
group.add(*filter->getIsEnabled());
for (auto s : filter->getSliders())
{
group.add(*s);
}
_D400Params.add(group);
}

_autoExposure.addListener(this, &GuiUtils::onD400BoolParamChanged);
_enableEmitter.addListener(this, &GuiUtils::onD400BoolParamChanged);
_irExposure.addListener(this, &GuiUtils::onD400IntParamChanged);
_depthMin.addListener(this, &GuiUtils::onD400ColorizerParamChanged);
_depthMax.addListener(this, &GuiUtils::onD400ColorizerParamChanged);

return _D400Params;
}


void GuiUtils::onD400BoolParamChanged(bool &value)
{
rs2::sensor sensor = realsense->rs2_pipeline->get_active_profile().get_device().first<rs2::depth_sensor>();
if (sensor.supports(RS2_OPTION_ENABLE_AUTO_EXPOSURE))
sensor.set_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, _autoExposure ? 1.0f : 0.0f);
if (sensor.supports(RS2_OPTION_EMITTER_ENABLED))
sensor.set_option(RS2_OPTION_EMITTER_ENABLED, _enableEmitter ? 1.0f : 0.0f);
}


void GuiUtils::onD400IntParamChanged(int &value)
{
rs2::sensor sensor = realsense->rs2_pipeline->get_active_profile().get_device().first<rs2::depth_sensor>();
if (sensor.supports(RS2_OPTION_EXPOSURE))
sensor.set_option(RS2_OPTION_EXPOSURE, (float)_irExposure);
}


void GuiUtils::onD400ColorizerParamChanged(float &value)
{
realsense->rs2colorizer.set_option(RS2_OPTION_HISTOGRAM_EQUALIZATION_ENABLED, 0);

if (realsense->rs2colorizer.supports(RS2_OPTION_MIN_DISTANCE))
realsense->rs2colorizer.set_option(RS2_OPTION_MIN_DISTANCE, _depthMin);
if (realsense->rs2colorizer.supports(RS2_OPTION_MAX_DISTANCE))
realsense->rs2colorizer.set_option(RS2_OPTION_MAX_DISTANCE, _depthMax);
}


ofParameterGroup& GuiUtils::getGui()
{
return _D400Params;
}

28 changes: 28 additions & 0 deletions src/ofxLRS2/GuiUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include "ofxLibRealSense2P.h"
#include <librealsense2/rs.hpp>
#include <librealsense2/rsutil.h>

class GuiUtils
{
public:
GuiUtils();
~GuiUtils();

ofParameterGroup& setupGUI(ofxLibRealSense2P* realsense);
ofParameterGroup& getGui();
private:

void onD400BoolParamChanged(bool &value);
void onD400IntParamChanged(int &value);
void onD400ColorizerParamChanged(float &value);
//attribute
ofParameterGroup _D400Params;
ofParameter<bool> _autoExposure;
ofParameter<bool> _enableEmitter;
ofParameter<int> _irExposure;
ofParameter<float> _depthMin;
ofParameter<float> _depthMax;
ofxLibRealSense2P* realsense;
};

0 comments on commit 0b5dd46

Please sign in to comment.