Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkNavigationToolCreationAdvancedWidget.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
19 
20 // mitk includes
21 #include <mitkRenderingManager.h>
22 #include <mitkNodePredicateNot.h>
24 
25 // vtk includes
26 #include <vtkSphereSource.h>
27 #include <vtkConeSource.h>
28 
29 const std::string QmitkNavigationToolCreationAdvancedWidget::VIEW_ID = "org.mitk.views.navigationtoolcreationadvancedwidget";
30 
32  : QDialog(parent, f), m_Controls(NULL), m_DataStorage(NULL), m_ToolTipSurface(NULL), m_ManipulatedToolTip(NULL),
33  m_SurfaceNodeName("")
34 {
35  CreateQtPartControl(this);
37 }
38 
40 {
41 }
42 
44  {
45  if (!m_Controls)
46  {
47  // create GUI widgets
48  m_Controls = new Ui::QmitkNavigationToolCreationAdvancedWidgetControls;
49  m_Controls->setupUi(parent);
50  }
51  }
52 
54  {
55  if ( m_Controls )
56  {
57  connect( (QObject*)(this), SIGNAL(finished(int)), this, SLOT(OnClose()));
58  connect( (QObject*)(m_Controls->m_InteractiveTransformation), SIGNAL(ApplyManipulatedToolTip()), this, SLOT(OnApplyManipulatedToolTip()));
59  }
60  }
61 
63 {
64  //clean the data storage
65  if(m_DataStorage->Exists(m_DataStorage->GetNamedNode("StandardToolTip")))
66  {
67  m_DataStorage->Remove(m_DataStorage->GetNamedNode("StandardToolTip"));
68  }
69 
70  if(m_DataStorage.IsNotNull() && m_DataStorage->Exists(m_DataStorage->GetNamedNode("ManipulatedToolTip")))
71  {
72  m_DataStorage->Remove(m_DataStorage->GetNamedNode("ManipulatedToolTip"));
73  }
74 
75  emit DialogCloseRequested();
76 }
77 
79 {
80  m_DataStorage = dataStorage;
81 }
82 
84 {
85  if (m_DataStorage.IsNull()) return;
86 
87  //reset some variables
88  m_ManipulatedToolTip = NULL;
89  m_ToolTipSurface = NULL;
90  m_SurfaceNodeName = "";
92  mitk::BaseGeometry::Pointer emptyGeo = dynamic_cast<mitk::BaseGeometry*>(geo3d.GetPointer());
93  m_Controls->m_InteractiveTransformation->SetGeometry(emptyGeo,emptyGeo);
94 
95  //call initialization method
97 
98  //care for new data nodes
99  mitk::DataNode::Pointer manipulatedTipNode = NULL;
100  if(!m_DataStorage->Exists(m_DataStorage->GetNamedNode("ManipulatedToolTip")))
101  {
102  manipulatedTipNode = mitk::DataNode::New();
103  manipulatedTipNode->SetData(m_ManipulatedToolTip);
104  manipulatedTipNode->SetName("ManipulatedToolTip");
105  manipulatedTipNode->SetColor(1.0, 0.0, 0.0);
106  manipulatedTipNode->SetOpacity(0.5);
107  m_DataStorage->Add(manipulatedTipNode);
108  }
109  else
110  {
111  manipulatedTipNode = m_DataStorage->GetNamedNode("ManipulatedToolTip");
112  manipulatedTipNode->SetData(m_ManipulatedToolTip);
113  }
114 
115  // reinit the views with the new nodes
117 }
118 
120 {
121  // we need the tooltip surface (point or stl)
123 
124  if(m_ToolTipSurface.IsNotNull())
125  {
126  mitk::DataNode::Pointer toolTipNode = NULL;
127 
128  if(m_SurfaceNodeName.empty())
129  {
130  m_SurfaceNodeName = "StandardToolTip";
131  }
132 
133  if(!m_DataStorage->Exists(m_DataStorage->GetNamedNode(m_SurfaceNodeName)))
134  {
135  toolTipNode = mitk::DataNode::New();
136  toolTipNode->SetName(m_SurfaceNodeName);
137  toolTipNode->SetData(m_ToolTipSurface);
138  m_DataStorage->Add(toolTipNode);
139 
140  }
141  else
142  {
143  toolTipNode = m_DataStorage->GetNamedNode(m_SurfaceNodeName);
144  toolTipNode->SetData(m_ToolTipSurface);
145  }
146 
148 
149  mitk::BaseGeometry::Pointer defaultGeo = dynamic_cast<mitk::BaseGeometry*> (mitk::Geometry3D::New().GetPointer());
150  defaultGeo->SetIndexToWorldTransform(m_DefaultToolTip);
151 
152  m_Controls->m_InteractiveTransformation->SetGeometry(m_ManipulatedToolTip->GetGeometry(),defaultGeo);
153  }
154  else
155  {
156  mitkThrow() << "No tooltip surface specified, operation aborted";
157  }
158 }
159 
161 {
162  m_DefaultToolTip = defaultToolTip;
163 }
164 
166 {
167  m_ToolTipSurface = NULL;
168  if(cone)
169  {
171  vtkConeSource *vtkData = vtkConeSource::New();
172  vtkData->SetAngle(5.0);
173  vtkData->SetResolution(50);
174  vtkData->SetHeight(6.0f);
175  vtkData->SetRadius(2.0f);
176  vtkData->SetCenter(0.0, 0.0, 0.0);
177 
178  vtkData->Update();
179  m_ToolTipSurface->SetVtkPolyData(vtkData->GetOutput());
180 
181  vtkData->Delete();
182  m_SurfaceNodeName ="";
183  }
184  else if(!cone && node.IsNotNull())
185  {
186  m_ToolTipSurface = dynamic_cast<mitk::Surface*>(node->GetData());
187  m_SurfaceNodeName = node->GetName();
188  }
189 }
190 
192 {
193  //save manipulated surface object, which holds the tooltip as geometry
194  m_ManipulatedToolTip = dynamic_cast<mitk::Surface*>(m_DataStorage->GetNamedNode("ManipulatedToolTip")->GetData()->Clone().GetPointer());
195  //then close the window
196  OnClose();
197 }
198 
200 {
202  if (m_ManipulatedToolTip.IsNotNull()) returnValue = m_ManipulatedToolTip->GetGeometry()->GetIndexToWorldTransform();
203  else returnValue->SetIdentity();
204  return returnValue;
205 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
void SetToolTipSurface(bool cone, mitk::DataNode::Pointer node=NULL)
itk::SmartPointer< Self > Pointer
Ui::QmitkNavigationToolCreationAdvancedWidgetControls * m_Controls
static Pointer New()
void SetDataStorage(mitk::DataStorage::Pointer dataStorage)
mitk::DataStorage::Pointer m_DataStorage
static Pointer New()
void SetDefaultTooltip(mitk::AffineTransform3D::Pointer defaultToolTip)
static RenderingManager * GetInstance()
#define mitkThrow()
mitk::Surface::Pointer m_ManipulatedToolTip
manipulated surface object, which holds the tooltip as geometry
virtual void InitializeViewsByBoundingObjects(const DataStorage *)
Initializes the renderwindows by the aggregated geometry of all objects that are held in the data sto...
static Pointer New()
BaseGeometry Describes the geometry of a data object.
QmitkNavigationToolCreationAdvancedWidget(QWidget *parent=0, Qt::WindowFlags f=0)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.