Loading LrColor.cpp 0 → 100644 +154 −0 Original line number Diff line number Diff line /** * @brief OBJET : une couleur * @file LrColor.cpp * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'une couleur */ #include "config.h" #include "LrColor.h" LrColor::LrColor() : m_r(0), m_g(0), m_b(0) { } LrColor::LrColor(const LrColor & c) :m_r(c.m_r), m_g(c.m_g), m_b(c.m_b) { } LrColor::LrColor(Real red, Real green, Real blue) : m_r(red), m_g(green), m_b(blue) { } LrColor::~LrColor() { } Real LrColor::getRed() const { return m_r; } void LrColor::setRed(Real red) { m_r = red; } Real LrColor::getGreen() const { return m_g; } void LrColor::setGreen(Real green) { m_g = green; } Real LrColor::getBlue() const { return m_b; } void LrColor::setBlue(Real blue) { m_b = blue; } void LrColor::toRGB255 (int & red, int & green, int & blue) const { red = (int)m_r * 255; green = (int)m_g * 255; blue = (int)m_b * 255; } void LrColor::fromRGB255 (const int red, const int green, const int blue) { m_r = red / 255; if(m_r > 1) m_r = 1; if(m_r < 0) m_r = 0; m_g = green / 255; if(m_g > 1) m_r = 1; if(m_g < 0) m_r = 0; m_b = blue / 255; if(m_b > 1) m_r = 1; if(m_b < 0) m_r = 0; } LrColor & LrColor::operator = (const LrColor & c) { if(this == &c)return (*this); m_r = c.m_r; m_g = c.m_g; m_b = c.m_b; return (*this); } LrColor & LrColor::operator += (const LrColor & c) { return (*this = (*this + c)); } LrColor & LrColor::operator -= (const LrColor & c) { return (*this = (*this - c)); } bool operator == (const LrColor & c_lhs, const LrColor & c_rhs) { return ((c_lhs.m_r == c_rhs.m_r) && (c_lhs.m_g == c_rhs.m_g) && (c_lhs.m_b == c_rhs.m_b)); } bool operator != (const LrColor & c_lhs, const LrColor & c_rhs) { return !(c_lhs == c_rhs); } LrColor operator + (const LrColor &lhs, const LrColor &rhs) { LrColor color; color.m_r = lhs.m_r + rhs.m_r; if(color.m_r > 1)color.m_r = 1; color.m_g = lhs.m_g + rhs.m_g; if(color.m_g > 1)color.m_g = 1; color.m_b = lhs.m_b + rhs.m_b; if(color.m_b > 1)color.m_b = 1; return color; } LrColor operator - (const LrColor &lhs, const LrColor &rhs) { LrColor color; color.m_r = lhs.m_r - rhs.m_r; if(color.m_r < 0)color.m_r = 0; color.m_g = lhs.m_g - rhs.m_g; if(color.m_g < 0)color.m_g = 0; color.m_b = lhs.m_b - rhs.m_b; if(color.m_b < 0)color.m_b = 0; return color; } LrColor.h +62 −92 Original line number Diff line number Diff line /***************************************************************************** * class LrColor (specification) * * * * author : Gilles Subrenat * * creation : Sunday, March 2 2008 (3/2/2008) * * note : * *****************************************************************************/ /** * @brief OBJET : une couleur * @file LrColor.h * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'une couleur */ #ifndef LRCOLOR_h #define LRCOLOR_h #ifndef LRCOLOR_H #define LRCOLOR_H class LrColor { public: static const LrColor BLACK; static const LrColor WHITE; static const LrColor RED; static const LrColor GREEN; static const LrColor BLUE; static const LrColor CYAN; static const LrColor MAGENTA; static const LrColor YELLOW; // constructors and destructor // *************************** private : Real m_r; Real m_g; Real m_b; public : LrColor(); LrColor(const LrColor &source); LrColor(const LrColor & c); LrColor(Real red, Real green, Real blue); explicit LrColor(Real grey); ~LrColor(); virtual ~LrColor(); // assignement operator(s) // *********************** LrColor & operator = (const LrColor &source); LrColor & operator += (const LrColor &source); LrColor & operator += (Real grey); LrColor & operator -= (const LrColor &source); LrColor & operator -= (Real grey); LrColor & operator *= (const LrColor &source); LrColor & operator *= (Real factor); LrColor & operator /= (Real factor); // comparison operator(s) // ********************** friend bool operator == (const LrColor &lhs, const LrColor &rhs); friend bool operator != (const LrColor &lhs, const LrColor &rhs); // "mathematical" operator(s) // ************************** friend LrColor operator + (const LrColor &lhs, const LrColor &rhs); friend LrColor operator + (Real lhs, const LrColor &rhs); friend LrColor operator + (const LrColor &lhs, Real rhs); friend LrColor operator - (const LrColor &lhs, const LrColor &rhs); friend LrColor operator - (Real lhs, const LrColor &rhs); friend LrColor operator - (const LrColor &lhs, Real rhs); friend LrColor operator * (const LrColor &lhs, const LrColor &rhs); friend LrColor operator * (Real lhs, const LrColor &rhs); friend LrColor operator * (const LrColor &lhs, Real rhs); friend LrColor operator / (const LrColor &lhs, Real rhs); // accessors // ********* LrColor & operator = (const LrColor & c); LrColor & operator += (const LrColor & c); LrColor & operator -= (const LrColor & c); Real getRed() const; void setRed(Real red); Real getGreen() const; void setGreen(Real green); Real getBlue() const; void setBlue(Real blue); void setRGB(Real red, Real green, Real blue); Real getGrey() const; void setGrey(Real grey); Real getLuminosity() const; /*met � jour les parametre rentrant en convertissant l es valeur real de l'instance au format RGB 255*/ void toRGB255 (int & red, int & green, int & blue) const; /*Modifie les valeurs de l'instance � partir de valeurs RGB255*/ void fromRGB255 (const int red, const int green, const int blue); private: friend bool operator == (const LrColor & c_lhs, const LrColor & c_rhs); friend bool operator != (const LrColor & c_lhs, const LrColor & c_rhs); // data // **** friend LrColor operator + (const LrColor &lhs, const LrColor &rhs); friend LrColor operator - (const LrColor &lhs, const LrColor &rhs); Real m_red; Real m_green; Real m_blue; }; }; #endif LrPoint.cpp +31 −15 Original line number Diff line number Diff line /** * @brief OBJET : un point 3D * @file LrPoint.cpp * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'un point 3D */ #include "config.h" #include "LrPoint.h" /*---------------------------------------------------------------------------* * constructors and destructor * *---------------------------------------------------------------------------*/ LrPoint::LrPoint() :x(0), y(0), z(0) :m_x(0), m_y(0), m_z(0) { } LrPoint::LrPoint(const LrPoint &source) :x(source.x), y(source.y), z(source.z) :m_x(source.m_x), m_y(source.m_y), m_z(source.m_z) { } LrPoint::LrPoint(Real x, Real y, Real z) :x(x), y(y), z(z) :m_x(x), m_y(y), m_z(z) { } Loading @@ -29,9 +44,9 @@ LrPoint::~LrPoint() void LrPoint::translate(const LrVector &v) { x+=v.getCompo(X); y+=v.getCompo(Y); z+=v.getCompo(Z); m_x+=v.getCompo(X); m_y+=v.getCompo(Y); m_z+=v.getCompo(Z); } /*---------------------------------------------------------------------------* * assignement operator(s) * Loading @@ -39,9 +54,9 @@ void LrPoint::translate(const LrVector &v) LrPoint & LrPoint::operator = (const LrPoint &source) { if(this == &source) return (*this); this->x = source.x; this->y = source.y; this->z = source.z; m_x = source.m_x; m_y = source.m_y; m_z = source.m_z; return (*this); } Loading @@ -51,7 +66,7 @@ LrPoint & LrPoint::operator = (const LrPoint &source) bool operator == (const LrPoint &lhs, const LrPoint &rhs) { return ((lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.z == rhs.z)); return ((lhs.m_x == rhs.m_x) && (lhs.m_y == rhs.m_y) && (lhs.m_z == rhs.m_z)); } bool operator != (const LrPoint &lhs, const LrPoint &rhs) Loading @@ -63,12 +78,12 @@ bool operator != (const LrPoint &lhs, const LrPoint &rhs) *---------------------------------------------------------------------------*/ static Real distance(const LrPoint &p1, const LrPoint &p2) { return sqrt(pow((p2.x - p1.x),2)+ pow((p2.y - p1.y),2)+ pow((p2.z - p1.z),2)); return sqrt(pow((p2.m_x - p1.m_x),2)+ pow((p2.m_y - p1.m_y),2)+ pow((p2.m_z - p1.m_z),2)); } static LrPoint middle(const LrPoint &p1, const LrPoint &p2) { LrPoint point((p2.x - p1.x), (p2.y - p1.y), (p2.z - p1.z)); LrPoint point((p2.m_x - p1.m_x), (p2.m_y - p1.m_y), (p2.m_z - p1.m_z)); return point; } Loading @@ -76,11 +91,12 @@ static LrPoint interpolate(Real t, const LrPoint &p1,const LrPoint &p2) { } static LrPoint translate( const LrPoint &p, const LrVector &v) { LrPoint point; point.x = x + v.getCompo(X); point.y = y + v.getCompo(Y); point.z = z + v.getCompo(Z); point.m_x = p.m_x + v.getCompo(X); point.m_y = p.m_y + v.getCompo(Y); point.m_z = p.m_z + v.getCompo(Z); return point; } LrPoint.h +15 −9 Original line number Diff line number Diff line /***************************************************************************** * class LrPoint (specification) * * * * author : Gilles Subrenat * * creation : Sunday, March 2 2008 (3/2/2008) * * note : * *****************************************************************************/ /** * @brief OBJET : un point 3D * @file LrPoint.h * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'un point 3D */ #ifndef LRPOINT3D_H #define LRPOINT3D_H #include "config.h" #include <math.h> class LrVector; Loading Loading @@ -74,7 +80,7 @@ public: // **** // public members EXCEPTIONNALY : to simplify use of this class Real x, y, z; Real m_x, m_y, m_z; private: Loading LrVector.cpp +16 −0 Original line number Diff line number Diff line /** * @brief OBJET : un vecteur 3D * @file LrVector.cpp * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'un vecteur 3D */ #include "config.h" #include "LrVector.h" ////////////////////////////// CONSTRUCTEURS /////////////////////////////////////////////////////// //Par defaut Loading Loading
LrColor.cpp 0 → 100644 +154 −0 Original line number Diff line number Diff line /** * @brief OBJET : une couleur * @file LrColor.cpp * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'une couleur */ #include "config.h" #include "LrColor.h" LrColor::LrColor() : m_r(0), m_g(0), m_b(0) { } LrColor::LrColor(const LrColor & c) :m_r(c.m_r), m_g(c.m_g), m_b(c.m_b) { } LrColor::LrColor(Real red, Real green, Real blue) : m_r(red), m_g(green), m_b(blue) { } LrColor::~LrColor() { } Real LrColor::getRed() const { return m_r; } void LrColor::setRed(Real red) { m_r = red; } Real LrColor::getGreen() const { return m_g; } void LrColor::setGreen(Real green) { m_g = green; } Real LrColor::getBlue() const { return m_b; } void LrColor::setBlue(Real blue) { m_b = blue; } void LrColor::toRGB255 (int & red, int & green, int & blue) const { red = (int)m_r * 255; green = (int)m_g * 255; blue = (int)m_b * 255; } void LrColor::fromRGB255 (const int red, const int green, const int blue) { m_r = red / 255; if(m_r > 1) m_r = 1; if(m_r < 0) m_r = 0; m_g = green / 255; if(m_g > 1) m_r = 1; if(m_g < 0) m_r = 0; m_b = blue / 255; if(m_b > 1) m_r = 1; if(m_b < 0) m_r = 0; } LrColor & LrColor::operator = (const LrColor & c) { if(this == &c)return (*this); m_r = c.m_r; m_g = c.m_g; m_b = c.m_b; return (*this); } LrColor & LrColor::operator += (const LrColor & c) { return (*this = (*this + c)); } LrColor & LrColor::operator -= (const LrColor & c) { return (*this = (*this - c)); } bool operator == (const LrColor & c_lhs, const LrColor & c_rhs) { return ((c_lhs.m_r == c_rhs.m_r) && (c_lhs.m_g == c_rhs.m_g) && (c_lhs.m_b == c_rhs.m_b)); } bool operator != (const LrColor & c_lhs, const LrColor & c_rhs) { return !(c_lhs == c_rhs); } LrColor operator + (const LrColor &lhs, const LrColor &rhs) { LrColor color; color.m_r = lhs.m_r + rhs.m_r; if(color.m_r > 1)color.m_r = 1; color.m_g = lhs.m_g + rhs.m_g; if(color.m_g > 1)color.m_g = 1; color.m_b = lhs.m_b + rhs.m_b; if(color.m_b > 1)color.m_b = 1; return color; } LrColor operator - (const LrColor &lhs, const LrColor &rhs) { LrColor color; color.m_r = lhs.m_r - rhs.m_r; if(color.m_r < 0)color.m_r = 0; color.m_g = lhs.m_g - rhs.m_g; if(color.m_g < 0)color.m_g = 0; color.m_b = lhs.m_b - rhs.m_b; if(color.m_b < 0)color.m_b = 0; return color; }
LrColor.h +62 −92 Original line number Diff line number Diff line /***************************************************************************** * class LrColor (specification) * * * * author : Gilles Subrenat * * creation : Sunday, March 2 2008 (3/2/2008) * * note : * *****************************************************************************/ /** * @brief OBJET : une couleur * @file LrColor.h * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'une couleur */ #ifndef LRCOLOR_h #define LRCOLOR_h #ifndef LRCOLOR_H #define LRCOLOR_H class LrColor { public: static const LrColor BLACK; static const LrColor WHITE; static const LrColor RED; static const LrColor GREEN; static const LrColor BLUE; static const LrColor CYAN; static const LrColor MAGENTA; static const LrColor YELLOW; // constructors and destructor // *************************** private : Real m_r; Real m_g; Real m_b; public : LrColor(); LrColor(const LrColor &source); LrColor(const LrColor & c); LrColor(Real red, Real green, Real blue); explicit LrColor(Real grey); ~LrColor(); virtual ~LrColor(); // assignement operator(s) // *********************** LrColor & operator = (const LrColor &source); LrColor & operator += (const LrColor &source); LrColor & operator += (Real grey); LrColor & operator -= (const LrColor &source); LrColor & operator -= (Real grey); LrColor & operator *= (const LrColor &source); LrColor & operator *= (Real factor); LrColor & operator /= (Real factor); // comparison operator(s) // ********************** friend bool operator == (const LrColor &lhs, const LrColor &rhs); friend bool operator != (const LrColor &lhs, const LrColor &rhs); // "mathematical" operator(s) // ************************** friend LrColor operator + (const LrColor &lhs, const LrColor &rhs); friend LrColor operator + (Real lhs, const LrColor &rhs); friend LrColor operator + (const LrColor &lhs, Real rhs); friend LrColor operator - (const LrColor &lhs, const LrColor &rhs); friend LrColor operator - (Real lhs, const LrColor &rhs); friend LrColor operator - (const LrColor &lhs, Real rhs); friend LrColor operator * (const LrColor &lhs, const LrColor &rhs); friend LrColor operator * (Real lhs, const LrColor &rhs); friend LrColor operator * (const LrColor &lhs, Real rhs); friend LrColor operator / (const LrColor &lhs, Real rhs); // accessors // ********* LrColor & operator = (const LrColor & c); LrColor & operator += (const LrColor & c); LrColor & operator -= (const LrColor & c); Real getRed() const; void setRed(Real red); Real getGreen() const; void setGreen(Real green); Real getBlue() const; void setBlue(Real blue); void setRGB(Real red, Real green, Real blue); Real getGrey() const; void setGrey(Real grey); Real getLuminosity() const; /*met � jour les parametre rentrant en convertissant l es valeur real de l'instance au format RGB 255*/ void toRGB255 (int & red, int & green, int & blue) const; /*Modifie les valeurs de l'instance � partir de valeurs RGB255*/ void fromRGB255 (const int red, const int green, const int blue); private: friend bool operator == (const LrColor & c_lhs, const LrColor & c_rhs); friend bool operator != (const LrColor & c_lhs, const LrColor & c_rhs); // data // **** friend LrColor operator + (const LrColor &lhs, const LrColor &rhs); friend LrColor operator - (const LrColor &lhs, const LrColor &rhs); Real m_red; Real m_green; Real m_blue; }; }; #endif
LrPoint.cpp +31 −15 Original line number Diff line number Diff line /** * @brief OBJET : un point 3D * @file LrPoint.cpp * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'un point 3D */ #include "config.h" #include "LrPoint.h" /*---------------------------------------------------------------------------* * constructors and destructor * *---------------------------------------------------------------------------*/ LrPoint::LrPoint() :x(0), y(0), z(0) :m_x(0), m_y(0), m_z(0) { } LrPoint::LrPoint(const LrPoint &source) :x(source.x), y(source.y), z(source.z) :m_x(source.m_x), m_y(source.m_y), m_z(source.m_z) { } LrPoint::LrPoint(Real x, Real y, Real z) :x(x), y(y), z(z) :m_x(x), m_y(y), m_z(z) { } Loading @@ -29,9 +44,9 @@ LrPoint::~LrPoint() void LrPoint::translate(const LrVector &v) { x+=v.getCompo(X); y+=v.getCompo(Y); z+=v.getCompo(Z); m_x+=v.getCompo(X); m_y+=v.getCompo(Y); m_z+=v.getCompo(Z); } /*---------------------------------------------------------------------------* * assignement operator(s) * Loading @@ -39,9 +54,9 @@ void LrPoint::translate(const LrVector &v) LrPoint & LrPoint::operator = (const LrPoint &source) { if(this == &source) return (*this); this->x = source.x; this->y = source.y; this->z = source.z; m_x = source.m_x; m_y = source.m_y; m_z = source.m_z; return (*this); } Loading @@ -51,7 +66,7 @@ LrPoint & LrPoint::operator = (const LrPoint &source) bool operator == (const LrPoint &lhs, const LrPoint &rhs) { return ((lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.z == rhs.z)); return ((lhs.m_x == rhs.m_x) && (lhs.m_y == rhs.m_y) && (lhs.m_z == rhs.m_z)); } bool operator != (const LrPoint &lhs, const LrPoint &rhs) Loading @@ -63,12 +78,12 @@ bool operator != (const LrPoint &lhs, const LrPoint &rhs) *---------------------------------------------------------------------------*/ static Real distance(const LrPoint &p1, const LrPoint &p2) { return sqrt(pow((p2.x - p1.x),2)+ pow((p2.y - p1.y),2)+ pow((p2.z - p1.z),2)); return sqrt(pow((p2.m_x - p1.m_x),2)+ pow((p2.m_y - p1.m_y),2)+ pow((p2.m_z - p1.m_z),2)); } static LrPoint middle(const LrPoint &p1, const LrPoint &p2) { LrPoint point((p2.x - p1.x), (p2.y - p1.y), (p2.z - p1.z)); LrPoint point((p2.m_x - p1.m_x), (p2.m_y - p1.m_y), (p2.m_z - p1.m_z)); return point; } Loading @@ -76,11 +91,12 @@ static LrPoint interpolate(Real t, const LrPoint &p1,const LrPoint &p2) { } static LrPoint translate( const LrPoint &p, const LrVector &v) { LrPoint point; point.x = x + v.getCompo(X); point.y = y + v.getCompo(Y); point.z = z + v.getCompo(Z); point.m_x = p.m_x + v.getCompo(X); point.m_y = p.m_y + v.getCompo(Y); point.m_z = p.m_z + v.getCompo(Z); return point; }
LrPoint.h +15 −9 Original line number Diff line number Diff line /***************************************************************************** * class LrPoint (specification) * * * * author : Gilles Subrenat * * creation : Sunday, March 2 2008 (3/2/2008) * * note : * *****************************************************************************/ /** * @brief OBJET : un point 3D * @file LrPoint.h * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'un point 3D */ #ifndef LRPOINT3D_H #define LRPOINT3D_H #include "config.h" #include <math.h> class LrVector; Loading Loading @@ -74,7 +80,7 @@ public: // **** // public members EXCEPTIONNALY : to simplify use of this class Real x, y, z; Real m_x, m_y, m_z; private: Loading
LrVector.cpp +16 −0 Original line number Diff line number Diff line /** * @brief OBJET : un vecteur 3D * @file LrVector.cpp * @date Vendredi 7 mars 2008 * @note * @author Josselin Francois * @author Michael Nauge * @author Axel Richard * @author Hervé Souchaud * @author Emeric Verschuur * * Ce fichier contient la classe qui gère la creation d'un vecteur 3D */ #include "config.h" #include "LrVector.h" ////////////////////////////// CONSTRUCTEURS /////////////////////////////////////////////////////// //Par defaut Loading