NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxGuideRep2D.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 
14 #include "cxGuideRep2D.h"
15 #include "boost/bind.hpp"
16 
17 #include <vtkActor.h>
18 #include <vtkPolyDataMapper.h>
19 #include <vtkProperty.h>
20 #include <vtkRenderer.h>
21 #include <vtkSectorSource.h>
22 #include "cxTool.h"
23 
24 #include "cxSliceProxy.h"
25 #include "cxView.h"
26 #include "cxPatientModelService.h"
27 
28 namespace cx
29 {
30 
31 GuideRep2DPtr GuideRep2D::New(PatientModelServicePtr dataManager, const QString& uid)
32 {
33  return wrap_new(new GuideRep2D(dataManager), uid);
34 }
35 
36 GuideRep2D::GuideRep2D(PatientModelServicePtr dataManager) :
37  mDataManager(dataManager),
38  mOutlineWidth(1),
39  mRequestedAccuracy(1)
40 {
41 }
42 
43 
45 {
46  if (this->getView())
47  this->getView()->getRenderer()->RemoveActor(mCircleActor);
48 }
49 
51 {
52  if (!mMetric)
53  return;
54 
55  if (!mCircleActor && this->getView() && mMetric && mSliceProxy)
56  {
57  mCircleSource = vtkSectorSource::New();
58  mCircleSource->SetOuterRadius(mGraphicsSize);
59  mCircleSource->SetInnerRadius(0);
60  mCircleSource->SetStartAngle(0);
61  mCircleSource->SetEndAngle(360);
62  mCircleSource->SetCircumferentialResolution(60);
63  vtkPolyDataMapperPtr mapper = vtkPolyDataMapper::New();
64  mapper->SetInputConnection(mCircleSource->GetOutputPort());
65  mapper->ScalarVisibilityOff();
66  mCircleActor = vtkActor::New();
67  mCircleActor->SetMapper(mapper);
68  mCircleActor->GetProperty()->LightingOff();
69  this->getRenderer()->AddActor(mCircleActor);
70 
71  }
72 
73  if (!mCircleActor)
74  return;
75  if (!mSliceProxy->getTool())
76  {
77  return;
78  }
79 
80  double toolOffset = mSliceProxy->getTool()->getTooltipOffset();
81  Transform3D rMt = mDataManager->get_rMpr()*mSliceProxy->getTool()->get_prMt();
82  Vector3D toolOffsetPosRef = rMt.coord(Vector3D(0,0,toolOffset));
83  Vector3D toolPosRef = rMt.coord(Vector3D(0,0,0));
84 
85  Vector3D centerRef = mMetric->getRefCoord() + 0.5*(toolOffsetPosRef - mMetric->getRefCoord());
86  Vector3D position = mSliceProxy->get_sMr() * centerRef;
87  mCircleActor->SetPosition(position[0], position[1], 0);
88 
89  const double margin = 10;
90  double offsetDistance = (mMetric->getRefCoord() - toolOffsetPosRef).length();
91  double distance = (mMetric->getRefCoord() - toolPosRef).length();
92  double radius = 0.5 * offsetDistance + margin;
93  mCircleSource->SetOuterRadius(radius);
94  mCircleSource->SetInnerRadius(radius - mOutlineWidth);
95 
96  if (distance < mRequestedAccuracy)
97  {
98  mCircleActor->GetProperty()->SetColor(0, 1, 1);
99  }
100  else if (offsetDistance < mRequestedAccuracy && toolOffset >= 0 && distance < 4*mRequestedAccuracy)
101  {
102  mCircleActor->GetProperty()->SetColor(0, 1, 1.0 - (distance-mRequestedAccuracy)/(3*mRequestedAccuracy));
103  }
104  else if (offsetDistance < mRequestedAccuracy && toolOffset >= 0)
105  {
106  mCircleActor->GetProperty()->SetColor(0, 1, 0);
107  }
108  else
109  {
110  mCircleActor->GetProperty()->SetColor(1, 0, 0);
111  }
112 
113 }
114 
116 {
117  if (mSliceProxy)
118  disconnect(mSliceProxy.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(setModified()));
119  mSliceProxy = sliceProxy;
120  if (mSliceProxy)
121  connect(mSliceProxy.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(setModified()));
122  this->setModified();
123 }
124 
125 void GuideRep2D::setOutlineWidth(double width)
126 {
127  mOutlineWidth = width;
128  this->setModified();
129 }
130 
131 void GuideRep2D::setRequestedAccuracy(double accuracy)
132 {
133  mRequestedAccuracy = accuracy;
134  this->setModified();
135 }
136 
137 }
cx::GuideRep2D
Definition: cxGuideRep2D.h:36
cxGuideRep2D.h
cx::GuideRep2D::setSliceProxy
void setSliceProxy(SliceProxyPtr slicer)
Definition: cxGuideRep2D.cpp:115
cx::GuideRep2D::setRequestedAccuracy
void setRequestedAccuracy(double accuracy)
Definition: cxGuideRep2D.cpp:131
cx::GuideRep2D::setOutlineWidth
void setOutlineWidth(double width)
Definition: cxGuideRep2D.cpp:125
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::RepImpl::getRenderer
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
cx::GuideRep2D::clear
virtual void clear()
Definition: cxGuideRep2D.cpp:44
cx::GuideRep2D::onModifiedStartRender
virtual void onModifiedStartRender()
Definition: cxGuideRep2D.cpp:50
vtkPolyDataMapperPtr
vtkSmartPointer< class vtkPolyDataMapper > vtkPolyDataMapperPtr
Definition: vtkForwardDeclarations.h:112
cx::RepImpl::getView
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
cx::SliceProxyPtr
boost::shared_ptr< class SliceProxy > SliceProxyPtr
Definition: cxForwardDeclarations.h:96
length
RealScalar length() const
Definition: cxMatrixBaseEigenAddons.h:35
cx::GuideRep2D::New
static GuideRep2DPtr New(PatientModelServicePtr dataManager, const QString &uid="")
Definition: cxGuideRep2D.cpp:31
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cxTool.h
cxView.h
cx::GuideRep2DPtr
boost::shared_ptr< class GuideRep2D > GuideRep2DPtr
Definition: cxForwardDeclarations.h:75
cxPatientModelService.h
cx::RepImpl::setModified
void setModified()
Definition: cxRepImpl.cpp:112
cx::DataMetricRep::mGraphicsSize
double mGraphicsSize
Definition: cxDataMetricRep.h:62
cxSliceProxy.h
cx::DataMetricRep::mMetric
DataMetricPtr mMetric
Definition: cxDataMetricRep.h:68
cx::RepImpl::wrap_new
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42