void PlotRna(char* seqName, char* sequence, short* structure, char* filename, float score) { /*A:red, U: Green, G:Blue, C:Yellow*/ int i, j; int length; int sizex, sizey; fname = filename; length = (int)strlen(sequence) ; sizex = length; sizey = length; /*printf("here......length %d\n",length);*/ drawInit(length, length, seqName, filename, score); /* print out stems */ int st, stp; char* c = (char*)malloc(sizeof(char)*1000); i = 0; j = 0; while(i < length) { while(i < length && (structure[i] == 0 || structure[i] < i)) i++; st = i; while(i < length && (structure[i]-1 == structure[i+1])) i++; stp = i; if (i >= length) break; sprintf(c, "%d-%d; %d-%d ",st+1, stp+1, structure[stp],structure[st]); i++; j++; if ((j%2) == 1) drawtext (sizex*CELLSIZE/4,sizey*CELLSIZE/10.0+((int)(j/2)+1)*CELLSIZE*sizey/30,c,1.0e6); else drawtext (sizex*CELLSIZE/2,sizey*CELLSIZE/10.0+((int)(j/2))*CELLSIZE*sizey/30,c,1.0e6); flushinput(); } for(i=0; i<length; i++) { if(sequence[i] == 'A' || sequence[i] == 'a') setcolor(RED); else if(sequence[i] == 'U'|| sequence[i] == 'u' || sequence[i] == 'T' || sequence[i] == 't') setcolor(GREEN); else if(sequence[i] == 'G' || sequence[i] == 'g') setcolor(BLUE); else if(sequence[i] == 'C' || sequence[i] == 'c') setcolor(YELLOW); else setcolor(BLACK); fillrect((i+0.2)*CELLSIZE, (sizey/2 - 0.8)*CELLSIZE, (i+0.8)*CELLSIZE, (sizey/2 - 0.2)*CELLSIZE); flushinput(); } plotBP(sequence, structure); close_postscript(); close_graphics(); }
void DrawTexObj(GXTexObj *texObj, int x, int y, int width, int height, int depth, float s1, float s2, float t1, float t2, int centered) { drawInit(); GX_SetTevOp (GX_TEVSTAGE0, GX_REPLACE); GX_InvalidateTexAll(); GX_LoadTexObj(texObj, GX_TEXMAP0); if(centered) x = (int) x - width/2; GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position3f32((float) x,(float) y,(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s1,t1); GX_Position3f32((float) (x+width),(float) y,(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s2,t1); GX_Position3f32((float) (x+width),(float) (y+height),(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s2,t2); GX_Position3f32((float) x,(float) (y+height),(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s1,t2); GX_End(); }
void DrawSimpleBox(int x, int y, int width, int height, int depth, GXColor fillColor, GXColor borderColor) { //Adjust for blank texture border x-=4; y-=4; width+=8; height+=8; drawInit(); GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE); GX_InvalidateTexAll(); GX_LoadTexObj(&boxinnerTexObj, GX_TEXMAP0); drawRect(x, y, width/2, height/2, depth, fillColor, 0.0f, ((float)width/32), 0.0f, ((float)height/32)); drawRect(x+(width/2), y, width/2, height/2, depth, fillColor, ((float)width/32), 0.0f, 0.0f, ((float)height/32)); drawRect(x, y+(height/2), width/2, height/2, depth, fillColor, 0.0f, ((float)width/32), ((float)height/32), 0.0f); drawRect(x+(width/2), y+(height/2), width/2, height/2, depth, fillColor, ((float)width/32), 0.0f, ((float)height/32), 0.0f); GX_InvalidateTexAll(); GX_LoadTexObj(&boxouterTexObj, GX_TEXMAP0); drawRect(x, y, width/2, height/2, depth, borderColor, 0.0f, ((float)width/32), 0.0f, ((float)height/32)); drawRect(x+(width/2), y, width/2, height/2, depth, borderColor, ((float)width/32), 0.0f, 0.0f, ((float)height/32)); drawRect(x, y+(height/2), width/2, height/2, depth, borderColor, 0.0f, ((float)width/32), ((float)height/32), 0.0f); drawRect(x+(width/2), y+(height/2), width/2, height/2, depth, borderColor, ((float)width/32), 0.0f, ((float)height/32), 0.0f); }
void DrawImage(int textureId, int x, int y, int width, int height, int depth, float s1, float s2, float t1, float t2, int centered) { drawInit(); GX_SetTevOp (GX_TEVSTAGE0, GX_REPLACE); GX_InvalidateTexAll(); switch(textureId) { case TEX_BACKDROP: GX_LoadTexObj(&backdropTexObj, GX_TEXMAP0); break; case TEX_GCDVDSMALL: GX_LoadTexObj(&gcdvdsmallTexObj, GX_TEXMAP0); break; case TEX_SDSMALL: GX_LoadTexObj(&sdsmallTexObj, GX_TEXMAP0); break; case TEX_HDD: GX_LoadTexObj(&hddTexObj, GX_TEXMAP0); break; case TEX_QOOB: GX_LoadTexObj(&qoobTexObj, GX_TEXMAP0); break; case TEX_WODEIMG: GX_LoadTexObj(&wodeimgTexObj, GX_TEXMAP0); break; case TEX_USBGECKO: GX_LoadTexObj(&usbgeckoTexObj, GX_TEXMAP0); break; case TEX_WIIKEY: GX_LoadTexObj(&wiikeyTexObj, GX_TEXMAP0); break; case TEX_SYSTEM: GX_LoadTexObj(&systemTexObj, GX_TEXMAP0); break; case TEX_MEMCARD: GX_LoadTexObj(&memcardTexObj, GX_TEXMAP0); break; case TEX_SAMBA: GX_LoadTexObj(&sambaTexObj, GX_TEXMAP0); break; case TEX_BTNNOHILIGHT: GX_LoadTexObj(&btnnohilightTexObj, GX_TEXMAP0); break; case TEX_BTNHILIGHT: GX_LoadTexObj(&btnhilightTexObj, GX_TEXMAP0); break; case TEX_BTNDEVICE: GX_LoadTexObj(&btndeviceTexObj, GX_TEXMAP0); break; case TEX_BTNSETTINGS: GX_LoadTexObj(&btnsettingsTexObj, GX_TEXMAP0); break; case TEX_BTNINFO: GX_LoadTexObj(&btninfoTexObj, GX_TEXMAP0); break; case TEX_BTNREFRESH: GX_LoadTexObj(&btnrefreshTexObj, GX_TEXMAP0); break; case TEX_BTNEXIT: GX_LoadTexObj(&btnexitTexObj, GX_TEXMAP0); break; case TEX_NTSCJ: GX_LoadTexObj(&ntscjTexObj, GX_TEXMAP0); break; case TEX_NTSCU: GX_LoadTexObj(&ntscuTexObj, GX_TEXMAP0); break; case TEX_PAL: GX_LoadTexObj(&palTexObj, GX_TEXMAP0); break; case TEX_CHECKED: GX_LoadTexObj(&checkedTexObj, GX_TEXMAP0); break; case TEX_UNCHECKED: GX_LoadTexObj(&uncheckedTexObj, GX_TEXMAP0); break; } if(centered) { x = (int) x - width/2; } GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position3f32((float) x,(float) y,(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s1,t1); GX_Position3f32((float) (x+width),(float) y,(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s2,t1); GX_Position3f32((float) (x+width),(float) (y+height),(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s2,t2); GX_Position3f32((float) x,(float) (y+height),(float) depth ); GX_Color4u8(255, 255, 255, 255); GX_TexCoord2f32(s1,t2); GX_End(); }
void DepthPeelBin::drawImplementation( osg::RenderInfo& renderInfo, osgUtil::RenderLeaf*& previous ) { TRACEDUMP("DepthPeelBin::drawImplementation"); UTIL_GL_ERROR_CHECK("DepthPeelBin::drawImplementation start"); unsigned int debugMode = Manager::instance()->getDebugMode(); osg::State& state = *renderInfo.getState(); const unsigned int contextID = state.getContextID(); osg::FBOExtensions* fboExt( osg::FBOExtensions::instance( contextID, true ) ); UTIL_GL_FBO_ERROR_CHECK("DepthPeelBin::drawImplementation start",fboExt); osg::GL2Extensions* ext = osg::GL2Extensions::Get( contextID, true ); UTIL_MEMORY_CHECK( ext, "DepthPeelBin: NULL GL2Extensions", ); // Get the last applied viewport. When we render to our internal textures, // we will render to the lower left corner in an area the size of the viewport. // We track the width and height and maintain internal textures large enough // to render the largest width and height we've seen. const osg::Viewport* vp = dynamic_cast< const osg::Viewport* >( state.getLastAppliedAttribute( osg::StateAttribute::VIEWPORT ) ); const GLsizei width( vp->width() ), height( vp->height() ); char* pixels( NULL ); const bool dumpImages = ( ( debugMode & backdropFX::BackdropCommon::debugImages ) != 0 ); if( dumpImages ) { pixels = new char[ width * height * 4 ]; UTIL_MEMORY_CHECK( pixels, "DepthPeelBin: debug image pixel buffer", ) } // Fix for redmine issue 8, and the recurrance of this issue // in the new depth peel work. // The most general way to handle the single StateGraph case // is to save the last StateGraph and re-apply it just before // we return from ::draw(). osgUtil::StateGraph* savedStateGraph( NULL ); if( _stateGraphList.size() ) savedStateGraph = _stateGraphList.back(); PerContextInfo& pci = s_contextInfo[ contextID ]; unsigned int insertStateSetPosition; { // Get the current Draw FBO and restore it when fboSRH goes out of scope. // Get this now, first, before we call pci._init. Also, having it hear means // we query OpenGL once. If, instead, we instantiated one of these for every // layer, we would query OpenGL every layer. Having just one instance, with // its constructor invoked once, is a better solution. FBOSaveRestoreHelper fboSRH( fboExt, pci ); insertStateSetPosition = drawInit( state, previous ); if( pci._init && ( ( pci._width < width ) || ( pci._height < height ) ) ) { // We've already created textures at a given size, but we // now have a larger viewport. Delete those textures and // force a re-initialization. // NOTE We never resize the textures smaller, only larger. osg::notify( osg::INFO ) << "BDFX: DepthPeelBin cleanup. "; pci.cleanup( state ); } if( !pci._init ) { osg::notify( osg::INFO ) << "BDFX: DepthPeelBin resize to width: " << width << " height: " << height << std::endl; pci.init( state, width, height ); } // Compute the percentage of the texture we will render to. // This is the viewport width and height divided by the texture // width and height. It's used to ensure we display the appropriate // portion of the texture during drawFSTP(). osg::Vec2f texturePercent( vp->width() / (float)( pci._width ), vp->height() / (float)( pci._height ) ); _texturePercentUniform->set( texturePercent ); // Uniform locations, used during drawFSTP(). We declare them here and pass // them by reference. drawFSTP() inits them after binding the fstpProgram. // Then we reuse the values until next frame. Avoids looking up the uniform // location (via map keyed by string) for every layer. GLint fstpLoc( -1 ), texturePercentLoc( -1 ); // Opaque pass. bool transparentRemaining( false ); // After opaque pass, are there transparent bins? int drawCount( 0 ); { osgwTools::glBindFramebuffer( fboExt, GL_FRAMEBUFFER_EXT, pci._fbo ); state.applyAttribute( _opaqueDepth.get() ); state.applyMode( GL_DEPTH_TEST, true ); glClearDepth( 1.0 ); unsigned int idx; for( idx=0; idx<2; idx++ ) { osgwTools::glFramebufferTexture2D( fboExt, GL_DRAW_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, pci._depthTex[ idx ], 0 ); glClear( GL_DEPTH_BUFFER_BIT ); } osgwTools::glFramebufferTexture2D( fboExt, GL_DRAW_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, pci._depthTex[ 2 ], 0 ); state.setActiveTextureUnit( s_textureUnit ); glBindTexture( GL_TEXTURE_2D, pci._depthTex[ 0 ] ); state.setActiveTextureUnit( s_textureUnit+1 ); glBindTexture( GL_TEXTURE_2D, pci._depthTex[ 1 ] ); glClearColor( 0., 0., 0., 0. ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); drawCount = drawOpaque( renderInfo, previous, transparentRemaining ); // Blend the opaque pass into the output buffer. // We could probably do this a different way, by attaching // the output color buffer to our FBO and rendering directly // into it. This is TBD as a later enhancement. fboSRH.restore(); drawFSTP( renderInfo, state, ext, pci, fstpLoc, texturePercentLoc ); if( dumpImages ) { FBOSaveRestoreHelper fboSRHRead( fboExt, pci, GL_READ_FRAMEBUFFER_EXT ); osgwTools::glBindFramebuffer( fboExt, GL_READ_FRAMEBUFFER_EXT, pci._fbo ); std::string fileName = createFileName( state ); glReadBuffer( GL_COLOR_ATTACHMENT0_EXT ); glReadPixels( (GLint)( 0 ), (GLint)( 0 ), width, height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)pixels ); backdropFX::debugDumpImage( fileName, pixels, width, height ); osg::notify( osg::NOTICE ) << " - " << fileName << std::endl; fileName = createFileName( state, -1, true ); glReadPixels( (GLint)( 0 ), (GLint)( 0 ), width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, (GLvoid*)pixels ); backdropFX::debugDumpDepthImage( fileName, (const short*)pixels, width, height ); osg::notify( osg::NOTICE ) << " - " << fileName << std::endl; } } // drawOpaque() sets this to true if there are transparent bins to render. if( transparentRemaining ) { // Transparent passes state.setActiveTextureUnit( s_textureUnit ); glBindTexture( GL_TEXTURE_2D, pci._depthTex[ 2 ] ); // If we already drew something in the opaque pass, then GL_LESS has already been // set. But if we didn't draw anything in the opaque pass (drawCount==0) then the // scene graph will almost certainly set depth function to GL_LESS using lazy state // setting. In that case, we must apply state _now_ so that the transparent pass can // correctly set the depth function to GL_GREATER. if( drawCount == 0 ) state.apply(); // Create depth peel layers until we hit _maxPasses, or until // occlusion query indicates we didn't render anything. unsigned int passCount; for( passCount = 0; passCount < _maxPasses; passCount++ ) { // Specify the depth buffer to render to. osgwTools::glBindFramebuffer( fboExt, GL_FRAMEBUFFER_EXT, pci._fbo ); osgwTools::glFramebufferTexture2D( fboExt, GL_DRAW_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, pci._depthTex[ passCount & 0x1 ], 0 ); osg::notify( osg::DEBUG_FP ) << " Attaching depth buffer " << pci._depthTex[ passCount & 0x1 ] << std::endl; // Use the other depth buffer as an input texture. state.setActiveTextureUnit( s_textureUnit+1 ); glBindTexture( GL_TEXTURE_2D, pci._depthTex[ (passCount+1) & 0x1 ] ); osg::notify( osg::DEBUG_FP ) << " Binding depth map " << pci._depthTex[ (passCount+1) & 0x1 ] << std::endl; _transparentDepth->apply( state ); glEnable( GL_DEPTH_TEST ); glClearDepth( 0.0 ); glClearColor( 0., 0., 0., 0. ); glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); pci._glBeginQuery( GL_SAMPLES_PASSED_ARB, pci._queryID ); drawTransparent( renderInfo, previous ); pci._glEndQuery( GL_SAMPLES_PASSED_ARB ); if( dumpImages ) { FBOSaveRestoreHelper fboSRHRead( fboExt, pci, GL_READ_FRAMEBUFFER_EXT ); osgwTools::glBindFramebuffer( fboExt, GL_READ_FRAMEBUFFER_EXT, pci._fbo ); std::string fileName = createFileName( state, passCount ); glReadBuffer( GL_COLOR_ATTACHMENT0_EXT ); glReadPixels( (GLint)( 0 ), (GLint)( 0 ), width, height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)pixels ); backdropFX::debugDumpImage( fileName, pixels, width, height ); osg::notify( osg::NOTICE ) << " - " << fileName << std::endl; fileName = createFileName( state, passCount, true ); glReadPixels( (GLint)( 0 ), (GLint)( 0 ), width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, (GLvoid*)pixels ); backdropFX::debugDumpDepthImage( fileName, (const short*)pixels, width, height ); osg::notify( osg::NOTICE ) << " - " << fileName << std::endl; } // Query the number of pixels rendered to see if it's time to stop. GLint numPixels( 0 ); pci._glGetQueryObjectiv( pci._queryID, GL_QUERY_RESULT, &numPixels ); osg::notify( osg::DEBUG_FP ) << " BDFX: DP pass " << passCount << ", numPixels " << numPixels << std::endl; if( numPixels < _minPixels ) { passCount++; break; } // We rendered something, so now we render the FSTP to combine the layer we just // created with the original FBO. fboSRH.restore(); drawFSTP( renderInfo, state, ext, pci, fstpLoc, texturePercentLoc ); } if( debugMode & BackdropCommon::debugConsole ) osg::notify( osg::DEBUG_FP ) << "BDFX: DepthPeelBin: " << passCount << " pass" << ((passCount==1)?".":"es.") << std::endl; // Restore to default. glClearDepth( 1.0 ); } // if transparentRemaining } // RenderBin::drawImplementation wrap-up: State restore. drawComplete( state, insertStateSetPosition ); if( dumpImages ) delete[] pixels; // Re-apply the last StateGraph used to render the child subgraph. // This restores state to the way OSG thinks it should be. if( savedStateGraph != NULL ) state.apply( savedStateGraph->getStateSet() ); UTIL_GL_ERROR_CHECK("DepthPeelBin::drawImplementation end"); UTIL_GL_FBO_ERROR_CHECK("DepthPeelBin::drawImplementation end",fboExt); }
int main(int argc, char* argv[]) { XnBool bChooseDevice = false; const char* csRecordingName = NULL; if (argc > 1) { if (strcmp(argv[1], "-devices") == 0) { bChooseDevice = TRUE; } else { csRecordingName = argv[1]; } } if (csRecordingName != NULL) { // check if running from a different directory. If so, we need to change directory // to the real one, so that path to INI file will be OK (for log initialization, for example) if (0 != changeDirectory(argv[0])) { return(ERR_DEVICE); } } // Xiron Init XnStatus rc = XN_STATUS_OK; EnumerationErrors errors; if (csRecordingName != NULL) { xnLogInitFromXmlFile(SAMPLE_XML_PATH); rc = openDeviceFile(argv[1]); } else if (bChooseDevice) { rc = openDeviceFromXmlWithChoice(SAMPLE_XML_PATH, errors); } else { rc = openDeviceFromXml(SAMPLE_XML_PATH, errors); } if (rc == XN_STATUS_NO_NODE_PRESENT) { XnChar strError[1024]; errors.ToString(strError, 1024); printf("%s\n", strError); closeSample(ERR_DEVICE); return (rc); } else if (rc != XN_STATUS_OK) { printf("Open failed: %s\n", xnGetStatusString(rc)); closeSample(ERR_DEVICE); } captureInit(); statisticsInit(); //reshaper.zNear = 1; //reshaper.zFar = 100; //glut_add_interactor(&reshaper); //cb.mouse_function = MouseCallback; //cb.motion_function = MotionCallback; //cb.passive_motion_function = MotionCallback; //cb.keyboard_function = KeyboardCallback; //cb.reshape_function = ReshapeCallback; //glut_add_interactor(&cb); glutInit(&argc, argv); glutInitDisplayString("stencil double rgb"); glutInitWindowSize(WIN_SIZE_X, WIN_SIZE_Y); glutCreateWindow("OpenNI Viewer"); //glutFullScreen(); glutSetCursor(GLUT_CURSOR_NONE); glutMouseFunc(MouseCallback); glutMotionFunc(MotionCallback); init_opengl(); glutIdleFunc(IdleCallback); glutDisplayFunc(drawFunctionMain); glutPassiveMotionFunc(MotionCallback); //createKeyboardMap(); //createMenu(); atexit(onExit); //Use built in hand tracker class to handle all hand movements and gestures HandTracker mainHandTracker(g_Context); m_HandTracker = &mainHandTracker; drawInit(m_HandTracker); //mainHandTracker.Init(); //mainHandTracker.Run(); xn::ImageGenerator test; g_Context.FindExistingNode(XN_NODE_TYPE_IMAGE, test); xn::DepthGenerator depth; g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, depth); depth.GetAlternativeViewPointCap().SetViewPoint(test); glutMainLoop(); return 0; }