Fraxinus  16.5.0-fx-rc7
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxToolMetricRep.h"
34 
35 #include "cxView.h"
36 #include "boost/bind.hpp"
37 #include "cxGraphicalAxes3D.h"
38 
39 namespace cx
40 {
41 
43 {
44  return wrap_new(new ToolMetricRep(), uid);
45 }
46 
47 ToolMetricRep::ToolMetricRep()
48 {
49  mViewportListener.reset(new ViewportListener);
50  mViewportListener->setCallback(boost::bind(&ToolMetricRep::rescale, this));
51 }
52 
54 {
55  mToolTip.reset();
56  mToolOffset.reset();
57 
58  mAxes.reset();
60 }
61 
63 {
64  mViewportListener->startListen(view->getRenderer());
66 }
67 
69 {
71  mViewportListener->stopListen();
72 }
73 
74 ToolMetricPtr ToolMetricRep::getToolMetric()
75 {
76  return boost::dynamic_pointer_cast<ToolMetric>(mMetric);
77 }
78 
80 {
81  ToolMetricPtr metric = this->getToolMetric();
82 
83  if (!metric || !metric->isValid() || !this->getView())
84  return;
85 
86  if (!mAxes || !mToolTip || !mToolOffset)
87  {
88  mAxes.reset(new GraphicalAxes3D());
89  mToolTip.reset(new GraphicalPoint3D(this->getRenderer()));
90  mToolOffset.reset(new GraphicalLine3D(this->getRenderer()));
91  }
92 
93  mAxes->setFontSize(0.04);
94  mAxes->setAxisLength(0.05);
95 // mAxes->setAxisLength(0.2);
96  mAxes->setShowAxesLabels(false);
97  mAxes->setRenderer(this->getRenderer());
98 
99  Vector3D p0_r = mMetric->getRefCoord();
100  Transform3D rMt = metric->getRefFrame();
101  Vector3D toolTip_r = rMt.coord(Vector3D(0,0,-metric->getToolOffset()));
102 
103  mToolTip->setValue(toolTip_r);
104  mToolTip->setColor(mMetric->getColor());
105 
106  mToolOffset->setValue(p0_r, toolTip_r);
107  mToolOffset->setColor(mMetric->getColor());
108 
109  mAxes->setTransform(metric->getRefFrame());
110  this->drawText();
111  this->rescale();
112 }
113 
114 void ToolMetricRep::rescale()
115 {
116  if (!mToolTip)
117  return;
118 
119  double size = mViewportListener->getVpnZoom();
120  double sphereSize = mGraphicsSize / 100 / size;
121  mToolTip->setRadius(sphereSize);
122 }
123 
124 
125 } // namespace cx
ViewPtr getView() const
Definition: cxRepImpl.cpp:104
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:109
boost::shared_ptr< class ToolMetric > ToolMetricPtr
Definition: cxToolMetric.h:45
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:83
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:63
virtual void clear()
void removeRepActorsFromViewRenderer(ViewPtr view)
DataMetricPtr mMetric
void removeRepActorsFromViewRenderer(ViewPtr view)