File: SplineWidget.cxx

package info (click to toggle)
paraview 5.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 367,928 kB
  • sloc: cpp: 2,870,477; ansic: 1,329,317; python: 132,607; xml: 98,045; sh: 5,265; java: 4,541; yacc: 4,385; f90: 3,099; perl: 2,363; lex: 1,950; javascript: 1,574; objc: 143; makefile: 135; tcl: 59; pascal: 50; fortran: 27
file content (105 lines) | stat: -rw-r--r-- 3,044 bytes parent folder | download | duplicates (2)
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
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCommand.h"
#include "vtkImageData.h"
#include "vtkImagePlaneWidget.h"
#include "vtkInteractorEventRecorder.h"
#include "vtkKochanekSpline.h"
#include "vtkParametricSpline.h"
#include "vtkPlaneSource.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkProperty2D.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSplineWidget.h"
#include "vtkTextProperty.h"

// Callback for the spline widget interaction
class vtkSplineWidgetCallback : public vtkCommand
{
public:
  static vtkSplineWidgetCallback* New() { return new vtkSplineWidgetCallback; }
  virtual void Execute(vtkObject* caller, unsigned long, void*)
  {
    vtkSplineWidget* spline = reinterpret_cast<vtkSplineWidget*>(caller);
    spline->GetPolyData(Poly);
  }
  vtkSplineWidgetCallback()
    : Poly(0)
  {
  }
  vtkPolyData* Poly;
};

int main(int, char*[])
{
  vtkRenderer* ren1 = vtkRenderer::New();
  vtkRenderWindow* renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

  vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  vtkPlaneSource* planeSource = vtkPlaneSource::New();
  planeSource->Update();

  vtkPolyDataMapper* planeSourceMapper = vtkPolyDataMapper::New();
  planeSourceMapper->SetInput(planeSource->GetOutput());
  vtkActor* planeSourceActor = vtkActor::New();
  planeSourceActor->SetMapper(planeSourceMapper);

  vtkSplineWidget* spline = vtkSplineWidget::New();
  spline->SetInteractor(iren);
  spline->SetInput(planeSource->GetOutput());
  spline->SetPriority(1.0);
  spline->KeyPressActivationOff();
  spline->PlaceWidget();
  spline->ProjectToPlaneOn();
  spline->SetProjectionNormal(0);
  spline->SetProjectionPosition(102.4); // initial plane oriented position
  spline->SetProjectionNormal(3);       // allow arbitrary oblique orientations
  spline->SetPlaneSource(planeSource);

  // Specify the type of spline (change from default vtkCardinalSpline)
  vtkKochanekSpline* xspline = vtkKochanekSpline::New();
  vtkKochanekSpline* yspline = vtkKochanekSpline::New();
  vtkKochanekSpline* zspline = vtkKochanekSpline::New();

  vtkParametricSpline* para = spline->GetParametricSpline();

  para->SetXSpline(xspline);
  para->SetYSpline(yspline);
  para->SetZSpline(zspline);

  vtkPolyData* poly = vtkPolyData::New();
  spline->GetPolyData(poly);

  vtkSplineWidgetCallback* swcb = vtkSplineWidgetCallback::New();
  swcb->Poly = poly;

  spline->AddObserver(vtkCommand::InteractionEvent, swcb);

  ren1->SetBackground(0.1, 0.2, 0.4);
  ren1->AddActor(planeSourceActor);

  renWin->SetSize(600, 300);
  renWin->Render();

  spline->On();
  spline->SetNumberOfHandles(4);
  spline->SetNumberOfHandles(5);
  spline->SetResolution(399);

  // Set up an interesting viewpoint
  vtkCamera* camera = ren1->GetActiveCamera();

  // Render the image
  iren->Initialize();
  renWin->Render();

  return EXIT_SUCCESS;
}