diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-29 00:21:05 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-29 00:21:05 +0400 |
commit | e5791cf48e10ec1336f463b7fccff6b302621eb9 (patch) | |
tree | 58ea33117cc9be35713b6d93ea9d1dfa538ca5bd /source/blender/freestyle/intern/scene_graph | |
parent | 9fe9c1d6436e400217fdfd8999117a4719efdf68 (diff) |
Another mega (literally :p) code clean-up patch by Bastien Montagne, thanks again!
Diffstat (limited to 'source/blender/freestyle/intern/scene_graph')
31 files changed, 3404 insertions, 2683 deletions
diff --git a/source/blender/freestyle/intern/scene_graph/DrawingStyle.h b/source/blender/freestyle/intern/scene_graph/DrawingStyle.h index 58dcf4fede9..000b6c8575d 100644 --- a/source/blender/freestyle/intern/scene_graph/DrawingStyle.h +++ b/source/blender/freestyle/intern/scene_graph/DrawingStyle.h @@ -1,82 +1,128 @@ -// -// Filename : DrawingStyle.h -// Author(s) : Stephane Grabli -// Purpose : Class to define the drawing style of a node -// Date of creation : 10/10/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef DRAWINGSTYLE_H -# define DRAWINGSTYLE_H +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_DRAWING_STYLE_H__ +#define __FREESTYLE_DRAWING_STYLE_H__ + +/** \file blender/freestyle/intern/scene_graph/DrawingStyle.h + * \ingroup freestyle + * \brief Class to define the drawing style of a node + * \author Stephane Grabli + * \date 10/10/2002 + */ class DrawingStyle { public: - enum STYLE - {FILLED, LINES, POINTS, INVISIBLE}; - - inline DrawingStyle() {Style = FILLED; LineWidth = 2.f; PointSize = 2.f; LightingEnabled = true;} - inline explicit DrawingStyle(const DrawingStyle& iBrother); - - virtual ~DrawingStyle() {} - - /*! operators */ - inline DrawingStyle& operator=(const DrawingStyle& ds); - - inline void setStyle(const STYLE iStyle) {Style = iStyle;} - inline void setLineWidth(const float iLineWidth) {LineWidth = iLineWidth;} - inline void setPointSize(const float iPointSize) {PointSize = iPointSize;} - inline void setLightingEnabled(const bool on) {LightingEnabled = on;} - - inline STYLE style() const {return Style;} - inline float lineWidth() const {return LineWidth;} - inline float pointSize() const {return PointSize;} - inline bool lightingEnabled() const {return LightingEnabled;} + enum STYLE { + FILLED, + LINES, + POINTS, + INVISIBLE, + }; + + inline DrawingStyle() + { + Style = FILLED; + LineWidth = 2.0f; + PointSize = 2.0f; + LightingEnabled = true; + } + + inline explicit DrawingStyle(const DrawingStyle& iBrother); + + virtual ~DrawingStyle() {} + + /*! operators */ + inline DrawingStyle& operator=(const DrawingStyle& ds); + + inline void setStyle(const STYLE iStyle) + { + Style = iStyle; + } + + inline void setLineWidth(const float iLineWidth) + { + LineWidth = iLineWidth; + } + + inline void setPointSize(const float iPointSize) + { + PointSize = iPointSize; + } + + inline void setLightingEnabled(const bool on) + { + LightingEnabled = on; + } + + inline STYLE style() const + { + return Style; + } + + inline float lineWidth() const + { + return LineWidth; + } + + inline float pointSize() const + { + return PointSize; + } + + inline bool lightingEnabled() const + { + return LightingEnabled; + } private: - STYLE Style; - float LineWidth; - float PointSize; - bool LightingEnabled; + STYLE Style; + float LineWidth; + float PointSize; + bool LightingEnabled; }; DrawingStyle::DrawingStyle(const DrawingStyle& iBrother) { - Style = iBrother.Style; - LineWidth = iBrother.LineWidth; - PointSize = iBrother.PointSize; - LightingEnabled = iBrother.LightingEnabled; + Style = iBrother.Style; + LineWidth = iBrother.LineWidth; + PointSize = iBrother.PointSize; + LightingEnabled = iBrother.LightingEnabled; } DrawingStyle& DrawingStyle::operator=(const DrawingStyle& ds) { - Style = ds.Style; - LineWidth = ds.LineWidth; - PointSize = ds.PointSize; - LightingEnabled = ds.LightingEnabled; + Style = ds.Style; + LineWidth = ds.LineWidth; + PointSize = ds.PointSize; + LightingEnabled = ds.LightingEnabled; - return *this; + return *this; } -#endif // DRAWINGSTYLE_H +#endif // __FREESTYLE_DRAWING_STYLE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h index 1cbadab2bd3..831c384d472 100644 --- a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h +++ b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h @@ -1,304 +1,379 @@ -// -// Filename : FrsMaterial.h -// Author(s) : Stephane Grabli -// Purpose : Class used to handle materials. -// Date of creation : 10/10/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef FRS_MATERIAL_H -# define FRS_MATERIAL_H - -# include "../system/FreestyleConfig.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_MATERIAL_H__ +#define __FREESTYLE_MATERIAL_H__ + +/** \file blender/freestyle/intern/scene_graph/FrsMaterial.h + * \ingroup freestyle + * \brief Class used to handle materials. + * \author Stephane Grabli + * \date 10/10/2002 + */ + +#include "../system/FreestyleConfig.h" /*! Class defining a material */ class FrsMaterial { public: - /*! Default constructor */ - inline FrsMaterial(); - /*! Builds a Material from its diffuse, ambiant, specular, emissive - * colors and a shininess coefficient. - * \param iDiffuse - * A 4 element float-array containing the diffuse color. - * \param iAmbiant - * A 4 element float-array containing the ambiant color. - * \param iSpecular - * A 4 element float-array containing the specular color. - * \param iEmission - * A 4 element float-array containing the emissive color. - * \param iShininess - * The shininess coefficient. - */ - inline FrsMaterial(const float *iDiffuse, - const float *iAmbiant, - const float *iSpecular, - const float *iEmission, - const float iShininess); - - /*! Copy constructor */ - inline FrsMaterial(const FrsMaterial& m); - /*! Destructor */ - virtual ~FrsMaterial() {} - - - /*! Returns the diffuse color as a 4 float array */ - inline const float * diffuse() const { return Diffuse; } - /*! Returns the red component of the diffuse color */ - inline const float diffuseR() const { return Diffuse[0]; } - /*! Returns the green component of the diffuse color */ - inline const float diffuseG() const { return Diffuse[1]; } - /*! Returns the blue component of the diffuse color */ - inline const float diffuseB() const { return Diffuse[2]; } - /*! Returns the alpha component of the diffuse color */ - inline const float diffuseA() const { return Diffuse[3]; } - - /*! Returns the specular color as a 4 float array */ - inline const float * specular() const { return Specular; } - /*! Returns the red component of the specular color */ - inline const float specularR() const { return Specular[0]; } - /*! Returns the green component of the specular color */ - inline const float specularG() const { return Specular[1]; } - /*! Returns the blue component of the specular color */ - inline const float specularB() const { return Specular[2]; } - /*! Returns the alpha component of the specular color */ - inline const float specularA() const { return Specular[3]; } - - /*! Returns the ambiant color as a 4 float array */ - inline const float * ambient() const { return Ambient; } - /*! Returns the red component of the ambiant color */ - inline const float ambientR() const { return Ambient[0]; } - /*! Returns the green component of the ambiant color */ - inline const float ambientG() const { return Ambient[1]; } - /*! Returns the blue component of the ambiant color */ - inline const float ambientB() const { return Ambient[2]; } - /*! Returns the alpha component of the ambiant color */ - inline const float ambientA() const { return Ambient[3]; } - - /*! Returns the emissive color as a 4 float array */ - inline const float * emission() const { return Emission; } - /*! Returns the red component of the emissive color */ - inline const float emissionR() const { return Emission[0]; } - /*! Returns the green component of the emissive color */ - inline const float emissionG() const { return Emission[1]; } - /*! Returns the blue component of the emissive color */ - inline const float emissionB() const { return Emission[2]; } - /*! Returns the alpha component of the emissive color */ - inline const float emissionA() const { return Emission[3]; } - - /*! Returns the shininess coefficient */ - inline const float shininess() const { return Shininess; } - - /*! Sets the diffuse color. - * \param r - * Red component - * \param g - * Green component - * \param b - * Blue component - * \param a - * Alpha component - */ - inline void setDiffuse(const float r, const float g, const float b, const float a); - /*! Sets the specular color. - * \param r - * Red component - * \param g - * Green component - * \param b - * Blue component - * \param a - * Alpha component - */ - inline void setSpecular(const float r, const float g, const float b, const float a); - /*! Sets the ambiant color. - * \param r - * Red component - * \param g - * Green component - * \param b - * Blue component - * \param a - * Alpha component - */ - inline void setAmbient(const float r, const float g, const float b, const float a); - - /*! Sets the emissive color. - * \param r - * Red component - * \param g - * Green component - * \param b - * Blue component - * \param a - * Alpha component - */ - inline void setEmission(const float r, const float g, const float b, const float a); - - /*! Sets the shininess. - * \param s - * Shininess - */ - inline void setShininess(const float s); - - /* operators */ - inline FrsMaterial& operator=(const FrsMaterial& m); - inline bool operator!=(const FrsMaterial& m) const; - inline bool operator==(const FrsMaterial& m) const; + /*! Default constructor */ + inline FrsMaterial(); + + /*! Builds a Material from its diffuse, ambiant, specular, emissive colors and a shininess coefficient. + * \param iDiffuse + * A 4 element float-array containing the diffuse color. + * \param iAmbiant + * A 4 element float-array containing the ambiant color. + * \param iSpecular + * A 4 element float-array containing the specular color. + * \param iEmission + * A 4 element float-array containing the emissive color. + * \param iShininess + * The shininess coefficient. + */ + inline FrsMaterial(const float *iDiffuse, const float *iAmbiant, const float *iSpecular, const float *iEmission, + const float iShininess); + + /*! Copy constructor */ + inline FrsMaterial(const FrsMaterial& m); + + /*! Destructor */ + virtual ~FrsMaterial() {} + + + /*! Returns the diffuse color as a 4 float array */ + inline const float *diffuse() const + { + return Diffuse; + } + + /*! Returns the red component of the diffuse color */ + inline const float diffuseR() const + { + return Diffuse[0]; + } + + /*! Returns the green component of the diffuse color */ + inline const float diffuseG() const + { + return Diffuse[1]; + } + + /*! Returns the blue component of the diffuse color */ + inline const float diffuseB() const + { + return Diffuse[2]; + } + + /*! Returns the alpha component of the diffuse color */ + inline const float diffuseA() const + { + return Diffuse[3]; + } + + /*! Returns the specular color as a 4 float array */ + inline const float *specular() const + { + return Specular; + } + + /*! Returns the red component of the specular color */ + inline const float specularR() const + { + return Specular[0]; + } + + /*! Returns the green component of the specular color */ + inline const float specularG() const + { + return Specular[1]; + } + + /*! Returns the blue component of the specular color */ + inline const float specularB() const + { + return Specular[2]; + } + + /*! Returns the alpha component of the specular color */ + inline const float specularA() const + { + return Specular[3]; + } + + /*! Returns the ambiant color as a 4 float array */ + inline const float *ambient() const + { + return Ambient; + } + + /*! Returns the red component of the ambiant color */ + inline const float ambientR() const + { + return Ambient[0]; + } + + /*! Returns the green component of the ambiant color */ + inline const float ambientG() const + { + return Ambient[1]; + } + + /*! Returns the blue component of the ambiant color */ + inline const float ambientB() const + { + return Ambient[2]; + } + + /*! Returns the alpha component of the ambiant color */ + inline const float ambientA() const + { + return Ambient[3]; + } + + /*! Returns the emissive color as a 4 float array */ + inline const float *emission() const + { + return Emission; + } + + /*! Returns the red component of the emissive color */ + inline const float emissionR() const + { + return Emission[0]; + } + + /*! Returns the green component of the emissive color */ + inline const float emissionG() const + { + return Emission[1]; + } + + /*! Returns the blue component of the emissive color */ + inline const float emissionB() const + { + return Emission[2]; + } + + /*! Returns the alpha component of the emissive color */ + inline const float emissionA() const + { + return Emission[3]; + } + + /*! Returns the shininess coefficient */ + inline const float shininess() const + { + return Shininess; + } + + /*! Sets the diffuse color. + * \param r + * Red component + * \param g + * Green component + * \param b + * Blue component + * \param a + * Alpha component + */ + inline void setDiffuse(const float r, const float g, const float b, const float a); + + /*! Sets the specular color. + * \param r + * Red component + * \param g + * Green component + * \param b + * Blue component + * \param a + * Alpha component + */ + inline void setSpecular(const float r, const float g, const float b, const float a); + + /*! Sets the ambiant color. + * \param r + * Red component + * \param g + * Green component + * \param b + * Blue component + * \param a + * Alpha component + */ + inline void setAmbient(const float r, const float g, const float b, const float a); + + /*! Sets the emissive color. + * \param r + * Red component + * \param g + * Green component + * \param b + * Blue component + * \param a + * Alpha component + */ + inline void setEmission(const float r, const float g, const float b, const float a); + + /*! Sets the shininess. + * \param s + * Shininess + */ + inline void setShininess(const float s); + + /* operators */ + inline FrsMaterial& operator=(const FrsMaterial& m); + inline bool operator!=(const FrsMaterial& m) const; + inline bool operator==(const FrsMaterial& m) const; private: - - /*! Material properties */ - float Diffuse[4]; - float Specular[4]; - float Ambient[4]; - float Emission[4]; - float Shininess; - + /*! Material properties */ + float Diffuse[4]; + float Specular[4]; + float Ambient[4]; + float Emission[4]; + float Shininess; }; FrsMaterial::FrsMaterial() { - Ambient[0] = Ambient[1] = Ambient[2] = 0.2f; - Ambient[3] = 1.f; + Ambient[0] = Ambient[1] = Ambient[2] = 0.2f; + Ambient[3] = 1.0f; - Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f; - Diffuse[3] = 1.f; + Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f; + Diffuse[3] = 1.0f; - Emission[0] = Emission[1] = Emission[2] = 0.f; - Emission[3] = 1.f; + Emission[0] = Emission[1] = Emission[2] = 0.0f; + Emission[3] = 1.0f; - Specular[0] = Specular[1] = Specular[2] = 0.f; - Specular[3] = 1.f; + Specular[0] = Specular[1] = Specular[2] = 0.0f; + Specular[3] = 1.0f; - Shininess = 0.f; + Shininess = 0.0f; } -FrsMaterial::FrsMaterial(const float *iDiffuse, - const float *iAmbiant, - const float *iSpecular, - const float *iEmission, - const float iShininess) +FrsMaterial::FrsMaterial(const float *iDiffuse, const float *iAmbiant, const float *iSpecular, const float *iEmission, + const float iShininess) { - for(int i=0; i<4; i++) - { - Diffuse[i] = iDiffuse[i]; - Specular[i] = iSpecular[i]; - Ambient[i] = iAmbiant[i]; - Emission[i] = iEmission[i]; - } - - Shininess = iShininess; + for (int i = 0; i < 4; i++) { + Diffuse[i] = iDiffuse[i]; + Specular[i] = iSpecular[i]; + Ambient[i] = iAmbiant[i]; + Emission[i] = iEmission[i]; + } + + Shininess = iShininess; } FrsMaterial::FrsMaterial(const FrsMaterial& m) { - for(int i=0; i<4; i++) - { - Diffuse[i] = m.diffuse()[i]; - Specular[i] = m.specular()[i]; - Ambient[i] = m.ambient()[i]; - Emission[i] = m.emission()[i]; - } - - Shininess = m.shininess(); + for (int i = 0; i < 4; i++) { + Diffuse[i] = m.diffuse()[i]; + Specular[i] = m.specular()[i]; + Ambient[i] = m.ambient()[i]; + Emission[i] = m.emission()[i]; + } + + Shininess = m.shininess(); } void FrsMaterial::setDiffuse(const float r, const float g, const float b, const float a) { - Diffuse[0] = r; - Diffuse[1] = g; - Diffuse[2] = b; - Diffuse[3] = a; + Diffuse[0] = r; + Diffuse[1] = g; + Diffuse[2] = b; + Diffuse[3] = a; } void FrsMaterial::setSpecular(const float r, const float g, const float b, const float a) { - Specular[0] = r; - Specular[1] = g; - Specular[2] = b; - Specular[3] = a; + Specular[0] = r; + Specular[1] = g; + Specular[2] = b; + Specular[3] = a; } - + void FrsMaterial::setAmbient(const float r, const float g, const float b, const float a) { - Ambient[0] = r; - Ambient[1] = g; - Ambient[2] = b; - Ambient[3] = a; + Ambient[0] = r; + Ambient[1] = g; + Ambient[2] = b; + Ambient[3] = a; } void FrsMaterial::setEmission(const float r, const float g, const float b, const float a) { - Emission[0] = r; - Emission[1] = g; - Emission[2] = b; - Emission[3] = a; + Emission[0] = r; + Emission[1] = g; + Emission[2] = b; + Emission[3] = a; } void FrsMaterial::setShininess(const float s) { - Shininess = s; + Shininess = s; } FrsMaterial& FrsMaterial::operator=(const FrsMaterial& m) { - for(int i=0; i<4; i++) - { - Diffuse[i] = m.diffuse()[i]; - Specular[i] = m.specular()[i]; - Ambient[i] = m.ambient()[i]; - Emission[i] = m.emission()[i]; - } - - Shininess = m.shininess(); - - return *this; + for (int i = 0; i < 4; i++) { + Diffuse[i] = m.diffuse()[i]; + Specular[i] = m.specular()[i]; + Ambient[i] = m.ambient()[i]; + Emission[i] = m.emission()[i]; + } + + Shininess = m.shininess(); + return *this; } bool FrsMaterial::operator!=(const FrsMaterial& m) const { - if(Shininess != m.shininess()) - return true; - for(int i=0; i<4; i++) - { - if(Diffuse[i] != m.diffuse()[i]) - return true; - if(Specular[i] != m.specular()[i]) - return true; - if(Ambient[i] != m.ambient()[i]) - return true; - if(Emission[i] != m.emission()[i]) - return true; - } - - return false; + if (Shininess != m.shininess()) + return true; + + for (int i = 0; i < 4; i++) { + if (Diffuse[i] != m.diffuse()[i]) + return true; + if (Specular[i] != m.specular()[i]) + return true; + if (Ambient[i] != m.ambient()[i]) + return true; + if (Emission[i] != m.emission()[i]) + return true; + } + + return false; } bool FrsMaterial::operator==(const FrsMaterial& m) const { - return (!((*this)!=m)); + return (!((*this) != m)); } -#endif // FRS_MATERIAL_H +#endif // __FREESTYLE_MATERIAL_H__ diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp index aaeba943ab6..f373b730d0f 100644 --- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp +++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp @@ -1,336 +1,331 @@ - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp + * \ingroup freestyle + * \brief A Set of indexed faces to represent a surfacic object + * \author Stephane Grabli + * \date 22/01/2002 + */ #include "IndexedFaceSet.h" -IndexedFaceSet::IndexedFaceSet() -: Rep() +IndexedFaceSet::IndexedFaceSet() : Rep() { - _Vertices = NULL; - _Normals = NULL; - _FrsMaterials = 0; - _TexCoords = 0; - _FaceEdgeMarks = 0; - _VSize = 0; - _NSize = 0; - _MSize = 0; - _TSize = 0; - _NumFaces = 0; - _NumVertexPerFace = NULL; - _FaceStyle = NULL; - _VIndices = NULL; - _VISize = 0; - _NIndices = NULL; - _NISize = 0; - _MIndices = NULL; - _MISize = 0; - _TIndices = NULL; - _TISize = 0; - _displayList = 0; + _Vertices = NULL; + _Normals = NULL; + _FrsMaterials = 0; + _TexCoords = 0; + _FaceEdgeMarks = 0; + _VSize = 0; + _NSize = 0; + _MSize = 0; + _TSize = 0; + _NumFaces = 0; + _NumVertexPerFace = NULL; + _FaceStyle = NULL; + _VIndices = NULL; + _VISize = 0; + _NIndices = NULL; + _NISize = 0; + _MIndices = NULL; + _MISize = 0; + _TIndices = NULL; + _TISize = 0; + _displayList = 0; } -IndexedFaceSet::IndexedFaceSet( real *iVertices, unsigned iVSize, - real *iNormals, unsigned iNSize, - FrsMaterial **iMaterials, unsigned iMSize, - real *iTexCoords, unsigned iTSize, - unsigned iNumFaces, unsigned *iNumVertexPerFace, TRIANGLES_STYLE *iFaceStyle, - FaceEdgeMark *iFaceEdgeMarks, - unsigned *iVIndices, unsigned iVISize, - unsigned *iNIndices, unsigned iNISize, - unsigned *iMIndices, unsigned iMISize, - unsigned *iTIndices, unsigned iTISize, - unsigned iCopy) - : Rep() +IndexedFaceSet::IndexedFaceSet(real *iVertices, unsigned iVSize, real *iNormals, unsigned iNSize, + FrsMaterial **iMaterials, unsigned iMSize, real *iTexCoords, unsigned iTSize, + unsigned iNumFaces, unsigned *iNumVertexPerFace, TRIANGLES_STYLE *iFaceStyle, + FaceEdgeMark *iFaceEdgeMarks, unsigned *iVIndices, unsigned iVISize, + unsigned *iNIndices, unsigned iNISize, unsigned *iMIndices, unsigned iMISize, + unsigned *iTIndices, unsigned iTISize, unsigned iCopy) +: Rep() { - if(1 == iCopy) - { - _VSize = iVSize; - _Vertices = new real[_VSize]; - memcpy(_Vertices, iVertices, iVSize*sizeof(real)); - - _NSize = iNSize; - _Normals = new real[_NSize]; - memcpy(_Normals, iNormals, iNSize*sizeof(real)); - - _MSize = iMSize; - _FrsMaterials = 0; - if(iMaterials){ - _FrsMaterials = new FrsMaterial*[_MSize]; - for(unsigned i=0; i<_MSize; ++i) - _FrsMaterials[i] = new FrsMaterial(*(iMaterials[i])); - } - _TSize = iTSize; - _TexCoords = 0; - if(_TSize){ - _TexCoords = new real[_TSize]; - memcpy(_TexCoords, iTexCoords, iTSize*sizeof(real)); - } - - _NumFaces = iNumFaces; - _NumVertexPerFace = new unsigned[_NumFaces]; - memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces*sizeof(unsigned)); - - _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; - memcpy(_FaceStyle, iFaceStyle, _NumFaces*sizeof(TRIANGLES_STYLE)); - - _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; - memcpy(_FaceEdgeMarks, iFaceEdgeMarks, _NumFaces*sizeof(FaceEdgeMark)); - - _VISize = iVISize; - _VIndices = new unsigned[_VISize]; - memcpy(_VIndices, iVIndices, _VISize*sizeof(unsigned)); - - _NISize = iNISize; - _NIndices = new unsigned[_NISize]; - memcpy(_NIndices, iNIndices, _NISize*sizeof(unsigned)); - - _MISize = iMISize; + if (1 == iCopy) { + _VSize = iVSize; + _Vertices = new real[_VSize]; + memcpy(_Vertices, iVertices, iVSize * sizeof(real)); + + _NSize = iNSize; + _Normals = new real[_NSize]; + memcpy(_Normals, iNormals, iNSize * sizeof(real)); + + _MSize = iMSize; + _FrsMaterials = 0; + if (iMaterials) { + _FrsMaterials = new FrsMaterial * [_MSize]; + for (unsigned int i = 0; i < _MSize; ++i) + _FrsMaterials[i] = new FrsMaterial(*(iMaterials[i])); + } + _TSize = iTSize; + _TexCoords = 0; + if (_TSize) { + _TexCoords = new real[_TSize]; + memcpy(_TexCoords, iTexCoords, iTSize * sizeof(real)); + } + + _NumFaces = iNumFaces; + _NumVertexPerFace = new unsigned[_NumFaces]; + memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces * sizeof(unsigned)); + + _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; + memcpy(_FaceStyle, iFaceStyle, _NumFaces * sizeof(TRIANGLES_STYLE)); + + _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; + memcpy(_FaceEdgeMarks, iFaceEdgeMarks, _NumFaces * sizeof(FaceEdgeMark)); + + _VISize = iVISize; + _VIndices = new unsigned[_VISize]; + memcpy(_VIndices, iVIndices, _VISize * sizeof(unsigned)); + + _NISize = iNISize; + _NIndices = new unsigned[_NISize]; + memcpy(_NIndices, iNIndices, _NISize * sizeof(unsigned)); + + _MISize = iMISize; _MIndices = 0; - if(iMIndices){ + if (iMIndices) { _MIndices = new unsigned[_MISize]; - memcpy(_MIndices, iMIndices, _MISize*sizeof(unsigned)); + memcpy(_MIndices, iMIndices, _MISize * sizeof(unsigned)); } - _TISize = iTISize; - _TIndices = 0; - if(_TISize){ - _TIndices = new unsigned[_TISize]; - memcpy(_TIndices, iTIndices, _TISize*sizeof(unsigned)); - } - } - else - { - _VSize = iVSize; - _Vertices = iVertices; - - _NSize = iNSize; - _Normals = iNormals; - - _MSize = iMSize; + _TISize = iTISize; + _TIndices = 0; + if (_TISize) { + _TIndices = new unsigned[_TISize]; + memcpy(_TIndices, iTIndices, _TISize * sizeof(unsigned)); + } + } + else { + _VSize = iVSize; + _Vertices = iVertices; + + _NSize = iNSize; + _Normals = iNormals; + + _MSize = iMSize; _FrsMaterials = 0; - if(iMaterials) + if (iMaterials) _FrsMaterials = iMaterials; - - _TSize = iTSize; - _TexCoords = iTexCoords; - - _NumFaces = iNumFaces; - _NumVertexPerFace = iNumVertexPerFace; - _FaceStyle = iFaceStyle; - _FaceEdgeMarks = iFaceEdgeMarks; - - _VISize = iVISize; - _VIndices = iVIndices; - - _NISize = iNISize; - _NIndices = iNIndices; - - _MISize = iMISize; + + _TSize = iTSize; + _TexCoords = iTexCoords; + + _NumFaces = iNumFaces; + _NumVertexPerFace = iNumVertexPerFace; + _FaceStyle = iFaceStyle; + _FaceEdgeMarks = iFaceEdgeMarks; + + _VISize = iVISize; + _VIndices = iVIndices; + + _NISize = iNISize; + _NIndices = iNIndices; + + _MISize = iMISize; _MIndices = 0; - if(iMISize) + if (iMISize) _MIndices = iMIndices; - _TISize = iTISize; - _TIndices = iTIndices; - } + _TISize = iTISize; + _TIndices = iTIndices; + } - _displayList = 0; + _displayList = 0; } -IndexedFaceSet::IndexedFaceSet( const IndexedFaceSet& iBrother) -:Rep(iBrother) +IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet& iBrother) : Rep(iBrother) { - _VSize = iBrother.vsize(); - _Vertices = new real[_VSize]; - memcpy(_Vertices, iBrother.vertices(), _VSize*sizeof(real)); - - _NSize = iBrother.nsize(); - _Normals = new real[_NSize]; - memcpy(_Normals, iBrother.normals(), _NSize*sizeof(real)); - - _MSize = iBrother.msize(); - if(_MSize){ - _FrsMaterials = new FrsMaterial*[_MSize]; - for(unsigned i=0; i<_MSize; ++i){ + _VSize = iBrother.vsize(); + _Vertices = new real[_VSize]; + memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(real)); + + _NSize = iBrother.nsize(); + _Normals = new real[_NSize]; + memcpy(_Normals, iBrother.normals(), _NSize * sizeof(real)); + + _MSize = iBrother.msize(); + if (_MSize) { + _FrsMaterials = new FrsMaterial * [_MSize]; + for (unsigned int i = 0; i < _MSize; ++i) { _FrsMaterials[i] = new FrsMaterial(*(iBrother._FrsMaterials[i])); } - }else{ + } + else { _FrsMaterials = 0; } - _TSize = iBrother.tsize(); - _TexCoords = 0; - if(_TSize){ - _TexCoords = new real[_TSize]; - memcpy(_TexCoords, iBrother.texCoords(), _TSize*sizeof(real)); - } - - _NumFaces = iBrother.numFaces(); - _NumVertexPerFace = new unsigned[_NumFaces]; - memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces*sizeof(unsigned)); - - _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; - memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces*sizeof(TRIANGLES_STYLE)); - - _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; - memcpy(_FaceEdgeMarks, iBrother.faceEdgeMarks(), _NumFaces*sizeof(FaceEdgeMark)); - - _VISize = iBrother.visize(); - _VIndices = new unsigned[_VISize]; - memcpy(_VIndices, iBrother.vindices(), _VISize*sizeof(unsigned)); - - _NISize = iBrother.nisize(); - _NIndices = new unsigned[_NISize]; - memcpy(_NIndices, iBrother.nindices(), _NISize*sizeof(unsigned)); - - _MISize = iBrother.misize(); - if(_MISize){ + _TSize = iBrother.tsize(); + _TexCoords = 0; + if (_TSize) { + _TexCoords = new real[_TSize]; + memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(real)); + } + + _NumFaces = iBrother.numFaces(); + _NumVertexPerFace = new unsigned[_NumFaces]; + memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces * sizeof(unsigned)); + + _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; + memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces * sizeof(TRIANGLES_STYLE)); + + _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; + memcpy(_FaceEdgeMarks, iBrother.faceEdgeMarks(), _NumFaces * sizeof(FaceEdgeMark)); + + _VISize = iBrother.visize(); + _VIndices = new unsigned[_VISize]; + memcpy(_VIndices, iBrother.vindices(), _VISize * sizeof(unsigned)); + + _NISize = iBrother.nisize(); + _NIndices = new unsigned[_NISize]; + memcpy(_NIndices, iBrother.nindices(), _NISize * sizeof(unsigned)); + + _MISize = iBrother.misize(); + if (_MISize) { _MIndices = new unsigned[_MISize]; - memcpy(_MIndices, iBrother.mindices(), _MISize*sizeof(unsigned)); - }else{ - _MIndices=0; + memcpy(_MIndices, iBrother.mindices(), _MISize * sizeof(unsigned)); + } + else { + _MIndices = 0; } - _TISize = iBrother.tisize(); - _TIndices = 0; - if(_TISize){ - _TIndices = new unsigned[_TISize]; - memcpy(_TIndices, iBrother.tindices(), _TISize*sizeof(unsigned)); - } + _TISize = iBrother.tisize(); + _TIndices = 0; + if (_TISize) { + _TIndices = new unsigned[_TISize]; + memcpy(_TIndices, iBrother.tindices(), _TISize * sizeof(unsigned)); + } - _displayList = 0; + _displayList = 0; } IndexedFaceSet::~IndexedFaceSet() { - if(NULL != _Vertices) - { - delete [] _Vertices; - _Vertices = NULL; - } - - if(NULL != _Normals) - { - delete [] _Normals; - _Normals = NULL; - } - - if(NULL != _FrsMaterials) - { - for(unsigned i=0; i<_MSize; ++i) - delete _FrsMaterials[i]; - delete [] _FrsMaterials; - _FrsMaterials = NULL; - } - - if(NULL != _TexCoords) - { - delete [] _TexCoords; - _TexCoords = NULL; - } - - if(NULL != _NumVertexPerFace) - { - delete [] _NumVertexPerFace; - _NumVertexPerFace = NULL; - } - - if(NULL != _FaceStyle) - { - delete [] _FaceStyle; - _FaceStyle = NULL; - } - - if(NULL != _FaceEdgeMarks) - { - delete [] _FaceEdgeMarks; - _FaceEdgeMarks = NULL; - } - - if(NULL != _VIndices) - { - delete [] _VIndices; - _VIndices = NULL; - } - - if(NULL != _NIndices) - { - delete [] _NIndices; - _NIndices = NULL; - } - - if(NULL != _MIndices) - { - delete [] _MIndices; - _MIndices = NULL; - } - if(NULL != _TIndices) - { - delete [] _TIndices; - _TIndices = NULL; - } - // should find a way to deallocates the displayList - // glDeleteLists(GLuint list, GLSizei range) - _displayList = 0; + if (NULL != _Vertices) { + delete[] _Vertices; + _Vertices = NULL; + } + + if (NULL != _Normals) + { + delete[] _Normals; + _Normals = NULL; + } + + if (NULL != _FrsMaterials) { + for (unsigned int i = 0; i < _MSize; ++i) + delete _FrsMaterials[i]; + delete[] _FrsMaterials; + _FrsMaterials = NULL; + } + + if (NULL != _TexCoords) { + delete[] _TexCoords; + _TexCoords = NULL; + } + + if (NULL != _NumVertexPerFace) { + delete[] _NumVertexPerFace; + _NumVertexPerFace = NULL; + } + + if (NULL != _FaceStyle) { + delete[] _FaceStyle; + _FaceStyle = NULL; + } + + if (NULL != _FaceEdgeMarks) { + delete[] _FaceEdgeMarks; + _FaceEdgeMarks = NULL; + } + + if (NULL != _VIndices) { + delete[] _VIndices; + _VIndices = NULL; + } + + if (NULL != _NIndices) { + delete[] _NIndices; + _NIndices = NULL; + } + + if (NULL != _MIndices) { + delete[] _MIndices; + _MIndices = NULL; + } + if (NULL != _TIndices) { + delete[] _TIndices; + _TIndices = NULL; + } + + // should find a way to deallocates the displayList + // glDeleteLists(GLuint list, GLSizei range) + _displayList = 0; } -void IndexedFaceSet::accept(SceneVisitor& v) { - Rep::accept(v); - v.visitIndexedFaceSet(*this); +void IndexedFaceSet::accept(SceneVisitor& v) +{ + Rep::accept(v); + v.visitIndexedFaceSet(*this); } void IndexedFaceSet::ComputeBBox() { - real XMax = _Vertices[0]; - real YMax = _Vertices[1]; - real ZMax = _Vertices[2]; - - real XMin = _Vertices[0]; - real YMin = _Vertices[1]; - real ZMin = _Vertices[2]; - - // parse all the coordinates to find - // the Xmax, YMax, ZMax - real *v = _Vertices; - - for(unsigned i=0; i<_VSize/3; i++) - { - // X - if(*v > XMax) - XMax = *v; - if(*v < XMin) - XMin = *v; - v++; - - if(*v > YMax) - YMax = *v; - if(*v < YMin) - YMin = *v; - v++; - - if(*v > ZMax) - ZMax = *v; - if(*v < ZMin) - ZMin = *v; - v++; - } - - setBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); + real XMax = _Vertices[0]; + real YMax = _Vertices[1]; + real ZMax = _Vertices[2]; + + real XMin = _Vertices[0]; + real YMin = _Vertices[1]; + real ZMin = _Vertices[2]; + + // parse all the coordinates to find the Xmax, YMax, ZMax + real *v = _Vertices; + + for (unsigned int i = 0; i < (_VSize / 3); ++i) { + if (*v > XMax) + XMax = *v; + if (*v < XMin) + XMin = *v; + ++v; + + if (*v > YMax) + YMax = *v; + if (*v < YMin) + YMin = *v; + ++v; + + if (*v > ZMax) + ZMax = *v; + if (*v < ZMin) + ZMin = *v; + ++v; + } + + setBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); } diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h index b578dc1257e..6ec769f4caf 100644 --- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h +++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h @@ -1,143 +1,145 @@ -// -// Filename : IndexedFaceSet.h -// Author(s) : Stephane Grabli -// Purpose : A Set of indexed faces to represent a surfacic object -// Date of creation : 22/01/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef INDEXEDFACESET_H -# define INDEXEDFACESET_H - -# include <stdio.h> -# include <memory.h> - -//! inherits from class Rep -# include "Rep.h" - -# include "../system/FreestyleConfig.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_INDEXED_FACE_SET_H__ +#define __FREESTYLE_INDEXED_FACE_SET_H__ + +/** \file blender/freestyle/intern/scene_graph/IndexedFaceSet.h + * \ingroup freestyle + * \brief A Set of indexed faces to represent a surfacic object + * \author Stephane Grabli + * \date 22/01/2002 + */ + +#include <memory.h> +#include <stdio.h> + +//! inherits from class Rep +#include "Rep.h" + +#include "../system/FreestyleConfig.h" class LIB_SCENE_GRAPH_EXPORT IndexedFaceSet : public Rep - { +{ public: + /*! Triangles description style:*/ + enum TRIANGLES_STYLE { + TRIANGLE_STRIP, + TRIANGLE_FAN, + TRIANGLES, + }; - /*! Triangles description style:*/ - enum TRIANGLES_STYLE{TRIANGLE_STRIP, TRIANGLE_FAN, TRIANGLES}; - - /*! User-specified face and edge marks for feature edge detection */ - typedef unsigned char FaceEdgeMark; - static const FaceEdgeMark FACE_MARK = 1; - static const FaceEdgeMark EDGE_MARK_V1V2 = 2; - static const FaceEdgeMark EDGE_MARK_V2V3 = 4; - static const FaceEdgeMark EDGE_MARK_V3V1 = 8; - - /*! Builds an empty indexed face set - */ - IndexedFaceSet(); - /*! Builds an indexed face set - iVertices - The array of object vertices 3D coordinates (for all faces). - If iCopy != 0, the array is copied; you must desallocate iVertices. Else you must not. - iVSize - The size of iVertices (must be a multiple of 3) - iNormals - The array of object normals 3D coordinates. - If iCopy != 0, the array is copied; you must desallocate iNormals. Else you must not. - iNSize - The size of iNormals - iMaterials - The array of materials - iMSize - The size of iMaterials - iTexCoords - The array of texture coordinates. - iTSize - The size of iTexCoords (must be multiple of 2) - iNumFaces - The number of faces - iNumVertexPerFace - Array containing the number of vertices per face. - iFaceStyle - Array containing the description style of each faces. - The style belongs to: - - TRIANGLE_STRIP: the face indices describe a triangle strip - - TRIANGLE_FAN : the face indices describe a triangle fan - - TRIANGLES : the face indices describe single triangles - If iCopy != 0, the array is copied; you must desallocate iFaceStyle. Else you must not. - iVIndices, - Array of vertices indices. - The integers contained in this array must be multiple of 3. - If iCopy != 0, the array is copied; you must desallocate iVIndices. Else you must not. - iVISize - The size of iVIndices. - iNIndices - Array of normals indices. - The integers contained in this array must be multiple of 3. - If iCopy != 0, the array is copied; you must desallocate iNIndices. Else you must not. - iNISize - The size of iNIndices - iMIndices - The Material indices (per vertex) - iMISize - The size of iMIndices - iTIndices - The Texture coordinates indices (per vertex). The integers contained in this array must be multiple of 2. - iTISize - The size of iMIndices - iCopy - 0 : the arrays are not copied. The pointers passed as arguments are used. - IndexedFaceSet takes these arrays desallocation in charge. - 1 : the arrays are copied. The caller is in charge of the arrays, passed - as arguments desallocation. - */ - IndexedFaceSet( real *iVertices, unsigned iVSize, - real *iNormals, unsigned iNSize, - FrsMaterial **iMaterials, unsigned iMSize, - real *iTexCoords, unsigned iTSize, - unsigned iNumFaces, unsigned *iNumVertexPerFace, TRIANGLES_STYLE *iFaceStyle, - FaceEdgeMark *iFaceEdgeMarks, - unsigned *iVIndices, unsigned iVISize, - unsigned *iNIndices, unsigned iNISize, - unsigned *iMIndices, unsigned iMISize, - unsigned *iTIndices, unsigned iTISize, - unsigned iCopy = 1 - ); - - /*! Builds an indexed face set from an other indexed face set */ - IndexedFaceSet(const IndexedFaceSet& iBrother); - - void swap(IndexedFaceSet& ioOther){ + /*! User-specified face and edge marks for feature edge detection */ + /* XXX Why in hel not use an enum here too? */ + typedef unsigned char FaceEdgeMark; + static const FaceEdgeMark FACE_MARK = 1 << 0; + static const FaceEdgeMark EDGE_MARK_V1V2 = 1 << 1; + static const FaceEdgeMark EDGE_MARK_V2V3 = 1 << 2; + static const FaceEdgeMark EDGE_MARK_V3V1 = 1 << 3; + + /*! Builds an empty indexed face set */ + IndexedFaceSet(); + + /*! Builds an indexed face set + * iVertices + * The array of object vertices 3D coordinates (for all faces). + * If iCopy != 0, the array is copied; you must desallocate iVertices. Else you must not. + * iVSize + * The size of iVertices (must be a multiple of 3) + * iNormals + * The array of object normals 3D coordinates. + * If iCopy != 0, the array is copied; you must desallocate iNormals. Else you must not. + * iNSize + * The size of iNormals + * iMaterials + * The array of materials + * iMSize + * The size of iMaterials + * iTexCoords + * The array of texture coordinates. + * iTSize + * The size of iTexCoords (must be multiple of 2) + * iNumFaces + * The number of faces + * iNumVertexPerFace + * Array containing the number of vertices per face. + * iFaceStyle + * Array containing the description style of each faces. + * The style belongs to: + * - TRIANGLE_STRIP: the face indices describe a triangle strip + * - TRIANGLE_FAN : the face indices describe a triangle fan + * - TRIANGLES : the face indices describe single triangles + * If iCopy != 0, the array is copied; you must desallocate iFaceStyle. Else you must not. + * iVIndices, + * Array of vertices indices. + * The integers contained in this array must be multiple of 3. + * If iCopy != 0, the array is copied; you must desallocate iVIndices. Else you must not. + * iVISize + * The size of iVIndices. + * iNIndices + * Array of normals indices. + * The integers contained in this array must be multiple of 3. + * If iCopy != 0, the array is copied; you must desallocate iNIndices. Else you must not. + * iNISize + * The size of iNIndices + * iMIndices + * The Material indices (per vertex) + * iMISize + * The size of iMIndices + * iTIndices + * The Texture coordinates indices (per vertex). The integers contained in this array must be multiple of 2. + * iTISize + * The size of iMIndices + * iCopy + * 0 : the arrays are not copied. The pointers passed as arguments are used. IndexedFaceSet takes these + * arrays desallocation in charge. + * 1 : the arrays are copied. The caller is in charge of the arrays, passed as arguments desallocation. + */ + IndexedFaceSet(real *iVertices, unsigned iVSize, real *iNormals, unsigned iNSize, FrsMaterial **iMaterials, + unsigned iMSize, real *iTexCoords, unsigned iTSize, unsigned iNumFaces, unsigned *iNumVertexPerFace, + TRIANGLES_STYLE *iFaceStyle, FaceEdgeMark *iFaceEdgeMarks, unsigned *iVIndices, unsigned iVISize, + unsigned *iNIndices, unsigned iNISize, unsigned *iMIndices, unsigned iMISize, unsigned *iTIndices, + unsigned iTISize, unsigned iCopy = 1); + + /*! Builds an indexed face set from an other indexed face set */ + IndexedFaceSet(const IndexedFaceSet& iBrother); + + void swap(IndexedFaceSet& ioOther) + { std::swap(_Vertices, ioOther._Vertices); std::swap(_Normals, ioOther._Normals); std::swap(_FrsMaterials, ioOther._FrsMaterials); - std::swap(_TexCoords, ioOther._TexCoords); + std::swap(_TexCoords, ioOther._TexCoords); std::swap(_FaceEdgeMarks, ioOther._FaceEdgeMarks); std::swap(_VSize, ioOther._VSize); std::swap(_NSize, ioOther._NSize); std::swap(_MSize, ioOther._MSize); - std::swap(_TSize, ioOther._TSize); + std::swap(_TSize, ioOther._TSize); std::swap(_NumFaces, ioOther._NumFaces); std::swap(_NumVertexPerFace, ioOther._NumVertexPerFace); @@ -146,88 +148,175 @@ public: std::swap(_VIndices, ioOther._VIndices); std::swap(_NIndices, ioOther._NIndices); std::swap(_MIndices, ioOther._MIndices); // Material Indices - std::swap(_TIndices, ioOther._TIndices); + std::swap(_TIndices, ioOther._TIndices); std::swap(_VISize, ioOther._VISize); std::swap(_NISize, ioOther._NISize); std::swap(_MISize, ioOther._MISize); - std::swap(_TISize, ioOther._TISize); + std::swap(_TISize, ioOther._TISize); std::swap(_displayList, ioOther._displayList); Rep::swap(ioOther); } - IndexedFaceSet& operator=(const IndexedFaceSet& iBrother){ + IndexedFaceSet& operator=(const IndexedFaceSet& iBrother) + { IndexedFaceSet tmp(iBrother); swap(tmp); return *this; } - /*! Desctructor - desallocates all the ressources */ - virtual ~IndexedFaceSet(); - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Compute the Bounding Box */ - virtual void ComputeBBox(); - - /*! modifiers */ - inline void setDisplayList(unsigned int index) {_displayList = index;} - - /*! Accessors */ - virtual const real * vertices() const {return _Vertices;} - virtual const real * normals() const {return _Normals;} - virtual const FrsMaterial*const* frs_materials() const {return _FrsMaterials;} - virtual const real* texCoords() const {return _TexCoords;} - virtual const unsigned vsize() const {return _VSize;} - virtual const unsigned nsize() const {return _NSize;} - virtual const unsigned msize() const {return _MSize;} - virtual const unsigned tsize() const {return _TSize;} - virtual const unsigned numFaces() const {return _NumFaces;} - virtual const unsigned * numVertexPerFaces() const {return _NumVertexPerFace;} - virtual const TRIANGLES_STYLE * trianglesStyle() const {return _FaceStyle;} - virtual const unsigned char * faceEdgeMarks() const {return _FaceEdgeMarks;} - virtual const unsigned* vindices() const {return _VIndices;} - virtual const unsigned* nindices() const {return _NIndices;} - virtual const unsigned* mindices() const {return _MIndices;} - virtual const unsigned* tindices() const {return _TIndices;} - virtual const unsigned visize() const {return _VISize;} - virtual const unsigned nisize() const {return _NISize;} - virtual const unsigned misize() const {return _MISize;} - virtual const unsigned tisize() const {return _TISize;} - inline unsigned int displayList() const {return _displayList;} + /*! Desctructor + * desallocates all the ressources + */ + virtual ~IndexedFaceSet(); + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); + + /*! Compute the Bounding Box */ + virtual void ComputeBBox(); + + /*! modifiers */ + inline void setDisplayList(unsigned int index) + { + _displayList = index; + } + + /*! Accessors */ + virtual const real * vertices() const + { + return _Vertices; + } + + virtual const real * normals() const + { + return _Normals; + } + + virtual const FrsMaterial*const* frs_materials() const + { + return _FrsMaterials; + } + + virtual const real* texCoords() const + { + return _TexCoords; + } + + virtual const unsigned vsize() const + { + return _VSize; + } + + virtual const unsigned nsize() const + { + return _NSize; + } + + virtual const unsigned msize() const + { + return _MSize; + } + + virtual const unsigned tsize() const + { + return _TSize; + } + + virtual const unsigned numFaces() const + { + return _NumFaces; + } + + virtual const unsigned * numVertexPerFaces() const + { + return _NumVertexPerFace; + } + + virtual const TRIANGLES_STYLE * trianglesStyle() const + { + return _FaceStyle; + } + + virtual const unsigned char * faceEdgeMarks() const + { + return _FaceEdgeMarks; + } + + virtual const unsigned* vindices() const + { + return _VIndices; + } + + virtual const unsigned* nindices() const + { + return _NIndices; + } + + virtual const unsigned* mindices() const + { + return _MIndices; + } + + virtual const unsigned* tindices() const + { + return _TIndices; + } + + virtual const unsigned visize() const + { + return _VISize; + } + + virtual const unsigned nisize() const + { + return _NISize; + } + + virtual const unsigned misize() const + { + return _MISize; + } + + virtual const unsigned tisize() const + { + return _TISize; + } + + inline unsigned int displayList() const + { + return _displayList; + } protected: - real *_Vertices; - real *_Normals; - FrsMaterial** _FrsMaterials; - real *_TexCoords; - - unsigned _VSize; - unsigned _NSize; - unsigned _MSize; - unsigned _TSize; - - unsigned _NumFaces; - unsigned *_NumVertexPerFace; - TRIANGLES_STYLE *_FaceStyle; - FaceEdgeMark *_FaceEdgeMarks; - - unsigned *_VIndices; - unsigned *_NIndices; - unsigned *_MIndices; // Material Indices - unsigned *_TIndices; // Texture coordinates Indices - - unsigned _VISize; - unsigned _NISize; - unsigned _MISize; - unsigned _TISize; - - unsigned int _displayList; + real *_Vertices; + real *_Normals; + FrsMaterial **_FrsMaterials; + real *_TexCoords; + + unsigned _VSize; + unsigned _NSize; + unsigned _MSize; + unsigned _TSize; + + unsigned _NumFaces; + unsigned *_NumVertexPerFace; + TRIANGLES_STYLE *_FaceStyle; + FaceEdgeMark *_FaceEdgeMarks; + + unsigned *_VIndices; + unsigned *_NIndices; + unsigned *_MIndices; // Material Indices + unsigned *_TIndices; // Texture coordinates Indices + + unsigned _VISize; + unsigned _NISize; + unsigned _MISize; + unsigned _TISize; + unsigned int _displayList; }; -#endif // INDEXEDFACESET_H +#endif // __FREESTYLE_INDEXED_FACE_SET_H__ diff --git a/source/blender/freestyle/intern/scene_graph/LineRep.cpp b/source/blender/freestyle/intern/scene_graph/LineRep.cpp index 504db06acf4..bf442bccbc1 100644 --- a/source/blender/freestyle/intern/scene_graph/LineRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/LineRep.cpp @@ -1,58 +1,71 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/LineRep.cpp + * \ingroup freestyle + * \brief Class to define the representation of 3D Line. + * \author Stephane Grabli + * \date 26/03/2002 + */ #include "LineRep.h" void LineRep::ComputeBBox() { - real XMax = _vertices.front()[0]; - real YMax = _vertices.front()[1]; - real ZMax = _vertices.front()[2]; - - real XMin = _vertices.front()[0]; - real YMin = _vertices.front()[1]; - real ZMin = _vertices.front()[2]; - - // parse all the coordinates to find - // the XMax, YMax, ZMax - vector<Vec3r>::iterator v; - for(v=_vertices.begin(); v!=_vertices.end(); v++) { - // X - if((*v)[0] > XMax) - XMax = (*v)[0]; - if((*v)[0] < XMin) - XMin = (*v)[0]; - - // Y - if((*v)[1] > YMax) - YMax = (*v)[1]; - if((*v)[1] < YMin) - YMin = (*v)[1]; - - // Z - if((*v)[2] > ZMax) - ZMax = (*v)[2]; - if((*v)[2] < ZMin) - ZMin = (*v)[2]; - } - - setBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); + real XMax = _vertices.front()[0]; + real YMax = _vertices.front()[1]; + real ZMax = _vertices.front()[2]; + + real XMin = _vertices.front()[0]; + real YMin = _vertices.front()[1]; + real ZMin = _vertices.front()[2]; + + // parse all the coordinates to find + // the XMax, YMax, ZMax + vector<Vec3r>::iterator v; + for (v = _vertices.begin(); v != _vertices.end(); ++v) { + // X + if ((*v)[0] > XMax) + XMax = (*v)[0]; + if ((*v)[0] < XMin) + XMin = (*v)[0]; + + // Y + if ((*v)[1] > YMax) + YMax = (*v)[1]; + if ((*v)[1] < YMin) + YMin = (*v)[1]; + + // Z + if ((*v)[2] > ZMax) + ZMax = (*v)[2]; + if ((*v)[2] < ZMin) + ZMin = (*v)[2]; + } + + setBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); } diff --git a/source/blender/freestyle/intern/scene_graph/LineRep.h b/source/blender/freestyle/intern/scene_graph/LineRep.h index 232557af857..3d93db4835d 100644 --- a/source/blender/freestyle/intern/scene_graph/LineRep.h +++ b/source/blender/freestyle/intern/scene_graph/LineRep.h @@ -1,39 +1,46 @@ -// -// Filename : LineRep.h -// Author(s) : Stephane Grabli -// Purpose : Class to define the representation of 3D Line. -// Date of creation : 26/03/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef LINEREP_H -# define LINEREP_H - -# include <vector> -# include <list> -# include "Rep.h" -# include "../system/FreestyleConfig.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_LINE_REP_H__ +#define __FREESTYLE_LINE_REP_H__ + +/** \file blender/freestyle/intern/scene_graph/LineRep.h + * \ingroup freestyle + * \brief Class to define the representation of 3D Line. + * \author Stephane Grabli + * \date 26/03/2002 + */ + +#include <list> +#include <vector> + +#include "Rep.h" + +#include "../system/FreestyleConfig.h" using namespace std; @@ -41,90 +48,111 @@ using namespace std; class LIB_SCENE_GRAPH_EXPORT LineRep : public Rep { public: - - /*! Line description style */ - enum LINES_STYLE{LINES, LINE_STRIP, LINE_LOOP}; - inline LineRep() : Rep() {_width = 0.f;} - - /*! Builds a single line from 2 vertices - * v1 - * first vertex - * v2 - * second vertex - */ - inline LineRep(const Vec3r& v1, const Vec3r& v2) - : Rep() - { - setStyle(LINES); - AddVertex(v1); - AddVertex(v2); - _width = 0.f; - } - - /*! Builds a line rep from a vertex chain */ - inline LineRep(const vector<Vec3r>& vertices) - : Rep() - { - _vertices = vertices; - setStyle(LINE_STRIP); - _width = 0.f; - } - - /*! Builds a line rep from a vertex chain */ - inline LineRep(const list<Vec3r>& vertices) - : Rep() - { - for(list<Vec3r>::const_iterator v=vertices.begin(), end=vertices.end(); - v!=end; - v++) - { - _vertices.push_back(*v); - } - setStyle(LINE_STRIP); - _width = 0.f; - } - - virtual ~LineRep() - { - _vertices.clear(); - } - - /*! accessors */ - inline const LINES_STYLE style() const {return _Style;} - inline const vector<Vec3r>& vertices() const {return _vertices;} - inline float width() const {return _width;} - - /*! modifiers */ - inline void setStyle(const LINES_STYLE iStyle) {_Style = iStyle;} - inline void AddVertex(const Vec3r& iVertex) {_vertices.push_back(iVertex);} - inline void setVertices(const vector<Vec3r>& iVertices) - { - if(0 != _vertices.size()) - { - _vertices.clear(); - } - for(vector<Vec3r>::const_iterator v=iVertices.begin(), end=iVertices.end(); - v!=end; - v++) - { - _vertices.push_back(*v); - } - } - inline void setWidth(float iWidth) {_width=iWidth;} - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v) { - Rep::accept(v); - v.visitLineRep(*this); - } - - /*! Computes the line bounding box.*/ - virtual void ComputeBBox(); + /*! Line description style */ + enum LINES_STYLE { + LINES, + LINE_STRIP, + LINE_LOOP, + }; + + inline LineRep() : Rep() + { + _width = 0.0f; + } + + /*! Builds a single line from 2 vertices + * v1 + * first vertex + * v2 + * second vertex + */ + inline LineRep(const Vec3r& v1, const Vec3r& v2) : Rep() + { + setStyle(LINES); + AddVertex(v1); + AddVertex(v2); + _width = 0.0f; + } + + /*! Builds a line rep from a vertex chain */ + inline LineRep(const vector<Vec3r>& vertices) : Rep() + { + _vertices = vertices; + setStyle(LINE_STRIP); + _width = 0.0f; + } + + /*! Builds a line rep from a vertex chain */ + inline LineRep(const list<Vec3r>& vertices) : Rep() + { + for (list<Vec3r>::const_iterator v = vertices.begin(), end = vertices.end(); v != end; ++v) { + _vertices.push_back(*v); + } + setStyle(LINE_STRIP); + _width = 0.0f; + } + + virtual ~LineRep() + { + _vertices.clear(); + } + + /*! accessors */ + inline const LINES_STYLE style() const + { + return _Style; + } + + inline const vector<Vec3r>& vertices() const + { + return _vertices; + } + + inline float width() const + { + return _width; + } + + /*! modifiers */ + inline void setStyle(const LINES_STYLE iStyle) + { + _Style = iStyle; + } + + inline void AddVertex(const Vec3r& iVertex) + { + _vertices.push_back(iVertex); + } + + inline void setVertices(const vector<Vec3r>& iVertices) + { + if (0 != _vertices.size()) { + _vertices.clear(); + } + for (vector<Vec3r>::const_iterator v = iVertices.begin(), end = iVertices.end(); v != end; ++v) { + _vertices.push_back(*v); + } + } + + inline void setWidth(float iWidth) + { + _width = iWidth; + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v) + { + Rep::accept(v); + v.visitLineRep(*this); + } + + /*! Computes the line bounding box.*/ + virtual void ComputeBBox(); private: - LINES_STYLE _Style; - vector<Vec3r> _vertices; - float _width; + LINES_STYLE _Style; + vector<Vec3r> _vertices; + float _width; }; -#endif // LINEREP_H +#endif // __FREESTYLE_LINE_REP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/Node.h b/source/blender/freestyle/intern/scene_graph/Node.h index 41afaa353be..626a0913233 100644 --- a/source/blender/freestyle/intern/scene_graph/Node.h +++ b/source/blender/freestyle/intern/scene_graph/Node.h @@ -1,42 +1,48 @@ -// -// Filename : Node.h -// Author(s) : Stephane Grabli -// Purpose : Abstract class for scene graph nodes. Inherits from -// BaseObject which defines the addRef release mechanism. -// Date of creation : 24/01/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef NODE_H -# define NODE_H - -# include "../system/FreestyleConfig.h" -# include "../system/BaseObject.h" -# include "SceneVisitor.h" -# include "../geometry/BBox.h" -# include "../geometry/Geom.h" -# include "../system/Precision.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_H__ +#define __FREESTYLE_NODE_H__ + +/** \file blender/freestyle/intern/scene_graph/Node.h + * \ingroup freestyle + * \brief Abstract class for scene graph nodes. Inherits from BaseObject which defines the addRef release mechanism. + * \author Stephane Grabli + * \date 24/01/2002 + */ + +#include "SceneVisitor.h" + +#include "../system/BaseObject.h" +#include "../system/FreestyleConfig.h" +#include "../system/Precision.h" + +#include "../geometry/BBox.h" +#include "../geometry/Geom.h" using namespace std; using namespace Geometry; @@ -44,54 +50,66 @@ using namespace Geometry; class LIB_SCENE_GRAPH_EXPORT Node : public BaseObject { public: + inline Node() : BaseObject() {} + + inline Node(const Node& iBrother) : BaseObject() + { + _BBox = iBrother.bbox(); + } + + virtual ~Node(){} + + /*! Accept the corresponding visitor + * Each inherited node must overload this method + */ + virtual void accept(SceneVisitor& v) + { + v.visitNode(*this); + } + + /*! bounding box management */ + /*! Returns the node bounding box + * If no bounding box exists, an empty bbox is returned + */ + virtual const BBox<Vec3r>& bbox() const + { + return _BBox; + } + + /*! Sets the Node bounding box */ + virtual void setBBox(const BBox<Vec3r>& iBox) + { + _BBox = iBox; + } + + /*! Makes the union of _BBox and iBox */ + virtual void AddBBox(const BBox<Vec3r>& iBox) + { + if(iBox.empty()) + return; + + if(_BBox.empty()) + _BBox = iBox; + else + _BBox += iBox; + } + + /*! Updates the BBox */ + virtual const BBox<Vec3r>& UpdateBBox() + { + return _BBox; + } + + /*! Clears the bounding box */ + virtual void clearBBox() + { + _BBox.clear(); + } - inline Node() : BaseObject() {} - inline Node(const Node& iBrother) : BaseObject() - { - _BBox = iBrother.bbox(); - } - virtual ~Node(){} - - /*! Accept the corresponding visitor - * Each inherited node - * must overload this method - */ - virtual void accept(SceneVisitor& v) { - v.visitNode(*this); - } - - /*! bounding box management */ - /*! Returns the node bounding box - * If no bounding box exists, an empty bbox - * is returned - */ - virtual const BBox<Vec3r>& bbox() const {return _BBox;} - - /*! Sets the Node bounding box */ - virtual void setBBox(const BBox<Vec3r>& iBox) {_BBox = iBox;} - - /*! Makes the union of _BBox and iBox */ - virtual void AddBBox(const BBox<Vec3r>& iBox) - { - if(iBox.empty()) - return; - - if(_BBox.empty()) - _BBox = iBox; - else - _BBox += iBox; - } - - /*! Updates the BBox */ - virtual const BBox<Vec3r>& UpdateBBox() {return _BBox;} - - /*! Clears the bounding box */ - virtual void clearBBox() { _BBox.clear(); } - protected: - + private: - BBox<Vec3r> _BBox; + BBox<Vec3r> _BBox; }; -#endif // NODE_H +#endif // __FREESTYLE_NODE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp b/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp index f299c44de40..d8b01bf3f64 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp @@ -1,120 +1,143 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/freestyle/intern/scene_graph/NodeCamera.cpp + * \ingroup freestyle + * \brief Class to represent a light node + * \author Stephane Grabli + * \date 25/01/2002 + */ + +#include <math.h> #include <string.h> // for memcpy + #include "NodeCamera.h" -#include <math.h> -static void loadIdentity(double * matrix){ - int i; - - // Build Identity matrix - for(i=0;i<16;++i){ - double value ; - if((i % 5) == 0) - value = 1.0; - else - value = 0; - matrix[i] = value; - } +static void loadIdentity(double * matrix) +{ + int i; + + // Build Identity matrix + for (i = 0; i < 16; ++i) { + double value ; + if ((i % 5) == 0) + value = 1.0; + else + value = 0; + matrix[i] = value; + } } -NodeCamera::NodeCamera(CameraType camera_type) -:camera_type_(camera_type){ - loadIdentity(modelview_matrix_); - loadIdentity(projection_matrix_); +NodeCamera::NodeCamera(CameraType camera_type) : camera_type_(camera_type) +{ + loadIdentity(modelview_matrix_); + loadIdentity(projection_matrix_); } -NodeCamera::NodeCamera(const NodeCamera& iBrother) -:camera_type_(iBrother.camera_type_){ - memcpy(modelview_matrix_, iBrother.modelview_matrix_, 16*sizeof(double)); - memcpy(projection_matrix_, iBrother.projection_matrix_, 16*sizeof(double)); +NodeCamera::NodeCamera(const NodeCamera& iBrother) : camera_type_(iBrother.camera_type_) +{ + memcpy(modelview_matrix_, iBrother.modelview_matrix_, 16 * sizeof(double)); + memcpy(projection_matrix_, iBrother.projection_matrix_, 16 * sizeof(double)); } -void NodeCamera::accept(SceneVisitor& v){ - v.visitNodeCamera(*this) ; +void NodeCamera::accept(SceneVisitor& v) +{ + v.visitNodeCamera(*this); } -void NodeCamera::setModelViewMatrix(double modelview_matrix[16]){ - memcpy(modelview_matrix_, modelview_matrix,16*sizeof(double)); +void NodeCamera::setModelViewMatrix(double modelview_matrix[16]) +{ + memcpy(modelview_matrix_, modelview_matrix, 16 * sizeof(double)); } -void NodeCamera::setProjectionMatrix(double projection_matrix[16]){ - memcpy(projection_matrix_, projection_matrix,16*sizeof(double)); +void NodeCamera::setProjectionMatrix(double projection_matrix[16]) +{ + memcpy(projection_matrix_, projection_matrix, 16 * sizeof(double)); } NodeOrthographicCamera::NodeOrthographicCamera() -:NodeCamera(NodeCamera::ORTHOGRAPHIC), -left_(0),right_(0),bottom_(0),top_(0),zNear_(0),zFar_(0){ - loadIdentity(projection_matrix_); - loadIdentity(modelview_matrix_); +: NodeCamera(NodeCamera::ORTHOGRAPHIC), left_(0), right_(0), bottom_(0), top_(0), zNear_(0), zFar_(0) +{ + loadIdentity(projection_matrix_); + loadIdentity(modelview_matrix_); } -NodeOrthographicCamera::NodeOrthographicCamera(double left - , double right - , double bottom - , double top - , double zNear - , double zFar - ) -:NodeCamera(NodeCamera::ORTHOGRAPHIC), -left_(left), -right_(right), -bottom_(bottom), -top_(top), -zNear_(zNear), -zFar_(zFar){ - - loadIdentity(projection_matrix_); - - projection_matrix_[0] = 2.0/(right-left); - projection_matrix_[3] = -(right + left) / (right - left) ; - projection_matrix_[5] = 2.0/(top-bottom); - projection_matrix_[7] = -(top + bottom) / (top - bottom) ; - projection_matrix_[10] = -2.0/(zFar-zNear); - projection_matrix_[11] = -(zFar + zNear) / (zFar - zNear); - +NodeOrthographicCamera::NodeOrthographicCamera(double left, double right, double bottom, double top, + double zNear, double zFar) +: NodeCamera(NodeCamera::ORTHOGRAPHIC), left_(left), right_(right), bottom_(bottom), top_(top), + zNear_(zNear), zFar_(zFar) +{ + loadIdentity(projection_matrix_); + + projection_matrix_[0] = 2.0 / (right - left); + projection_matrix_[3] = -(right + left) / (right - left) ; + projection_matrix_[5] = 2.0 / (top - bottom); + projection_matrix_[7] = -(top + bottom) / (top - bottom) ; + projection_matrix_[10] = -2.0 / (zFar - zNear); + projection_matrix_[11] = -(zFar + zNear) / (zFar - zNear); } NodeOrthographicCamera::NodeOrthographicCamera(const NodeOrthographicCamera& iBrother) -:NodeCamera(iBrother),left_(iBrother.left_),right_(iBrother.right_),bottom_(iBrother.bottom_),top_(iBrother.top_),zNear_(iBrother.zNear_),zFar_(iBrother.zFar_){ +: NodeCamera(iBrother), left_(iBrother.left_), right_(iBrother.right_), bottom_(iBrother.bottom_), top_(iBrother.top_), + zNear_(iBrother.zNear_), zFar_(iBrother.zFar_) +{ } -NodePerspectiveCamera::NodePerspectiveCamera() -:NodeCamera(NodeCamera::PERSPECTIVE){ +NodePerspectiveCamera::NodePerspectiveCamera() : NodeCamera(NodeCamera::PERSPECTIVE) +{ } -NodePerspectiveCamera::NodePerspectiveCamera(double fovy - , double aspect - , double zNear - , double zFar) -:NodeCamera(NodeCamera::PERSPECTIVE){ - loadIdentity(projection_matrix_); - - double f = cos(fovy/2.0)/sin(fovy/2.0); // cotangent +NodePerspectiveCamera::NodePerspectiveCamera(double fovy, double aspect, double zNear, double zFar) +: NodeCamera(NodeCamera::PERSPECTIVE) +{ + loadIdentity(projection_matrix_); - projection_matrix_[0] = f/aspect; - projection_matrix_[5] = f; - projection_matrix_[10] = (zNear+zFar)/(zNear-zFar); - projection_matrix_[11] = (2.0*zNear*zFar)/(zNear-zFar); - projection_matrix_[14] = -1.0; - projection_matrix_[15] = 0; + double f = cos(fovy / 2.0) / sin(fovy / 2.0); // cotangent + projection_matrix_[0] = f / aspect; + projection_matrix_[5] = f; + projection_matrix_[10] = (zNear + zFar) / (zNear - zFar); + projection_matrix_[11] = (2.0 * zNear * zFar) / (zNear - zFar); + projection_matrix_[14] = -1.0; + projection_matrix_[15] = 0; } -NodePerspectiveCamera::NodePerspectiveCamera(double left, - double right, - double bottom, - double top, - double zNear, - double zFar) -:NodeCamera(NodeCamera::PERSPECTIVE){ - loadIdentity(projection_matrix_); - - projection_matrix_[0] = (2.0*zNear)/(right-left); - projection_matrix_[2] = (right+left)/(right-left); - projection_matrix_[5] = (2.0*zNear)/(top-bottom); - projection_matrix_[6] = (top+bottom)/(top-bottom); - projection_matrix_[10] = - (zFar+zNear)/(zFar-zNear); - projection_matrix_[11] = - (2.0*zFar*zNear)/(zFar-zNear); - projection_matrix_[14] = -1.0; - projection_matrix_[15] = 0; +NodePerspectiveCamera::NodePerspectiveCamera(double left, double right, double bottom, double top, + double zNear, double zFar) +: NodeCamera(NodeCamera::PERSPECTIVE) +{ + loadIdentity(projection_matrix_); + + projection_matrix_[0] = (2.0 * zNear) / (right - left); + projection_matrix_[2] = (right + left) / (right - left); + projection_matrix_[5] = (2.0 * zNear) / (top - bottom); + projection_matrix_[6] = (top + bottom) / (top - bottom); + projection_matrix_[10] = -(zFar + zNear) / (zFar - zNear); + projection_matrix_[11] = -(2.0 * zFar * zNear) / (zFar - zNear); + projection_matrix_[14] = -1.0; + projection_matrix_[15] = 0; } - diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.h b/source/blender/freestyle/intern/scene_graph/NodeCamera.h index cdd6fa83048..f7141a72a51 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeCamera.h +++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.h @@ -1,192 +1,216 @@ -// -// Filename : NodeCamera.h -// Author(s) : Stephane Grabli -// Purpose : Class to represent a light node -// Date of creation : 25/01/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - - -#ifndef NODE_CAMERA_H_ -#define NODE_CAMERA_H_ - -# include "../geometry/Geom.h" -# include "../system/FreestyleConfig.h" -# include "Node.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_CAMERA_H__ +#define __FREESTYLE_NODE_CAMERA_H__ + +/** \file blender/freestyle/intern/scene_graph/NodeCamera.h + * \ingroup freestyle + * \brief Class to represent a light node + * \author Stephane Grabli + * \date 25/01/2002 + */ + +#include "Node.h" + +#include "../geometry/Geom.h" + +#include "../system/FreestyleConfig.h" using namespace Geometry; class NodeOrthographicCamera; + class NodePerspectiveCamera; + class LIB_SCENE_GRAPH_EXPORT NodeCamera : public Node { public: - typedef enum {PERSPECTIVE,ORTHOGRAPHIC,GENERIC} CameraType; + typedef enum { + PERSPECTIVE, + ORTHOGRAPHIC, + GENERIC, + } CameraType; + + /*! Default matrices: Identity for both projection and modelview. */ + NodeCamera(CameraType camera_type = GENERIC); + NodeCamera(const NodeCamera& iBrother); - /*! Default matrices: Identity for both projection and modelview. */ - NodeCamera(CameraType camera_type = GENERIC); - NodeCamera(const NodeCamera& iBrother); + virtual ~NodeCamera() {} - virtual ~NodeCamera() {} + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); + /*! Matrix is copied */ + void setModelViewMatrix(double modelview_matrix[16]); - /*! Matrix is copied */ - void setModelViewMatrix(double modelview_matrix[16]); - /*! Matrix is copied */ - void setProjectionMatrix(double projection_matrix[16]); + /*! Matrix is copied */ + void setProjectionMatrix(double projection_matrix[16]); - double * modelViewMatrix() {return modelview_matrix_;} - double * projectionMatrix() {return projection_matrix_;} + double * modelViewMatrix() + { + return modelview_matrix_; + } + + double * projectionMatrix() + { + return projection_matrix_; + } protected: - // row major right handed matrix - double modelview_matrix_[16]; - // row major right handed matrix - double projection_matrix_[16]; + // row major right handed matrix + double modelview_matrix_[16]; + // row major right handed matrix + double projection_matrix_[16]; - CameraType camera_type_; + CameraType camera_type_; }; -class LIB_SCENE_GRAPH_EXPORT NodeOrthographicCamera : public NodeCamera{ +class LIB_SCENE_GRAPH_EXPORT NodeOrthographicCamera : public NodeCamera +{ public: - NodeOrthographicCamera(); - /*! Builds a parallel projection matrix a la glOrtho. - A 0 0 tx - 0 B 0 ty - 0 0 C tz - 0 0 0 1 - - where - - A = - 2 / (right - left) - B = - 2 / (top - bottom) - C = - -2 / (far - near) - tx = - -(right + left) / (right - left) - ty = - -(top + bottom) / (top - bottom) - tz = - -(zFar + zNear) / (zFar - zNear) - */ - NodeOrthographicCamera(double left - , double right - , double bottom - , double top - , double zNear - , double zFar - ); - - double left() const {return left_;} - double right() const {return right_;} - double bottom() const {return bottom_;} - double top() const {return top_;} - double zNear() const {return zNear_;} - double zFar() const {return zFar_;} - - NodeOrthographicCamera(const NodeOrthographicCamera& iBrother); + NodeOrthographicCamera(); + + /*! Builds a parallel projection matrix a la glOrtho. + * A 0 0 tx + * 0 B 0 ty + * 0 0 C tz + * 0 0 0 1 + * + * where + * A = 2 / (right - left) + * B = 2 / (top - bottom) + * C = -2 / (far - near) + * tx = -(right + left) / (right - left) + * ty = -(top + bottom) / (top - bottom) + * tz = -(zFar + zNear) / (zFar - zNear) + */ + NodeOrthographicCamera(double left, double right, double bottom, double top, double zNear, double zFar); + + double left() const + { + return left_; + } + + double right() const + { + return right_; + } + + double bottom() const + { + return bottom_; + } + + double top() const + { + return top_; + } + + double zNear() const + { + return zNear_; + } + + double zFar() const + { + return zFar_; + } + + NodeOrthographicCamera(const NodeOrthographicCamera& iBrother); private: - double left_; - double right_; - double bottom_; - double top_; - double zNear_; - double zFar_; + double left_; + double right_; + double bottom_; + double top_; + double zNear_; + double zFar_; }; -class LIB_SCENE_GRAPH_EXPORT NodePerspectiveCamera : public NodeCamera { +class LIB_SCENE_GRAPH_EXPORT NodePerspectiveCamera : public NodeCamera +{ public: - NodePerspectiveCamera(); - /*! Builds a perspective projection matrix a la gluPerspective. - Given f defined as follows: - fovy - f = cotangent(____) - 2 - The generated matrix is - - - ( f ) - | ______ | - | aspect 0 0 0 | - | | - | 0 f 0 0 | - | | - | zNear+zFar 2*zNear*zFar | - | __________ ____________ | - | 0 0 zNear-zFar zNear-zFar | - | | - ( 0 0 -1 0 ) - \param fovy - Field of View specified in radians. - */ - NodePerspectiveCamera(double fovy - , double aspect - , double zNear - , double zFar); - - /*! Builds a perspective projection matrix a la glFrustum. - ( 2*zNear ) - | __________ | - | right-left 0 A 0 | - | | - | 2*zNear | - | 0 __________ B 0 | - | top-bottom | - | | - | 0 0 C D | - | | - | 0 0 -1 0 | - ( ) - - right+left - A = __________ - right-left - - top+bottom - B = __________ - top-bottom - - zFar+zNear - C = - __________ - zFar-zNear - - 2*zFar*zNear - D = - ____________ - zFar-zNear - */ - NodePerspectiveCamera(double left, - double right, - double bottom, - double top, - double zNear, - double zFar); + NodePerspectiveCamera(); + + /*! Builds a perspective projection matrix a la gluPerspective. + * Given f defined as follows: + * fovy + * f = cotangent(____) + * 2 + * The generated matrix is + * ( f ) + * | ______ 0 0 0 | + * | aspect | + * | | + * | 0 f 0 0 | + * | | + * | zNear+zFar 2*zNear*zFar | + * | 0 0 __________ ____________ | + * | zNear-zFar zNear-zFar | + * | | + * ( 0 0 -1 0 ) + * \param fovy + * Field of View specified in radians. + */ + NodePerspectiveCamera(double fovy, double aspect, double zNear, double zFar); + + /*! Builds a perspective projection matrix a la glFrustum. + * ( 2*zNear ) + * | __________ 0 A 0 | + * | right-left | + * | | + * | 2*zNear | + * | 0 __________ B 0 | + * | top-bottom | + * | | + * | 0 0 C D | + * | | + * | 0 0 -1 0 | + * ( ) + * + * right+left + * A = __________ + * right-left + * + * top+bottom + * B = __________ + * top-bottom + * + * zFar+zNear + * C = - __________ + * zFar-zNear + * + * 2*zFar*zNear + * D = - ____________ + * zFar-zNear + */ + NodePerspectiveCamera(double left, double right, double bottom, double top, double zNear, double zFar); }; -#endif // NODE_CAMERA_H_ +#endif // __FREESTYLE_NODE_CAMERA_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp index acd740ee055..fed589b17c5 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp @@ -1,34 +1,46 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp + * \ingroup freestyle + * \brief Class to define a Drawing Style to be applied to the underlying children. Inherits from NodeGroup. + * \author Stephane Grabli + * \date 06/02/2002 + */ #include "NodeDrawingStyle.h" -void NodeDrawingStyle::accept(SceneVisitor& v) { - v.visitNodeDrawingStyle(*this); +void NodeDrawingStyle::accept(SceneVisitor& v) +{ + v.visitNodeDrawingStyle(*this); - v.visitNodeDrawingStyleBefore(*this); - v.visitDrawingStyle(_DrawingStyle); - for(vector<Node*>::iterator node=_Children.begin(), end=_Children.end(); - node!=end; - node++) - (*node)->accept(v); - v.visitNodeDrawingStyleAfter(*this); + v.visitNodeDrawingStyleBefore(*this); + v.visitDrawingStyle(_DrawingStyle); + for (vector<Node*>::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node) + (*node)->accept(v); + v.visitNodeDrawingStyleAfter(*this); } diff --git a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h index 012f963ea8c..29a05290df1 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h +++ b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h @@ -1,70 +1,111 @@ -// -// Filename : NodeDrawingStyle.h -// Author(s) : Stephane Grabli -// Purpose : Class to define a Drawing Style to be applied -// to the underlying children. Inherits from NodeGroup. -// Date of creation : 06/02/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef NODEDRAWINGSTYLE_H -# define NODEDRAWINGSTYLE_H - -# include "../system/FreestyleConfig.h" -# include "NodeGroup.h" -# include "DrawingStyle.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_DRAWING_STYLE_H__ +#define __FREESTYLE_NODE_DRAWING_STYLE_H__ + +/** \file blender/freestyle/intern/scene_graph/NodeDrawingStyle.h + * \ingroup freestyle + * \brief Class to define a Drawing Style to be applied to the underlying children. Inherits from NodeGroup. + * \author Stephane Grabli + * \date 06/02/2002 + */ + +#include "DrawingStyle.h" +#include "NodeGroup.h" + +#include "../system/FreestyleConfig.h" class LIB_SCENE_GRAPH_EXPORT NodeDrawingStyle : public NodeGroup { public: + inline NodeDrawingStyle() : NodeGroup() {} + virtual ~NodeDrawingStyle() {} + + inline const DrawingStyle& drawingStyle() const + { + return _DrawingStyle; + } + + inline void setDrawingStyle(const DrawingStyle& iDrawingStyle) + { + _DrawingStyle = iDrawingStyle; + } + + /*! Sets the style. Must be one of FILLED, LINES, POINTS, INVISIBLE. */ + inline void setStyle(const DrawingStyle::STYLE iStyle) + { + _DrawingStyle.setStyle(iStyle); + } + + /*! Sets the line width in the LINES style case */ + inline void setLineWidth(const float iLineWidth) + { + _DrawingStyle.setLineWidth(iLineWidth); + } + + /*! Sets the Point size in the POINTS style case */ + inline void setPointSize(const float iPointSize) + { + _DrawingStyle.setPointSize(iPointSize); + } + + /*! Enables or disables the lighting. TRUE = enable */ + inline void setLightingEnabled(const bool iEnableLighting) + { + _DrawingStyle.setLightingEnabled(iEnableLighting); + } - inline NodeDrawingStyle() : NodeGroup() {} - virtual ~NodeDrawingStyle() {} + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); - inline const DrawingStyle& drawingStyle() const { return _DrawingStyle; } - inline void setDrawingStyle(const DrawingStyle& iDrawingStyle) { _DrawingStyle = iDrawingStyle; } + /*! accessors */ + inline DrawingStyle::STYLE style() const + { + return _DrawingStyle.style(); + } - /*! Sets the style. Must be one of FILLED, LINES, POINTS, INVISIBLE. */ - inline void setStyle(const DrawingStyle::STYLE iStyle) { _DrawingStyle.setStyle(iStyle); } - /*! Sets the line width in the LINES style case */ - inline void setLineWidth(const float iLineWidth) { _DrawingStyle.setLineWidth(iLineWidth); } - /*! Sets the Point size in the POINTS style case */ - inline void setPointSize(const float iPointSize) { _DrawingStyle.setPointSize(iPointSize); } - /*! Enables or disables the lighting. TRUE = enable */ - inline void setLightingEnabled(const bool iEnableLighting) { _DrawingStyle.setLightingEnabled(iEnableLighting); } + inline float lineWidth() const + { + return _DrawingStyle.lineWidth(); + } - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); + inline float pointSize() const + { + return _DrawingStyle.pointSize(); + } - /*! accessors */ - inline DrawingStyle::STYLE style() const {return _DrawingStyle.style();} - inline float lineWidth() const {return _DrawingStyle.lineWidth();} - inline float pointSize() const {return _DrawingStyle.pointSize();} - inline bool lightingEnabled() const {return _DrawingStyle.lightingEnabled();} + inline bool lightingEnabled() const + { + return _DrawingStyle.lightingEnabled(); + } private: - DrawingStyle _DrawingStyle; + DrawingStyle _DrawingStyle; }; -#endif // NODEDRAWINGSTYLE_H +#endif // __FREESTYLE_NODE_DRAWING_STYLE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp b/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp index 3d2aa2c8694..5426c60d3e1 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp @@ -1,122 +1,126 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/NodeGroup.cpp + * \ingroup freestyle + * \brief Class to represent a group node. This node can contains several children. + * \brief It also contains a transform matrix indicating the transform state of the underlying children. + * \author Stephane Grabli + * \date 24/01/2002 + */ #include "NodeGroup.h" void NodeGroup::AddChild(Node *iChild) { - if(NULL == iChild) - return; + if (NULL == iChild) + return; - _Children.push_back(iChild); - iChild->addRef(); + _Children.push_back(iChild); + iChild->addRef(); } int NodeGroup::destroy() { - /*! Node::destroy makes a release on the object - * and then returns the reference counter. - * If the reference counter is equal to 0, - * that means that nobody else is linking - * this node group and that we can destroy the whole - * underlying tree. - * Else, one or several Node link this node group, - * and we only returns the reference counter - * decremented by Node::destroy(); - */ - int refThis = Node::destroy(); - - // if refThis != 0, we can't destroy the tree - if(0 != refThis) - return refThis; - - // If we are here, that means that nobody else - // needs our NodeGroup and we can destroy it. - int refCount = 0; - vector<Node *>::iterator node; - - for(node=_Children.begin(); node!=_Children.end(); node++) - { - refCount = (*node)->destroy(); - if(0 == refCount) - delete (*node); - } - - _Children.clear(); - - return refThis; + /*! Node::destroy makes a release on the object and then returns the reference counter. + * If the reference counter is equal to 0, that means that nobody else is linking this node group and + * that we can destroy the whole underlying tree. + * Else, one or several Node link this node group, and we only returns the reference counter + * decremented by Node::destroy(); + */ + int refThis = Node::destroy(); + + // if refThis != 0, we can't destroy the tree + if (0 != refThis) + return refThis; + + // If we are here, that means that nobody else needs our NodeGroup and we can destroy it. + int refCount = 0; + vector<Node *>::iterator node; + + for (node = _Children.begin(); node != _Children.end(); ++node) { + refCount = (*node)->destroy(); + if (0 == refCount) + delete (*node); + } + + _Children.clear(); + + return refThis; } -void NodeGroup::accept(SceneVisitor& v) { - v.visitNodeGroup(*this); - - v.visitNodeGroupBefore(*this); - for(vector<Node *>::iterator node=_Children.begin(), end=_Children.end(); - node!=end; - node++) - (*node)->accept(v); - v.visitNodeGroupAfter(*this); +void NodeGroup::accept(SceneVisitor& v) +{ + v.visitNodeGroup(*this); + + v.visitNodeGroupBefore(*this); + for (vector<Node *>::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node) + (*node)->accept(v); + v.visitNodeGroupAfter(*this); } void NodeGroup::DetachChildren() { - vector<Node *>::iterator node; - - for(node=_Children.begin(); node!=_Children.end(); node++) - { - (*node)->release(); - } - - _Children.clear(); + vector<Node *>::iterator node; + + for (node = _Children.begin(); node != _Children.end(); ++node) { + (*node)->release(); + } + + _Children.clear(); } void NodeGroup::DetachChild(Node *iChild) { - int found = 0; - vector<Node*>::iterator node; - - for(node=_Children.begin(); node!=_Children.end(); node++) - { - if((*node) == iChild) - { - (*node)->release(); - _Children.erase(node); - found = 1; - break; - } - } + int found = 0; + vector<Node*>::iterator node; + + for (node = _Children.begin(); node != _Children.end(); ++node) { + if ((*node) == iChild) { + (*node)->release(); + _Children.erase(node); + found = 1; + break; + } + } } -void NodeGroup::RetrieveChildren(vector<Node*>& oNodes){ - oNodes = _Children; +void NodeGroup::RetrieveChildren(vector<Node*>& oNodes) +{ + oNodes = _Children; } const BBox<Vec3r>& NodeGroup::UpdateBBox() { - vector<Node *>::iterator node; - clearBBox(); - for(node=_Children.begin(); node!=_Children.end(); node++) - { - AddBBox((*node)->UpdateBBox()); - } - - return Node::UpdateBBox(); + vector<Node *>::iterator node; + clearBBox(); + for (node = _Children.begin(); node != _Children.end(); ++node) { + AddBBox((*node)->UpdateBBox()); + } + + return Node::UpdateBBox(); } diff --git a/source/blender/freestyle/intern/scene_graph/NodeGroup.h b/source/blender/freestyle/intern/scene_graph/NodeGroup.h index a1bd2b57e56..1c5b106d5c6 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeGroup.h +++ b/source/blender/freestyle/intern/scene_graph/NodeGroup.h @@ -1,84 +1,89 @@ -// -// Filename : NodeGroup.h -// Author(s) : Stephane Grabli -// Purpose : Class to represent a group node. This node can contains -// several children. It also contains a transform matrix -// indicating the transform state of the underlying -// children. -// Date of creation : 24/01/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef NODEGROUP_H -# define NODEGROUP_H - -# include <vector> -# include "../system/FreestyleConfig.h" -# include "Node.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_GROUP_H__ +#define __FREESTYLE_NODE_GROUP_H__ + +/** \file blender/freestyle/intern/scene_graph/NodeGroup.h + * \ingroup freestyle + * \brief Class to represent a group node. This node can contains several children. + * \brief It also contains a transform matrix indicating the transform state of the underlying children. + * \author Stephane Grabli + * \date 24/01/2002 + */ + +#include <vector> + +#include "Node.h" + +#include "../system/FreestyleConfig.h" using namespace std; class LIB_SCENE_GRAPH_EXPORT NodeGroup : public Node { public: + inline NodeGroup(): Node() {} + virtual ~NodeGroup(){} - inline NodeGroup(): Node() {} - virtual ~NodeGroup(){} + /*! Adds a child. Makes a addRef on the iChild reference counter */ + virtual void AddChild(Node *iChild); - /*! Adds a child. Makes a addRef on the - * iChild reference counter */ - virtual void AddChild(Node *iChild); + /*! destroys all the underlying nodes + * Returns the reference counter after having done a release() + */ + virtual int destroy(); - /*! destroys all the underlying nodes - * Returns the reference counter - * after having done a release() */ - virtual int destroy(); + /*! Detaches all the children */ + virtual void DetachChildren(); - /*! Detaches all the children */ - virtual void DetachChildren(); + /*! Detached the sepcified child */ + virtual void DetachChild(Node *iChild); - /*! Detached the sepcified child */ - virtual void DetachChild(Node *iChild); + /*! Retrieve children */ + virtual void RetrieveChildren(vector<Node*>& oNodes); - /*! Retrieve children */ - virtual void RetrieveChildren(vector<Node*>& oNodes); + /*! Renders every children */ +// virtual void Render(Renderer *iRenderer); + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); - /*! Renders every children */ - // virtual void Render(Renderer *iRenderer); + /*! Updates the BBox */ + virtual const BBox<Vec3r>& UpdateBBox(); - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Updates the BBox */ - virtual const BBox<Vec3r>& UpdateBBox(); - - /*! Returns the number of children */ - virtual int numberOfChildren() {return _Children.size();} + /*! Returns the number of children */ + virtual int numberOfChildren() + { + return _Children.size(); + } protected: - vector<Node*> _Children; + vector<Node*> _Children; }; -#endif // NODEGROUP_H +#endif // __FREESTYLE_NODE_GROUP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeLight.cpp b/source/blender/freestyle/intern/scene_graph/NodeLight.cpp index 61a46155cfa..f410d2da18e 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeLight.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeLight.cpp @@ -1,80 +1,86 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/NodeLight.cpp + * \ingroup freestyle + * \brief Class to represent a light node + * \author Stephane Grabli + * \date 25/01/2002 + */ #include "NodeLight.h" int NodeLight::numberOfLights = 0; -NodeLight::NodeLight() -: Node() +NodeLight::NodeLight() : Node() { - if(numberOfLights > 7) - { - _number = 7; - } - else - { - _number = numberOfLights; - numberOfLights++; - } - - Ambient[0] = Ambient[1] = Ambient[2] = 0.f; - Ambient[3] = 1.f; - - for(int i=0; i<4; i++) - { - Diffuse[i] = 1.f; - Specular[i] = 1.f; - } + if (numberOfLights > 7) { + _number = 7; + } + else { + _number = numberOfLights; + numberOfLights++; + } - Position[0] = Position[1] = Position[3] = 0.f; - Position[2] = 1.f; + Ambient[0] = Ambient[1] = Ambient[2] = 0.0f; + Ambient[3] = 1.0f; - on = true; + for (int i = 0; i < 4; i++) { + Diffuse[i] = 1.0f; + Specular[i] = 1.0f; + } + + Position[0] = Position[1] = Position[3] = 0.0f; + Position[2] = 1.0f; + + on = true; } -NodeLight::NodeLight(NodeLight& iBrother) -: Node(iBrother) +NodeLight::NodeLight(NodeLight& iBrother) : Node(iBrother) { - if(numberOfLights > 7) - { - _number = 7; - } - else - { - _number = numberOfLights; - numberOfLights++; - } + if (numberOfLights > 7) { + _number = 7; + } + else { + _number = numberOfLights; + numberOfLights++; + } - for(int i=0; i<4; i++) - { - Ambient[i] = iBrother.ambient()[i]; - Diffuse[i] = iBrother.diffuse()[i]; - Specular[i] = iBrother.specular()[i]; - Position[i] = iBrother.position()[i]; - } + for (int i = 0; i < 4; i++) { + Ambient[i] = iBrother.ambient()[i]; + Diffuse[i] = iBrother.diffuse()[i]; + Specular[i] = iBrother.specular()[i]; + Position[i] = iBrother.position()[i]; + } - on = iBrother.isOn(); + on = iBrother.isOn(); } -void NodeLight::accept(SceneVisitor& v) { - v.visitNodeLight(*this); +void NodeLight::accept(SceneVisitor& v) +{ + v.visitNodeLight(*this); } diff --git a/source/blender/freestyle/intern/scene_graph/NodeLight.h b/source/blender/freestyle/intern/scene_graph/NodeLight.h index 0689505fb24..49484d8b9b3 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeLight.h +++ b/source/blender/freestyle/intern/scene_graph/NodeLight.h @@ -1,86 +1,113 @@ -// -// Filename : NodeLight.h -// Author(s) : Stephane Grabli -// Purpose : Class to represent a light node -// Date of creation : 25/01/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef NODELIGHT_H -# define NODELIGHT_H - -# include "../geometry/Geom.h" -# include "../system/FreestyleConfig.h" -# include "Node.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_LIGHT_H__ +#define __FREESTYLE_NODE_LIGHT_H__ + +/** \file blender/freestyle/intern/scene_graph/NodeLight.h + * \ingroup freestyle + * \brief Class to represent a light node + * \author Stephane Grabli + * \date 25/01/2002 + */ + +#include "Node.h" + +#include "../geometry/Geom.h" + +#include "../system/FreestyleConfig.h" using namespace Geometry; class LIB_SCENE_GRAPH_EXPORT NodeLight : public Node { public: + NodeLight(); + NodeLight(NodeLight& iBrother); + + virtual ~NodeLight() {} + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); - NodeLight(); - NodeLight(NodeLight& iBrother); + /*! Accessors for the light properties */ + inline const float * ambient() const + { + return Ambient; + } - virtual ~NodeLight() {} + inline const float * diffuse() const + { + return Diffuse; + } - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); + inline const float * specular() const + { + return Specular; + } + + inline const float * position() const + { + return Position; + } + + inline bool isOn() const + { + return on; + } + + inline int number() const + { + return _number; + } - /*! Accessors for the light properties */ - inline const float * ambient() const {return Ambient;} - inline const float * diffuse() const {return Diffuse;} - inline const float * specular() const {return Specular;} - inline const float * position() const {return Position;} - inline bool isOn() const {return on;} - inline int number() const {return _number;} - private: - // Data members - // ============ - - /*! on=true, the light is on */ - bool on; - - /*! The color definition */ - float Ambient[4]; - float Diffuse[4]; - float Specular[4]; - - /*! Light position. if w = 0, the light is - * placed at infinite. - */ - float Position[4]; - - /*! used to manage the number of lights */ - /*! numberOfLights - * the number of lights in the scene. - * Initially, 0. - */ - static int numberOfLights; - /*! The current lignt number */ - int _number; + // Data members + // ============ + + /*! on=true, the light is on */ + bool on; + + /*! The color definition */ + float Ambient[4]; + float Diffuse[4]; + float Specular[4]; + + /*! Light position. if w = 0, the light is placed at infinite. */ + float Position[4]; + + /*! used to manage the number of lights */ + /*! numberOfLights + * the number of lights in the scene. + * Initially, 0. + */ + static int numberOfLights; + /*! The current lignt number */ + int _number; }; -#endif // NODELIGHT_H +#endif // __FREESTYLE_NODE_LIGHT_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeShape.cpp b/source/blender/freestyle/intern/scene_graph/NodeShape.cpp index 9083c852d36..b1593c9f43b 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeShape.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeShape.cpp @@ -1,51 +1,63 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/NodeShape.cpp + * \ingroup freestyle + * \brief Class to build a shape node. It contains a Rep, which is the shape geometry + * \author Stephane Grabli + * \date 25/01/2002 + */ #include "NodeShape.h" NodeShape::~NodeShape() { - vector<Rep *>::iterator rep; - - if(0 != _Shapes.size()) - { - for(rep=_Shapes.begin(); rep!=_Shapes.end(); rep++) - { - int refCount = (*rep)->destroy(); - if(0 == refCount) - delete (*rep); - } - - _Shapes.clear(); - } + vector<Rep *>::iterator rep; + + if (0 != _Shapes.size()) { + for (rep = _Shapes.begin(); rep != _Shapes.end(); ++rep) { + int refCount = (*rep)->destroy(); + if (0 == refCount) + delete (*rep); + } + + _Shapes.clear(); + } } -void NodeShape::accept(SceneVisitor& v) { - v.visitNodeShape(*this); - - v.visitFrsMaterial(_FrsMaterial); - - v.visitNodeShapeBefore(*this); - vector<Rep *>::iterator rep; - for(rep = _Shapes.begin(); rep != _Shapes.end(); rep++) - (*rep)->accept(v); - v.visitNodeShapeAfter(*this); +void NodeShape::accept(SceneVisitor& v) +{ + v.visitNodeShape(*this); + + v.visitFrsMaterial(_FrsMaterial); + + v.visitNodeShapeBefore(*this); + vector<Rep *>::iterator rep; + for (rep = _Shapes.begin(); rep != _Shapes.end(); ++rep) + (*rep)->accept(v); + v.visitNodeShapeAfter(*this); } diff --git a/source/blender/freestyle/intern/scene_graph/NodeShape.h b/source/blender/freestyle/intern/scene_graph/NodeShape.h index 9849d4661b8..046d8b0e392 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeShape.h +++ b/source/blender/freestyle/intern/scene_graph/NodeShape.h @@ -1,43 +1,50 @@ -// -// Filename : NodeShape.h -// Author(s) : Stephane Grabli -// Purpose : Class to build a shape node. It contains a Rep, -// which is the shape geometry -// Date of creation : 25/01/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef NODESHAPE_H -# define NODESHAPE_H - -# include <vector> -# include "../system/FreestyleConfig.h" -# include "Node.h" -# include "Rep.h" -# include "../geometry/BBox.h" -# include "../geometry/Geom.h" -# include "FrsMaterial.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_SHAPE_H__ +#define __FREESTYLE_NODE_SHAPE_H__ + +/** \file blender/freestyle/intern/scene_graph/NodeShape.h + * \ingroup freestyle + * \brief Class to build a shape node. It contains a Rep, which is the shape geometry + * \author Stephane Grabli + * \date 25/01/2002 + */ + +#include <vector> + +#include "../geometry/BBox.h" +#include "../geometry/Geom.h" + +#include "../system/FreestyleConfig.h" + +#include "FrsMaterial.h" +#include "Node.h" +#include "Rep.h" using namespace std; using namespace Geometry; @@ -45,45 +52,52 @@ using namespace Geometry; class LIB_SCENE_GRAPH_EXPORT NodeShape : public Node { public: - - inline NodeShape() : Node() {} - - virtual ~NodeShape(); - - /*! Adds a Rep to the _Shapes list - * The delete of the rep is done - * when it is not used any more by - * the Scene Manager. So, it must not - * be deleted by the caller - */ - virtual void AddRep(Rep *iRep) - { - if(NULL == iRep) - return; - _Shapes.push_back(iRep); - iRep->addRef(); - - // updates bbox: - AddBBox(iRep->bbox()); - } - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Sets the shape material */ - inline void setFrsMaterial(const FrsMaterial& iMaterial) { _FrsMaterial = iMaterial; } - - /*! accessors */ - /*! returns the shape's material */ - inline FrsMaterial& frs_material() { return _FrsMaterial; } - inline const vector<Rep*>& shapes() {return _Shapes;} + inline NodeShape() : Node() {} + + virtual ~NodeShape(); + + /*! Adds a Rep to the _Shapes list + * The delete of the rep is done when it is not used any more by the Scene Manager. + * So, it must not be deleted by the caller + */ + virtual void AddRep(Rep *iRep) + { + if (NULL == iRep) + return; + _Shapes.push_back(iRep); + iRep->addRef(); + + // updates bbox: + AddBBox(iRep->bbox()); + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); + + /*! Sets the shape material */ + inline void setFrsMaterial(const FrsMaterial& iMaterial) + { + _FrsMaterial = iMaterial; + } + + /*! accessors */ + /*! returns the shape's material */ + inline FrsMaterial& frs_material() + { + return _FrsMaterial; + } + + inline const vector<Rep*>& shapes() + { + return _Shapes; + } private: - /*! list of shapes */ - vector<Rep*> _Shapes; + /*! list of shapes */ + vector<Rep*> _Shapes; - /*! Shape Material */ - FrsMaterial _FrsMaterial; + /*! Shape Material */ + FrsMaterial _FrsMaterial; }; -#endif // NODESHAPE_H +#endif // __FREESTYLE_NODE_SHAPE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp b/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp index 8f706c78259..aa01200a4d2 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp @@ -1,166 +1,178 @@ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/freestyle/intern/scene_graph/NodeTransform.cpp + * \ingroup freestyle + * \brief Class to represent a transform node. A Transform node contains one or several children, + * \brief all affected by the transformation. + * \author Stephane Grabli + * \date 06/02/2002 + */ +#include "NodeTransform.h" #include "../system/FreestyleConfig.h" -#include "NodeTransform.h" void NodeTransform::Translate(real x, real y, real z) { - _Matrix(0, 3) += x; - _Matrix(1, 3) += y; - _Matrix(2, 3) += z; + _Matrix(0, 3) += x; + _Matrix(1, 3) += y; + _Matrix(2, 3) += z; } void NodeTransform::Rotate(real iAngle, real x, real y, real z) { - //Normalize the x,y,z vector; - real norm = (real)sqrt(x*x+y*y+z*z); - if(0 == norm) - return; - - x /= norm; - y /= norm; - z /= norm; - - // find the corresponding matrix with the Rodrigues formula: - // R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda - Matrix33r Ntilda; - Ntilda(0,0) = Ntilda(1,1) = Ntilda(2,2) = 0.f; - Ntilda(0,1) = -z; - Ntilda(0,2) = y; - Ntilda(1,0) = z; - Ntilda(1,2) = -x; - Ntilda(2,0) = -y; - Ntilda(2,1) = x; - - const Matrix33r Ntilda2(Ntilda * Ntilda); - - - const real sinAngle = (real)sin((iAngle/180.f)*M_PI); - const real cosAngle = (real)cos((iAngle/180.f)*M_PI); - - Matrix33r NS(Ntilda*sinAngle); - Matrix33r NC(Ntilda2*(1.f-cosAngle)); - Matrix33r R; - R = Matrix33r::identity(); - R += NS + NC; - - //R4 is the corresponding 4x4 matrix - Matrix44r R4; - R4 = Matrix44r::identity(); - - for(int i=0; i<3; i++) - for(int j=0; j<3; j++) - R4(i,j) = R(i,j); - - // Finally, we multiply our current matrix by R4: - Matrix44r mat_tmp(_Matrix); - _Matrix = mat_tmp * R4; + //Normalize the x,y,z vector; + real norm = (real)sqrt(x * x + y * y + z * z); + if (0 == norm) + return; + + x /= norm; + y /= norm; + z /= norm; + + /* find the corresponding matrix with the Rodrigues formula: + * R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda + */ + Matrix33r Ntilda; + Ntilda(0, 0) = Ntilda(1, 1) = Ntilda(2, 2) = 0.0f; + Ntilda(0, 1) = -z; + Ntilda(0, 2) = y; + Ntilda(1, 0) = z; + Ntilda(1, 2) = -x; + Ntilda(2, 0) = -y; + Ntilda(2, 1) = x; + + const Matrix33r Ntilda2(Ntilda * Ntilda); + + + const real sinAngle = (real)sin((iAngle / 180.0f) * M_PI); + const real cosAngle = (real)cos((iAngle / 180.0f) * M_PI); + + Matrix33r NS(Ntilda * sinAngle); + Matrix33r NC(Ntilda2 * (1.0f - cosAngle)); + Matrix33r R; + R = Matrix33r::identity(); + R += NS + NC; + + // R4 is the corresponding 4x4 matrix + Matrix44r R4; + R4 = Matrix44r::identity(); + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) + R4(i, j) = R(i, j); + } + + // Finally, we multiply our current matrix by R4: + Matrix44r mat_tmp(_Matrix); + _Matrix = mat_tmp * R4; } void NodeTransform::Scale(real x, real y, real z) { - _Matrix(0,0) *= x; - _Matrix(1,1) *= y; - _Matrix(2,2) *= z; + _Matrix(0, 0) *= x; + _Matrix(1, 1) *= y; + _Matrix(2, 2) *= z; - _Scaled = true; + _Scaled = true; } void NodeTransform::MultiplyMatrix(const Matrix44r &iMatrix) { - Matrix44r mat_tmp(_Matrix); - _Matrix = mat_tmp * iMatrix; + Matrix44r mat_tmp(_Matrix); + _Matrix = mat_tmp * iMatrix; } void NodeTransform::setMatrix(const Matrix44r &iMatrix) { - _Matrix = iMatrix; - if(isScaled(iMatrix)) - _Scaled = true; + _Matrix = iMatrix; + if (isScaled(iMatrix)) + _Scaled = true; } -void NodeTransform::accept(SceneVisitor& v) { - v.visitNodeTransform(*this); +void NodeTransform::accept(SceneVisitor& v) +{ + v.visitNodeTransform(*this); - v.visitNodeTransformBefore(*this); - for(vector<Node *>::iterator node=_Children.begin(), end=_Children.end(); - node!=end; - node++) - (*node)->accept(v); - v.visitNodeTransformAfter(*this); + v.visitNodeTransformBefore(*this); + for (vector<Node *>::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node) + (*node)->accept(v); + v.visitNodeTransformAfter(*this); } void NodeTransform::AddBBox(const BBox<Vec3r>& iBBox) { - Vec3r oldMin(iBBox.getMin()); - Vec3r oldMax(iBBox.getMax()); - - // compute the 8 corners of the bbox - HVec3r box[8]; - box[0] = HVec3r(iBBox.getMin()); - box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]); - box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]); - box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]); - box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]); - box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]); - box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]); - box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]); - - // Computes the transform iBBox - HVec3r tbox[8]; - unsigned i; - for(i = 0; i < 8; i++) - tbox[i] = _Matrix * box[i]; - - Vec3r newMin(tbox[0]); - Vec3r newMax(tbox[0]); - for (i=0; i<8; i++) - { - for (unsigned int j=0; j<3; j++) - { - if (newMin[j] > tbox[i][j]) - newMin[j] = tbox[i][j]; - if (newMax[j] < tbox[i][j]) - newMax[j] = tbox[i][j]; - } - } - - BBox<Vec3r> transformBox(newMin, newMax); - - Node::AddBBox(transformBox); + Vec3r oldMin(iBBox.getMin()); + Vec3r oldMax(iBBox.getMax()); + + // compute the 8 corners of the bbox + HVec3r box[8]; + box[0] = HVec3r(iBBox.getMin()); + box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]); + box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]); + box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]); + box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]); + box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]); + box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]); + box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]); + + // Computes the transform iBBox + HVec3r tbox[8]; + unsigned int i; + for (i = 0; i < 8; i++) + tbox[i] = _Matrix * box[i]; + + Vec3r newMin(tbox[0]); + Vec3r newMax(tbox[0]); + for (i = 0; i < 8; i++) { + for (unsigned int j = 0; j < 3; j++) { + if (newMin[j] > tbox[i][j]) + newMin[j] = tbox[i][j]; + if (newMax[j] < tbox[i][j]) + newMax[j] = tbox[i][j]; + } + } + + BBox<Vec3r> transformBox(newMin, newMax); + + Node::AddBBox(transformBox); } bool NodeTransform::isScaled(const Matrix44r &M) { - for(unsigned int j=0; j<3; j++) - { - real norm = 0; - for(unsigned int i=0; i<3; i++) - { - norm += M(i,j)*M(i,j); - } - if((norm > 1.01) || (norm < 0.99)) - return true; - } - - return false; + for (unsigned int j = 0; j < 3; j++) { + real norm = 0; + for (unsigned int i = 0; i < 3; i++) { + norm += M(i, j) * M(i, j); + } + if ((norm > 1.01) || (norm < 0.99)) + return true; + } + + return false; } diff --git a/source/blender/freestyle/intern/scene_graph/NodeTransform.h b/source/blender/freestyle/intern/scene_graph/NodeTransform.h index e75132466f0..e98045989d3 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeTransform.h +++ b/source/blender/freestyle/intern/scene_graph/NodeTransform.h @@ -1,107 +1,110 @@ -// -// Filename : NodeTransform.h -// Author(s) : Stephane Grabli -// Purpose : Class to represent a transform node. A Transform node -// contains one or several children, all affected by the -// transformation. -// Date of creation : 06/02/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef NODETRANSFORM_H -# define NODETRANSFORM_H - -# include "../geometry/Geom.h" -# include "../system/FreestyleConfig.h" -# include "NodeGroup.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_TRANSFORM_H__ +#define __FREESTYLE_NODE_TRANSFORM_H__ + +/** \file blender/freestyle/intern/scene_graph/NodeTransform.h + * \ingroup freestyle + * \brief Class to represent a transform node. A Transform node contains one or several children, + * \brief all affected by the transformation. + * \author Stephane Grabli + * \date 06/02/2002 + */ + +#include "NodeGroup.h" + +#include "../geometry/Geom.h" + +#include "../system/FreestyleConfig.h" using namespace Geometry; class LIB_SCENE_GRAPH_EXPORT NodeTransform : public NodeGroup { public: - - inline NodeTransform() : NodeGroup() { - _Matrix = Matrix44r::identity(); - _Scaled=false; - } - - virtual ~NodeTransform() {} - - /*! multiplys the current matrix by the - * x, y, z translation matrix. - */ - void Translate(real x, real y, real z); - - /*! multiplys the current matrix by a - * rotation matrix - * iAngle - * The rotation angle - * x, y, z - * The rotation axis - */ - void Rotate(real iAngle, real x, real y, real z); - - /*! multiplys the current matrix by a - * scaling matrix. - * x, y, z - * The scaling coefficients - * with respect to the x,y,z axis - */ - void Scale(real x, real y, real z); - - /*! Multiplys the current matrix - * by iMatrix - */ - void MultiplyMatrix(const Matrix44r &iMatrix); - - /*! Sets the current matrix to iMatrix */ - void setMatrix(const Matrix44r &iMatrix); - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Overloads the Node::AddBBox in order to take care - * about the transformation - */ - virtual void AddBBox(const BBox<Vec3r>& iBBox); - - /*! Checks whether a matrix contains a scale factor - * or not. - * Returns true if yes. - * iMatrix - * The matrix to check - */ - bool isScaled(const Matrix44r &M); - - /*! accessors */ - inline const Matrix44r& matrix() const { return _Matrix; } - inline bool scaled() const {return _Scaled;} + inline NodeTransform() : NodeGroup() + { + _Matrix = Matrix44r::identity(); + _Scaled = false; + } + + virtual ~NodeTransform() {} + + /*! multiplys the current matrix by the x, y, z translation matrix. */ + void Translate(real x, real y, real z); + + /*! multiplys the current matrix by a rotation matrix + * iAngle + * The rotation angle + * x, y, z + * The rotation axis + */ + void Rotate(real iAngle, real x, real y, real z); + + /*! multiplys the current matrix by a scaling matrix. + * x, y, z + * The scaling coefficients with respect to the x,y,z axis + */ + void Scale(real x, real y, real z); + + /*! Multiplys the current matrix by iMatrix */ + void MultiplyMatrix(const Matrix44r &iMatrix); + + /*! Sets the current matrix to iMatrix */ + void setMatrix(const Matrix44r &iMatrix); + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); + + /*! Overloads the Node::AddBBox in order to take care about the transformation */ + virtual void AddBBox(const BBox<Vec3r>& iBBox); + + /*! Checks whether a matrix contains a scale factor or not. + * Returns true if yes. + * M + * The matrix to check + */ + bool isScaled(const Matrix44r &M); + + /*! accessors */ + inline const Matrix44r& matrix() const + { + return _Matrix; + } + + inline bool scaled() const + { + return _Scaled; + } private: - Matrix44r _Matrix; - bool _Scaled; + Matrix44r _Matrix; + bool _Scaled; }; -#endif // NODETRANSFORM_H +#endif // __FREESTYLE_NODE_TRANSFORM_H__ diff --git a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp index 94068983596..8b29c0256ff 100644 --- a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp @@ -1,31 +1,46 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/OrientedLineRep.cpp + * \ingroup freestyle + * \brief Class to display an oriented line representation. + * \author Stephane Grabli + * \date 24/10/2002 + */ #include "OrientedLineRep.h" + #include "../system/BaseObject.h" -void OrientedLineRep::accept(SceneVisitor& v) { - Rep::accept(v); - if(!frs_material()) - v.visitOrientedLineRep(*this); - else - v.visitLineRep(*this); +void OrientedLineRep::accept(SceneVisitor& v) +{ + Rep::accept(v); + if (!frs_material()) + v.visitOrientedLineRep(*this); + else + v.visitLineRep(*this); } diff --git a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h index 4274581e39a..45cda3610f2 100644 --- a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h +++ b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h @@ -1,67 +1,66 @@ -// -// Filename : OrientedLineRep.h -// Author(s) : Stephane Grabli -// Purpose : Class to display an oriented line representation. -// Date of creation : 24/10/2002 -// -/////////////////////////////////////////////////////////////////////////////// +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __FREESTYLE_ORIENTED_LINE_REP_H__ +#define __FREESTYLE_ORIENTED_LINE_REP_H__ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/OrientedLineRep.h + * \ingroup freestyle + * \brief Class to display an oriented line representation. + * \author Stephane Grabli + * \date 24/10/2002 + */ -#ifndef VIEWEDGEREP_H -# define VIEWEDGEREP_H +#include "LineRep.h" -# include "../system/FreestyleConfig.h" -# include "LineRep.h" +#include "../system/FreestyleConfig.h" class LIB_SCENE_GRAPH_EXPORT OrientedLineRep : public LineRep { public: + OrientedLineRep() : LineRep() {} + /*! Builds a single line from 2 vertices + * v1 + * first vertex + * v2 + * second vertex + */ + inline OrientedLineRep(const Vec3r& v1, const Vec3r& v2) : LineRep(v1,v2) {} - OrientedLineRep() : LineRep() {} - /*! Builds a single line from 2 vertices - * v1 - * first vertex - * v2 - * second vertex - */ - inline OrientedLineRep(const Vec3r& v1, const Vec3r& v2) - : LineRep(v1,v2) - {} + /*! Builds a line rep from a vertex chain */ + inline OrientedLineRep(const vector<Vec3r>& vertices) : LineRep(vertices) {} - /*! Builds a line rep from a vertex chain */ - inline OrientedLineRep(const vector<Vec3r>& vertices) - : LineRep(vertices) - {} + /*! Builds a line rep from a vertex chain */ + inline OrientedLineRep(const list<Vec3r>& vertices) : LineRep(vertices) {} - /*! Builds a line rep from a vertex chain */ - inline OrientedLineRep(const list<Vec3r>& vertices) - : LineRep(vertices) - {} + virtual ~OrientedLineRep() {} - virtual ~OrientedLineRep() {} - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); }; -#endif // VIEWEDGEREP_H +#endif // __FREESTYLE_ORIENTED_LINE_REP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/Rep.cpp b/source/blender/freestyle/intern/scene_graph/Rep.cpp index 84ad2c2a966..0319a617a68 100644 --- a/source/blender/freestyle/intern/scene_graph/Rep.cpp +++ b/source/blender/freestyle/intern/scene_graph/Rep.cpp @@ -1 +1,35 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/freestyle/intern/scene_graph/Rep.cpp + * \ingroup freestyle + * \brief Base class for all shapes. Inherits from BasicObjects for references counter management (addRef, release). + * \author Stephane Grabli + * \date 25/01/2002 + */ + #include "Rep.h" diff --git a/source/blender/freestyle/intern/scene_graph/Rep.h b/source/blender/freestyle/intern/scene_graph/Rep.h index 58be0374ae4..c1b29d3fceb 100644 --- a/source/blender/freestyle/intern/scene_graph/Rep.h +++ b/source/blender/freestyle/intern/scene_graph/Rep.h @@ -1,133 +1,173 @@ -// -// Filename : Rep.h -// Author(s) : Stephane Grabli -// Purpose : Base class for all shapes. Inherits from BasicObjects -// for references counter management (addRef, release). -// Date of creation : 25/01/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef REP_H -# define REP_H - -# include "../system/BaseObject.h" -# include "SceneVisitor.h" -# include "../geometry/BBox.h" -# include "../geometry/Geom.h" -# include "../system/Precision.h" -# include "FrsMaterial.h" -# include "../system/Id.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_REP_H__ +#define __FREESTYLE_REP_H__ + +/** \file blender/freestyle/intern/scene_graph/Rep.h + * \ingroup freestyle + * \brief Base class for all shapes. Inherits from BasicObjects for references counter management (addRef, release). + * \author Stephane Grabli + * \date 25/01/2002 + */ + +#include "FrsMaterial.h" +#include "SceneVisitor.h" + +#include "../geometry/BBox.h" +#include "../geometry/Geom.h" + +#include "../system/BaseObject.h" +#include "../system/Id.h" +#include "../system/Precision.h" using namespace Geometry; class LIB_SCENE_GRAPH_EXPORT Rep : public BaseObject { public: - - inline Rep() : BaseObject() {_Id = 0; _FrsMaterial=0;} - inline Rep(const Rep& iBrother) - : BaseObject() - { - _Id = iBrother._Id; - _Name = iBrother._Name; - if(0 == iBrother._FrsMaterial) - _FrsMaterial = 0; - else - _FrsMaterial = new FrsMaterial(*(iBrother._FrsMaterial)); - - _BBox = iBrother.bbox(); - } - inline void swap(Rep& ioOther){ + inline Rep() : BaseObject() + { + _Id = 0; + _FrsMaterial = 0; + } + + inline Rep(const Rep& iBrother) : BaseObject() + { + _Id = iBrother._Id; + _Name = iBrother._Name; + if (0 == iBrother._FrsMaterial) + _FrsMaterial = 0; + else + _FrsMaterial = new FrsMaterial(*(iBrother._FrsMaterial)); + + _BBox = iBrother.bbox(); + } + + inline void swap(Rep& ioOther) + { std::swap(_BBox,ioOther._BBox); std::swap(_Id, ioOther._Id); std::swap(_Name, ioOther._Name); std::swap(_FrsMaterial,ioOther._FrsMaterial); } - Rep& operator=(const Rep& iBrother){ - if(&iBrother != this){ + + Rep& operator=(const Rep& iBrother) + { + if (&iBrother != this) { _Id = iBrother._Id; _Name = iBrother._Name; - if(0 == iBrother._FrsMaterial) + if (0 == iBrother._FrsMaterial) { _FrsMaterial = 0; - else{ - if(_FrsMaterial == 0){ + } + else { + if (_FrsMaterial == 0) { _FrsMaterial = new FrsMaterial(*iBrother._FrsMaterial); - }else{ - (*_FrsMaterial)=(*(iBrother._FrsMaterial)); + } + else { + (*_FrsMaterial) = (*(iBrother._FrsMaterial)); } _BBox = iBrother.bbox(); } } return *this; } - virtual ~Rep() - { - if(0 != _FrsMaterial) - { - delete _FrsMaterial; - _FrsMaterial = 0; - } - } - - /*! Accept the corresponding visitor - * Must be overload by - * inherited classes - */ - virtual void accept(SceneVisitor& v) { - if(_FrsMaterial) - v.visitFrsMaterial(*_FrsMaterial); - v.visitRep(*this); - } - - /*! Computes the rep bounding box. - * Each Inherited rep must compute - * its bbox depending on the way the data - * are stored. So, each inherited class - * must overload this method - */ - virtual void ComputeBBox() = 0; - - /*! Returns the rep bounding box */ - virtual const BBox<Vec3r>& bbox() const {return _BBox;} - inline Id getId() const {return _Id;} - inline const string& getName() const {return _Name;} - inline const FrsMaterial * frs_material() const {return _FrsMaterial;} - - /*! Sets the Rep bounding box */ - virtual void setBBox(const BBox<Vec3r>& iBox) {_BBox = iBox;} - inline void setId(const Id& id) {_Id = id;} - inline void setName(const string& name) {_Name = name;} - inline void setFrsMaterial(const FrsMaterial& iMaterial) - { - _FrsMaterial = new FrsMaterial(iMaterial); - } + + virtual ~Rep() + { + if (0 != _FrsMaterial) { + delete _FrsMaterial; + _FrsMaterial = 0; + } + } + + /*! Accept the corresponding visitor + * Must be overload by inherited classes + */ + virtual void accept(SceneVisitor& v) + { + if (_FrsMaterial) + v.visitFrsMaterial(*_FrsMaterial); + v.visitRep(*this); + } + + /*! Computes the rep bounding box. + * Each Inherited rep must compute its bbox depending on the way the data are stored. So, each inherited class + * must overload this method + */ + virtual void ComputeBBox() = 0; + + /*! Returns the rep bounding box */ + virtual const BBox<Vec3r>& bbox() const + { + return _BBox; + } + + inline Id getId() const + { + return _Id; + } + + inline const string& getName() const + { + return _Name; + } + + inline const FrsMaterial * frs_material() const + { + return _FrsMaterial; + } + + /*! Sets the Rep bounding box */ + virtual void setBBox(const BBox<Vec3r>& iBox) + { + _BBox = iBox; + } + + inline void setId(const Id& id) + { + _Id = id; + } + + inline void setName(const string& name) + { + _Name = name; + } + + inline void setFrsMaterial(const FrsMaterial& iMaterial) + { + _FrsMaterial = new FrsMaterial(iMaterial); + } private: - BBox<Vec3r> _BBox; - Id _Id; - string _Name; - FrsMaterial *_FrsMaterial; + BBox<Vec3r> _BBox; + Id _Id; + string _Name; + FrsMaterial *_FrsMaterial; }; -#endif // REP_H +#endif // __FREESTYLE_REP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp index aeee87f8222..8be3f2527b6 100644 --- a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp +++ b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp @@ -1,32 +1,48 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp + * \ingroup freestyle + * \brief Class to display textual information about a scene graph. + * \author Stephane Grabli + * \author Emmanuel Turquin + * \date 26/04/2003 + */ #include <iomanip> -#include "ScenePrettyPrinter.h" + #include "IndexedFaceSet.h" +#include "ScenePrettyPrinter.h" -#define VISIT(CLASS) \ - void ScenePrettyPrinter::visit##CLASS(CLASS&) { \ - _ofs << _space << #CLASS << endl; \ - } +#define VISIT(CLASS) \ + void ScenePrettyPrinter::visit##CLASS(CLASS&) \ + { \ + _ofs << _space << #CLASS << endl; \ + } VISIT(Node) VISIT(NodeShape) @@ -35,36 +51,44 @@ VISIT(NodeLight) VISIT(NodeDrawingStyle) VISIT(NodeTransform) -void ScenePrettyPrinter::visitNodeShapeBefore(NodeShape&) { - increaseSpace(); +void ScenePrettyPrinter::visitNodeShapeBefore(NodeShape&) +{ + increaseSpace(); } -void ScenePrettyPrinter::visitNodeShapeAfter(NodeShape&) { - decreaseSpace(); +void ScenePrettyPrinter::visitNodeShapeAfter(NodeShape&) +{ + decreaseSpace(); } -void ScenePrettyPrinter::visitNodeGroupBefore(NodeGroup&) { - increaseSpace(); +void ScenePrettyPrinter::visitNodeGroupBefore(NodeGroup&) +{ + increaseSpace(); } -void ScenePrettyPrinter::visitNodeGroupAfter(NodeGroup&) { - decreaseSpace(); +void ScenePrettyPrinter::visitNodeGroupAfter(NodeGroup&) +{ + decreaseSpace(); } -void ScenePrettyPrinter::visitNodeDrawingStyleBefore(NodeDrawingStyle&) { - increaseSpace(); +void ScenePrettyPrinter::visitNodeDrawingStyleBefore(NodeDrawingStyle&) +{ + increaseSpace(); } -void ScenePrettyPrinter::visitNodeDrawingStyleAfter(NodeDrawingStyle&) { - decreaseSpace(); +void ScenePrettyPrinter::visitNodeDrawingStyleAfter(NodeDrawingStyle&) +{ + decreaseSpace(); } -void ScenePrettyPrinter::visitNodeTransformBefore(NodeTransform&) { - increaseSpace(); +void ScenePrettyPrinter::visitNodeTransformBefore(NodeTransform&) +{ + increaseSpace(); } -void ScenePrettyPrinter::visitNodeTransformAfter(NodeTransform&) { - decreaseSpace(); +void ScenePrettyPrinter::visitNodeTransformAfter(NodeTransform&) +{ + decreaseSpace(); } VISIT(LineRep) @@ -72,15 +96,15 @@ VISIT(OrientedLineRep) VISIT(TriangleRep) VISIT(VertexRep) -void ScenePrettyPrinter::visitIndexedFaceSet(IndexedFaceSet& ifs) { - const real* vertices = ifs.vertices(); - unsigned vsize = ifs.vsize(); - - _ofs << _space << "IndexedFaceSet" << endl; - const real *p = vertices; - for (unsigned i = 0; i < vsize / 3; i++) { - _ofs << _space << " " << setw(3) << setfill('0') << i << ": " - << p[0] << ", " << p[1] << ", " << p[2] << endl; - p += 3; - } +void ScenePrettyPrinter::visitIndexedFaceSet(IndexedFaceSet& ifs) +{ + const real *vertices = ifs.vertices(); + unsigned vsize = ifs.vsize(); + + _ofs << _space << "IndexedFaceSet" << endl; + const real *p = vertices; + for (unsigned int i = 0; i < vsize / 3; i++) { + _ofs << _space << " " << setw(3) << setfill('0') << i << ": " << p[0] << ", " << p[1] << ", " << p[2] << endl; + p += 3; + } } diff --git a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h index 4e83825ff55..39fb9eceef8 100644 --- a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h +++ b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h @@ -1,105 +1,109 @@ -// -// Filename : ScenePrettyPrinter.h -// Author(s) : Stephane Grabli, Emmanuel Turquin -// Purpose : Class to display textual information -// about a scene graph. -// Date of creation : 26/04/2003 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef SCENE_PRETTY_PRINTER_H -# define SCENE_PRETTY_PRINTER_H - -# include <iostream> -# include <fstream> -# include <string> -# include "SceneVisitor.h" +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_SCENE_PRETTY_PRINTER_H__ +#define __FREESTYLE_SCENE_PRETTY_PRINTER_H__ + +/** \file blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h + * \ingroup freestyle + * \brief Class to display textual information about a scene graph. + * \author Stephane Grabli + * \author Emmanuel Turquin + * \date 26/04/2003 + */ + +#include <fstream> +#include <iostream> +#include <string> + +#include "SceneVisitor.h" using namespace std; class ScenePrettyPrinter : public SceneVisitor { public: - - ScenePrettyPrinter(const string filename = "SceneLog.txt") - : SceneVisitor() { - if (!filename.empty()) - _ofs.open(filename.c_str()); - if (!_ofs.is_open()) - cerr << "Warning, unable to open file \"" << filename << "\"" << endl; - _space = ""; - } - - virtual ~ScenePrettyPrinter() { - if (_ofs.is_open()) - _ofs.close(); - } - - - // - // visitClass methods - // - ////////////////////////////////////////////// - - VISIT_DECL(Node) - VISIT_DECL(NodeShape) - VISIT_DECL(NodeGroup) - VISIT_DECL(NodeLight) - VISIT_DECL(NodeDrawingStyle) - VISIT_DECL(NodeTransform) - - VISIT_DECL(LineRep) - VISIT_DECL(OrientedLineRep) - VISIT_DECL(TriangleRep) - VISIT_DECL(VertexRep) - VISIT_DECL(IndexedFaceSet) - - virtual void visitNodeShapeBefore(NodeShape&); - virtual void visitNodeShapeAfter(NodeShape&); - virtual void visitNodeGroupBefore(NodeGroup&); - virtual void visitNodeGroupAfter(NodeGroup&); - virtual void visitNodeDrawingStyleBefore(NodeDrawingStyle&); - virtual void visitNodeDrawingStyleAfter(NodeDrawingStyle&); - virtual void visitNodeTransformBefore(NodeTransform&); - virtual void visitNodeTransformAfter(NodeTransform&); - - protected: - - void increaseSpace() - { - _space += " "; - } - - void decreaseSpace() - { - _space.erase(0, 2); - } - - private: - - ofstream _ofs; - string _space; + ScenePrettyPrinter(const string filename = "SceneLog.txt") : SceneVisitor() + { + if (!filename.empty()) + _ofs.open(filename.c_str()); + if (!_ofs.is_open()) + cerr << "Warning, unable to open file \"" << filename << "\"" << endl; + _space = ""; + } + + virtual ~ScenePrettyPrinter() + { + if (_ofs.is_open()) + _ofs.close(); + } + + + // + // visitClass methods + // + ////////////////////////////////////////////// + + VISIT_DECL(Node); + VISIT_DECL(NodeShape); + VISIT_DECL(NodeGroup); + VISIT_DECL(NodeLight); + VISIT_DECL(NodeDrawingStyle); + VISIT_DECL(NodeTransform); + + VISIT_DECL(LineRep); + VISIT_DECL(OrientedLineRep); + VISIT_DECL(TriangleRep); + VISIT_DECL(VertexRep); + VISIT_DECL(IndexedFaceSet); + + virtual void visitNodeShapeBefore(NodeShape&); + virtual void visitNodeShapeAfter(NodeShape&); + virtual void visitNodeGroupBefore(NodeGroup&); + virtual void visitNodeGroupAfter(NodeGroup&); + virtual void visitNodeDrawingStyleBefore(NodeDrawingStyle&); + virtual void visitNodeDrawingStyleAfter(NodeDrawingStyle&); + virtual void visitNodeTransformBefore(NodeTransform&); + virtual void visitNodeTransformAfter(NodeTransform&); + +protected: + void increaseSpace() + { + _space += " "; + } + + void decreaseSpace() + { + _space.erase(0, 2); + } + +private: + ofstream _ofs; + string _space; }; -#endif // SCENE_PRETTY_PRINTER_H +#endif // __FREESTYLE_SCENE_PRETTY_PRINTER_H__ diff --git a/source/blender/freestyle/intern/scene_graph/SceneVisitor.cpp b/source/blender/freestyle/intern/scene_graph/SceneVisitor.cpp index da9c94930bd..32ba38ece80 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneVisitor.cpp +++ b/source/blender/freestyle/intern/scene_graph/SceneVisitor.cpp @@ -1 +1,35 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/freestyle/intern/scene_graph/SceneVisitor.cpp + * \ingroup freestyle + * \brief Class to visit (without doing anything) a scene graph structure + * \author Emmanuel Turquin + * \date 26/04/2003 + */ + #include "SceneVisitor.h" diff --git a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h index 5f67b4b44aa..57d3f9189ed 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h +++ b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h @@ -1,49 +1,54 @@ -// -// Filename : SceneVisitor.h -// Author(s) : Emmanuel Turquin -// Purpose : Class to visit (without doing anything) -// a scene graph structure -// Date of creation : 26/04/2003 -// -/////////////////////////////////////////////////////////////////////////////// +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __FREESTYLE_SCENE_VISITOR_H__ +#define __FREESTYLE_SCENE_VISITOR_H__ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/SceneVisitor.h + * \ingroup freestyle + * \brief Class to visit (without doing anything) a scene graph structure + * \author Emmanuel Turquin + * \date 26/04/2003 + */ -#ifndef SCENE_VISITOR_H -# define SCENE_VISITOR_H - -# define VISIT_COMPLETE_DEF(type) \ -virtual void visit##type(type&) {} \ -virtual void visit##type##Before(type&) {} \ -virtual void visit##type##After(type&) {} +#include "../system/FreestyleConfig.h" -# define VISIT_DECL(type) virtual void visit##type(type&); +#define VISIT_COMPLETE_DEF(type) \ + virtual void visit##type(type&) {} \ + virtual void visit##type##Before(type&) {} \ + virtual void visit##type##After(type&) {} -# define VISIT_COMPLETE_DECL(type) \ - virtual void visit##type##Before(type&); \ - virtual void visit##type(type&); \ - virtual void visit##type##After(type&); +#define VISIT_DECL(type) \ + virtual void visit##type(type&); -#include "../system/FreestyleConfig.h" +#define VISIT_COMPLETE_DECL(type) \ + virtual void visit##type##Before(type&); \ + virtual void visit##type(type&); \ + virtual void visit##type##After(type&); class Node; class NodeShape; @@ -65,34 +70,33 @@ class FrsMaterial; class LIB_SCENE_GRAPH_EXPORT SceneVisitor { public: - - SceneVisitor() {} - virtual ~SceneVisitor() {} + SceneVisitor() {} + virtual ~SceneVisitor() {} - virtual void beginScene() {} - virtual void endScene() {} + virtual void beginScene() {} + virtual void endScene() {} - // - // visitClass methods - // - ////////////////////////////////////////////// + // + // visitClass methods + // + ////////////////////////////////////////////// - VISIT_COMPLETE_DEF(Node) - VISIT_COMPLETE_DEF(NodeShape) - VISIT_COMPLETE_DEF(NodeGroup) - VISIT_COMPLETE_DEF(NodeLight) - VISIT_COMPLETE_DEF(NodeCamera) - VISIT_COMPLETE_DEF(NodeDrawingStyle) - VISIT_COMPLETE_DEF(NodeTransform) + VISIT_COMPLETE_DEF(Node) + VISIT_COMPLETE_DEF(NodeShape) + VISIT_COMPLETE_DEF(NodeGroup) + VISIT_COMPLETE_DEF(NodeLight) + VISIT_COMPLETE_DEF(NodeCamera) + VISIT_COMPLETE_DEF(NodeDrawingStyle) + VISIT_COMPLETE_DEF(NodeTransform) - VISIT_COMPLETE_DEF(Rep) - VISIT_COMPLETE_DEF(LineRep) - VISIT_COMPLETE_DEF(OrientedLineRep) - VISIT_COMPLETE_DEF(TriangleRep) - VISIT_COMPLETE_DEF(VertexRep) - VISIT_COMPLETE_DEF(IndexedFaceSet) - VISIT_COMPLETE_DEF(DrawingStyle) - VISIT_COMPLETE_DEF(FrsMaterial) + VISIT_COMPLETE_DEF(Rep) + VISIT_COMPLETE_DEF(LineRep) + VISIT_COMPLETE_DEF(OrientedLineRep) + VISIT_COMPLETE_DEF(TriangleRep) + VISIT_COMPLETE_DEF(VertexRep) + VISIT_COMPLETE_DEF(IndexedFaceSet) + VISIT_COMPLETE_DEF(DrawingStyle) + VISIT_COMPLETE_DEF(FrsMaterial) }; -#endif // SCENEVISITOR_H +#endif // __FREESTYLE_SCENE_VISITOR_H__ diff --git a/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp b/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp index f73a8498714..01053561aae 100644 --- a/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp @@ -1,59 +1,69 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/TriangleRep.cpp + * \ingroup freestyle + * \brief Class to define the represenation of a triangle + * \author Stephane Grabli + * \date 16/12/2002 + */ #include "TriangleRep.h" void TriangleRep::ComputeBBox() { - real XMax = _vertices[0][0]; - real YMax = _vertices[0][1]; - real ZMax = _vertices[0][2]; - - real XMin = _vertices[0][0]; - real YMin = _vertices[0][1]; - real ZMin = _vertices[0][2]; - - // parse all the coordinates to find - // the XMax, YMax, ZMax - for(int i=0; i<3; ++i) - { - // X - if(_vertices[i][0] > XMax) - XMax = _vertices[i][0]; - if(_vertices[i][0] < XMin) - XMin = _vertices[i][0]; - - // Y - if(_vertices[i][1] > YMax) - YMax = _vertices[i][1]; - if(_vertices[i][1] < YMin) - YMin = _vertices[i][1]; - - // Z - if(_vertices[i][2] > ZMax) - ZMax = _vertices[i][2]; - if(_vertices[i][2] < ZMin) - ZMin = _vertices[i][2]; - - } - - setBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); + real XMax = _vertices[0][0]; + real YMax = _vertices[0][1]; + real ZMax = _vertices[0][2]; + + real XMin = _vertices[0][0]; + real YMin = _vertices[0][1]; + real ZMin = _vertices[0][2]; + + // parse all the coordinates to find the XMax, YMax, ZMax + for (int i = 0; i < 3; ++i) { + // X + if (_vertices[i][0] > XMax) + XMax = _vertices[i][0]; + if (_vertices[i][0] < XMin) + XMin = _vertices[i][0]; + + // Y + if (_vertices[i][1] > YMax) + YMax = _vertices[i][1]; + if (_vertices[i][1] < YMin) + YMin = _vertices[i][1]; + + // Z + if (_vertices[i][2] > ZMax) + ZMax = _vertices[i][2]; + if (_vertices[i][2] < ZMin) + ZMin = _vertices[i][2]; + } + + setBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); } diff --git a/source/blender/freestyle/intern/scene_graph/TriangleRep.h b/source/blender/freestyle/intern/scene_graph/TriangleRep.h index 9d986857060..c65eee72e03 100644 --- a/source/blender/freestyle/intern/scene_graph/TriangleRep.h +++ b/source/blender/freestyle/intern/scene_graph/TriangleRep.h @@ -1,34 +1,39 @@ -// -// Filename : TriangleRep.h -// Author(s) : Stephane Grabli -// Purpose : Class to define the represenation of a triangle -// Date of creation : 16/12/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef TRIANGLEREP_H -# define TRIANGLEREP_H +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_TRIANGLE_REP_H__ +#define __FREESTYLE_TRIANGLE_REP_H__ + +/** \file blender/freestyle/intern/scene_graph/TriangleRep.h + * \ingroup freestyle + * \brief Class to define the represenation of a triangle + * \author Stephane Grabli + * \date 16/12/2002 + */ //! inherits from class Rep #include "Rep.h" @@ -37,70 +42,109 @@ class LIB_SCENE_GRAPH_EXPORT TriangleRep : public Rep { public: - - /*! Line description style */ - enum TRIANGLE_STYLE{FILL, LINES}; + /*! Line description style */ + enum TRIANGLE_STYLE { + FILL, + LINES, + }; + private: - TRIANGLE_STYLE _Style; - Vec3r _vertices[3]; - Vec3r _colors[3]; + TRIANGLE_STYLE _Style; + Vec3r _vertices[3]; + Vec3r _colors[3]; + public: - inline TriangleRep() : Rep() {_Style = FILL;} - - /*! Builds a triangle from 3 vertices - * v0 - * first vertex - * v1 - * second vertex - * v2 - * third vertex - */ - inline TriangleRep(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2) - : Rep() - { - _vertices[0] = v0; - _vertices[1] = v1; - _vertices[2] = v2; - _Style = FILL; - } - inline TriangleRep( const Vec3r& v0, const Vec3r& c0, - const Vec3r& v1, const Vec3r& c1, - const Vec3r& v2, const Vec3r& c2) - : Rep() - { - _vertices[0] = v0; - _vertices[1] = v1; - _vertices[2] = v2; - _colors[0] = c0; - _colors[1] = c1; - _colors[2] = c2; - _Style = FILL; - } - - virtual ~TriangleRep() - {} - - /*! accessors */ - inline const TRIANGLE_STYLE style() const {return _Style;} - inline const Vec3r& vertex(int index) const {return _vertices[index];} - inline const Vec3r& color(int index) const {return _colors[index];} - /*! modifiers */ - inline void setStyle(const TRIANGLE_STYLE iStyle) {_Style = iStyle;} - inline void setVertex(int index, const Vec3r& iVertex) {_vertices[index] = iVertex;} - inline void setColor(int index, const Vec3r& iColor) {_colors[index] = iColor;} - inline void setVertices(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2) {_vertices[0] = v0; _vertices[1] = v1; _vertices[2] = v2;} - inline void setColors(const Vec3r& c0, const Vec3r& c1, const Vec3r& c2) {_colors[0] = c0; _colors[1] = c1; _colors[2] = c2;} - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v) { - Rep::accept(v); - v.visitTriangleRep(*this); - } - - /*! Computes the triangle bounding box.*/ - virtual void ComputeBBox(); + inline TriangleRep() : Rep() + { + _Style = FILL; + } + + /*! Builds a triangle from 3 vertices + * v0 + * first vertex + * v1 + * second vertex + * v2 + * third vertex + */ + inline TriangleRep(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2) : Rep() + { + _vertices[0] = v0; + _vertices[1] = v1; + _vertices[2] = v2; + _Style = FILL; + } + + inline TriangleRep(const Vec3r& v0, const Vec3r& c0, const Vec3r& v1, const Vec3r& c1, + const Vec3r& v2, const Vec3r& c2) + : Rep() + { + _vertices[0] = v0; + _vertices[1] = v1; + _vertices[2] = v2; + _colors[0] = c0; + _colors[1] = c1; + _colors[2] = c2; + _Style = FILL; + } + + virtual ~TriangleRep() {} + + /*! accessors */ + inline const TRIANGLE_STYLE style() const + { + return _Style; + } + + inline const Vec3r& vertex(int index) const + { + return _vertices[index]; + } + + inline const Vec3r& color(int index) const + { + return _colors[index]; + } + + /*! modifiers */ + inline void setStyle(const TRIANGLE_STYLE iStyle) + { + _Style = iStyle; + } + + inline void setVertex(int index, const Vec3r& iVertex) + { + _vertices[index] = iVertex; + } + + inline void setColor(int index, const Vec3r& iColor) + { + _colors[index] = iColor; + } + + inline void setVertices(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2) + { + _vertices[0] = v0; + _vertices[1] = v1; + _vertices[2] = v2; + } + + inline void setColors(const Vec3r& c0, const Vec3r& c1, const Vec3r& c2) + { + _colors[0] = c0; + _colors[1] = c1; + _colors[2] = c2; + } + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v) + { + Rep::accept(v); + v.visitTriangleRep(*this); + } + /*! Computes the triangle bounding box.*/ + virtual void ComputeBBox(); }; -#endif +#endif // __FREESTYLE_TRIANGLE_REP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/VertexRep.cpp b/source/blender/freestyle/intern/scene_graph/VertexRep.cpp index e4f774bfb84..75b0d4b91b3 100644 --- a/source/blender/freestyle/intern/scene_graph/VertexRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/VertexRep.cpp @@ -1,29 +1,41 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// +/** \file blender/freestyle/intern/scene_graph/VertexRep.cpp + * \ingroup freestyle + * \brief Class to define the representation of a vertex for displaying purpose. + * \author Stephane Grabli + * \date 03/04/2002 + */ #include "VertexRep.h" void VertexRep::ComputeBBox() { - - setBBox(BBox<Vec3r>(Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]), - Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]))); + setBBox(BBox<Vec3r>(Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]), + Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]))); } diff --git a/source/blender/freestyle/intern/scene_graph/VertexRep.h b/source/blender/freestyle/intern/scene_graph/VertexRep.h index 9e31b4b8ef9..7483806f1fe 100644 --- a/source/blender/freestyle/intern/scene_graph/VertexRep.h +++ b/source/blender/freestyle/intern/scene_graph/VertexRep.h @@ -1,87 +1,141 @@ -// -// Filename : VertexRep.h -// Author(s) : Stephane Grabli -// Purpose : Class to define the representation of a vertex for -// displaying purpose. -// Date of creation : 03/04/2002 -// -/////////////////////////////////////////////////////////////////////////////// - - -// -// Copyright (C) : Please refer to the COPYRIGHT file distributed -// with this source distribution. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef VERTEXREP_H -# define VERTEXREP_H +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_VERTEX_REP_H__ +#define __FREESTYLE_VERTEX_REP_H__ + +/** \file blender/freestyle/intern/scene_graph/VertexRep.h + * \ingroup freestyle + * \brief Class to define the representation of a vertex for displaying purpose. + * \author Stephane Grabli + * \date 03/04/2002 + */ #include "Rep.h" class LIB_SCENE_GRAPH_EXPORT VertexRep : public Rep { public: - - inline VertexRep() : Rep() {_vid = 0;_PointSize = 0.f;} - inline VertexRep(real x, real y, real z, int id = 0) - : Rep() - { - _coordinates[0] = x; - _coordinates[1] = y; - _coordinates[2] = z; - - _vid = id; - _PointSize = 0.f; - } - - inline ~VertexRep() {} - - /*! Accept the corresponding visitor */ - - virtual void accept(SceneVisitor& v) { - Rep::accept(v); - v.visitVertexRep(*this); - } - - /*! Computes the rep bounding box. - */ - virtual void ComputeBBox(); - - /*! accessors */ - inline const int vid() const {return _vid;} - inline const real * coordinates() const {return _coordinates;} - inline real x() const {return _coordinates[0];} - inline real y() const {return _coordinates[1];} - inline real z() const {return _coordinates[2];} - inline float pointSize() const {return _PointSize;} - - /*! modifiers */ - inline void setVid(int id) {_vid = id;} - inline void setX(real x) {_coordinates[0] = x;} - inline void setY(real y) {_coordinates[1] = y;} - inline void setZ(real z) {_coordinates[2] = z;} - inline void setCoordinates(real x, real y, real z) {_coordinates[0] = x;_coordinates[1] = y; _coordinates[2] = z;} - inline void setPointSize(float iPointSize) {_PointSize = iPointSize;} + inline VertexRep() : Rep() + { + _vid = 0; + _PointSize = 0.0f; + } + + inline VertexRep(real x, real y, real z, int id = 0) : Rep() + { + _coordinates[0] = x; + _coordinates[1] = y; + _coordinates[2] = z; + + _vid = id; + _PointSize = 0.0f; + } + + inline ~VertexRep() {} + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v) + { + Rep::accept(v); + v.visitVertexRep(*this); + } + + /*! Computes the rep bounding box. */ + virtual void ComputeBBox(); + + /*! accessors */ + inline const int vid() const + { + return _vid; + } + + inline const real * coordinates() const + { + return _coordinates; + } + + inline real x() const + { + return _coordinates[0]; + } + + inline real y() const + { + return _coordinates[1]; + } + + inline real z() const + { + return _coordinates[2]; + } + + inline float pointSize() const + { + return _PointSize; + } + + /*! modifiers */ + inline void setVid(int id) + { + _vid = id; + } + + inline void setX(real x) + { + _coordinates[0] = x; + } + + inline void setY(real y) + { + _coordinates[1] = y; + } + + inline void setZ(real z) + { + _coordinates[2] = z; + } + + inline void setCoordinates(real x, real y, real z) + { + _coordinates[0] = x; + _coordinates[1] = y; + _coordinates[2] = z; + } + + inline void setPointSize(float iPointSize) + { + _PointSize = iPointSize; + } private: - int _vid; // vertex id - real _coordinates[3]; - float _PointSize; + int _vid; // vertex id + real _coordinates[3]; + float _PointSize; }; -#endif // VERTEXREP_H +#endif // __FREESTYLE_VERTEX_REP_H__ |