Ray Tracer  2020
Public Member Functions | Private Attributes | List of all members
ImageDisplay Class Reference

Class to display and save images. More...

#include <ImageDisplay.h>

Inheritance diagram for ImageDisplay:
NonCopyable

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ImageDisplay()

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.

Parameters
windowNameThe (unique) name of the window for this ImageDisplay.
widthThe width, in pixels, of the image associated with this ImageDisplay.
heightThe height, in pixels, of the image associated with this ImageDisplay.

◆ ~ImageDisplay()

ImageDisplay::~ImageDisplay ( )

ImageDisplay destructor.

ImageDisplay's destructor closes the associated window, and deallocates the image.

Member Function Documentation

◆ pause()

void ImageDisplay::pause ( double  seconds)

Wait for a specified duration.

This function pauses the program for a specified duration

Parameters
secondsThe number of seconds to wait (fractions allowed).

◆ refresh()

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.

◆ save()

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.

Parameters
filenameThe file to save to, with an appropriate extension.

◆ set()

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().

Parameters
xThe x co-ordinate of the pixel to set.
yThe y co-ordinate of the pixel to set.
colourThe Colour to set at (x,y).

Member Data Documentation

◆ height_

size_t ImageDisplay::height_
private

Height of the image.

◆ image_

std::vector<unsigned char> ImageDisplay::image_
private

Internal storage of the image to render to.

◆ lastRowWritten_

size_t ImageDisplay::lastRowWritten_
private

Last row rendered, for the purpose of progress reporting.

◆ width_

size_t ImageDisplay::width_
private

Width of the image.


The documentation for this class was generated from the following files: