예제 #1
0
int main()
{ 
   SquareMaze m;
   m.makeMaze(TEST,TEST);
   std::cout << "MakeMaze complete" << std::endl;

    /*
    for ( int i = 0; i < TEST; i++)
    {
        for ( int j = 0; j < TEST ; j++)
        {
            cout <<"RIGHT: "<< m.canTravel(i,j,RIGHT)<< " x: "<<i<<" y: "<<j<<endl;
            cout <<"BOTTOM: "<< m.canTravel(i,j,BOTTOM)<< " x: "<<i<<" y: "<<j<<endl;
        }
    }
    */

   PNG* unsolved = m.drawMaze();
   unsolved->writeToFile("unsolved.png");
   delete unsolved;
   std::cout << "drawMaze complete" << std::endl;
   
   vector<int> sol = m.solveMaze();
   std::cout << "solveMaze complete" << std::endl;
   
   PNG* solved = m.drawMazeWithSolution();
   solved->writeToFile("solved.png");
   delete solved;
   std::cout << "drawMazeWithSolution complete" << std::endl;

   return 0;
}
예제 #2
0
void testWaterfall()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_05.png");

	List<RGBAPixel> list = imageToList(in);
	list.waterfall();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_01.png");

	checkSoln(__func__, out, "soln_waterfall_01.png");

	in.readFromFile("in_06.png");
	list = imageToList(in);
	list.waterfall();
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_02.png");

	checkSoln(__func__, out, "soln_waterfall_02.png");
	
	List<int> list3;

	for (int i = 1; i <= 8; i++)
	list3.insertBack(i);
	list3.waterfall();
	//cout << "[waterfall custom]: " << list3 << endl;
}
예제 #3
0
void testReverseNth()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_03.png");
	
    /*
    List<int> test;

    for (int i = 1; i <= 11; i++)
    {
        test.insertBack(i);
    }

    cout<<test<<endl;
    test.reverseNth(3);
    cout<<test<<endl;
    */
	List<RGBAPixel> list = imageToList(in);
	list.reverseNth(in.height() * 20);

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverseNth_01.png");

	checkSoln(__func__, out, "soln_reverseNth_01.png");

	in.readFromFile("in_04.png");
	list = imageToList(in);
	list.reverseNth(in.height() * 61);
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverseNth_02.png");

	checkSoln(__func__, out, "soln_reverseNth_02.png");

}
예제 #4
0
void testWaterfall()
{
	List<double> li;
	cout<<li<<endl;
	li.waterfall();
	cout<<li<<endl;
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_05.png");

	List<RGBAPixel> list = imageToList(in);
	list.waterfall();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_01.png");

	checkSoln(__func__, out, "soln_waterfall_01.png");

	in.readFromFile("in_06.png");
	list = imageToList(in);
	list.waterfall();
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_02.png");

	checkSoln(__func__, out, "soln_waterfall_02.png");
}
예제 #5
0
/**
 * Simply parses the command line args and runs the appropriate functions.
 */
int main(int argc, char* argv[]){

    if(argc != 5)
    {
        cerr << endl;
        cerr << "Please run as " << argv[0] << " numThreads operation imageName saveFile" << endl;
        cerr << "    numThreads    number of threads to use (if #pragma omp... is encountered)" << endl;
        cerr << "    operation     \"flip\" or \"remove\"" << endl;
        cerr << "    imageName     for example, \"images/01_8182x4096.png\"" << endl;
        cerr << "    saveFile      \"yes\" (if you want to save output), \"no\" otherwise" << endl;
        cerr << endl;
        return 1;
    }

    // set the number of thread for the program to use (the first argument)
    omp_set_num_threads(atoi(argv[1]));
    
    // read the parameter PNG from file
    string filename(argv[3]);
    PNG img(filename);
    PNG output;

    cout << "Performing operation..." << endl;
    double start = omp_get_wtime();
    double end;
    if(argv[2][0] == 'f')
    {
        output = ImageTools::verticalFlip(img);
        end = omp_get_wtime();
        if(argv[4][0] == 'y')
        {
            cout << "Saving image..." << endl;
            output.writeToFile("flipped.png");
        }
    }
    else
    {
        Color color = GREEN;
        output = ImageTools::removeColor(img, color);
        end = omp_get_wtime();
        if(argv[4][0] == 'y')
        {
            cout << "Saving image..." << endl;
            output.writeToFile("removed.png");
        }
    }

    cout << "Total processed pixels: " << img.height() * img.width() << endl;
    cout << "Time: " << end - start << " seconds" << endl;
    return 0;
}
예제 #6
0
void pacmanTests() {
	cout << "Testing PacMan" << endl;

	// PAC MAN BFS
	PNG img;
	img.readFromFile("originals/pacMan.png");
	rainbowColorPicker BFSfiller(1.0/1000.0);
	animation pacManBFS = filler::bfs::fill(img, img.width()/2, img.height()/2,
	                               BFSfiller, 8000, INT_MAX);
	img.writeToFile("images/pacManBFS.png");
	cout << "\tWrote images/pacManBFS.png" << endl;
	//blueManBFS.write("pacManBFS.gif");

	// PAC MAN DFS
	img.readFromFile("originals/pacMan.png");
	rainbowColorPicker DFSfiller(1.0/1000.0);
	animation pacManDFS = filler::dfs::fill(img, img.width()/2, img.height()/2,
	                               DFSfiller, 8000, INT_MAX);
	img.writeToFile("images/pacManDFS.png");
	cout << "\tWrote images/pacManDFS.png" << endl;


	// Make ANTI image
	PNG antiImg;
	antiImg.readFromFile("originals/pacMan.png");
	RGBAPixel black;
	black.red = black.green = black.blue = 0;
	RGBAPixel grey;
	grey.red = grey.green = grey.blue = 1;
    filler::bfs::fillSolid(antiImg, 10, 10, grey, 8000, INT_MAX);
    filler::bfs::fillSolid(antiImg, antiImg.width()/2, antiImg.height()/2, black, 8000, INT_MAX);

	// ANTI PAC MAN BFS
	img = antiImg;
	rainbowColorPicker aBFSfiller(1.0/1000.0);
	animation aManBFS = filler::bfs::fill(img, 20, 20, aBFSfiller, 0, 2000);
	//img.writeToFile("antiPacManBFS.png");
	aManBFS.write("images/antiPacManBFS.gif");
	cout << "\tWrote images/antiPacManBFS.gif" << endl;

	// ANTI PAC MAN DFS
	img = antiImg;
	rainbowColorPicker aDFSfiller(1.0/1000.0);
	animation aManDFS = filler::dfs::fill(img, 20, 20, aDFSfiller, 0, 2000);
	//img.writeToFile("antiPacManDFS.png");
	aManDFS.write("images/antiPacManDFS.gif");
	cout << "\tWrote images/antiPacManDFS.gif" << endl;
}
예제 #7
0
파일: main.cpp 프로젝트: chrislee0793/CS225
/**
 * Tests the image flipping code.
 */
void testFlip()
{
    PNG image;
    cout << "Testing in-place image flipper:" << endl;
    image.readFromFile("images/03_2560x1680.png");

    cout << "  - flipping image" << endl;
    double startTime = omp_get_wtime();
    Flipper::flipParallel(image);
    double endTime = omp_get_wtime();
    double parallelTime = endTime - startTime;

    cout << "  - saving image" << endl;
    image.writeToFile("flipped.png");
    cout << "Elapsed flip time: " << parallelTime << endl;

    cout << "Checking correctness: ";
    bool correct = Flipper::checkCorrectness(image);
    cout << (correct ? makeGreen("PASS") : makeRed("FAIL") + " (the images are different)") << endl;

    startTime = omp_get_wtime();
    Flipper::flipSerial(image);
    endTime = omp_get_wtime();
    cout << "Speedup: " << (endTime - startTime) / parallelTime << endl;
}
예제 #8
0
int main()
{
	PNG oldImage;
	oldImage.readFromFile("in.png");	
	size_t vertical = oldImage.height();
	size_t horizontal = oldImage.width();
/*
* have initialized newImage just so that the pixels are accessable 
*/
	PNG newImage;
	newImage.readFromFile("in.png");
/*
 * we will flip the image horizontally and vertically to rotate it by 180 degrees
*/
	for (size_t x = 0; x < oldImage.width(); x++)
	{	
		for (size_t y = 0; y < oldImage.height(); y++)
		{
			newImage(horizontal-x-1, vertical-y-1)->red = oldImage(x,y)->red;
			newImage(horizontal-x-1, vertical-y-1)->green = oldImage(x,y)->green;
			newImage(horizontal-x-1, vertical-y-1)->blue = oldImage(x,y)->blue;
		}
	}
	newImage.writeToFile("out.png");
}	
예제 #9
0
파일: main.cpp 프로젝트: chrislee0793/CS225
/**
 * Tests the collage code with the appropriate algorithm.
 */
void testCollage(DrawAlgorithm algorithm)
{
    cout << "Testing collage:" << endl;
    vector<PNG> layers = setupImages();
    vector<Point> coords = setupPoints();
    Collage collage(layers, coords);

    double startTime = omp_get_wtime();
    PNG* result = collage.draw(algorithm, true);
    double endTime = omp_get_wtime();
    double parallelTime = endTime - startTime;

    cout << "  - saving image" << endl;
    result->writeToFile("collage.png");    
    cout << "Elapsed collage time: " << parallelTime << endl;

    cout << "Checking correctness: ";
    bool correct = collage.checkCorrectness(*result);
    cout << (correct ? makeGreen("PASS") : makeRed("FAIL") + " (the images are different)") << endl;
    delete result;

    startTime = omp_get_wtime();
    result = collage.draw(algorithm, false);
    endTime = omp_get_wtime();
    cout << "Speedup: " << (endTime - startTime) / parallelTime << endl;
    delete result;
}
예제 #10
0
void makePhotoMosaic(const string & inFile, const string & tileDir, int numTiles, int pixelsPerTile, const string & outFile)
{
	PNG inImage(inFile);
	SourceImage source(inImage, numTiles);
	vector<TileImage> tiles = getTiles(tileDir);

	if (tiles.empty())
	{
		cerr << "ERROR: No tile images found in " << tileDir << endl;
		exit(2);
	}

	MosaicCanvas::enableOutput = true;
	MosaicCanvas * mosaic = mapTiles(source, tiles);
	cerr << endl;

	if (mosaic == NULL)
	{
		cerr << "ERROR: Mosaic generation failed" << endl;
		exit(3);
	}

	PNG result = mosaic->drawMosaic(pixelsPerTile);
	cerr << "Saving Output Image... ";
	result.writeToFile(outFile);
	cerr << "Done" << endl;
	delete mosaic;
}
예제 #11
0
int main(int argc, char* argv[])
{
	const int canvas_width = 128;
	const int canvas_height = 128;

	PNG canvas;
	canvas.resize(canvas_width, canvas_height);


	const RGBAPixel triangle_color = color::ORANGE;
	Shape* triangle = new Triangle(triangle_color,
			Vector2(32, 32),
			Vector2(64, 64),
			Vector2(32, 64));

	triangle->draw(&canvas);

	canvas.writeToFile("test_destructor.png");

	/* TODO: Why is this leaking memory?  Triangle does have a valid destructor!?
	 * Can you stop it from leaking WITHOUT changing triangle's type from a
	 * Shape pointer to a Triangle pointer type? */
	delete triangle;
	triangle = NULL;

	return 0;
}
예제 #12
0
int main()
{

	// Load in.png
	PNG * original;

	original=new PNG;
	original->readFromFile("in.png");
	int width  = original->width();
	int height = original->height();
	// Create out.png
	PNG * output;
	output = new PNG;
	output = setupOutput(width, height);	
	// Loud our favorite color to color the outline
	RGBAPixel * myPixel;
	myPixel=new RGBAPixel;
	myPixel= myFavoriteColor(192);

	

	// Go over the whole image, and if a pixel differs from that to its upper
	// left, color it my favorite color in the output
	for (int y = 1; y < height; y++)
	{
		for (int x = 1; x < width; x++)
		{
			// Calculate the pixel difference
			RGBAPixel * prev = (*original)(x-1, y-1);
			RGBAPixel * curr = (*original)(x  , y  );
			int diff = abs(curr->red   - prev->red  ) +
					   abs(curr->green - prev->green) +
					   abs(curr->blue  - prev->blue );

			// If the pixel is an edge pixel,
			// color the output pixel with my favorite color
			RGBAPixel * currOutPixel = (*output)(x,y);
			if (diff > 100)
				{currOutPixel->red=myPixel->red;
currOutPixel->green=myPixel->green;
currOutPixel->blue=myPixel->blue;}

		
	}
}

	// Save the output file
	output->writeToFile("out.png");


	// Clean up memory
	myPixel=NULL;
	delete myPixel;
	delete output;
	output=NULL;
	delete original;
	original=NULL;
	return 0;
}
예제 #13
0
int main(int argc, char* argv[])
{
	const int canvas_width = 128;
	const int canvas_height = 128;

	PNG canvas;
	canvas.resize(canvas_width, canvas_height);

	Vector2 rectangle_center(canvas_width / 2, canvas_height / 2);
	const int rectangle_width = canvas_width / 4;
	const int rectangle_height = canvas_height / 4;
	Rectangle* rectangle = new Rectangle(rectangle_center,
			color::BLUE,
			rectangle_width,
			rectangle_height);

	rectangle->draw(&canvas);

	const int rectangle_perimeter = rectangle->perimeter();
	cout << "Rectangle's Perimeter = " << rectangle_perimeter << endl;
	const int rectangle_area = rectangle->area();
	cout << "Rectangle's Area = " << rectangle_area << endl;

	/* But we can treat a Rectangle just like a Shape using a Shape pointer */
	Shape* shape = rectangle;
	const int shape_perimeter = shape->perimeter();
	cout << "Shape's Perimeter = " << shape_perimeter << endl;
	const int shape_area = shape->area();
	cout << "Shape' Area = " << shape_area << endl;

	/* TODO: For some reason the shape's area and perimeter is different from
	 * triangle's area and perimeter even though they are pointing to the same
	 * object!  Can you this this so they are the same WITHOUT changing the
	 * shape's type from a Shape pointer to a Triangle pointer? */
	if (rectangle_perimeter == shape_perimeter)
	{
		cout << "The Perimeters are the same!" << endl;
	} else
	{
		
		cout << "The Perimeters are NOT the same." << endl;
	}

	if (rectangle_area == shape_area)
	{
		cout << "The Areas are the same!" << endl;
	} else
	{
		cout << "The Areas are NOT the same." << endl;
	}

	canvas.writeToFile("test_virtual.png");

	delete rectangle;

	return 0;
}
예제 #14
0
파일: sketchify.cpp 프로젝트: Yankkk/C-
void sketchify()
{
	// Load in.png
	PNG * original;

	//std::cout << "Reached line 28" << endl;	
	original = new PNG();
	original->readFromFile("in.png");
	int width  = original->width();
	int height = original->height();
	//std::cout << "Reached line 32" << endl;

	// Create out.png
	PNG * output = setupOutput(width, height);	

	// Loud our favorite color to color the outline
	RGBAPixel * myPixel = myFavoriteColor(192);

	// Go over the whole image, and if a pixel differs from that to its upper
	// left, color it my favorite color in the output
	for (int y = 1; y < height; y++)
	{
		//std::cout << "begin" << endl;
		for (int x = 1; x < width; x++)
		{
			// Calculate the pixel difference
			RGBAPixel * prev = (*original)(x-1, y-1);
			RGBAPixel * curr = (*original)(x  , y  );
			int diff = abs(curr->red   - prev->red  ) +
					   abs(curr->green - prev->green) +
					   abs(curr->blue  - prev->blue );

			// If the pixel is an edge pixel,
			// color the output pixel with my favorite color
			RGBAPixel * currOutPixel =(*output)(x,y);

			if (diff > 100)
				*currOutPixel = *myPixel;
				//*(*output)(x,y) = *myPixel;
			
		}
		//std::cout << "end" << endl;
	}
	
	// Save the output file
	//std::cout << "begin" << endl;
	output->writeToFile("out.png");
	//std::cout << "end" << endl;

	// Clean up memory
	delete myPixel;
	//std::cout << "check1" << endl;
	delete output;
	delete original;
	//std::cout << "check2" << endl;
}
예제 #15
0
int main()
{
   SquareMaze m;
   m.makeMaze(2, 2);
   std::cout << "MakeMaze complete" << std::endl;

   PNG* unsolved = m.drawMaze();
   unsolved->writeToFile("unsolved.png");
   delete unsolved;
   std::cout << "drawMaze complete" << std::endl;
   
   vector<int> sol = m.solveMaze();
   std::cout << "solveMaze complete" << std::endl;

   PNG* solved = m.drawMazeWithSolution();
   solved->writeToFile("solved.png");
   delete solved;
   std::cout << "drawMazeWithSolution complete" << std::endl;

   return 0;
}
예제 #16
0
void testReverseNth()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_03.png");
	
	List<RGBAPixel> list = imageToList(in);
	list.reverseNth(in.height() * 20);

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverseNth_01.png");

	checkSoln(__func__, out, "soln_reverseNth_01.png");

	in.readFromFile("in_04.png");
	list = imageToList(in);
	list.reverseNth(in.height() * 61);
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverseNth_02.png");

	checkSoln(__func__, out, "soln_reverseNth_02.png");
}
예제 #17
0
void testReverse()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in.png");

	List<RGBAPixel> list = imageToList(in);
	list.reverse();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverse.png");

	checkSoln(__func__, out, "soln_reverse.png");
}
예제 #18
0
int main()
{
    const int rectangle_width = 16;
    const int rectangle_height = 16;
    Vector2 rectangle_center(32, 16);
    // I can create a Rectangle using a Rectangle Pointer!
    Rectangle* rectangle = new Rectangle(rectangle_center, color::RED,
                                         rectangle_width, rectangle_height);

    rectangle_center.set_x(rectangle_center.x() + rectangle_width);
    // OR I can create a Rectangle using a Shape Pointer!!
    Shape* rectangle_shape = new Rectangle(rectangle_center, color::ORANGE,
                                           rectangle_width, rectangle_height);

    rectangle_center.set_x(rectangle_center.x() + rectangle_width);
    // OR I can create a Rectangle using a Drawable Pointer!!!
    Drawable* rectangle_drawable = new Rectangle(
        rectangle_center, color::YELLOW, rectangle_width, rectangle_height);

    // Since all these pointers point to something that is a Drawable type
    // lets make an array of drawable pointers
    size_t num_drawables = 3;
    Drawable** drawables = new Drawable*[num_drawables];
    drawables[0] = rectangle;
    drawables[1] = rectangle_shape;
    drawables[2] = rectangle_drawable;

    PNG canvas;
    canvas.resize(WIDTH, HEIGHT);

    // Since they are all drawable I can call draw on all of them
    for (size_t i = 0; i < num_drawables; i++) {
        drawables[i]->draw(&canvas);
    }

    canvas.writeToFile(OUTPUT_FILE);

    for (size_t i = 0; i < num_drawables; i++) {
        delete drawables[i];
        drawables[i] = NULL;
    }

    delete[] drawables;
    drawables = NULL;
    return 0;
}
예제 #19
0
void testReverse()
{

	/*List<int> list;
	for (int i = 1; i <= 2; i++)
		list.insertBack(i);
	cout << list << endl;
	list.reverse();
	cout << list << endl;*/
	
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in.png");

	List<RGBAPixel> list = imageToList(in);
	list.reverse();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverse.png");

	checkSoln(__func__, out, "soln_reverse.png");
}
예제 #20
0
파일: main.cpp 프로젝트: chrislee0793/CS225
/**
 * Tests the serial collage code.
 */
void testCollageCoordsSerial()
{
    cout << "Testing collage by coordinates in serial:" << endl;
    vector<PNG> layers = setupImages();
    vector<Point> coords = setupPoints();
    Collage collage(layers, coords);
    DrawAlgorithm algorithm = byCoordinates;

    double startTime = omp_get_wtime();
    PNG* result = collage.draw(algorithm, false);
    double endTime = omp_get_wtime();

    cout << "  - saving image" << endl;
    result->writeToFile("collage.png");    
    cout << "Elapsed collage time: " << endTime - startTime << endl;

    cout << "Checking correctness: ";
    bool correct = collage.checkCorrectness(*result);
    cout << (correct ? makeGreen("PASS") : makeRed("FAIL") + " (the images are different)") << endl;
    delete result;
}