Here are two ways to get the same effect:

  1. Make Roughness lower
  2. Configure Coat layer and use it.
#include <iostream>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkSphereSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataNormals.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkLight.h>
#include <vtkSTLReader.h>

#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();

using namespace std;

int main()
{
    vtkSPtrNew( reader, vtkSTLReader );
    reader->SetFileName( "string.stl" );
    reader->Update();

    vtkSPtrNew(polyDataNormals, vtkPolyDataNormals);
    polyDataNormals->SetInputData( reader->GetOutput() );
    polyDataNormals->ComputePointNormalsOn();
    polyDataNormals->ComputeCellNormalsOff();
    polyDataNormals->SetSplitting(false);
    polyDataNormals->Update();

    vtkSPtrNew( mapper, vtkPolyDataMapper );
    mapper->SetInputConnection( polyDataNormals->GetOutputPort() );

    vtkSPtrNew( actor, vtkActor );
    actor->SetMapper( mapper );

#if (VTK_MAJOR_VERSION >= 9)
    // Ambient 环境; diffuse 扩散; specular 镜面; coefficient 系数
    actor->GetProperty()->SetInterpolationToPBR(); // shading interpolation: PBR

    actor->GetProperty()->SetRoughness(0.1); // A: set 0.1

//    actor->GetProperty()->SetCoatStrength(1.0); // B: use Coat method if Roughness is big(such as 0.7)
//    actor->GetProperty()->SetCoatRoughness(0.15);
//    actor->GetProperty()->SetCoatIOR(1.3);
#endif

    vtkSPtrNew( renderer, vtkRenderer );
    renderer->AddActor(actor);
    renderer->SetBackground( 0, 0, 0 );

    vtkSPtrNew( renderWindow, vtkRenderWindow );
    renderWindow->AddRenderer( renderer );

    vtkSPtrNew( renderWindowInteractor, vtkRenderWindowInteractor );
    renderWindowInteractor->SetRenderWindow( renderWindow );

    renderer->ResetCamera();
    renderWindow->Render();
    renderWindowInteractor->Start();
    return 0;
}

The string.stl used in the project can be downloaded at:

https://pan.quark.cn/s/5537f0b7de11

Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x