OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
material.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef CMZN_MATERIAL_HPP__
10 #define CMZN_MATERIAL_HPP__
11 
12 #include "zinc/material.h"
13 #include "zinc/context.hpp"
14 #include "zinc/field.hpp"
15 
16 namespace OpenCMISS
17 {
18 namespace Zinc
19 {
20 
29 class Material
30 {
31 
32 protected:
33  cmzn_material_id id;
34 
35 public:
36 
37  Material() : id(0)
38  { }
39 
40  // takes ownership of C handle, responsibility for destroying it
41  explicit Material(cmzn_material_id material_id) :
42  id(material_id)
43  { }
44 
45  Material(const Material& material) :
46  id(cmzn_material_access(material.id))
47  { }
48 
49  Material& operator=(const Material& material)
50  {
51  cmzn_material_id temp_id = cmzn_material_access(material.id);
52  if (0 != id)
53  {
54  cmzn_material_destroy(&id);
55  }
56  id = temp_id;
57  return *this;
58  }
59 
60  ~Material()
61  {
62  if (0 != id)
63  {
64  cmzn_material_destroy(&id);
65  }
66  }
67 
73  bool isValid() const
74  {
75  return (0 != id);
76  }
77 
83  cmzn_material_id getId() const
84  {
85  return id;
86  }
87 
92  enum Attribute
93  {
94  ATTRIBUTE_INVALID = CMZN_MATERIAL_ATTRIBUTE_INVALID,
96  ATTRIBUTE_ALPHA = CMZN_MATERIAL_ATTRIBUTE_ALPHA,
102  ATTRIBUTE_AMBIENT = CMZN_MATERIAL_ATTRIBUTE_AMBIENT,
108  ATTRIBUTE_DIFFUSE = CMZN_MATERIAL_ATTRIBUTE_DIFFUSE,
115  ATTRIBUTE_EMISSION = CMZN_MATERIAL_ATTRIBUTE_EMISSION,
121  ATTRIBUTE_SHININESS = CMZN_MATERIAL_ATTRIBUTE_SHININESS,
126  ATTRIBUTE_SPECULAR = CMZN_MATERIAL_ATTRIBUTE_SPECULAR
133  };
134 
141  bool isManaged()
142  {
143  return cmzn_material_is_managed(id);
144  }
145 
158  int setManaged(bool value)
159  {
160  return cmzn_material_set_managed(id, value);
161  }
162 
169  double getAttributeReal(Attribute attribute)
170  {
171  return cmzn_material_get_attribute_real(id,
172  static_cast<cmzn_material_attribute>(attribute));
173  }
174 
183  int setAttributeReal(Attribute attribute, double value)
184  {
185  return cmzn_material_set_attribute_real(id,
186  static_cast<cmzn_material_attribute>(attribute), value);
187  }
188 
196  int getAttributeReal3(Attribute attribute, double *valuesOut3)
197  {
198  return cmzn_material_get_attribute_real3(id,
199  static_cast<cmzn_material_attribute>(attribute), valuesOut3);
200  }
201 
210  int setAttributeReal3(Attribute attribute, const double *valuesIn3)
211  {
212  return cmzn_material_set_attribute_real3(id,
213  static_cast<cmzn_material_attribute>(attribute), valuesIn3);
214  }
215 
222  char *getName()
223  {
224  return cmzn_material_get_name(id);
225  }
226 
234  int setName(const char *name)
235  {
236  return cmzn_material_set_name(id, name);
237  }
238 
245  Field getTextureField(int textureNumber)
246  {
247  return Field(cmzn_material_get_texture_field(id, textureNumber));
248  }
249 
261  int setTextureField(int textureNumber, const Field& textureField)
262  {
263  return cmzn_material_set_texture_field(id, textureNumber, textureField.getId());
264  }
265 
266 };
267 
279 {
280 protected:
281  cmzn_materialmodule_id id;
282 
283 public:
284 
285  Materialmodule() : id(0)
286  { }
287 
288  // takes ownership of C handle, responsibility for destroying it
289  explicit Materialmodule(cmzn_materialmodule_id in_materialmodule_id) :
290  id(in_materialmodule_id)
291  { }
292 
293  Materialmodule(const Materialmodule& materialModule) :
294  id(cmzn_materialmodule_access(materialModule.id))
295  { }
296 
297  Materialmodule& operator=(const Materialmodule& materialModule)
298  {
299  cmzn_materialmodule_id temp_id = cmzn_materialmodule_access(
300  materialModule.id);
301  if (0 != id)
302  {
303  cmzn_materialmodule_destroy(&id);
304  }
305  id = temp_id;
306  return *this;
307  }
308 
309  ~Materialmodule()
310  {
311  if (0 != id)
312  {
313  cmzn_materialmodule_destroy(&id);
314  }
315  }
316 
322  bool isValid() const
323  {
324  return (0 != id);
325  }
326 
332  cmzn_materialmodule_id getId() const
333  {
334  return id;
335  }
336 
344  {
345  return Material(cmzn_materialmodule_create_material(id));
346  }
347 
354  Material findMaterialByName(const char *name)
355  {
356  return Material(cmzn_materialmodule_find_material_by_name(id, name));
357  }
358 
369  {
370  return cmzn_materialmodule_begin_change(id);
371  }
372 
382  int endChange()
383  {
384  return cmzn_materialmodule_end_change(id);
385  }
386 
395  {
396  return cmzn_materialmodule_define_standard_materials(id);
397  }
398 
405  {
406  return Material(cmzn_materialmodule_get_default_material(id));
407  }
408 
416  int setDefaultMaterial(const Material& material)
417  {
418  return cmzn_materialmodule_set_default_material(id, material.getId());
419  }
420 
428  {
429  return Material(cmzn_materialmodule_get_default_selected_material(id));
430  }
431 
439  {
440  return cmzn_materialmodule_set_default_selected_material(id, material.getId());
441  }
442 };
443 
445 {
446  return Materialmodule(cmzn_context_get_materialmodule(id));
447 }
448 
449 } // namespace cmzn
450 }
451 #endif
int setTextureField(int textureNumber, const Field &textureField)
Definition: material.hpp:261
int getAttributeReal3(Attribute attribute, double *valuesOut3)
Definition: material.hpp:196
int endChange()
Definition: material.hpp:382
int beginChange()
Definition: material.hpp:368
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
bool isValid() const
Definition: material.hpp:73
Materialmodule getMaterialmodule()
Definition: material.hpp:444
Attribute
Definition: material.hpp:92
Material createMaterial()
Definition: material.hpp:343
cmzn_material_id getId() const
Definition: material.hpp:83
char * getName()
Definition: material.hpp:222
int setDefaultMaterial(const Material &material)
Definition: material.hpp:416
int setDefaultSelectedMaterial(const Material &material)
Definition: material.hpp:438
cmzn_materialmodule_id getId() const
Definition: material.hpp:332
cmzn_field_id getId() const
Definition: field.hpp:98
bool isValid() const
Definition: material.hpp:322
int defineStandardMaterials()
Definition: material.hpp:394
Material getDefaultMaterial()
Definition: material.hpp:404
Zinc materials specify colouring of graphics.
Definition: material.hpp:29
int setManaged(bool value)
Definition: material.hpp:158
Module managing all materials.
Definition: material.hpp:278
bool isManaged()
Definition: material.hpp:141
Material findMaterialByName(const char *name)
Definition: material.hpp:354
Material getDefaultSelectedMaterial()
Definition: material.hpp:427
int setAttributeReal(Attribute attribute, double value)
Definition: material.hpp:183
int setAttributeReal3(Attribute attribute, const double *valuesIn3)
Definition: material.hpp:210
int setName(const char *name)
Definition: material.hpp:234
Field getTextureField(int textureNumber)
Definition: material.hpp:245
double getAttributeReal(Attribute attribute)
Definition: material.hpp:169