Exemple #1
0
//Display functions
void display(float interval)
{
  int i;
  const VGfloat *style;
  VGfloat clearColor[] = {1,1,1,1};
  
  if (animate) {
    ang += interval * 360 * 0.1f;
    if (ang > 360) ang -= 360;
  }
  
  vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
  vgClear(0,0,testWidth(),testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  vgTranslate(testWidth()/2 + tx,testHeight()/2 + ty);
  vgScale(sx, sy);
  vgRotate(ang);
  
  for (i=0; i<pathCount; ++i) {
    
    style = styleArrays[i];
    vgSetParameterfv(tigerStroke, VG_PAINT_COLOR, 4, &style[0]);
    vgSetParameterfv(tigerFill, VG_PAINT_COLOR, 4, &style[4]);
    vgSetf(VG_STROKE_LINE_WIDTH, style[8]);
    vgDrawPath(tigerPaths[i], (VGint)style[9]); // Bingo!!, Draw it!! 
  }
  vgFlush();
}
Exemple #2
0
void display(float interval)
{
  VGfloat cc[] = {0,0,0,1};
  
  vgSetfv(VG_CLEAR_COLOR, 4, cc);
  vgClear(0,0,testWidth(),testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
  vgLoadIdentity();
  vgTranslate(tx, ty);
  vgRotate(ang);
  vgScale(sx, sy);
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  
  vgSetPaint(radialFill, VG_FILL_PATH);
  vgDrawPath(p, VG_FILL_PATH);
  
  vgTranslate(tx, ty);
  vgRotate(ang);
  vgScale(sx, sy);
  
  vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH);
  vgDrawPath(radius, VG_STROKE_PATH);
  vgDrawPath(center, VG_STROKE_PATH);
  vgDrawPath(focus, VG_FILL_PATH);
}
Exemple #3
0
int main(int argc, char **argv)
{
  testInit(argc, argv, 400,400, "ShivaVG: Radial Gradient Test");
  testCallback(TEST_CALLBACK_DISPLAY, (CallbackFunc)display);
  testCallback(TEST_CALLBACK_BUTTON, (CallbackFunc)click);
  testCallback(TEST_CALLBACK_DRAG, (CallbackFunc)drag);
  testCallback(TEST_CALLBACK_KEY, (CallbackFunc)key);
  
  p = testCreatePath();
  center = testCreatePath();
  focus = testCreatePath();
  radius = testCreatePath();
  
  cx = testWidth()/2;
  cy = testHeight()/2;
  fx = cx;
  fy = cy;
  r = sqx/2;
  
  radialFill = vgCreatePaint();
  blackFill = vgCreatePaint();
  vgSetParameterfv(blackFill, VG_PAINT_COLOR, 4, black);
  
  createSquare(p);
  createRadial();
  
  testOverlayString("Press H for a list of commands");
  testOverlayColor(1,1,1,1);
  testRun();
  
  return EXIT_SUCCESS;
}
Exemple #4
0
void click(int button, int state, int x, int y)
{
  y = testHeight() - y;
  clickX = x; clickY = y;
  
  switch (mode)
  {
  case 'c':
    startX = cx;
    startY = cy;
    break;
  case 'f':
    startX = fx;
    startY = fy;
    break;
  case 'r':
    startY = r;
    break;
  case 'x':
    startY = sx;
    break;
  case 'y':
    startY = sy;
    break;
  }
  
  glutPostRedisplay();
}
Exemple #5
0
int main(void) {
    testInsert();
    testDelete();
    testSearch();
    testHeight();
    testIsCorrectBST();
}
Exemple #6
0
void display(float interval)
{
  VGfloat cc[] = {0,0,0,1};
  
  vgSetfv(VG_CLEAR_COLOR, 4, cc);
  vgClear(0,0,testWidth(),testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
  vgLoadIdentity();
  vgTranslate(tx, ty);
  vgScale(sx, sy);
  vgRotate(a);
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
  vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
  vgLoadIdentity();
  
  vgSetPaint(patternFill, VG_FILL_PATH);
  /*vgDrawPath(p, VG_FILL_PATH);*/
  vgDrawImage(backImage);
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  vgTranslate(tx, ty);
  vgScale(sx, sy);
  vgRotate(a);
  
  vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH);
  vgDrawPath(org, VG_FILL_PATH);
}
Exemple #7
0
void createSquare(VGPath p)
{
  testMoveTo(p, (testWidth()-sqx)/2, (testHeight()-sqy)/2, VG_ABSOLUTE);
  testLineTo(p, sqx, 0, VG_RELATIVE);
  testLineTo(p, 0, sqy, VG_RELATIVE);
  testLineTo(p, -sqx, 0, VG_RELATIVE);
  testClosePath(p);
}
Exemple #8
0
void display(float interval)
{
  VGfloat cc[] = {0,0,0,1};

  angle += interval * 0.4 * PI;
  if (angle > 2*PI) angle -= 2*PI;
  amount = (sin(angle) + 1) * 0.5f;
  createMorph();

  vgSetfv(VG_CLEAR_COLOR, 4, cc);
  vgClear(0,0,testWidth(),testHeight());

  vgLoadIdentity();
  vgTranslate(testWidth()/2, testHeight()/2);
  vgScale(1.5, 1.5);
  vgDrawPath(iMorph, VG_FILL_PATH);
}
Exemple #9
0
void click(int button, int state, int x, int y)
{
  y = testHeight() - y;
  clickX = x; clickY = y;
  
  switch (mode) {
  case 'z':
    startY = sx;
    break;
  case 'p':
    startX = tx;
    startY = ty;
    break;
  }
}
Exemple #10
0
void testDisplay(void)
{
  int now, msinterval;
  float interval;
  
  DisplayFunc callback =
    (DisplayFunc)callbacks[TEST_CALLBACK_DISPLAY];
  
  /* Get interval from last redraw */
  now = glutGet(GLUT_ELAPSED_TIME);
  if (!timeinit) lastdraw = now;
  msinterval = now - lastdraw;
  interval = (float)msinterval / 1000;
  lastdraw = now;
  
  /* Draw scene */
  if (callback)
    (*callback)(interval);
  
  /* Draw overlay text */
  if (overtext != NULL) {
    glColor4fv(overcolor);
    testDrawString(10, testHeight()-25, overtext);
  }
  
  /* Draw fps */
  glColor4fv(overcolor);
  testDrawString(10, 10, "FPS: %d", fpsdraw);
  
  /* Swap */
  glutSwapBuffers();
  
  /* Count frames per second */
  ++fps;
  
  if (timeinit) {
    if (now - lastfps > 1000) {
      lastfps = now;
      fpsdraw = fps;
      fps = 0;
    }
  }else{
    lastfps = now;
    timeinit = 1;
  }
}
Exemple #11
0
void drag(int x, int y)
{
  VGfloat dx, dy;
  y = testHeight() - y;
  dx = x - clickX;
  dy = y - clickY;
  
  switch (mode) {
  case 'z':
    sx = startY + dy * 0.01;
    sy = sx;
    break;
  case 'p':
    tx = startX + dx;
    ty = startY + dy;
    break;
  }
  
  updateOverlayString();
}
Exemple #12
0
void display(float interval)
{
  int x,y,p;
  VGfloat white[] = {1,1,1,1};
  
  vgSetfv(VG_CLEAR_COLOR, 4, white);
  vgClear(0, 0, testWidth(), testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  
  for (y=0, p=0; y<3; ++y) {
    for (x=0; x<3; ++x, ++p) {
      if (p > NUM_PRIMITIVES) break;
      
      vgLoadIdentity();
      vgTranslate(100 + x*150, 100 + y*150);
      vgDrawPath(primitives[p], VG_STROKE_PATH);
    }
  }
}
Exemple #13
0
void click(int button, int state, int x, int y)
{
  y = testHeight() - y;
  clickX = x; clickY = y;
  
  switch (mode)
  {
  case 't':
    startX = tx;
    startY = ty;
    break;
  case 'x':
    startY = sx;
    break;
  case 'y':
    startY = sy;
    break;
  }
  
  glutPostRedisplay();
}
Exemple #14
0
void drag(int x, int y)
{
  VGfloat dx, dy;
  y = testHeight() - y;
  dx = x - clickX;
  dy = y - clickY;
  
  switch(mode) {
  case 'c': {
    VGfloat dcx, dcy;
    dcx = startX + dx - cx;
    dcy = startY + dy - cy;
    cx = startX + dx;
    cy = startY + dy;
    fx += dcx;
    fy += dcy;
    createRadial();
    break; }
  case 'f':
    fx = startX + dx;
    fy = startY + dy;
    createRadial();
    break;
  case 'r':
    r = startY + dy;
    createRadial();
    break;
  case 'x':
    sx = startY + dy * 0.01f;
    break;
  case 'y':
    sy = startY + dy * 0.01f;
    break;
  }
  
  updateOverlayString();
  glutPostRedisplay();
}
Exemple #15
0
void drag(int x, int y)
{
  VGfloat dx, dy;
  y = testHeight() - y;
  dx = x - clickX;
  dy = y - clickY;
  
  switch(mode) {
  case 't': {
      tx = startX + dx;
      ty = startY + dy;
      break;}
  case 'x':
    sx = startY + dy * 0.01;
    break;
  case 'y':
    sy = startY + dy * 0.01;
    break;
  }
  
  updateOverlayString();
  glutPostRedisplay();
}
Exemple #16
0
void FTS_ANPR_Seg::extractCharByCCAnalysis( const cv::Mat& oBin,
                                            FTS_ANPR_SegResult& oSegResult )
{
    // Padd the input image first
    // ------------------------------------------------------------------------
	m_oPadded.create( oBin.rows + 2,
					  oBin.cols  + 2,
					  CV_8UC1 );
	cv::copyMakeBorder( oBin, m_oPadded, 1, 1, 1, 1, cv::BORDER_CONSTANT );

    IplImage iiBin    = oBin;
    IplImage iiPadded = m_oPadded;

    cvCopyMakeBorder( &iiBin,
                      &iiPadded,
                      cvPoint( 1, 1 ),
                      IPL_BORDER_CONSTANT,
                      cvScalarAll( 0 )  ); // pad with black border


    // Initializes contour scanning process
    // ------------------------------------------------------------------------
    CvSeq* poContour = 0;
    CvContourScanner oContourScanner;

    oContourScanner = cvStartFindContours( &iiPadded,
                                           m_poStorage,
                                           sizeof( CvContour ),
                                           CV_RETR_EXTERNAL, //CV_RETR_LIST,
                                           CV_CHAIN_APPROX_SIMPLE,
                                           cvPoint( 0, 0 )  );

    // Contour scanning process
    // ------------------------------------------------------------------------
    while(  ( poContour = cvFindNextContour( oContourScanner ) )  )
    {
        // Finding bounding boxes that meet the ratio tests
        // --------------------------------------------------------------------
        CvRect oBox = cvBoundingRect( poContour, 0 );

        if(    !testArea( oBox )
            || !testHeightOverWidth( oBox )
            || !testHeight( oBox.height, iiBin.height )  )
        {
            continue;
        }

        std::list< FTS_ANPR_SegChar*>& oChars = oSegResult.m_oChars;

        // Make sure not too many candidates
        // --------------------------------------------------------------------
        if( oChars.size() >= m_nMaxNumCharCandidates )
        {
            break; // exit the while loop
        }

        // Store the character candidate to the segmentation structure
        // --------------------------------------------------------------------
        oChars.push_back( new FTS_ANPR_SegChar );

        FTS_ANPR_SegChar& oSegChar = *( oChars.back() ); // fill in the empty object

        oSegChar.m_oCharRect = oBox;

        // Offset the bounding box from coordinates in padded image, into coordinates of input image.
        --oSegChar.m_oCharRect.x;
        --oSegChar.m_oCharRect.y;

//        oSegChar.m_oCharBin.resize(oBox.width, oBox.height, SN_PIX_FMT_GREY );
        oSegChar.m_oCharBin = cv::Mat::zeros( cv::Size( oSegChar.m_oCharRect.width, oSegChar.m_oCharRect.height ), CV_8UC1 );

        IplImage iiSegCharBin = oSegChar.m_oCharBin;
//        cvZero( &iiSegCharBin );
//        printf("width = %d, height = %d\n", oSegChar.m_oCharRect.width, oSegChar.m_oCharRect.height );

        // Draw the outer contour and fill all holes. No internal holes
        // after this.
        cvDrawContours( &iiSegCharBin,
                        poContour,
                        CV_RGB( 255, 255, 255 ),
                        CV_RGB( 255, 255, 255 ),
                        1,
                        CV_FILLED,
                        8,
                        cvPoint( -oBox.x, -oBox.y ) // offset contour to smaller image
                        );

        // Recover all the holes in the original image
        cvSetImageROI( &iiBin, oSegChar.m_oCharRect );
        cvAnd( &iiBin, &iiSegCharBin, &iiSegCharBin, 0 );

//        cv::namedWindow( "CCCCCCCCCCCCCCCCCCCCCCC" );
//        cv::imshow( "CCCCCCCCCCCCCCCCCCCCCCC", oSegChar.m_oCharBin );
//        cv::waitKey();
    }

    cvResetImageROI( &iiBin );
    cvEndFindContours( &oContourScanner );


    // Sort the segments using x-coordinate
    // --------------------------------------------------------------------
    oSegResult.m_oChars.sort( &FTS_ANPR_SegChar::LessInX );
}
Exemple #17
0
void key(unsigned char key, int x, int y)
{
  glutPostRedisplay();
  
  if (key == BACKSPACE) {
    /* Reset value */
    switch(mode) {
    case 'c':
      cx = testWidth()/2;
      cy = testHeight()/2;
      fx = cx; fy = cy;
      createRadial();
      break;
    case 'f':
      fx = cx; fy = cy;
      createRadial();
      break;
    case 'r':
      r = sqx;
      createRadial();
      break;
    case 'x':
      sx = 1.0f;
      break;
    case 'y':
      sy = 1.0f;
      break;
    }
    updateOverlayString();
    return;
  }
  
  switch (tolower(key)) {
  case 'c':
  case 'f':
  case 'r':
  case 'x':
  case 'y':
    break;
    
  case TAB:
    
    /* Cycle spread mode */
    sindex = (sindex+1) % ssize;
    createRadial();
    switch(sindex) {
    case 0: testOverlayString("Gradient Spread mode: PAD"); break;
    case 1: testOverlayString("Gradient Spread mode: REPEAT"); break;
    case 2: testOverlayString("Gradient Spread mode: REFLECT"); break;
    }return;
    
  case 'h':
    /* Show help */
    testOverlayString(commands);
    return;
    
  default:
    return;
  }
  
  /* Switch mode */
  mode = tolower(key);
  updateOverlayString();
}