std::vector<Edgel> EdgelDetector::findEdgelsInRegion(const int left, const int top, const int width, const int height ) {
	float prev1, prev2;
	std::vector<Edgel> edgels;

// debug function
	if( drawSectorGrids ) {
		for( int y=top; y<top+height; y+=RASTERSIZE ) {			
			drawLine( left, y, left+width, y, 128, 128, 128, 1);			
		}
		for( int x=left; x<left+width; x+=RASTERSIZE ) {			
			drawLine( x, top, x, top+height, 128, 128, 128, 1);			
		}		
	}
	
	// debug function	
	if( drawSectors ) {
		drawLine( left, top, left+width, top, 255, 255, 0, 1);
		drawLine( left, top, left, top+height, 255, 255, 0, 1);
		drawLine( left, top+height, left+width, top+height, 255, 255, 0, 1);
		drawLine( left+width, top, left+width, top+height, 255, 255, 0, 1);
	}	
	
	for( int y=0; y<height; y+=RASTERSIZE ) {
		unsigned char* offset = buffer->getBuffer() + (left + (y+top)*buffer->getWidth() ) * 3;
		prev1 = prev2 = 0.0f;
		const int pitch = 3;

		for( int x=0; x<width; x++) {
//// CODE DUPLICATED
			// check channels
			int current = edgeKernel( offset, pitch );
			if( current > THRESHOLD && 
				edgeKernel( offset+1, pitch ) > THRESHOLD &&
				edgeKernel( offset+2, pitch ) > THRESHOLD ) {
				// edge!
			} else {
				current = 0.0f;
			}
			// find local maximum
			if( prev1 > 0.0f && prev1 > prev2 && prev1 > current ) {
				Edgel edgel;
				edgel.setPosition(left+x-1, top+y);
				edgel.slope = edgeGradientIntensity(edgel.position.x, edgel.position.y);

				edgels.push_back(edgel);
			}
			prev2 = prev1;
			prev1 = current;

			offset += pitch;
//// CODE DUPLICATED
		}
	}

	
	// debug function
	if( drawEdges ) {
		for( int i=0, s = edgels.size(); i<s; i++ ) {
			drawPoint( edgels[i].position.x, edgels[i].position.y, 0, 0, 255, THICKNESS);
		}
	}
	int debugNumOfHorizontalEdges = edgels.size();
	
	for( int x=0; x<width; x+=RASTERSIZE ) {
		unsigned char* offset = buffer->getBuffer() + (left + x + (top*buffer->getWidth() )) * 3;
		const int pitch = 3*buffer->getWidth();
		prev1 = prev2 = 0.0f;

		for( int y=0; y<height; y++) {
//// CODE DUPLICATED			
			// check channels
			int current = edgeKernel( offset, pitch );
			if( current > THRESHOLD && 
				edgeKernel( offset+1, pitch ) > THRESHOLD &&
				edgeKernel( offset+2, pitch ) > THRESHOLD ) {
				// edge!
			} else {
				current = 0.0f;
			}
			// find local maximum
			if( prev1 > 0.0f && prev1 > prev2 && prev1 > current  ) {
				Edgel edgel;

				edgel.setPosition(left+x, top+y-1);
				edgel.slope = edgeGradientIntensity(edgel.position.x, edgel.position.y);

				edgels.push_back(edgel);
			}
			prev2 = prev1;
			prev1 = current;

			offset += pitch;
//// CODE DUPLICATED
		}
	}
	
	// debug function
	if( drawEdges ) {
		for( int i=debugNumOfHorizontalEdges, s = edgels.size(); i<s; i++ ) {
			drawPoint( edgels[i].position.x, edgels[i].position.y, 0, 255, 0, THICKNESS);
		}
	}
	
	return edgels;
}
示例#2
0
int mainStaticMatch()
{

    time_t start,end1,end2,end3,end4,end5;
    start = clock();

    IplImage *img1, *img2;
    img1 = cvLoadImage("../data/1.JPG");
    img2 = cvLoadImage("../data/2.JPG");


    end1 = clock();

    IpVec ipts1, ipts2;
    surfDetDes(img1,ipts1,false,4,4,2,0.0008f);
    surfDetDes(img2,ipts2,false,4,4,2,0.0008f);

    std::cout << "im1" << std::endl;
    std::cout << "Size:" << ipts1.size() << std::endl;

    std::cout << "im2" << std::endl;
    std::cout << "Size:" << ipts2.size() << std::endl;
    end2 = clock();

    IpPairVec matches;
    getMatches(ipts1,ipts2,matches);

    end3 = clock();

    for (unsigned int i = 0; i < matches.size(); ++i)
    {
        drawPoint(img1,matches[i].first);
        drawPoint(img2,matches[i].second);

        const int & w = img1->width;
        cvLine(img1,cvPoint(matches[i].first.x,matches[i].first.y),cvPoint(matches[i].second.x+w,matches[i].second.y), cvScalar(255,255,255),1);
        cvLine(img2,cvPoint(matches[i].first.x-w,matches[i].first.y),cvPoint(matches[i].second.x,matches[i].second.y), cvScalar(255,255,255),1);
    }

    std::cout << "Matches: " << matches.size() << std::endl;
    /*
      cvNamedWindow("1", CV_WINDOW_AUTOSIZE );
      cvNamedWindow("2", CV_WINDOW_AUTOSIZE );
      cvShowImage("1", img1);
      cvShowImage("2", img2);
      cvWaitKey(0);
    */
    end4 = clock();

//  cvSaveImage("result_gpu1.jpg",img1);
//	cvSaveImage("result_gpu2.jpg",img2);

    // Stitch two images
    IplImage *img = cvCreateImage(cvSize(img1->width + img2->width,
                                         img1->height),img1->depth,img1->nChannels);
    cvSetImageROI( img, cvRect( 0, 0, img1->width, img1->height ) );
    cvCopy(img1, img);
    cvSetImageROI( img, cvRect(img1->width,0, img2->width, img2->height) );
    cvCopy(img2, img);
    cvResetImageROI(img);
    cvSaveImage("result_gpu.jpg",img);

    end5 = clock();
    double dif1 = (double)(end1 - start) / CLOCKS_PER_SEC;
    double dif2 = (double)(end2 - end1) / CLOCKS_PER_SEC;
    double dif3 = (double)(end3 - end2) / CLOCKS_PER_SEC;
    double dif4 = (double)(end4 - end3) / CLOCKS_PER_SEC;
    double dif5 = (double)(end5 - end4) / CLOCKS_PER_SEC;
    double total = (double)(end5 - start) / CLOCKS_PER_SEC;
    std::cout.setf(std::ios::fixed,std::ios::floatfield);
    std::cout.precision(5);
    std::cout << "Time(load):" << dif1 << std::endl;
    std::cout << "Time(descriptor):" << dif2 << std::endl;
    std::cout << "Time(match):" << dif3 << std::endl;
    std::cout << "Time(plot):" << dif4 << std::endl;
    std::cout << "Time(save):" << dif5 << std::endl;
    std::cout << "Time(Total):" << total << std::endl;
    return 0;
}
//vind alle markers in de buffer
std::vector<ARMarker>  EdgelDetector::findMarkers() {
	std::vector<LineSegment> mergedlinesegments;

	//maak regio's van REGIONSIZE*REGIONSIZE
	for( int y=2; y<buffer->getHeight()-3; y+=REGIONSIZE ) {
		for( int x=2; x<buffer->getWidth()-3; x+=REGIONSIZE) {			
			//zoek edgels per regio
			std::vector<Edgel> edgels = findEdgelsInRegion(x, y, std::min( REGIONSIZE, buffer->getWidth()-x-3), std::min( REGIONSIZE, buffer->getHeight()-y-3) );

			std::vector<LineSegment> linesegments;

			//als er meer dan 5 edgels in de regio zitten, maak hier dan linesegments van
			if (edgels.size() > 5) {
				linesegments = findLineSegment( edgels );	
			}
			
			// debug function
			if( drawLineSegments ) {
				for( int i=0, s = linesegments.size(); i<s; i++ ) {
					drawArrow( linesegments[i].start.position.x, linesegments[i].start.position.y, linesegments[i].end.position.x, linesegments[i].end.position.y, 
							   linesegments[i].slope.x, linesegments[i].slope.y, 255, 0, 0, THICKNESS);
				}
			}				
			
			//als er meer dan 1 linesegments gevonden zijn, merge ze dan
			if (linesegments.size() > 1) {				
				linesegments = mergeLineSegments( linesegments, 50 );
			}
			
			// debug function
			if( drawPartialMergedLineSegments ) {
				for( int i=0, s = linesegments.size(); i<s; i++ ) {
					drawArrow( linesegments[i].start.position.x, linesegments[i].start.position.y, linesegments[i].end.position.x, linesegments[i].end.position.y, 
							  linesegments[i].slope.x, linesegments[i].slope.y, 255, 0, 0, THICKNESS);				}
			}			
			
			//en stop alle linesegments in een vector
			for (int i = 0; i < linesegments.size(); i++) {
				mergedlinesegments.push_back(linesegments.at(i));			}
			
		}
	}
	//merge de lines nog 1 keer over de gehele image
	mergedlinesegments = mergeLineSegments( mergedlinesegments, 50 );

	// debug function
	if( drawMergedLineSegments ) {
		for( int i=0, s = mergedlinesegments.size(); i<s; i++ ) {
			drawArrow( mergedlinesegments[i].start.position.x, mergedlinesegments[i].start.position.y, mergedlinesegments[i].end.position.x, mergedlinesegments[i].end.position.y, 
					  mergedlinesegments[i].slope.x, mergedlinesegments[i].slope.y, 255, 0, 0, THICKNESS);		}
	}	
	
	// extend linesegments
	
	extendLineSegments( mergedlinesegments );
	
	// debug function
	if( drawExtendedLineSegments ) {
		for( int i=0, s = mergedlinesegments.size(); i<s; i++ ) {
			drawArrow( mergedlinesegments[i].start.position.x, mergedlinesegments[i].start.position.y, mergedlinesegments[i].end.position.x, mergedlinesegments[i].end.position.y, 
					  mergedlinesegments[i].slope.x, mergedlinesegments[i].slope.y, 255, 255, 0, THICKNESS );		}
	}	
	
	std::vector<LineSegment> linesWithCorners = findLinesWithCorners( mergedlinesegments );
	
	if( drawCorners ) {
		for( int i=0, s = linesWithCorners.size(); i<s; i++ ) {
			if( linesWithCorners[i].start_corner ) { drawPoint( linesWithCorners[i].start.position.x, linesWithCorners[i].start.position.y, 255, 0, 255, THICKNESS); }
			if( linesWithCorners[i].end_corner ) { drawPoint( linesWithCorners[i].end.position.x, linesWithCorners[i].end.position.y, 255, 0, 255, THICKNESS); }
			
			
			drawArrow( linesWithCorners[i].start.position.x, linesWithCorners[i].start.position.y, linesWithCorners[i].end.position.x, linesWithCorners[i].end.position.y, 
					  linesWithCorners[i].slope.x, linesWithCorners[i].slope.y, 0, 255, 0, THICKNESS);		
		}
	}	
	
	// detect markers
	std::vector<ARMarker> markers;
	
	do {
		
		// pak een willekeurig segment, en probeer hier een chain mee te maken..
		LineSegment chainSegment = linesWithCorners[0];
		linesWithCorners[0] = linesWithCorners[ linesWithCorners.size() - 1 ];
		linesWithCorners.resize( linesWithCorners.size() - 1 );
		
		std::vector<LineSegment> chain;
		int length = 1;
		
		// kijk eerst of er schakels voor dit element moeten...
		findChainOfLines( chainSegment, true, linesWithCorners, chain, length);

		chain.push_back( chainSegment );
				
		// en misschien ook nog wel erna..
		if( length < 4 ) {
			findChainOfLines( chainSegment, false, linesWithCorners, chain, length);
		}
				
		if( length > 2 ) {
			ARMarker marker;
			
			marker.chain = chain;
			marker.reconstructCorners();
			
			markers.push_back( marker );
		}
	} while( linesWithCorners.size() );
	
	if( drawMarkers ) {
		for( int i=0, s=markers.size(); i<s; i++ ) {
			drawLine( markers[i].c1.x, markers[i].c1.y, markers[i].c2.x, markers[i].c2.y, 255, 0, 0, THICKNESS); 
			drawLine( markers[i].c2.x, markers[i].c2.y, markers[i].c3.x, markers[i].c3.y, 255, 0, 0, THICKNESS); 
			drawLine( markers[i].c3.x, markers[i].c3.y, markers[i].c4.x, markers[i].c4.y, 255, 0, 0, THICKNESS); 
			drawLine( markers[i].c4.x, markers[i].c4.y, markers[i].c1.x, markers[i].c1.y, 255, 0, 0, THICKNESS); 
		}
	}
	
	return markers;
}
void detectNewImageFeatures( const cv::Mat image,
                             const VectorImageFeaturePrediction &featuresPrediction,
                             uint newImageFeaturesMaxSize,
                             VectorImageFeatureMeasurement &newImageFeatures )
{
    newImageFeatures.clear();

    // Calculamos el tamaño de las zonas de la imágen según los parámetros configurados
    ConfigurationManager& configManager = ConfigurationManager::getInstance();
    
	//int zonesInARow = exp2f(configManager.ekfParams->detectNewFeaturesImageAreasDivideTimes);
	int zonesInARow = 1;

    int zoneWidth = image.cols / zonesInARow;
    int zoneHeight = image.rows / zonesInARow;

    // Construimos la mascara para buscar features solamente en zonas poco densas
    cv::Mat imageMask( cv::Mat::ones(image.rows, image.cols, CV_8UC1) * 255 );
    buildImageMask( featuresPrediction, imageMask );

    // Detectamos features
    std::vector<cv::KeyPoint> imageKeypoints;
    configManager.featureDetector->detect(image, imageKeypoints, imageMask);

    // Extraemos descriptores
    cv::Mat descriptors;
    configManager.descriptorExtractor->compute(image, imageKeypoints, descriptors);

    // Caso particular: la cantidad de features encontrados no supera los pedidos
    size_t imageKeypointsSize = imageKeypoints.size();

#ifdef DEBUG
    std::cout << "Cantidad de features detectados al agregar nuevos: " << imageKeypointsSize << std::endl;
#endif

    if (imageKeypointsSize <= newImageFeaturesMaxSize)
    {
        double imagePos[2];
        for (int i = 0; i < imageKeypointsSize; ++i)
        {
            cv::KeyPoint &currKeypoint = imageKeypoints[i];

            imagePos[0] = currKeypoint.pt.x;
            imagePos[1] = currKeypoint.pt.y;

            newImageFeatures.push_back( new ImageFeatureMeasurement( imagePos,
                                                                     descriptors.row(i) ) );
        }
    }
    else
    {
        // Buscamos nuevos features intentando que esten
        // lo mejor distribuidos posible en la imagen
        searchFeaturesByZone( featuresPrediction, imageKeypoints, descriptors,
                              zonesInARow, zoneWidth, zoneHeight,
                              imageMask,
                              newImageFeaturesMaxSize, newImageFeatures );
    }

#ifdef DEBUG_SHOW_NEW_FEATURES
    cv::Mat imageCopy;
    image.copyTo(imageCopy);
    for (int i = 1; i < zonesInARow; ++i)
    {
        cv::line(imageCopy, cv::Point(i * zoneWidth, 0), cv::Point(i * zoneWidth, imageCopy.rows), cv::Scalar(0, 255, 0));
        cv::line(imageCopy, cv::Point(0, i * zoneHeight), cv::Point(imageCopy.cols, i * zoneHeight), cv::Scalar(0, 255, 0));
    }

    int featuresPredictionSize = featuresPrediction.size();
    for (int i = 0; i < featuresPredictionSize; ++i)
    {
        ImageFeaturePrediction *currFeaturePrediction = featuresPrediction[i];

        drawUncertaintyEllipse2D( imageCopy,
                                  cv::Point2f(currFeaturePrediction->imagePos[0], currFeaturePrediction->imagePos[1]),
                                  currFeaturePrediction->covarianceMatrix,
                                  2 * (image.cols + image.rows),
                                  cv::Scalar(0, 255, 0),
                                  false );
    }

    cv::namedWindow("Busqueda de nuevos features: mascara");
    cv::imshow("Busqueda de nuevos features: mascara", imageMask);
    cv::waitKey(0);

    for (int i = 0; i < newImageFeatures.size(); ++i)
    {
        drawPoint(imageCopy, newImageFeatures[i]->imagePos, cv::Scalar(0, 255, 255));
    }

    cv::namedWindow("Busqueda de nuevos features: imagen con nuevos features");
    cv::imshow("Busqueda de nuevos features: imagen con nuevos features", imageCopy);
    cv::waitKey(0);

    // Se borran todas las ventanas creadas
    cv::destroyWindow("Busqueda de nuevos features: mascara");
    cv::destroyWindow("Busqueda de nuevos features: imagen con nuevos features");
#endif
}
示例#5
0
void EKF::init(const cv::Mat &image)
{
    if (_logFile.is_open())
    {
        time_t seed = time(NULL);
        srand(static_cast<uint>(seed));

        _logFile << "Random Seed: " << seed << std::endl << std::endl;

        _logFile << "~~~~~~~~~~~~ STEP " << _ekfSteps << " ~~~~~~~~~~~~" << std::endl;
    }

    ExtendedKalmanFilterParameters *ekfParams = ConfigurationManager::getInstance().ekfParams;

    initState(state);

    state.mapFeatures.reserve(ekfParams->reserveFeaturesDepth);
    state.mapFeaturesDepth.reserve(ekfParams->reserveFeaturesDepth);
    state.mapFeaturesInvDepth.reserve(ekfParams->reserveFeaturesInvDepth);

    initCovariance(stateCovarianceMatrix);

    // Detectar features en la imagen
    VectorFeatureMatch noMatches; // Al principio no tiene nada ya que no hay matches
    VectorImageFeaturePrediction noPredictions;
    VectorImageFeatureMeasurement newFeatureMeasurements;
    detectNewImageFeatures(image, noPredictions, ekfParams->minMatchesPerImage, newFeatureMeasurements);

#ifdef DEBUG_SHOW_IMAGES
    cv::Mat imageWithKeypoints;
    image.copyTo(imageWithKeypoints);

    for (uint i = 0; i < newFeatureMeasurements.size(); ++i)
    {
        drawPoint(imageWithKeypoints, newFeatureMeasurements[i]->imagePos, cv::Scalar(0, 0, 255));
    }

    std::cout << std::endl;

    std::string windowName = "Features detectados en la primer imagen (";

    std::stringstream convert;
    convert << newFeatureMeasurements.size();

    windowName += convert.str();
    windowName += ")";

    cv::namedWindow(windowName);
    cv::imshow(windowName, imageWithKeypoints);
    cv::waitKey(0);

    cv::destroyWindow(windowName);
#endif

    // Agregar los features nuevos al estado
    addFeaturesToStateAndCovariance(newFeatureMeasurements, state, stateCovarianceMatrix);

    size_t newFeatureMeasurementsSize = newFeatureMeasurements.size();
    for (uint i = 0; i < newFeatureMeasurementsSize; ++i)
    {
        delete newFeatureMeasurements[i];
    }

    if (_logFile.is_open())
    {
        state.showDetailed(_logFile);
    }
}
示例#6
0
void main(void) {

    unsigned char i,j;

    /* Output configurations */

    ADCON1 |= 0x0F;    // All possible analog input pins config as digital I/O
    CMCON = 0x07;    // Comparators disabled

    /* Natural interaction expansion port configuration    */
    TRISAbits.TRISA4 = 1;    // A4 Botton 3
    TRISAbits.TRISA3 = 1;    // A3 Botton 2
    TRISAbits.TRISA2 = 1;    // A2 Botton 1
    TRISAbits.TRISA1 = 1;    // A1 Potentiometer 2
    TRISAbits.TRISA0 = 1;    // A0 Potentiometer 1

    TRISB = 0;    // B0..B6    Serial input for the Shift Registers
    TRISD = 0;    // D0..D3    Shift Registers control inputs: SCK, RCK, _SCL, _G
    TRISEbits.TRISE0 = 1; //Input button PORTEbits.RE0

    LATA = 0;    // Disable expansion port
    _SCL = 1;    // Disable Shift Register _SCL (Global Clear)
    _G = 0;        // Enables Shift Regusters outputs _G

    // Resetting variables
    for (i = 0; i <= MAX_INDEX_G_BUFFER_GREYSCALE; i++) {
        gBufferGreyscale[i] = 0;
        gPreBufferGreyscale[i] = 0;
    }
    for (i = 0; i <= MAX_INDEX_M_BUFFER_MATRIX; i++) {
        mBufferMatrix[i] = RESET_M_BUFFER_MATRIX;
    }
    iGreyscale = 0;
    iTimer1 = 0;
    iMenu = 0;
    FIRST = 0;
    SECOND = 0;
    THIRD = 0;
    FOURTH = 0;
    FIFTH = 0;
    SIXTH = 0;
    pwm = 0;

    /* Timer 0 Configuration */
    // Used to trigger the refresh matrix printed data routine
    OpenTimer0(TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_1);
    WriteTimer0(0);

    /* Timer 1 Configuration */
    // Used to periodically check the input data (external buttons)
    OpenTimer1(TIMER_INT_ON & T1_SOURCE_INT &  T1_PS_1_8 & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF);
    WriteTimer1( 0x00 & 0x00 );

    /* Timer 3 Configuration */
    // Used to create delays within the different menus without blocking with delays
    OpenTimer3( TIMER_INT_ON & T3_16BIT_RW & T3_SOURCE_INT & T3_PS_1_8 & T3_SYNC_EXT_OFF);
    WriteTimer3( 0x00 & 0x00 );

    /* A/D configuration */
    //ADCON1
    ADCON1bits.VCFG1 = 0;    // Voltage Reference Configuration bit (Vref-) = Vss
    ADCON1bits.VCFG0 = 0;    // Voltage Reference Configuration bit (Vref+) = Vdd
    ADCON1bits.PCFG3 = 1;    // PCFG = "1110" enables AN0 and AN1
    ADCON1bits.PCFG2 = 1;
    ADCON1bits.PCFG1 = 1;
    ADCON1bits.PCFG0 = 0;

    //ADCON0
    ADCON0bits.ADON = 1;    // A/D converter module is enabled
    ADCON0bits.CHS0 = 0;    // CHS = "0000" AN0 selected
    ADCON0bits.CHS1 = 0;
    ADCON0bits.CHS2 = 0;
    ADCON0bits.CHS3 = 0;

    //ADCON2
    ADCON2bits.ADCS0 = 0;    // A/D Adquisition Clock Select bits
    ADCON2bits.ADCS1 = 1;    // Tad = conversion time per bit. The A/D conversion requires 11 Tad
    ADCON2bits.ADCS2 = 0;    // "010" = 32 * Tosc

    ADCON2bits.ACQT0 = 0;    // A/D Adquisition time bits    "000" = Manual adquisition
    ADCON2bits.ACQT1 = 0;
    ADCON2bits.ACQT2 = 0;
    ADCON2bits.ADFM = 0;    // Left justified     . . .ADRESH . . : . . ADRESL. . .
    //                    7 6 5 4 3 2 1 0 : 7 6 5 4 3 2 1 0
    //                    X X X X X X X X . X X . . . . . . <-Left Justified


    /* Enabling interrups */
    INTCONbits.TMR0IE = 1;    // Enables interrupts for TIMER0
    PIE1bits.TMR1IE = 1;    // Enables interrupts for TIMER1
    PIE2bits.TMR3IE = 1;    // Enables interrupts for TIMER3
    INTCONbits.PEIE = 1;    // Peripherial interrupt enabled
    INTCONbits.GIE = 1;    // Global interrupt enabled


    /* Main Loop */
    while(1)
    {

        /*    Main MENU includes the different modes that the table can show
            Switching between menus is done using external button(RE0):

                0 - Fixed light dimmed with external control
                1 - Slow square
                2 - Slow chess board
                3 - Message
                4 - Invaders
                5 - Party (Dirty)

        */
        switch(iMenu) {

        /******************************************************************/
        /* 0 - Fixed light dimmed with external control                   */
        /******************************************************************/
        case 0:
            if (FIRST == 0) {
                deleteMatrix();
                (FIRST = 1);
            }
            drawLine(1,1,1,5,pwm);    //dirty way to draw the all pixels at the same time
            drawLine(2,1,2,5,pwm);
            drawLine(3,1,3,5,pwm);
            drawLine(4,1,4,5,pwm);
            drawLine(5,1,5,5,pwm);
            break;

        /******************/
        /* 1- Slow square */
        /******************/
        case 1:
            if (SECOND == 0) {
                deleteMatrix();
                (SECOND = 1);
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,j);
                drawSquare(2,2,4,4,i);
                drawPoint(3,3,j);
                Delay10KTCYx(100);
                if(iMenu != 1) {
                    break;
                }
            }
            if(iMenu != 1) {
                break;
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,i);
                drawSquare(2,2,4,4,j);
                drawPoint(3,3,i);
                Delay10KTCYx(100);
                if(iMenu != 1) {
                    break;
                }
            }
            if(iMenu != 1) {
                break;   // It allows to break the case during the executation
            }

        /***********************/
        /* 2- Slow Chess board */
        /***********************/
        case 2:
            if (THIRD == 0) {
                deleteMatrix();
                (THIRD = 1);
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawPoint(1,5,j);
                drawLine(1,3,3,5,j);
                drawLine(1,1,5,5,j);
                drawLine(3,1,5,3,j);
                drawPoint(5,1,j);

                drawLine(1,4,2,5,i);
                drawLine(1,2,4,5,i);
                drawLine(2,1,5,4,i);
                drawLine(4,1,5,2,i);
                Delay10KTCYx(100);
                if(iMenu != 2) {
                    break;
                }
            }
            if(iMenu != 2) {
                break;
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawPoint(1,5,i);
                drawLine(1,3,3,5,i);
                drawLine(1,1,5,5,i);
                drawLine(3,1,5,3,i);
                drawPoint(5,1,i);

                drawLine(1,4,2,5,j);
                drawLine(1,2,4,5,j);
                drawLine(2,1,5,4,j);
                drawLine(4,1,5,2,j);
                Delay10KTCYx(100);
                if(iMenu != 2) {
                    break;
                }
            }
            if(iMenu != 2) {
                break;   // It allows to break the case during the executation
            }


        /**************/
        /* 3- Message */
        /**************/
        case 3:
            if (FOURTH == 0) {
                deleteMatrix();
                (FOURTH = 1);
            }
            //knightRider(4);
            scrollText((rom unsigned char *)&Nino[0], TRANS_RIGHT_2_LEFT);

            break;



        /***************/
        /* 4- Invaders */
        /***************/
        case 4:
            if (FIFTH == 0) {
                deleteMatrix();
                (FIFTH = 1);
            }
            for(i = 1; i <= INVADERS_PAIR_REPETITIONS; i++) {
                drawFrame((rom unsigned char *)&invaders[0]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
                drawFrame((rom unsigned char *)&invaders[1]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
            }// end for
            for(i = 1; i <= INVADERS_PAIR_REPETITIONS; i++) {
                drawFrame((rom unsigned char *)&invaders[2]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
                drawFrame((rom unsigned char *)&invaders[3]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
            }// end for
            for(i = 1; i <= INVADERS_PAIR_REPETITIONS; i++) {
                drawFrame((rom unsigned char *)&invaders[4]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
                drawFrame((rom unsigned char *)&invaders[5]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
            }// end for

            break;


        /********************/
        /* 5- Party (Dirty) */
        /********************/
        case 5:
            if (SIXTH == 0) {
                deleteMatrix();
                drawLine(1,5,5,5,254);
            }
            for(j = 100, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,j);
                drawSquare(2,2,4,4,i);
                drawPoint(3,3,j);
                if(iMenu != 5) {
                    break;
                }
            }
            if(iMenu != 5) {
                break;
            }
            for(j = 100, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,i);
                drawSquare(2,2,4,4,j);
                drawPoint(3,3,i);
                if(iMenu != 5) {
                    break;
                }
            }

            if(iMenu != 5) {
                break;    // It allows to break the case during the executation
            }

            //SOLVES A BUG: because when TMR1F is called from this case, FIFTH is
            //reset but when we come back is set one because we are in case 4 not 1,
            if (iMenu == 5)(SIXTH = 1);
            break;

        default:
            drawPoint(3,3, 180);

        }// End switch iMenu
    }// End while

    CloseTimer0();
    CloseTimer1();
}//end main
static void lvDisplay(void) {
    glClear(GL_COLOR_BUFFER_BIT);


    applyTransforms();


    glScalef(scale, scale, scale);
	glColor3f(0.25f, 0.25f, 0.25f);
	glLineWidth(2);
	drawLine(-lvWidth-lvTransX, 0, lvWidth-lvTransX, 0);
	drawLine(0, -lvHeight-lvTransY, 0, lvHeight-lvTransY);
	glLineWidth(1);

	lsystem.Draw();		

	// Draw image planes
	glColor3f(1.0, 0.0, 1.0);
	glLineWidth(2);
	drawLine(lsystem.iPlane, lsystem.maxAperture()/2, lsystem.iPlane, -lsystem.maxAperture()/2); 
	drawText(lsystem.iPlane - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "I");
	drawLine(zDist, lsystem.maxAperture()/2, zDist, -lsystem.maxAperture()/2);
	drawText(zDist - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "O");

	// Trace rays through lens system
	glColor3f(0.0, 0.0, 1.0);
	glLineWidth(1);
	
	for (int i = -9; i < 10; i++)
	{
        Ray rayv = Ray(Point(0, iPlaneY, lsystem.iPlane), Vector(0, lsystem.pupil.y/2 * (float) i/9 - iPlaneY, lsystem.pupil.z - lsystem.iPlane));
        Ray& rays = rayv;
        lsystem.Trace(rays, new Ray());
	}
	

	//lsystem.findExitPupil();
	//lsystem.recalAper();
	//lsystem.findF();
	//lsystem.findFp();
	//lsystem.refocus(zDist, -1);

	//Draw principal axes
	glColor3f(0.0, 1.0, 0.0);
	glLineWidth(2);
	drawLine(lsystem.pupil.z, lsystem.pupil.y/2, lsystem.pupil.z, (lsystem.pupil.y+lsystem.maxAperture()) / 2);
	drawLine(lsystem.pupil.z, -lsystem.pupil.y/2, lsystem.pupil.z, (-lsystem.pupil.y-lsystem.maxAperture()) / 2);
	drawText(lsystem.pupil.z, (-lsystem.pupil.y-lsystem.maxAperture()) / 2 - 5, SBFONT, "ep");

	//Draw principal axes
	glColor3f(1.0, 0.0, 0.0);
	glLineWidth(2);
	drawLine(lsystem.p2, lsystem.maxAperture()/2, lsystem.p2, -lsystem.maxAperture()/2);
	drawText(lsystem.p2 - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "P'");
	drawLine(lsystem.p1, lsystem.maxAperture()/2, lsystem.p1, -lsystem.maxAperture()/2);
	drawText(lsystem.p1 - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "P");

	//Draw focal planes
	glColor3f(1.0, 1.0, 0.0);
	drawPoint(5, lsystem.f1, 0);
	drawText(lsystem.f1 - 1, -5, SBFONT, "F");
	drawPoint(5, lsystem.f2, 0);
	drawText(lsystem.f2 - 1, -5, SBFONT, "F'");
	
	glMatrixMode(GL_PROJECTION); glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0, lvWidth, lvHeight, 0);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    drawSquare(0.25f, 0.25f, 0.25f, 0, 0, lvWidth, BARH);
	drawSquare(0.25f, 0.25f, 0.25f, 0, lvHeight, lvWidth, lvHeight-BARH);
	glLoadIdentity();

	gluOrtho2D(-lvWidth, lvWidth, lvHeight, -lvHeight);
	glColor3f(0, 1, 1);
	drawText(-lvWidth + 15, -lvTransY*lvZoom - 8, SBFONT, "+z");
	drawText(lvWidth - 50, -lvTransY*lvZoom - 8, SBFONT, "-z");
	drawText(-lvTransX*lvZoom, -lvHeight + 75, SBFONT, "+y");
	drawText(-lvTransX*lvZoom, lvHeight - 65, SBFONT, "-y");
	
    glColor3f(1, 1, 1);
    const char* mode = lsystem.M == precise ? "precise" : "thick";
	lvText(9, lvHeight-16, SBFONT, 0, "fstop %1.1f (aperture %1.1fmm) | "
		                              "object %1.1fmm | image %1.1fmm | mode: %s", 
									  lsystem.fstop,lsystem.getAperture()->aper,zDist,lsystem.iPlane, mode); 

	lvText(9, 8, SBFONT, 0, "F %1.1fmm | F' %1.1fmm | P %1.1fmm | "
		                    "P' %1.1fmm | exit pupil (%1.1fmm, %1.1fmm)", 
							lsystem.f1,lsystem.f2,lsystem.p1,lsystem.p2,lsystem.pupil.z,lsystem.pupil.y);

	glPopMatrix();
	glutSwapBuffers();
}
示例#8
0
//FIXME: Do we really need two versions of all of this code? (int/float)
void SkyQPainter::drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle)
{
    float x = pos.x();
    float y = pos.y();
    float zoom = Options::zoomFactor();

    int isize = int(size);

    float dx1 = -0.5*size;
    float dx2 =  0.5*size;
    float dy1 = -1.0*e*size/2.;
    float dy2 = e*size/2.;
    float x1 = x + dx1;
    float x2 = x + dx2;
    float y1 = y + dy1;
    float y2 = y + dy2;

    float dxa = -size/4.;
    float dxb =  size/4.;
    float dya = -1.0*e*size/4.;
    float dyb = e*size/4.;
    float xa = x + dxa;
    float xb = x + dxb;
    float ya = y + dya;
    float yb = y + dyb;

    float psize;

    QBrush tempBrush;

    switch ( type ) {
    case 0:
    case 1: //catalog star
        //Some NGC/IC objects are stars...changed their type to 1 (was double star)
        if (size<2.) size = 2.;
        if ( Options::useAntialias() )
            drawEllipse( QRectF(x1, y1, size/2., size/2.) );
        else
            drawEllipse( QRect(int(x1), int(y1), int(size/2), int(size/2)) );
        break;
    case 2: //Planet
        break;
    case 3: //Open cluster; draw circle of points
    case 13: // Asterism
        tempBrush = brush();
        setBrush( pen().color() );
        psize = 2.;
        if ( size > 50. )  psize *= 2.;
        if ( size > 100. ) psize *= 2.;
        if ( Options::useAntialias() ) {
            drawEllipse( QRectF(xa, y1, psize, psize) );
            drawEllipse( QRectF(xb, y1, psize, psize) );
            drawEllipse( QRectF(xa, y2, psize, psize) );
            drawEllipse( QRectF(xb, y2, psize, psize) );
            drawEllipse( QRectF(x1, ya, psize, psize) );
            drawEllipse( QRectF(x1, yb, psize, psize) );
            drawEllipse( QRectF(x2, ya, psize, psize) );
            drawEllipse( QRectF(x2, yb, psize, psize) );
        } else {
            int ix1 = int(x1); int iy1 = int(y1);
            int ix2 = int(x2); int iy2 = int(y2);
            int ixa = int(xa); int iya = int(ya);
            int ixb = int(xb); int iyb = int(yb);
            drawEllipse( QRect(ixa, iy1, int(psize), int(psize)) );
            drawEllipse( QRect(ixb, iy1, int(psize), int(psize)) );
            drawEllipse( QRect(ixa, iy2, int(psize), int(psize)) );
            drawEllipse( QRect(ixb, iy2, int(psize), int(psize)) );
            drawEllipse( QRect(ix1, iya, int(psize), int(psize)) );
            drawEllipse( QRect(ix1, iyb, int(psize), int(psize)) );
            drawEllipse( QRect(ix2, iya, int(psize), int(psize)) );
            drawEllipse( QRect(ix2, iyb, int(psize), int(psize)) );
        }
        setBrush( tempBrush );
        break;
    case 4: //Globular Cluster
        if (size<2.) size = 2.;
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system

        if ( Options::useAntialias() ) {
            drawEllipse( QRectF(dx1, dy1, size, e*size) );
            drawLine( QPointF(0., dy1), QPointF(0., dy2) );
            drawLine( QPointF(dx1, 0.), QPointF(dx2, 0.) );
            restore(); //reset coordinate system
        } else {
            int idx1 = int(dx1); int idy1 = int(dy1);
            int idx2 = int(dx2); int idy2 = int(dy2);
            drawEllipse( QRect(idx1, idy1, isize, int(e*size)) );
            drawLine( QPoint(0, idy1), QPoint(0, idy2) );
            drawLine( QPoint(idx1, 0), QPoint(idx2, 0) );
            restore(); //reset coordinate system
        }
        break;

    case 5: //Gaseous Nebula
    case 15: // Dark Nebula
        if (size <2.) size = 2.;
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system

        if ( Options::useAntialias() ) {
            drawLine( QPointF(dx1, dy1), QPointF(dx2, dy1) );
            drawLine( QPointF(dx2, dy1), QPointF(dx2, dy2) );
            drawLine( QPointF(dx2, dy2), QPointF(dx1, dy2) );
            drawLine( QPointF(dx1, dy2), QPointF(dx1, dy1) );
        } else {
            int idx1 = int(dx1); int idy1 = int(dy1);
            int idx2 = int(dx2); int idy2 = int(dy2);
            drawLine( QPoint(idx1, idy1), QPoint(idx2, idy1) );
            drawLine( QPoint(idx2, idy1), QPoint(idx2, idy2) );
            drawLine( QPoint(idx2, idy2), QPoint(idx1, idy2) );
            drawLine( QPoint(idx1, idy2), QPoint(idx1, idy1) );
        }
        restore(); //reset coordinate system
        break;
    case 6: //Planetary Nebula
        if (size<2.) size = 2.;
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system

        if ( Options::useAntialias() ) {
            drawEllipse( QRectF(dx1, dy1, size, e*size) );
            drawLine( QPointF(0., dy1), QPointF(0., dy1 - e*size/2. ) );
            drawLine( QPointF(0., dy2), QPointF(0., dy2 + e*size/2. ) );
            drawLine( QPointF(dx1, 0.), QPointF(dx1 - size/2., 0.) );
            drawLine( QPointF(dx2, 0.), QPointF(dx2 + size/2., 0.) );
        } else {
            int idx1 = int(dx1); int idy1 = int(dy1);
            int idx2 = int(dx2); int idy2 = int(dy2);
            drawEllipse( QRect( idx1, idy1, isize, int(e*size) ) );
            drawLine( QPoint(0, idy1), QPoint(0, idy1 - int(e*size/2) ) );
            drawLine( QPoint(0, idy2), QPoint(0, idy2 + int(e*size/2) ) );
            drawLine( QPoint(idx1, 0), QPoint(idx1 - int(size/2), 0) );
            drawLine( QPoint(idx2, 0), QPoint(idx2 + int(size/2), 0) );
        }

        restore(); //reset coordinate system
        break;
    case 7: //Supernova remnant
        if (size<2) size = 2;
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system

        if ( Options::useAntialias() ) {
            drawLine( QPointF(0., dy1), QPointF(dx2, 0.) );
            drawLine( QPointF(dx2, 0.), QPointF(0., dy2) );
            drawLine( QPointF(0., dy2), QPointF(dx1, 0.) );
            drawLine( QPointF(dx1, 0.), QPointF(0., dy1) );
        } else {
            int idx1 = int(dx1); int idy1 = int(dy1);
            int idx2 = int(dx2); int idy2 = int(dy2);
            drawLine( QPoint(0, idy1), QPoint(idx2, 0) );
            drawLine( QPoint(idx2, 0), QPoint(0, idy2) );
            drawLine( QPoint(0, idy2), QPoint(idx1, 0) );
            drawLine( QPoint(idx1, 0), QPoint(0, idy1) );
        }

        restore(); //reset coordinate system
        break;
    case 8: //Galaxy
    case 16: // Quasar
        if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20
        if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5
        if ( size>2. ) {
            save();
            translate( x, y );
            rotate( positionAngle );  //rotate the coordinate system

            if ( Options::useAntialias() ) {
                drawEllipse( QRectF(dx1, dy1, size, e*size) );
            } else {
                int idx1 = int(dx1); int idy1 = int(dy1);
                drawEllipse( QRect(idx1, idy1, isize, int(e*size)) );
            }

            restore(); //reset coordinate system

        } else if ( size>0. ) {
            drawPoint( QPointF(x, y) );
        }
        break;
    case 14: // Galaxy cluster - draw a circle of + marks
        tempBrush = brush();
        setBrush( pen().color() );
        psize = 1.;
        if ( size > 50. )  psize *= 2.;

        if ( Options::useAntialias() ) {
            drawLine( QLineF( xa - psize, y1, xa + psize, y1 ) );
            drawLine( QLineF( xa, y1 - psize, xa, y1 + psize ) );
            drawLine( QLineF( xb - psize, y1, xb + psize, y1 ) );
            drawLine( QLineF( xb, y1 - psize, xb, y1 + psize ) );
            drawLine( QLineF( xa - psize, y2, xa + psize, y2 ) );
            drawLine( QLineF( xa, y2 - psize, xa, y2 + psize ) );
            drawLine( QLineF( xb - psize, y2, xb + psize, y2 ) );
            drawLine( QLineF( xb, y2 - psize, xb, y2 + psize ) );
            drawLine( QLineF( x1 - psize, ya, x1 + psize, ya ) );
            drawLine( QLineF( x1, ya - psize, x1, ya + psize ) );
            drawLine( QLineF( x1 - psize, yb, x1 + psize, yb ) );
            drawLine( QLineF( x1, yb - psize, x1, yb + psize ) );
            drawLine( QLineF( x2 - psize, ya, x2 + psize, ya ) );
            drawLine( QLineF( x2, ya - psize, x2, ya + psize ) );
            drawLine( QLineF( x2 - psize, yb, x2 + psize, yb ) );
            drawLine( QLineF( x2, yb - psize, x2, yb + psize ) );
        } else {
            int ix1 = int(x1); int iy1 = int(y1);
            int ix2 = int(x2); int iy2 = int(y2);
            int ixa = int(xa); int iya = int(ya);
            int ixb = int(xb); int iyb = int(yb);
            drawLine( QLineF( ixa - int(psize), iy1, ixa + int(psize), iy1 ) );
            drawLine( QLineF( ixa, iy1 - int(psize), ixa, iy1 + int(psize) ) );
            drawLine( QLineF( ixb - int(psize), iy1, ixb + int(psize), iy1 ) );
            drawLine( QLineF( ixb, iy1 - int(psize), ixb, iy1 + int(psize) ) );
            drawLine( QLineF( ixa - int(psize), iy2, ixa + int(psize), iy2 ) );
            drawLine( QLineF( ixa, iy2 - int(psize), ixa, iy2 + int(psize) ) );
            drawLine( QLineF( ixb - int(psize), iy2, ixb + int(psize), iy2 ) );
            drawLine( QLineF( ixb, iy2 - int(psize), ixb, iy2 + int(psize) ) );
            drawLine( QLineF( ix1 - int(psize), iya, ix1 + int(psize), iya ) );
            drawLine( QLineF( ix1, iya - int(psize), ix1, iya + int(psize) ) );
            drawLine( QLineF( ix1 - int(psize), iyb, ix1 + int(psize), iyb ) );
            drawLine( QLineF( ix1, iyb - int(psize), ix1, iyb + int(psize) ) );
            drawLine( QLineF( ix2 - int(psize), iya, ix2 + int(psize), iya ) );
            drawLine( QLineF( ix2, iya - int(psize), ix2, iya + int(psize) ) );
            drawLine( QLineF( ix2 - int(psize), iyb, ix2 + int(psize), iyb ) );
            drawLine( QLineF( ix2, iyb - int(psize), ix2, iyb + int(psize) ) );
        }
        setBrush( tempBrush );
        break;
    }
}
示例#9
0
/**
 * @function showCorrespondences
 */
void Tensor3D::showCorrespondences() {
  
  // Create images
  mCorrImages.resize(0);

  for( int i = 0; i < mRgbImages.size(); ++i ) {
    cv::Mat image = mRgbImages[i].clone();
    mCorrImages.push_back(image);
  }

  cv::Scalar color; 

  // Draw PPP
  for( int i = 0; i < mPPP.size(); ++i ) {
    color = cv::Scalar( mRng.uniform(0, 255), mRng.uniform(0,255), mRng.uniform(0,255) );
    drawPoint( mPPP[i][0], mCorrImages[0], color );
    drawPoint( mPPP[i][1], mCorrImages[1], color );
    drawPoint( mPPP[i][2], mCorrImages[2], color );
  }
  
  // Draw LLL 
  for( int i = 0; i < mLLL.size(); ++i ) {
    color = cv::Scalar( mRng.uniform(0, 255), mRng.uniform(0,255), mRng.uniform(0,255) );
    drawLine( mLLL[i][0], mCorrImages[0], color );
    drawLine( mLLL[i][1], mCorrImages[1], color );
    drawLine( mLLL[i][2], mCorrImages[2], color );
  }

  // Draw PLP  
  for( int i = 0; i < mPLP.size(); ++i ) {
    color = cv::Scalar( mRng.uniform(0, 255), mRng.uniform(0,255), mRng.uniform(0,255) );
    drawPoint( mPLP[i][0], mCorrImages[0], color );
    drawLine( mPLP[i][1], mCorrImages[1], color );
    drawPoint( mPLP[i][2], mCorrImages[2], color );
  }

  // Draw PLL 
  for( int i = 0; i < mPLL.size(); ++i ) {
    color = cv::Scalar( mRng.uniform(0, 255), mRng.uniform(0,255), mRng.uniform(0,255) );
    drawPoint( mPLL[i][0], mCorrImages[0], color );
    drawLine( mPLL[i][1], mCorrImages[1], color );
    drawLine( mPLL[i][2], mCorrImages[2], color );
  }
  
  // Draw CorrImages
  for( int i = 0; i < mCorrImages.size(); ++i ) {
    char windowName[50];
    int n = sprintf( windowName, "Corresp-%d", i );
    cv::namedWindow( windowName, CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO );
    cv::imshow( windowName, mCorrImages[i] );
  }
    
  // Press a key to keep with the program
  int key;
  while(  true ) {
    key = cv::waitKey(30);
    if( key != -1 ) {
      break;
    }
  }
  
}
示例#10
0
文件: main.c 项目: Phillrb/vecpong
void runGameplay(GameVars* gameVars)
{
    //GAME
    
    //Draw the court
    drawCourt();
    
    //Draw the scores
    drawScores(gameVars);
    
    //Game play states
    switch (gameVars->gameState) {
        case GSGameStart:
        {
#ifdef DEBUG
            debugPrint("START\x80");
#endif
            //Draw Ready message
            drawReady(0x80);
            
            //Wait for a number of frames
            waitForFramesThenMoveOnToNextState(60, gameVars);
        }
            break;
            
        case GSWaitForServe:
        {
#ifdef DEBUG
            debugPrint("SERVE\x80");
#endif
            //Score max?
            if (gameVars->player1.score >= maxScoreForPlayer
                || gameVars->player2.score >= maxScoreForPlayer)
            {
                //Served - move to next state
                moveToNextGameState(gameVars, GEWinner);
                return;
            }
            
            //Draw player paddles
            movePaddles(gameVars);

            //Inform who is about to serve
            drawServe(gameVars->player1ServeNext);
            
            //wait for user to start game with button 4
            readButton();
            
            //Player 1 Button 4 or P2 Button 4
            if (
                (gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY1_B4))
                ||
                (!gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY2_B4))
                )
            {
                //Position the ball and make visible
                serve(gameVars);
                
                //Served - move to next state
                moveToNextGameState(gameVars, GENone);
            }

        }
            break;
            
        case GSPlay:
        {
#ifdef DEBUG
            debugPrint("PLAY\x80");
#endif
            //GAME PLAY ACTION
            
            drawCenterLine(gameVars);
            
            //Draw player paddles
            movePaddles(gameVars);
            
            //Only deal with visible balls
            if(gameVars->ball.visibility == false) return;
            
            //Move ball - check for goal
            moveBallSprite(gameVars);
        }
            break;
            
        case GSScored:
        {
#ifdef DEBUG
            debugPrint("SCORED\x80");
#endif
            //Goal!
            drawPoint(!gameVars->player1ServeNext);
            
            waitForFramesThenMoveOnToNextState(60, gameVars);
        }
            break;
            
        case GSGameOver:
        {
#ifdef DEBUG
            debugPrint("GAMEOVER\x80");
#endif
            //Display 'Game Over'
            drawGameOver(gameVars->player1.score > gameVars->player2.score);
            
            //wait for user to select replay or menu
            readButton();
            //Player 1 Button 1
            if (_BTN_CUR_MASK & _JOY1_B1)
            {
                //Reset scores
                resetPlayerScores(gameVars);
                
                //Replay - move to next state
                moveToNextGameState(gameVars, GEPlayAgain);
            }
            else if (_BTN_CUR_MASK & _JOY1_B2)
            {
                //Reset scores
                resetPlayerScores(gameVars);
                
                //Menu - move to next state
                moveToNextGameState(gameVars, GEBackToMenu);
            }
        }
            break;
            
        default:
            break;
    }
    
}
示例#11
0
//----------------------------------------------------------------------------------------------------------------------
void SMCAgentViz::update()
{
  glDisable(GL_DEPTH_TEST);
  
  // data
  const ci::Vec2f& pos = m_agent->getPosition();
  float angle = m_agent->getAngle();
  
  // Update trajectory
  if(!m_paused && m_steps % 2 == 0){
    m_traj.push_back(pos);
  
    if(m_traj.size() >= 800)
    {
      m_traj.pop_front();
    }
  }
  
  m_steps++;
  
  // pose
  m_pTM->setToIdentity();  
  m_pTM->setTranslate(ci::Vec3f(pos));  
  m_pTM->rotate(ci::Vec3f(0.0f, 0.0f, 1.0f), angle);

  NodeGroup::update();
  
  // draw
  glPushAttrib(GL_LIGHTING);
  glDisable(GL_LIGHTING);
  
  // Trajectory
  ci::ColorA trajCol (235.0/255.0, 89.0/255.0, 55.0/255.0, 1.0);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);
  int numPoints =  m_traj.size();
  float lineVerts[numPoints*2];
  float colors[numPoints*4];
  glVertexPointer(2, GL_FLOAT, 0, lineVerts); // 2d positions
  glColorPointer(4, GL_FLOAT, 0, colors);     // 4d colors
  
  for(size_t i = 0; i < numPoints; i++)
  {
    lineVerts[i*2 + 0] = m_traj[i].x;
    lineVerts[i*2 + 1] = m_traj[i].y;
    float a = (float)i / (float)numPoints;
    
    colors[i*4 + 0] = trajCol[0];
    colors[i*4 + 1] = trajCol[1];
    colors[i*4 + 2] = trajCol[2];
    colors[i*4 + 3] = a;
  }
  glLineWidth(2.0);
  glDrawArrays( GL_LINE_STRIP, 0, numPoints);
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);
  glLineWidth(1.0);
  
  // This is in world space
  glColor3f(0, 0, 0);
  const float velScale = 0.1f;
  glLineWidth(2.0);
  ci::gl::drawLine(m_agent->getPosition(), m_agent->getPosition() + m_agent->getVelocity() * velScale);
  glLineWidth(1.0);
  
  if(m_agent->hasDistanceSensor())
  {
    DistanceSensor* sensor = m_agent->getDistanceSensor();
    float sensedDistance = sensor->getDistance();
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(2, 0xAAAA);
    glColor3f(0.2, 0.2, 0.2);    
    ci::gl::drawLine(sensor->getPosition(), sensor->getPosition() + sensor->getDirection() * sensedDistance);
    glDisable(GL_LINE_STIPPLE);
    
    glColor3f(1,0,0);
    if(sensedDistance < sensor->getMaxDistance())
    {
      drawPoint(ci::Vec3f(sensor->getCollision()), 5.0f);
    }
    
    // Sensor in local space
    glPushMatrix();
    glMultMatrixf(*m_pTM);
    glTranslatef(m_agent->getRadius(), 0, 0.001);
    float act = m_agent->getDistanceSensor()->getDistanceProportional();
    glColor3f(act,act,act);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_FILL);
    glColor3f(0,0,0);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_SILHOUETTE);
    glPopMatrix();
  }
  
  if(m_agent->hasGradientSensor())
  {
    GradientSensor* sensor = m_agent->getGradientSensor();
    float s = 1.0f - sensor->getActivation();
    
    // Sensor in local space
    glPushMatrix();
    glTranslatef(sensor->getPosition().x, sensor->getPosition().y, 0.0);
    glColor3f(s,s,s);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_FILL);
    glColor3f(0,0,0);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_SILHOUETTE);
    glPopMatrix();
  }
  
  if(m_agent->hasTorusSensor())
  {
    Sensor* sensor = m_agent->getTorusSensor();
    float s = 1.0f - sensor->getActivation();
    
    // Sensor in local space
    glPushMatrix();
    glTranslatef(sensor->getPosition().x, sensor->getPosition().y, 0.0);
    glColor3f(s,s,s);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_FILL);
    glColor3f(0,0,0);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_SILHOUETTE);
    glPopMatrix();
  }

  
  // draw positional range
  if(m_agent->positionWraps())
  {
    float p = m_agent->getMaxPosition();
    ci::gl::drawStrokedRect(ci::Rectf(ci::Vec2f(-p,-p), ci::Vec2f(p,p)));
  }

  // Change body color depending on energy level
  ci::Vec3f col = getColorMapRainbow(m_agent->getEnergy() / 5);
  ci::Vec4f col4 = ci::Vec4f(col);
  col4[3] = 0.5;
  m_agentDisk->m_color = col4;
  
  glPopAttrib();
  glEnable(GL_DEPTH_TEST);
}
示例#12
0
void SkyQPainter::drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle)
{
    float x = pos.x();
    float y = pos.y();
    float zoom = Options::zoomFactor();

    int isize = int(size);

    float dx1 = -0.5*size;
    float dx2 =  0.5*size;
    float dy1 = -1.0*e*size/2.;
    float dy2 = e*size/2.;
    float x1 = x + dx1;
    float x2 = x + dx2;
    float y1 = y + dy1;
    float y2 = y + dy2;

    float dxa = -size/4.;
    float dxb =  size/4.;
    float dya = -1.0*e*size/4.;
    float dyb = e*size/4.;
    float xa = x + dxa;
    float xb = x + dxb;
    float ya = y + dya;
    float yb = y + dyb;

    QString color;

    float psize;

    QBrush tempBrush;

    std::function<void( float, float, float, float )> lambdaDrawEllipse;
    std::function<void( float, float, float, float )> lambdaDrawLine;
    std::function<void( float, float, float, float )> lambdaDrawCross;

    if ( Options::useAntialias() ) {
        lambdaDrawEllipse = [this]( float x, float y, float width, float height ) {
            drawEllipse( QRectF( x, y, width, height ) );
        };
        lambdaDrawLine = [this]( float x1, float y1, float x2, float y2 ) {
            drawLine( QLineF( x1, y1, x2, y2 ) );
        };
        lambdaDrawCross = [this]( float centerX, float centerY, float sizeX, float sizeY ) {
            drawLine( QLineF( centerX - sizeX/2., centerY, centerX + sizeX/2., centerY ) );
            drawLine( QLineF( centerX, centerY - sizeY/2., centerX, centerY + sizeY/2. ) );
        };
    }
    else {
        lambdaDrawEllipse = [this]( float x, float y, float width, float height ) {
            drawEllipse( QRect( x, y, width, height ) );
        };
        lambdaDrawLine = [this]( float x1, float y1, float x2, float y2 ) {
            drawLine( QLine( x1, y1, x2, y2 ) );
        };
        lambdaDrawCross = [this]( float centerX, float centerY, float sizeX, float sizeY ) {
            drawLine( QLine( centerX - sizeX/2., centerY, centerX + sizeX/2., centerY ) );
            drawLine( QLine( centerX, centerY - sizeY/2., centerX, centerY + sizeY/2. ) );
        };
    }

    switch ( type ) {
    case 0:
    case 1: //catalog star
        //Some NGC/IC objects are stars...changed their type to 1 (was double star)
        if (size<2.) size = 2.;
        lambdaDrawEllipse( x1, y1, size/2., size/2. );
        break;
    case 2: //Planet
        break;
    case 3: //Open cluster; draw circle of points
    case 13: { // Asterism
        tempBrush = brush();
        color = pen().color().name();
        setBrush( pen().color() );
        psize = 2.;
        if ( size > 50. )  psize *= 2.;
        if ( size > 100. ) psize *= 2.;
        auto putDot = [this, psize, &lambdaDrawEllipse]( float x, float y ) {
            lambdaDrawEllipse( x, y, psize, psize );
        };
        putDot( xa, y1 );
        putDot( xb, y1 );
        putDot( xa, y2 );
        putDot( xb, y2 );
        putDot( x1, ya );
        putDot( x1, yb );
        putDot( x2, ya );
        putDot( x2, yb );
        setBrush( tempBrush );
        break;
    }
    case 4: //Globular Cluster
        if (size<2.) size = 2.;
        save();
        translate( x, y );
        color = pen().color().name();
        rotate( positionAngle );  //rotate the coordinate system
        lambdaDrawEllipse( dx1, dy1, size, e*size );
        lambdaDrawCross( 0, 0, size, e*size );
        restore(); //reset coordinate system
        break;

    case 5: //Gaseous Nebula
    case 15: // Dark Nebula
        if (size <2.) size = 2.;
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system
        color = pen().color().name();
        lambdaDrawLine( dx1, dy1, dx2, dy1 );
        lambdaDrawLine( dx2, dy1, dx2, dy2 );
        lambdaDrawLine( dx2, dy2, dx1, dy2 );
        lambdaDrawLine( dx1, dy2, dx1, dy1 );
        restore(); //reset coordinate system
        break;
    case 6: //Planetary Nebula
        if (size<2.) size = 2.;
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system
        color = pen().color().name();
        lambdaDrawEllipse( dx1, dy1, size, e*size );
        lambdaDrawLine( 0., dy1, 0., dy1 - e*size/2. );
        lambdaDrawLine( 0., dy2, 0., dy2 + e*size/2. );
        lambdaDrawLine( dx1, 0., dx1 - size/2., 0. );
        lambdaDrawLine( dx2, 0., dx2 + size/2., 0. );
        restore(); //reset coordinate system
        break;
    case 7: //Supernova remnant // FIXME: Why is SNR drawn different from a gaseous nebula?
        if (size<2) size = 2;
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system
        color = pen().color().name();
        lambdaDrawLine( 0., dy1, dx2, 0. );
        lambdaDrawLine( dx2, 0., 0., dy2 );
        lambdaDrawLine( 0., dy2, dx1, 0. );
        lambdaDrawLine( dx1, 0., 0., dy1 );
        restore(); //reset coordinate system
        break;
    case 8: //Galaxy
    case 16: // Quasar
        color = pen().color().name();
        if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20
        if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5
        if ( size>2. ) {
            save();
            translate( x, y );
            rotate( positionAngle );  //rotate the coordinate system
            lambdaDrawEllipse( dx1, dy1, size, e*size );
            restore(); //reset coordinate system

        } else if ( size>0. ) {
            drawPoint( QPointF(x, y) );
        }
        break;
    case 14: { // Galaxy cluster - draw a dashed circle
        tempBrush = brush();
        setBrush( QBrush() );
        psize = 1.;
        if ( size > 50. )  psize *= 2.;
        color = pen().color().name();
        save();
        translate( x, y );
        rotate( positionAngle );  //rotate the coordinate system
        QPen newPen = pen();
        newPen.setStyle( Qt::DashLine );
        setPen( newPen );
        lambdaDrawEllipse( dx1, dy1, size, e*size );
        restore();
        setBrush( tempBrush );
        break;
    }
    default: // Unknown object or something we don't know how to draw. Just draw an ellipse with a ?-mark
        color = pen().color().name();
        if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20
        if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5
        if ( size>2. ) {
            save();
            QFont f = font();
            const QString qMark = " ? ";
            double scaleFactor = 0.8 * size / fontMetrics().width( qMark );
            f.setPointSizeF( f.pointSizeF() * scaleFactor );
            setFont( f );
            translate( x, y );
            rotate( positionAngle );  //rotate the coordinate system
            lambdaDrawEllipse( dx1, dy1, size, e*size );
            if ( Options::useAntialias() )
                drawText( QRectF(dx1, dy1, size, e*size), Qt::AlignCenter, qMark );
            else {
                int idx1 = int(dx1); int idy1 = int(dy1);
                drawText( QRect(idx1, idy1, isize, int(e*size)), Qt::AlignCenter, qMark );
            }
            restore(); //reset coordinate system (and font?)
        }
        else if ( size>0. ) {
            if ( Options::useAntialias() )
                drawPoint( QPointF(x, y) );
            else
                drawPoint( QPoint( x, y ) );
        }
    }

}
示例#13
0
	// рисует круг
	void Form1::drawCircle(int R, int shiftX, int shiftY)
	{
		int x = 0, y = R, d = 2*(1-R), lim = 0;

		int eps = 2;

		canvas()->DrawEllipse(circlePen, shiftX - R - eps, shiftY - R - eps, 2*R, 2*R);

		while(true)
		{
			drawPoint(shiftX + x, shiftY + y);
			drawPoint(shiftX + x, shiftY - y);
			drawPoint(shiftX - x, shiftY + y);
			drawPoint(shiftX - x, shiftY - y);

			int flag = 0;

			if(y <= lim)
				return;
			else
			{
				flag = 0;
				int temp = 0;

				if(d < 0)
				{
					temp = 2*d + 2*y - 1;
					if(temp <= 0)
						flag = 2;
					else
						flag = 1;
				}
				else
				{
					if(d > 0)
					{
						temp = 2*d - 2*x - 1;

						if(temp <= 0)
							flag = 1;
						else
							flag = 0;
					}
					else
					{
						flag = 1;
					}
				}
			}

			switch(flag)
			{
			case 0:
				y--;
				d = d - 2*y + 1;
				;break;

			case 1:
				y--;
				x++;
				d = d - 2*y + 2 + 2*x;
				;break;


			case 2:
				x++;
				d = d + 2*x + 1;
				;break;
			}
		}
	}
示例#14
0
void drawLine(bsCurve cv) {
    float x1, x2, y1, y2, sp, sp2;
    float slope;
    float newx, newy;
    y1 = y2 = x1 = x2 = 0;
    Vector3 red(1,0,0);
    Vector3 green(0,1,0);
    Vector3 color;
    if (cv.ctype == 0)
        color = red;
    else
        color = green;
    for (int i = 0; i < cv.numctrlpts - 1; i++)
    {        
        x1 = cv.ctrlpts[i].x;
        y1 = cv.ctrlpts[i].y;
        x2 = cv.ctrlpts[i + 1].x;
        y2 = cv.ctrlpts[i + 1].y;

        
        
        if(x1 == x2) {
            if (y2 < y1) {
                sp = y1;
                y1 = y2;
                y2 = sp;
            }
            for (int i = y1; i < y2; i++) {
                drawPoint(x1, i, color);
            }
        }
        else if(y1 == y2) {
            if (x2 < x1) {
                sp = x1;
                x1 = x2;
                x2 = sp;
            }
            for (int i = x1; i < x2; i++) {
                drawPoint(i, y1, color);
            }
        }
        else if ((y2-y1)/(x2-x1) <= 1 && (y2-y1)/(x2-x1) >= -1) {
            if(x2 < x1) {
                sp = x1;
                sp2 = y1;
                x1 = x2;
                y1 = y2;
                x2 = sp;
                y2 = sp2;
            }
            slope = (y2-y1)/(x2-x1);
            newy = y1;
            for (int i = x1+1; i < x2; i++) {
                newy += slope;
                drawPoint(i, rounder(newy), color);
            }
        }
        else if ((float)(y2-y1)/(x2-x1) > 1 || (float)(y2-y1)/(x2-x1) < -1) {
            if(y2 < y1) {
                sp = x1;
                sp2 = y1;
                x1 = x2;
                y1 = y2;
                x2 = sp;
                y2 = sp2;
            }
            slope = (x2-x1)/(y2-y1);
            newx = x1;
            for (int i = y1 + 1; i < y2; i++) {
                newx += slope;
                drawPoint(rounder(newx), i, color);
            }
        }
    }
}
示例#15
0
void FeatureCoordinates::drawEllipse(cv::Mat& drawImg, const cv::Scalar& color, double scaleFactor, const bool withCenterPoint) const {
    if(withCenterPoint) drawPoint(drawImg,color);
    cv::ellipse(drawImg,get_c(),cv::Size(std::max(static_cast<int>(scaleFactor*sigma1_+0.5),1),std::max(static_cast<int>(scaleFactor*sigma2_+0.5),1)),sigmaAngle_*180/M_PI,0,360,color,1,8,0);
}
示例#16
0
//--------------------------------------------------------------
void ofApp::draw(){

	float lineHeight = ofMap(mouseY, 0, ofGetHeight(), 0, 2, true);
	unicodeFont.setLineHeight(lineHeight);

	float x = 30;
	float y = 40;
	
	string demoText = "This is my text in BitStream Vera font.";
	float fontSize = 28;

	// simple demo //////////////////////////////////////////////////////////
	
	drawPoint(x, y);		//draw insertion point	

	ofSetColor(255);
	TIME_SAMPLE_START("simple draw");
	font.draw(
				  demoText,	//text to draw
				  fontSize,	//font size
				  x,		//x coord where to draw
				  y			//y coord where to draw
			  );
	TIME_SAMPLE_STOP("simple draw");

	// bounding box demo ///////////////////////////////////////////////////
	ofRectangle bbox;
	ofRectangle bboxMultiline;

	ofSetColor(255, 0, 0, 32);
	TIME_SAMPLE_START("bbox");
	bbox = font.getBBox( demoText, fontSize, x, y);
	TIME_SAMPLE_STOP("bbox");
	ofRect( bbox );

	// draw multiline text /////////////////////////////////////////////////
	
	y += 25 + bbox.height;
	drawPoint(x, y); //draw insertion point	
	
	ofSetColor(255);
	string s = (string)"ofxFontStash can draw multiline text" + "\n" +
	"It also supports unicode strings: " + "\n" +
	"槊監しゅ祟䤂לרפובליקה. אם מיזם 銆銌 憉 圩芰敔 तकनिकल कार्यलय";

	TIME_SAMPLE_START("drawMultiLine");
	unicodeFont.drawMultiLine( s,  fontSize, x, y);
	TIME_SAMPLE_STOP("drawMultiLine");
	
	// multiline bbox /////////////////////////////////////////////////////

	ofSetColor(0, 255, 0, 32);
	TIME_SAMPLE_START("getBoundingBoxSize");
	bboxMultiline = unicodeFont.getBBox( s, fontSize, x, y);
	TIME_SAMPLE_STOP("getBoundingBoxSize");
	ofRect( bboxMultiline );


	// draw multiline column with a fixed width ///////////////////////////

	y += 25 + bboxMultiline.height;
	drawPoint(x, y); //draw insertion point

	ofSetColor(255);
	s = "And you can wrap text to a certain (mouseX) width:\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.";
	//s = "international bananas";

	int numLines = 0;
	bool wordsWereCropped;
	ofRectangle column;
	TIME_SAMPLE_START("drawMultiLineColumn");
	column = font.drawMultiLineColumn(	s,			/*string*/
										fontSize,	/*size*/
										x, y,		/*where*/
										MAX( 10 ,mouseX - x), /*column width*/
										numLines,	/*get back the number of lines*/
										false,		/* if true, we wont draw (just get bbox back) */
										5,			/* max number of lines to draw, crop after that */
										true,		/*get the final text formatting (by adding \n's) in the supplied string;
													 BE ARWARE that using TRUE in here will modify your supplied string! */
										&wordsWereCropped /* this bool will b set to true if the box was to small to fit all text*/
									 );
	TIME_SAMPLE_STOP("drawMultiLineColumn");


	//report if some words had to be cropped to fit in the column when using drawMultiLineColumn()
	if(!wordsWereCropped) ofSetColor(255,32);
	else (ofGetFrameNum()%6 <= 2) ? ofSetColor(255,32):ofSetColor(255,0,0,32); //flash if cropped
	ofRect(column);


	// batch drawing, optimized for multiple drawing calls /////////////////

	y += column.height + 25;
	drawPoint(x, y); //draw insertion point

	ofSetColor(255);
	TIME_SAMPLE_START("drawBatch");
	font.beginBatch();	//call "begin" before drawing fonts
	for (int i = 0; i < 5; i++){
		font.drawBatch("batch mode #" + ofToString(i+1), fontSize, x, y + i * fontSize );
	}
	font.endBatch();		//call "end" once finished
	TIME_SAMPLE_STOP("drawBatch");

	// formatted text //////////////////////////////////////////////////////

	string formattedText = "the #0xff0000 @1 %2.0 red %1.0 #0xffffff @0 apple is on the big %4.0 #0x00ff00 tree.";

	ofPushMatrix();
	ofTranslate(20,500);
	ofSetColor(255);
	ofVec2f size = font.drawMultiColumnFormatted(formattedText, 22, mouseX);
	ofSetColor(255,10);
	ofRect(0, 0, size.x, size.y);
	ofPopMatrix();


	// rotating text ///////////////////////////////////////////////////////
	
	ofPushMatrix();
		ofTranslate(x + 400, y + 50);
		ofRotate( -200 * ofGetElapsedTimef(), 0, 0, 1);
		ofSetColor(ofRandom(255), ofRandom(255), ofRandom(255));
		font.draw("surrealismoooo!", fontSize, 0, 0 );
		drawPoint(0,0);
	ofPopMatrix();

	// scaling text with mipmaps ///////////////////////////////////////////

	ofPushMatrix();
	ofTranslate(600, 40);
	float scale = mouseY /(float) ofGetHeight();
	ofPushMatrix();
	ofScale(scale, scale);
	ofSetColor(255);
	unicodeFont.draw("MIPMAPS :)", fontSize * 2, 0, 0 );
	drawPoint(0,0);
	ofPopMatrix();

	ofTranslate(0, 30);
	ofScale(scale, scale);
	font.draw("NO MIPMAPS :(", fontSize * 2, 0, 0 );
	drawPoint(0,0);
	ofPopMatrix();


}
示例#17
0
#include <QDateTime>
#include <QFileDialog>
#include <QMessageBox>
#include <QTextEdit>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setupUi(this);
    setWindowTitle(tr("GD CAD"));
    newFile();

    qApp->installEventFilter(this);

<<<<<<< HEAD
    connect(ui->pointButton, SIGNAL(clicked()), this, SLOT(drawPoint()));
    connect(ui->lineButton, SIGNAL(clicked()), this, SLOT(drawLine()));
    connect(ui->circleButton, SIGNAL(clicked()), this, SLOT(drawCircle()));
    connect(ui->ellipseButton, SIGNAL(clicked()), this, SLOT(drawEllipse()));
    connect(ui->arcButton, SIGNAL(clicked()),this, SLOT(drawArc()));
    connect(ui->polylineButton, SIGNAL(clicked()),this, SLOT(drawPolyline()));


    connect(ui->actionPoints, SIGNAL(triggered()), this, SLOT(drawPoint()));
    connect(ui->actionLine, SIGNAL(triggered()), this, SLOT(drawLine()));
    connect(ui->actionCircle, SIGNAL(triggered()), this, SLOT(drawCircle()));
    connect(ui->actionEllipse, SIGNAL(triggered()), this, SLOT(drawEllipse()));

    connect(ui->actionArc, SIGNAL(triggered()), this, SLOT(drawArc()));
    connect(ui->actionPolyline, SIGNAL(triggered()), this, SLOT(drawPolyline()));
示例#18
0
void
pamd_circle(tuple **      const tuples, 
            unsigned int  const cols, 
            unsigned int  const rows, 
            unsigned int  const depth, 
            sample        const maxval, 
            pamd_point    const center,
            unsigned int  const radius, 
            pamd_drawproc       drawProc,
            const void *  const clientData) {
/*----------------------------------------------------------------------------
  If lineclip mode is on, draw only points within the image.
  If lineclip is off, "draw" all points (by designated drawproc).  Note
  that the drawproc can't actually draw a point outside the image, but
  it might maintain state that is affected by imaginary points outside
  the image.

  Initial point is 3 o'clock. 
-----------------------------------------------------------------------------*/
    if (radius >= DDA_SCALE)
        pm_error("Error drawing circle.  Radius %d is too large.", radius);

    pamd_validateCoord(center.x + radius);
    pamd_validateCoord(center.y + radius);
    pamd_validateCoord(center.x - radius);
    pamd_validateCoord(center.y - radius);

    if (radius > 0) {
        long const e = DDA_SCALE / radius;

        pamd_point const p0 = makePoint(radius, 0);  /* 3 o'clock */
            /* The starting point around the circle, assuming (0, 0) center */
        pamd_point p;
            /* Current drawing position in the circle, assuming (0,0) center */
        bool onFirstPoint;
        bool prevPointExists;
        pamd_point prevPoint;
            /* Previous drawing position, assuming (0, 0) center*/
        long sx, sy;  /* 'p', scaled by DDA_SCALE */

        p = p0;

        sx = p.x * DDA_SCALE + DDA_SCALE / 2;
        sy = p.y * DDA_SCALE + DDA_SCALE / 2;

        onFirstPoint = TRUE;
        prevPointExists = FALSE;

        while (onFirstPoint || !pointsEqual(p, p0)) {
            if (prevPointExists && pointsEqual(p, prevPoint)) {
                /* We're on the same point we were on last time (we moved less
                   than a point's worth).  Just keep moving.
                */
            } else {
                pamd_point const imagePoint = vectorSum(center,p);
                if (!lineclip || pointIsWithinBounds(imagePoint, cols, rows))
                    drawPoint(drawProc, clientData,
                              tuples, cols, rows, depth, maxval, imagePoint);

                prevPoint = p;
                prevPointExists = TRUE;
            }

            if (!pointsEqual(p, p0))
                onFirstPoint = FALSE;

            sx += e * sy / DDA_SCALE;
            sy -= e * sx / DDA_SCALE;
            p = makePoint(sx / DDA_SCALE, sy / DDA_SCALE);
        }
    }
}