VTK
vtkProperty.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkProperty.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
36 #ifndef __vtkProperty_h
37 #define __vtkProperty_h
38 
39 #include "vtkObject.h"
40 
41 // shading models
42 #define VTK_FLAT 0
43 #define VTK_GOURAUD 1
44 #define VTK_PHONG 2
45 
46 // representation models
47 #define VTK_POINTS 0
48 #define VTK_WIREFRAME 1
49 #define VTK_SURFACE 2
50 
51 class vtkActor;
52 class vtkRenderer;
53 class vtkShaderProgram;
54 class vtkTexture;
55 class vtkWindow;
56 class vtkXMLDataElement;
57 class vtkXMLMaterial;
58 
59 class vtkPropertyInternals;
60 
62 {
63 public:
64  vtkTypeMacro(vtkProperty,vtkObject);
65  void PrintSelf(ostream& os, vtkIndent indent);
66 
72  static vtkProperty *New();
73 
75  void DeepCopy(vtkProperty *p);
76 
82  virtual void Render(vtkActor *,vtkRenderer *);
83 
89  virtual void BackfaceRender(vtkActor *,vtkRenderer *) {};
90 
91  //BTX
93 
95  virtual void PostRender(vtkActor*, vtkRenderer*);
96  //ETX
98 
100 
101  vtkGetMacro(Lighting,bool);
102  vtkSetMacro(Lighting,bool);
103  vtkBooleanMacro(Lighting,bool);
105 
107 
108  vtkSetClampMacro(Interpolation,int,VTK_FLAT,VTK_PHONG);
109  vtkGetMacro(Interpolation,int);
110  void SetInterpolationToFlat() {this->SetInterpolation(VTK_FLAT);};
111  void SetInterpolationToGouraud() {this->SetInterpolation(VTK_GOURAUD);};
112  void SetInterpolationToPhong() {this->SetInterpolation(VTK_PHONG);};
113  const char *GetInterpolationAsString();
115 
117 
118  vtkSetClampMacro(Representation,int,VTK_POINTS,VTK_SURFACE);
119  vtkGetMacro(Representation,int);
120  void SetRepresentationToPoints() {this->SetRepresentation(VTK_POINTS);};
122  this->SetRepresentation(VTK_WIREFRAME);};
123  void SetRepresentationToSurface() {this->SetRepresentation(VTK_SURFACE);};
124  const char *GetRepresentationAsString();
126 
128 
131  void SetColor(double r, double g, double b);
132  void SetColor(double a[3]) { this->SetColor(a[0], a[1], a[2]); };
133  double *GetColor();
134  void GetColor(double rgb[3]);
135  void GetColor(double &r, double &g, double &b);
137 
139 
140  vtkSetClampMacro(Ambient,double,0.0,1.0);
141  vtkGetMacro(Ambient,double);
143 
145 
146  vtkSetClampMacro(Diffuse,double,0.0,1.0);
147  vtkGetMacro(Diffuse,double);
149 
151 
152  vtkSetClampMacro(Specular,double,0.0,1.0);
153  vtkGetMacro(Specular,double);
155 
157 
158  vtkSetClampMacro(SpecularPower,double,0.0,128.0);
159  vtkGetMacro(SpecularPower,double);
161 
163 
165  vtkSetClampMacro(Opacity,double,0.0,1.0);
166  vtkGetMacro(Opacity,double);
168 
170 
174  vtkSetVector3Macro(AmbientColor,double);
175  vtkGetVector3Macro(AmbientColor,double);
177 
179 
180  vtkSetVector3Macro(DiffuseColor,double);
181  vtkGetVector3Macro(DiffuseColor,double);
183 
185 
186  vtkSetVector3Macro(SpecularColor,double);
187  vtkGetVector3Macro(SpecularColor,double);
189 
191 
194  vtkGetMacro(EdgeVisibility,int);
195  vtkSetMacro(EdgeVisibility,int);
196  vtkBooleanMacro(EdgeVisibility,int);
198 
200 
201  vtkSetVector3Macro(EdgeColor,double);
202  vtkGetVector3Macro(EdgeColor,double);
204 
206 
208  vtkSetClampMacro(LineWidth,float,0,VTK_LARGE_FLOAT);
209  vtkGetMacro(LineWidth,float);
211 
213 
216  vtkSetMacro(LineStipplePattern,int);
217  vtkGetMacro(LineStipplePattern,int);
219 
221 
224  vtkSetClampMacro(LineStippleRepeatFactor,int,1,VTK_LARGE_INTEGER);
225  vtkGetMacro(LineStippleRepeatFactor,int);
227 
229 
231  vtkSetClampMacro(PointSize,float,0,VTK_LARGE_FLOAT);
232  vtkGetMacro(PointSize,float);
234 
236 
239  vtkGetMacro(BackfaceCulling,int);
240  vtkSetMacro(BackfaceCulling,int);
241  vtkBooleanMacro(BackfaceCulling,int);
243 
245 
248  vtkGetMacro(FrontfaceCulling,int);
249  vtkSetMacro(FrontfaceCulling,int);
250  vtkBooleanMacro(FrontfaceCulling,int);
252 
254 
256  vtkGetObjectMacro(Material, vtkXMLMaterial);
258 
260 
261  vtkGetStringMacro(MaterialName);
263 
266  void LoadMaterial(const char* name);
267 
269  void LoadMaterialFromString(const char* materialxml);
270 
272  void LoadMaterial(vtkXMLMaterial*);
273 
275 
277  vtkSetMacro(Shading, int);
278  vtkGetMacro(Shading, int);
279  vtkBooleanMacro(Shading, int);
281 
283 
285  vtkGetObjectMacro(ShaderProgram, vtkShaderProgram);
287 
289 
293  virtual void AddShaderVariable(const char *name, int numVars, int *x);
294  virtual void AddShaderVariable(const char *name, int numVars, float *x);
295  virtual void AddShaderVariable(const char *name, int numVars, double *x);
297 
299 
300  void AddShaderVariable(const char* name, int v)
301  {
302  this->AddShaderVariable(name, 1, &v);
303  }
304  void AddShaderVariable(const char* name, float v)
305  {
306  this->AddShaderVariable(name, 1, &v);
307  }
308  void AddShaderVariable(const char* name, double v)
309  {
310  this->AddShaderVariable(name, 1, &v);
311  }
312  void AddShaderVariable(const char* name, int v1, int v2)
313  {
314  int v[2];
315  v[0] = v1;
316  v[1] = v2;
317  this->AddShaderVariable(name, 2, v);
318  }
319  void AddShaderVariable(const char* name, float v1, float v2)
320  {
321  float v[2];
322  v[0] = v1;
323  v[1] = v2;
324  this->AddShaderVariable(name, 2, v);
325  }
326  void AddShaderVariable(const char* name, double v1, double v2)
327  {
328  double v[2];
329  v[0] = v1;
330  v[1] = v2;
331  this->AddShaderVariable(name, 2, v);
332  }
333  void AddShaderVariable(const char* name, int v1, int v2, int v3)
334  {
335  int v[3];
336  v[0] = v1;
337  v[1] = v2;
338  v[2] = v3;
339  this->AddShaderVariable(name, 3, v);
340  }
341  void AddShaderVariable(const char* name, float v1, float v2, float v3)
342  {
343  float v[3];
344  v[0] = v1;
345  v[1] = v2;
346  v[2] = v3;
347  this->AddShaderVariable(name, 3, v);
348  }
349  void AddShaderVariable(const char* name, double v1, double v2, double v3)
350  {
351  double v[3];
352  v[0] = v1;
353  v[1] = v2;
354  v[2] = v3;
355  this->AddShaderVariable(name, 3, v);
356  }
358 
360 
364  void SetTexture(const char* name, vtkTexture* texture);
365  vtkTexture* GetTexture(const char* name);
367 
369 
373  void SetTexture(int unit, vtkTexture* texture);
374  vtkTexture* GetTexture(int unit);
375  void RemoveTexture(int unit);
377 
378 
381  void RemoveTexture(const char* name);
382 
384  void RemoveAllTextures();
385 
387  int GetNumberOfTextures();
388 
392  virtual void ReleaseGraphicsResources(vtkWindow *win);
393 
394 //BTX
396 
399  {
400  VTK_TEXTURE_UNIT_0 = 0,
407  VTK_TEXTURE_UNIT_7
408  };
409 //ETX
411 
412 protected:
413  vtkProperty();
414  ~vtkProperty();
415 
417 
418  void LoadProperty();
419  void LoadTextures();
420  void LoadTexture(vtkXMLDataElement* elem);
421  void LoadPerlineNoise(vtkXMLDataElement* );
422  void LoadMember(vtkXMLDataElement* elem);
424 
425  double Color[3];
426  double AmbientColor[3];
427  double DiffuseColor[3];
428  double SpecularColor[3];
429  double EdgeColor[3];
430  double Ambient;
431  double Diffuse;
432  double Specular;
434  double Opacity;
435  float PointSize;
436  float LineWidth;
444  bool Lighting;
445 
446  int Shading;
447 
449  vtkSetStringMacro(MaterialName);
450 
452  void SetShaderProgram(vtkShaderProgram*);
453 
454  vtkXMLMaterial* Material; // TODO: I wonder if this reference needs to be maintained.
455 
458  virtual void ReadFrameworkMaterial();
459 
460 //BTX
461  // These friends are provided only for the time being
462  // till we device a graceful way of loading texturing for GLSL.
463  friend class vtkGLSLShaderProgram;
464  friend class vtkShader;
465  // FIXME:
466  // Don't use these methods. They will be removed. They are provided only
467  // for the time-being.
468  vtkTexture* GetTextureAtIndex(int index);
469  int GetTextureUnitAtIndex(int index);
470  int GetTextureUnit(const char* name);
471 //ETX
472 
473 private:
474  vtkProperty(const vtkProperty&); // Not implemented.
475  void operator=(const vtkProperty&); // Not implemented.
476 
477  vtkPropertyInternals* Internals;
478 };
479 
481 
483 {
484  if ( this->Interpolation == VTK_FLAT )
485  {
486  return "Flat";
487  }
488  else if ( this->Interpolation == VTK_GOURAUD )
489  {
490  return "Gouraud";
491  }
492  else
493  {
494  return "Phong";
495  }
496 }
498 
499 
501 
503 {
504  if ( this->Representation == VTK_POINTS )
505  {
506  return "Points";
507  }
508  else if ( this->Representation == VTK_WIREFRAME )
509  {
510  return "Wireframe";
511  }
512  else
513  {
514  return "Surface";
515  }
516 }
518 
519 
520 
521 #endif
void AddShaderVariable(const char *name, float v1, float v2, float v3)
Definition: vtkProperty.h:341
double Opacity
Definition: vtkProperty.h:434
GLSL Shader Program.
encapsulates a VTK Material description.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:49
void SetInterpolationToPhong()
Definition: vtkProperty.h:112
abstract base class for most VTK objects
Definition: vtkObject.h:60
float PointSize
Definition: vtkProperty.h:435
void AddShaderVariable(const char *name, double v)
Definition: vtkProperty.h:308
Represents an XML element and those nested inside.
int LineStipplePattern
Definition: vtkProperty.h:437
float LineWidth
Definition: vtkProperty.h:436
void AddShaderVariable(const char *name, double v1, double v2, double v3)
Definition: vtkProperty.h:349
represent surface properties of a geometric object
Definition: vtkProperty.h:61
const char * GetRepresentationAsString()
Definition: vtkProperty.h:502
#define VTK_SURFACE
Definition: vtkProperty.h:49
void SetInterpolationToFlat()
Definition: vtkProperty.h:110
void AddShaderVariable(const char *name, int v1, int v2, int v3)
Definition: vtkProperty.h:333
double Ambient
Definition: vtkProperty.h:430
double SpecularPower
Definition: vtkProperty.h:433
char * MaterialName
Definition: vtkProperty.h:448
int FrontfaceCulling
Definition: vtkProperty.h:443
void AddShaderVariable(const char *name, float v)
Definition: vtkProperty.h:304
abstract specification for renderers
Definition: vtkRenderer.h:69
void AddShaderVariable(const char *name, double v1, double v2)
Definition: vtkProperty.h:326
void SetRepresentationToPoints()
Definition: vtkProperty.h:120
void SetInterpolationToGouraud()
Definition: vtkProperty.h:111
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
double Diffuse
Definition: vtkProperty.h:431
int EdgeVisibility
Definition: vtkProperty.h:441
void AddShaderVariable(const char *name, float v1, float v2)
Definition: vtkProperty.h:319
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
void SetColor(double a[3])
Definition: vtkProperty.h:132
int BackfaceCulling
Definition: vtkProperty.h:442
#define VTK_FLAT
Definition: vtkProperty.h:42
vtkXMLMaterial * Material
Definition: vtkProperty.h:454
void SetRepresentationToWireframe()
Definition: vtkProperty.h:121
int Interpolation
Definition: vtkProperty.h:439
handles properties associated with a texture map
Definition: vtkTexture.h:68
int Representation
Definition: vtkProperty.h:440
vtkShaderProgram * ShaderProgram
Definition: vtkProperty.h:449
void SetRepresentationToSurface()
Definition: vtkProperty.h:123
#define VTK_POINTS
Definition: vtkProperty.h:47
void AddShaderVariable(const char *name, int v)
Definition: vtkProperty.h:300
#define VTK_GOURAUD
Definition: vtkProperty.h:43
#define VTK_RENDERING_EXPORT
#define VTK_PHONG
Definition: vtkProperty.h:44
virtual void BackfaceRender(vtkActor *, vtkRenderer *)
Definition: vtkProperty.h:89
int LineStippleRepeatFactor
Definition: vtkProperty.h:438
#define VTK_LARGE_FLOAT
Definition: vtkType.h:149
const char * GetInterpolationAsString()
Definition: vtkProperty.h:482
void AddShaderVariable(const char *name, int v1, int v2)
Definition: vtkProperty.h:312
#define VTK_LARGE_INTEGER
Definition: vtkType.h:148
static vtkObject * New()
double Specular
Definition: vtkProperty.h:432
vtkShaderInternals * Internals
Definition: vtkShader.h:138
#define VTK_WIREFRAME
Definition: vtkProperty.h:48