void FaceApp::setup() { gl::enableAlphaBlending(); mEnabledFace2d = true; mEnabledFace3d = true; mFrameRate = 0.0f; mFullScreen = false; mDevice = Kinect2::Device::create(); mDevice->start(); mDevice->enableFaceMesh(); mDevice->connectBodyEventHandler( [ & ]( const Kinect2::BodyFrame frame ) { } ); mDevice->connectColorEventHandler( [ & ]( const Kinect2::ColorFrame frame ) { mSurface = frame.getSurface(); } ); mParams = params::InterfaceGl::create( "Params", Vec2i( 230, 130 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addParam( "2d face tracking", &mEnabledFace2d ).key( "2" ); mParams->addParam( "3d face tracking", &mEnabledFace3d ).key( "3" ); mParams->addButton( "Quit", [ & ]() { quit(); } , "key=q" ); }
void BasicApp::setup() { gl::enable( GL_TEXTURE_2D ); mFrameRate = 0.0f; mFullScreen = false; mDevice = Kinect2::Device::create(); mDevice->start(); mDevice->connectBodyIndexEventHandler( [ & ]( const Kinect2::BodyIndexFrame& frame ) { mChannelBodyIndex = frame.getChannel(); } ); mDevice->connectColorEventHandler( [ & ]( const Kinect2::ColorFrame& frame ) { mSurfaceColor = frame.getSurface(); } ); mDevice->connectDepthEventHandler( [ & ]( const Kinect2::DepthFrame& frame ) { mChannelDepth = frame.getChannel(); } ); mDevice->connectInfraredEventHandler( [ & ]( const Kinect2::InfraredFrame& frame ) { mChannelInfrared = frame.getChannel(); } ); mParams = params::InterfaceGl::create( "Params", ivec2( 200, 100 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addButton( "Quit", [ & ]() { quit(); } , "key=q" ); }
void UdpServerApp::setup() { gl::enableAlphaBlending(); gl::enable( GL_TEXTURE_2D ); mFont = Font( "Georgia", 24 ); mFrameRate = 0.0f; mFullScreen = false; mPort = 2000; mPortPrev = mPort; mParams = params::InterfaceGl::create( "Params", ivec2( 200, 110 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen, "key=f" ); mParams->addParam( "Port", &mPort, "min=0 max=65535 step=1 keyDecr=p keyIncr=P" ); mParams->addButton( "Quit", bind( &UdpServerApp::quit, this ), "key=q" ); // Initialize a server by passing a boost::asio::io_service to it. // ci::App already has one that it polls on update, so we'll use that. // You can use your own io_service, but you will have to manage it // manually (i.e., call poll(), poll_one(), run(), etc). mServer = UdpServer::create( io_service() ); // Add callbacks to work with the server asynchronously. mServer->connectAcceptEventHandler( &UdpServerApp::onAccept, this ); mServer->connectErrorEventHandler( &UdpServerApp::onError, this ); // Start listening. accept(); }
void ServerApp::setup() { mFrameRate = 0.0f; mFullScreen = false; mMessage = "Hello, client!"; gl::enable( GL_TEXTURE_2D ); mFont = Font( "Georgia", 80 ); mSize = Vec2f( getWindowSize() ); mText = "Listening..."; mTextPrev = ""; mServer.addConnectCallback( &ServerApp::onConnect, this ); mServer.addDisconnectCallback( &ServerApp::onDisconnect, this ); mServer.addErrorCallback( &ServerApp::onError, this ); mServer.addInterruptCallback( &ServerApp::onInterrupt, this ); mServer.addPingCallback( &ServerApp::onPing, this ); mServer.addReadCallback( &ServerApp::onRead, this ); mParams = params::InterfaceGl::create( "SERVER", Vec2i( 200, 100 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Fullscreen", &mFullScreen, "key=f" ); mParams->addParam( "Message", &mMessage ); mParams->addButton( "Write", bind( &ServerApp::write, this ), "key=w" ); mParams->addButton( "Quit", bind( &ServerApp::quit, this ), "key=q" ); mServer.listen( 9002 ); }
void CameraComponent::loadGUI(const ci::params::InterfaceGlRef &gui) { gui->addSeparator(); gui->addText( mContext->getName() +" : "+ getName()); auto updateFn = std::bind(&CameraComponent::updateCameraParams, this); gui->addParam( mContext->getName() +" : FOV", &mFov).updateFn(updateFn); gui->addParam( mContext->getName() +" : Far", &mFar).updateFn(updateFn); gui->addParam( mContext->getName() +" : Near", &mNear).updateFn(updateFn); gui->addParam( mContext->getName() +" : Interest Point", &mInterestPoint); }
void BasicApp::draw() { gl::viewport( getWindowSize() ); gl::clear(); gl::setMatricesWindow( getWindowSize() ); gl::enableAlphaBlending(); if ( mSurfaceColor ) { gl::TextureRef tex = gl::Texture::create( *mSurfaceColor ); gl::draw( tex, tex->getBounds(), Rectf( vec2( 0.0f ), getWindowCenter() ) ); } if ( mChannelDepth ) { gl::TextureRef tex = gl::Texture::create( *Kinect2::channel16To8( mChannelDepth ) ); gl::draw( tex, tex->getBounds(), Rectf( getWindowCenter().x, 0.0f, (float)getWindowWidth(), getWindowCenter().y ) ); } if ( mChannelInfrared ) { gl::TextureRef tex = gl::Texture::create( *mChannelInfrared ); gl::draw( tex, tex->getBounds(), Rectf( 0.0f, getWindowCenter().y, getWindowCenter().x, (float)getWindowHeight() ) ); } if ( mChannelBodyIndex ) { gl::TextureRef tex = gl::Texture::create( *Kinect2::colorizeBodyIndex( mChannelBodyIndex ) ); gl::draw( tex, tex->getBounds(), Rectf( getWindowCenter(), vec2( getWindowSize() ) ) ); } mParams->draw(); }
void SegmentationApp::setup() { #ifdef _WIN32 showWin32Console(); #endif guiMode = GUI_MODE::LOAD_IMAGE; drawMode = DRAW_MODE::INPUT_GROUNDTRUTH; this->setWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); this->setWindowPos(20, 20); interface = params::InterfaceGl::create(this->getWindow(), "Segmentation", ci::app::toPixels(ci::Vec2i(WINDOW_WIDTH/6,GUI_HEIGHT))); interface->setPosition(ci::Vec2i(25,50)); firstImageRect = Rectf(WINDOW_WIDTH/6.f+50, 50, 3.5f*WINDOW_WIDTH/6.f, GUI_HEIGHT); secondImageRect = Rectf(3.5f*WINDOW_WIDTH/6.f+10, 50, 3.5f*WINDOW_WIDTH/6.f+10+firstImageRect.x2-firstImageRect.x1, GUI_HEIGHT); colorThreshold = 120; mahalonobisThreshold = 50; greenWeight = 1.2f; blueWeight = 2.9f; filterRadius = 2; hueThreshold = 0.075f; hueAngle = -0.046f; otsusIterations = 2; diceCoefficientResult = 0; mouse = new MouseUI(this->getWindow()); initInterface(); }
void FtpClientApp::setup() { gl::enable( GL_TEXTURE_2D ); mFont = Font( "Georgia", 24 ); mFrameRate = 0.0f; mFullScreen = false; mParams = params::InterfaceGl::create( "Params", ivec2( 200, 120 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen, "key=f" ); mParams->addButton( "Quit", [ & ]() { quit(); }, "key=q" ); mConnectionControl = TcpClientConnection::create( io_service() ); mConnectionControl->connect( "www.bantherewind.com", 21 ); }
void ClientApp::setup() { gl::enable( GL_TEXTURE_2D ); mFont = Font( "Georgia", 80 ); mSize = Vec2f( getWindowSize() ); mText = ""; mTextPrev = mText; mClient.addConnectCallback( &ClientApp::onConnect, this ); mClient.addDisconnectCallback( &ClientApp::onDisconnect, this ); mClient.addErrorCallback( &ClientApp::onError, this ); mClient.addInterruptCallback( &ClientApp::onInterrupt, this ); mClient.addPingCallback( &ClientApp::onPing, this ); mClient.addReadCallback( &ClientApp::onRead, this ); mFrameRate = 0.0f; mFullScreen = false; mMessage = "Hello, server!"; mPing = false; mPingTime = getElapsedSeconds(); mParams = params::InterfaceGl::create( "CLIENT", Vec2i( 200, 160 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Fullscreen", &mFullScreen, "key=f" ); mParams->addParam( "Ping enabled", &mPing, "key=p" ); mParams->addParam( "Message", &mMessage ); mParams->addButton( "Connect", bind( &ClientApp::connect, this ), "key=c" ); mParams->addButton( "Disconnect", bind( &ClientApp::disconnect, this ), "key=d" ); mParams->addButton( "Write", bind( &ClientApp::write, this ), "key=w" ); mParams->addButton( "Quit", bind( &ClientApp::quit, this ), "key=q" ); connect(); }
void MultiUdpClientApp::setup() { gl::enableAlphaBlending(); gl::enable( GL_TEXTURE_2D ); mFont = Font( "Georgia", 24 ); mFrameRate = 0.0f; mFullScreen = false; mHost = "127.0.0.1"; mPortLocal = 0; mPortRemote = 2000; mRequest = "Hello, server!"; mParams = params::InterfaceGl::create( "Params", ivec2( 200, 150 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen, "key=f" ); mParams->addParam( "Host", &mHost ); mParams->addParam( "Port", &mPortRemote, "min=0 max=65535 step=1 keyDecr=p keyIncr=P" ); mParams->addParam( "Request", &mRequest ); mParams->addButton( "Write", bind( &MultiUdpClientApp::write, this ), "key=w" ); mParams->addButton( "Quit", bind( &MultiUdpClientApp::quit, this ), "key=q" ); mClient = UdpClient::create( io_service() ); mServer = UdpServer::create( io_service() ); mClient->connectConnectEventHandler( &MultiUdpClientApp::onConnect, this ); mClient->connectErrorEventHandler( &MultiUdpClientApp::onError, this ); mClient->connectResolveEventHandler( &MultiUdpClientApp::onResolve, this ); mServer->connectAcceptEventHandler( &MultiUdpClientApp::onAccept, this ); mServer->connectErrorEventHandler( &MultiUdpClientApp::onError, this ); }
void ImageApp::setup() { gl::enable( GL_TEXTURE_2D ); mDevice = Device::create(); mDevice->connectEventHandler( [ & ]( Leap::Frame frame ) { mFrame = frame; } ); mFrameRate = 0.0f; mFullScreen = false; mParams = params::InterfaceGl::create( "Params", Vec2i( 200, 105 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addButton( "Screen shot", [ & ]() { screenShot(); }, "key=space" ); mParams->addButton( "Quit", [ & ]() { quit(); }, "key=q" ); }
void OSCComponent::loadGUI(const ci::params::InterfaceGlRef &gui) { gui->addSeparator(); gui->addText( mContext->getName() +" : "+ getName()); auto updateFn = [&]{ mListener.setup(mListenPort); }; gui->addParam("listen port", &mListenPort).updateFn(updateFn); ///TODO:: change osc sender gui update // auto loadFn = [&]{ // auto tree = ec::ConfigManager::get()->retreiveComponent(ec::Controller::get()->scene().lock()->getName(), mContext->getName(), getName() ); // auto ip = tree["send_ip"].getValue(); // auto port = tree["send_port"].getValue<int>(); // mSendPort = port; // mSendIp = ip; // mSender.setup(mSendIp, mSendPort); // }; // gui->addButton("reload osc sender", loadFn ); }
void WebClientApp::draw() { gl::clear( Colorf::black() ); gl::setMatricesWindow( getWindowSize() ); if ( mTexture ) { gl::draw( mTexture, ivec2( 250, 20 ) ); } mParams->draw(); }
void ImageFileBasicApp::draw() { gl::clear( Color( 0.5f, 0.5f, 0.5f ) ); gl::enableAlphaBlending(); if( mTexture ) { Rectf destRect = Rectf( mTexture->getBounds() ).getCenteredFit( getWindowBounds(), true ).scaledCentered( 0.85f ); gl::draw(mTexture, getWindowBounds()); } m_params->draw(); }
void LeapApp::setup() { gl::enable( GL_LINE_SMOOTH ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); gl::enable( GL_POLYGON_SMOOTH ); glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 1.0f, 1000.0f ); mCamera.lookAt( Vec3f( 0.0f, 250.0f, 500.0f ), Vec3f( 0.0f, 250.0f, 0.0f ) ); mDevice = Device::create(); mDevice->connectEventHandler( &LeapApp::onFrame, this ); mFrameRate = 0.0f; mFullScreen = false; mParams = params::InterfaceGl::create( "Params", Vec2i( 200, 105 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addButton( "Screen shot", bind( &LeapApp::screenShot, this ), "key=space" ); mParams->addButton( "Quit", bind( &LeapApp::quit, this ), "key=q" ); }
void TcpClientApp::draw() { gl::setViewport( getWindowBounds() ); gl::clear( Colorf::black() ); gl::setMatricesWindow( getWindowSize() ); if ( mTexture ) { gl::draw( mTexture, Vec2i( 250, 20 ) ); } mParams->draw(); }
void FaceApp::draw() { gl::setViewport( getWindowBounds() ); gl::clear(); gl::setMatricesWindow( getWindowSize() ); if ( mSurface ) { gl::color( Colorf::white() ); gl::enable( GL_TEXTURE_2D ); gl::TextureRef tex = gl::Texture::create( mSurface ); gl::draw( tex, tex->getBounds(), Rectf( getWindowBounds() ) ); gl::disable( GL_TEXTURE_2D ); gl::pushMatrices(); gl::scale( Vec2f( getWindowSize() ) / Vec2f( mSurface.getSize() ) ); for ( const Kinect2::Face3d& face : mFaces3d ) { const TriMesh& mesh = face.getMesh(); if ( mesh.getNumIndices() > 0 ) { vector<Vec2f> verts; for ( const Vec3f& i : mesh.getVertices() ) { Vec2f v = mDevice->mapCameraToColor( i ); verts.push_back( v ); } gl::lineWidth( 0.5f ); gl::enableWireframe(); TriMesh2d mesh2d; mesh2d.appendIndices( &mesh.getIndices()[ 0 ], mesh.getNumIndices() ); mesh2d.appendVertices( &verts[ 0 ], mesh.getNumVertices() ); gl::draw( mesh2d ); gl::disableWireframe(); } } if ( mEnabledFace3d ) { gl::color( Colorf( 1.0f, 0.0f, 0.0f ) ); } else { gl::lineWidth( 2.0f ); } for ( const Kinect2::Face2d& face : mFaces2d ) { if ( face.isTracked() ) { gl::drawStrokedRect( face.getBoundsColor() ); for ( const Vec2f& i : face.getPointsColor() ) { gl::drawSolidCircle( i, 3.0f, 16 ); } } } gl::popMatrices(); } mParams->draw(); }
void HttpClientApp::setup() { gl::enable( GL_TEXTURE_2D ); mBytesRead = 0; mContentLength = 0; mFont = Font( "Georgia", 24 ); mFrameRate = 0.0f; mFullScreen = false; mHost = "127.0.0.1"; mIndex = 0; mHttpRequest = HttpRequest( "GET", "/", HttpVersion::HTTP_1_1 ); mHttpRequest.setHeader( "Host", mHost ); mHttpRequest.setHeader( "Accept", "*/*" ); mParams = params::InterfaceGl::create( "Params", ivec2( 200, 150 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addParam( "Image index", &mIndex, "min=0 max=3 step=1 keyDecr=i keyIncr=I" ); mParams->addParam( "Host", &mHost ); mParams->addButton( "Write", [ & ]() { write(); }, "key=w" ); mParams->addButton( "Quit", [ & ]() { quit(); }, "key=q" ); mClient = TcpClient::create( io_service() ); mClient->connectConnectEventHandler( &HttpClientApp::onConnect, this ); mClient->connectErrorEventHandler( &HttpClientApp::onError, this ); mClient->connectResolveEventHandler( &HttpClientApp::onResolve, this ); }
void WebClientApp::setup() { gl::enable( GL_TEXTURE_2D ); mFont = Font( "Georgia", 24 ); mFrameRate = 0.0f; mFullScreen = false; mHost = "libcinder.org"; mPort = 80; mHttpRequest = HttpRequest( "GET", "/", HttpVersion::HTTP_1_0 ); mHttpRequest.setHeader( "Host", mHost ); mHttpRequest.setHeader( "Accept", "*/*" ); mHttpRequest.setHeader( "Connection", "close" ); mParams = params::InterfaceGl::create( "Params", ivec2( 200, 150 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addParam( "Host", &mHost ); mParams->addParam( "Port", &mPort, "min=0 max=65535 step=1 keyDecr=p keyIncr=P" ); mParams->addButton( "Write", bind( &WebClientApp::write, this ), "key=w" ); mParams->addButton( "Quit", bind( &WebClientApp::quit, this ), "key=q" ); mClient = TcpClient::create( io_service() ); mClient->connectConnectEventHandler( &WebClientApp::onConnect, this ); mClient->connectErrorEventHandler( &WebClientApp::onError, this ); mClient->connectResolveEventHandler( &WebClientApp::onResolve, this ); }
void ClientApp::draw() { gl::setViewport( getWindowBounds() ); gl::clear(); gl::setMatricesWindow( getWindowSize() ); if ( mTexture ) { gl::enableAlphaBlending(); gl::draw( mTexture, getWindowCenter() - mSize * 0.5f ); } mParams->draw(); }
void ImageApp::draw() { gl::setViewport( getWindowBounds() ); gl::clear( Colorf::white() ); gl::setMatricesWindow( getWindowSize() ); gl::color( ColorAf::white() ); size_t i = 0; const Leap::ImageList& images = mFrame.images(); for ( Leap::ImageList::const_iterator iter = images.begin(); iter != images.end(); ++iter, ++i ) { const Leap::Image& img = *iter; Channel8u channel = LeapMotion::toChannel8u( img ); gl::draw( gl::Texture::create( channel ), channel.getBounds(), getWindowBounds() ); } mParams->draw(); }
void ImageFileBasicApp::setup() { m_params = params::InterfaceGl::create("Params", ivec2(210, 210)); m_params->addParam<bool>("Full Screen", [&](bool b)->void { setFullScreen(b); }, [&]()->bool { return isFullScreen(); }).key("g"); // Fails m_params->addParam("full screen", &m_bFullscreen).updateFn([this] { setFullScreen(m_bFullscreen); CI_LOG_I("m_bFullscreen: " << m_bFullscreen); }).key("h"); try { fs::path path = getOpenFilePath( "", ImageIo::getLoadExtensions() ); if( ! path.empty() ) { mTexture = gl::Texture::create( loadImage( path ) ); } } catch( Exception &exc ) { CI_LOG_EXCEPTION( "failed to load image.", exc ); } }
void GestureApp::draw() { gl::viewport( getWindowSize() ); gl::clear( mBackgroundColor + Colorf::gray( mBackgroundBrightness ) ); gl::setMatricesWindow( getWindowSize() ); gl::enableAlphaBlending(); gl::color( Colorf::white() ); { const gl::ScopedMatrices scopedMatrices; gl::translate( mOffset ); drawUi(); drawGestures(); drawPointables(); } mParams->draw(); }
void TcpClientApp::setup() { gl::enableAlphaBlending(); gl::enable( GL_TEXTURE_2D ); mFont = Font( "Georgia", 24 ); mFrameRate = 0.0f; mFullScreen = false; mHost = "localhost"; mPort = 2000; mRequest = "echo"; mParams = params::InterfaceGl::create( "Params", Vec2i( 200, 150 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen, "key=f" ); mParams->addParam( "Host", &mHost ); mParams->addParam( "Port", &mPort, "min=0 max=65535 step=1 keyDecr=p keyIncr=P" ); mParams->addParam( "Request", &mRequest ); mParams->addButton( "Write", bind( &TcpClientApp::write, this ), "key=w" ); mParams->addButton( "Quit", bind( &TcpClientApp::quit, this ), "key=q" ); // Initialize a client by passing a boost::asio::io_service to it. // ci::App already has one that it polls on update, so we'll use that. // You can use your own io_service, but you will have to manage it // manually (i.e., call poll(), poll_one(), run(), etc). mClient = TcpClient::create( io_service() ); // Add callbacks to work with the client asynchronously. // Note that you can use lambdas. mClient->connectConnectEventHandler( &TcpClientApp::onConnect, this ); mClient->connectErrorEventHandler( &TcpClientApp::onError, this ); mClient->connectResolveEventHandler( [ & ]() { mText.push_back( "Endpoint resolved" ); } ); }
void SegmentationApp::draw() { // clear out the window with black gl::clear( Color( 0, 0, 0 ) ); gl::color(1, 1, 1); gl::drawStrokedRoundedRect(firstImageRect, 10); gl::drawStrokedRoundedRect(secondImageRect, 10); if(drawMode == DRAW_MODE::INPUT) { gl::Texture& inputTexture = inputImage.second; if(inputTexture) { gl::pushMatrices(); gl::translate(firstImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-inputTexture.getWidth()/2.f,-inputTexture.getHeight()/2.f); gl::draw(inputTexture); gl::popMatrices(); } } else if(drawMode == DRAW_MODE::INPUT_GROUNDTRUTH) { gl::Texture& inputTexture = inputImage.second; if(inputTexture) { gl::pushMatrices(); gl::translate(firstImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-inputTexture.getWidth()/2.f,-inputTexture.getHeight()/2.f); gl::draw(inputTexture); gl::popMatrices(); } gl::Texture& groundTruthTexture = groundTruthImage.second; if(groundTruthTexture) { gl::pushMatrices(); gl::translate(secondImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-groundTruthTexture.getWidth()/2.f,-groundTruthTexture.getHeight()/2.f); gl::draw(groundTruthTexture); gl::popMatrices(); } } else if (drawMode == DRAW_MODE::THRESHOLD_GROUNDTRUTH) { gl::Texture& segmentationTexture = segmentedImage.second; if(segmentationTexture) { gl::pushMatrices(); gl::translate(firstImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-segmentationTexture.getWidth()/2.f,-segmentationTexture.getHeight()/2.f); gl::draw(segmentationTexture); gl::popMatrices(); } gl::Texture& groundTruthTexture = groundTruthImage.second; if(groundTruthTexture) { gl::pushMatrices(); gl::translate(secondImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-groundTruthTexture.getWidth()/2.f,-groundTruthTexture.getHeight()/2.f); gl::draw(groundTruthTexture); gl::popMatrices(); } } else if (drawMode == DRAW_MODE::INPUT_THRESHOLD) { gl::Texture& inputTexture = inputImage.second; if(inputTexture) { gl::pushMatrices(); gl::translate(firstImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-inputTexture.getWidth()/2.f,-inputTexture.getHeight()/2.f); gl::draw(inputTexture); gl::popMatrices(); } gl::Texture& thresholdTexture = segmentedImage.second; if(thresholdTexture) { gl::pushMatrices(); gl::translate(secondImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-thresholdTexture.getWidth()/2.f,-thresholdTexture.getHeight()/2.f); gl::draw(thresholdTexture); gl::popMatrices(); } } else if (drawMode == DRAW_MODE::INPUT_RESULT) { gl::Texture& inputTexture = inputImage.second; if(inputTexture) { gl::pushMatrices(); gl::translate(firstImageRect.getCenter()); gl::scale(glScale,glScale); gl::translate(-inputTexture.getWidth()/2.f,-inputTexture.getHeight()/2.f); gl::draw(inputTexture); gl::popMatrices(); } gl::Texture& resultTexture = resultImage.second; if(resultTexture) { gl::pushMatrices(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); float glScale = (float)mouse->getGLScale(); gl::scale(glScale,glScale); gl::translate(ci::Vec2d(mouse->getGLTx(), mouse->getGLTy())); gl::draw(resultTexture); gl::popMatrices(); } } interface->draw(); }
void SegmentationApp::initInterface() { interface->clear(); if (guiMode == GUI_MODE::LOAD_IMAGE) { interface->addButton( "Open Image", std::bind( &SegmentationApp::openImage, this ) ); } else if (guiMode == GUI_MODE::LOAD_GROUNDTRUTH) { interface->addButton( "Open Ground Truth", std::bind( &SegmentationApp::openGroundTruth, this ) ); //interface->addButton( "Open Doctor Image", std::bind( &SegmentationApp::openDoctorImage, this ) ); interface->addSeparator(); interface->addParam("filter radius", &filterRadius).min(0).max(10).step(1); interface->addButton( "Mean Filter", std::bind( &SegmentationApp::meanFilter, this ) ); interface->addButton( "Median Filter", std::bind( &SegmentationApp::medianFilter, this ) ); interface->addButton( "Min Filter", std::bind( &SegmentationApp::minFilter, this ) ); interface->addButton( "Max Filter", std::bind( &SegmentationApp::maxFilter, this ) ); interface->addSeparator(); interface->addButton( "Get Hue", std::bind( &SegmentationApp::getHue, this ) ); interface->addSeparator(); interface->addParam("hue threshold", &hueThreshold).min(0).max(PI).step(.005).updateFn([this] () { thresholdHue(); });; interface->addParam("angle", &hueAngle).min(-PI).max(PI).step(.005).updateFn([this] () { thresholdHue(); });; interface->addButton( "threshold hue", std::bind( &SegmentationApp::thresholdHue, this ) ); interface->addSeparator(); interface->addParam("green weight", &greenWeight).min(0).max(5).step(.01).updateFn([this] () { experimentalColorDistance(); });; interface->addParam("blue weight", &blueWeight).min(0).max(5).step(.01).updateFn([this] () { experimentalColorDistance(); });; interface->addButton( "experimental threshold", std::bind( &SegmentationApp::experimentalColorDistance, this ) ); interface->addSeparator(); interface->addParam("otsus Iterations", &otsusIterations).min(1).max(5).step(1); interface->addButton( "otsus red", std::bind( &SegmentationApp::redOtsusThreshold, this ) ); interface->addButton( "otsus green", std::bind( &SegmentationApp::greenOtsusThreshold, this ) ); interface->addButton( "otsus blue", std::bind( &SegmentationApp::blueOtsusThreshold, this ) ); interface->addButton( "otsus gray", std::bind( &SegmentationApp::grayOtsusThreshold, this ) ); interface->addButton( "otsus best", std::bind( &SegmentationApp::multiImageOtsusThreshold, this ) ); //interface->addButton( "otsus binary mask", std::bind( &SegmentationApp::otsusBinaryMask, this ) ); //interface->addButton( "otsus color union", std::bind( &SegmentationApp::otsusColorUnion, this ) ); interface->addSeparator(); interface->addButton( "erode", std::bind( &SegmentationApp::erode, this ) ); interface->addButton( "dilate", std::bind( &SegmentationApp::dilate, this ) ); interface->addSeparator(); interface->addButton( "get largest component", std::bind( &SegmentationApp::getLargestComponents, this ) ); interface->addButton( "fill holes", std::bind( &SegmentationApp::fillHoles, this ) ); interface->addSeparator(); interface->addButton( "show result", std::bind( &SegmentationApp::showResult, this ) ); //interface->addButton( "otsus edge intersection", std::bind( &SegmentationApp::otsusEdgeIntersection, this ) ); //interface->addSeparator(); //interface->addButton( "color gradient", std::bind( &SegmentationApp::getColorGradient, this ) ); //interface->addButton( "thin edges", std::bind( &SegmentationApp::edgeThinColorGradient, this ) ); interface->addSeparator(); interface->addButton( "autoSegment", std::bind( &SegmentationApp::autoSegment, this ) ); interface->addText( "Dice Coeddicient : " + std::to_string(diceCoefficientResult) ); interface->addSeparator(); interface->addButton( "Reset", std::bind( &SegmentationApp::reset, this ) ); interface->addSeparator(); interface->addButton( "Save Input", std::bind( &SegmentationApp::saveInputImage, this ) ); interface->addButton( "Save Segmentation", std::bind( &SegmentationApp::saveSegmentedImage, this ) ); interface->addButton( "Save Result", std::bind( &SegmentationApp::saveResultImage, this ) ); } else if (guiMode == GUI_MODE::DO_TRAINING) { interface->addParam("filter radius", &filterRadius).min(0).max(10).step(1); interface->addButton( "Mean Filter", std::bind( &SegmentationApp::meanFilter, this ) ); interface->addButton( "Median Filter", std::bind( &SegmentationApp::medianFilter, this ) ); interface->addButton( "Min Filter", std::bind( &SegmentationApp::minFilter, this ) ); interface->addButton( "Max Filter", std::bind( &SegmentationApp::maxFilter, this ) ); interface->addSeparator(); interface->addButton( "Open Doctor Image", std::bind( &SegmentationApp::openDoctorImage, this ) ); interface->addSeparator(); interface->addButton( "Train", std::bind( &SegmentationApp::trainImage, this ) ); } else if (guiMode == GUI_MODE::DO_DOCTOR_TRAINING) { interface->addParam("filter radius", &filterRadius).min(0).max(10).step(1); interface->addButton( "Mean Filter", std::bind( &SegmentationApp::meanFilter, this ) ); interface->addButton( "Median Filter", std::bind( &SegmentationApp::medianFilter, this ) ); interface->addSeparator(); interface->addButton( "Doctor Training", std::bind( &SegmentationApp::trainDoctorImage, this ) ); } else if (guiMode == GUI_MODE::THRESHOLD) { interface->addButton( "Show Mean Distance", std::bind( &SegmentationApp::getColorDistance, this ) ); interface->addButton( "Threshold Color", std::bind( &SegmentationApp::thresholdColor, this ) ); interface->addParam("color distance", &colorThreshold).min(0.f).max(255.f).step(1).updateFn([this] () { thresholdColor(); }); interface->addSeparator(); interface->addButton( "Threshold Mahalonobis", std::bind( &SegmentationApp::thresholdMahalonobis, this ) ); interface->addParam("mahalonobis distance", &mahalonobisThreshold).min(0.f).max(255.f).step(1); } interface->addSeparator(); }
void ComponentTemplate::loadGUI(const ci::params::InterfaceGlRef &gui) { gui->addSeparator(); gui->addText(getName()); }
void GpGpuApp::draw() { // We're going to draw new data onto the "ping" FBO, // using the "pong" FBO's textures as input size_t pong = ( mFboIndex + 1 ) % 2; // Set up OpenGL for data gl::disableDepthRead(); gl::disableDepthWrite(); gl::setViewport( mFbo[ mFboIndex ].getBounds() ); gl::color( ColorAf::white() ); // Draw any new input onto the acceleration texture mFbo[ pong ].bindFramebuffer(); glDrawBuffer( GL_COLOR_ATTACHMENT2 ); if ( mMouseDown ) { Vec2f fboSize = Vec2f( mFbo[ mFboIndex ].getSize() ); Vec2f winSize = Vec2f( app::getWindowSize() ); gl::setMatricesWindow( fboSize, true ); Vec2f brushSize = Vec2f::one() * mBrushSize * fboSize; Vec2f pos = ( mMouse / winSize ); pos.y = 1.0f - pos.y; pos *= fboSize; mGlslProgGpGpu0->bind(); mGlslProgGpGpu0->uniform( "color", ColorAf( mMouseVelocity.x, 0.0f, 1.0f - mMouseVelocity.y, 1.0f ) ); mGlslProgGpGpu0->uniform( "tex", 0 ); gl::enable( GL_TEXTURE_2D ); mTextureBrush->bind(); gl::drawSolidRect( Rectf( pos - brushSize, pos + brushSize ) ); mTextureBrush->unbind(); gl::disable( GL_TEXTURE_2D ); mGlslProgGpGpu0->unbind(); } mFbo[ pong ].unbindFramebuffer(); // Now let's do an update pass in GLSL mFbo[ mFboIndex ].bindFramebuffer(); gl::setMatricesWindow( mFbo[ mFboIndex ].getSize(), false ); // Bind the "pong" textures to use as input data for ( int32_t i = 0; i < 3; ++i ) { mFbo[ pong ].bindTexture( i, i ); } // Set up shader to read data textures mGlslProgGpGpu1->bind(); mGlslProgGpGpu1->uniform( "offsets", 0 ); mGlslProgGpGpu1->uniform( "velocities", 1 ); mGlslProgGpGpu1->uniform( "acceleration", 2 ); // Draw a rect to process data glDrawBuffers( 3, kColorAttachments ); gl::drawSolidRect( mFbo[ pong ].getBounds() ); // Unbind everything mFbo[ pong ].unbindTexture(); mGlslProgGpGpu1->unbind(); mFbo[ mFboIndex ].unbindFramebuffer(); // Swap FBOs mFboIndex = pong; ///////////////////////////////// // Make sure we have data to work with before we draw geometry if ( mFbo[ mFboIndex ] && mFbo[ mFboIndex ].getTexture( 0 ) && mFbo[ mFboIndex ].getTexture( 1 ) ) { // Set up window for 3D drawing gl::clear( Colorf( 0.5f, 0.45f, 0.4f ) ); gl::setViewport( getWindowBounds() ); gl::setMatrices( mCamera ); gl::enableDepthRead(); gl::enableDepthWrite(); gl::multModelView( mArcball.getQuat() ); gl::color( ColorAf::black() ); // Set up shader to render scene mGlslProgDraw->bind(); mGlslProgDraw->uniform( "Ax", mLightAmbient ); mGlslProgDraw->uniform( "Ac", mLightAttenuationConstant ); mGlslProgDraw->uniform( "Al", mLightAttenuationLinear ); mGlslProgDraw->uniform( "Aq", mLightAttenuationQuadratic ); mGlslProgDraw->uniform( "Dx", mLightDiffuse ); mGlslProgDraw->uniform( "eyePoint", mEyePoint ); mGlslProgDraw->uniform( "Ka", mMaterialAmbient ); mGlslProgDraw->uniform( "Kd", mMaterialDiffuse ); mGlslProgDraw->uniform( "Ke", mMaterialEmissive ); mGlslProgDraw->uniform( "Ks", mMaterialSpecular ); mGlslProgDraw->uniform( "lightPos", mLightPosition ); mGlslProgDraw->uniform( "n", mLightShine ); mGlslProgDraw->uniform( "offsets", 0 ); mGlslProgDraw->uniform( "projection", mCamera.getProjectionMatrix() ); mGlslProgDraw->uniform( "size", Vec2f( mSize ) ); mGlslProgDraw->uniform( "Sx", mLightSpecular ); mGlslProgDraw->uniform( "t", (float)getElapsedSeconds() ); // Bind textures to use as input data for ( int32_t i = 0; i <= 2; ++i ) { mFbo[ mFboIndex ].bindTexture( i, i ); } // Draw instanced drawInstanced( mMesh, mSize.x * mSize.y ); // Finished drawing mFbo[ mFboIndex ].unbindTexture(); mGlslProgDraw->unbind(); // Draw textures so we can see what's going on under the hood gl::setMatricesWindow( getWindowSize() ); gl::disableDepthRead(); gl::disableDepthWrite(); gl::color( ColorAf::white() ); gl::pushMatrices(); float x = 20.0f; float y = 440.0f; float width = 64.0f; Area srcArea( Vec2i::zero(), mSize ); Rectf destRect( x, y, x + width, y + width ); gl::draw( mFbo[ 0 ].getTexture( 0 ), srcArea, destRect ); destRect.x1 += width; destRect.x2 += width; gl::draw( mFbo[ 1 ].getTexture( 0 ), srcArea, destRect ); destRect.y1 += width; destRect.y2 += width; destRect.x1 = x; destRect.x2 = x + width; gl::draw( mFbo[ 0 ].getTexture( 1 ), srcArea, destRect ); destRect.x1 += width; destRect.x2 += width; gl::draw( mFbo[ 1 ].getTexture( 1 ), srcArea, destRect ); destRect.y1 += width; destRect.y2 += width; destRect.x1 = x; destRect.x2 = x + width; gl::draw( mFbo[ 0 ].getTexture( 2 ), srcArea, destRect ); destRect.x1 += width; destRect.x2 += width; gl::draw( mFbo[ 1 ].getTexture( 2 ), srcArea, destRect ); gl::popMatrices(); } // Draw parameters if ( getElapsedFrames() > 1 ) { // This condition prevents a memory leak mParams->draw(); } }
void GpGpuApp::setup() { // Load shaders try { mGlslProgDraw = gl::GlslProg::create( loadResource( RES_GLSL_DRAW_VERT ), loadResource( RES_GLSL_DRAW_FRAG ) ); } catch ( gl::GlslProgCompileExc ex ) { console() << ex.what() << "\n"; quit(); } try { mGlslProgGpGpu0 = gl::GlslProg::create( loadResource( RES_GLSL_GPGPU_VERT ), loadResource( RES_GLSL_GPGPU0_FRAG ) ); } catch ( gl::GlslProgCompileExc ex ) { console() << ex.what() << "\n"; quit(); } try { mGlslProgGpGpu1 = gl::GlslProg::create( loadResource( RES_GLSL_GPGPU_VERT ), loadResource( RES_GLSL_GPGPU1_FRAG ) ); } catch ( gl::GlslProgCompileExc ex ) { console() << ex.what() << "\n"; quit(); } // Define all properties mArcball = Arcball( getWindowSize() ); mBrushSize = 0.1f; mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 1.0f, 100000.0f ); mEyePoint = Vec3f( 0.0f, 20.0f, 256.0f ); mFullScreen = isFullScreen(); mFullScreenPrev = mFullScreen; mLightAmbient = ColorAf::gray( 0.1f ); mLightAttenuationConstant = 0.1f; mLightAttenuationLinear = 0.01f; mLightAttenuationQuadratic = 0.001f; mLightDiffuse = ColorAf( 0.9f, 0.3f, 0.667f ); mLightPosition = Vec3f( 11.38f, -1.39f, 59.74f ); mLightSpecular = ColorAf::white(); mLightShine = 1.0f; mMaterialAmbient = 1.0f; mMaterialDiffuse = 1.0f; mMaterialEmissive = 0.0f; mMaterialSpecular = 1.0f; mMesh = gl::VboMesh::create( MeshHelper::createCube() ); mMouseDown = false; mMouse = Vec2f::zero(); mMouseVelocity = Vec2f::zero(); mParams = params::InterfaceGl::create( "Params", Vec2i( 250, 400 ) ); mSize = Vec2i( 512, 512 ); mSizePrev = Vec2i::zero(); mTextureBrush = gl::Texture::create( loadImage( loadResource( RES_PNG_BRUSH ) ) ); // Set up arcball mArcball.setRadius( (float)getWindowHeight() * 0.5f ); // Set up parameters mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen, "key=f" ); mParams->addButton( "Quit", bind( &GpGpuApp::quit, this ), "key=q" ); mParams->addSeparator( "" ); mParams->addParam( "Brush size", &mBrushSize, "min=0.0 max=1.0 step=0.001" ); mParams->addParam( "Size X", &mSize.x, "min=1 max=1024 step=1" ); mParams->addParam( "Size Y", &mSize.y, "min=1 max=1024 step=1" ); mParams->addSeparator( "" ); mParams->addParam( "Light ambient", &mLightAmbient ); mParams->addParam( "Light att const", &mLightAttenuationConstant, "min=0.0 max=1.0 step=0.001" ); mParams->addParam( "Light att line", &mLightAttenuationLinear, "min=0.0 max=1.0 step=0.0001" ); mParams->addParam( "Light att quad", &mLightAttenuationQuadratic, "min=0.0 max=1.0 step=0.00001" ); mParams->addParam( "Light diffuse", &mLightDiffuse ); mParams->addParam( "Light position", &mLightPosition ); mParams->addParam( "Light specular", &mLightSpecular ); mParams->addParam( "Light shine", &mLightShine, "min=0.0 max=100000.0 step=1.0" ); mParams->addSeparator( "" ); mParams->addParam( "Material ambient", &mMaterialAmbient, "min=0.0 max=1.0 step=0.001" ); mParams->addParam( "Material diffuse", &mMaterialDiffuse, "min=0.0 max=1.0 step=0.001" ); mParams->addParam( "Material emissive", &mMaterialEmissive, "min=0.0 max=1.0 step=0.001" ); mParams->addParam( "Material specular", &mMaterialSpecular, "min=0.0 max=1.0 step=0.001" ); }
void SpherePrimitive::AddParams(ci::params::InterfaceGlRef _params) { Primitive::AddParams(_params); _params->addParam(GetName() + "::Center", &mCenter, "group=" + GetName() + " label='Center'"); _params->addParam(GetName() + "::Radius", &mRadius, "group=" + GetName() + " label='Radius'"); }