NorMIT-nav  22.09
An IGT application
cxDataMetricRep.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 "cxDataMetricRep.h"
15 
16 #include "cxGraphicalPrimitives.h"
17 #include "cxView.h"
18 #include "cxDataMetric.h"
19 
20 #include "cxVtkHelperClasses.h"
21 
22 namespace cx
23 {
24 
26  RepImpl(),
27  mGraphicsSize(1),
28  mShowLabel(false),
29  mLabelSize(2.5),
30  mShowAnnotation(true)
31 // mView(NULL)
32 {
33 }
34 
36 {
37  if (mMetric)
38  {
39  disconnect(mMetric.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
40  disconnect(mMetric.get(), SIGNAL(propertiesChanged()), this, SLOT(setModified()));
41  }
42 
43  mMetric = value;
44 
45  if (mMetric)
46  {
47  connect(mMetric.get(), SIGNAL(propertiesChanged()), this, SLOT(setModified()));
48  connect(mMetric.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
49  }
50 
51  this->clear();
52  this->setModified();
53 }
54 
56 {
57  return mMetric;
58 }
59 
61 {
62  mShowLabel = on;
63  this->setModified();
64 }
65 
67 {
68  mGraphicsSize = size;
69  this->setModified();
70 }
71 
72 void DataMetricRep::setLabelSize(double size)
73 {
74  mLabelSize = size;
75  this->setModified();
76 }
77 
79 {
80  mShowAnnotation = on;
81  this->setModified();
82 }
83 
85 {
86  mText.reset();
87 }
88 
90 {
91 // mView = view;
92 
93 // vtkRendererPtr renderer = mView->getRenderer();
94 // renderer->AddObserver(vtkCommand::StartEvent, this->mCallbackCommand, 1.0);
95 
96  this->clear();
97  this->setModified();
98 }
99 
101 {
102 // vtkRendererPtr renderer = mView->getRenderer();
103 // renderer->RemoveObserver(this->mCallbackCommand);
104 
105 // mView = NULL;
106  this->clear();
107 }
108 
110 {
111  if (!this->getView())
112  return;
113 
114  QString text = this->getText();
115 
116  if (text.isEmpty())
117  {
118  mText.reset();
119  return;
120  }
121 
122  if (!mText)
123  {
124  mText.reset(new CaptionText3D(this->getRenderer()));
125  }
126  mText->setColor(mMetric->getColor());
127  mText->setText(text);
128  mText->setPosition(mMetric->getRefCoord());
129  mText->setSize(mLabelSize / 100);
130 }
131 
133 {
134  if (!mShowAnnotation)
135  return "";
136  QStringList text;
137  if (mShowLabel)
138  text << mMetric->getName();
139  if (mMetric->showValueInGraphics())
140  text << mMetric->getValueAsString();
141  return text.join(" = ");
142 }
143 
145 {
146  if (!mMetric)
147  return Vector3D(1,1,1);
148 // QColor color = mMetric->getColor();
149 // Vector3D retval(color.redF(), color.greenF(), color.blueF());
150 // return retval;
151  return cx::getColorAsVector3D(mMetric->getColor());
152 }
153 
154 }
cx::DataMetricRep::DataMetricRep
DataMetricRep()
Definition: cxDataMetricRep.cpp:25
cx::CaptionText3D
Helper for rendering 3D text that faces the camera and has a constant viewed size,...
Definition: cxGraphicalPrimitives.h:258
cx::DataMetricRep::addRepActorsToViewRenderer
void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:89
cx::DataMetricRep::setDataMetric
void setDataMetric(DataMetricPtr value)
Definition: cxDataMetricRep.cpp:35
cx::DataMetricRep::mShowAnnotation
bool mShowAnnotation
Definition: cxDataMetricRep.h:65
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DataMetricRep::clear
virtual void clear()
Definition: cxDataMetricRep.cpp:84
cx::RepImpl::getRenderer
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
cxDataMetric.h
cx::DataMetricPtr
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
cxGraphicalPrimitives.h
cx::DataMetricRep::setLabelSize
void setLabelSize(double size)
Definition: cxDataMetricRep.cpp:72
cx::RepImpl::getView
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
cx::DataMetricRep::mLabelSize
double mLabelSize
Definition: cxDataMetricRep.h:64
cx::DataMetricRep::removeRepActorsFromViewRenderer
void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxDataMetricRep.cpp:100
cx::DataMetricRep::getText
virtual QString getText()
Definition: cxDataMetricRep.cpp:132
cx::DataMetricRep::setShowAnnotation
void setShowAnnotation(bool on)
Definition: cxDataMetricRep.cpp:78
cx::getColorAsVector3D
Vector3D getColorAsVector3D(QColor color)
Definition: cxVtkHelperClasses.cpp:40
cxView.h
cx::DataMetricRep::drawText
void drawText()
Definition: cxDataMetricRep.cpp:109
cx::DataMetricRep::setShowLabel
void setShowLabel(bool on)
Definition: cxDataMetricRep.cpp:60
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl
Default implementation of Rep.
Definition: cxRepImpl.h:42
cx::DataMetricRep::getColorAsVector3D
Vector3D getColorAsVector3D() const
Definition: cxDataMetricRep.cpp:144
cx::RepImpl::setModified
void setModified()
Definition: cxRepImpl.cpp:112
cxVtkHelperClasses.h
cxDataMetricRep.h
cx::DataMetricRep::mGraphicsSize
double mGraphicsSize
Definition: cxDataMetricRep.h:62
cx::DataMetricRep::mMetric
DataMetricPtr mMetric
Definition: cxDataMetricRep.h:68
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::DataMetricRep::getDataMetric
DataMetricPtr getDataMetric()
Definition: cxDataMetricRep.cpp:55
cx::DataMetricRep::setGraphicsSize
void setGraphicsSize(double size)
Definition: cxDataMetricRep.cpp:66
cx::DataMetricRep::mShowLabel
bool mShowLabel
Definition: cxDataMetricRep.h:63