Exemple #1
0
void EditView::DrawView( Box const& viewbox, Box* affectedview )
{
    // note: viewbox can be outside the project boundary

//    Colour checkerboard[2] = { Colour(192,192,192), Colour(224,224,224) }; 

    Box vb(viewbox);
    vb.ClipAgainst(m_ViewBox);

    Img const& img = Proj().GetAnim().GetFrame(Frame());
    // get project bounds in view coords (unclipped)
    Box pbox(ProjToView(img.Bounds()));

    // step x,y through view coords of the area to draw
    int y;
//    int xmin = std::min(pbox.XMin(), vb.XMax()+1);
    int xbegin = std::min(pbox.x, vb.x + vb.w);
    int xend = std::min(pbox.x + pbox.w, vb.x + vb.w);
    for(y=vb.YMin(); y<=vb.YMax(); ++y) {
        RGBX8* dest = m_Canvas->Ptr_RGBX8(vb.x,y);
        int x=vb.XMin();

        // scanline intersects canvas?
        if(y<pbox.YMin() || y>pbox.YMax()) {
            // line is above or below the project
            while(x<=vb.XMax()) {
                *dest++ = checker2(x,y);
                ++x;
            }
            continue;
        }

        // left of project canvas
        while(x<xbegin) {
            *dest++ = checker2(x,y);
            ++x;
        }

        if(x<xend) {
            // on the project canvas
            Point p( ViewToProj(Point(x,y)) );
            switch( img.Fmt() ) {

            case FMT_I8:
                {
                    /*
                    if( p.x<0) {
                        printf("POOP:\n");
                        printf("pbox: %d %d %d %d\n", pbox.x, pbox.y, pbox.w, pbox.h);
                        printf("vb  : %d %d %d %d\n", vb.x, vb.y, vb.w, vb.h);
                        printf("x,y : %d %d\n", x,y);
                        printf("p.x,p.y : %d %d\n", p.x,p.y);
                        printf("xbegin,xend : %d %d\n", xbegin,xend);
                    }
                    assert( p.x >=0);
                    assert( p.x < img.W());
                    assert( p.y < img.H());
                    assert( p.y >=0);
                    */
                    //printf("%d\n",y);
                    I8 const* src = img.PtrConst_I8( p.x,p.y );
                    while(x<xend) {
                        int cx = x + (m_Offset.x*m_XZoom);
                        int pixstop = x + (m_XZoom-(cx%m_XZoom));
                        if(pixstop>xend)
                            pixstop=xend;
                        RGBA8 c = Proj().PaletteConst().GetColour(*src++);
                        while(x<pixstop)
                        {
                            //*dest++ = c;
                            *dest++ = Blend(c,checker(x,y));
                            ++x;
                        }
                    }
                }
                break;
            case FMT_RGBX8:
                {
                    RGBX8 const* src = img.PtrConst_RGBX8( p.x,p.y );
                    while(x<xend) {
                        int cx = x + (m_Offset.x*m_XZoom);
                        int pixstop = x + (m_XZoom-(cx%m_XZoom));
                        if(pixstop>xend)
                            pixstop=xend;
                        RGBX8 c = *src++;
                        while(x<pixstop) {
                            *dest++ = c;
                            ++x;
                        }
                    }
                }
                break;
            case FMT_RGBA8:
                {
                    RGBA8 const* src = img.PtrConst_RGBA8( p.x,p.y );
                    while(x<xend) {
                        int cx = x + (m_Offset.x*m_XZoom);
                        int pixstop = x + (m_XZoom-(cx%m_XZoom));
                        if(pixstop>xend)
                            pixstop=xend;
                        RGBA8 c = *src++;
                        while(x<pixstop) {
                            *dest++ = Blend(c,checker(x,y));
                            ++x;
                        }
                    }
                }
                break;
            default:
                assert(false);
                break;
            }
        }
        // right of canvas
        while(x < vb.x+vb.w)
        {
            *dest++ = checker2(x,y);
            ++x;
        }
    }

    if(affectedview)
        *affectedview = vb;
}
Exemple #2
0
int main()
{
  Point p1(-253.357, -123.36);
  Point p2(-190.03, 216.606);
  Point p3(-343.349, 286.6);
  Point p4(141.604, 279.934);
  Point p5(276.591, -46.7012);
  Point p6(251.593, -263.347);
  Point p7(-3.38184, -343.339);
  Point p8(-380.012, -173.355);
  Point p9(-98.3726, 39.957);
  Point p10(133.271, 124.949);
  Point p11(289.923, 301.598);
  Point p12(421.577, 23.292);
  Point p13(79.9434, -93.3633);
  Point p14(-40.0449, 366.592);
  Point p15(311.587, 374.924);
  Point p16(431.576, 214.94);
  Point p17(426.576, -131.693);
  Point p18(-265.023, -285.011);
  Point p19(369.915, 89.9521);
  Point p20(368.249, -15.0376);
  Point p21(484.904, 18.2925);
  Point p22(-411.675, 283.267);
  Point p23(-250.024, 124.949);
  Point p24(-80.041, -78.3647);
  Point p25(-360.014, 31.6245);
  Point p26(-305.019, 356.593);
  
  // built Delaunay triangulation
  PS.insert(p1); PS.insert(p2); PS.insert(p3); PS.insert(p4);
  PS.insert(p5); PS.insert(p6); PS.insert(p7); PS.insert(p8);  
  PS.insert(p9); PS.insert(p10); PS.insert(p11); PS.insert(p12);
  PS.insert(p13); PS.insert(p14); PS.insert(p15); PS.insert(p16);  
  PS.insert(p17); PS.insert(p18); PS.insert(p19); PS.insert(p20);
  PS.insert(p21); PS.insert(p22); PS.insert(p23); PS.insert(p24);
  PS.insert(p25); PS.insert(p26);
  
  std::list<Vertex_handle> LV;
  
  bool correct = true;
  
  // circle emptiness check
  Circle cs1(Point(-23.3799, 108.284), 1124.78);
  check_empty checker(cs1);
  
  CGAL::range_search(PS,cs1,std::back_inserter(LV),checker,true);
   
  if (checker.get_result()) {
    std::cout << "circle not empty !\n";
    std::cout <<  "this is an error !\n"; correct=false;
  }
  else std::cout << "circle was empty !\n";  
  
  Circle cs2(Point(-255.024, -100.029), 23551);
  check_empty checker2(cs2);
  
  CGAL::range_search(PS,cs2,std::back_inserter(LV),checker2,true);
   
  if (checker2.get_result()) std::cout << "circle not empty !\n";
  else {
    std::cout << "circle was empty !\n";   
    std::cout <<  "this is an error !\n"; correct=false;
  } 
  
  // triangle check
  Triangle t1(Point(-21.7134, -123.36), Point(84.9429, 74.9536), Point(209.931, -161.69)); 
  Triangle t2(Point(-61.7095, 164.945), Point(-88.3735, 101.618), Point(49.9463, 101.618));
  
  check_empty_triangle tchecker1(t1);
  CGAL::range_search(PS,t1.vertex(0),t1.vertex(1),t1.vertex(2),std::back_inserter(LV),tchecker1,true);
   
  if (tchecker1.get_result()) std::cout << "triangle not empty !\n";
  else {
    std::cout << "triangle was empty !\n";   
    std::cout <<  "this is an error !\n"; correct=false;
  }
  
  check_empty_triangle tchecker2(t2);
  CGAL::range_search(PS,t2.vertex(0),t2.vertex(1),t2.vertex(2),std::back_inserter(LV),tchecker2,true);
   
  if (tchecker2.get_result()) {
     std::cout << "triangle not empty !\n";
     std::cout <<  "this is an error !\n"; correct=false;
  }
  else std::cout << "triangle was empty !\n";   
  
  // rectangle check
  Rectangle_2 r1(-290.021, -175.022, -125.037, -35.0356);       
  Rectangle_2 r2(-48.3774, 136.614, -23.3799, 251.603);   

  check_empty_rectangle rchecker1(r1);
  CGAL::range_search(PS,r1.vertex(0),r1.vertex(1),r1.vertex(2),r1.vertex(3),std::back_inserter(LV),rchecker1,true);
   
  if (rchecker1.get_result()) std::cout << "rectangle not empty !\n";
  else {
    std::cout << "rectangle was empty !\n";
    std::cout <<  "this is an error !\n"; correct=false;
  }
   
  check_empty_rectangle rchecker2(r2);
  CGAL::range_search(PS,r2.vertex(0),r2.vertex(1),r2.vertex(2),r2.vertex(3),std::back_inserter(LV),rchecker2,true);
   
  if (rchecker2.get_result()) {
    std::cout << "rectangle not empty !\n";
    std::cout <<  "this is an error !\n"; correct=false;
  }
  else std::cout << "rectangle was empty !\n";
 
  if (correct) return 0;
  
  return 1;
}