After upgrading our application from VTK 6.0.0 to VTK 8.2.0 we have a problem with artifacts (“cross-hatching,” “Moire patterns,” “aliasing”) when zooming in on details. This is for vtkCamera::ParallelProjectionOn()
Here I provide a simple program that is just 30 lines of actual code.
If you compile and link this with VTK 8.2.0, you should be able to see the Moire patterns when you zoom in on the small triangle. We did not have this problem with VTK 6.0.0.
// This simple program demonstrates a problem we have with VTK 8.2.0.
// When we zoom in we get Moire patterns ("cross-hatching" or "aliasing")
// Based on https://kitware.github.io/vtk-examples/site/Cxx/Widgets/ScalarBarWidget/
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkDataSet.h>
#include <vtkDataSetMapper.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkUnstructuredGrid.h>
#include <vtkUnstructuredGridReader.h>
// Note: At the end of the list of points, there are 3 points which define a small triangle that we will zoom in on.
const char* data_string =
"# vtk DataFile Version 1.0\n\
Unstructured Grid Example\n\
ASCII\n\
DATASET UNSTRUCTURED_GRID\n\
POINTS 27 float\n\
0.0 0.0 0.0\n\
1.0 0.0 0.0\n\
2.0 0.0 0.0\n\
0.0 1.0 0.0\n\
1.0 1.0 0.0\n\
2.0 1.0 0.0\n\
0.0 0.0 1.0\n\
1.0 0.0 1.0\n\
2.0 0.0 1.0\n\
0.0 1.0 1.0\n\
1.0 1.0 1.0\n\
2.0 1.0 1.0\n\
0.0 1.0 2.0\n\
1.0 1.0 2.0\n\
2.0 1.0 2.0\n\
0.0 1.0 3.0\n\
1.0 1.0 3.0\n\
2.0 1.0 3.0\n\
0.0 1.0 4.0\n\
1.0 1.0 4.0\n\
2.0 1.0 4.0\n\
0.0 1.0 5.0\n\
1.0 1.0 5.0\n\
2.0 1.0 5.0\n\
0.95 1.0 6.0\n\
1.0 0.95 6.05\n\
1.05 1.05 5.95\n\
CELLS 12 64\n\
8 0 1 4 3 6 7 10 9\n\
8 1 2 5 4 7 8 11 10\n\
4 7 10 9 12\n\
4 8 11 10 14\n\
6 15 16 17 14 13 12\n\
6 18 15 19 16 20 17\n\
4 22 23 20 19\n\
3 21 22 18\n\
3 22 19 18\n\
3 24 25 26\n\
2 21 24\n\
1 25\n\
CELL_TYPES 12\n\
12\n12\n10\n10\n7\n6\n9\n5\n5\n5\n3\n1\n\
POINT_DATA 27\n\
SCALARS scalars float\n\
LOOKUP_TABLE default\n\
0.0\n1.0\n2.0\n3.0\n4.0\n5.0\n6.0\n7.0\n8.0\n9.0\n10.0\n11.0\n12.0\n13.0\n14.0\n15.0\n16.0\n17.0\n18.0\n19.0\n20.0\n21.0\n22.0\n23.0\n24.0\n25.0\n26.0\n";
int main(int argc, char* argv[])
{
vtkNew<vtkUnstructuredGridReader> reader;
reader->ReadFromInputStringOn();
reader->SetInputString(data_string);
reader->Update();
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputData(reader->GetOutput());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
vtkNew<vtkRenderer> renderer;
renderer->AddActor(actor);
renderer->SetBackground(0.1,0.4,0.1);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(1500, 1000);
renderWindow->SetWindowName("TestMoirePatterns");
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow);
interactor->Initialize();
renderWindow->Render();
// The triangle of interest is near the point (1, 1, 6)
renderer->GetActiveCamera()->SetPosition(-9.0, 11.0, 7.0);
renderer->GetActiveCamera()->SetFocalPoint(1.0, 1.0, 6.0);
renderer->GetActiveCamera()->SetViewUp(0.6, 0.4, -0.7);
renderer->GetActiveCamera()->ParallelProjectionOn();
renderWindow->Render();
interactor->Start();
return EXIT_SUCCESS;
}