Skip to content

Commit b7a5191

Browse files
committed
Update test samples to use ImGui instead of AntTweakBar
1 parent 960c6ce commit b7a5191

File tree

6 files changed

+250
-46
lines changed

6 files changed

+250
-46
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required( VERSION 3.10 FATAL_ERROR )
2+
set( CMAKE_VERBOSE_MAKEFILE ON )
3+
4+
project( SphereProjectionTest )
5+
6+
get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../" ABSOLUTE )
7+
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../.." ABSOLUTE )
8+
9+
include( "${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake" )
10+
11+
ci_make_app(
12+
APP_NAME "SphereProjectionTest"
13+
CINDER_PATH ${CINDER_PATH}
14+
SOURCES ${APP_PATH}/src/SphereProjectionApp.cpp
15+
INCLUDES ${APP_PATH}/include
16+
)

test/SphereProjection/src/SphereProjectionApp.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "cinder/app/App.h"
22
#include "cinder/app/RendererGl.h"
33
#include "cinder/gl/gl.h"
4-
#include "cinder/params/Params.h"
54
#include "cinder/ip/Checkerboard.h"
65
#include "cinder/Sphere.h"
76
#include "cinder/Timer.h"
7+
#include "cinder/Log.h"
8+
#include "cinder/CinderImGui.h"
9+
#include "cinder/CameraUi.h"
810

911
using namespace ci;
1012
using namespace ci::app;
@@ -18,15 +20,16 @@ class SphereProjectionApp : public App {
1820
void update() override;
1921
void keyDown( KeyEvent event ) override;
2022
void draw() override;
23+
void mouseDown( MouseEvent event ) override;
24+
void mouseDrag( MouseEvent event ) override;
2125

2226
vec2 clipToScreenCoords( const vec2 &v ) const;
2327

2428
vec3 mSpherePositions[3];
2529
float mSphereRadii[3];
2630
CameraPersp mCam;
2731
float mFov;
28-
29-
params::InterfaceGlRef mParams;
32+
CameraUi mCamUi;
3033

3134
gl::TextureRef mTex;
3235
gl::BatchRef mPlaneBatch;
@@ -41,11 +44,9 @@ void SphereProjectionApp::prepareSettings( Settings *settings )
4144

4245
void SphereProjectionApp::setup()
4346
{
44-
mFov = 45.0f;
47+
ImGui::Initialize();
4548

46-
mParams = params::InterfaceGl::create( getWindow(), "App parameters", toPixels( ivec2( 200, 200 ) ) );
47-
mParams->addParam( "FOV", &mFov );
48-
mParams->addButton( "Pause", [=] { if( mTimer.isStopped() ) mTimer.resume(); else mTimer.stop(); } );
49+
mFov = 45.0f;
4950

5051
mCam.lookAt( vec3( 15, 10, 20 ), vec3( 0 ) );
5152

@@ -54,17 +55,14 @@ void SphereProjectionApp::setup()
5455

5556
mPlaneBatch = gl::Batch::create( geom::Plane().size( vec2( 40, 40 ) ), gl::getStockShader( gl::ShaderDef().texture() ) );
5657

58+
mCamUi = CameraUi( &mCam, getWindow(), -1 );
59+
5760
mTimer.start();
5861
}
5962

6063
void SphereProjectionApp::keyDown( KeyEvent event )
6164
{
62-
if( event.getChar() == '1' )
63-
mCam = mCam.calcFraming( Sphere( mSpherePositions[0], mSphereRadii[0] ) );
64-
else if( event.getChar() == '2' )
65-
mCam = mCam.calcFraming( Sphere( mSpherePositions[1], mSphereRadii[1] ) );
66-
else if( event.getChar() == '3' )
67-
mCam = mCam.calcFraming( Sphere( mSpherePositions[2], mSphereRadii[2] ) );
65+
(void)event;
6866
}
6967

7068
void SphereProjectionApp::update()
@@ -130,7 +128,37 @@ void SphereProjectionApp::draw()
130128
gl::drawStrokedCircle( center, std::max( length( axisA ), length( axisB ) ) );
131129
}
132130

133-
mParams->draw();
131+
ImGui::ScopedWindow window( "Sphere Projection Controls" );
132+
float fov = mFov;
133+
if( ImGui::SliderFloat( "Field of View", &fov, 1.0f, 120.0f, "%.1f deg" ) )
134+
mFov = fov;
135+
136+
bool paused = mTimer.isStopped();
137+
if( ImGui::Checkbox( "Pause Animation", &paused ) ) {
138+
if( paused )
139+
mTimer.stop();
140+
else
141+
mTimer.resume();
142+
}
143+
144+
if( ImGui::Button( "Frame Sphere 1" ) )
145+
mCam = mCam.calcFraming( Sphere( mSpherePositions[0], mSphereRadii[0] ) );
146+
ImGui::SameLine();
147+
if( ImGui::Button( "Sphere 2" ) )
148+
mCam = mCam.calcFraming( Sphere( mSpherePositions[1], mSphereRadii[1] ) );
149+
ImGui::SameLine();
150+
if( ImGui::Button( "Sphere 3" ) )
151+
mCam = mCam.calcFraming( Sphere( mSpherePositions[2], mSphereRadii[2] ) );
152+
}
153+
154+
void SphereProjectionApp::mouseDown( MouseEvent event )
155+
{
156+
mCamUi.mouseDown( event );
157+
}
158+
159+
void SphereProjectionApp::mouseDrag( MouseEvent event )
160+
{
161+
mCamUi.mouseDrag( event );
134162
}
135163

136164
CINDER_APP( SphereProjectionApp, RendererGl, SphereProjectionApp::prepareSettings )
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required( VERSION 3.10 FATAL_ERROR )
2+
set( CMAKE_VERBOSE_MAKEFILE ON )
3+
4+
project( ThresholdTest )
5+
6+
get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../" ABSOLUTE )
7+
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../.." ABSOLUTE )
8+
9+
include( "${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake" )
10+
11+
ci_make_app(
12+
APP_NAME "ThresholdTest"
13+
CINDER_PATH ${CINDER_PATH}
14+
SOURCES ${APP_PATH}/src/ThresholdTestApp.cpp
15+
)

test/ThresholdTest/src/ThresholdTestApp.cpp

Lines changed: 104 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "cinder/app/App.h"
22
#include "cinder/app/RendererGl.h"
33
#include "cinder/gl/gl.h"
4-
#include "cinder/params/Params.h"
54
#include "cinder/ip/Threshold.h"
65
#include "cinder/ip/Grayscale.h"
6+
#include "cinder/Log.h"
7+
#include "cinder/CinderImGui.h"
8+
9+
#include <algorithm>
710

811
using namespace std;
912
using namespace ci;
@@ -14,41 +17,35 @@ class ThresholdTestApp : public App {
1417
void setup() override;
1518
void update() override;
1619
void draw() override;
20+
void keyDown( KeyEvent event ) override;
1721

1822
private:
1923
void loadFile( const fs::path &path );
24+
void drawGui();
2025

2126
bool mUseAdaptiveThreshold = false;
2227
bool mUseAdaptivePercentage = false;
2328
bool mShowOriginalGrayScale = false;
2429
bool mUseClassVersion = true;
2530
int mThresholdValue, mAdaptiveThresholdKernel;
2631
float mAdaptiveThresholdPercentage;
27-
params::InterfaceGlRef mParams;
2832
gl::TextureRef mTexture;
2933
Surface8uRef mSurface;
3034
Channel8u mGraySurface, mThresholded;
35+
bool mShowGui = true;
36+
bool mRequestOpenDialog = false;
3137

3238
ip::AdaptiveThreshold mThresholdClass;
3339
};
3440

3541
void ThresholdTestApp::setup()
3642
{
37-
mParams = params::InterfaceGl::create( "Parameters", ivec2( 300, 240 ) );
38-
mParams->addParam( "Threshold", &mThresholdValue, "min=0 max=255 keyIncr=v keyDecr=V" );
39-
mParams->addButton( "open file", [this] { loadFile( getOpenFilePath() ); }, "key=o" );
40-
mParams->addSeparator();
41-
mParams->addParam( "Use Adapative", &mUseAdaptiveThreshold );
42-
mParams->addParam( "Use Adapative class", &mUseClassVersion );
43-
mParams->addParam( "Use Adapative percentage", &mUseAdaptivePercentage );
44-
mParams->addParam( "Show Grayscale", &mShowOriginalGrayScale );
45-
mParams->addParam( "Adaptive Kernel", &mAdaptiveThresholdKernel, "min=0 max=1000 keyIncr=k keyDecr=K" );
46-
mParams->addParam( "Adaptive Percentage", &mAdaptiveThresholdPercentage, "min=0 max=1.0 step=0.01 keyIncr=p keyDecr=P" );
47-
43+
ImGui::Initialize();
44+
4845
mThresholdValue = 128;
4946
mAdaptiveThresholdPercentage = 0.01f;
5047
mAdaptiveThresholdKernel = 64;
51-
48+
5249
loadFile( getOpenFilePath() );
5350
}
5451

@@ -89,14 +86,105 @@ void ThresholdTestApp::update()
8986
}
9087
}
9188

89+
void ThresholdTestApp::keyDown( KeyEvent event )
90+
{
91+
const int code = event.getCode();
92+
if( code == KeyEvent::KEY_ESCAPE ) {
93+
quit();
94+
return;
95+
}
96+
97+
if( ! event.isControlDown() )
98+
return;
99+
100+
switch( code ) {
101+
case KeyEvent::KEY_o:
102+
mRequestOpenDialog = true;
103+
break;
104+
case KeyEvent::KEY_a:
105+
mUseAdaptiveThreshold = ! mUseAdaptiveThreshold;
106+
CI_LOG_I( "Use adaptive threshold: " << std::boolalpha << mUseAdaptiveThreshold );
107+
break;
108+
case KeyEvent::KEY_c:
109+
mUseClassVersion = ! mUseClassVersion;
110+
CI_LOG_I( "Use adaptive class: " << std::boolalpha << mUseClassVersion );
111+
break;
112+
case KeyEvent::KEY_d:
113+
mUseAdaptivePercentage = ! mUseAdaptivePercentage;
114+
CI_LOG_I( "Use adaptive percentage: " << std::boolalpha << mUseAdaptivePercentage );
115+
break;
116+
case KeyEvent::KEY_g:
117+
mShowOriginalGrayScale = ! mShowOriginalGrayScale;
118+
CI_LOG_I( "Show grayscale: " << std::boolalpha << mShowOriginalGrayScale );
119+
break;
120+
case KeyEvent::KEY_h:
121+
case KeyEvent::KEY_QUESTION:
122+
mShowGui = ! mShowGui;
123+
break;
124+
case KeyEvent::KEY_v:
125+
if( event.isShiftDown() )
126+
mThresholdValue = std::max( mThresholdValue - 1, 0 );
127+
else
128+
mThresholdValue = std::min( mThresholdValue + 1, 255 );
129+
CI_LOG_I( "Threshold value: " << mThresholdValue );
130+
break;
131+
case KeyEvent::KEY_k:
132+
if( event.isShiftDown() )
133+
mAdaptiveThresholdKernel = std::max( mAdaptiveThresholdKernel - 1, 0 );
134+
else
135+
mAdaptiveThresholdKernel = std::min( mAdaptiveThresholdKernel + 1, 1000 );
136+
CI_LOG_I( "Adaptive kernel: " << mAdaptiveThresholdKernel );
137+
break;
138+
case KeyEvent::KEY_p:
139+
if( event.isShiftDown() )
140+
mAdaptiveThresholdPercentage = std::max( mAdaptiveThresholdPercentage - 0.01f, 0.0f );
141+
else
142+
mAdaptiveThresholdPercentage = std::min( mAdaptiveThresholdPercentage + 0.01f, 1.0f );
143+
CI_LOG_I( "Adaptive percentage: " << mAdaptiveThresholdPercentage );
144+
break;
145+
default:
146+
break;
147+
}
148+
}
149+
92150
void ThresholdTestApp::draw()
93151
{
94152
gl::clear( Color( 0.1f, 0.1f, 0.15f ) );
95153

96154
if( mTexture )
97155
gl::draw( mTexture );
98-
99-
mParams->draw();
156+
157+
if( mRequestOpenDialog ) {
158+
mRequestOpenDialog = false;
159+
loadFile( getOpenFilePath() );
160+
}
161+
162+
if( mShowGui )
163+
drawGui();
164+
}
165+
166+
void ThresholdTestApp::drawGui()
167+
{
168+
ImGui::ScopedWindow window( "Threshold Controls" );
169+
if( ImGui::Button( "Open Image..." ) )
170+
mRequestOpenDialog = true;
171+
172+
ImGui::SameLine();
173+
ImGui::Checkbox( "Show Grayscale", &mShowOriginalGrayScale );
174+
175+
ImGui::Separator();
176+
ImGui::Text( "Processing Mode" );
177+
ImGui::Checkbox( "Use Adaptive Threshold", &mUseAdaptiveThreshold );
178+
ImGui::Checkbox( "Use Adaptive Class", &mUseClassVersion );
179+
ImGui::Checkbox( "Use Adaptive Percentage", &mUseAdaptivePercentage );
180+
181+
ImGui::Separator();
182+
ImGui::SliderInt( "Threshold", &mThresholdValue, 0, 255 );
183+
ImGui::SliderInt( "Adaptive Kernel", &mAdaptiveThresholdKernel, 0, 1000 );
184+
ImGui::SliderFloat( "Adaptive Percent", &mAdaptiveThresholdPercentage, 0.0f, 1.0f, "%.2f" );
185+
186+
ImGui::Separator();
187+
ImGui::TextUnformatted( "Shortcuts: O=open, H=toggle GUI" );
100188
}
101189

102190
CINDER_APP( ThresholdTestApp, RendererGl )
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required( VERSION 3.10 FATAL_ERROR )
2+
set( CMAKE_VERBOSE_MAKEFILE ON )
3+
4+
project( CubeMapLayoutTest )
5+
6+
get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../" ABSOLUTE )
7+
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../.." ABSOLUTE )
8+
9+
include( "${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake" )
10+
11+
ci_make_app(
12+
APP_NAME "CubeMapLayoutTest"
13+
CINDER_PATH ${CINDER_PATH}
14+
SOURCES ${APP_PATH}/src/CubeMapLayoutApp.cpp
15+
INCLUDES ${APP_PATH}/include
16+
RESOURCES ${APP_PATH}/assets/horizontal_cross.jpg
17+
${APP_PATH}/assets/vertical_cross.png
18+
${APP_PATH}/assets/vertical_cross_layout.png
19+
${APP_PATH}/assets/horizontal.png
20+
${APP_PATH}/assets/vertical.hdr
21+
)

0 commit comments

Comments
 (0)