Path Tracer
Public Member Functions | List of all members
Sphere Class Reference

A sphere described by its center and its radius. More...

#include <Sphere.h>

Inheritance diagram for Sphere:
[legend]
Collaboration diagram for Sphere:
[legend]

Public Member Functions

 Sphere ()
 Default constructor. More...
 
 Sphere (const DoubleVec3D &center, double radius, Material *material)
 Main constructor. More...
 
 Sphere (const Sphere &sphere)
 Copy constructor. More...
 
double getRadius () const
 Getter for the radius. More...
 
DoubleVec3D getCenter () const
 Getter for the center. More...
 
void setCenter (const DoubleVec3D &center)
 Setter for the center. More...
 
void setRadius (double radius)
 Setter for the radius. More...
 
void computeArea ()
 Computes this sphere's area. More...
 
Object3DdeepCopy () const
 Makes a deep copy of this object. More...
 
double smallestPositiveIntersection (const Ray &ray) const
 Computes the smallest positive intersection between the ray and this object. More...
 
DoubleUnitVec3D getNormal (const DoubleVec3D &point) const
 Computes the normal at a point on the object. More...
 
DoubleVec3D getRandomPoint () const
 Computes a random point on the object. More...
 
DoubleVec3D getMinCoord () const
 Returns the minimum coordinate of a cuboid containing this object. More...
 
DoubleVec3D getMaxCoord () const
 Returns the maximum coordinate of a cuboid containing this object. More...
 
std::ostream & getDescription (std::ostream &stream) const
 Returns this object's description. More...
 
std::string getType () const
 Returns this object type. More...
 
json getLocationJson () const
 Converts this objects's location to json. More...
 
void setLocationJson (const json &j)
 Sets this object's location according to json. More...
 
- Public Member Functions inherited from Object3D
 Object3D ()
 Default constructor. More...
 
 Object3D (Material *material)
 Main constructor. More...
 
 Object3D (const Object3D &obj)
 Copy constructor. More...
 
 ~Object3D ()
 Destructor. More...
 
MaterialgetMaterial () const
 Getter for the Material. More...
 
double getArea () const
 Getter for this object's area. More...
 
void setMaterial (Material *material)
 Setter for the Material. More...
 
Object3Doperator= (const Object3D &otherObject)
 Assignment operator. More...
 

Additional Inherited Members

- Protected Attributes inherited from Object3D
double area
 Stores the area of this object. More...
 

Detailed Description

A sphere described by its center and its radius.

Constructor & Destructor Documentation

◆ Sphere() [1/3]

Sphere::Sphere ( )

Default constructor.

Calls Object3D::Object3D(), then sets the center at (0, 0, 0) and the radius at 1.

◆ Sphere() [2/3]

Sphere::Sphere ( const DoubleVec3D center,
double  radius,
Material material 
)

Main constructor.

Parameters
centerThe center of this sphere.
radiusThe radius of this sphere.
materialA pointer to the material of this sphere.

◆ Sphere() [3/3]

Sphere::Sphere ( const Sphere sphere)

Copy constructor.

Parameters
sphereThe sphere that will be copied.

Member Function Documentation

◆ computeArea()

void Sphere::computeArea ( )
virtual

Computes this sphere's area.

Modifies Object3D::area. It uses the formula A = 4*pi*radius*radius.

See also
Object3D::area, Object3D::getArea()

Implements Object3D.

◆ deepCopy()

Object3D * Sphere::deepCopy ( ) const
virtual

Makes a deep copy of this object.

Returns
A pointer to a deeply copied version of this object.

Implements Object3D.

◆ getCenter()

DoubleVec3D Sphere::getCenter ( ) const
virtual

Getter for the center.

Returns
This sphere's center.

Implements Object3D.

◆ getDescription()

std::ostream & Sphere::getDescription ( std::ostream &  stream) const
virtual

Returns this object's description.

Parameters
streamThe current stream.
Returns
The stream with the description.
See also
operator<<(std::ostream& stream, const Object3D& object)

Implements Object3D.

◆ getLocationJson()

json Sphere::getLocationJson ( ) const
virtual

Converts this objects's location to json.

Returns
This sphere's center and radius converted to json.

Implements Object3D.

◆ getMaxCoord()

DoubleVec3D Sphere::getMaxCoord ( ) const
virtual

Returns the maximum coordinate of a cuboid containing this object.

This is computed using the following formula: center + DoubleVec3D(radius).

Returns
The maximum coordinate of a cuboid containing this object.
See also
getMaxPoint(std::vector<Object3D*> objects)

Implements Object3D.

◆ getMinCoord()

DoubleVec3D Sphere::getMinCoord ( ) const
virtual

Returns the minimum coordinate of a cuboid containing this object.

This is computed using the following formula: center - DoubleVec3D(radius).

Returns
The minimum coordinate of a cuboid containing this object.
See also
getMinPoint(std::vector<Object3D*> objects)

Implements Object3D.

◆ getNormal()

DoubleUnitVec3D Sphere::getNormal ( const DoubleVec3D point) const
virtual

Computes the normal at a point on the object.

Parameters
pointThe point on the object at which we want to compute the normal.
Returns
The normal at this point.

Implements Object3D.

◆ getRadius()

double Sphere::getRadius ( ) const

Getter for the radius.

Returns
This sphere's radius.

◆ getRandomPoint()

DoubleVec3D Sphere::getRandomPoint ( ) const
virtual

Computes a random point on the object.

Every point has the same probability to show up.

Returns
A random point on this object.
See also
randomVectorOnUnitRadiusSphere()

Implements Object3D.

◆ getType()

std::string Sphere::getType ( ) const
virtual

Returns this object type.

Returns
"Sphere".

Implements Object3D.

◆ setCenter()

void Sphere::setCenter ( const DoubleVec3D center)

Setter for the center.

Calls Sphere::computeArea().

Parameters
centerThe new center of this sphere.
See also
Sphere::computeArea()

◆ setLocationJson()

void Sphere::setLocationJson ( const json j)
virtual

Sets this object's location according to json.

Parameters
jThe json input.

Implements Object3D.

◆ setRadius()

void Sphere::setRadius ( double  radius)

Setter for the radius.

Calls Sphere::computeArea().

Parameters
radiusThe new radius of this sphere.
See also
Sphere::computeArea()

◆ smallestPositiveIntersection()

double Sphere::smallestPositiveIntersection ( const Ray ray) const
virtual

Computes the smallest positive intersection between the ray and this object.

Parameters
rayThe ray with wich we want to compute the intersection.
Returns
The distance between the ray origin and the intersection (the smallest one if there is more than one intersection). Returns -1 if the ray does not intersect with this object.

Implements Object3D.


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