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

A triangle defined by its three vertices. More...

#include <Triangle.h>

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

Public Member Functions

 Triangle ()
 Default constructor. More...
 
 Triangle (const DoubleVec3D &vertex0, const DoubleVec3D &vertex1, const DoubleVec3D &vertex2, Material *material)
 Main constructor. More...
 
 Triangle (const Triangle &triangle)
 Copy constructor. More...
 
DoubleVec3D getVertex0 () const
 Getter for the first vertex. More...
 
DoubleVec3D getVertex1 () const
 Getter for the second vertex. More...
 
DoubleVec3D getVertex2 () const
 Getter for the third vertex. More...
 
DoubleVec3D getCenter () const
 Getter for the center. More...
 
void setVertex0 (const DoubleVec3D &vertex)
 Setter for the first vertex. More...
 
void setVertex1 (const DoubleVec3D &vertex)
 Setter for the second vertex. More...
 
void setVertex2 (const DoubleVec3D &vertex)
 Setter for the third vertex. More...
 
void computeArea ()
 Computes this triangle'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 triangle defined by its three vertices.

The order of its vertices is important. See the main constructor for more information.

Constructor & Destructor Documentation

◆ Triangle() [1/3]

Triangle::Triangle ( )

Default constructor.

Calls Object3D::Object3D(), then defines vertex0 = (1, 0, 0), vertex1 = (0, 1, 0) and vertex2 = (0, 0, 1).

◆ Triangle() [2/3]

Triangle::Triangle ( const DoubleVec3D vertex0,
const DoubleVec3D vertex1,
const DoubleVec3D vertex2,
Material material 
)

Main constructor.

The order of the vertices is important, because the normal is only on one side of the triangle (meaning that the triangle can only be seen from one side). Give the vertices counterclockwise from where you want the triangle to be visible.

Parameters
vertex0The first vertex of this triangle.
vertex1The second vertex of this triangle.
vertex2The third vertex of this triangle.
materialA pointer to the material of this triangle.

◆ Triangle() [3/3]

Triangle::Triangle ( const Triangle triangle)

Copy constructor.

Parameters
triangleThe triangle that will be copied.

Member Function Documentation

◆ computeArea()

void Triangle::computeArea ( )
virtual

Computes this triangle's area.

Modifies Object3D::area. It uses the formula A = 0.5 * ||edge1 x edge2||, with edge1 = vertex1 - vertex0 and edge2 = vertex2 - vertex0.

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

Implements Object3D.

◆ deepCopy()

Object3D * Triangle::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 Triangle::getCenter ( ) const
virtual

Getter for the center.

Returns
The average of the three vertices.

Implements Object3D.

◆ getDescription()

std::ostream & Triangle::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 Triangle::getLocationJson ( ) const
virtual

Converts this objects's location to json.

Returns
This triangle's vertices converted to json.

Implements Object3D.

◆ getMaxCoord()

DoubleVec3D Triangle::getMaxCoord ( ) const
virtual

Returns the maximum coordinate of a cuboid containing this object.

For each axis, picks the greatest coordinate among the three vertices.

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

Implements Object3D.

◆ getMinCoord()

DoubleVec3D Triangle::getMinCoord ( ) const
virtual

Returns the minimum coordinate of a cuboid containing this object.

For each axis, picks the smallest coordinate among the three vertices.

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

Implements Object3D.

◆ getNormal()

DoubleUnitVec3D Triangle::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 cross product between (vertex1 - vertex0) and (vertex2 - vertex0).

Implements Object3D.

◆ getRandomPoint()

DoubleVec3D Triangle::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.

Implements Object3D.

◆ getType()

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

Returns this object type.

Returns
"Triangle".

Implements Object3D.

◆ getVertex0()

DoubleVec3D Triangle::getVertex0 ( ) const

Getter for the first vertex.

Returns
This triangle's first vertex.

◆ getVertex1()

DoubleVec3D Triangle::getVertex1 ( ) const

Getter for the second vertex.

Returns
This triangle's second vertex.

◆ getVertex2()

DoubleVec3D Triangle::getVertex2 ( ) const

Getter for the third vertex.

Returns
This triangle's third vertex.

◆ setLocationJson()

void Triangle::setLocationJson ( const json j)
virtual

Sets this object's location according to json.

Parameters
jThe json input.

Implements Object3D.

◆ setVertex0()

void Triangle::setVertex0 ( const DoubleVec3D vertex)

Setter for the first vertex.

Calls Triangle::computeArea().

Parameters
vertexThe new first vertex of this triangle.
See also
Triangle::computeArea()

◆ setVertex1()

void Triangle::setVertex1 ( const DoubleVec3D vertex)

Setter for the second vertex.

Calls Triangle::computeArea().

Parameters
vertexThe new second vertex of this triangle.
See also
Triangle::computeArea()

◆ setVertex2()

void Triangle::setVertex2 ( const DoubleVec3D vertex)

Setter for the third vertex.

Calls Triangle::computeArea().

Parameters
vertexThe new third vertex of this triangle.
See also
Triangle::computeArea()

◆ smallestPositiveIntersection()

double Triangle::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. Returns -1 if the ray does not intersect with this object.

Implements Object3D.


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