1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkProperty.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkActor.h"
#include "vtkGraphicsFactory.h"
#include <stdlib.h>
vtkCxxRevisionMacro(vtkProperty, "$Revision: 1.55 $");
//----------------------------------------------------------------------------
// Needed when we don't use the vtkStandardNewMacro.
vtkInstantiatorNewMacro(vtkProperty);
//----------------------------------------------------------------------------
// Construct object with object color, ambient color, diffuse color,
// specular color, and edge color white; ambient coefficient=0; diffuse
// coefficient=0; specular coefficient=0; specular power=1; Gouraud shading;
// and surface representation. Backface and frontface culling are off.
vtkProperty::vtkProperty()
{
this->AmbientColor[0] = 1;
this->AmbientColor[1] = 1;
this->AmbientColor[2] = 1;
this->DiffuseColor[0] = 1;
this->DiffuseColor[1] = 1;
this->DiffuseColor[2] = 1;
this->SpecularColor[0] = 1;
this->SpecularColor[1] = 1;
this->SpecularColor[2] = 1;
this->EdgeColor[0] = 1;
this->EdgeColor[1] = 1;
this->EdgeColor[2] = 1;
this->Ambient = 0.0;
this->Diffuse = 1.0;
this->Specular = 0.0;
this->SpecularPower = 1.0;
this->Opacity = 1.0;
this->Interpolation = VTK_GOURAUD;
this->Representation = VTK_SURFACE;
this->EdgeVisibility = 0;
this->BackfaceCulling = 0;
this->FrontfaceCulling = 0;
this->PointSize = 1.0;
this->LineWidth = 1.0;
this->LineStipplePattern = 0xFFFF;
this->LineStippleRepeatFactor = 1;
}
// Assign one property to another.
void vtkProperty::DeepCopy(vtkProperty *p)
{
if ( p != NULL )
{
this->SetColor(p->GetColor());
this->SetAmbientColor(p->GetAmbientColor());
this->SetDiffuseColor(p->GetDiffuseColor());
this->SetSpecularColor(p->GetSpecularColor());
this->SetEdgeColor(p->GetEdgeColor());
this->SetAmbient(p->GetAmbient());
this->SetDiffuse(p->GetDiffuse());
this->SetSpecular(p->GetSpecular());
this->SetSpecularPower(p->GetSpecularPower());
this->SetOpacity(p->GetOpacity());
this->SetInterpolation(p->GetInterpolation());
this->SetRepresentation(p->GetRepresentation());
this->SetEdgeVisibility(p->GetEdgeVisibility());
this->SetBackfaceCulling(p->GetBackfaceCulling());
this->SetFrontfaceCulling(p->GetFrontfaceCulling());
this->SetPointSize(p->GetPointSize());
this->SetLineWidth(p->GetLineWidth());
this->SetLineStipplePattern(p->GetLineStipplePattern());
this->SetLineStippleRepeatFactor(p->GetLineStippleRepeatFactor());
}
}
// return the correct type of Property
vtkProperty *vtkProperty::New()
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkGraphicsFactory::CreateInstance("vtkProperty");
return (vtkProperty*)ret;
}
void vtkProperty::SetColor(double R,double G,double B)
{
// Use Set macros to insure proper modified time behavior
this->SetAmbientColor(R,G,B);
this->SetDiffuseColor(R,G,B);
this->SetSpecularColor(R,G,B);
}
// Return composite color of object (ambient + diffuse + specular). Return value
// is a pointer to rgb values.
double *vtkProperty::GetColor()
{
double norm;
int i;
if ((this->Ambient + this->Diffuse + this->Specular)>0)
{
norm = 1.0 / (this->Ambient + this->Diffuse + this->Specular);
}
else
{
norm = 0.0;
}
for (i = 0; i < 3; i ++)
{
this->Color[i] = this->AmbientColor[i]*this->Ambient*norm;
this->Color[i] = this->Color[i] + this->DiffuseColor[i]*this->Diffuse*norm;
this->Color[i] = this->Color[i] + this->SpecularColor[i]*this->Specular*norm;
}
return this->Color;
}
// Copy composite color of object (ambient + diffuse + specular) into array
// provided.
void vtkProperty::GetColor(double rgb[3])
{
this->GetColor();
rgb[0] = this->Color[0];
rgb[1] = this->Color[1];
rgb[2] = this->Color[2];
}
void vtkProperty::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Ambient: " << this->Ambient << "\n";
os << indent << "Ambient Color: (" << this->AmbientColor[0] << ", "
<< this->AmbientColor[1] << ", " << this->AmbientColor[2] << ")\n";
os << indent << "Diffuse: " << this->Diffuse << "\n";
os << indent << "Diffuse Color: (" << this->DiffuseColor[0] << ", "
<< this->DiffuseColor[1] << ", " << this->DiffuseColor[2] << ")\n";
os << indent << "Edge Color: (" << this->EdgeColor[0] << ", "
<< this->EdgeColor[1] << ", " << this->EdgeColor[2] << ")\n";
os << indent << "Edge Visibility: "
<< (this->EdgeVisibility ? "On\n" : "Off\n");
os << indent << "Interpolation: ";
switch (this->Interpolation)
{
case VTK_FLAT: os << "VTK_FLAT\n"; break;
case VTK_GOURAUD: os << "VTK_GOURAUD\n"; break;
case VTK_PHONG: os << "VTK_PHONG\n"; break;
default: os << "unknown\n";
}
os << indent << "Opacity: " << this->Opacity << "\n";
os << indent << "Representation: ";
switch (this->Representation)
{
case VTK_POINTS: os << "VTK_POINTS\n"; break;
case VTK_WIREFRAME: os << "VTK_WIREFRAME\n"; break;
case VTK_SURFACE: os << "VTK_SURFACE\n"; break;
default: os << "unknown\n";
}
os << indent << "Specular: " << this->Specular << "\n";
os << indent << "Specular Color: (" << this->SpecularColor[0] << ", "
<< this->SpecularColor[1] << ", " << this->SpecularColor[2] << ")\n";
os << indent << "Specular Power: " << this->SpecularPower << "\n";
os << indent << "Backface Culling: "
<< (this->BackfaceCulling ? "On\n" : "Off\n");
os << indent << "Frontface Culling: "
<< (this->FrontfaceCulling ? "On\n" : "Off\n");
os << indent << "Point size: " << this->PointSize << "\n";
os << indent << "Line width: " << this->LineWidth << "\n";
os << indent << "Line stipple pattern: " << this->LineStipplePattern << "\n";
os << indent << "Line stipple repeat factor: " << this->LineStippleRepeatFactor << "\n";
}
|