Example #1
0
void RenderScene::mousePressEvent(QGraphicsSceneMouseEvent *event)  {
   if (_isDrawing) {

       drawingFigure->addPoint(event->scenePos());

       if (drawingFigure->isFinished()) {

           figures.push_back(drawingFigure);
           drawingFigure->draw(*this);
           endDrawing();
       }
    }
    else {
       startDrawing();
       drawingFigure = getDrawingFigure(figureName, event->scenePos());
       if (!drawingFigure) {
           endDrawing();
           return;
       }
       drawingFigure->setBorderColor(new QColor(lineColor));
       Figure2D* df = dynamic_cast<Figure2D*>(drawingFigure);
       if (withFill && df)
           df->setFillColor(new QColor(fillColor));
    }
}
Example #2
0
void MyBrush::draw() {
    // Set up camera for drawing
    setup2DDrawing( Color(0,0,0), screenWidth, screenHeight );

    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    // Draw a border around the actual image
    glColor3f(1.0f, 1.0f, 1.0f);
    glBegin(GL_LINE_LOOP);
    glVertex2i( 0,            0 );
    glVertex2i( imageWidth+1, 0 );
    glVertex2i( imageWidth+1, imageHeight+1 );
    glVertex2i( 0,            imageHeight+1 );
    glEnd();


    glRasterPos2i(0, 0);
    // Copy data into window
	//for ( int iX = 0; iX < 100; iX++ )
		//putPixel( iX, iX, Color(1,0,0) );

    glDrawPixels(imageWidth, imageHeight, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);

	// These 5 lines draw a white line across your canvas
	// Remove this and replace it with intelligent OpenGL preview code

    // Add in your OpenGL pre-view code here

    // display draw in progress (mouse is down)
    if (isMouseDown) {
    }
    endDrawing();
}
Example #3
0
void drawGame(Game *game)
{
	beginDrawing(game->renderer);
	
	drawMap(game->map, game->renderer);
	drawPerso(game->renderer);
	
	endDrawing(game->renderer);
}
void ShapesUI::draw() {
    // Sets up the viewport and background color
    setup3DDrawing( Color( 0,0,0 ), width, height, true );

    // Changes the way triangles are drawn
    switch ( shapesUI->getDisplayType() ) {
        case DISPLAY_WIREFRAME: {
            glDisable(GL_LIGHTING);
            glPolygonMode(GL_FRONT, GL_LINE);
            glColor3f(1.0f, 1.0f, 1.0f);
        } break;
        case DISPLAY_FLAT_SHADING: {
            glEnable(GL_LIGHTING);
            glPolygonMode(GL_FRONT, GL_FILL);
            glColor3f(1.0f, 1.0f, 1.0f);
            glShadeModel(GL_FLAT);
        } break;
        case DISPLAY_SMOOTH_SHADING: {
            glEnable(GL_LIGHTING);
            glPolygonMode(GL_FRONT, GL_FILL);
            glColor3f(1.0f, 1.0f, 1.0f);
            glShadeModel(GL_SMOOTH);
        } break;
        default: break;
    }

    // Setup the camera
    gluLookAt( 3.5 * cos( shapesUI->getYRot() ) * cos( shapesUI->getXRot() ), 
               3.5 * sin( shapesUI->getYRot() ), 
               3.5 * cos( shapesUI->getYRot() ) * sin( shapesUI->getXRot() ), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    // ToDo: draw your shape here
    // DO NOT put the actual draw OpenGL code here - put it in the shape class and call the draw method
	if (current != 0){
		if(shapesUI->getShapeType() != SHAPE_TORUS)	{
			current->draw();
		}
		else
			Torus(5,5);
		
	}

    endDrawing();
}
void SummaryDrawWidget::paintEvent( QPaintEvent * )
{
  Channel *ch;

  //if((right - left) <= 0) return;
  View *view = gdata->view;
/*  if (view->totalTime() == 0) {
    buffer = new QPixmap(size());
    buffer->fill(myBackgroundColor);
    bitBlt(this, 0, 0, buffer); */
  if(gdata->totalTime() < 0) return;

  double timeRatio = double(width()) / gdata->totalTime();
  double pitchRatio = double(height()) / (gdata->topPitch() / scaler);

  beginDrawing();

  //draw all the channels
  for(int j = 0; j < (int)gdata->channels.size(); j++) {
    ch = gdata->channels.at(j);
    if(!ch->isVisible()) continue;

    //drawChannel(ch, p, view->leftTime(), (view->totalTime() / (double) width()), 0.0f, (double) view->topNote() / (double) height(), DRAW_VIEW_SUMMARY);
    drawChannel(*this, ch, p, gdata->leftTime(), view->currentTime(), (gdata->totalTime() / (double) width()), 0.0f, (double) gdata->topPitch() / (double) height(), DRAW_VIEW_SUMMARY);
  }

  //draw the view rectangle 
  p.setPen(QPen(colorGroup().highlight(), 1));
  p.drawRect(int((gdata->leftTime()+view->viewLeft())*timeRatio), height()-1-int((view->viewTop())*pitchRatio),
             int(view->viewWidth()*timeRatio), int(view->viewHeight()*pitchRatio));

  //draw the current time line
  p.setPen(QPen(colorGroup().foreground(), 1));
  //p.moveTo(int((gdata->leftTime()+view->currentTime())*timeRatio), 0);
  //p.lineTo(int((gdata->leftTime()+view->currentTime())*timeRatio), height()-1);
  p.drawLine(int((gdata->leftTime()+view->currentTime())*timeRatio), 0, 
             int((gdata->leftTime()+view->currentTime())*timeRatio), height()-1);

  endDrawing();
}
Example #6
0
Figure* RenderScene::getDrawingFigure(FigureName newFigure,
                                      const QPointF& startPosition) {

    switch (newFigure) {
        case RenderScene::Seg :
            return new Segment(startPosition);
        case RenderScene::Ell :
            return new Ellipse(startPosition);
        case RenderScene::Cir :
            return new Circle(startPosition);
        case RenderScene::Pol :
            return new Polygon(startPosition);
        case RenderScene::Tri :
            return new Triangle(startPosition);
        case RenderScene::Rec :
            return new Rectangle(startPosition);
        case RenderScene::Squ :
            return new Square(startPosition);
        default:
            endDrawing();
            return NULL;
    }
}
void InteractiveUI::draw() {
    setup3DDrawing( scene.getBackground(), scene.getCamera().getWidth(), scene.getCamera().getHeight(), false );

    // Sets up the camera and model view matrices
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixd( &ibar.getCamera().getProjection()(0,0) );    
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( &ibar.getCamera().getWorldToCamera()(0,0) );    

    glPushAttrib( GL_ALL_ATTRIB_BITS );
    // Start drawing at the top of the tree
    scene.draw();
    glPopAttrib();

    if ( interactiveUI->m_bWidget->value() ) {
        glEnable( GL_LIGHT0 );
        widget.DrawWidget();
    }

    if ( interactiveUI->m_bIBar->value() )
        ibar.Draw( bIsMouseOverIBar, interactiveUI->m_bIBarHelp->value() ? true : false );

    endDrawing();
}
Example #8
0
void VolumeMeterWidget::paintEvent( QPaintEvent * )
{
  Channel *active = gdata->getActiveChannel();
  //if(!active) { return; printf("failed active\n"); }
  //AnalysisData *analysisData = active->currentLookup();
  //if(!analysisData) { return; printf("failed currentLookup\n"); }

  beginDrawing(false);
  fillBackground(colorGroup().background());
  p.setFont(_font);
  
  // Work out how many labels we can draw
  QFontMetrics fm = p.fontMetrics();
  int labelWidth = fm.width("-60"); // Since we'll have two characters normally
  int halfLabelWidth = labelWidth / 2;
  int stopWidth = fm.width("0dB") / 2;
  int realWidth = width() - stopWidth - halfLabelWidth; // The actual width of the data
  int places = labelNumbers[MIN(realWidth / 20, 6) - 1]; // How many labels we should have
  int pixelStep = toInt(double(realWidth) / double(places)); // How many pixels to jump between labels/markers
  //int stopPixel = halfLabelWidth + places * pixelStep; // The actual pixel to stop drawing on
  //int fontSize = 9;
  //int lineY = height() - fontSize - 8;
  int lineY = height() - _fontSize - 2;

  int labelStep = 10;

  // Determine how many dB we should jump by each time
  switch (places) {
    case 1:
    labelStep = 60;
    break;
    case 2:
    labelStep = 30;
    break;
    case 3:
    labelStep = 20;
    break;
    case 6:
    labelStep = 10;
    break;
    default:
    myassert(false); // This should never happen!
    break;
  }


  // Draw horizontal line
  //p.setPen(colorGroup().foreground());
  p.setPen(Qt::black);
  //p.drawLine(halfLabelWidth, lineY, stopPixel, lineY);
  //p.setFont(QFont("AnyStyle", fontSize));

  int y = height() - (lineY/2)- 1;

  for (int i=0; i < places; i++) {
    int x = i * pixelStep;
    p.drawText(x, y, QString::number(-60 + (i * labelStep)));
  }
  p.drawText(places * pixelStep - 2, y, "0dB");

/*
  // Draw the number markers
  int secondaryMarker = pixelStep / 2;
  for (int j=0; j <= places; j++) {
    int major = j * pixelStep + halfLabelWidth;
    int minor = major + secondaryMarker;
    p.drawLine(major, lineY, major, lineY + 5);
    p.drawLine(minor, lineY, minor, lineY + 3);
  }
*/
  
  QColor colour;
  //if (active != NULL && active->hasAnalysisData()) {
  //printf("%d, %d\n", active->chunkAtCurrentTime(), active->totalChunks());
  //int chunk = active->chunkAtCurrentTime() - 1;
  //printf("%d, %d\n", active->chunkNum(), active->totalChunks());
  float theVal[2];
  if (active != NULL && active->isValidChunk(active->currentChunk())) {
    int chunk = active->currentChunk();
    if(active->getParent()->numChannels() > 1) {
      theVal[0] = active->getParent()->channels(0)->dataAtChunk(chunk)->getMaxIntensityDB();
      theVal[1] = active->getParent()->channels(1)->dataAtChunk(chunk)->getMaxIntensityDB();
    } else {
      theVal[0] = theVal[1] = active->dataAtChunk(chunk)->getMaxIntensityDB();
    }
  } else {
    theVal[0] = theVal[1] = 0.0;
  }
  
  //AnalysisData &analysisData = active->dataAtCurrentTime();
  //int val = toInt(analysisData->maxIntensity * double(width()));
  //double decibels = 20.0 * log10(analysisData.maxIntensity);
  for(int chnl=0; chnl<2; chnl++) {
    //double decibels = 20.0 * log10(theVal[chnl]);
    double decibels = theVal[chnl];
    // We'll show 60 dB
    //int val = toInt(((double(width() - halfLabelWidth) / 60.0) * decibels) + width() - halfLabelWidth);
    int val = toInt((double(realWidth / 60.0) * decibels) + realWidth);

    //**************************************************************
    //int barWidth = 12; // Not right - needs to be based on realWidth
    //int barWidth = 5; // Not right - needs to be based on realWidth
    int barWidth = 5; // Not right - needs to be based on realWidth
    //**************************************************************
    // double step = realWidth / floor(realWidth / 12)



    //for(int j=halfLabelWidth; j<=val; j+=10) {
    for(int j=halfLabelWidth; j<=realWidth; j+=10) {
      if(j < val) {
        //int col = MIN(MAX(j*255/width(), 0), 255);
        //p.fillRect(j-3, 0, 3, height()-1, QColor(col, 255 - col, 0));
        if ( j < (width() * 0.5)) colour = Qt::blue;
        else if ( j < (width() * 0.85)) colour = QColor(255, 120, 60);
        else colour = Qt::red;
      } else {
        colour = QColor(198, 198, 198);
      }
      
      if(chnl == 0)
        p.fillRect(j, 2, barWidth, lineY/2 -3, colour);
      else
        p.fillRect(j, height() - (lineY/2) + 1, barWidth, lineY/2 -3, colour);
      //p.setPen(Qt::black);
      //p.drawRect(j, 0, barWidth, height()-20+1);
    }
    //p.fillRect(0, height()-1-val, width()-1, height()-1, QColor(Qt::red));
  }

  endDrawing();  
/*
    float pos;
    float *data;
    float step = float(width()) / float(buffer->length());
    // int h2 = height() / 2;
    float hf = float(height());
    unsigned int j;
    int cur=0, prev=0;

    int c;
    //float *temp[gdata->process_channels];
    float *temp[2];

    for(c = 0; c < gdata->process_channels; c++)
        temp[c] = (float *)malloc(buffer->length() * sizeof(float));
    buffer->lock();
    for(c = 0; c < gdata->process_channels; c++)
        memcpy(temp[c], buffer->begin(c), buffer->length() * sizeof(float));
    buffer->unlock();


    QPainter p;
    p.begin(this);

    for(c=0; c < gdata->process_channels; c++) {
	data = temp[c]; //buffer->data[c];
	pos = 0.0;
	if(c == 0) p.setPen(QPen(red, 4));
	else p.setPen(QPen(blue, 4));
	prev = height()-1-int(data[0]*hf);
	//p.moveTo(0, height()-1-int(data[0]*hf));
	for(j=0; j<buffer->length(); j++, pos+=step) {
	    //p.lineTo(j, h2-int(interpolate_linear(buffer->length(), data, pos)*h2f));
	    cur = height()-1-int(data[j]*hf);
	    //p.lineTo(j, cur);
	    p.drawLine(int(pos-step), prev, int(pos), cur);
	    prev = cur;
	}
    }
    p.end();
*/
}
Example #9
0
void TimeAxis::paintEvent(QPaintEvent *)
{
  int frameWidth = 2;
  const int	h = height(), w = width() - 2*frameWidth;
  int fontSpace = _fontSize+2;
  
  beginDrawing(false);
  fillBackground(colorGroup().background());

  double timeStep = timeWidth() / double(w) * 150.0; //time per 150 pixels
  double timeScaleBase = pow10(floor(log10(timeStep))); //round down to the nearest power of 10

  //choose a timeScaleStep which is a multiple of 1, 2 or 5 of timeScaleBase
  int largeFreq;
  if(timeScaleBase * 5.0 < timeStep) { largeFreq = 5; }
  else if (timeScaleBase * 2.0 < timeStep) { largeFreq = 2; }
  else { largeFreq = 2; timeScaleBase /= 2; }
    
  // Draw Ruler Numbers
  p.setBrush(Qt::black);
  //p.setFont(QFont("AnyStyle", h / 2 - 7));
  p.setFont(_font);
  double timePos = floor(leftTime() / (timeScaleBase*largeFreq)) * (timeScaleBase*largeFreq); //calc the first one just off the left of the screen
  int x, largeCounter=-1;
  
  //precalculate line sizes (for efficiency)
  int smallLineTop = 0;
  int smallLineBottom = 0;
  if(_numbersOnTop) {
    smallLineTop = h - 1 - (h - 1 - fontSpace)/2;
    smallLineBottom = h - 1;
  } else {
    smallLineTop = 0;
    smallLineBottom = (h - 1 - fontSpace) / 2;
  }
  int bigLineTop = 0;
  int bigLineBottom = 0;
  if(_numbersOnTop) {
    bigLineTop = fontSpace;
    bigLineBottom = h - 1;
  } else {
    bigLineTop = 0;
    bigLineBottom = h - 1 - fontSpace;
  }
  int textBottom = 0;
  if(_numbersOnTop) textBottom = _fontSize;
  else textBottom = h - 1;
    
  for(; timePos <= rightTime(); timePos += timeScaleBase) {
    if(++largeCounter == largeFreq) {
      largeCounter = 0;
      //draw the bigger lines and the numbers
      //QString numString = QString::number(timePos);

      double newTime = myround(timePos / timeScaleBase) * timeScaleBase;
      QString mins;
      double secs = fmod(newTime, 60.0);

      if (timePos < 0) {
        mins = "-" + QString::number(int(ceil(newTime / 60)));
        secs *= -1;
      } else {
        mins = QString::number(int(floor(newTime / 60)));
      }

      QString seconds = QString::number(secs);
      if (secs < 10 && secs > -10) {
        seconds = "0" + seconds;
      }
      
      QString numString = mins + ":" + seconds;
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawText(x - (p.fontMetrics().width(numString) / 2), textBottom, numString);
      p.drawLine(x, bigLineTop, x, bigLineBottom);
    } else {
      //draw the smaller lines
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawLine(x, smallLineTop, x, smallLineBottom);
    }
  }
  //draw the horizontal line
  if(_numbersOnTop) {
    p.drawLine(0, h-1, width(), h-1);
  } else {
    p.drawLine(0, 0, width(), 0);
  }
  endDrawing();
}
Example #10
0
void MyBrush::draw() {
    // Set up camera for drawing
    setup2DDrawing( Color(0,0,0), screenWidth, screenHeight );

    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    // Draw a border around the actual image
    glColor3f(1.0f, 1.0f, 1.0f);
    glBegin(GL_LINE_LOOP);
    glVertex2i( 0,            0 );
    glVertex2i( imageWidth+1, 0 );
    glVertex2i( imageWidth+1, imageHeight+1 );
    glVertex2i( 0,            imageHeight+1 );
    glEnd();


    glRasterPos2i(0, 0);
    // Copy data into window
	//for ( int iX = 0; iX < 100; iX++ )
		//putPixel( iX, iX, Color(1,0,0) );

    glDrawPixels(imageWidth, imageHeight, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);

	// These 5 lines draw a white line across your canvas
	// Remove this and replace it with intelligent OpenGL preview code
	/*
	glLineWidth( 10);
	glBegin( GL_LINES );
	glVertex2i( 100, 100 );
	glVertex2i( 200, 200 );
	glEnd();
	*/

    // Add in your OpenGL pre-view code here

    // display draw in progress (mouse is down)
	ToolType type = brushUI->getToolType();
    if (!isMouseDown) {
		switch(type) {
			case TOOL_BRUSH:{
				int xCenter = mouseDrag[0];
				int yCenter = mouseDrag[1];
				int radius = brushUI->getRadius();
				int segments = radius * 4;
				glBegin(GL_LINE_LOOP);
				for (int i = 0; i < segments; i++)
				{
					float angle = 2.0f * 3.1415926f * float(i) / float(segments);
					float x = radius * cosf(angle);
					float y = radius * sinf(angle); 
					glVertex2f(x + xCenter, y + yCenter);
				}
				glEnd();
			}break;
		}
    }
	else{
		switch (type) {
			case TOOL_LINE:{
				const int radius = brushUI->getRadius();

				int x0 = mouseDown[0];
				int y0 = mouseDown[1];
				int x1 = mouseDrag[0];
				int y1 = mouseDrag[1];

				LineSegment ls(x0, y0, x1, y1);
				std::vector<LineSegment> lineList;

				//find four corners of thick line
				if (ls.v0.horizontal){
					LineSegment ls0(x0, (int)(y0 - floor(radius / (float)2)), x1, (int)(y1 - floor(radius / (float)2)));
					LineSegment ls1(x0, (int)(y0 + ceil(radius / (float)2)), x1, (int)(y1 + ceil(radius / (float)2)));
					lineList.push_back(ls0);
					lineList.push_back(ls1);
				}
				else if (ls.v0.type == VERTICAL){
					LineSegment ls0((int)(x0 - floor(radius / (float)2)), y0, (int)(x1 + ceil(radius / (float)2)), y0);
					LineSegment ls1((int)(x0 - floor(radius / (float)2)), y1, (int)(x1 + ceil(radius / (float)2)), y1);
					lineList.push_back(ls0);
					lineList.push_back(ls1);
				}
				else{
					int rise = y1 - y0;
					int run = x1 - x0;
					float normFactor = (float)sqrt(rise*rise + run*run);
					float dy = run / normFactor;
					float dx = rise / normFactor;

					float halfRadius = radius / (float)2;
					int fR = (int)floor(halfRadius);
					int cR = (int)ceil(halfRadius);

					LineSegment ls0(x0 - myroundf(dx*fR), y0 + myroundf(dy*fR), x1 - myroundf(dx*fR), y1 + myroundf(dy*fR));
					LineSegment ls1(x1 + myroundf(dx*cR), y1 - myroundf(dy*cR), x0 + myroundf(dx*cR), y0 - myroundf(dy*cR));
					lineList.push_back(ls0);
					lineList.push_back(ls1);
				}
				glBegin(GL_LINE_LOOP);
				glVertex2f((GLfloat)lineList[0].v0.x, (GLfloat)lineList[0].v0.y);
				glVertex2f((GLfloat)lineList[0].v1.x, (GLfloat)lineList[0].v1.y);
				glVertex2f((GLfloat)lineList[1].v0.x, (GLfloat)lineList[1].v0.y);
				glVertex2f((GLfloat)lineList[1].v1.x, (GLfloat)lineList[1].v1.y);
				glEnd();
			}break;
			case TOOL_CIRCLE:{
				int xCenter = mouseDown[0];
				int yCenter = mouseDown[1];
				int thickness = brushUI->getRadius();

				int xExtent = mouseDrag[0];
				int yExtent = mouseDrag[1];

				int radius = myroundf((float)sqrt((xExtent - xCenter)*(xExtent - xCenter) + (yExtent - yCenter)*(yExtent - yCenter)));

				int innerRadius = radius - (int)floor(thickness / (float)2);
				int outerRadius = radius + (int)ceil(thickness / (float)2);

				int segments = innerRadius * 4;
				glBegin(GL_LINE_LOOP);
				for (int i = 0; i < segments; i++)
				{
					float angle = 2.0f * 3.1415926f * float(i) / float(segments);
					float x = innerRadius * cosf(angle);
					float y = innerRadius * sinf(angle);
					glVertex2f(x + xCenter, y + yCenter);
				}
				glEnd();

				segments = outerRadius * 4;
				glBegin(GL_LINE_LOOP);
				for (int i = 0; i < segments; i++)
				{
					float angle = 2.0f * 3.1415926f * float(i) / float(segments);
					float x = outerRadius * cosf(angle);
					float y = outerRadius * sinf(angle);
					glVertex2f((GLfloat)(x + xCenter), (GLfloat)(y + yCenter));
				}
				glEnd();
			}break;
			case TOOL_POLYGON:{
				glBegin(GL_LINE_LOOP);
				for (size_t i = 0; i < polygon.size(); ++i){
					glVertex2f((GLfloat)polygon[i][0], (GLfloat)polygon[i][1]);
				}
				glVertex2f((GLfloat)mouseDrag[0], (GLfloat)mouseDrag[1]);
				glEnd();
			}break;
		}
	}
    endDrawing();
}
Example #11
0
void IntersectionUI::draw() {
    setup3DDrawing( Color(1,1,1), width, height, true );

    glMatrixMode(GL_MODELVIEW);
    gluLookAt( 3.5 * cos( intersectionUI->getYRot() ) * cos( intersectionUI->getXRot() ), 
               3.5 * sin( intersectionUI->getYRot() ), 
               3.5 * cos( intersectionUI->getYRot() ) * sin( intersectionUI->getXRot() ), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);


    glDisable(GL_LIGHTING);
    if ( intersectionUI->m_bGrid->value() ) {
        glBegin(GL_LINES);
        // draw grid
        glColor3f(0.0f, 0.0f, 0.0f);
        for (int i = 0; i <= 10; i++) {
            float s = -2.0f + i / 2.5f;
            glVertex3f(s, 0.0f, -2.0f);
            glVertex3f(s, 0.0f,  2.0f);
            glVertex3f(-2.0f, 0.0f, s);
            glVertex3f( 2.0f, 0.0f, s);
        }
        glEnd();
        // draw (X,Y,Z) axes
        glLineWidth(3.0f);
        glBegin(GL_LINES);
        glColor3f(1.0f, 0.0f, 0.0f);
        glVertex3f(-2.0f, 0.0f, 0.0f);
        glVertex3f( 2.0f, 0.0f, 0.0f);
        glColor3f(0.0f, 1.0f, 0.0f);
        glVertex3f(0.0f, -2.0f, 0.0f);
        glVertex3f(0.0f,  2.0f, 0.0f);
        glColor3f(0.0f, 0.0f, 1.0f);
        glVertex3f(0.0f, 0.0f, -2.0f);
        glVertex3f(0.0f, 0.0f,  2.0f);
        glEnd();
        glLineWidth(1.0f);
    }

    // compute ray origin from parameters
    Point3 pAt( intersectionUI->m_dXAt->value(), intersectionUI->m_dYAt->value(), intersectionUI->m_dZAt->value() );

    // compute ray direction from parameters
    Vector3 dir;
    dir[0] = cos(intersectionUI->getPhi()) * cos(intersectionUI->getTheta());
    dir[1] = sin(intersectionUI->getPhi());
    dir[2] = cos(intersectionUI->getPhi()) * sin(intersectionUI->getTheta());

    const Point3 pE1 = pAt - dir * 2.0;
    const Point3 pE2 = pAt + dir * 2.0;
    
    if (intersectionUI->m_bRay->value()) {
        glPointSize(6.0f);
        glLineWidth(3.0f);
        glColor3f(0.5f, 0.5f, 0.0f);
        glBegin(GL_POINTS);
        glVertex3dv( &pE1[0]);
        glEnd();
        glColor3f(0.5f, 0.0f, 0.5f);
        glBegin(GL_LINES);
        glVertex3dv( &pE1[0]);
        glVertex3dv( &pE2[0]);
        glEnd();
        glLineWidth(1.0f);
        glPointSize(1.0f);
    }
    if (intersectionUI->m_bRayShadow->value()) {
        glPointSize(6.0f);
        glLineWidth(2.0f);
        glColor3f(0.1f, 0.1f, 0.0f);
        glBegin(GL_POINTS);
        glVertex3d( pE1[0], 0.0, pE1[2] );
        glEnd();
        glColor3f(0.0f, 0.0f, 0.0f);
        glEnable(GL_LINE_STIPPLE);
        glLineStipple(1, 0xF0F0);
        glBegin(GL_LINES);
        glVertex3d( pE1[0], 0.0, pE1[2] );
        glVertex3d( pE2[0], 0.0, pE2[2] );
        glVertex3d( pE1[0], 0.0, pE1[2] );
        glVertex3dv( &pE1[0]);
        glVertex3d( pE2[0], 0.0, pE2[2] );
        glVertex3dv( &pE2[0]);
        glEnd();
        glLineWidth(1.0f);
        glPointSize(1.0f);
        glDisable(GL_LINE_STIPPLE);
    }
    glEnable(GL_LIGHTING);

    glEnable( GL_BLEND );
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    const float colPlane[4] = {0.5, 0.5, 0.75, 0.5};
    const float colObj[4] = {0.5, 0.25, 0.25, 0.5};
    glColor4fv( colPlane );
    glMaterialfv(GL_FRONT, GL_DIFFUSE , colPlane);

    glBegin( GL_POLYGON );
    glVertex3f( -2.0, 0.0, -2.0 );
    glVertex3f(  2.0, 0.0, -2.0 );
    glVertex3f(  2.0, 0.0,  2.0 );
    glVertex3f( -2.0, 0.0,  2.0 );
    glEnd();

    glBegin( GL_POLYGON );
    glVertex3f( -2.0, 0.0001f, -2.0 );
    glVertex3f( -2.0, 0.0001f,  2.0 );
    glVertex3f(  2.0, 0.0001f,  2.0 );
    glVertex3f(  2.0, 0.0001f, -2.0 );
    glEnd();

    
    glColor4fv( colObj );
    glMaterialfv(GL_FRONT, GL_DIFFUSE , colObj);
    glMaterialfv(GL_FRONT, GL_SPECULAR, colObj);

    // ToDo: draw your shape here and perform the intersection
    // then call drawHits so you can see where the ray has hit the shape
    // the origin is in variable 'p' and direction in variable 'dir'
	shape->DrawTriangles();

    //Call HitRecord hr = intersect(pE1, dir);
	HitRecord *hr = shape->intersect(pE1, dir);
    drawHits(*hr);

    endDrawing();
}
Example #12
0
void CorrelationWidget::paintEvent( QPaintEvent * )
{
  Channel *active = gdata->getActiveChannel();

  AnalysisData *data = NULL;
  int chunk=0;
  double dh2 = double(height()-1) / 2.0;
  int j, x, y;
    
  beginDrawing(false);
    
  if(active) {
    
    active->lock();
    chunk = active->currentChunk();
    data = active->dataAtChunk(chunk);

    //int centerX = width() / 2;
    if(data) {
      double freq = data->getFundamentalFreq();
      double period = double(active->rate()) / freq;
      //double numPeriods = double(active->size()) / period;
      double scaleX = period * double(width()) / double(active->nsdfData.size()); //pixels per period
      
      //draw alternating background color indicating period
      if(gdata->view->backgroundShading() && period > 4.0 && period < double(active->nsdfData.size())) {
        int n = int(ceil(double(width()) / scaleX)); //number of colored patches
        p.setPen(Qt::NoPen);
        QColor color1 = colorBetween(gdata->backgroundColor(), gdata->shading1Color(), data->getCorrelation());
        QColor color2 = colorBetween(gdata->backgroundColor(), gdata->shading2Color(), data->getCorrelation());
        for(j = 0; j<n; j++) {
          x = toInt(scaleX*double(j));
          p.setBrush((j%2) ? color1 : color2);
          p.drawRect(x, 0, toInt(scaleX*double(j+1)) - toInt(scaleX*double(j)), height());
        }
        p.setPen(colorBetween(gdata->backgroundColor(), Qt::black, 0.3 * data->getCorrelation()));
        for(j = 0; j<n; j++) {
          x = toInt(scaleX*double(j));
          p.drawLine(x, 0, x, height());
        }
      } else {
        clearBackground();
      }
      QString numPeriodsText;
      numPeriodsText.sprintf("Period = %lf", period);
      p.setPen(Qt::black);
      p.drawText(5, height() - 8, numPeriodsText);
    } else {
      clearBackground();
    }
  } else {
    clearBackground();
  }

  //draw the horizontal center line
  p.setPen(QPen(colorBetween(colorGroup().background(), Qt::black, 0.3), 0));
  p.drawLine(0, toInt(dh2), width(), toInt(dh2));

  if(active) { 
    if(gdata->doingFreqAnalysis()) {
      int w = width() / 2; //only do every second pixel (for speed)
      //draw the waveform
      if(int(pointArray.size()) != w) pointArray.resize(w);
      if(lookup.size() != w) lookup.resize(w);

      NoteData *currentNote = active->getCurrentNote();
      Array1d<float> *input = &(active->nsdfData);
      if(currentNote) {
        if(aggregateMode == 1) input = &currentNote->nsdfAggregateData;
        else if(aggregateMode == 2) input = &currentNote->nsdfAggregateDataScaled;
      }
      //bresenham1d(*input, lookup);
      maxAbsDecimate1d(*input, lookup);
      for(int j=0; j<w; j++) {
        pointArray.setPoint(j, j*2, toInt(dh2 - lookup[j]*dh2));
      }

      p.setPen(QPen(active->color, 0));
      p.drawPolyline(pointArray);
    }
    if(data && (aggregateMode == 0)) {
      double ratio = double(width()) / double(active->nsdfData.size()); //pixels per index
      //float highest = active->nsdfData.at(data->highestCorrelationIndex);
      //float chosen = active->nsdfData.at(data->chosenCorrelationIndex);
      
      //draw a dot at all the period estimates
      p.setPen(Qt::blue);
      p.setBrush(Qt::blue);
      for(j=0; j<int(data->getPeriodEstimatesSize()); j++) {
        x = toInt(double(data->getPeriodEstimatesAt(j)) * ratio);
        y = toInt(dh2 - data->getPeriodEstimatesAmpAt(j) * dh2);
        p.drawEllipse(x-2, y-2, 5, 5);
      }
      
      if(data->getHighestCorrelationIndex() >= 0) {
        float highest = data->getPeriodEstimatesAmpAt(data->getHighestCorrelationIndex());
        //draw threshold line
        p.setPen(QPen(colorBetween(colorGroup().background(), Qt::black, 0.3), 0));
        y = toInt(dh2 - (highest * active->threshold()) * dh2);
        p.drawLine(0, y, width(), y);
      
        //draw a dot at the highest correlation period
        p.setPen(Qt::black);
        p.setBrush(Qt::black);
        //x = toInt(double(data->highestCorrelationIndex) * ratio);
        x = toInt(double(data->getPeriodEstimatesAt(data->getHighestCorrelationIndex())) * ratio);
        y = toInt(dh2 - highest * dh2);
        p.drawEllipse(x-2, y-2, 5, 5);
      }
      
      //draw a dot at the chosen correlation period
      if(data->getChosenCorrelationIndex() >= 0) {
        p.setPen(Qt::red);
        p.setBrush(Qt::red);
        //x = toInt(double(data->chosenCorrelationIndex) * ratio);
        //y = toInt(dh2 - chosen * dh2);
        x = toInt(double(data->getPeriodEstimatesAt(data->getChosenCorrelationIndex())) * ratio);
        y = toInt(dh2 - data->getPeriodEstimatesAmpAt(data->getChosenCorrelationIndex()) * dh2);
        p.drawEllipse(x-2, y-2, 5, 5);
      }

      //draw a line at the chosen correlation period
      if(data->getChosenCorrelationIndex() >= 0) {
        p.setPen(Qt::green);
        p.setBrush(Qt::green);
        //x = toInt(double(data->periodOctaveEstimate) * ratio);
        x = toInt(double(active->periodOctaveEstimate(chunk)) * ratio);
        p.drawLine(x, 0, x, height());
      }
    }
    
    active->unlock();
    
  }
  endDrawing();
}
Example #13
0
void VibratoTimeAxis::paintEvent( QPaintEvent * )
{
  beginDrawing(false);

  fillBackground(colorGroup().background());

  doUpdate();

  if (currentChunkToUse >= 0) {
    QFontMetrics fm = p.fontMetrics();
    QString s;
    p.setBrush(Qt::black);
    p.setFont(QFont("AnyStyle", 12));

    int polyLengthInPixels = toInt((endChunkToUse - startChunkToUse) * zoomFactorX);
    float pixelsPerSecond = polyLengthInPixels / noteLengthToUse;
    int notchesDivider = 2;
    double secondsPerNotch = 5;
    int calculationStep = 1;

    // Calculate which notches and labels to draw
    for (int pixelsPerSecondThreshold = 25; ;pixelsPerSecondThreshold *= 2) {
      if (pixelsPerSecond < pixelsPerSecondThreshold) {
        break;
      } else {
        switch (calculationStep) {
          case 1:
            notchesDivider = 5;
            secondsPerNotch /= 5;
            calculationStep = 2;
            break;
          case 2:
            notchesDivider = 2;
            secondsPerNotch = secondsPerNotch;
            calculationStep = 3;
            break;
          case 3:
            notchesDivider = 2;
            secondsPerNotch /= 2;
            calculationStep = 1;
            break;
        }
      }
    }

    // Draw the notches + labels
    for (int i = 0; i < (noteLengthToUse / secondsPerNotch); i++) {
      int x = toInt((((endChunkToUse - startChunkToUse) * zoomFactorX) / noteLengthToUse) * i * secondsPerNotch - windowOffsetToUse);
      if ((x >= 0) && (x < width())) {
        if (i % notchesDivider == 0) {  // Even: bigger notch + label
          p.drawLine(x, height()-6, x, height()-1);
          // The 1.000001 factors in the following statements prevent freaky rounding/floor errors...
          int minutes = intFloor(i*secondsPerNotch*1.000001) / 60;
          int seconds = intFloor(i*secondsPerNotch*1.000001) % 60;
          int thousandthseconds = intFloor(1000*i*secondsPerNotch*1.000001) % 1000;
          if (thousandthseconds == 0) {  // Label: m:ss
            s.sprintf("%1d:%02d", minutes, seconds);
          } else if (thousandthseconds % 100 == 0) {  // Label: m:ss.h
            s.sprintf("%1d:%02d.%01d", minutes, seconds, thousandthseconds / 100);
          } else if (thousandthseconds % 10 == 0) {  // Label: m:ss.hh
            s.sprintf("%1d:%02d.%02d", minutes, seconds, thousandthseconds / 10);
          } else {  // Label: m:ss.hhh
            s.sprintf("%1d:%02d.%03d", minutes, seconds, thousandthseconds);
          }
          p.drawText(x - fm.width(s)/2, 12, s);
          } else {  // Odd: smaller notch
          p.drawLine(x, height()-3, x, height()-1);
        }
      }
    }

    // Draw the horizontal line at the bottom of the axis
    p.drawLine(0, height()-1, width(), height()-1);
  }
  endDrawing();
}
Example #14
0
void HBlockWidget::paintEvent( QPaintEvent * )
{
  Channel *active = gdata->getActiveChannel();
  
  beginDrawing();
    
  if(active) {
    AnalysisData *theData = active->dataAtCurrentChunk();
    if(theData) {
  
      //get a copy of theData so we don't hold the mutex for too long
      active->lock();
      AnalysisData data = *theData;
      active->unlock();
  
      // We have harmonicFreq - the actual frequencies of the harmonies - and harmonicAmp, their amplitude
      //std::vector<float> harmonicFreq = active->lookup[frame].harmonicFreq;
      std::vector<float> harmonicFreq = data.harmonicFreq;
      // harmonicAmp values range between 0-1
      //std::vector<float> harmonicAmp = active->lookup[frame].harmonicAmp;
      std::vector<float> harmonicAmp = data.harmonicAmp;
  
      // Get the frame's fundamental frequency
      //float fund = active->lookup[frame].fundamentalFreq;
      float fund = data.fundamentalFreq;
  
      // Work out the bar height for each harmonic
      double barHeight = double(height()) / double(harmonicFreq.size());
      QColor fillColor = colorBetween(colorGroup().background(), active->color, data.volumeValue());
      QColor outlineColor = colorBetween(colorGroup().background(), Qt::black, data.volumeValue());
      p.setBrush(fillColor);
  
      int barStart = 0;
      float barWidth = 0;
      int diff = 0;
      /*
      * Each note has a fundamental frequency f, which comes from the lookup table.
      * The harmonic frequencies are defined as f, 2f, 3f, 4f, 5f...
      * harmonicFreq stores what the harmonics have been calculated to be.
      */
      for (uint i = 0; i < harmonicFreq.size(); i++) {
        p.setPen(outlineColor);
        p.setBrush(colorBetween(fillColor, Qt::black, data.harmonicNoise[i]));
        // Work out how many pixels wide the harmonic should be
        barWidth = (harmonicAmp.at(i)) * width();
        /* Work out how many pixels the harmonic should be offset from where it would be
        * if it were exactly (i+1)f   */
        //diff = toInt( (harmonicFreq.at(i) - (i+1) * fund) / fund * width() / 10.0 );
        diff = toInt( (harmonicFreq.at(i) - (i+1) * fund) / fund * barWidth );
        // Work out the starting position, and draw the bar
        barStart = toInt( ((width() / 2) + diff) - barWidth / 2);
	     int barBottom = height() - toInt(barHeight * i);
        p.drawRect(barStart, barBottom, toInt(barWidth), -toInt(barHeight));
        // Draw the centre line on the bar
        p.setPen(Qt::white);
        p.drawLine((width() / 2) + diff, barBottom, (width() / 2) + diff, barBottom - toInt(barHeight));
      }
      // Draw the exact line (f, 2f, 3f...)
      p.setPen(Qt::white);
      p.drawLine(width() / 2, 0, width() /2, height());
    }
  }
  endDrawing();
}