Fraxinus  2023.01.05-dev+develop.0da12
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 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
void setDataMetric(DataMetricPtr value)
Vector3D getColorAsVector3D(QColor color)
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
virtual void clear()
boost::shared_ptr< class View > ViewPtr
DataMetricPtr getDataMetric()
void addRepActorsToViewRenderer(ViewPtr view)
void setShowLabel(bool on)
Default implementation of Rep.
Definition: cxRepImpl.h:42
Helper for rendering 3D text that faces the camera and has a constant viewed size, always on top.
void setShowAnnotation(bool on)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
void removeRepActorsFromViewRenderer(ViewPtr view)
virtual QString getText()
void setLabelSize(double size)
DataMetricPtr mMetric
Vector3D getColorAsVector3D() const
void setModified()
Definition: cxRepImpl.cpp:112
void setGraphicsSize(double size)
Namespace for all CustusX production code.