Incorrect display of actors

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);

SetResolveCoincidentTopologyToShiftZBuffer
https://vtk.org/doc/nightly/html/classvtkMapper.html#ab9b4ffce6f66b951fb8b3b4532eb8cd9

might help.

didn’t help

  mapper1->SetResolveCoincidentTopologyToShiftZBuffer();
  mapper1->SetResolveCoincidentTopologyZShift(100);

that didn’t help either

  mapper1->SetResolveCoincidentTopologyToPolygonOffset();
  mapper1->SetResolveCoincidentTopologyPolygonOffsetParameters(5, -5);

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."

You can use something like dropbox or drive.

https://drive.google.com/drive/folders/1vGtmhSWAzYoP-ut9Cwc-7XxZ3SfvP--2

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.

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

1 red, 2 blue

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

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.