コード例 #1
0
ファイル: gui.c プロジェクト: ofrinevo/Chess
/*function the present the page- AI MENU- and handle the events releated to him*/
int AISettings(SDL_Surface* screen){
	int x, y;
	int move_next_page = FALSE;
	SDL_Surface* AI_Menu = NULL;
	SDL_Event event;

	AI_Menu = SDL_LoadBMP("Images/aiset.bmp");
	if (AI_Menu == NULL)
		return 1;
	apply_surface(0, 0, AI_Menu, screen);
	drawArrows(screen, AI_SETTINGS);
	
	//Update Screen
	SDL_Flip(screen);

	while (quit == FALSE && move_next_page == FALSE){
		if (SDL_PollEvent(&event)){
			if (event.type == SDL_MOUSEBUTTONUP){
				//Get the mouse offsets
				x = event.button.x;
				y = event.button.y;
				//If the mouse is over the button
				//colorComp
				if ((x > 60) && (x < 60 + 155) && (y > 210) && (y < 210 + 70)){ userColor = BLACK; }
				if ((x > 60) && (x < 60 + 155) && (y > 330) && (y < 330 + 70)){ userColor = WHITE; }
				//cancel
				if ((x > 60) && (x < 60 + 155) && (y > 490) && (y < 490 + 70)){
					return FALSE; // return to previous page- but dont exit the program!
				}
				//depth
				if ((x > 310) && (x < 310 + 155) && (y > 100) && (y < 100 + 70)){ minimax_depth = 1; }
				if ((x > 310) && (x < 310 + 155) && (y > 212) && (y < 212 + 70)){ minimax_depth = 2; }
				if ((x > 310) && (x < 310 + 155) && (y > 332) && (y < 332 + 70)){ minimax_depth = 3; }
				if ((x > 310) && (x < 310 + 155) && (y > 440) && (y < 440 + 70)){ minimax_depth = 4; }
				if ((x > 577) && (x < 577 + 155) && (y > 324) && (y < 324 + 70)){ minimax_depth = 5; }
				//next
				if ((x > 577) && (x < 577 + 155) && (y > 488) && (y < 488 + 70)){
					if (GamePlay(screen, fileName)){
						quit = TRUE;
						break;
					}
				}
				apply_surface(0, 0, AI_Menu, screen);
				drawArrows(screen, AI_SETTINGS);
				//Update Screen
				SDL_Flip(screen);
			}//end of handle key pressed

			//If the user has Xed out the window
			if (event.type == SDL_QUIT){ quit = TRUE; break; }
			//Apply image to screen
		}//end of handle events 
	}//end while

	//Free the loaded image
	SDL_FreeSurface(AI_Menu);
	return quit;
}
コード例 #2
0
ファイル: gps_overlays.cpp プロジェクト: malasiot/maplite
void GPSTrackOverlay::draw(QPainter &p, MapWidget *w)
{
    LinestringOverlay::draw(p, w) ;

    if ( selected_ )
        drawArrows(p, w) ;
}
コード例 #3
0
void UBEditableGraphicsLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(widget)
    Q_UNUSED(option)

    setStyle(painter);

    painter->drawPath(path());

    drawArrows();
}
コード例 #4
0
bool ScaleSpaceComputer::gradientOrientationMap(Mat& dstImg, int scaleFactor, int magnitudeThreshold){
    Mat gradX, gradY;
    Mat srcImg = imagesAtScale[scaleFactor];
    srcImg = srcImg.clone();
    Mat angleImg;
    horizontalGradient(srcImg, gradX);
    verticalGradient(srcImg, gradY);
    cv::phase(gradX, gradY, angleImg, false);
    drawArrows(angleImg, dstImg, scaleFactor, magnitudeThreshold);
    return true;
}
コード例 #5
0
ファイル: storage.cpp プロジェクト: RISK46kaf/Practise
void Storage::paintEvent(QPaintEvent *anEvent)
{
    QLabel::paintEvent(anEvent);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    //painter.setRenderHint(QPainter::SmoothPixmapTransform);
    QPen pen;

    if (NoTool != tool_) {
        pen.setWidth(5);
        pen.setColor(QColor(Qt::white));
        pen.setStyle(Qt::DashLine);
        painter.setPen(pen);

        if (BoundingBoxTool == tool_) {
            /* с учётом масштаба */
            QRect bbox = rect.getCoordinates();
            QPoint bboxTopLeft = bbox.topLeft() * scale_;
            QPoint bboxBottomRight = bbox.bottomRight() * scale_;

            bbox.setTopLeft(bboxTopLeft);
            bbox.setBottomRight(bboxBottomRight);

            painter.drawRect(bbox);
        }
        else if (EllipseTool == tool_) {
            /* с учётом масштаба */
            QRect elli = ell.getCoordinates().normalized();
            QPoint ellTopLeft = elli.topLeft() * scale_;
            QPoint ellBottomRight = elli.bottomRight() * scale_;

            elli.setTopLeft(ellTopLeft);
            elli.setBottomRight(ellBottomRight);

            if(1 < elli.height() && 1 < elli.width() )
            {
                painter.drawEllipse(elli);
            }
//            painter.drawRect(ell);
        }
        else if (ArrowTool == tool_) {
            /* с учётом масштаба */
            QLineF line = arrow.getCoordinates();
            QPointF p1 = line.p1() * scale_;
            QPointF p2 = line.p2() * scale_;

            line.setP1(p1);
            line.setP2(p2);

            if(1 < line.length())
            {
                double angle = ::acos(line.dx() / line.length());
                qreal Pi = atan(1)*4;
                if (line.dy() >= 0)
                    angle = (Pi * 2) - angle;

                QPointF arrowP1 = line.p1() + QPointF(sin(angle + Pi / 3) * arrow_size_,
                                                cos(angle + Pi / 3) * arrow_size_);
                QPointF arrowP2 = line.p1() + QPointF(sin(angle + Pi - Pi / 3) * arrow_size_,
                                                cos(angle + Pi - Pi / 3) * arrow_size_);

                QPolygonF arrowTop;
                arrowTop.clear();
                arrowTop << line.p1() << arrowP1 << arrowP2;

                painter.drawLine(line);
                painter.drawPolygon(arrowTop);///111
                qDebug() << "arrowTop" << arrowTop;
                arrow_top_ = arrowTop;
            }

            }
        else if (PolygonTool == tool_) {
            /* с учётом масштаба */
            QPoint point;
            QPolygon pol = poly.getCoordinates();
            for (int i = 0; i < pol.size(); i++) {
                point.setX(pol.at(i).x());
                point.setY(pol.at(i).y());
                point *= scale_;
                pol.remove(i);
                pol.insert(i, point);
            }
            painter.drawPolygon(pol);
        }
    }

    /* рисуем фигуры */
    drawBoundingBoxes(&painter, &pen);
    drawPolygons(&painter, &pen);
    drawEllipses(&painter, &pen);
    drawArrows(&painter, &pen);
}
コード例 #6
0
ファイル: GUILane.cpp プロジェクト: p1tt1/sumo
void
GUILane::drawGL(const GUIVisualizationSettings& s) const {
    glPushMatrix();
    const bool isInternal = myEdge->getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL;
    bool mustDrawMarkings = false;
    const bool drawDetails =  s.scale * s.laneWidthExaggeration > 5;
    if (isInternal) {
        // draw internal lanes on top of junctions
        glTranslated(0, 0, GLO_JUNCTION + 0.1);
    } else {
        glTranslated(0, 0, getType());
    }
    // set lane color
    if (!MSGlobals::gUseMesoSim) {
        setColor(s);
        glPushName(getGlID()); // do not register for clicks in MESOSIM
    }
    // draw lane
    // check whether it is not too small
    if (s.scale * s.laneWidthExaggeration < 1.) {
        GLHelper::drawLine(myShape);
        if (!MSGlobals::gUseMesoSim) {
            glPopName();
        }
        glPopMatrix();
    } else {
        if (isRailway(myPermissions)) {
            // draw as railway
            const SUMOReal halfRailWidth = 0.725 * s.laneWidthExaggeration;
            GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, halfRailWidth);
            glColor3d(1, 1, 1);
            glTranslated(0, 0, .1);
            GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, halfRailWidth - 0.2);
            drawCrossties(s, s.laneWidthExaggeration);
        } else {
            const SUMOReal laneWidth = isInternal ? myQuarterLaneWidth : myHalfLaneWidth;
            mustDrawMarkings = !isInternal;
            GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, laneWidth * s.laneWidthExaggeration);
        }
        if (!MSGlobals::gUseMesoSim) {
            glPopName();
        }
        glPopMatrix();
        // draw ROWs (not for inner lanes)
        if (!isInternal && drawDetails) {
            glPushMatrix();
            glTranslated(0, 0, GLO_JUNCTION); // must draw on top of junction shape
            GUINet* net = (GUINet*) MSNet::getInstance();
            glTranslated(0, 0, .2);
            drawLinkRules(*net);
            if (s.showLinkDecals && !isRailway(myPermissions)) {
                drawArrows();
            }
            if (s.showLane2Lane) {
                // this should be independent to the geometry:
                //  draw from end of first to the begin of second
                drawLane2LaneConnections();
            }
            glTranslated(0, 0, .1);
            if (s.drawLinkJunctionIndex) {
                drawLinkNo();
            }
            if (s.drawLinkTLIndex) {
                drawTLSLinkNo(*net);
            }
            glPopMatrix();
        }
    }
    if (mustDrawMarkings && drawDetails) { // needs matrix reset
        drawMarkings(s, s.laneWidthExaggeration);
    }
    // draw vehicles
    if (s.scale > s.minVehicleSize) {
        // retrieve vehicles from lane; disallow simulation
        const MSLane::VehCont& vehicles = getVehiclesSecure();
        for (MSLane::VehCont::const_iterator v = vehicles.begin(); v != vehicles.end(); ++v) {
            if ((*v)->getLane() == this) {
                static_cast<const GUIVehicle* const>(*v)->drawGL(s);
            } // else: this is the shadow during a continuous lane change
        }
        // draw parking vehicles
        const std::set<const MSVehicle*> parking = MSVehicleTransfer::getInstance()->getParkingVehicles(this);
        for (std::set<const MSVehicle*>::const_iterator v = parking.begin(); v != parking.end(); ++v) {
            static_cast<const GUIVehicle* const>(*v)->drawGL(s);
        }
        // allow lane simulation
        releaseVehicles();
    }
}
コード例 #7
0
ファイル: gui.c プロジェクト: ofrinevo/Chess
/*function the present the page- SETTING MENU- and handle the events releated to him*/
int SettingMenu(SDL_Surface* screen, int isLoaded){
	int x, y;
	int move_next_page = FALSE;
	SDL_Surface* Setting_Menu = NULL;
	SDL_Event event;



	Setting_Menu = SDL_LoadBMP("Images/settingsmenu.bmp");
	if (Setting_Menu == NULL)
		return 1;

	apply_surface(0, 0, Setting_Menu, screen);
	drawArrows(screen, SET_SETTINGS); // the function draw arrows on the chosen options
	SDL_Flip(screen);

	while (quit == FALSE && move_next_page == FALSE){
		if (SDL_PollEvent(&event)){
			if (event.type == SDL_MOUSEBUTTONUP){
				//Get the mouse offsets
				x = event.button.x;
				y = event.button.y;
				//If the mouse is over the button:
				//gameMode
				if ((x > 52) && (x < 52 + 155) && (y > 212) && (y < 212 + 70)){ game_mode = 1; }
				if ((x > 52) && (x < 52 + 155) && (y > 332) && (y < 332 + 70)){ game_mode = 2; }
				//cancel
				if ((x > 52) && (x < 52 + 155) && (y > 501) && (y < 501 + 70)){
					return FALSE;// return to previous page- but dont exit the program!
				}
				//to setTheBoard
				if (isLoaded == 0 && (x > 318) && (x < 318 + 155) && (y > 379) && (y < 379 + 70)){
					if (setBoard(screen)){
						quit = TRUE;
						break;
					}
				}
				//color
				if ((x > 579) && (x < 579 + 155) && (y > 212) && (y < 212 + 70)){ nextPlayer = WHITE; }
				if ((x > 579) && (x < 579 + 155) && (y > 332) && (y < 332 + 70)){ nextPlayer = BLACK; }
				//next
				if ((x > 581) && (x < 581 + 155) && (y > 501) && (y < 501 + 70)){
					if (game_mode == 2){
						if (AISettings(screen)){
							quit = TRUE;
							break;
						}
					}
					if (game_mode == 1){
						if (GamePlay(screen, fileName)){
							quit = TRUE;
							break;
						}
					}
				}
				apply_surface(0, 0, Setting_Menu, screen);
				drawArrows(screen, SET_SETTINGS); //the user clicked- maybe somthings changed- need to update the arrows
				SDL_Flip(screen); //update screen
			}
			//If the user has Xed out the window
			if (event.type == SDL_QUIT){ quit = TRUE; break; }
		}
	}
	//Free the loaded image
	SDL_FreeSurface(Setting_Menu);
	return quit;
}
コード例 #8
0
void	draw_thread(void *args)
{
   static long          b,b2,index;
	static int           distance;
   static RECTL         ScreenSize;
   static long          Color;
   static DATETIME	   DateTime;
   static POINTL        p1,p2,op1,op2;
   static POINTL        ptl[3];
   static long          width,height;
   static long          starcount,whiteStars,redStars,blueStars,yellowStars;
   static POINTL        *whitesegs,*redsegs,*bluesegs,*yellowsegs;  
   static POINTL        *whitesegs_o,*redsegs_o,*bluesegs_o,*yellowsegs_o;  
   static long          x[500],y[500];
   static float         realX[500],realY[500],realZ[500],sx[500],sy[500],sz[500],size[500];
   static float         ss,dfx,dfy,dfz,dd,f;
   static long          whitecount,redcount,bluecount,yellowcount;
   static long          whitecount_o,redcount_o,bluecount_o,yellowcount_o;
   static long          wc,rc,bc,yc;
   static long          gravity;
   static float         middleX,middleY,middleZ;

   int first;


   POINTL whitesegsAr[200]; 
   POINTL redsegsAr[200];
   POINTL bluesegsAr[200];
   POINTL yellowsegsAr[200];
   POINTL whitesegsAr_o[200]; 
   POINTL redsegsAr_o[200];
   POINTL bluesegsAr_o[200];
   POINTL yellowsegsAr_o[200];

   long gridX,gridY;
   long gridX_o,gridY_o;
   int isGrid;

   int inside;

   long searchNearX;
   long searchNearY;

   float dsx;
   float dsy;
   float ds;
   float minds;

   char starName[MAX_NAMESIZE];
   char starName_o[MAX_NAMESIZE];

   BOOL tracename;

   BOOL trid;

   float sinA;
   float cosA;

   float yAxis1Mx,yAxis1My,yAxis1Mz;
   float yAxis2Mx,yAxis2My,yAxis2Mz;
   float xAxis1Mx,xAxis1My,xAxis1Mz;
   float xAxis2Mx,xAxis2My,xAxis2Mz;
   float zAxis1Mx,zAxis1My,zAxis1Mz;
   float zAxis2Mx,zAxis2My,zAxis2Mz;

   float yAr1x,yAr1y,yAr1z;
   float yAr2x,yAr2y,yAr2z;
   float xAr1x,xAr1y,xAr1z;
   float xAr2x,xAr2y,xAr2z;
   float zAr1x,zAr1y,zAr1z;
   float zAr2x,zAr2y,zAr2z;


   long yAxis12Dx,yAxis12Dy;
   long yAxis22Dx,yAxis22Dy;
   long xAxis12Dx,xAxis12Dy;
   long xAxis22Dx,xAxis22Dy;
   long zAxis12Dx,zAxis12Dy;
   long zAxis22Dx,zAxis22Dy;

   long yAr12Dx,yAr12Dy;
   long yAr22Dx,yAr22Dy;
   long xAr12Dx,xAr12Dy;
   long xAr22Dx,xAr22Dy;
   long zAr12Dx,zAr12Dy;
   long zAr22Dx,zAr22Dy;

   HAB	   drawingthread_hab = WinInitialize(0);
   HMQ	   drawingthread_hmq = WinCreateMsgQueue(drawingthread_hab, 0);

   /* Settings galaxy parameter. */

   setTNGfont(hps); /* Setzen der Schriftart */


   whiteStars=configuration_data.whitestar_count;
   redStars=configuration_data.redstar_count;
   blueStars=configuration_data.bluestar_count;
   yellowStars=configuration_data.yellowstar_count;

   tracename=configuration_data.tracename;

   gravity=configuration_data.gravity;

   starcount=whiteStars+redStars+blueStars+yellowStars;

   width    = screenSizeX;
   height   = screenSizeY;

   trid=configuration_data.show3d;
   sinA=sin(-0.03f);
   cosA=cos(-0.03f);


   if ( trid )
   {
       yAxis1Mx=   0;
       yAxis1My=AXISMY;
       yAxis1Mz=   0;
       yAxis2Mx=   0;
       yAxis2My=AXISMY+AXISL;
       yAxis2Mz=   0;

       yAr1x=   ARROWW;
       yAr1y=   AXISMY+AXISL-ARROWL;
       yAr1z=      0;
       yAr2x=   -ARROWW;
       yAr2y=   AXISMY+AXISL-ARROWL;
       yAr2z=      0;

       xAxis1Mx=-AXISL2;
       xAxis1My=AXISMY;
       xAxis1Mz=   0;
       xAxis2Mx=AXISL2;
       xAxis2My=AXISMY;
       xAxis2Mz=   0;

       xAr1x=   AXISL2-ARROWL;
       xAr1y=   AXISMY;
       xAr1z=   ARROWW;
       xAr2x=   AXISL2-ARROWL;
       xAr2y=   AXISMY;
       xAr2z=   -ARROWW;


       zAxis1Mx=   0;
       zAxis1My=AXISMY;
       zAxis1Mz=-AXISL2;
       zAxis2Mx=   0;
       zAxis2My=AXISMY;
       zAxis2Mz=AXISL2;

       zAr1x=   ARROWW;
       zAr1y=   AXISMY;
       zAr1z=   AXISL2-ARROWL;
       zAr2x=   -ARROWW;
       zAr2y=   AXISMY;
       zAr2z=   AXISL2-ARROWL;

       convertTo2D(yAxis1Mx,yAxis1My,yAxis1Mz,&yAxis12Dx,&yAxis12Dy);
       convertTo2D(yAxis2Mx,yAxis2My,yAxis2Mz,&yAxis22Dx,&yAxis22Dy);
   }

   /* random seed (needed for each thread) */
	srand(WinGetCurrentTime(hab));


   /* Clear the background. */
   WinQueryWindowRect( hwndSaver, &ScreenSize );
   WinFillRect( hps, &ScreenSize, CLR_BLACK );


   /* Allocate memory. */
/*
   whitesegs = (POINTL *) ( malloc ( sizeof ( POINTL ) * starcount * 4 ) );
   redsegs = (POINTL *) ( malloc ( sizeof ( POINTL ) * starcount * 4 ) );
   bluesegs = (POINTL *) ( malloc ( sizeof ( POINTL ) * starcount * 4 ) );
   yellowsegs = (POINTL *) ( malloc ( sizeof ( POINTL ) * starcount * 4 ) );
*/   

   whitesegs = (POINTL *) &whitesegsAr;
   redsegs =   (POINTL *) &redsegsAr;
   bluesegs =  (POINTL *) &bluesegsAr;
   yellowsegs =(POINTL *) &yellowsegsAr;

   whitesegs_o = (POINTL *) &whitesegsAr_o;
   redsegs_o =   (POINTL *) &redsegsAr_o;
   bluesegs_o =  (POINTL *) &bluesegsAr_o;
   yellowsegs_o =(POINTL *) &yellowsegsAr_o;


  
   /* Init stars */
   for (b = 0; b < starcount; b++)
   {

      if (trid)
      {
          realX[b] = (rand()%(4000))-2000;
          realY[b] = (rand()%(2000))-1000;
          realZ[b] = (rand()%(4000))-2000;
      }
      else
      {
          realX[b] = (rand()%(4000))-2000;
          realY[b] = (rand()%(4000))-2000;
          realZ[b] = 0;
      }

      size[b]=1;
      if ( rand()%(10)>7 )
      {
         size[b]=4;
      }

      sx[b]=0;
      sy[b]=0; 
      sz[b]=0;

      x[b]=-1;
      y[b]=-1;
   }
 
   first=1;

   searchNearX=screenSizeX/2;
   searchNearY=screenSizeY/2;

   while(!stop_draw_thread)
   {
      DosGetDateTime ( &DateTime );
      srand ( DateTime.hundredths * 320 );

      if (trid )
      {
         turn2D(&xAxis1Mx,&xAxis1Mz,sinA,cosA);
         turn2D(&xAxis2Mx,&xAxis2Mz,sinA,cosA);
         turn2D(&zAxis1Mx,&zAxis1Mz,sinA,cosA);
         turn2D(&zAxis2Mx,&zAxis2Mz,sinA,cosA);

         turn2D(&yAr1x,&yAr1z,sinA,cosA);
         turn2D(&yAr2x,&yAr2z,sinA,cosA);

         turn2D(&xAr1x,&xAr1z,sinA,cosA);
         turn2D(&xAr2x,&xAr2z,sinA,cosA);

         turn2D(&zAr1x,&zAr1z,sinA,cosA);
         turn2D(&zAr2x,&zAr2z,sinA,cosA);
      }

      if (!first)
      {
         memcpy(whitesegs_o,whitesegs,sizeof ( POINTL ) * whitecount * 4);
         memcpy(redsegs_o,redsegs,sizeof ( POINTL ) * redcount * 4);
         memcpy(bluesegs_o,bluesegs,sizeof ( POINTL ) * bluecount * 4);
         memcpy(yellowsegs_o,yellowsegs,sizeof ( POINTL ) * yellowcount * 4);

         whitecount_o= whitecount;
         redcount_o=   redcount;
         bluecount_o=  bluecount;
         yellowcount_o=yellowcount;

         if (isGrid)
         {
            gridX_o=gridX;
            gridY_o=gridY;
            strcpy(starName_o,starName);
         }
      }
     
      
      /* <=- Stars -=> */

      whitecount=0;
      redcount=0;
      bluecount=0;
      yellowcount=0;

      wc=0;
      rc=0;
      bc=0;
      yc=0;


      middleX=0;
      middleY=0;
      middleZ=0;

      for (b = 0; b < starcount; b++)
      {
          if (trid )
          {
             turn2D(&realX[b],&realZ[b],sinA,cosA);
          }

          middleX+=realX[b];
          middleY+=realY[b];
          middleZ+=realZ[b];
      }
      middleX=middleX/starcount;
      middleY=middleY/starcount;
      middleZ=middleZ/starcount;
      for (b = 0; b < starcount; b++)
      {
          realX[b]-=middleX;
          if (!trid)
              realY[b]-=middleY;
          realZ[b]-=middleZ;
      }

      isGrid=0;

      minds=1e9;


      for (b = 0; b < starcount; b++)
      {
         for (b2=b+1 ;b2<starcount ;b2++)
         {
              if (trid)
              {
                  dfx=realX[b]-realX[b2];
                  dfy=realY[b]-realY[b2];
                  dfz=realZ[b]-realZ[b2];

                  dd=gravity*size[b2]/((dfx*dfx)+(dfy*dfy)+(dfz*dfz));           
                  dfx=dfx*dd;
                  dfy=dfy*dd;
                  dfz=dfz*dd;
                  sx[b]=sx[b]-dfx;
                  sy[b]=sy[b]-dfy;
                  sz[b]=sz[b]-dfz;

                  sx[b2]=sx[b2]+dfx;
                  sy[b2]=sy[b2]+dfy;
                  sz[b2]=sz[b2]+dfz;
              }
              else {
                  dfx=realX[b]-realX[b2];
                  dfy=realY[b]-realY[b2];

                  dd=gravity*size[b2]/((dfx*dfx)+(dfy*dfy));           
                  dfx=dfx*dd;
                  dfy=dfy*dd;
                  sx[b]=sx[b]-dfx;
                  sy[b]=sy[b]-dfy;

                  sx[b2]=sx[b2]+dfx;
                  sy[b2]=sy[b2]+dfy;
              }

         }
         realX[b]=realX[b]+sx[b];
         realY[b]=realY[b]+sy[b];
         realZ[b]=realZ[b]+sz[b];

         convertTo2D(realX[b],realY[b],realZ[b],&x[b],&y[b]);

         inside=isInside(x[b],y[b]);

         if ( wc<whiteStars )
         {
            wc++;
            if (inside)
            {
                index = whitecount*4;
                whitesegs[index].x = x[b];
                whitesegs[index].y = y[b];
                whitesegs[index+1].x = x[b]+2;
                whitesegs[index+1].y = y[b];
                whitesegs[index+2].x = x[b];
                whitesegs[index+2].y = y[b]+1;
                whitesegs[index+3].x = x[b]+2;
                whitesegs[index+3].y = y[b]+1;
                whitecount++;
            }
         }
         else {
            if (rc<redStars )
            {
                rc++;
                if (inside)
                {
                   index = redcount*4;
                   redsegs[index].x = x[b];
                   redsegs[index].y = y[b];
                   redsegs[index+1].x = x[b]+2;
                   redsegs[index+1].y = y[b];
                   redsegs[index+2].x = x[b];
                   redsegs[index+2].y = y[b]+1;
                   redsegs[index+3].x = x[b]+2;
                   redsegs[index+3].y = y[b]+1;
                   redcount++;
                }
            }
            else {
               if (bc<blueStars )
               {
                    bc++;
                    if (inside)
                    {
                       index = bluecount*4;
                       bluesegs[index].x = x[b];
                       bluesegs[index].y = y[b];
                       bluesegs[index+1].x = x[b]+2;
                       bluesegs[index+1].y = y[b];
                       bluesegs[index+2].x = x[b];
                       bluesegs[index+2].y = y[b]+1;
                       bluesegs[index+3].x = x[b]+2;
                       bluesegs[index+3].y = y[b]+1;
                       bluecount++;
                    }
               }
               else {
                    yc++;
                    if (inside)
                    {
                       index = yellowcount*4;
                       yellowsegs[index].x = x[b];
                       yellowsegs[index].y = y[b];
                       yellowsegs[index+1].x = x[b]+2;
                       yellowsegs[index+1].y = y[b];
                       yellowsegs[index+2].x = x[b];
                       yellowsegs[index+2].y = y[b]+1;
                       yellowsegs[index+3].x = x[b]+2;
                       yellowsegs[index+3].y = y[b]+1;
                       yellowcount++;
                    }
               }
             }
         }

         if (inside)
         {
             isGrid=1;
             dsx=(searchNearX-x[b]);
             dsy=(searchNearY-y[b]);
             ds=dsx*dsx+dsy*dsy;
             if (ds<minds)
             {
                 minds=ds;
                 gridX=x[b];
                 gridY=y[b];

                 strcpy(starName,starNames[b % CNT_STARS]);
             }
         }
      }

      if (!first)
      {
           drawGrid(hps,gridX_o,gridY_o,0,starName_o,tracename);

           if ( trid )
           {
               drawAxis(hps,yAxis12Dx,yAxis12Dy,yAxis22Dx,yAxis22Dy,xAxis12Dx,xAxis12Dy,xAxis22Dx,xAxis22Dy,zAxis12Dx,zAxis12Dy,zAxis22Dx,zAxis22Dy,0);
               drawArrows(hps,yAxis22Dx,yAxis22Dy,yAr12Dx,yAr12Dy,yAr22Dx,yAr22Dy,0);
               drawArrows(hps,xAxis22Dx,xAxis22Dy,xAr12Dx,xAr12Dy,xAr22Dx,xAr22Dy,0);
               drawArrows(hps,zAxis22Dx,zAxis22Dy,zAr12Dx,zAr12Dy,zAr22Dx,zAr22Dy,0);

           }

      }

      if (!first)
      {

          Color=CLR_BLACK;
          GpiSetColor ( hps , Color );
          GpiPolyLineDisjoint ( hps ,whitecount_o * 4 , whitesegs_o );
      }
      Color=CLR_WHITE;
      GpiSetColor ( hps , Color );
      GpiPolyLineDisjoint ( hps ,whitecount * 4 , whitesegs );

      if (!first)
      {
          Color=CLR_BLACK;
          GpiSetColor ( hps , Color );
          GpiPolyLineDisjoint ( hps ,redcount_o * 4 , redsegs_o );
      }
      Color=CLR_RED;
      GpiSetColor ( hps , Color );
      GpiPolyLineDisjoint ( hps ,redcount * 4 , redsegs );

      if (!first)
      {
          Color=CLR_BLACK;
          GpiSetColor ( hps , Color );
          GpiPolyLineDisjoint ( hps ,bluecount_o * 4 , bluesegs_o );
      }
      Color=CLR_BLUE;
      GpiSetColor ( hps , Color );
      GpiPolyLineDisjoint ( hps ,bluecount * 4 , bluesegs );

      if (!first)
      {
          Color=CLR_BLACK;
          GpiSetColor ( hps , Color );
          GpiPolyLineDisjoint ( hps ,yellowcount_o * 4 , yellowsegs_o );
      }
      Color=CLR_YELLOW;
      GpiSetColor ( hps , Color );
      GpiPolyLineDisjoint ( hps ,yellowcount * 4 , yellowsegs );

      if (isGrid)
      {
          drawGrid(hps,gridX,gridY,1,starName,tracename);
          searchNearX=gridX+(rand()%(4))-2;
          searchNearY=gridY+(rand()%(4))-2;
      }
      else {
           for (b = 0; b < starcount; b++)
           {
                if (trid)
                {
                    realX[b] = (rand()%(4000))-2000;
                    realY[b] = (rand()%(2000))-1000;
                    realZ[b] = (rand()%(4000))-2000;
                }
                else
                {
                    realX[b] = (rand()%(4000))-2000;
                    realY[b] = (rand()%(4000))-2000;
                    realZ[b] = 0;
                }
           }
      }

      if ( trid )
      {

         convertTo2D(xAxis1Mx,xAxis1My,xAxis1Mz,&xAxis12Dx,&xAxis12Dy);
         convertTo2D(xAxis2Mx,xAxis2My,xAxis2Mz,&xAxis22Dx,&xAxis22Dy);

         convertTo2D(zAxis1Mx,zAxis1My,zAxis1Mz,&zAxis12Dx,&zAxis12Dy);
         convertTo2D(zAxis2Mx,zAxis2My,zAxis2Mz,&zAxis22Dx,&zAxis22Dy);

         convertTo2D(yAr1x,yAr1y,yAr1z,&yAr12Dx,&yAr12Dy);
         convertTo2D(yAr2x,yAr2y,yAr2z,&yAr22Dx,&yAr22Dy);

         convertTo2D(xAr1x,xAr1y,xAr1z,&xAr12Dx,&xAr12Dy);
         convertTo2D(xAr2x,xAr2y,xAr2z,&xAr22Dx,&xAr22Dy);

         convertTo2D(zAr1x,zAr1y,zAr1z,&zAr12Dx,&zAr12Dy);
         convertTo2D(zAr2x,zAr2y,zAr2z,&zAr22Dx,&zAr22Dy);


         drawAxis(hps,yAxis12Dx,yAxis12Dy,yAxis22Dx,yAxis22Dy,xAxis12Dx,xAxis12Dy,xAxis22Dx,xAxis22Dy,zAxis12Dx,zAxis12Dy,zAxis22Dx,zAxis22Dy,1);

         drawArrows(hps,yAxis22Dx,yAxis22Dy,yAr12Dx,yAr12Dy,yAr22Dx,yAr22Dy,1);
         drawArrows(hps,xAxis22Dx,xAxis22Dy,xAr12Dx,xAr12Dy,xAr22Dx,xAr22Dy,1);
         drawArrows(hps,zAxis22Dx,zAxis22Dy,zAr12Dx,zAr12Dy,zAr22Dx,zAr22Dy,1);
      }


      first=0;
     
      /* sleep a while if necessary */
	   if(low_priority == TRUE)
          DosSleep(10);
      else
          DosSleep(2);
      }
/*   
   free ( whitesegs );
   free ( redsegs );
*/
   WinDestroyMsgQueue(drawingthread_hmq);
   WinTerminate(drawingthread_hab);

   _endthread();
}
コード例 #9
0
int main(int argc, char* argv[])
{
    try
    {
        nvxio::Application &app = nvxio::Application::get();

        //
        // Parse command line arguments
        //

        std::string sourceUri = app.findSampleFilePath("cars.mp4");
        std::string configFile = app.findSampleFilePath("feature_tracker_demo_config.ini");

        app.setDescription("This demo demonstrates Feature Tracker algorithm");
        app.addOption('s', "source", "Source URI", nvxio::OptionHandler::string(&sourceUri));
        app.addOption('c', "config", "Config file path", nvxio::OptionHandler::string(&configFile));

#if defined USE_OPENCV || defined USE_GSTREAMER
        std::string maskFile;
        app.addOption('m', "mask", "Optional mask", nvxio::OptionHandler::string(&maskFile));
#endif

        app.init(argc, argv);

        //
        // Create OpenVX context
        //

        nvxio::ContextGuard context;

        //
        // Reads and checks input parameters
        //

        nvx::FeatureTracker::HarrisPyrLKParams params;
        std::string error;
        if (!read(configFile, params, error))
        {
            std::cout<<error;
            return nvxio::Application::APP_EXIT_CODE_INVALID_VALUE;
        }

        //
        // Create a Frame Source
        //

        std::unique_ptr<nvxio::FrameSource> source(
            nvxio::createDefaultFrameSource(context, sourceUri));

        if (!source || !source->open())
        {
            std::cerr << "Can't open source URI " << sourceUri << std::endl;
            return nvxio::Application::APP_EXIT_CODE_NO_RESOURCE;
        }

        if (source->getSourceType() == nvxio::FrameSource::SINGLE_IMAGE_SOURCE)
        {
            std::cerr << "Can't work on a single image." << std::endl;
            return nvxio::Application::APP_EXIT_CODE_INVALID_FORMAT;
        }

        nvxio::FrameSource::Parameters sourceParams = source->getConfiguration();

        //
        // Create a Render
        //

        std::unique_ptr<nvxio::Render> renderer(nvxio::createDefaultRender(
            context, "Feature Tracker Demo", sourceParams.frameWidth, sourceParams.frameHeight));

        if (!renderer)
        {
            std::cerr << "Can't create a renderer" << std::endl;
            return nvxio::Application::APP_EXIT_CODE_NO_RENDER;
        }

        EventData eventData;
        renderer->setOnKeyboardEventCallback(eventCallback, &eventData);

        //
        // Messages generated by the OpenVX framework will be processed by nvxio::stdoutLogCallback
        //

        vxRegisterLogCallback(context, &nvxio::stdoutLogCallback, vx_false_e);

        //
        // Create OpenVX Image to hold frames from video source
        //

        vx_image frameExemplar = vxCreateImage(context,
            sourceParams.frameWidth, sourceParams.frameHeight, sourceParams.format);
        NVXIO_CHECK_REFERENCE(frameExemplar);
        vx_delay frame_delay = vxCreateDelay(context, (vx_reference)frameExemplar, 2);
        NVXIO_CHECK_REFERENCE(frame_delay);
        vxReleaseImage(&frameExemplar);

        vx_image prevFrame = (vx_image)vxGetReferenceFromDelay(frame_delay, -1);
        vx_image frame = (vx_image)vxGetReferenceFromDelay(frame_delay, 0);

        //
        // Load mask image if needed
        //

        vx_image mask = NULL;

#if defined USE_OPENCV || defined USE_GSTREAMER
        if (!maskFile.empty())
        {
            mask = nvxio::loadImageFromFile(context, maskFile, VX_DF_IMAGE_U8);

            vx_uint32 mask_width = 0, mask_height = 0;
            NVXIO_SAFE_CALL( vxQueryImage(mask, VX_IMAGE_ATTRIBUTE_WIDTH, &mask_width, sizeof(mask_width)) );
            NVXIO_SAFE_CALL( vxQueryImage(mask, VX_IMAGE_ATTRIBUTE_HEIGHT, &mask_height, sizeof(mask_height)) );

            if (mask_width != sourceParams.frameWidth || mask_height != sourceParams.frameHeight)
            {
                std::cerr << "The mask must have the same size as the input source." << std::endl;
                return nvxio::Application::APP_EXIT_CODE_INVALID_DIMENSIONS;
            }
        }
#endif

        //
        // Create FeatureTracker instance
        //

        std::unique_ptr<nvx::FeatureTracker> tracker(nvx::FeatureTracker::createHarrisPyrLK(context, params));

        nvxio::FrameSource::FrameStatus frameStatus;

        do
        {
            frameStatus = source->fetch(frame);
        } while (frameStatus == nvxio::FrameSource::TIMEOUT);

        if (frameStatus == nvxio::FrameSource::CLOSED)
        {
            std::cerr << "Source has no frames" << std::endl;
            return nvxio::Application::APP_EXIT_CODE_NO_FRAMESOURCE;
        }

        tracker->init(frame, mask);

        vxAgeDelay(frame_delay);

        //
        // Run processing loop
        //

        nvx::Timer totalTimer;
        totalTimer.tic();
        double proc_ms = 0;
        while (!eventData.shouldStop)
        {
            if (!eventData.pause)
            {
                frameStatus = source->fetch(frame);

                if (frameStatus == nvxio::FrameSource::TIMEOUT) {
                    continue;
                }
                if (frameStatus == nvxio::FrameSource::CLOSED) {
                    if (!source->open()) {
                        std::cerr << "Failed to reopen the source" << std::endl;
                        break;
                    }
                    continue;
                }

                //
                // Process
                //

                nvx::Timer procTimer;
                procTimer.tic();

                tracker->track(frame, mask);

                proc_ms = procTimer.toc();

                //
                // Print performance results
                //

                tracker->printPerfs();
            }

            //
            // show the previous frame
            //
            renderer->putImage(prevFrame);

            //
            // Draw arrows & state
            //

            drawArrows(renderer.get(), tracker->getPrevFeatures(), tracker->getCurrFeatures());

            double total_ms = totalTimer.toc();

            std::cout << "Display Time : " << total_ms << " ms" << std::endl << std::endl;

            //
            // Add a delay to limit frame rate
            //

            app.sleepToLimitFPS(total_ms);

            total_ms = totalTimer.toc();

            totalTimer.tic();

            displayState(renderer.get(), sourceParams, proc_ms, total_ms);

            if (!renderer->flush())
            {
                eventData.shouldStop = true;
            }

            if (!eventData.pause)
            {
                vxAgeDelay(frame_delay);
            }
        }

        //
        // Release all objects
        //

        vxReleaseImage(&mask);
        vxReleaseDelay(&frame_delay);
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error: " << e.what() << std::endl;
        return nvxio::Application::APP_EXIT_CODE_ERROR;
    }

    return nvxio::Application::APP_EXIT_CODE_SUCCESS;
}
コード例 #10
0
ファイル: GNELane.cpp プロジェクト: cbrafter/sumo
void
GNELane::drawGL(const GUIVisualizationSettings& s) const {
    glPushMatrix();
    glPushName(getGlID());
    glTranslated(0, 0, getType());
    const bool selectedEdge = gSelected.isSelected(myParentEdge.getType(), myParentEdge.getGlID());
    const bool selected = gSelected.isSelected(getType(), getGlID());
    if (mySpecialColor != 0) {
        GLHelper::setColor(*mySpecialColor);
    } else if (selected) {
        GLHelper::setColor(GNENet::selectedLaneColor);
    } else if (selectedEdge) {
        GLHelper::setColor(GNENet::selectionColor);
    } else {
        const GUIColorer& c = s.laneColorer;
        if (!setFunctionalColor(c.getActive()) && !setMultiColor(c)) {
            GLHelper::setColor(c.getScheme().getColor(getColorValue(c.getActive())));
        }
    };

    // draw lane
    // check whether it is not too small
    const SUMOReal selectionScale = selected || selectedEdge ? s.selectionScale : 1;
    const SUMOReal exaggeration = selectionScale * s.laneWidthExaggeration; // * s.laneScaler.getScheme().getColor(getScaleValue(s.laneScaler.getActive()));
    if (s.scale * exaggeration < 1.) {
        if (myShapeColors.size() > 0) {
            GLHelper::drawLine(getShape(), myShapeColors);
        } else {
            GLHelper::drawLine(getShape());
        }
        glPopMatrix();
    } else {
        if (drawAsRailway(s)) {
            // draw as railway
            const SUMOReal halfRailWidth = 0.725 * exaggeration;
            if (myShapeColors.size() > 0) {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, myShapeColors, halfRailWidth);
            } else {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, halfRailWidth);
            }
            RGBColor current = GLHelper::getColor();
            glColor3d(1, 1, 1);
            glTranslated(0, 0, .1);
            GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, halfRailWidth - 0.2);
            GLHelper::setColor(current);
            drawCrossties(0.3 * exaggeration, 1 * exaggeration, 1 * exaggeration);
        } else {
            // the actual lane
            // reduce lane width to make sure that a selected edge can still be seen
            const SUMOReal halfWidth = selectionScale * (myParentEdge.getNBEdge()->getLaneWidth(myIndex) / 2 - (selectedEdge ? .3 : 0));
            if (myShapeColors.size() > 0) {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, myShapeColors, halfWidth);
            } else {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, halfWidth);
            }
        }
        glPopMatrix();
        if (exaggeration == 1) {
            drawMarkings(selectedEdge, exaggeration);
        }

        // draw ROWs only if target junction has a valid logic)
        if (myParentEdge.getDest()->isLogicValid() && s.scale > 3) {
            drawArrows();
        }
    }

    glPopName();
}