Beispiel #1
0
bool FileIntersect::processSortedFiles()
{
    // use the chromsweep algorithm to detect overlaps on the fly.
    NewChromSweep sweep(_context);

    if (!sweep.init()) {
    	return false;
    }
    if (!_recordOutputMgr->init(_context)) {
    	return false;
    }

    RecordKeyList hitSet;
    while (sweep.next(hitSet)) {
    	if (_context->getObeySplits()) {
    		RecordKeyList keySet(hitSet.getKey());
    		RecordKeyList resultSet(hitSet.getKey());
    		_blockMgr->findBlockedOverlaps(keySet, hitSet, resultSet);
    		processHits(resultSet);
    	} else {
    		processHits(hitSet);
    	}
    }
    return true;
}
Beispiel #2
0
Block *
click(int x, int y, int *face)
{
	GLuint  buffer[BUFFER_SIZE];
	GLint	viewport[4];
	GLint  hits;

	glGetIntegerv(GL_VIEWPORT, viewport);
	glSelectBuffer(BUFFER_SIZE, buffer);

	glRenderMode(GL_SELECT);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3]-y), 1.0f, 1.0f, viewport);

	gluPerspective(FOV, (GLfloat) (WINDOW_WIDTH/WINDOW_HEIGHT), Z_NEAR, Z_FAR);
	glMatrixMode(GL_MODELVIEW);
	redraw_world();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glMatrixMode(GL_MODELVIEW);
	hits=glRenderMode(GL_RENDER);

	return processHits(hits, buffer, face);
}
void
SpaceView::postSelectionMode()
{
  // Restore the original projection matrix
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glFlush();

  // Revert to render mode and identify hits under the mouse pointer.
  int hits = glRenderMode(GL_RENDER);
  int numberNames = 0;
  int* hitNames = 0;

  if (hits != 0) {
    hitNames = processHits(hits, _model.getSelectBuffer(), &numberNames);
  }

  // Locate mouse hits with 3D objects
  int name;
  for (int i = 0; i < numberNames; i++) {
    name = hitNames[i];
    _model.getHitModel()._node = _model.getCurrentShot().getScene().getRoot().getNodeForName(name);
    if (_model.getHitModel()._node != 0) {
      _model.getHitModel()._node->triggerHitListeners();
    }
  }
}
void pickRects(AUX_EVENTREC *event)
{
    GLuint selectBuf[BUFSIZE];
    GLint hits;
    GLint viewport[4];
    int x, y;

    x = event->data[AUX_MOUSEX];
    y = event->data[AUX_MOUSEY];
    glGetIntegerv (GL_VIEWPORT, viewport);

    glSelectBuffer (BUFSIZE, selectBuf);
    (void) glRenderMode (GL_SELECT);

    glInitNames();
    glPushName(-1);

    glMatrixMode (GL_PROJECTION);
    glPushMatrix ();
    glLoadIdentity ();
/*  create 5x5 pixel picking region near cursor location	*/
    gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 
	5.0, 5.0, viewport);
    glOrtho (0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
    drawRects (GL_SELECT);
    glPopMatrix ();
    glFlush ();

    hits = glRenderMode (GL_RENDER);
    processHits (hits, selectBuf);
} 
bool BedIntersect::FindBlockedOverlaps(const BED &a, const vector<BED> &a_blocks, 
                                       const vector<BED> &hits, bool a_is_bam) {
    int a_footprint = GetTotalBlockLength(a_blocks);
    // container to store the set of raw hits 
    // that actually overlap the A blocks
    bedVector valid_hits;
    valid_hits.reserve(hits.size());
    
    // 1. Loop through each raw hit (outer loop)
    // 2. Break the raw hit into it;s blocks
    //    and see of one of the hit blocks (inner loop)
    //    overlaps one of a's blocks (inner, inner loop)
    // 3. If so, mark the hit as valid and add it to the valid_set.
    //    Otherwise, the hit only overlapped the span of a and not
    //    the individual blocks.  Thus, it doesn't count.
    bedVector::const_iterator hItr = hits.begin();
    bedVector::const_iterator hEnd = hits.end();
    for (; hItr != hEnd; ++hItr) {
        // break the hit into blocks
        bedVector hitBlocks;
        GetBedBlocks(*hItr, hitBlocks);
        int b_footprint = GetTotalBlockLength(hitBlocks);
        // test to see if there is a valid hit with one of the blocks
        bool valid_hit    = false;
        int total_overlap = 0;
        bedVector::const_iterator hbItr = hitBlocks.begin();
        bedVector::const_iterator hbEnd = hitBlocks.end();
        for (; hbItr != hbEnd; ++hbItr) {
            // look for overlaps between this hit/block and each block in a
            bedVector::const_iterator a_blockItr = a_blocks.begin();
            bedVector::const_iterator a_blockEnd = a_blocks.end();
            for (; a_blockItr != a_blockEnd; ++a_blockItr) {
                int hs = max(a_blockItr->start, hbItr->start);
                int he = min(a_blockItr->end, hbItr->end);
                int overlap = he - hs;
                if (overlap > 0) {
                    valid_hit = true;
                    total_overlap += overlap;
                }
            }
        }
        if (valid_hit) {
            // require sufficint overlap fraction (reciprocal or otherwise)
            // w.r.t to the "footprint" (i.e., the total length of each block)
            if ( ((float) total_overlap / (float) a_footprint) > _overlapFraction) {
                if (_reciprocal && ((float) total_overlap / (float) b_footprint) > _overlapFraction) {
                    valid_hits.push_back(*hItr);
                }
                else if (!_reciprocal) {
                    valid_hits.push_back(*hItr);
                }
            }
        }
    }
    if (!a_is_bam) {
        return processHits(a, valid_hits);
    }
    else
        return !valid_hits.empty();
}
Beispiel #6
0
static void selectObjects(void)
{
   GLuint selectBuf[BUFSIZE];
   GLint hits;

   glSelectBuffer (BUFSIZE, selectBuf);
   (void) glRenderMode (GL_SELECT);

   glInitNames();
   glPushName(0);

   glPushMatrix ();
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   glOrtho (0.0, 5.0, 0.0, 5.0, 0.0, 10.0);
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity ();
   glLoadName(1);
   drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0);
   glLoadName(2);
   drawTriangle (2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0);
   glLoadName(3);
   drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0);
   drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0);
   glPopMatrix ();
   glFlush ();

   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
} 
Beispiel #7
0
void mouse(int button, int state, int x, int y) {
    if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return;

    GLuint select_buf[BUFSIZE];
    GLint hits;
    GLint viewport[4];

    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(BUFSIZE, select_buf);

    (void) glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    gluPickMatrix((GLdouble) x, (GLdouble) viewport[3] - y, 20.0, 20.0, viewport);
    gluPerspective(45.0, width / (double) height, .2, 200.0);

    scene.render(true);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();

    hits = glRenderMode(GL_RENDER);

    if (hits != 0) processHits(hits, select_buf);

    glutPostRedisplay();
}
Beispiel #8
0
/* ARGSUSED */
void
locate(int value)
{
  GLint viewport[4];
  GLint hits;

  if (locating) {
    if (mouse_state == GLUT_ENTERED) {
      (void) glRenderMode(GL_SELECT);
      glInitNames();
      glPushName(-1);

      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      glLoadIdentity();
      viewport[0] = 0;
      viewport[1] = 0;
      viewport[2] = W;
      viewport[3] = H;
      gluPickMatrix(x, H - y, 5.0, 5.0, viewport);
      myortho();
      glMatrixMode(GL_MODELVIEW);
      draw();
      glMatrixMode(GL_PROJECTION);
      glPopMatrix();
      glMatrixMode(GL_MODELVIEW);
      hits = glRenderMode(GL_RENDER);
    } else {
      hits = 0;
    }
    processHits(hits, selectBuf);
  }
  locating = 0;
}
Beispiel #9
0
void pickSquares(int button, int state, int x, int y)
{
   GLuint selectBuf[BUFSIZE];
   GLint hits;
   GLint viewport[4];

   if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)
      return;

   glGetIntegerv (GL_VIEWPORT, viewport);

   glSelectBuffer (BUFSIZE, selectBuf);
   (void) glRenderMode (GL_SELECT);

   glInitNames();
   glPushName(0);

   glMatrixMode (GL_PROJECTION);
   glPushMatrix ();
   glLoadIdentity ();
/*  create 5x5 pixel picking region near cursor location	*/
   gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 
                  5.0, 5.0, viewport);
   gluOrtho2D (0.0, 3.0, 0.0, 3.0);
  
   drawSquares (GL_SELECT);

   glMatrixMode (GL_PROJECTION);
   glPopMatrix ();
   glFlush ();

   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
   glutPostRedisplay();
} 
Beispiel #10
0
int SubdivScene::select(int x, int y, int width, int height, float fovy, Face* f) {
    GLuint buffer[SELECT_BUFFER_SIZE];
    glSelectBuffer(SELECT_BUFFER_SIZE, buffer);
    glRenderMode(GL_SELECT);
    glInitNames();

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, (GLint*) &viewport);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix(x,y, 2, 2, (GLint*) &viewport);
    gluPerspective(fovy, (GLfloat) width/height, 0.01, 100.0);
    glMatrixMode(GL_MODELVIEW);
    
    glPushName(0);

    //draw the scene we will select from
    if (f)
      drawQuads(f);
    else
      drawHDS(true);
      

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    const GLuint hitlist = glRenderMode(GL_RENDER);
    return processHits(hitlist, buffer);
}
void selectionDetection(int button, int state, int x, int y)
{
    GLuint selectBuf[ BUFSIZE ] ;
    GLint viewport[4];
    if (state !=GLUT_DOWN)
        return;
    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(BUFSIZE, selectBuf);
    (void) glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
    gluPerspective(45.0, (GLfloat) ww/(GLfloat) wh, 1.0, 50.0);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    draw(GL_SELECT);
    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();
    glMatrixMode(GL_MODELVIEW);
    processHits( glRenderMode(GL_RENDER),selectBuf, button);
}
Beispiel #12
0
bool FileIntersect::processUnsortedFiles()
{
	const QuickString &databaseFilename = _context->getDatabaseFileName();
	BinTree *binTree = new BinTree(_context->getDatabaseFileIdx(), _context);

	FileRecordMgr *queryFRM = new FileRecordMgr(_context->getQueryFileIdx(), _context);
	if (!queryFRM->open()) {
		return false;
	}

	if (!binTree->loadDB()) {
		fprintf(stderr, "Error: Unable to load database file %s.\n", databaseFilename.c_str());
		delete binTree;
		exit(1);
	}


    _context->determineOutputType();
    _recordOutputMgr->init(_context);

	while (!queryFRM->eof()) {
		Record *queryRecord = queryFRM->allocateAndGetNextRecord();
		if (queryRecord == NULL) {
			continue;
		}
		RecordKeyList hitSet(queryRecord);
		binTree->getHits(queryRecord, hitSet);
    	if (_context->getObeySplits()) {
    		RecordKeyList keySet(hitSet.getKey());
    		RecordKeyList resultSet;
    		_blockMgr->findBlockedOverlaps(keySet, hitSet, resultSet);
    		processHits(resultSet);
    	} else {
    		processHits(hitSet);
    	}
		queryFRM->deleteRecord(queryRecord);
	}
	queryFRM->close();

	//clean up.
	delete queryFRM;
	delete binTree;
	return true;
}
Beispiel #13
0
void Visualizer::finishSelectMode(
  GLint hits,
  GLuint selectBuf[])
{
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();

  hits = glRenderMode(GL_RENDER);
  processHits(hits, selectBuf);
}
Beispiel #14
0
bool BedIntersect::FindOverlaps(const BED &a, vector<BED> &hits) {
    bool hitsFound = false;
    
    // collect and report the sufficient hits
    _bedB->allHits(a.chrom, a.start, a.end, a.strand,
                   hits, _sameStrand, _diffStrand,
                   _overlapFraction, _reciprocal);
    hitsFound = processHits(a, hits);
    return hitsFound;
}
Beispiel #15
0
int GLWidget::selectCube(int mouseX, int mouseY)
{
    const int BUFFER_SIZE = 512;
    GLuint selectionBuffer[BUFFER_SIZE];
    memset(selectionBuffer, 0, sizeof(int) * BUFFER_SIZE);
    GLint viewport[4];
    glGetIntegerv (GL_VIEWPORT, viewport);

    // tell OpenGL to use selection buffer
    glSelectBuffer(BUFFER_SIZE, selectionBuffer);

    // enter selection mode
    glRenderMode(GL_SELECT);

    // init name stack
    glInitNames();

    // Pick Matrix
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix(mouseX, viewport[3] - mouseY, 2, 2, viewport);
    //gluPerspective(FOV_Y,  (float)viewport[2] / viewport[3], 0.1f, 1000.0f);
    glFrustum(-1,1, -1,1, 2.0,10000.0);

    // view transform
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    //glDisable(GL_BLEND);
    //glDisable(GL_LIGHTING);
    glShadeModel(GL_FLAT);

    // draw cubes
    drawCubes();

    //glEnable(GL_BLEND);
    //glEnable(GL_LIGHTING);
    glShadeModel(GL_SMOOTH);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    //glMatrixMode(GL_MODELVIEW);
    //glPopMatrix();
    //glFlush();

    // leave selection mode
    int hitCount = glRenderMode(GL_RENDER);

    // process hits
    if(hitCount > 0)
        return processHits(hitCount, selectionBuffer);
    else
        return -1; // not hit
}
Beispiel #16
0
void GameInterface::performPicking(int x, int y) 
{
	// Sets the buffer to be used for selection and activate selection mode
	glSelectBuffer (BUFSIZE, selectBuf);
	glRenderMode(GL_SELECT);

	// Initialize the picking name stack
	glInitNames();

	// The process of picking manipulates the projection matrix
	// so we will be activating, saving and manipulating it
	glMatrixMode(GL_PROJECTION);

	//store current projmatrix to restore easily in the end with a pop
	glPushMatrix ();

	//get the actual projection matrix values on an array of our own to multiply with pick matrix later
	GLfloat projmat[16];
	glGetFloatv(GL_PROJECTION_MATRIX,projmat);

	// reset projection matrix
	glLoadIdentity();

	// get current viewport and use it as reference for 
	// setting a small picking window of 5x5 pixels around mouse coordinates for picking
	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);

	// this is multiplied in the projection matrix
	gluPickMatrix ((GLdouble) x, (GLdouble) (CGFapplication::height - y), 5.0, 5.0, viewport);

	// multiply the projection matrix stored in our array to ensure same conditions as in normal render
	glMultMatrixf(projmat);

	// force scene drawing under this mode
	// only the names of objects that fall in the 5x5 window will actually be stored in the buffer
	scene->display();

	// restore original projection matrix
	glMatrixMode (GL_PROJECTION);
	glPopMatrix ();

	glFlush();

	// revert to render mode, get the picking results and process them
	GLint hits;
	hits = glRenderMode(GL_RENDER);

	processHits(hits, selectBuf);
}
Beispiel #17
0
void GLWidget::myPick(const QPoint & posMouse)
{
    double x = posMouse.x();
    double y = posMouse.y();

    cout<<"position Pick "<< x<<", "<<y <<endl;
    int BUFSIZE=1024;
    GLuint selectBuf[BUFSIZE];
    GLint hits;
    GLint viewport[4];

    //On récupère le viewport courant
    glGetIntegerv (GL_VIEWPORT, viewport);

    glSelectBuffer (BUFSIZE, selectBuf);
    glRenderMode (GL_SELECT);

    //Initialisation de la pile des noms
    glInitNames();
    glPushName(0);
    glMatrixMode (GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    /*  create 1.0x1.0 pixel picking region near cursor location */
    gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
                   1.0, 1.0, viewport);

    //On doit avoir la même projection en mode sélection qu'en mode rendu :
    float ratio = ((double)vol_width)/((double)vol_height);
    glOrtho(-ratio*100/2.0, ratio*100/2.0,
            -100/2.0, 100/2.0,
            -100*2.,100*2.);

    //drawSquares(GL_SELECT);


    glMatrixMode (GL_PROJECTION);
    glPopMatrix ();

    //On s'assure que les ordres OpenGL sont exécutés
    glFlush();

    hits = glRenderMode (GL_RENDER);
    cout<<"on lance Prohits "<<endl;
    //On traite les sommets cliqués
    processHits(hits, selectBuf); //Fonction appelée ci-dessous
    cout<<" Prohits finit "<<endl;
    updateGL();
}
Beispiel #18
0
void stopPicking() {
	int hits;
	// restoring the original projection matrix
 	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glFlush();
	// returning to normal rendering mode
	hits = glRenderMode(GL_RENDER);
	// if there are hits process them
//	std::cout<<"\nhits = "<< hits;
	if (hits != 0)
		processHits(hits,buff);
}
Beispiel #19
0
bool BedIntersect::FindOverlaps(const BED &a, vector<BED> &hits) {
	
	bool hitsFound = false;

	// should we print each overlap, or does the user want summary information?
	bool printable = true;			
	if (_anyHit || _noHit || _writeCount)
		printable = false;

	// collect and report the sufficient hits
	_bedB->FindOverlapsPerBin(a.chrom, a.start, a.end, a.strand, hits, _forceStrand);
    hitsFound = processHits(a, hits, printable);

    return hitsFound;
}
Beispiel #20
0
void mouse(int button, int state, int x, int y)
{
	GLuint selectBuf[SIZE];
	GLint hits;
	GLint viewport[4];
	
	if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
	{
		glGetIntegerv (GL_VIEWPORT, viewport);
		glSelectBuffer(SIZE, selectBuf);
		
		glRenderMode(GL_SELECT);
		glInitNames();
		glPushName(0);
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		
		gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3]-y), 5.0,5.0,viewport);
		
		gluPerspective(60.0f,(float)Window_Width/(float)Window_Height,1.0f,100.0f);
		
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		
		robotOrientation();

		gluLookAt(deltaX+betaX,deltaY+betaY,deltaZ+betaZ,0.0+deltaX,0.0,0.0+deltaZ, 0.0,1.0,0.0);
		
		drawBuildings(GL_SELECT);
		
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glFlush();
		
		glMatrixMode(GL_MODELVIEW);
		
		hits = glRenderMode(GL_RENDER);
		
		processHits(hits, selectBuf);
		
		//printf("Left Button Press Detected! X: %i Y: %i \n", x, y);
		
		glutPostRedisplay();
		
		
	}
}
Beispiel #21
0
bool Sample_13_3::sendMessage(int message, int mode, int x, int y)
{
	GLuint selectBuf[BUFSIZE];
	GLint hits;
	GLint viewport[4];

	switch (message) {
	case SDL_BUTTON_LEFT:
		/*  sets up selection mode, name stack,
		 *  and projection matrix for picking.  Then the
		 *  objects are drawn.
		 */
		if (mode==SDL_PRESSED) {
			glGetIntegerv (GL_VIEWPORT, viewport);

			glSelectBuffer (BUFSIZE, selectBuf);
			(void) glRenderMode (GL_SELECT);

			glInitNames();
			glPushName(0);

			glMatrixMode (GL_PROJECTION);
			glPushMatrix ();
			glLoadIdentity ();
			/*  create 5x5 pixel picking region near cursor location	*/
			gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
					5.0, 5.0, viewport);
			gluOrtho2D (0.0, 3.0, 0.0, 3.0);
			drawSquares (GL_SELECT);

			glMatrixMode (GL_PROJECTION);
			glPopMatrix ();

			hits = glRenderMode (GL_RENDER);
			processHits (hits, selectBuf);
		}
		break;
	default:
		return false;
		break;
	}

	return true;
}
Beispiel #22
0
void picker(int button, int state, int x, int y){
	x = mousex;
	y = mousey;
	GLuint selectBuf[BUFSIZE];
	GLint hits;
	GLint viewport[4];
	bool newobj = false;
	
	if(button == GLUT_LEFT_BUTTON){
		if(state == GLUT_DOWN){	
		glGetIntegerv(GL_VIEWPORT, viewport);
		
		glSelectBuffer(BUFSIZE, selectBuf); //Array to be used for recording object hits
		(void) glRenderMode(GL_SELECT); 	//Enter Selection Mode
		
		//Initialize the name stack
		glInitNames();  
		glPushName(0);
		//Save current transformation state.
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		
		// Create a 5x5 picking region near cursor location
		gluPickMatrix((GLdouble) mousex, (GLdouble) (viewport[3] - mousey), 5.0,
		5.0, viewport);
		drawHouse(GL_SELECT, -7,0, 0,    0,     3, 5, 3.4,   2,   .85,.8,0,  .9,.9,0, .7,.7,0,   0.9,.8,0, texture[1], texture[5]);
		
		glMatrixMode (GL_PROJECTION);
		glPopMatrix ();
		glFlush ();
		
		hits = glRenderMode (GL_RENDER);
		processHits (hits, selectBuf);
		glutPostRedisplay();
	}
	
	if((state == GLUT_UP)&&(newobj == true)){
		glutWarpPointer(winwidth/2, winheight/2);
	}	
	}
	glutPostRedisplay();
}
Beispiel #23
0
// use the mouse call back to enter and leave the selection mode
void mouse(int button, int state, int x, int y)
{
	GLuint selectBuf[SIZE];
	GLint hits;
	GLint viewport[4];
	
	if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
		isSelected = true;
		glGetIntegerv (GL_VIEWPORT, viewport);
		
		glSelectBuffer (SIZE, selectBuf);
		glRenderMode(GL_SELECT);
		
		glInitNames(); // initialize the name stack
		glPushName(0); // with an unused name
		
		glMatrixMode (GL_PROJECTION);
		glPushMatrix ();
		glLoadIdentity ();
		/*  create 5x5 pixel picking region near cursor location	*/
		gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
					   5.0, 5.0, viewport);
//		glOrtho(-2.0, 2.0, -2.0, 2.0,0.0,5.0); // same as in the render mode
		glViewport(0, 0, width, height);
		drawCurves(GL_SELECT); // direct call of the drawing function
		
		glMatrixMode (GL_PROJECTION);
		glPopMatrix ();
		glFlush ();
		
		hits = glRenderMode (GL_RENDER); // returns the number of hits
		processHits (hits, selectBuf);
	}
	else
	{
		isSelected = false;
	}
	
	glutPostRedisplay();
}
Beispiel #24
0
void rotationGizmo::pickAxis( float x, float y, float width, float height )
{
    std::cout << "PICKING AXIS " << std::endl;
    int BUFSIZE = 512;
    GLuint selectBuf[BUFSIZE];
    GLint hits;
    GLint viewport[4];

    glGetIntegerv (GL_VIEWPORT, viewport);

    glSelectBuffer (BUFSIZE, selectBuf);
    (void) glRenderMode (GL_SELECT);

    glInitNames();
    glPushName(0);

    glMatrixMode (GL_PROJECTION);
    glPushMatrix ();
    glLoadIdentity ();
    /*  create 5x5 pixel picking region near cursor location      */
    gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
                  25.0, 25.0, viewport);

    //gluOrtho2D (0.0, 3.0, 0.0, 3.0);
    glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
    this->draw(true);

    glMatrixMode (GL_PROJECTION);
    glPopMatrix ();
    glFlush ();

    hits = glRenderMode (GL_RENDER);
    processHits (hits, selectBuf);

    //    glutPostRedisplay();

}
void Picksquare::mousePressEvent(QMouseEvent *e)

{
   GLuint selectBuf[BUFSIZE];
   GLint hits;
   GLint viewport[4];

   if (e-> button() != LeftButton) //|| state != GLUT_DOWN)
      return;

   glGetIntegerv (GL_VIEWPORT, viewport);

   glSelectBuffer (BUFSIZE, selectBuf);
   (void) glRenderMode (GL_SELECT);

   glInitNames();
   glPushName(0);

   glMatrixMode (GL_PROJECTION);
   glPushMatrix ();
   glLoadIdentity ();

//  create 5x5 pixel picking region near cursor location        

   gluPickMatrix ((GLdouble) e->x(), (GLdouble) (viewport[3] - e->y()), 
                  5.0, 5.0, viewport);
   gluOrtho2D (0.0, 3.0, 0.0, 3.0);
   drawSquares (GL_SELECT);

   glMatrixMode (GL_PROJECTION);
   glPopMatrix ();
   glFlush ();

   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
   update();
} 
Beispiel #26
0
void selectFace(int x, int y)
{
    GLuint selBuffer[BUFSIZE];
    GLint hits;
    glSelectBuffer(BUFSIZE, selBuffer);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix((GLfloat) x, (GLfloat) (g_viewport[3] - y),
                  1.0, 1.0, g_viewport);
    gluPerspective(45.0, (GLfloat) g_viewport[2] / (GLfloat) g_viewport[3], 1.0, 300.0);
    drawCube();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();

    hits = glRenderMode(GL_RENDER);
    processHits(hits, selBuffer);
    glutPostRedisplay();
}
Beispiel #27
0
void GlWidget::pick(const QPoint &pos)
{
  qreal x = pos.x();
  qreal y = pos.y();

  GLuint selectBuf[1024];
  GLint hits;
  GLint viewport[4];

  glGetIntegerv(GL_VIEWPORT, viewport);
  glSelectBuffer(1024, selectBuf);
  glRenderMode(GL_SELECT);

  glInitNames();
  glPushName(0);

  glPushMatrix();
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), 1.f, 1.f, viewport);
  glOrtho(-1, +1, +1, -1, -1.0, 15.0);

  draw();

  glMatrixMode(GL_PROJECTION);
  glPopMatrix();

  hits = glRenderMode(GL_RENDER);

  //On traite les sommets cliqués
  processHits(hits, selectBuf); //Fonction appelée ci-dessous

  glPopMatrix();

  updateGL();
}
Beispiel #28
0
void pickFaces(int button, int state, int x, int y)
{
    GLuint selectBuf[BUFSIZE];
    GLint hits;
    GLint viewport[4];
    
    if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) {
        return;
    }
    glGetIntegerv(GL_VIEWPORT, viewport);
    
    glSelectBuffer(BUFSIZE, selectBuf);
    (void) glRenderMode(GL_SELECT);
    
    glInitNames();
    glPushName(0);
    
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    /*  create 5x5 pixel picking region near cursor location */
    gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y),
                  5.0, 5.0, viewport);
    glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
//    glOrtho(0.0f, windowWidth, windowHeight, 0.0f, 0.0f, 1.0f);

    drawObj(GL_SELECT);
    
    glMatrixMode (GL_PROJECTION);
    glPopMatrix();
    glutSwapBuffers();
    
    hits = glRenderMode(GL_RENDER);
    processHits(hits, selectBuf);
    glutPostRedisplay();
}
Beispiel #29
0
void BedIntersect::IntersectBed() {

    // create new BED file objects for A and B
    _bedA = new BedFile(_bedAFile);
    _bedB = new BedFile(_bedBFile);

    if (_sortedInput == false) {
        // load the "B" file into a map in order to
        // compare each entry in A to it in search of overlaps.
        _bedB->loadBedFileIntoMap();

        vector<BED> hits;
        hits.reserve(100);
        BED a;

        // open the "A" file, process each BED entry and searh for overlaps.
        _bedA->Open();
        // report A's header first if asked.
        if (_printHeader == true) {
            _bedA->PrintHeader();
        }
        while (_bedA->GetNextBed(a)) {
            if (_bedA->_status == BED_VALID) {
                // treat the BED as a single "block"
                if (_obeySplits == false)
                    FindOverlaps(a, hits);
                // split the BED12 into blocks and look for overlaps in each discrete block
                else {
                    // find the hits that overlap with the full span of the blocked BED
                    _bedB->allHits(a.chrom, a.start, a.end, a.strand,
                                   hits, _sameStrand, _diffStrand,
                                   _overlapFraction, _reciprocal);
                    // break a into discrete blocks, as we need to 
                    // measure overlap with the individual blocks, not the full span.
                    bedVector a_blocks; 
                    GetBedBlocks(a, a_blocks);
                    // find the overlaps between the block in A and B 
                    // last parm is false as a is not a BAM entry
                    FindBlockedOverlaps(a, a_blocks, hits, false);
                }
                hits.clear();
            }
        }
        _bedA->Close();
    }
    else {
        // use the chromsweep algorithm to detect overlaps on the fly.
        ChromSweep sweep = ChromSweep(_bedA, _bedB, 
                                      _sameStrand, _diffStrand, 
                                      _overlapFraction, _reciprocal,
                                      _printHeader);

        pair<BED, vector<BED> > hit_set;
        hit_set.second.reserve(10000);
        while (sweep.Next(hit_set)) {
            if (_obeySplits == false)
                processHits(hit_set.first, hit_set.second);
            else {
                bedVector a_blocks; 
                GetBedBlocks(hit_set.first, a_blocks);
                FindBlockedOverlaps(hit_set.first, a_blocks, hit_set.second, false);
            }
        }
    }
}
Beispiel #30
0
/**
 * base de este codigo tomado de la pagina que 
 * hace picking con hombres de nieve
 */
void pick_points(int x, int y) {
  int i,j;
  int cursorX = x;
  int cursorY = y;
  GLint hits;

  // inicializo el picking
  GLint viewport[4];
  float ratio;

  GLuint selectBuf[BUFSIZE];
  glSelectBuffer(BUFSIZE,selectBuf);

  glGetIntegerv(GL_VIEWPORT,viewport);

  glRenderMode(GL_SELECT);

  glInitNames();

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();

  gluPickMatrix(cursorX,viewport[3]-cursorY,1,1,viewport);
  ratio = (viewport[2]+0.0) / viewport[3];
  gluPerspective(camera->aperture,ratio,0.1,1000);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(camera->position.x, camera->position.y, camera->position.z,
	    camera->center.x,   camera->center.y,   camera->center.z,
	    camera->up.x,       camera->up.y,       camera->up.z);
  glRotatef(surface->alphax,1.0,0.0,0.0);
  glRotatef(surface->alphaz,0.0,0.0,1.0);
  for (i=0;i<11;i++) {
    for (j=0;j<11;j++) {
      POINT3D punto = *(surface->ptscontrol+i*11+j);
      glPushMatrix();
      glPushName(11*i + j);
      glTranslatef(punto.x,
		   punto.y+2.0,
		   punto.z);
      glRectf(-0.25f,0.25f,0.25f,-0.25f);
      glRotatef(90,1,0,0);
      glRectf(-0.25f,0.25f,0.25f,-0.25f);
      glRotatef(90,0,1,0);
      glRectf(-0.25f,0.25f,0.25f,-0.25f);
      glPopName();
      glPopMatrix();
    }
  }

  // termino de pickear y testeo
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glFlush();
  hits = glRenderMode(GL_RENDER);

  if (hits != 0){
    processHits(hits,selectBuf,0);
  }
}