NorMIT-nav  22.09
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 }
cx::PointMetricRep2D::New
static PointMetricRep2DPtr New(const QString &uid="")
Definition: cxPointMetricRep2D.cpp:31
cx::PointMetricRep2D::onModifiedStartRender
virtual void onModifiedStartRender()
Definition: cxPointMetricRep2D.cpp:74
cx::PointMetricRep2DPtr
boost::shared_ptr< class PointMetricRep2D > PointMetricRep2DPtr
Definition: cxForwardDeclarations.h:86
cx::DataMetricRep::addRepActorsToViewRenderer
void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:89
cxPointMetricRep2D.h
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::GraphicalDisk
Definition: cxGraphicalDisk.h:32
cx::RepImpl::getView
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
cx::SliceProxyPtr
boost::shared_ptr< class SliceProxy > SliceProxyPtr
Definition: cxForwardDeclarations.h:96
cx::DataMetricRep::removeRepActorsFromViewRenderer
void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:100
cx::PointMetricRep2D::setSliceProxy
void setSliceProxy(SliceProxyPtr slicer)
Definition: cxPointMetricRep2D.cpp:122
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::PointMetricRep2D
Definition: cxPointMetricRep2D.h:37
cx::PointMetricRep2D::clear
virtual void clear()
Definition: cxPointMetricRep2D.cpp:69
cxView.h
cxGraphicalDisk.h
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::PointMetricRep2D::setDynamicSize
void setDynamicSize(bool on)
Definition: cxPointMetricRep2D.cpp:40
cx::PointMetricRep2D::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxPointMetricRep2D.cpp:60
cx::RepImpl::setModified
void setModified()
Definition: cxRepImpl.cpp:112
cx::PointMetricRep2D::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxPointMetricRep2D.cpp:53
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