Fraxinus  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
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
boost::shared_ptr< class ToolMetric > ToolMetricPtr
Definition: cxToolMetric.h:24
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Visualization for one 3D coordinate axis triplet.
boost::shared_ptr< class ToolMetricRep > ToolMetricRepPtr
virtual void clear()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
Helper for rendering a point in 3D.
boost::shared_ptr< class View > ViewPtr
static ToolMetricRepPtr New(const QString &uid="")
Listens to changes in viewport and camera matrix.
void addRepActorsToViewRenderer(ViewPtr view)
void addRepActorsToViewRenderer(ViewPtr view)
Helper for rendering a line in 3D.
virtual void onModifiedStartRender()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
virtual void clear()
void removeRepActorsFromViewRenderer(ViewPtr view)
DataMetricPtr mMetric
void removeRepActorsFromViewRenderer(ViewPtr view)
Namespace for all CustusX production code.