Esempio n. 1
0
void FunctionGraphView::drawRect(KDContext * ctx, KDRect rect) const {
  ctx->fillRect(rect, KDColorWhite);
  drawGrid(ctx, rect);
  drawAxes(ctx, rect, Axis::Horizontal);
  drawAxes(ctx, rect, Axis::Vertical);
  drawLabels(ctx, rect, Axis::Horizontal, true);
  drawLabels(ctx, rect, Axis::Vertical, true);
}
Esempio n. 2
0
void Game2D::paint(QPainter &p){

    drawBackground (p);

    for (std::size_t i=0; i<evec_.size(); i++) drawUnit (evec_[i], p);//evec_[i].draw (p);

    if (state_==2) ship_.setType(1);
    else ship_.setType(0);

    drawUnit (ship_, p, direction_);

    drawLabels (p);

    drawState (p);

    /*
    typedef QSharedPointer <Unit> spUnit;
    QVector < spUnit>  units;

    Ship ship;
    Enemy e;

    units.push_back((spUnit)new Ship());
    //units.push_back((spUnit)&e);

    for (int i=0; i<units.size(); i++) drawUnit (*units[i].data(), p);

    */
}
Esempio n. 3
0
void RadarObject::drawOnScope(float scopeAngle) {
	glColor3f(0, 1, 0);
	ObjectInformation i = lastInformation;

	float posAngle = getRadial().getAngle();

	glTranslatef(i.getX(), i.getY(), 0);
	glRotatef(i.getAngle().getGLAngle(), 0, 0, 1);
	float alpha;
	Angle sc(scopeAngle);
	Angle pos(posAngle);
	float diff = (sc - pos).getAngle();
	alpha = diff / 270;
	alpha = alpha > 1 ? 1 : alpha;
	if (diff <= 2)
		lastInformation = currentInformation;

	glColor4f(0, 0.9, 0, alpha);
	draw();
	glRotatef(-i.getAngle().getGLAngle(), 0, 0, 1);

	drawLabels();

	glTranslatef(-i.getX(), -i.getY(), 0);
}
Esempio n. 4
0
void caCircularGauge::paintEvent(QPaintEvent *)
{
    QPainter	painter(this);
    int size = qMin(height(), width());

    /* see http://doc.trolltech.com/4.4/coordsys.html#window-viewport-conversion for a analogous example */
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setViewport((int)((width()-size)*.5),(int)((height()-size)*.5),size,size);
    painter.setWindow(-50,-50,100,100);

    drawColorBar(&painter);

    if (isEnabled())
        drawNeedle(&painter);

    if (m_valueDisplayed)
        drawValue(&painter);

    if (!isEnabled())
    {
        QColor c = palette().color(QPalette::Background);
        c.setAlpha(200);
        painter.fillRect(painter.window(), c);
    }
    if (m_scaleEnabled)
    {
        drawScale(&painter);
        drawLabels(&painter);
    }
}
Esempio n. 5
0
std::vector<cv::Point2f> findLabelPositions(const cv::Mat3b& img, double threshold, bool visualize)
{
    std::vector<LabelContour> labels = findLabelContours(img, threshold, visualize);

    printf("Num labels: %lu\n", labels.size());
    fflush(stdout);

    if (visualize)
    {
        cv::Mat3b canvas = img * 0.25f;
        drawLabels(canvas, labels, cv::Scalar(255, 255, 255));
        cv::imshow("detected labels", canvas);
    }

    // Connect labels with each other in order to associate them.
    std::vector<std::vector<LabelContour>> grouped_labels;
    std::vector<std::vector<cv::Point2f>> spatial_indices;

    std::tie(grouped_labels, spatial_indices) = connectLabelContours(labels, visualize);

    Camera cam;
    try
    {
        cam = solveCamera(grouped_labels, spatial_indices, img.size());
    }
    catch (cv::Exception)
    {
        return {};
    }

    return projectCube(cam);
}
Esempio n. 6
0
void GraphDrawer::draw()
{
    startDrawing();
    drawEdges();
    drawHighlightEdges();
    drawNodes();
    drawLabels();
    clearChanged();
}
void QgsPointDisplacementRenderer::drawGroup( QPointF centerPoint, QgsRenderContext &context, const ClusteredGroup &group )
{

  //calculate max diagonal size from all symbols in group
  double diagonal = 0;

  for ( const GroupedFeature &feature : group )
  {
    if ( QgsMarkerSymbol *symbol = feature.symbol() )
    {
      diagonal = std::max( diagonal, M_SQRT2 * symbol->size( context ) );
    }
  }

  QgsSymbolRenderContext symbolContext( context, QgsUnitTypes::RenderMillimeters, 1.0, false );

  QList<QPointF> symbolPositions;
  QList<QPointF> labelPositions;
  double circleRadius = -1.0;
  double gridRadius = -1.0;
  int gridSize = -1;

  calculateSymbolAndLabelPositions( symbolContext, centerPoint, group.size(), diagonal, symbolPositions, labelPositions, circleRadius, gridRadius, gridSize );

  //only draw circle/grid if there's a pen present - otherwise skip drawing transparent grids
  if ( mCircleColor.isValid() && mCircleColor.alpha() > 0 )
  {
    //draw circle
    if ( circleRadius > 0 )
      drawCircle( circleRadius, symbolContext, centerPoint, group.size() );
    //draw grid
    else
      drawGrid( gridSize, symbolContext, symbolPositions, group.size() );
  }

  if ( group.size() > 1 )
  {
    //draw mid point
    QgsFeature firstFeature = group.at( 0 ).feature;
    if ( mCenterSymbol )
    {
      mCenterSymbol->renderPoint( centerPoint, &firstFeature, context, -1, false );
    }
    else
    {
      context.painter()->drawRect( QRectF( centerPoint.x() - symbolContext.outputLineWidth( 1 ), centerPoint.y() - symbolContext.outputLineWidth( 1 ), symbolContext.outputLineWidth( 2 ), symbolContext.outputLineWidth( 2 ) ) );
    }
  }

  //draw symbols on the circle
  drawSymbols( group, context, symbolPositions );
  //and also the labels
  if ( mLabelIndex >= 0 )
  {
    drawLabels( centerPoint, symbolContext, labelPositions, group );
  }
}
void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
{
  if ( !mScaleBar )
  {
    return;
  }
  double barTopPosition = QgsComposerUtils::fontAscentMM( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();
  double segmentHeight = mScaleBar->height() / 2;

  p->save();
  //antialiasing on
  p->setRenderHint( QPainter::Antialiasing, true );
  p->setPen( mScaleBar->pen() );

  QList<QPair<double, double> > segmentInfo;
  mScaleBar->segmentPositions( segmentInfo );

  bool useColor = true; //alternate brush color/white

  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
  {
    //draw top half
    if ( useColor )
    {
      p->setBrush( mScaleBar->brush() );
    }
    else //secondary color
    {
      p->setBrush( mScaleBar->brush2() );
    }

    QRectF segmentRectTop( segmentIt->first + xOffset, barTopPosition, segmentIt->second, segmentHeight );
    p->drawRect( segmentRectTop );

    //draw bottom half
    if ( useColor )
    {
      //secondary color
      p->setBrush( mScaleBar->brush2() );
    }
    else //primary color
    {
      p->setBrush( mScaleBar->brush() );
    }

    QRectF segmentRectBottom( segmentIt->first + xOffset, barTopPosition + segmentHeight, segmentIt->second, segmentHeight );
    p->drawRect( segmentRectBottom );
    useColor = !useColor;
  }

  p->restore();

  //draw labels using the default method
  drawLabels( p );
}
Esempio n. 9
0
void createCanvas(){
  canvas= new TCanvas("canvas", "TrackerMap",width,height);
  gPad->SetFillColor(38);
  gPad->Range(0,0,width,height);

  getColorScale();
  drawTkMap();
  drawLabels();
 
}
Esempio n. 10
0
void
PartitionLabelsView::paintEvent( QPaintEvent* event )
{
    QPainter painter( viewport() );
    painter.fillRect( rect(), palette().window() );
    painter.setRenderHint( QPainter::Antialiasing );

    QRect lRect = labelsRect();

    drawLabels( &painter, lRect, QModelIndex() );
}
Esempio n. 11
0
void QgsTicksScaleBarStyle::draw( QPainter *p, double xOffset ) const
{
  if ( !mScaleBar )
  {
    return;
  }
  double barTopPosition = QgsComposerUtils::fontAscentMM( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();
  double middlePosition = barTopPosition + mScaleBar->height() / 2.0;
  double bottomPosition = barTopPosition + mScaleBar->height();

  p->save();
  //antialiasing on
  p->setRenderHint( QPainter::Antialiasing, true );
  p->setPen( mScaleBar->pen() );

  QList<QPair<double, double> > segmentInfo;
  mScaleBar->segmentPositions( segmentInfo );

  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
  {
    p->drawLine( QLineF( segmentIt->first + xOffset, barTopPosition, segmentIt->first + xOffset, barTopPosition + mScaleBar->height() ) );
  }

  //draw last tick and horizontal line
  if ( !segmentInfo.isEmpty() )
  {
    double lastTickPositionX = segmentInfo.last().first + mScaleBar->segmentMillimeters() + xOffset;
    double verticalPos = 0.0;
    switch ( mTickPosition )
    {
      case TicksDown:
        verticalPos = barTopPosition;
        break;
      case TicksMiddle:
        verticalPos = middlePosition;
        break;
      case TicksUp:
        verticalPos = bottomPosition;
        break;
    }
    //horizontal line
    p->drawLine( QLineF( xOffset + segmentInfo.at( 0 ).first, verticalPos, lastTickPositionX, verticalPos ) );
    //last vertical line
    p->drawLine( QLineF( lastTickPositionX, barTopPosition, lastTickPositionX, barTopPosition + mScaleBar->height() ) );
  }

  p->restore();

  //draw labels using the default method
  drawLabels( p );
}
Esempio n. 12
0
void BoltzmannInfoWidget::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    QPen pen;
    pen.setColor(QColor(0xEE, 0xEE, 0xEE));
    pen.setWidth(3);
    painter.setPen(pen);
    painter.fillRect(event->rect(), QBrush(QColor(0x30, 0x30, 0x30)));
    drawCoords(&painter);
    drawLabels(&painter);
    drawChart(&painter);
    drawStatus(&painter);
}
Esempio n. 13
0
void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
  ctx->fillRect(rect, KDColorWhite);
  drawGrid(ctx, rect);
  drawAxes(ctx, rect, Axis::Horizontal);
  drawAxes(ctx, rect, Axis::Vertical);
  drawLabels(ctx, rect, Axis::Horizontal, true);
  drawLabels(ctx, rect, Axis::Vertical, true);
  for (int series = 0; series < Store::k_numberOfSeries; series++) {
    if (!m_store->seriesIsEmpty(series)) {
      KDColor color = Palette::DataColor[series];
      float regressionParameters[2] = {(float)m_store->slope(series), (float)m_store->yIntercept(series)};
      drawCurve(ctx, rect, [](float abscissa, void * model, void * context) {
          float * params = (float *)model;
          return params[0]*abscissa+params[1];
          },
          regressionParameters, nullptr, color);
      for (int index = 0; index < m_store->numberOfPairsOfSeries(series); index++) {
        drawDot(ctx, rect, m_store->get(series, 0, index), m_store->get(series, 1, index), color);
      }
      drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), color, true);
      drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), KDColorWhite);
    }
  }
}
Esempio n. 14
0
void IntegralViewer::setupCanvas(CartesianCanvas*& can, const std::string& label, double delay) {
  const float BORDER = (myStopX-myStartX)/10.0f;
  const float SPACING = BORDER;
  can = new CartesianCanvas(-1, -1, myWidth, myHeight, myStartX - BORDER, myStartY - BORDER,
                            myStopX + BORDER, myStopY + BORDER, label, delay);

  can->setBackgroundColor(ColorFloat(0.95f, 0.95f, 0.95f, 1.0f));

  can->start();

  can->drawRectangle(myStartX,myStartY,myStopX,myStopY,WHITE);        //Area we're drawing to
  can->drawPartialFunction(myF,myStartX,myStopX,0,ColorInt(0,0,255)); //Outline of function
  can->drawAxes(0, 0, SPACING, SPACING);                              //Axes marks
  drawLabels(can);
}
void QgsPointDisplacementRenderer::drawGroup( QPointF centerPoint, QgsRenderContext& context, const ClusteredGroup& group )
{

  //calculate max diagonal size from all symbols in group
  double diagonal = 0;

  Q_FOREACH ( const GroupedFeature& feature, group )
  {
    if ( QgsMarkerSymbol* symbol = feature.symbol )
    {
      diagonal = qMax( diagonal, context.convertToPainterUnits( M_SQRT2 * symbol->size(),
                       symbol->sizeUnit(), symbol->sizeMapUnitScale() ) );
    }
  }

  QgsSymbolRenderContext symbolContext( context, QgsUnitTypes::RenderMillimeters, 1.0, false );

  QList<QPointF> symbolPositions;
  QList<QPointF> labelPositions;
  double circleRadius = -1.0;
  calculateSymbolAndLabelPositions( symbolContext, centerPoint, group.size(), diagonal, symbolPositions, labelPositions, circleRadius );

  //draw circle
  if ( circleRadius > 0 )
    drawCircle( circleRadius, symbolContext, centerPoint, group.size() );

  if ( group.size() > 1 )
  {
    //draw mid point
    QgsFeature firstFeature = group.at( 0 ).feature;
    if ( mCenterSymbol )
    {
      mCenterSymbol->renderPoint( centerPoint, &firstFeature, context, -1, false );
    }
    else
    {
      context.painter()->drawRect( QRectF( centerPoint.x() - symbolContext.outputLineWidth( 1 ), centerPoint.y() - symbolContext.outputLineWidth( 1 ), symbolContext.outputLineWidth( 2 ), symbolContext.outputLineWidth( 2 ) ) );
    }
  }

  //draw symbols on the circle
  drawSymbols( group, context, symbolPositions );
  //and also the labels
  if ( mLabelIndex >= 0 )
  {
    drawLabels( centerPoint, symbolContext, labelPositions, group );
  }
}
Esempio n. 16
0
void PlotCartesianWidget::paintGL()
{
    if( !isShowing() || !isExposed())
        return;

    glcontext->makeCurrent(this);

    glf->glClearColor(1,1,1,1);
    glf->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glf->glDisable(GL_DEPTH_TEST);

    float currentFWidth = float(width()*devicePixelRatio());
    float currentFHeight = float(height()*devicePixelRatio());
    if(currentFWidth != fWidth || currentFHeight != fHeight)
    {
        fWidth = currentFWidth;
        fHeight = currentFHeight;
        mAspect = fWidth / fHeight;
        updateInputDataLineVAO();
        updateProjectionMatrix();
    }

    glf->glViewport(0, 0, fWidth, fHeight);
    glf->glEnable(GL_MULTISAMPLE);

    drawAxis();
    drawLabels();

    glf->glBindVertexArray(dataLineVAO);
    for( int i = 0; i < (int)brdfs.size(); i++ )
    {
        DGLShader* shader = updateShader( brdfs[i] );
        glf->glDrawArrays(GL_LINE_STRIP_ADJACENCY, 0,  dataLineNPoints);
        shader->disable();
    }
    glf->glBindVertexArray(0);

    glf->glDisable(GL_BLEND);
    glf->glEnable(GL_DEPTH_TEST);

    glcontext->swapBuffers(this);
}
Esempio n. 17
0
void caLinearGauge::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    int size, w, h;
    QFontMetrics fm(painter.font());

    h = fm.height()+2;
    w = fm.width(labels[longestLabelIndex])+2;

    if (m_orientation == Qt::Horizontal) {
        size = qMin((int)(width()*totalSize/100.0), height());
    } else {
        size = qMin((int)(height()*totalSize/100.0), width());
    }

    painter.setRenderHint(QPainter::Antialiasing);

    if (m_orientation == Qt::Horizontal) {
        painter.setViewport((int)((width()-size*100.0/totalSize)*.5),(int)((height()-size)*.5), (int)(size*100.0/totalSize), size);
        painter.setWindow((int)(-w*.5), 0, 100+w, totalSize+2); /* border */
    } else {
        painter.setViewport((int)((width()-size)*.5),(int)((height()-size*100.0/totalSize)*.5), size, (int)(size*100.0/totalSize));
        painter.setWindow(-2, (int)(-h*.5), totalSize+2, 100+h); /* border */
    }
    painter.setViewport(0,0, width(), height()); // A.Mezger I do not like above behaviour when resizing

    drawColorBar(&painter);
    if (m_scaleEnabled)
    {
        drawScale(&painter);
        drawLabels(&painter);
    }
    if (isEnabled() && (m_fillMode == ALL))
        drawMarker(&painter, true);

    if (!isEnabled())
    {
        QColor c = palette().color(QPalette::Background);
        c.setAlpha(200);
        painter.fillRect(painter.window(), c);
    }
}
Esempio n. 18
0
void phaseDiagram(){

  //set-up stuff
  gROOT->Macro("init.C");
  setStyle();  
 
  //draw stuff
  drawCanvas();
  drawTransition();   //also draws critical point
  drawAxis();
  drawLabels();       //draws labels and arrows for phases
  drawExperiments();  //draws where RCIC, LHC etc. lie on curve
  drawNormal();       //draws normal matter

  //save stuff
  if(iSave){
    cPhase->Update();
    cPhase->SaveAs("phaseDiagram5.eps");
  }
}
Esempio n. 19
0
Graph2D::Graph2D(const char _typeView, const char _typeSource)
{

    // For now there is no receiver for the event
    this->resizeReceiver = NULL;

    // Initialize the graph
    initGraph(_typeView, _typeSource);

    // Generate new elements
    createLabels();
    createHorizontalAxes();
    createVerticalAxes();
    createEmptyGrid();
    createEmptyAll();

    // Draw all elements
    drawLabels();
    drawGrid();

}
Esempio n. 20
0
void ShowScene2(int mode, int view_mode, int quad, GLint s_left, GLint s_down){

  if(rotation_type==EYE_CENTERED&&nskyboxinfo>0)draw_skybox();

  if(UpdateLIGHTS==1)updateLights(light_position0,light_position1);

  if(mode==DRAWSCENE){
    glPointSize((float)1.0);


    /* ++++++++++++++++++++++++ draw trees +++++++++++++++++++++++++ */

    if(ntreeinfo>0){
      CLIP_GEOMETRY;
      drawtrees();
      SNIFF_ERRORS("after drawtrees");
    }

/* ++++++++++++++++++++++++ draw particles +++++++++++++++++++++++++ */

    if(showsmoke==1){
      CLIP_VALS;
      drawpart_frame();
    }

/* ++++++++++++++++++++++++ draw evacuation +++++++++++++++++++++++++ */

    if(showevac==1){
      CLIP_VALS;
      drawevac_frame();
    }

/* ++++++++++++++++++++++++ draw targets +++++++++++++++++++++++++ */

    if(showtarget==1){
      CLIP_VALS;
      drawTargets();
    }

#ifdef pp_GEOMTEST
    if(show_geomtest==1){
      CLIP_GEOMETRY;
      draw_geomtestclip();
      draw_geomtestoutline();
    }
    if(show_cutcells==1)draw_geom_cutcells();
#endif

/* ++++++++++++++++++++++++ draw circular vents +++++++++++++++++++++++++ */

    if(ncvents>0&&visCircularVents!=VENT_HIDE){
      CLIP_GEOMETRY;
      DrawCircVents(visCircularVents);
    }

/* ++++++++++++++++++++++++ draw sensors/sprinklers/heat detectors +++++++++++++++++++++++++ */

    CLIP_GEOMETRY;
    draw_devices();
#ifdef pp_PILOT
    draw_pilot();
#endif    
    SNIFF_ERRORS("after draw_devices");

    if(visaxislabels==1){
      UNCLIP;
      outputAxisLabels();
      SNIFF_ERRORS("after outputAxisLables");
    }


 /* ++++++++++++++++++++++++ draw user ticks +++++++++++++++++++++++++ */

    if(visUSERticks==1){
      antialias(ON);
      UNCLIP;
      draw_user_ticks();
      antialias(OFF);
      SNIFF_ERRORS("after drawticks");
    }

 /* ++++++++++++++++++++++++ draw ticks +++++++++++++++++++++++++ */

    if(visFDSticks==1&&ntickinfo>0){
      UNCLIP;
      drawticks();
      SNIFF_ERRORS("after drawticks");
    }

    /* ++++++++++++++++++++++++ draw ticks +++++++++++++++++++++++++ */

    if(showgravity==1){
      UNCLIP;
      drawaxis();
      SNIFF_ERRORS("after drawaxis");
    }

    /* draw the box framing the simulation (corners at (0,0,0) (xbar,ybar,zbar) */


/* ++++++++++++++++++++++++ draw simulation frame (corners at (0,0,0) and (xbar,ybar,zbar) +++++++++++++++++++++++++ */

    if(isZoneFireModel==0&&visFrame==1&&highlight_flag==2){
      CLIP_GEOMETRY;
      drawoutlines();
      SNIFF_ERRORS("after drawoutlines");
    }

    if(show_rotation_center==1){
      unsigned char pcolor[4];

      CLIP_GEOMETRY;
      glPushMatrix();
      glTranslatef(camera_current->xcen,camera_current->ycen,camera_current->zcen);
      pcolor[0]=255*foregroundcolor[0];
      pcolor[1]=255*foregroundcolor[1];
      pcolor[2]=255*foregroundcolor[2];
      drawsphere(0.03,pcolor);
      glPopMatrix();
    }


/* ++++++++++++++++++++++++ draw mesh +++++++++++++++++++++++++ */

    if(setPDIM==1){
      if(visGrid!=noGridnoProbe){
        int igrid;
        mesh *meshi;

        UNCLIP;
        for(igrid=0;igrid<nmeshes;igrid++){
          meshi=meshinfo+igrid;
          drawgrid(meshi);
          SNIFF_ERRORS("drawgrid");
        }
      }
    }
  } /* end of if(mode==DRAWSCENE) code segment */


/* ++++++++++++++++++++++++ draw selected devices +++++++++++++++++++++++++ */

  if(mode==SELECTOBJECT){
    if(select_device==1){
      CLIP_GEOMETRY;
      draw_devices();
      SNIFF_ERRORS("after drawselect_devices");
      return;
    }
  }

/* ++++++++++++++++++++++++ draw selected avatars +++++++++++++++++++++++++ */

  if(mode==SELECTOBJECT){
    if(select_avatar==1){
      CLIP_GEOMETRY;
      drawselect_avatars();
      SNIFF_ERRORS("after drawselect_avatars");
      return;
    }
  }

/* ++++++++++++++++++++++++ draw selected tours +++++++++++++++++++++++++ */

  if(mode==SELECTOBJECT){
    if(edittour==1&&ntours>0){
      CLIP_GEOMETRY;
      drawselect_tours();
      SNIFF_ERRORS("after drawselect_tours");
      return;
    }
  }


/* ++++++++++++++++++++++++ draw tours +++++++++++++++++++++++++ */

  if(showtours==1){
    CLIP_GEOMETRY;
    drawtours();
    SNIFF_ERRORS("after drawtours");
  }

  /* ++++++++++++++++++++++++ draw stereo parallax indicator +++++++++++++++++++++++++ */
  
  if(show_parallax==1){
    UNCLIP;
    antialias(ON);
    glLineWidth(linewidth);
    glBegin(GL_LINES);
    glColor3fv(foregroundcolor);
    glVertex3f(0.75,0.0,0.25);
    glVertex3f(0.75,1.0,0.25);
    glEnd();
    antialias(OFF);
  }

  /* ++++++++++++++++++++++++ draw blockages +++++++++++++++++++++++++ */

  CLIP_GEOMETRY;
  drawBlockages(mode,DRAW_OPAQUE);
  SNIFF_ERRORS("drawBlockages");

  /* ++++++++++++++++++++++++ draw triangles +++++++++++++++++++++++++ */
  
  if(ngeominfoptrs>0){
    CLIP_GEOMETRY;
    draw_geom(DRAW_OPAQUE,GEOM_STATIC);
    draw_geom(DRAW_OPAQUE,GEOM_DYNAMIC);
  }

/* ++++++++++++++++++++++++ draw shooter points +++++++++++++++++++++++++ */

  if(showshooter!=0&&shooter_active==1){
    CLIP_VALS;
    draw_shooter();
  }

/* ++++++++++++++++++++++++ draw terrain +++++++++++++++++++++++++ */

  if(visTerrainType!=TERRAIN_HIDDEN&&nterraininfo>0){
    int i;
    
    //shaded 17 0
    //stepped 18 1
    //line    19 2
    //texture 20 3
    //hidden 20 4

    CLIP_GEOMETRY;
    for(i=0;i<nterraininfo;i++){
      terraindata *terri;
      int only_geom;

      terri = terraininfo + i;
      if(terri->loaded==1){
        only_geom=0;
      }
      else{
        only_geom=1;
      }
      switch(visTerrainType){
        case TERRAIN_3D:
          drawterrain(terri,only_geom);
          break;
        case TERRAIN_2D_STEPPED:
          if(cullfaces==1)glDisable(GL_CULL_FACE);
          glPushMatrix();
          glScalef(SCALE2SMV(1.0),SCALE2SMV(1.0),SCALE2SMV(1.0));
          glTranslatef(-xbar0,-ybar0,-zbar0);
          DrawContours(&meshinfo[i].terrain_contour);
          glPopMatrix();
          if(cullfaces==1)glEnable(GL_CULL_FACE);
          break;
        case TERRAIN_2D_LINE:
          glPushMatrix();
          glScalef(SCALE2SMV(1.0),SCALE2SMV(1.0),SCALE2SMV(1.0));
          glTranslatef(-xbar0,-ybar0,-zbar0);
          DrawLineContours(&meshinfo[i].terrain_contour,1.0);
          glPopMatrix();
          break;
        case TERRAIN_3D_MAP:
          if(terrain_texture!=NULL&&terrain_texture->loaded==1){
            drawterrain_texture(terri,only_geom);
          }
          else{
            drawterrain(terri,only_geom);
          }
          break;
        default:
          ASSERT(FFALSE);
          break;
      }
    }
  }

/* ++++++++++++++++++++++++ draw slice files +++++++++++++++++++++++++ */

  if(show_gslice_triangles==1||show_gslice_normal==1||show_gslice_normal_keyboard==1||show_gslice_triangulation==1){
    CLIP_VALS;
    drawgslice_outline();
  }
  if((show_slices_and_vectors==1&&showvslice==1)||(showslice==1&&use_transparency_data==0)){
    CLIP_VALS;
    drawslice_frame();
  } 

  /* ++++++++++++++++++++++++ draw boundary files +++++++++++++++++++++++++ */

  if(showpatch==1){
    CLIP_VALS;
    drawpatch_frame();
  }

/* ++++++++++++++++++++++++ draw labels +++++++++++++++++++++++++ */

  if(visLabels==1){
    CLIP_GEOMETRY;
    drawLabels();
  }

/* ++++++++++++++++++++++++ draw animated isosurfaces +++++++++++++++++++++++++ */

    //if(isoinfo!=NULL)drawspherepoints(sphereinfo);
  if(showiso==1){
    CLIP_VALS;
    drawiso(DRAW_OPAQUE);
  }

/* ++++++++++++++++++++++++ draw zone fire modeling info +++++++++++++++++++++++++ */

  if(nrooms>0){
    CLIP_GEOMETRY;
    drawroomgeom();
    SNIFF_ERRORS("after drawroomgeom");
  }
  if(nrooms>0){
    if(showzone==1){
      CLIP_VALS;
      drawfiredata();
      SNIFF_ERRORS("after drawroomdata");
      if(ReadZoneFile==1&&nzvents>0){
        drawventdata();
        SNIFF_ERRORS("after drawventdata");
      }
    }
  }


//**********************************************************************************
//**********************************************************************************
//**********************************************************************************
//    nothing transparent should be drawn before this portion of the code
//    (ie draw all opaque objects first then draw transparent objects
//**********************************************************************************
//**********************************************************************************
//**********************************************************************************

  /* ++++++++++++++++++++++++ draw triangles +++++++++++++++++++++++++ */
  
  if(ngeominfoptrs>0){
    CLIP_GEOMETRY;
    draw_geom(DRAW_TRANSPARENT,GEOM_STATIC);
    draw_geom(DRAW_TRANSPARENT,GEOM_DYNAMIC);
  }

  if(showiso==1){
    CLIP_VALS;
    drawiso(DRAW_TRANSPARENT);
  }

/* ++++++++++++++++++++++++ draw transparent faces +++++++++++++++++++++++++ */

  CLIP_GEOMETRY;
  draw_transparent_faces();

/* ++++++++++++++++++++++++ draw 3D smoke +++++++++++++++++++++++++ */

  if(show3dsmoke==1||showvolrender==1){
    CLIP_VALS;
    drawsmoke_frame();
  }

  if(active_smokesensors==1&&show_smokesensors!=0){
    CLIP_VALS;
    getsmokesensors();
    draw_devices_val();
  }

/* ++++++++++++++++++++++++ draw zone fire modeling info +++++++++++++++++++++++++ */

  if(nrooms>0&&showzone==1){
    CLIP_VALS;
    drawroomdata();
    SNIFF_ERRORS("after drawroomdata");
  }

/* ++++++++++++++++++++++++ draw slice files +++++++++++++++++++++++++ */

  if((show_slices_and_vectors==1&&showvslice==1)||(showslice==1&&use_transparency_data==1)){
    CLIP_VALS;
    drawslice_frame();
    SNIFF_ERRORS("after drawslice_frame");
  } 

/* ++++++++++++++++++++++++ draw transparent blockages +++++++++++++++++++++++++ */

//  draw_demo(20,20);
//  draw_demo2(1);
  CLIP_GEOMETRY;
  drawBlockages(mode,DRAW_TRANSPARENT);
  SNIFF_ERRORS("after drawBlokcages");

/* ++++++++++++++++++++++++ draw vector slice files +++++++++++++++++++++++++ */

  if(showvslice==1){
    CLIP_VALS;
    drawvslice_frame();
  }
  SNIFF_ERRORS("after drawvslice");

/* ++++++++++++++++++++++++ draw plot3d files +++++++++++++++++++++++++ */

  if(showplot3d==1){
    CLIP_VALS;
    drawplot3d_frame();
  }
  SNIFF_ERRORS("after drawplot3d");
}
void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, QgsRenderContext& context )
{
  const QgsFeature& feature = group.begin().value().first;
  bool selected = mSelectedFeatures.contains( feature.id() ); // maybe we should highlight individual features instead of the whole group?

  QPointF pt;
  _getPoint( pt, context, feature.constGeometry()->asWkb() );

  //get list of labels and symbols
  QStringList labelAttributeList;
  QList<QgsMarkerSymbolV2*> symbolList;

  for ( DisplacementGroup::const_iterator attIt = group.constBegin(); attIt != group.constEnd(); ++attIt )
  {
    labelAttributeList << ( mDrawLabels ? getLabel( attIt.value().first ) : QString() );
    symbolList << dynamic_cast<QgsMarkerSymbolV2*>( attIt.value().second );
  }

  //draw symbol
  double diagonal = 0;
  double currentWidthFactor; //scale symbol size to map unit and output resolution

  QList<QgsMarkerSymbolV2*>::const_iterator it = symbolList.constBegin();
  for ( ; it != symbolList.constEnd(); ++it )
  {
    if ( *it )
    {
      currentWidthFactor = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context, ( *it )->outputUnit(), ( *it )->mapUnitScale() );
      double currentDiagonal = sqrt( 2 * (( *it )->size() * ( *it )->size() ) ) * currentWidthFactor;
      if ( currentDiagonal > diagonal )
      {
        diagonal = currentDiagonal;
      }
    }
  }


  QgsSymbolV2RenderContext symbolContext( context, QgsSymbolV2::MM, 1.0, selected );
  double circleAdditionPainterUnits = symbolContext.outputLineWidth( mCircleRadiusAddition );
  double radius = qMax(( diagonal / 2 ), labelAttributeList.size() * diagonal / 2 / M_PI ) + circleAdditionPainterUnits;

  //draw Circle
  drawCircle( radius, symbolContext, pt, symbolList.size() );

  QList<QPointF> symbolPositions;
  QList<QPointF> labelPositions;
  calculateSymbolAndLabelPositions( pt, labelAttributeList.size(), radius, diagonal, symbolPositions, labelPositions );

  //draw mid point
  if ( labelAttributeList.size() > 1 )
  {
    if ( mCenterSymbol )
    {
      mCenterSymbol->renderPoint( pt, &feature, context, -1, selected );
    }
    else
    {
      context.painter()->drawRect( QRectF( pt.x() - symbolContext.outputLineWidth( 1 ), pt.y() - symbolContext.outputLineWidth( 1 ), symbolContext.outputLineWidth( 2 ), symbolContext.outputLineWidth( 2 ) ) );
    }
  }

  //draw symbols on the circle
  drawSymbols( feature, context, symbolList, symbolPositions, selected );
  //and also the labels
  drawLabels( pt, symbolContext, labelPositions, labelAttributeList );
}
Esempio n. 22
0
bool Graph2D::event(QEvent* event)
{

    if (event->type() == QEvent::User)
    {

        // +-----------------------------------------------+
        // | One frame of sources is added                 |
        // +-----------------------------------------------+

        UpdateGraphAddSampleEvent *updateGraphAddSampleEvent = dynamic_cast<UpdateGraphAddSampleEvent*>(event);

        if (updateGraphAddSampleEvent != NULL)
        {

            // Shift the grid
            shiftGridByOneFrame();

            // Draw new frame
            drawSources(updateGraphAddSampleEvent->getAllSources());

            // Redraw the modified grid on the complete pixmap
            drawGrid();

            // Display
            this->update();

        }

        // +-----------------------------------------------+
        // | The graph is resized                          |
        // +-----------------------------------------------+

        UpdateGraphResizeEvent *updateGraphResizeEvent = dynamic_cast<UpdateGraphResizeEvent*>(event);

        if (updateGraphResizeEvent != NULL)
        {

            this->gridWidth = updateGraphResizeEvent->getWidth() - this->labelWidth - this->hspacerleft - this->hspacercenter - this->hspacerright;

            // The grid must be at least 1 pixel wide
            if (this->gridWidth < 1)
            {
                this->gridWidth = 1;
            }

            this->gridHeight = updateGraphResizeEvent->getHeight() - this->vspacertop - this->vspacerbottom;

            // The grid must be at least 1 pixel high
            if (this->gridHeight < 1)
            {
                this->gridHeight = 1;
            }

            // Update scaling
            this->timePerFrame = ((float) ParametersManager::HOPSIZE) / ((float) ParametersManager::SAMPLINGRATE);
            this->timePerPixel = (this->xView + this->xAfter) / ( this->gridWidth );
            this->pixelPerFrame = this->timePerFrame / this->timePerPixel;

            // Generate new elements since dimensions have changed
            createLabels();
            createHorizontalAxes();
            createVerticalAxes();
            createEmptyGrid();
            createEmptyAll();

            // Draw all elements
            drawLabels();
            drawAllSources(updateGraphResizeEvent->getSourcesAllFrames());
            drawGrid();

            // Display
            this->update();

        }

        // +-----------------------------------------------+
        // | Update parameters                             |
        // +-----------------------------------------------+

        UpdateParametersEvent *updateParametersEvent = dynamic_cast<UpdateParametersEvent*>(event);

        if (updateParametersEvent != NULL)
        {

            loadParameters(updateParametersEvent->getConfigurationVector());

        }

        // +-----------------------------------------------+
        // | The graph needs to be refreshed               |
        // +-----------------------------------------------+

        UpdateGraphRefreshEvent *updateGraphRefreshEvent = dynamic_cast<UpdateGraphRefreshEvent*>(event);

        if (updateGraphRefreshEvent != NULL)
        {

            // Generate new elements since parameters have changed
            createLabels();
            createHorizontalAxes();
            createVerticalAxes();
            createEmptyGrid();
            createEmptyAll();

            // Draw all elements
            drawLabels();
            drawGrid();

            // Draw all elements
            drawLabels();
            drawAllSources(updateGraphRefreshEvent->getSourcesAllFrames());
            drawGrid();

            // Display
            this->update();

        }

        return true;

    }

    return QWidget::event(event);

}
Esempio n. 23
0
void analyzeVideo(const std::string& folder, const Camera& calibrated_camera, float label_width)
{
    // Start with a single hypotheses of the cube.
    std::vector<ProbabalisticCube> cube_hypotheses;
    cube_hypotheses.push_back(ProbabalisticCube());
    for (int frame_i = 0;;)
    {
        printf("Frame %i\n", frame_i);

        char buf[1024];
        sprintf(buf, "%s/frame%05d.png", folder.c_str(), frame_i);
        cv::Mat3b img = cv::imread(buf, cv::IMREAD_COLOR);
        if (img.empty())
        {
            break;
        }

        const size_t num_hypotheses_before = cube_hypotheses.size();
        printf("Num hypotheses before: %lu\n", num_hypotheses_before);

        cube_hypotheses = predict(cube_hypotheses);
        const size_t num_hypotheses_after = cube_hypotheses.size();
        printf("Num hypotheses after:  %lu\n", num_hypotheses_after);
        printf("Brancing factor:  %f\n", double(num_hypotheses_after) / num_hypotheses_before);

        const size_t max_hypotheses = 216;
        if (num_hypotheses_after > max_hypotheses)
        {
            const size_t pruned_num = num_hypotheses_after - max_hypotheses;
            const double removed_percentage = pruned_num * 100.0 / num_hypotheses_after;
            printf("Pruning to %lu hypotheses, removing %lu (%.1f%%) hypotheses.\n",
                max_hypotheses, pruned_num, removed_percentage);
        }
        prune(cube_hypotheses, max_hypotheses);

        printf("Most likely cubes:\n");
        for (int i = 0; i < cube_hypotheses.size() && i < 5; ++i)
        {
            const ProbabalisticCube& cube = cube_hypotheses[i];
            const std::string permutation = cube.cube_permutation.to_String();
            const double likelihood_percent = exp(cube.log_likelihood) * 100.0;
            printf("%d: %s %3.5f%%\n", i, permutation.c_str(), likelihood_percent);
        }

        std::vector<LabelContour> labels = findLabelContours(img, 12, true);
        std::vector<std::vector<cv::Point2f>> detected_corners = findLabelCorners(labels);

        std::vector<Camera> all_camera_candidates;
        for (const auto& corners : detected_corners)
        {
            std::vector<Camera> cameras = predictCameraPosesForLabel(calibrated_camera, corners, label_width);
            all_camera_candidates.insert(all_camera_candidates.end(), cameras.begin(), cameras.end());
        }

        std::vector<double> camera_scores;
        camera_scores.reserve(all_camera_candidates.size());
        {
            cv::Mat1f accumulation(img.size(), 0.f);
            for (const auto& cam : all_camera_candidates)
            {
                cv::Mat1f contribution(img.size(), 0.f);
                std::vector<cv::Point2f> predicted_corners = projectCubeCorners(cam, label_width);
                double score = scorePredictedCorners(predicted_corners, detected_corners);
                camera_scores.push_back(score);

                for (int i = 0; i < predicted_corners.size(); i += 4)
                {
                    std::vector<cv::Point> corners = {
                        predicted_corners[i + 0],
                        predicted_corners[i + 1],
                        predicted_corners[i + 2],
                        predicted_corners[i + 3],
                    };
                    cv::polylines(contribution, corners, true, cv::Scalar(score * score));
                }
                accumulation += contribution;
            }
            double minval;
            double maxval;
            cv::minMaxLoc(accumulation, &minval, &maxval);
            cv::imshow("accumulation", accumulation / maxval);
        }
        if (!camera_scores.empty())
        {
            std::vector<double> sorted_camera_scores = camera_scores;
            std::sort(sorted_camera_scores.begin(), sorted_camera_scores.end());
            std::reverse(sorted_camera_scores.begin(), sorted_camera_scores.end());
            printf("Min score: %f max score: %f\n", sorted_camera_scores.back(), sorted_camera_scores.front());

            for (int i = 0; i < sorted_camera_scores.size() && i < 5; ++i)
            {
                double score = sorted_camera_scores[i];
                printf("#%d score: %f\n", i + 1, score);
            }
        }

        if (!all_camera_candidates.empty())
        {
            const size_t index = std::distance(camera_scores.begin(),
                std::max_element(camera_scores.begin(), camera_scores.end()));
            printf("detected_corners size: %lu index: %lu\n", detected_corners.size(), index);

            const Camera& cam = all_camera_candidates[index];
            std::vector<cv::Point2f> predicted_corners = projectCubeCorners(cam, label_width);

            cv::Mat3b canvas = img * 0.25f;
            for (int i = 0; i < predicted_corners.size(); i += 4)
            {
                std::vector<cv::Point> corners = {
                    predicted_corners[i + 0],
                    predicted_corners[i + 1],
                    predicted_corners[i + 2],
                    predicted_corners[i + 3],
                };
                cv::polylines(canvas, corners, true, cv::Scalar(0, 0, 255));
            }

            {
                std::vector<cv::Point> corners = {
                    detected_corners[index / 9][0],
                    detected_corners[index / 9][1],
                    detected_corners[index / 9][2],
                    detected_corners[index / 9][3],
                };
                cv::polylines(canvas, corners, true, cv::Scalar(255, 0, 255));
            }

            cv::imshow("predicted labels", canvas);
        }

        {
            cv::Mat3b canvas = img * 0.25f;
            drawLabels(canvas, labels, cv::Scalar(255, 255, 255));

            for (const auto& corners : detected_corners)
            {
                cv::polylines(canvas, cast<cv::Point>(corners), true, cv::Scalar(0, 0, 255));
                for (size_t i = 0; i < corners.size(); ++i)
                {
                    char text[12];
                    sprintf(text, "%lu", i);
                    cv::putText(canvas, text, corners[i],
                        cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(0, 0, 255));
                }
            }

            cv::imshow("detected labels", canvas);
        }

        if (int key = cv::waitKey(0) & 255)
        {
            if (key == 27)
            {
                break; // stop by pressing ESC
            }
            if (key == 32) // space
            {
                ++frame_i;
            }
            if (key == 83) // right arrow
            {
                ++frame_i;
            }
            if (key == 82) // up arrow
            {

            }
            if (key == 81) // left arrow
            {
                --frame_i;
            }
            if (key == 84) // down arrow
            {

            }
            if (key != 255)
            {
                printf("Key: %d\n", key);
                fflush(stdout);
            }
        }
    }
}
void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, QgsRenderContext& context )
{
  const QgsFeature& feature = group.begin().value().first;
  bool selected = mSelectedFeatures.contains( feature.id() ); // maybe we should highlight individual features instead of the whole group?



  //get list of labels and symbols
  QStringList labelAttributeList;
  QList<QgsMarkerSymbolV2*> symbolList;

  QgsMultiPointV2* groupMultiPoint = new QgsMultiPointV2();
  for ( DisplacementGroup::const_iterator attIt = group.constBegin(); attIt != group.constEnd(); ++attIt )
  {
    labelAttributeList << ( mDrawLabels ? getLabel( attIt.value().first ) : QString() );
    symbolList << dynamic_cast<QgsMarkerSymbolV2*>( attIt.value().second );
    groupMultiPoint->addGeometry( attIt.value().first.constGeometry()->geometry()->clone() );
  }

  //calculate centroid of all points, this will be center of group
  QgsGeometry groupGeom( groupMultiPoint );
  QgsGeometry* centroid = groupGeom.centroid();
  QPointF pt;
  _getPoint( pt, context, centroid->asWkb() );
  delete centroid;

  //calculate max diagonal size from all symbols in group
  double diagonal = 0;
  Q_FOREACH ( QgsMarkerSymbolV2* symbol, symbolList )
  {
    if ( symbol )
    {
      diagonal = qMax( diagonal, QgsSymbolLayerV2Utils::convertToPainterUnits( context,
                       M_SQRT2 * symbol->size(),
                       symbol->outputUnit(), symbol->mapUnitScale() ) );
    }
  }

  QgsSymbolV2RenderContext symbolContext( context, QgsSymbolV2::MM, 1.0, selected );

  QList<QPointF> symbolPositions;
  QList<QPointF> labelPositions;
  double circleRadius = -1.0;
  calculateSymbolAndLabelPositions( symbolContext, pt, symbolList.size(), diagonal, symbolPositions, labelPositions, circleRadius );

  //draw Circle
  if ( circleRadius > 0 )
    drawCircle( circleRadius, symbolContext, pt, symbolList.size() );

  //draw mid point
  if ( labelAttributeList.size() > 1 )
  {
    if ( mCenterSymbol )
    {
      mCenterSymbol->renderPoint( pt, &feature, context, -1, selected );
    }
    else
    {
      context.painter()->drawRect( QRectF( pt.x() - symbolContext.outputLineWidth( 1 ), pt.y() - symbolContext.outputLineWidth( 1 ), symbolContext.outputLineWidth( 2 ), symbolContext.outputLineWidth( 2 ) ) );
    }
  }

  //draw symbols on the circle
  drawSymbols( feature, context, symbolList, symbolPositions, selected );
  //and also the labels
  drawLabels( pt, symbolContext, labelPositions, labelAttributeList );
}
bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
{
  Q_UNUSED( drawVertexMarker );
  //point position in screen coords
  QgsGeometry* geom = feature.geometry();
  QGis::WkbType geomType = geom->wkbType();
  if ( geomType != QGis::WKBPoint && geomType != QGis::WKBPoint25D )
  {
    //can only render point type
    return false;
  }
  QPointF pt;
  _getPoint( pt, context, geom->asWkb() );


  //get list of labels and symbols
  QStringList labelAttributeList;
  QList<QgsMarkerSymbolV2*> symbolList;

  if ( mDisplacementIds.contains( feature.id() ) )
  {
    //create the symbol for the whole display group if the id is the first entry in a display group
    QList<QMap<QgsFeatureId, QgsFeature> >::iterator it = mDisplacementGroups.begin();
    for ( ; it != mDisplacementGroups.end(); ++it )
    {
      //create the symbol for the whole display group if the id is the first entry in a display group
      if ( feature.id() == it->begin().key() )
      {
        QMap<QgsFeatureId, QgsFeature>::iterator attIt = it->begin();
        for ( ; attIt != it->end(); ++attIt )
        {
          if ( mDrawLabels )
          {
            labelAttributeList << getLabel( attIt.value() );
          }
          else
          {
            labelAttributeList << QString();
          }
          symbolList << dynamic_cast<QgsMarkerSymbolV2*>( firstSymbolForFeature( mRenderer, attIt.value() ) );
        }
      }
    }
  }
  else //only one feature
  {
    symbolList << dynamic_cast<QgsMarkerSymbolV2*>( firstSymbolForFeature( mRenderer, feature ) );
    if ( mDrawLabels )
    {
      labelAttributeList << getLabel( feature );
    }
    else
    {
      labelAttributeList << QString();
    }
  }

  if ( symbolList.isEmpty() && labelAttributeList.isEmpty() )
  {
    return true; //display all point symbols for one posi
  }


  //draw symbol
  double diagonal = 0;
  double currentWidthFactor; //scale symbol size to map unit and output resolution

  QList<QgsMarkerSymbolV2*>::const_iterator it = symbolList.constBegin();
  for ( ; it != symbolList.constEnd(); ++it )
  {
    if ( *it )
    {
      currentWidthFactor = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context, ( *it )->outputUnit() );
      double currentDiagonal = sqrt( 2 * (( *it )->size() * ( *it )->size() ) ) * currentWidthFactor;
      if ( currentDiagonal > diagonal )
      {
        diagonal = currentDiagonal;
      }
    }
  }


  QgsSymbolV2RenderContext symbolContext( context, QgsSymbolV2::MM, 1.0, selected );
  double circleAdditionPainterUnits = symbolContext.outputLineWidth( mCircleRadiusAddition );
  double radius = qMax(( diagonal / 2 ), labelAttributeList.size() * diagonal / 2 / M_PI ) + circleAdditionPainterUnits;

  //draw Circle
  drawCircle( radius, symbolContext, pt, symbolList.size() );

  QList<QPointF> symbolPositions;
  QList<QPointF> labelPositions;
  calculateSymbolAndLabelPositions( pt, labelAttributeList.size(), radius, diagonal, symbolPositions, labelPositions );

  //draw mid point
  if ( labelAttributeList.size() > 1 )
  {
    if ( mCenterSymbol )
    {
      mCenterSymbol->renderPoint( pt, &feature, context, layer, selected );
    }
    else
    {
      context.painter()->drawRect( QRectF( pt.x() - symbolContext.outputLineWidth( 1 ), pt.y() - symbolContext.outputLineWidth( 1 ), symbolContext.outputLineWidth( 2 ), symbolContext.outputLineWidth( 2 ) ) );
    }
  }

  //draw symbols on the circle
  drawSymbols( feature, context, symbolList, symbolPositions, selected );
  //and also the labels
  drawLabels( pt, symbolContext, labelPositions, labelAttributeList );
  return true;
}
Esempio n. 26
0
void playLoop(IplImage* frameBuffer[], int frameCount)
{
    Blob* pBlobs = NULL;
    int pBlobCount = 0;

    CvMemStorage* storage = cvCreateMemStorage(0);

    /////////////////////////////////////////// 
    // Etape 1: construction du modele de fond
    MedianModel medianModel;

    // Apprentissage du modele
    learnMedianModel(&medianModel, "../View_008", "%s/frame_%04d.jpg", frameCount, 0.95);
    
    char filename[255];
    int i, pb, b;
    IplImage* frame = NULL, *segFrame = NULL;
    for(i = 0; i < frameCount; i++)
    {
        frame = frameBuffer[i];
        
        ////////////////////////////////////////////
        // Etape 2: segmentation utilisant un modele
         
        segFrame = segmentMedianStdDev(frame, 2.0, &medianModel);
        
        opening(segFrame, segFrame, 3);
        closing(segFrame, segFrame, 3);
        

        ///////////////////////////////////////////////////////////
        // Etape 3: extraction des blobs et de leur caracteristiques
        
        Blob* blobs;
        DistMetrics m;

        // Extraction des blobs
        int blobCount = extractBlobs(segFrame, frame, &blobs, storage);
    
        if(pBlobs != NULL)
        {
            // Matrice des combinaisons de recouvrements spatiaux
            m.mSpatial = cvCreateMat(blobCount, pBlobCount, CV_32FC1);

            // Matrices des differences d'histogramme
            m.mHist5 = cvCreateMat(blobCount, pBlobCount, CV_32FC3);
            m.mHist10 = cvCreateMat(blobCount, pBlobCount, CV_32FC3);
            m.mHist15 = cvCreateMat(blobCount, pBlobCount, CV_32FC3);

            float coverage, absDiff;
            Blob *b1, *b2;
            int step = m.mSpatial->step, hstep = m.mHist5->step;
            for(b = 0; b < blobCount; b++)
            {
                for(pb = 0; pb < pBlobCount; pb++)
                {
                    b1 = &blobs[b];
                    b2 = &pBlobs[pb];

                    coverage = percentOverlap(b1, b2);
                    ((float*)(m.mSpatial->data.ptr + b*step))[pb] = coverage;

                    absDiff = absDiffHistograms(&b1->h5, &b2->h5, 0);
                    ((float*)(m.mHist5->data.ptr + b*hstep))[pb*3] = absDiff;

                    absDiff = absDiffHistograms(&b1->h10, &b2->h10, 0);
                    ((float*)(m.mHist10->data.ptr + b*hstep))[pb*3] = absDiff;

                    absDiff = absDiffHistograms(&b1->h15, &b2->h15, 0);
                    ((float*)(m.mHist15->data.ptr + b*hstep))[pb*3] = absDiff;

                    // TODO: Faire les autres canaux
                }
            }


            //////////////////////////////////////////////////////////
            // Etape 4: association temporelle avec le frame precedent
            int assocMatrix[blobCount];
            association(blobs, pBlobs, &m, assocMatrix);

            // Transfer des identites (etiquettes) aux nouveaux blobs
            for(b = 0; b < blobCount; b++)
            {
                int index = assocMatrix[b];
                if(index != -1)
                    blobs[b].label = pBlobs[index].label;
                else
                    blobs[b].label = generateLabel();
            }
        }
        else
        {
            // Attribution d'une premiere etiquette a chaque blob
            for(b = 0; b < blobCount; b++)
                blobs[b].label = generateLabel();
        }

        // Images binaires
        drawBoundingRects(segFrame, blobs, blobCount);
        drawLabels(segFrame, blobs, blobCount);
        sprintf(filename, "bbox_%04d.jpg", i);
        cvSaveImage(filename, segFrame);

        // Image originales
        drawBoundingRects(frame, blobs, blobCount);
        drawLabels(frame, blobs, blobCount);
        sprintf(filename, "suivi_%04d.jpg", i);
        cvSaveImage(filename, frame);

        pBlobCount = blobCount;
        pBlobs = blobs;
    }
    cvReleaseMemStorage(&storage);
}