CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxPointMetricRep2D.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 "cxPointMetricRep2D.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 "cxGraphicalDisk.h"
26 
27 
28 namespace cx
29 {
30 
32 {
33  return wrap_new(new PointMetricRep2D(), uid);
34 }
35 
36 PointMetricRep2D::PointMetricRep2D()
37 {
38 }
39 
41 {
42  if (on)
43  {
44  mViewportListener.reset(new ViewportListener);
45  //mViewportListener->setCallback(boost::bind(&PointMetricRep2D::rescale, this));
46  }
47  else
48  {
49  mViewportListener.reset();
50  }
51 }
52 
54 {
55  if (mViewportListener)
56  mViewportListener->startListen(view->getRenderer());
58 }
59 
61 {
62  mDisk.reset();
63 
64  if (mViewportListener)
65  mViewportListener->stopListen();
67 }
68 
70 {
72 }
73 
75 {
76  if (!mMetric)
77  return;
78 
79  if (!mDisk && this->getView() && mMetric && mSliceProxy)
80  {
81  mDisk.reset(new GraphicalDisk());
82  mDisk->setRenderer(this->getRenderer());
83  }
84 
85  if (!mDisk)
86  return;
87 
88  Vector3D position = mSliceProxy->get_sMr() * mMetric->getRefCoord();
89 
90  mDisk->setColor(mMetric->getColor());
91  mDisk->setOutlineColor(mMetric->getColor());
92  mDisk->setOutlineWidth(0.25);
93  mDisk->setFillVisible(false);
94 
95  mDisk->setRadiusBySlicingSphere(this->findSphereRadius(), position[2]);
96 
97  Vector3D projectedPosition = position;
98  double offsetFromXYPlane = 0.01;
99  projectedPosition[2] = offsetFromXYPlane;
100  mDisk->setPosition(projectedPosition);
101 
102  mDisk->update();
103 }
104 
105 double PointMetricRep2D::findSphereRadius()
106 {
107  double radius = mGraphicsSize;
108  if (mViewportListener)
109  {
110  double size = mViewportListener->getVpnZoom();
111  radius = mGraphicsSize / 100 / size * 2.5;
112  }
113 
114  return radius;
115 }
116 
117 //void PointMetricRep2D::rescale()
118 //{
119 // this->setModified();
120 //}
121 
123 {
124  if (mSliceProxy)
125  disconnect(mSliceProxy.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(setModified()));
126  mSliceProxy = sliceProxy;
127  if (mSliceProxy)
128  connect(mSliceProxy.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(setModified()));
129  this->setModified();
130 }
131 
132 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
virtual void clear()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
boost::shared_ptr< class PointMetricRep2D > PointMetricRep2DPtr
boost::shared_ptr< class View > ViewPtr
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
static PointMetricRep2DPtr New(const QString &uid="")
Listens to changes in viewport and camera matrix.
void addRepActorsToViewRenderer(ViewPtr view)
virtual void addRepActorsToViewRenderer(ViewPtr view)
virtual void onModifiedStartRender()
void setSliceProxy(SliceProxyPtr slicer)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
void removeRepActorsFromViewRenderer(ViewPtr view)
DataMetricPtr mMetric
void setModified()
Definition: cxRepImpl.cpp:112
Namespace for all CustusX production code.