-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
85 lines (71 loc) · 3.03 KB
/
main.cpp
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
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPlaneSource.h>
#include <vtkContourFilter.h>
#include <vtkStripper.h>
#include <vtkPolyData.h>
#include <vtkDoubleArray.h>
#include <vtkMath.h>
#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkLabeledDataMapper.h>
#include "vtkContourLabel.h"
#include "vtkActor2D.h"
int main()
{
//-------------------Initialising the contour using rendom values-------------------------
vtkPlaneSource *plane = vtkPlaneSource::New();
plane->SetXResolution(10);
plane->SetYResolution(20);
plane->Update();
vtkDoubleArray *randomScalars = vtkDoubleArray::New();
randomScalars->SetNumberOfComponents(1);
randomScalars->SetName("Isovalues");
for (int i = 0; i < plane->GetOutput()->GetNumberOfPoints(); i++)
{
randomScalars->InsertNextTuple1(vtkMath::Random(-100.0, 100.0));
}
plane->GetOutput()->GetPointData()->SetScalars(randomScalars);
vtkContourFilter *contours = vtkContourFilter::New();
contours->SetInputConnection(plane->GetOutputPort());
contours->GenerateValues(5, -100, 100);
// Connect the segments of the conours into polylines
vtkStripper *contourStripper = vtkStripper::New();
contourStripper->SetInputConnection(contours->GetOutputPort());
contourStripper->Update();
vtkPolyData *contourPolyData = contourStripper->GetOutput();
//---------------------Find Points to add labels using the newly created vtkContourLabel--------------------------------
vtkContourLabel *contourLabel = vtkContourLabel::New();
contourLabel->SetInputData(contourPolyData);
contourLabel->Update();
vtkPolyData *outputLabelPolydata = contourLabel->GetOutput();
//----------------------------------------------------------------------
// The labeled data mapper will place labels at the points
vtkLabeledDataMapper *labelMapper = vtkLabeledDataMapper::New();
labelMapper->SetFieldDataName("Isovalues");
labelMapper->SetInputData(outputLabelPolydata);
labelMapper->SetLabelModeToLabelScalars();
labelMapper->SetLabelFormat("%6.2f");
vtkActor2D *isolabels = vtkActor2D::New();
isolabels->SetMapper(labelMapper);
//----------------------------------------------------------------------
//Polydata for isolines
vtkPolyDataMapper *polyDataMapper = vtkPolyDataMapper::New();
polyDataMapper->SetInputData(contourPolyData);
polyDataMapper->ScalarVisibilityOff();
vtkActor *polyDataActor = vtkActor::New();
polyDataActor->SetMapper(polyDataMapper);
//----------------------------------------------------------------------
// Visualisation
vtkRenderer *rend = vtkRenderer::New();
rend->AddActor(polyDataActor);
rend->AddActor2D(isolabels);
vtkRenderWindow *renWind = vtkRenderWindow::New();
vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
renWind->AddRenderer(rend);
interactor->SetRenderWindow(renWind);
interactor->Start();
return 0;
}