Ray Tracer
2020
|
Class to display and save images. More...
#include <ImageDisplay.h>
Public Member Functions | |
ImageDisplay (const std::string &windowName, unsigned int width, unsigned int height) | |
ImageDisplay constructor. More... | |
~ImageDisplay () | |
ImageDisplay destructor. More... | |
void | set (int x, int y, const Colour &colour) |
Set a pixel value. More... | |
void | refresh () |
Update the window displaying the image. More... | |
void | save (const std::string &filename) const |
Save an image to file. More... | |
void | pause (double seconds) |
Wait for a specified duration. More... | |
Private Attributes | |
std::vector< unsigned char > | image_ |
Internal storage of the image to render to. More... | |
size_t | width_ |
Width of the image. More... | |
size_t | height_ |
Height of the image. More... | |
size_t | lastRowWritten_ |
Last row rendered, for the purpose of progress reporting. More... | |
Additional Inherited Members | |
Private Member Functions inherited from NonCopyable | |
NonCopyable () | |
NonCopyable default constructor. More... | |
~NonCopyable () | |
NonCopyable destructor. More... | |
Class to display and save images.
The ImageDisplay class provides a simple method to make images, show them in a window, and save them to a file. It is a wrapper around some CImg library functions that provides an abstraction that gives just enough functionality for the Ray Tracer.
Note that ImageDisplay is NonCopyable, so does not have a copy constructor or assingment operator available. You can, however, create multiple displays.
ImageDisplay::ImageDisplay | ( | const std::string & | windowName, |
unsigned int | width, | ||
unsigned int | height | ||
) |
ImageDisplay constructor.
A ImageDisplay is an image associated with a window where it can be shown. Multple displays can be created, and should normally have different window names, but this is not enforced. Two ImageDisplay objects with the same window name will function correctly, and will store distinct images. It just won't be possible to view them both at the same time.
windowName | The (unique) name of the window for this ImageDisplay. |
width | The width, in pixels, of the image associated with this ImageDisplay. |
height | The height, in pixels, of the image associated with this ImageDisplay. |
ImageDisplay::~ImageDisplay | ( | ) |
ImageDisplay destructor.
ImageDisplay's destructor closes the associated window, and deallocates the image.
void ImageDisplay::pause | ( | double | seconds | ) |
Wait for a specified duration.
This function pauses the program for a specified duration
seconds | The number of seconds to wait (fractions allowed). |
void ImageDisplay::refresh | ( | ) |
Update the window displaying the image.
The window displaying the image is not automatically updated when the image changes for efficiency reasons. Calling refresh() causes the current image to be displayed.
void ImageDisplay::save | ( | const std::string & | filename | ) | const |
Save an image to file.
Images can be saved to files, and the image format is determined by the file extension. For example, saving to render.png
would write a PNG image, while saving to RENDER.JPG
would write a JPEG.
filename | The file to save to, with an appropriate extension. |
void ImageDisplay::set | ( | int | x, |
int | y, | ||
const Colour & | colour | ||
) |
Set a pixel value.
Set a pixel value to the specified Colour. Pixels are indexed from (0,0) in the top-left corner, with the x-axis running left to right and the y-axis running top to bottom.
Note that this updates the internal image, but not the display shown in the window. To update the window call refresh().
x | The x co-ordinate of the pixel to set. |
y | The y co-ordinate of the pixel to set. |
colour | The Colour to set at (x,y). |
|
private |
Height of the image.
|
private |
Internal storage of the image to render to.
|
private |
Last row rendered, for the purpose of progress reporting.
|
private |
Width of the image.