TP2 : Perspective et géométrie projective
Énoncé :2007/TP/TP2.pdf
Correction :2007/TP/TP2-correction.pdf
Sources :2007/TP/TP2-src.zip
Exécutables pour Windows :2007/TP/TP2-win32exe.zip
#include "bitmap.h" #include "math.h" void copy(Bitmap<float> &source,Bitmap<float> &dest,int x,int y){ for (int i=0;i<source.getWidth();i++) for (int j=0;j<source.getHeight();j++) dest(x+i,y+j)=source(i,j); } void underSample(Bitmap<float> &source,Bitmap<float> &dest){ dest.setSize(source.getWidth()/2,source.getHeight()/2); for (int i=0;i<dest.getWidth();i++) for (int j=0;j<dest.getHeight();j++){ dest(i,j)=source(2*i,2*j)+source(2*i+1,2*j)+source(2*i,2*j+1)+source(2*i+1,2*j+1); dest(i,j)*=0.25; } } void multiUnderSample(Bitmap<float> &image,int n){ Bitmap<float> temp; for (int i=0;i<n;i++){ underSample(image,temp); image.setSize(temp.getWidth(),temp.getHeight()); copy(temp,image,0,0); } } void damier(Bitmap<float> &image){ for (int i=0;i<image.getWidth();i++) for (int j=0;j<image.getHeight()/2;j++){ float xx=2.*i/image.getWidth()-1, yy=2.*j/image.getHeight()-1, x=-(6+2*xx)/(sqrt(2)*yy), y=(6-2*xx)/(sqrt(2)*yy); bool k=(((int) x)-((int) y)) % 2; if (k) image(i,j)=image.yellow(); else image(i,j)=image.blue(); } } int main(int argc,char *argv[]){ Bitmap<float> image(803,803); image.fill(image.red()); for (int i=0;i<4;i++){ Bitmap<float> temp(400*(1<<i)); damier(temp); multiUnderSample(temp,i); copy(temp,image,1+401*(i%2),image.getHeight()-401*(1+i/2)); } SAVE_AND_SHOW(image,"damier.bmp"); }
Dernière modification le 18/3/2010
Ce document a été traduit de LaTeX par HeVeA