-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvtkMeshPointDifferenceExample.cxx
139 lines (116 loc) · 4.22 KB
/
vtkMeshPointDifferenceExample.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "vtkMeshPointDifference.h"
#include <vtkActor.h>
#include <vtkDataArray.h>
#include <vtkDoubleArray.h>
#include <vtkGlyph3D.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkLookupTable.h>
#include <vtkMath.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkScalarBarActor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkXMLPolyDataReader.h>
int main(int argc, char *argv[])
{
// Verify arguments
if(argc < 3)
{
std::cerr << "Required arguments: mesh1.vtp mesh2.vtp" << std::endl;
return EXIT_SUCCESS;
}
// Parse arguments
std::string mesh1FileName = argv[1];
std::string mesh2FileName = argv[2];
// Output arguments
std::cout << "Mesh1: " << mesh1FileName << std::endl;
std::cout << "Mesh2: " << mesh2FileName << std::endl;
// Read the files
vtkSmartPointer<vtkXMLPolyDataReader> reader1 =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader1->SetFileName(mesh1FileName.c_str());
reader1->Update();
vtkSmartPointer<vtkXMLPolyDataReader> reader2 =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader2->SetFileName(mesh1FileName.c_str());
reader2->Update();
// Compare the meshes
vtkSmartPointer<vtkMeshPointDifference> meshPointDifference =
vtkSmartPointer<vtkMeshPointDifference>::New();
meshPointDifference->SetInputConnection(0, reader1->GetOutputPort());
meshPointDifference->SetInputConnection(1, reader2->GetOutputPort());
meshPointDifference->Update();
// Create lookup table
vtkSmartPointer<vtkLookupTable> lookupTable =
vtkSmartPointer<vtkLookupTable>::New();
double range[2];
vtkDoubleArray::SafeDownCast(meshPointDifference->GetOutput()->GetPointData()->GetArray("Distances"))->GetRange(range);
std::cout << "Range: " << range[0] << " " << range[1] << std::endl;
lookupTable->SetRange(range);
lookupTable->Build();
// Create scalarbar
vtkSmartPointer<vtkScalarBarActor> scalarBar =
vtkSmartPointer<vtkScalarBarActor>::New();
scalarBar->SetLookupTable(lookupTable);
scalarBar->SetTitle("Mesh Distance");
// Create normal glyph
vtkSmartPointer<vtkGlyph3D> glyph =
vtkSmartPointer<vtkGlyph3D>::New();
glyph->SetInput(meshPointDifference->GetOutput());
glyph->SetVectorModeToUseNormal();
glyph->OrientOn();
// Set to mappers
vtkSmartPointer<vtkPolyDataMapper> mapperA =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapperA->SetInput(meshPointDifference->GetOutput());
mapperA->SetScalarRange(range);
mapperA->SetLookupTable(lookupTable);
vtkSmartPointer<vtkPolyDataMapper> mapperB =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapperB->SetInputConnection(reader2->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> normalMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
normalMapper->SetInputConnection(glyph->GetOutputPort());
// Set to Actors
vtkSmartPointer<vtkActor> actorA =
vtkSmartPointer<vtkActor>::New();
actorA->SetMapper(mapperA);
vtkSmartPointer<vtkActor> actorB =
vtkSmartPointer<vtkActor>::New();
actorB->SetMapper(mapperB);
actorB->GetProperty()->SetOpacity(.3);
vtkSmartPointer<vtkActor> normalActor =
vtkSmartPointer<vtkActor>::New();
normalActor->SetMapper(normalMapper);
normalActor->GetProperty()->SetOpacity(.8);
normalActor->GetProperty()->SetColor(0.,.2,0.);
// Visualize
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actorA);
bool DISPLAYNORMALS = false;
if(DISPLAYNORMALS)
{
renderer->AddActor(normalActor);
}
renderer->AddActor(actorB);
renderer->AddActor2D(scalarBar);
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
interactor->SetRenderWindow(renWin);
interactor->SetInteractorStyle(style);
interactor->Initialize();
interactor->Start();
return EXIT_SUCCESS;
}