cpe::image Class Reference

Container for picture data. Data are stored as unsigned char [0,255]. More...

+ Inheritance diagram for cpe::image:
+ Collaboration diagram for cpe::image:

Public Member Functions

 image ()
 empty constructor More...
 
 image (int N)
 create square picture of size NxN More...
 
 image (int Nx, int Ny)
 create picture of size Nx x Ny More...
 
 image (const std::string &filename)
 import pre-existing picture from file filename More...
 
int Nx () const
 get the picture width in pixel More...
 
int Ny () const
 get the picture height in pixel More...
 
void reshape (int Nx2)
 try to reshape the picture to a new size More...
 
bool check_position (const pos2 &u) const
 check if a given pixel (kx,ky) is within the size of the picture More...
 
const coloroperator() (const pos2 &index) const
 Accessor on a pixel. More...
 
coloroperator() (const pos2 &index)
 Accessor on a pixel. More...
 
void fill (const color &c)
 fill the entire picture with a given (r,g,b) color More...
 
void fill_rectangle (const pos2 &u1, const pos2 &u2, const color &c)
 fill a rectangle ((x1,y1);(x2,y2)) with a given (r,g,b) color More...
 
void export_file (const std::string &filename)
 write the picture into a file More...
 

Protected Member Functions

void assert_position (const pos2 &u) const
 Ensure a position is within the size of the image, otherwise throw exception. More...
 
int coordinate_to_index (const pos2 &u) const
 transform coordinate u=(kx,ky) to index in vector data More...
 

Private Attributes

std::vector< colorinternal_data
 internal data storage as std::vector of unsigned char More...
 
int internal_Nx
 storage of picture width More...
 
int internal_Ny
 storage of picture height More...
 

Detailed Description

Container for picture data. Data are stored as unsigned char [0,255].

Constructor & Destructor Documentation

cpe::image::image ( )

empty constructor

cpe::image::image ( int  N)

create square picture of size NxN

Parameters
unsignedint N: size (width & height) of the picture

References internal_data.

cpe::image::image ( int  Nx,
int  Ny 
)

create picture of size Nx x Ny

Parameters
unsignedint Nx: picture width
unsignedint Ny: picture height

References internal_data.

cpe::image::image ( const std::string &  filename)

import pre-existing picture from file filename

Parameters
std::stringfilename: path to the file to load

References cpe::read_ppm().

+ Here is the call graph for this function:

Member Function Documentation

void cpe::image::assert_position ( const pos2 u) const
protected

Ensure a position is within the size of the image, otherwise throw exception.

References check_position(), MACRO_EXCEPTION_PARAMETER, Nx(), and Ny().

Referenced by operator()(), and cpe::image_zbuffer::z().

+ Here is the call graph for this function:

bool cpe::image::check_position ( const pos2 u) const

check if a given pixel (kx,ky) is within the size of the picture

Parameters
p2du: current (kx,ky)-coordinate
Returns
true if (kx,ky) is within the picture, false otherwise

References internal_Nx, internal_Ny, cpe::pos2::x(), and cpe::pos2::y().

Referenced by assert_position(), cpe::draw_line(), and fill_rectangle().

+ Here is the call graph for this function:

int cpe::image::coordinate_to_index ( const pos2 u) const
protected

transform coordinate u=(kx,ky) to index in vector data

References internal_Nx, cpe::pos2::x(), and cpe::pos2::y().

Referenced by operator()().

+ Here is the call graph for this function:

void cpe::image::export_file ( const std::string &  filename)

write the picture into a file

References cpe::export_ppm().

Referenced by main().

+ Here is the call graph for this function:

void cpe::image::fill ( const color c)

fill the entire picture with a given (r,g,b) color

Parameters
colorc: (red,green,blue) value

References internal_data.

Referenced by main().

void cpe::image::fill_rectangle ( const pos2 u1,
const pos2 u2,
const color c 
)

fill a rectangle ((x1,y1);(x2,y2)) with a given (r,g,b) color

Parameters
p2du1: (x,y)-coordinate of starting point
p2du2: (x,y)-coordinate of ending point
colorc: (r,g,b) value

References check_position(), internal_Nx, internal_Ny, MACRO_EXCEPTION_PARAMETER, cpe::pos2::x(), and cpe::pos2::y().

+ Here is the call graph for this function:

int cpe::image::Nx ( ) const

get the picture width in pixel

References internal_Nx.

Referenced by assert_position(), and cpe::export_ppm().

int cpe::image::Ny ( ) const

get the picture height in pixel

References internal_Ny.

Referenced by assert_position(), and cpe::export_ppm().

const color & cpe::image::operator() ( const pos2 index) const

Accessor on a pixel.

References assert_position(), coordinate_to_index(), and internal_data.

+ Here is the call graph for this function:

color & cpe::image::operator() ( const pos2 index)

Accessor on a pixel.

References assert_position(), coordinate_to_index(), and internal_data.

+ Here is the call graph for this function:

void cpe::image::reshape ( int  Nx2)

try to reshape the picture to a new size

Parameters
unsignedint Nx: the new picture width
Note
Nx x Ny / Nx2 must be integer

References internal_Nx, internal_Ny, and MACRO_EXCEPTION_PARAMETER.

Member Data Documentation

std::vector<color> cpe::image::internal_data
private

internal data storage as std::vector of unsigned char

Picture is stored as (color_0 , color_1 , ...) vector size is therefore 3 Nx Ny

Referenced by fill(), image(), and operator()().

int cpe::image::internal_Nx
private

storage of picture width

Referenced by check_position(), coordinate_to_index(), fill_rectangle(), Nx(), and reshape().

int cpe::image::internal_Ny
private

storage of picture height

Referenced by check_position(), fill_rectangle(), Ny(), and reshape().


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