NorMIT-nav  22.09
An IGT application
cxToolMetricRep.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 #include "cxToolMetricRep.h"
13 
14 #include "cxView.h"
15 #include "boost/bind.hpp"
16 #include "cxGraphicalAxes3D.h"
17 
18 namespace cx
19 {
20 
22 {
23  return wrap_new(new ToolMetricRep(), uid);
24 }
25 
26 ToolMetricRep::ToolMetricRep()
27 {
28  mViewportListener.reset(new ViewportListener);
29  mViewportListener->setCallback(boost::bind(&ToolMetricRep::rescale, this));
30 }
31 
33 {
34  mToolTip.reset();
35  mToolOffset.reset();
36 
37  mAxes.reset();
39 }
40 
42 {
43  mViewportListener->startListen(view->getRenderer());
45 }
46 
48 {
50  mViewportListener->stopListen();
51 }
52 
53 ToolMetricPtr ToolMetricRep::getToolMetric()
54 {
55  return boost::dynamic_pointer_cast<ToolMetric>(mMetric);
56 }
57 
59 {
60  ToolMetricPtr metric = this->getToolMetric();
61 
62  if (!metric || !metric->isValid() || !this->getView())
63  return;
64 
65  if (!mAxes || !mToolTip || !mToolOffset)
66  {
67  mAxes.reset(new GraphicalAxes3D());
68  mToolTip.reset(new GraphicalPoint3D(this->getRenderer()));
69  mToolOffset.reset(new GraphicalLine3D(this->getRenderer()));
70  }
71 
72  mAxes->setFontSize(0.04);
73  mAxes->setAxisLength(0.05);
74 // mAxes->setAxisLength(0.2);
75  mAxes->setShowAxesLabels(false);
76  mAxes->setRenderer(this->getRenderer());
77 
78  Vector3D p0_r = mMetric->getRefCoord();
79  Transform3D rMt = metric->getRefFrame();
80  Vector3D toolTip_r = rMt.coord(Vector3D(0,0,-metric->getToolOffset()));
81 
82  mToolTip->setValue(toolTip_r);
83  mToolTip->setColor(mMetric->getColor());
84 
85  mToolOffset->setValue(p0_r, toolTip_r);
86  mToolOffset->setColor(mMetric->getColor());
87 
88  mAxes->setTransform(metric->getRefFrame());
89  this->drawText();
90  this->rescale();
91 }
92 
93 void ToolMetricRep::rescale()
94 {
95  if (!mToolTip)
96  return;
97 
98  double size = mViewportListener->getVpnZoom(this->getToolMetric()->getCoordinate());
99  double sphereSize = mGraphicsSize / 100 / size;
100  mToolTip->setRadius(sphereSize);
101 }
102 
103 
104 } // namespace cx
cx::ToolMetricRep::clear
virtual void clear()
Definition: cxToolMetricRep.cpp:32
cx::ToolMetricRep::New
static ToolMetricRepPtr New(const QString &uid="")
Definition: cxToolMetricRep.cpp:21
cx::DataMetricRep::addRepActorsToViewRenderer
void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:89
cx::ToolMetricRep::addRepActorsToViewRenderer
void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxToolMetricRep.cpp:41
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::ToolMetricRep
Definition: cxToolMetricRep.h:40
cx::ToolMetricPtr
boost::shared_ptr< class ToolMetric > ToolMetricPtr
Definition: cxToolMetric.h:24
cx::GraphicalLine3D
Helper for rendering a line in 3D.
Definition: cxGraphicalPrimitives.h:146
cx::ToolMetricRep::onModifiedStartRender
virtual void onModifiedStartRender()
Definition: cxToolMetricRep.cpp:58
cxToolMetricRep.h
cx::ToolMetricRep::removeRepActorsFromViewRenderer
void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxToolMetricRep.cpp:47
cx::DataMetricRep::removeRepActorsFromViewRenderer
void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:100
cx::ToolMetricRepPtr
boost::shared_ptr< class ToolMetricRep > ToolMetricRepPtr
Definition: cxToolMetricRep.h:29
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cxView.h
cx::DataMetricRep::drawText
void drawText()
Definition: cxDataMetricRep.cpp:109
cx::GraphicalAxes3D
Visualization for one 3D coordinate axis triplet.
Definition: cxGraphicalAxes3D.h:38
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::GraphicalPoint3D
Helper for rendering a point in 3D.
Definition: cxGraphicalPrimitives.h:122
cx::DataMetricRep::mGraphicsSize
double mGraphicsSize
Definition: cxDataMetricRep.h:62
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
cxGraphicalAxes3D.h