File: SplineWidget.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (106 lines) | stat: -rw-r--r-- 3,078 bytes parent folder | download | duplicates (3)
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
#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;
}