OpenCMISS-Zinc C++ API Documentation
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 "opencmiss/zinc/material.h"
13 #include "opencmiss/zinc/context.hpp"
14 #include "opencmiss/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 
268 inline bool operator==(const Material& a, const Material& b)
269 {
270  return a.getId() == b.getId();
271 }
272 
279 {
280 private:
281 
282  cmzn_materialiterator_id id;
283 
284 public:
285 
286  Materialiterator() : id(0)
287  { }
288 
289  // takes ownership of C handle, responsibility for destroying it
290  explicit Materialiterator(cmzn_materialiterator_id iterator_id) :
291  id(iterator_id)
292  { }
293 
294  Materialiterator(const Materialiterator& materialiterator) :
295  id(cmzn_materialiterator_access(materialiterator.id))
296  { }
297 
298  Materialiterator& operator=(const Materialiterator& materialiterator)
299  {
300  cmzn_materialiterator_id temp_id = cmzn_materialiterator_access(materialiterator.id);
301  if (0 != id)
302  {
303  cmzn_materialiterator_destroy(&id);
304  }
305  id = temp_id;
306  return *this;
307  }
308 
310  {
311  if (0 != id)
312  {
313  cmzn_materialiterator_destroy(&id);
314  }
315  }
316 
322  bool isValid() const
323  {
324  return (0 != id);
325  }
326 
335  {
336  return Material(cmzn_materialiterator_next(id));
337  }
338 };
339 
351 {
352 protected:
353  cmzn_materialmodule_id id;
354 
355 public:
356 
357  Materialmodule() : id(0)
358  { }
359 
360  // takes ownership of C handle, responsibility for destroying it
361  explicit Materialmodule(cmzn_materialmodule_id in_materialmodule_id) :
362  id(in_materialmodule_id)
363  { }
364 
365  Materialmodule(const Materialmodule& materialModule) :
366  id(cmzn_materialmodule_access(materialModule.id))
367  { }
368 
369  Materialmodule& operator=(const Materialmodule& materialModule)
370  {
371  cmzn_materialmodule_id temp_id = cmzn_materialmodule_access(
372  materialModule.id);
373  if (0 != id)
374  {
375  cmzn_materialmodule_destroy(&id);
376  }
377  id = temp_id;
378  return *this;
379  }
380 
381  ~Materialmodule()
382  {
383  if (0 != id)
384  {
385  cmzn_materialmodule_destroy(&id);
386  }
387  }
388 
394  bool isValid() const
395  {
396  return (0 != id);
397  }
398 
404  cmzn_materialmodule_id getId() const
405  {
406  return id;
407  }
408 
416  {
417  return Material(cmzn_materialmodule_create_material(id));
418  }
419 
433  {
434  return Materialiterator(cmzn_materialmodule_create_materialiterator(id));
435  }
436 
443  Material findMaterialByName(const char *name)
444  {
445  return Material(cmzn_materialmodule_find_material_by_name(id, name));
446  }
447 
458  {
459  return cmzn_materialmodule_begin_change(id);
460  }
461 
471  int endChange()
472  {
473  return cmzn_materialmodule_end_change(id);
474  }
475 
484  {
485  return cmzn_materialmodule_define_standard_materials(id);
486  }
487 
495  {
496  return Material(cmzn_materialmodule_get_default_material(id));
497  }
498 
508  int setDefaultMaterial(const Material& material)
509  {
510  return cmzn_materialmodule_set_default_material(id, material.getId());
511  }
512 
520  {
521  return Material(cmzn_materialmodule_get_default_selected_material(id));
522  }
523 
531  {
532  return cmzn_materialmodule_set_default_selected_material(id, material.getId());
533  }
534 
542  {
543  return Material(cmzn_materialmodule_get_default_surface_material(id));
544  }
545 
554  int setDefaultSurfaceMaterial(const Material& material)
555  {
556  return cmzn_materialmodule_set_default_surface_material(id, material.getId());
557  }
558 };
559 
561 {
562  return Materialmodule(cmzn_context_get_materialmodule(id));
563 }
564 
565 }
566 }
567 #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:471
int beginChange()
Definition: material.hpp:457
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:51
Material getDefaultSurfaceMaterial()
Definition: material.hpp:541
bool isValid() const
Definition: material.hpp:73
Materialmodule getMaterialmodule()
Definition: material.hpp:560
Attribute
Definition: material.hpp:92
Material createMaterial()
Definition: material.hpp:415
cmzn_material_id getId() const
Definition: material.hpp:83
char * getName()
Definition: material.hpp:222
int setDefaultSurfaceMaterial(const Material &material)
Definition: material.hpp:554
int setDefaultMaterial(const Material &material)
Definition: material.hpp:508
int setDefaultSelectedMaterial(const Material &material)
Definition: material.hpp:530
Material next()
Definition: material.hpp:334
An iterator for looping through all the materials in a materialmodule.
Definition: material.hpp:278
cmzn_materialmodule_id getId() const
Definition: material.hpp:404
cmzn_field_id getId() const
Definition: field.hpp:103
bool isValid() const
Definition: material.hpp:394
int defineStandardMaterials()
Definition: material.hpp:483
Material getDefaultMaterial()
Definition: material.hpp:494
Zinc materials specify colouring of graphics.
Definition: material.hpp:29
int setManaged(bool value)
Definition: material.hpp:158
Materialiterator createMaterialiterator()
Definition: material.hpp:432
bool isValid() const
Definition: material.hpp:322
Module managing all materials.
Definition: material.hpp:350
bool isManaged()
Definition: material.hpp:141
Material findMaterialByName(const char *name)
Definition: material.hpp:443
Material getDefaultSelectedMaterial()
Definition: material.hpp:519
int setAttributeReal(Attribute attribute, double value)
Definition: material.hpp:183
The OpenCMISS namespace.
Definition: context.hpp:20
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