Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkMaterial.h"
00019 #include "mitkProperties.h"
00020 #include "mitkVtkInterpolationProperty.h"
00021 #include "mitkVtkRepresentationProperty.h"
00022 #include <vtkProperty.h>
00023 #include "mitkDataNode.h"
00024 #include "mitkBaseRenderer.h"
00025
00026
00027 mitk::Material::Material( Color color, vtkFloatingPointType opacity )
00028 {
00029 InitializeStandardValues();
00030 SetColor( color );
00031 SetColorCoefficient( GetColorCoefficient() );
00032 SetSpecularColor( GetSpecularColor() );
00033 SetSpecularCoefficient( GetSpecularCoefficient() );
00034 SetSpecularPower( GetSpecularPower() );
00035 SetOpacity( opacity );
00036 SetInterpolation( GetInterpolation() );
00037 SetRepresentation( GetRepresentation() );
00038 SetLineWidth( GetLineWidth() );
00039 m_Name = "";
00040 }
00041
00042
00043
00044 mitk::Material::Material( vtkFloatingPointType red, vtkFloatingPointType green, vtkFloatingPointType blue, vtkFloatingPointType opacity )
00045 {
00046 InitializeStandardValues();
00047 SetColor( red, green, blue );
00048 SetColorCoefficient( GetColorCoefficient() );
00049 SetSpecularColor( GetSpecularColor() );
00050 SetSpecularCoefficient( GetSpecularCoefficient() );
00051 SetSpecularPower( GetSpecularPower() );
00052 SetOpacity( opacity );
00053 SetInterpolation( GetInterpolation() );
00054 SetRepresentation( GetRepresentation() );
00055 SetLineWidth( GetLineWidth() );
00056 m_Name = "";
00057 }
00058
00059
00060
00061 mitk::Material::Material( vtkFloatingPointType red, vtkFloatingPointType green, vtkFloatingPointType blue,
00062 vtkFloatingPointType colorCoefficient, vtkFloatingPointType specularCoefficient,
00063 vtkFloatingPointType specularPower, vtkFloatingPointType opacity )
00064 {
00065 InitializeStandardValues();
00066 SetColor( red, green, blue );
00067 SetColorCoefficient( colorCoefficient );
00068 SetSpecularColor( GetSpecularColor() );
00069 SetSpecularCoefficient( specularCoefficient );
00070 SetSpecularPower( specularPower );
00071 SetOpacity( opacity );
00072 SetInterpolation( GetInterpolation() );
00073 SetRepresentation( GetRepresentation() );
00074 SetLineWidth( GetLineWidth() );
00075 m_Name = "";
00076 }
00077
00078
00079 mitk::Material::Material( mitk::Material::Color color, vtkFloatingPointType colorCoefficient, vtkFloatingPointType specularCoefficient, vtkFloatingPointType specularPower, vtkFloatingPointType opacity )
00080 {
00081 InitializeStandardValues();
00082 SetColor( color );
00083 SetColorCoefficient( colorCoefficient );
00084 SetSpecularColor( GetSpecularColor() );
00085 SetSpecularCoefficient( specularCoefficient );
00086 SetSpecularPower( specularPower );
00087 SetOpacity( opacity );
00088 SetInterpolation( GetInterpolation() );
00089 SetRepresentation( GetRepresentation() );
00090 SetLineWidth( GetLineWidth() );
00091 }
00092
00093
00094 mitk::Material::Material( )
00095 {
00096 InitializeStandardValues();
00097 SetColor( GetColor() );
00098 SetColorCoefficient( GetColorCoefficient() );
00099 SetSpecularColor( GetSpecularColor() );
00100 SetSpecularCoefficient( GetSpecularCoefficient() );
00101 SetSpecularPower( GetSpecularPower() );
00102 SetOpacity( GetOpacity() );
00103 SetInterpolation( GetInterpolation() );
00104 SetRepresentation( GetRepresentation() );
00105 SetLineWidth( GetLineWidth() );
00106 }
00107
00108 mitk::Material::Material( const Material& property ) : itk::Object()
00109 {
00110 Initialize( property );
00111 }
00112
00113 mitk::Material::Material( const Material& property, vtkFloatingPointType red, vtkFloatingPointType green, vtkFloatingPointType blue, vtkFloatingPointType opacity, std::string name )
00114 {
00115 Initialize( property );
00116 SetColor( red, green, blue );
00117 SetOpacity( opacity );
00118 SetName( name );
00119 }
00120
00121 bool mitk::Material::Assignable(const Material& other) const
00122 {
00123 try
00124 {
00125 const Material& otherinstance = dynamic_cast<const Self&>(other);
00126 otherinstance.GetOpacity();
00127 return true;
00128 }
00129 catch (std::bad_cast)
00130 {
00131 }
00132 return false;
00133 }
00134
00135 mitk::Material& mitk::Material::operator=(const mitk::Material& other)
00136 {
00137 try
00138 {
00139 const Self& otherProp( dynamic_cast<const Self&>(other) );
00140
00141 Initialize(otherProp);
00142 }
00143 catch (std::bad_cast)
00144 {
00145
00146 }
00147
00148 return *this;
00149 }
00150
00151
00152
00153 void mitk::Material::SetColor( mitk::Material::Color color )
00154 {
00155 m_Color = color;
00156 Modified();
00157 }
00158
00159
00160 void mitk::Material::SetColor( vtkFloatingPointType red, vtkFloatingPointType green, vtkFloatingPointType blue )
00161 {
00162 m_Color.Set( red, green, blue );
00163 Modified();
00164 }
00165
00166
00167 void mitk::Material::SetColorCoefficient( vtkFloatingPointType coefficient )
00168 {
00169 m_ColorCoefficient = coefficient;
00170 Modified();
00171 }
00172
00173 void mitk::Material::SetSpecularColor( mitk::Material::Color specularColor )
00174 {
00175 m_SpecularColor = specularColor;
00176 Modified();
00177 }
00178
00179
00180 void mitk::Material::SetSpecularColor( vtkFloatingPointType red, vtkFloatingPointType green, vtkFloatingPointType blue )
00181 {
00182 m_SpecularColor.Set( red, green, blue );
00183 Modified();
00184 }
00185
00186 void mitk::Material::SetSpecularCoefficient( vtkFloatingPointType specularCoefficient )
00187 {
00188 m_SpecularCoefficient = specularCoefficient;
00189 Modified();
00190 }
00191
00192
00193 void mitk::Material::SetSpecularPower( vtkFloatingPointType specularPower )
00194 {
00195 m_SpecularPower = specularPower;
00196 Modified();
00197 }
00198
00199
00200 void mitk::Material::SetOpacity( vtkFloatingPointType opacity )
00201 {
00202 m_Opacity = opacity;
00203 Modified();
00204 }
00205
00206
00207 void mitk::Material::SetInterpolation( InterpolationType interpolation )
00208 {
00209 m_Interpolation = interpolation;
00210 Modified();
00211 }
00212
00213
00214 void mitk::Material::SetRepresentation( RepresentationType representation )
00215 {
00216 m_Representation = representation;
00217 Modified();
00218 }
00219
00220
00221 void mitk::Material::SetLineWidth( float lineWidth )
00222 {
00223 m_LineWidth = lineWidth;
00224 Modified();
00225 }
00226
00227
00228 mitk::Material::Color mitk::Material::GetColor() const
00229 {
00230 return m_Color;
00231 }
00232
00233
00234 vtkFloatingPointType mitk::Material::GetColorCoefficient() const
00235 {
00236 return m_ColorCoefficient;
00237 }
00238
00239 mitk::Material::Color mitk::Material::GetSpecularColor() const
00240 {
00241 return m_SpecularColor;
00242 }
00243
00244 vtkFloatingPointType mitk::Material::GetSpecularCoefficient() const
00245 {
00246 return m_SpecularCoefficient;
00247 }
00248
00249
00250 vtkFloatingPointType mitk::Material::GetSpecularPower() const
00251 {
00252 return m_SpecularPower;
00253 }
00254
00255
00256 vtkFloatingPointType mitk::Material::GetOpacity() const
00257 {
00258 return m_Opacity;
00259 }
00260
00261 mitk::Material::InterpolationType mitk::Material::GetInterpolation() const
00262 {
00263 return m_Interpolation;
00264 }
00265
00266 mitk::Material::RepresentationType mitk::Material::GetRepresentation() const
00267 {
00268 return m_Representation;
00269 }
00270
00271
00272 int mitk::Material::GetVtkInterpolation() const
00273 {
00274 switch ( m_Interpolation )
00275 {
00276 case( Flat ) : return VTK_FLAT;
00277 case( Gouraud ) : return VTK_GOURAUD;
00278 case( Phong ) : return VTK_PHONG;
00279 }
00280 return VTK_GOURAUD;
00281 }
00282
00283 int mitk::Material::GetVtkRepresentation() const
00284 {
00285 switch ( m_Representation )
00286 {
00287 case( Points ) : return VTK_POINTS;
00288 case( Wireframe ) : return VTK_WIREFRAME;
00289 case( Surface ) : return VTK_SURFACE;
00290 }
00291 return VTK_SURFACE;
00292 }
00293
00294 float mitk::Material::GetLineWidth() const
00295 {
00296 return m_LineWidth;
00297 }
00298
00299 void mitk::Material::Initialize( const Material& property )
00300 {
00301 this->SetColor( property.GetColor() );
00302 this->SetColorCoefficient( property.GetColorCoefficient() );
00303 this->SetSpecularColor( property.GetSpecularColor() );
00304 this->SetSpecularCoefficient( property.GetSpecularCoefficient() );
00305 this->SetSpecularPower( property.GetSpecularPower() );
00306 this->SetOpacity( property.GetOpacity() );
00307 this->SetInterpolation( property.GetInterpolation() );
00308 this->SetRepresentation( property.GetRepresentation() );
00309 this->SetLineWidth( property.GetLineWidth() );
00310 this->SetName( property.GetName() );
00311 }
00312
00313
00314 bool mitk::Material::operator==( const Material& property ) const
00315 {
00316 const Self * other = dynamic_cast<const Self*>( &property );
00317
00318 if ( other == NULL )
00319 return false;
00320 else
00321 return ( m_Color == other->GetColor() &&
00322 m_ColorCoefficient == other->GetColorCoefficient() &&
00323 m_SpecularColor == other->GetSpecularColor() &&
00324 m_SpecularCoefficient == other->GetSpecularCoefficient() &&
00325 m_SpecularPower == other->GetSpecularPower() &&
00326 m_Opacity == other->GetOpacity() &&
00327 m_Interpolation == other->GetInterpolation() &&
00328 m_Name == other->GetName() &&
00329 m_Representation == other->GetRepresentation() &&
00330 m_LineWidth == other->GetLineWidth()
00331 );
00332 }
00333
00334
00335
00336 void mitk::Material::InitializeStandardValues()
00337 {
00338 m_Color.Set( 0.5, 0.5, 0.0 );
00339 m_ColorCoefficient = 0.5 ;
00340 m_SpecularColor.Set( 1.0, 1.0, 1.0 );
00341 m_SpecularCoefficient = 0.5;
00342 m_SpecularPower = 10.0;
00343 m_Opacity = 1.0 ;
00344 m_Interpolation = Gouraud;
00345 m_Representation = Surface;
00346 m_LineWidth = 1.0;
00347 m_Name = "";
00348 }
00349
00350 void mitk::Material::Update()
00351 {
00352 this->SetColor( this->GetColor() );
00353 this->SetColorCoefficient( this->GetColorCoefficient() );
00354 this->SetSpecularColor( this->GetSpecularColor() );
00355 this->SetSpecularCoefficient( this->GetSpecularCoefficient() );
00356 this->SetSpecularPower( this->GetSpecularPower() );
00357 this->SetOpacity( this->GetOpacity() );
00358 this->SetInterpolation( this->GetInterpolation() );
00359 this->SetRepresentation( this->GetRepresentation() );
00360 }
00361
00362 void mitk::Material::PrintSelf ( std::ostream &os ) const
00363 {
00364 os << "Name: " << GetName() << std::endl;
00365 os << "Color: " << GetColor() << std::endl;
00366 os << "ColorCoefficient" << GetColorCoefficient() << std::endl;
00367 os << "SpecularColor: " << GetSpecularColor() << std::endl;
00368 os << "SpecularCoefficient: " << GetSpecularCoefficient() << std::endl;
00369 os << "SpecularPower: " << GetSpecularPower() << std::endl;
00370 os << "Opacity: " << GetOpacity() << std::endl;
00371 os << "Line width: " << GetLineWidth() << std::endl;
00372 switch ( GetInterpolation() )
00373 {
00374 case ( Flat ) : os << "Interpolation: Flat" << std::endl;
00375 break;
00376 case ( Gouraud ) : os << "Interpolation: Gouraud" << std::endl;
00377 break;
00378 case ( Phong ) : os << "Interpolation: Phong" << std::endl;
00379 break;
00380 }
00381 switch ( GetRepresentation() )
00382 {
00383 case ( Points ) : os << "Representation: Points" << std::endl;
00384 break;
00385 case ( Wireframe ) : os << "Representation: Wireframe" << std::endl;
00386 break;
00387 case ( Surface ) : os << "Representation: Surface" << std::endl;
00388 break;
00389 }
00390 }