NorMIT-nav  22.09
An IGT application
cxDistanceMetricRep2D.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 "cxDistanceMetricRep2D.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 
23 #include "cxSliceProxy.h"
24 #include "cxView.h"
25 #include "cxVtkHelperClasses.h"
26 #include "cxLogger.h"
27 
28 
29 namespace cx
30 {
31 
33 {
34  return wrap_new(new DistanceMetricRep2D(), uid);
35 }
36 
37 DistanceMetricRep2D::DistanceMetricRep2D()
38 {
39 }
40 
42 {
43  if (on)
44  {
45  mViewportListener.reset(new ViewportListener);
46  }
47  else
48  {
49  mViewportListener.reset();
50  }
51 }
52 
54 {
55  if (mViewportListener)
56  mViewportListener->startListen(view->getRenderer());
58 }
59 
61 {
62  mLine.reset();
63 
64  if (mViewportListener)
65  mViewportListener->stopListen();
67 }
68 
70 {
72 }
73 
75 {
76  if (!mMetric)
77  return;
78 
79  if (!mLine && this->getView() && mMetric && mSliceProxy)
80  {
81  mLine.reset(new LineSegment(this->getRenderer()));
82  mLine->setPoints(Vector3D(0.0, 0.0, 0.0), Vector3D(0.0, 0.0, 0.0), mMetric->getColor());
83  }
84 
85  if (!mLine)
86  return;
87 
88  Vector3D position = mSliceProxy->get_sMr() * mMetric->getRefCoord();
89 
90 
91  mLine->setWidth(2);
92 
93  mLine->setColor(mMetric->getColor());
94  DistanceMetricPtr distanceMetric = boost::dynamic_pointer_cast<DistanceMetric>(mMetric);
95  if(!distanceMetric)
96  {
97  CX_LOG_WARNING() << "DistanceMetricRep2D: Got no DistanceMetric";
98  return;
99  }
100  std::vector<Vector3D> points_r = distanceMetric->getEndpoints();
101 
102  Transform3D vpMs = getView()->get_vpMs();
103  Transform3D sMr = mSliceProxy->get_sMr();
104  Vector3D p1_vp = vpMs * sMr * points_r[0];
105  Vector3D p2_vp = vpMs * sMr * points_r[1];
106 
107 
108  mLine->updatePosition(p1_vp, p2_vp);
109 }
110 
112 {
113  if (mSliceProxy)
114  disconnect(mSliceProxy.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(setModified()));
115  mSliceProxy = sliceProxy;
116  if (mSliceProxy)
117  connect(mSliceProxy.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(setModified()));
118  this->setModified();
119 }
120 
121 }
cx::LineSegment
Helper for drawing a line in 2D.
Definition: cxVtkHelperClasses.h:87
cxLogger.h
cx::DataMetricRep::addRepActorsToViewRenderer
void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:89
cx::DistanceMetricRep2D::setSliceProxy
void setSliceProxy(SliceProxyPtr slicer)
Definition: cxDistanceMetricRep2D.cpp:111
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ViewportListener
Listens to changes in viewport and camera matrix.
Definition: cxViewportListener.h:67
cx::DataMetricRep::clear
virtual void clear()
Definition: cxDataMetricRep.cpp:84
cx::RepImpl::getRenderer
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
cx::DistanceMetricRep2D
Definition: cxDistanceMetricRep2D.h:35
cx::DistanceMetricRep2D::New
static DistanceMetricRep2DPtr New(const QString &uid="")
Definition: cxDistanceMetricRep2D.cpp:32
cx::RepImpl::getView
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
cx::SliceProxyPtr
boost::shared_ptr< class SliceProxy > SliceProxyPtr
Definition: cxForwardDeclarations.h:96
cx::DistanceMetricRep2D::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxDistanceMetricRep2D.cpp:53
cx::DataMetricRep::removeRepActorsFromViewRenderer
void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:100
cxDistanceMetricRep2D.h
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::DistanceMetricRep2D::clear
virtual void clear()
Definition: cxDistanceMetricRep2D.cpp:69
cxView.h
cx::DistanceMetricRep2D::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxDistanceMetricRep2D.cpp:60
cx::DistanceMetricRep2DPtr
boost::shared_ptr< class DistanceMetricRep2D > DistanceMetricRep2DPtr
Definition: cxDistanceMetricRep2D.h:25
cx::DistanceMetricRep2D::setDynamicSize
void setDynamicSize(bool on)
Definition: cxDistanceMetricRep2D.cpp:41
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl::setModified
void setModified()
Definition: cxRepImpl.cpp:112
cxVtkHelperClasses.h
cx::DistanceMetricRep2D::onModifiedStartRender
virtual void onModifiedStartRender()
Definition: cxDistanceMetricRep2D.cpp:74
CX_LOG_WARNING
#define CX_LOG_WARNING
Definition: cxLogger.h:98
cx::DistanceMetricPtr
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
Definition: cxForwardDeclarations.h:67
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