forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkTensorProbeWidget.cxx
145 lines (119 loc) · 4.18 KB
/
vtkTensorProbeWidget.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
140
141
142
143
144
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTensorProbeWidget.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkTensorProbeWidget.h"
#include "vtkCallbackCommand.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkRenderWindow.h"
#include "vtkWidgetEventTranslator.h"
#include "vtkWidgetCallbackMapper.h"
#include "vtkEvent.h"
#include "vtkWidgetEvent.h"
#include "vtkEllipsoidTensorProbeRepresentation.h"
#include "vtkMath.h"
#include "vtkLine.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
vtkStandardNewMacro(vtkTensorProbeWidget);
//----------------------------------------------------------------------
vtkTensorProbeWidget::vtkTensorProbeWidget()
{
// These are the event callbacks supported by this widget
this->CallbackMapper->SetCallbackMethod(
vtkCommand::LeftButtonPressEvent,
vtkWidgetEvent::Select,
this, vtkTensorProbeWidget::SelectAction);
this->CallbackMapper->SetCallbackMethod(
vtkCommand::LeftButtonReleaseEvent,
vtkWidgetEvent::EndSelect,
this, vtkTensorProbeWidget::EndSelectAction);
this->CallbackMapper->SetCallbackMethod(
vtkCommand::MouseMoveEvent,
vtkWidgetEvent::Move,
this, vtkTensorProbeWidget::MoveAction);
this->Selected = 0;
}
//----------------------------------------------------------------------
vtkTensorProbeWidget::~vtkTensorProbeWidget()
{
}
//----------------------------------------------------------------------
void vtkTensorProbeWidget::CreateDefaultRepresentation()
{
if ( ! this->WidgetRep )
{
this->WidgetRep = vtkEllipsoidTensorProbeRepresentation::New();
}
}
//-------------------------------------------------------------------------
void vtkTensorProbeWidget::SelectAction(vtkAbstractWidget *w)
{
vtkTensorProbeWidget *self =
reinterpret_cast<vtkTensorProbeWidget*>(w);
if ( !self->Selected )
{
vtkTensorProbeRepresentation *rep = reinterpret_cast<
vtkTensorProbeRepresentation*>(self->WidgetRep);
int pos[2];
self->Interactor->GetEventPosition(pos);
if (rep->SelectProbe(pos))
{
self->LastEventPosition[0] = pos[0];
self->LastEventPosition[1] = pos[1];
self->Selected = 1;
self->EventCallbackCommand->SetAbortFlag(1);
}
}
}
//-------------------------------------------------------------------------
void vtkTensorProbeWidget::EndSelectAction(vtkAbstractWidget *w)
{
vtkTensorProbeWidget *self =
reinterpret_cast<vtkTensorProbeWidget*>(w);
if ( self->Selected )
{
self->Selected = 0;
self->EventCallbackCommand->SetAbortFlag(1);
self->LastEventPosition[0] = -1;
self->LastEventPosition[1] = -1;
}
}
//-------------------------------------------------------------------------
void vtkTensorProbeWidget::MoveAction(vtkAbstractWidget *w)
{
vtkTensorProbeWidget *self =
reinterpret_cast<vtkTensorProbeWidget*>(w);
if ( self->Selected )
{
vtkTensorProbeRepresentation *rep = reinterpret_cast<
vtkTensorProbeRepresentation*>(self->WidgetRep);
int pos[2];
self->Interactor->GetEventPosition(pos);
int delta0 = pos[0] - self->LastEventPosition[0];
int delta1 = pos[1] - self->LastEventPosition[1];
double motionVector[2] = { static_cast<double>(delta0),
static_cast<double>(delta1) };
self->LastEventPosition[0] = pos[0];
self->LastEventPosition[1] = pos[1];
if (rep->Move( motionVector ))
{
self->EventCallbackCommand->SetAbortFlag(1);
self->Render();
}
}
}
//----------------------------------------------------------------------
void vtkTensorProbeWidget::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}