CustusX  22.04-rc5
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 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
boost::shared_ptr< class DistanceMetricRep2D > DistanceMetricRep2DPtr
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
virtual void addRepActorsToViewRenderer(ViewPtr view)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
static DistanceMetricRep2DPtr New(const QString &uid="")
virtual void clear()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
boost::shared_ptr< class View > ViewPtr
Listens to changes in viewport and camera matrix.
void setSliceProxy(SliceProxyPtr slicer)
void addRepActorsToViewRenderer(ViewPtr view)
Helper for drawing a line in 2D.
Data class that represents a distance between two points, or a point and a plane. ...
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
void removeRepActorsFromViewRenderer(ViewPtr view)
#define CX_LOG_WARNING
Definition: cxLogger.h:98
DataMetricPtr mMetric
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
void setModified()
Definition: cxRepImpl.cpp:112
Namespace for all CustusX production code.