fw4spl
src/fwData/Material.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <fwCom/Signal.hpp>
8 #include <fwCom/Signal.hxx>
9 
10 #include "fwData/registry/macros.hpp"
11 #include "fwData/Exception.hpp"
12 #include "fwData/Material.hpp"
13 
14 fwDataRegisterMacro( ::fwData::Material );
15 
16 namespace fwData
17 {
18 
19 //------------------------------------------------------------------------------
20 
21 const ::fwCom::Signals::SignalKeyType Material::s_ADDED_TEXTURE_SIG = "addedTexture";
22 const ::fwCom::Signals::SignalKeyType Material::s_REMOVED_TEXTURE_SIG = "removedTexture";
23 
24 //------------------------------------------------------------------------------
25 
27  m_shadingMode(PHONG),
28  m_representationMode(SURFACE),
29  m_optionsMode(STANDARD),
30  m_ambient( Color::New(0.05f, 0.05f, 0.05f, 1.f) ),
31  m_diffuse( Color::New() ),
32  m_diffuseTextureFiltering(NEAREST),
33  m_diffuseTextureWrapping(REPEAT)
34 {
35  newSignal< AddedTextureSignalType >(s_ADDED_TEXTURE_SIG);
36  newSignal< RemovedTextureSignalType >(s_REMOVED_TEXTURE_SIG);
37 }
38 
39 //------------------------------------------------------------------------------
40 
42 {
43 }
44 
45 //------------------------------------------------------------------------------
46 
47 void Material::shallowCopy(const Object::csptr &_source )
48 {
49  Material::csptr other = Material::dynamicConstCast(_source);
50  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
51  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
52  + " to " + this->getClassname()), !bool(other) );
53  this->fieldShallowCopy( _source );
54 
55  m_ambient = other->m_ambient;
56  m_diffuse = other->m_diffuse;
57  m_diffuseTexture = other->m_diffuseTexture;
58 
59  m_shadingMode = other->m_shadingMode;
60  m_representationMode = other->m_representationMode;
61  m_optionsMode = other->m_optionsMode;
62  m_diffuseTextureFiltering = other->m_diffuseTextureFiltering;
63  m_diffuseTextureWrapping = other->m_diffuseTextureWrapping;
64 }
65 
66 //------------------------------------------------------------------------------
67 
68 void Material::cachedDeepCopy(const Object::csptr &_source, DeepCopyCacheType &cache)
69 {
70  Material::csptr other = Material::dynamicConstCast(_source);
71  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
72  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
73  + " to " + this->getClassname()), !bool(other) );
74  this->fieldDeepCopy( _source, cache );
75 
76  m_ambient = ::fwData::Object::copy( other->m_ambient, cache );
77  m_diffuse = ::fwData::Object::copy( other->m_diffuse, cache );
78  m_diffuseTexture = ::fwData::Object::copy( other->m_diffuseTexture, cache );
79 
80  m_shadingMode = other->m_shadingMode;
81  m_representationMode = other->m_representationMode;
82  m_optionsMode = other->m_optionsMode;
83  m_diffuseTextureFiltering = other->m_diffuseTextureFiltering;
84  m_diffuseTextureWrapping = other->m_diffuseTextureWrapping;
85 }
86 
87 //------------------------------------------------------------------------------
88 
89 Color::sptr Material::ambient() const
90 {
91  return m_ambient;
92 }
93 
94 //------------------------------------------------------------------------------
95 
96 Color::sptr Material::diffuse() const
97 {
98  return m_diffuse;
99 }
100 
101 //------------------------------------------------------------------------------
102 
103 Image::sptr Material::getDiffuseTexture() const
104 {
105  return m_diffuseTexture;
106 }
107 
108 //------------------------------------------------------------------------------
109 
110 void Material::setAmbient(const Color::sptr& ambient)
111 {
112  m_ambient = ambient;
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 void Material::setDiffuse(const Color::sptr& diffuse)
118 {
119  m_diffuse = diffuse;
120 }
121 
122 //------------------------------------------------------------------------------
123 
124 void Material::setDiffuseTexture(const Image::sptr& diffuseTexture)
125 {
126  m_diffuseTexture = diffuseTexture;
127 }
128 
129 //------------------------------------------------------------------------------
130 
131 } //namespace fwData
FWDATA_API Material(::fwData::Object::Key key)
Constructor.
ShadingType m_shadingMode
Shading mode (flat, Gouraud, Phong)
This class defines a material. A material is represented by an ambient color and a diffuse color...
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
Implements data exception class.
Color::sptr m_ambient
Ambient color.
virtual FWDATA_API ~Material()
Destructor.
This class defines color object.
FWDATA_API Color::sptr diffuse() const
returns editable diffuse color
FWDATA_API void fieldDeepCopy(const ::fwData::Object::csptr &source)
A deep copy of fields (objects in m_children)
FWDATA_API void setDiffuseTexture(const Image::sptr &diffuseTexture)
Setter for diffuse texture.
OptionsType m_optionsMode
Options mode (display normals or not)
Color::sptr m_diffuse
Diffuse color.
FilteringType m_diffuseTextureFiltering
Filtering for diffuse texture.
Image::sptr m_diffuseTexture
Diffuse texture.
RepresentationType m_representationMode
Fill mode (flat, wireframe, point)
static FWDATA_API::fwData::Object::sptr copy(const ::fwData::Object::csptr &source)
return a copy of the source. if source is a null pointer, return a null pointer.
virtual const std::string & getClassname() const override
return full object&#39;s classname with its namespace, i.e. fwCore::BaseObject
FWDATA_API void setAmbient(const Color::sptr &ambient)
Setter for ambient color.
WrappingType m_diffuseTextureWrapping
Wrapping for diffuse texture.
FWDATA_API Image::sptr getDiffuseTexture() const
returns editable diffuse texture
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_TEXTURE_SIG
Type of signal when a texture is added.
FWDATA_API void shallowCopy(const Object::csptr &_source) override
Defines shallow copy.
Contains the representation of the data objects used in the framework.
FWDATA_API void fieldShallowCopy(const ::fwData::Object::csptr &source)
A shallow copy of fields (objects in m_children)
FWDATA_API Color::sptr ambient() const
returns editable ambient color
FWDATA_API void cachedDeepCopy(const Object::csptr &_source, DeepCopyCacheType &cache) override
Defines deep copy.
FWDATA_API void setDiffuse(const Color::sptr &diffuse)
Setter for diffuse color.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_TEXTURE_SIG
Type of signal when a texture is added.