7 #include "imstkVTKPolyDataRenderDelegate.h" 8 #include "imstkRenderMaterial.h" 9 #include "imstkVisualModel.h" 10 #include "imstkColorFunction.h" 13 #include <vtkColorTransferFunction.h> 14 #include <vtkPolyDataMapper.h> 15 #include <vtkProperty.h> 22 std::shared_ptr<RenderMaterial> material =
m_visualModel->getRenderMaterial();
23 vtkSmartPointer<vtkProperty> actorProperty = vtkActor::SafeDownCast(m_actor)->GetProperty();
24 vtkSmartPointer<vtkPolyDataMapper> polyMapper = vtkPolyDataMapper::SafeDownCast(m_mapper);
26 if (material->getScalarVisibility() && polyMapper !=
nullptr)
29 std::shared_ptr<ColorFunction> imstkLookupTable = material->getColorLookupTable();
30 const double* range = imstkLookupTable->getRange().data();
31 double spacing = (range[1] - range[0]) / imstkLookupTable->getNumberOfColors();
32 vtkNew<vtkColorTransferFunction> lookupTable;
33 lookupTable->SetColorSpaceToRGB();
34 for (
int i = 0; i < imstkLookupTable->getNumberOfColors(); i++)
36 const double t =
static_cast<double>(i) / imstkLookupTable->getNumberOfColors();
37 const Color& color = imstkLookupTable->getColor(i);
38 lookupTable->AddRGBPoint(t * (range[1] - range[0]) + range[0] + spacing * 0.5, color.r, color.g, color.b);
41 switch (imstkLookupTable->getColorSpace())
43 case ColorFunction::ColorSpace::RGB:
44 lookupTable->SetColorSpaceToRGB();
46 case ColorFunction::ColorSpace::HSV:
47 lookupTable->SetColorSpaceToHSV();
49 case ColorFunction::ColorSpace::LAB:
50 lookupTable->SetColorSpaceToLab();
52 case ColorFunction::ColorSpace::DIVERING:
53 lookupTable->SetColorSpaceToDiverging();
56 lookupTable->SetColorSpaceToRGB();
60 polyMapper->SetLookupTable(lookupTable);
61 polyMapper->SetScalarVisibility(material->getScalarVisibility());
65 const Color& diffuseColor = material->getDiffuseColor();
66 const Color& ambientColor = material->getAmbientColor();
67 const Color& specularColor = material->getSpecularColor();
68 const Color& edgeColor = material->getEdgeColor();
69 const Color& vertexColor = material->getVertexColor();
70 const Color& surfaceColor = material->getColor();
71 const Color& coatColor = material->getCoatColor();
72 const Color& edgeTintColor = material->getEdgeTint();
75 actorProperty->SetDiffuseColor(diffuseColor.r, diffuseColor.g, diffuseColor.b);
76 actorProperty->SetDiffuse(material->getDiffuse());
77 actorProperty->SetAmbientColor(ambientColor.r, ambientColor.g, ambientColor.b);
78 actorProperty->SetAmbient(material->getAmbient());
79 actorProperty->SetSpecularColor(specularColor.r, specularColor.g, specularColor.b);
80 actorProperty->SetSpecularPower(material->getSpecularPower());
81 actorProperty->SetSpecular(material->getSpecular());
84 actorProperty->SetOcclusionStrength(material->getOcclusionStrength());
85 actorProperty->SetRoughness(material->getRoughness());
86 actorProperty->SetMetallic(material->getMetalness());
87 actorProperty->SetNormalScale(material->getNormalStrength());
89 actorProperty->SetAnisotropy(material->getAnisotropy());
90 actorProperty->SetAnisotropyRotation(material->getAnisotropyRotation());
91 actorProperty->SetBaseIOR(material->getBaseIOR());
92 actorProperty->SetCoatColor(coatColor.r, coatColor.g, coatColor.b);
93 actorProperty->SetCoatIOR(material->getCoatIOR());
94 actorProperty->SetCoatNormalScale(material->getCoatNormalScale());
95 actorProperty->SetCoatRoughness(material->getCoatRoughness());
96 actorProperty->SetCoatStrength(material->getCoatStrength());
97 actorProperty->SetEdgeTint(edgeTintColor.r, edgeTintColor.g, edgeTintColor.b);
100 actorProperty->SetColor(surfaceColor.r, surfaceColor.g, surfaceColor.b);
101 actorProperty->SetVertexColor(vertexColor.r, vertexColor.g, vertexColor.b);
102 actorProperty->SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b);
103 actorProperty->SetLineWidth(material->getLineWidth());
104 actorProperty->SetPointSize(material->getPointSize());
105 actorProperty->SetBackfaceCulling(material->getBackFaceCulling());
106 actorProperty->SetOpacity(material->getOpacity());
107 actorProperty->SetRenderPointsAsSpheres(material->getRenderPointsAsSpheres());
111 actorProperty->LightingOn();
112 actorProperty->SetInterpolationToPBR();
116 actorProperty->LightingOn();
117 actorProperty->SetInterpolationToPhong();
121 actorProperty->LightingOn();
122 actorProperty->SetInterpolationToGouraud();
126 actorProperty->LightingOn();
127 actorProperty->SetInterpolationToFlat();
131 actorProperty->LightingOff();
135 switch (material->getDisplayMode())
137 case RenderMaterial::DisplayMode::Wireframe:
138 actorProperty->SetRepresentationToWireframe();
139 actorProperty->SetEdgeVisibility(
false);
141 case RenderMaterial::DisplayMode::Points:
142 actorProperty->SetRepresentationToPoints();
143 actorProperty->SetEdgeVisibility(
false);
145 case RenderMaterial::DisplayMode::WireframeSurface:
146 actorProperty->SetRepresentationToSurface();
147 actorProperty->SetEdgeVisibility(
true);
149 case RenderMaterial::DisplayMode::Surface:
151 actorProperty->SetRepresentationToSurface();
152 actorProperty->SetEdgeVisibility(
false);
153 actorProperty->SetVertexVisibility(
false);
Phong shading model (default)
std::shared_ptr< VisualModel > m_visualModel
imstk visual model (contains data (geometry) and render specification (render material)) ...
Flat shading model with no interpolation.
Renders without shading, no lighting.
Gouraud shading model (default)
void updateRenderProperties() override
Updates the actor and mapper properties from the currently set VisualModel.
Physically based rendering.