Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Material.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #ifndef MATERIAL_HH_INCLUDED
51 #define MATERIAL_HH_INCLUDED
52
53 #ifndef DOXY_IGNORE_THIS
54
55 #include <iomanip>
56 #include <map>
57 #include <string>
58
64 class Material
65 {
66 public:
67
68 Material() :
69 localNum_(0),
70 Kd_is_set_(false),
71 Ka_is_set_(false),
72 Ks_is_set_(false),
73 Tr_(0.0),
74 Tr_is_set_(false),
75 map_Kd_(""),
76 index_Kd_(0),
77 map_Kd_is_set_(false)
78 {
79 }
80
81
82
83 void cleanup() {
84 localNum_ = 0;
85 Kd_is_set_ = false;
86 Ka_is_set_ = false;
87 Ks_is_set_ = false;
88 Tr_ = 0.0;
89 Tr_is_set_ = false;
90 map_Kd_ = "";
91 index_Kd_ = 0;
92 map_Kd_is_set_ = false;
93 }
94
95 bool is_valid(void) const
96 { return Kd_is_set_ || Ka_is_set_ || Ks_is_set_ || Tr_is_set_; }
97
99 bool has_Kd(void) { return Kd_is_set_; }
100
102 bool has_Ka(void) { return Ka_is_set_; }
103
105 bool has_Ks(void) { return Ks_is_set_; }
106
108 bool has_Tr(void) { return Tr_is_set_; }
109
111 bool has_Texture() const { return map_Kd_is_set_; }
112
114 bool operator== (Material& _mat) {
115 if( _mat.Kd_ != Kd_ ||
116 _mat.Ka_ != Ka_ ||
117 _mat.Ks_ != Ks_ ||
118 _mat.Tr_ != Tr_ ||
119 _mat.map_Kd_ != map_Kd_ ||
120 _mat.index_Kd_ != index_Kd_ )
121 return false;
122 return true;
123 }
124
126 bool operator!= (Material& _mat) { return !(*this == _mat); }
127
129 int material_number() const { return localNum_; }
130 void material_number(unsigned int _n) { localNum_ = _n; }
131
133 void set_Kd( float r, float g, float b )
134 { Kd_=OpenMesh::Vec3f(r,g,b); Kd_is_set_=true; }
135
137 void set_Ka( float r, float g, float b )
138 { Ka_=OpenMesh::Vec3f(r,g,b); Ka_is_set_=true; }
139
141 void set_Ks( float r, float g, float b )
142 { Ks_=OpenMesh::Vec3f(r,g,b); Ks_is_set_=true; }
143
145 void set_Tr( float t )
146 { Tr_=t; Tr_is_set_=true; }
147
149 void set_map_Kd( std::string _name, int _index_Kd )
150 { map_Kd_ = _name, index_Kd_ = _index_Kd; map_Kd_is_set_ = true; };
151
153 const OpenMesh::Vec3f& Kd( void ) const { return Kd_; }
154
156 const OpenMesh::Vec3f& Ka( void ) const { return Ka_; }
157
159 const OpenMesh::Vec3f& Ks( void ) const { return Ks_; }
160
162 float Tr( void ) const { return Tr_; }
163
165 const std::string& map_Kd( void ) { return map_Kd_ ; }
166
168 const int& map_Kd_index( void ) { return index_Kd_ ; }
169
170 private:
171
172 unsigned int localNum_;
173 OpenMesh::Vec3f Kd_; bool Kd_is_set_; // diffuse
174 OpenMesh::Vec3f Ka_; bool Ka_is_set_; // ambient
175 OpenMesh::Vec3f Ks_; bool Ks_is_set_; // specular
176 float Tr_; bool Tr_is_set_; // transperency
177
178 std::string map_Kd_; int index_Kd_; bool map_Kd_is_set_; // Texture
179 };
180
181 inline std::ostream&
182 operator<< (std::ostream& _os, const Material& _mat) {
183 _os << "mat" << std::setfill('0') << std::setw(3) << _mat.material_number();
184
185 return _os;
186 }
187
188 typedef std::map<std::string, Material> MaterialList;
189
190 #endif
191
192 #endif // MATERIAL_HH_INCLUDED
OpenMesh::Utils::Timer::operator<<
std::ostream & operator<<(std::ostream &_o, const Timer &_t)
Definition: Timer.hh:201
OpenMesh::VectorT< float, 3 >
OpenMesh::Vec3f
VectorT< float, 3 > Vec3f
Definition: Vector11T.hh:769