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;
55 class vtkTexture;
56 class vtkWindow;
57 class vtkXMLDataElement;
58 class vtkXMLMaterial;
59 
60 class vtkPropertyInternals;
61 
63 {
64 public:
65  vtkTypeMacro(vtkProperty,vtkObject);
66  void PrintSelf(ostream& os, vtkIndent indent);
67 
73  static vtkProperty *New();
74 
76  void DeepCopy(vtkProperty *p);
77 
83  virtual void Render(vtkActor *,vtkRenderer *);
84 
90  virtual void BackfaceRender(vtkActor *,vtkRenderer *) {};
91 
92  //BTX
94 
96  virtual void PostRender(vtkActor*, vtkRenderer*);
97  //ETX
99 
101 
102  vtkGetMacro(Lighting,bool);
103  vtkSetMacro(Lighting,bool);
104  vtkBooleanMacro(Lighting,bool);
106 
108 
109  vtkSetClampMacro(Interpolation,int,VTK_FLAT,VTK_PHONG);
110  vtkGetMacro(Interpolation,int);
111  void SetInterpolationToFlat() {this->SetInterpolation(VTK_FLAT);};
112  void SetInterpolationToGouraud() {this->SetInterpolation(VTK_GOURAUD);};
113  void SetInterpolationToPhong() {this->SetInterpolation(VTK_PHONG);};
114  const char *GetInterpolationAsString();
116 
118 
119  vtkSetClampMacro(Representation,int,VTK_POINTS,VTK_SURFACE);
120  vtkGetMacro(Representation,int);
121  void SetRepresentationToPoints() {this->SetRepresentation(VTK_POINTS);};
123  this->SetRepresentation(VTK_WIREFRAME);};
124  void SetRepresentationToSurface() {this->SetRepresentation(VTK_SURFACE);};
125  const char *GetRepresentationAsString();
127 
129 
132  void SetColor(double r, double g, double b);
133  void SetColor(double a[3]) { this->SetColor(a[0], a[1], a[2]); };
134  double *GetColor();
135  void GetColor(double rgb[3]);
136  void GetColor(double &r, double &g, double &b);
138 
140 
141  vtkSetClampMacro(Ambient,double,0.0,1.0);
142  vtkGetMacro(Ambient,double);
144 
146 
147  vtkSetClampMacro(Diffuse,double,0.0,1.0);
148  vtkGetMacro(Diffuse,double);
150 
152 
153  vtkSetClampMacro(Specular,double,0.0,1.0);
154  vtkGetMacro(Specular,double);
156 
158 
159  vtkSetClampMacro(SpecularPower,double,0.0,128.0);
160  vtkGetMacro(SpecularPower,double);
162 
164 
166  vtkSetClampMacro(Opacity,double,0.0,1.0);
167  vtkGetMacro(Opacity,double);
169 
171 
175  vtkSetVector3Macro(AmbientColor,double);
176  vtkGetVector3Macro(AmbientColor,double);
178 
180 
181  vtkSetVector3Macro(DiffuseColor,double);
182  vtkGetVector3Macro(DiffuseColor,double);
184 
186 
187  vtkSetVector3Macro(SpecularColor,double);
188  vtkGetVector3Macro(SpecularColor,double);
190 
192 
195  vtkGetMacro(EdgeVisibility,int);
196  vtkSetMacro(EdgeVisibility,int);
197  vtkBooleanMacro(EdgeVisibility,int);
199 
201 
202  vtkSetVector3Macro(EdgeColor,double);
203  vtkGetVector3Macro(EdgeColor,double);
205 
207 
209  vtkSetClampMacro(LineWidth,float,0,VTK_LARGE_FLOAT);
210  vtkGetMacro(LineWidth,float);
212 
214 
217  vtkSetMacro(LineStipplePattern,int);
218  vtkGetMacro(LineStipplePattern,int);
220 
222 
225  vtkSetClampMacro(LineStippleRepeatFactor,int,1,VTK_LARGE_INTEGER);
226  vtkGetMacro(LineStippleRepeatFactor,int);
228 
230 
232  vtkSetClampMacro(PointSize,float,0,VTK_LARGE_FLOAT);
233  vtkGetMacro(PointSize,float);
235 
237 
240  vtkGetMacro(BackfaceCulling,int);
241  vtkSetMacro(BackfaceCulling,int);
242  vtkBooleanMacro(BackfaceCulling,int);
244 
246 
249  vtkGetMacro(FrontfaceCulling,int);
250  vtkSetMacro(FrontfaceCulling,int);
251  vtkBooleanMacro(FrontfaceCulling,int);
253 
255 
257  vtkGetObjectMacro(Material, vtkXMLMaterial);
259 
261 
262  vtkGetStringMacro(MaterialName);
264 
267  void LoadMaterial(const char* name);
268 
270  void LoadMaterialFromString(const char* materialxml);
271 
273  void LoadMaterial(vtkXMLMaterial*);
274 
276 
278  vtkSetMacro(Shading, int);
279  vtkGetMacro(Shading, int);
280  vtkBooleanMacro(Shading, int);
282 
284 
286  vtkGetObjectMacro(ShaderProgram, vtkShaderProgram);
288 
291 
293 
297  virtual void AddShaderVariable(const char *name, int numVars, int *x);
298  virtual void AddShaderVariable(const char *name, int numVars, float *x);
299  virtual void AddShaderVariable(const char *name, int numVars, double *x);
301 
303 
304  void AddShaderVariable(const char* name, int v)
305  {
306  this->AddShaderVariable(name, 1, &v);
307  }
308  void AddShaderVariable(const char* name, float v)
309  {
310  this->AddShaderVariable(name, 1, &v);
311  }
312  void AddShaderVariable(const char* name, double v)
313  {
314  this->AddShaderVariable(name, 1, &v);
315  }
316  void AddShaderVariable(const char* name, int v1, int v2)
317  {
318  int v[2];
319  v[0] = v1;
320  v[1] = v2;
321  this->AddShaderVariable(name, 2, v);
322  }
323  void AddShaderVariable(const char* name, float v1, float v2)
324  {
325  float v[2];
326  v[0] = v1;
327  v[1] = v2;
328  this->AddShaderVariable(name, 2, v);
329  }
330  void AddShaderVariable(const char* name, double v1, double v2)
331  {
332  double v[2];
333  v[0] = v1;
334  v[1] = v2;
335  this->AddShaderVariable(name, 2, v);
336  }
337  void AddShaderVariable(const char* name, int v1, int v2, int v3)
338  {
339  int v[3];
340  v[0] = v1;
341  v[1] = v2;
342  v[2] = v3;
343  this->AddShaderVariable(name, 3, v);
344  }
345  void AddShaderVariable(const char* name, float v1, float v2, float v3)
346  {
347  float v[3];
348  v[0] = v1;
349  v[1] = v2;
350  v[2] = v3;
351  this->AddShaderVariable(name, 3, v);
352  }
353  void AddShaderVariable(const char* name, double v1, double v2, double v3)
354  {
355  double v[3];
356  v[0] = v1;
357  v[1] = v2;
358  v[2] = v3;
359  this->AddShaderVariable(name, 3, v);
360  }
362 
364 
368  void SetTexture(const char* name, vtkTexture* texture);
369  vtkTexture* GetTexture(const char* name);
371 
373 
377  void SetTexture(int unit, vtkTexture* texture);
378  vtkTexture* GetTexture(int unit);
379  void RemoveTexture(int unit);
381 
382 
385  void RemoveTexture(const char* name);
386 
388  void RemoveAllTextures();
389 
391  int GetNumberOfTextures();
392 
396  virtual void ReleaseGraphicsResources(vtkWindow *win);
397 
398 //BTX
400 
403  {
404  VTK_TEXTURE_UNIT_0 = 0,
411  VTK_TEXTURE_UNIT_7
412  };
413 //ETX
415 
416 protected:
417  vtkProperty();
418  ~vtkProperty();
419 
421 
422  void LoadProperty();
423  void LoadTextures();
424  void LoadTexture(vtkXMLDataElement* elem);
425  void LoadPerlineNoise(vtkXMLDataElement* );
426  void LoadMember(vtkXMLDataElement* elem);
428 
429  double Color[3];
430  double AmbientColor[3];
431  double DiffuseColor[3];
432  double SpecularColor[3];
433  double EdgeColor[3];
434  double Ambient;
435  double Diffuse;
436  double Specular;
438  double Opacity;
439  float PointSize;
440  float LineWidth;
448  bool Lighting;
449 
450  int Shading;
451 
453  vtkSetStringMacro(MaterialName);
454 
456  void SetShaderProgram(vtkShaderProgram*);
457 
458  vtkXMLMaterial* Material; // TODO: I wonder if this reference needs to be maintained.
459 
462  virtual void ReadFrameworkMaterial();
463 
464 //BTX
465  // These friends are provided only for the time being
466  // till we device a graceful way of loading texturing for GLSL.
467  friend class vtkGLSLShaderProgram;
468  friend class vtkShader;
469  // FIXME:
470  // Don't use these methods. They will be removed. They are provided only
471  // for the time-being.
472  vtkTexture* GetTextureAtIndex(int index);
473  int GetTextureUnitAtIndex(int index);
474  int GetTextureUnit(const char* name);
475 //ETX
476 
477 private:
478  vtkProperty(const vtkProperty&); // Not implemented.
479  void operator=(const vtkProperty&); // Not implemented.
480 
481  vtkPropertyInternals* Internals;
482 };
483 
485 
487 {
488  if ( this->Interpolation == VTK_FLAT )
489  {
490  return "Flat";
491  }
492  else if ( this->Interpolation == VTK_GOURAUD )
493  {
494  return "Gouraud";
495  }
496  else
497  {
498  return "Phong";
499  }
500 }
502 
503 
505 
507 {
508  if ( this->Representation == VTK_POINTS )
509  {
510  return "Points";
511  }
512  else if ( this->Representation == VTK_WIREFRAME )
513  {
514  return "Wireframe";
515  }
516  else
517  {
518  return "Surface";
519  }
520 }
522 
523 
524 
525 #endif