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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
#include "GenericView3D.h"
#include "Generic3DModel.h"
#include "Generic3DRenderer.h"
#include "GlobalUIModel.h"
#include "GlobalState.h"
#include "vtkGenericRenderWindowInteractor.h"
#include <QEvent>
#include <QMouseEvent>
#include <vtkInteractorStyle.h>
#include <vtkInteractorStyleUser.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkCommand.h>
#include <QtVTKInteractionDelegateWidget.h>
#include <vtkPointPicker.h>
#include <vtkRendererCollection.h>
#include <vtkObjectFactory.h>
#include <vtkInteractorStyleSwitch.h>
#include "Window3DPicker.h"
#include "IRISApplication.h"
class CursorPlacementInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static CursorPlacementInteractorStyle* New();
vtkTypeMacro(CursorPlacementInteractorStyle, vtkInteractorStyleTrackballCamera)
irisGetSetMacro(Model, Generic3DModel *)
virtual void OnLeftButtonDown()
{
if(!m_Model->PickSegmentationVoxelUnderMouse(
this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1]))
{
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
}
private:
Generic3DModel *m_Model;
};
class SpraycanInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static SpraycanInteractorStyle* New();
vtkTypeMacro(SpraycanInteractorStyle, vtkInteractorStyleTrackballCamera)
irisGetSetMacro(Model, Generic3DModel *)
virtual void OnLeftButtonDown()
{
// Spray a voxel
if(m_Model->SpraySegmentationVoxelUnderMouse(
this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1]))
{
m_IsPainting = true;
}
else
{
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
}
virtual void OnLeftButtonUp()
{
if(m_IsPainting)
m_IsPainting = false;
else
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
}
virtual void OnMouseMove()
{
if(m_IsPainting)
m_Model->SpraySegmentationVoxelUnderMouse(
this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1]);
else
vtkInteractorStyleTrackballCamera::OnMouseMove();
}
protected:
SpraycanInteractorStyle() : m_IsPainting(false), m_Model(NULL) {}
virtual ~SpraycanInteractorStyle() {}
private:
Generic3DModel *m_Model;
bool m_IsPainting;
};
class ScalpelInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static ScalpelInteractorStyle* New();
vtkTypeMacro(ScalpelInteractorStyle, vtkInteractorStyleTrackballCamera)
irisGetSetMacro(Model, Generic3DModel *)
virtual void OnLeftButtonDown()
{
Vector2i xevent(this->Interactor->GetEventPosition());
switch(m_Model->GetScalpelStatus())
{
case Generic3DModel::SCALPEL_LINE_NULL:
// Holding and dragging the LMB acts as a trackball, only clicking
// the LMB causes drawing operations
m_ClickStart = xevent;
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
// m_Model->SetScalpelStartPoint(xevent[0], xevent[1]);
break;
case Generic3DModel::SCALPEL_LINE_STARTED:
m_Model->SetScalpelEndPoint(xevent[0], xevent[1], true);
break;
case Generic3DModel::SCALPEL_LINE_COMPLETED:
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
break;
}
}
virtual void OnMouseMove()
{
Vector2i xevent(this->Interactor->GetEventPosition());
switch(m_Model->GetScalpelStatus())
{
case Generic3DModel::SCALPEL_LINE_STARTED:
m_Model->SetScalpelEndPoint(xevent[0], xevent[1], false);
break;
default:
vtkInteractorStyleTrackballCamera::OnMouseMove();
break;
}
}
virtual void OnLeftButtonUp()
{
Vector2i xevent(this->Interactor->GetEventPosition());
Vector2i delta = xevent - m_ClickStart;
// Detect a click, which starts scalpel drawing
if(m_Model->GetScalpelStatus() == Generic3DModel::SCALPEL_LINE_NULL)
{
if(delta.squared_magnitude() < 4)
{
m_Model->SetScalpelStartPoint(xevent[0], xevent[1]);
}
}
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
}
virtual void OnEnter()
{
vtkInteractorStyleTrackballCamera::OnEnter();
// Record that we're inside
m_Inside = true;
// Record the end point
OnMouseMove();
}
virtual void OnLeave()
{
vtkInteractorStyleTrackballCamera::OnLeave();
// Record that we're inside
m_Inside = false;
}
irisGetMacro(Inside,bool)
protected:
ScalpelInteractorStyle() : m_Model(NULL) {}
virtual ~ScalpelInteractorStyle() {}
Generic3DModel *m_Model;
Vector2i m_ClickStart;
bool m_Inside;
};
vtkStandardNewMacro(CursorPlacementInteractorStyle)
vtkStandardNewMacro(SpraycanInteractorStyle)
vtkStandardNewMacro(ScalpelInteractorStyle)
GenericView3D::GenericView3D(QWidget *parent) :
QtVTKRenderWindowBox(parent)
{
// Create the interactor styles for each mode
m_InteractionStyle[TRACKBALL_MODE]
= vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
m_InteractionStyle[CROSSHAIRS_3D_MODE]
= vtkSmartPointer<CursorPlacementInteractorStyle>::New();
m_InteractionStyle[SCALPEL_MODE]
= vtkSmartPointer<ScalpelInteractorStyle>::New();
m_InteractionStyle[SPRAYPAINT_MODE]
= vtkSmartPointer<SpraycanInteractorStyle>::New();
}
GenericView3D::~GenericView3D()
{
}
void GenericView3D::SetModel(Generic3DModel *model)
{
m_Model = model;
// Assign the renderer
this->SetRenderer(m_Model->GetRenderer());
// Pass the model to the different interactors
CursorPlacementInteractorStyle::SafeDownCast(
m_InteractionStyle[CROSSHAIRS_3D_MODE])->SetModel(model);
SpraycanInteractorStyle::SafeDownCast(
m_InteractionStyle[SPRAYPAINT_MODE])->SetModel(model);
ScalpelInteractorStyle::SafeDownCast(
m_InteractionStyle[SCALPEL_MODE])->SetModel(model);
// Listen to toolbar changes
connectITK(m_Model->GetParentUI()->GetGlobalState()->GetToolbarMode3DModel(),
ValueChangedEvent(), SLOT(onToolbarModeChange()));
// Use the current toolbar settings
this->onToolbarModeChange();
}
void GenericView3D::onToolbarModeChange()
{
int mode = (int) m_Model->GetParentUI()->GetGlobalState()->GetToolbarMode3D();
m_Model->GetRenderer()->GetRenderWindowInteractor()
->SetInteractorStyle(m_InteractionStyle[mode]);
setMouseTracking(mode == SCALPEL_MODE);
}
|