#include "QuadTree.h" #include #include int main() { QuadTree q[3]; // We have 3 quadtrees to play with. char buffer[15]; int i, j, k, x, y; while ( EOF != scanf( "%10s", buffer ) ) { switch ( buffer[0] ) { case 'c': // copy one image to another scanf( "%d %d", &i, &j ); q[i] = q[j]; break; case 'r': // read in an image scanf( "%d", &i ); q[i].readImage(); break; case 'p': // print out some information on an image scanf( "%d", &i ); j = q[i].getSize(); printf(" Image %d is %dx%d with %d nodes\n", i, j, j, q[i].getNumNodes() ); break; case 'w': // write out an image scanf( "%d", &i ); printf(" Image %d content:\n", i ); q[i].writeImage(); break; case 't': // test a pixel value and print it out scanf( "%d %d %d", &i, &x, &y ); printf(" Pixel (%d,%d) in image %d is %c\n", x, y, i, q[i].isBlack(x,y) ? '1' : '0' ); break; case 'a': // print out black area of an image scanf( "%d", &i ); printf(" Black area of image %d is %d\n", i, q[i].blackArea() ); break; case 'i': // invert an image scanf( "%d", &i ); q[i].invert(); break; case 'R': // rotate an image scanf( "%d", &i ); q[i].rotate(); break; case 'U': // compute union of two images, store in a third scanf( "%d %d %d", &i, &j, &k ); q[i] = QuadTree::computeUnion( q[j], q[k] ); break; case 'I': // compute intersection of two images, store in a third scanf( "%d %d %d", &i, &j, &k ); q[i] = QuadTree::computeIntersection( q[j], q[k] ); break; case '/': // read up to the end of the line, echoing as we go printf( "%s", buffer ); do { i = scanf( "%c", buffer ); if ( i == EOF ) return 0; putchar( buffer[0] ); } while ( buffer[0] != '\n' ); break; } } return 0; }