When rendering two almost identical stl files, artifacts appear. Is it possible to remove them somehow?
If you change the transparency to 0.99 for example, the picture will become better
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
//stl1
{vtkSmartPointer<vtkSTLReader> myVtkSTLReader = vtkSmartPointer<vtkSTLReader>::New();
myVtkSTLReader->SetFileName("C://Cherep.stl");
myVtkSTLReader->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper1 =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper1->SetInputData(myVtkSTLReader->GetOutput());
actor1->GetProperty()->SetColor(1, 0, 0);
actor1->GetProperty()->SetOpacity(1);
actor1->SetMapper(mapper1);
renderer->AddActor(actor1);
}
//stl2
{vtkSmartPointer<vtkSTLReader> myVtkSTLReader = vtkSmartPointer<vtkSTLReader>::New();
myVtkSTLReader->SetFileName("C://Cherep2.stl");
myVtkSTLReader->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper1 =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper1->SetInputData(myVtkSTLReader->GetOutput());
actor2->GetProperty()->SetColor(0, 0, 1);
actor2->GetProperty()->SetOpacity(1);
actor2->SetMapper(mapper1);
renderer->AddActor(actor2);
}
renderer->SetBackground(1, 1, 1);
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderwindow =
vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
renderwindow->AddRenderer(renderer);
auto m_LightKit = vtkLightKit::New();
m_LightKit->AddLightsToRenderer(renderer);
qvtkWidget = new QVTKOpenGLNativeWidget;
this->setCentralWidget(qvtkWidget);
qvtkWidget->setRenderWindow(renderwindow);
qvtkWidget->renderWindow()->AddRenderer(renderer);
danlipsa
(Dan Lipsa (Kitware))
March 21, 2025, 12:51pm
2
didn’t help
mapper1->SetResolveCoincidentTopologyToShiftZBuffer();
mapper1->SetResolveCoincidentTopologyZShift(100);
that didn’t help either
mapper1->SetResolveCoincidentTopologyToPolygonOffset();
mapper1->SetResolveCoincidentTopologyPolygonOffsetParameters(5, -5);
danlipsa
(Dan Lipsa (Kitware))
March 21, 2025, 3:23pm
4
Can you share your data? These might be genuine differences between the two models.
Yes I can, but since I am a new user the forum does not allow me to do this "
Sorry, new users can not upload attachments."
danlipsa
(Dan Lipsa (Kitware))
March 21, 2025, 3:50pm
6
You can use something like dropbox or drive.
danlipsa
(Dan Lipsa (Kitware))
March 21, 2025, 5:15pm
8
What you see are small differences between the two models. They might have been through different processing pipelines which resulted in slightly different surfaces.
In case of z fighting what triangles are on top changes based on the angle of view. This is not the case here.
What are you trying to achieve?
We can specify which model is active. We would like the active model to be in the foreground in this case.
danlipsa
(Dan Lipsa (Kitware))
March 21, 2025, 6:25pm
10
Not sure what you mean by ‘in the foreground’. You can make either of the models transparent using
actor.GetProperty().SetOpacity(0)
We want to see both models, but without these artifacts, if you choose one model, then the red one is displayed and the blue one is displayed behind, if you choose another, then the blue one is displayed and the red one is displayed behind
danlipsa
(Dan Lipsa (Kitware))
March 21, 2025, 6:50pm
13
You can use clip to cut the top part of blue model. I’ve done this in ParaView, but the same can be done in VTK.
clip.pvsm (431.7 KB)
This is one example, artifacts can be anywhere, we would like to solve the problem more globally
danlipsa
(Dan Lipsa (Kitware))
March 21, 2025, 9:01pm
15
One thing you can try is to scale a little bit the model that is “on top” so that it hides the model “below”.
This way, surfaces that are approximately the same will be ordered the way you want.