NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
34 
35 #include "cxDataMetricRep.h"
36 
37 #include "cxGraphicalPrimitives.h"
38 #include "cxView.h"
39 #include "cxDataMetric.h"
40 
41 #include "cxVtkHelperClasses.h"
42 
43 namespace cx
44 {
45 
47  RepImpl(),
48  mGraphicsSize(1),
49  mShowLabel(false),
50  mLabelSize(2.5),
51  mShowAnnotation(true)
52 // mView(NULL)
53 {
54 }
55 
57 {
58  if (mMetric)
59  {
60  disconnect(mMetric.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
61  disconnect(mMetric.get(), SIGNAL(propertiesChanged()), this, SLOT(setModified()));
62  }
63 
64  mMetric = value;
65 
66  if (mMetric)
67  {
68  connect(mMetric.get(), SIGNAL(propertiesChanged()), this, SLOT(setModified()));
69  connect(mMetric.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
70  }
71 
72  this->clear();
73  this->setModified();
74 }
75 
77 {
78  return mMetric;
79 }
80 
82 {
83  mShowLabel = on;
84  this->setModified();
85 }
86 
88 {
89  mGraphicsSize = size;
90  this->setModified();
91 }
92 
93 void DataMetricRep::setLabelSize(double size)
94 {
95  mLabelSize = size;
96  this->setModified();
97 }
98 
100 {
101  mShowAnnotation = on;
102  this->setModified();
103 }
104 
106 {
107  mText.reset();
108 }
109 
111 {
112 // mView = view;
113 
114 // vtkRendererPtr renderer = mView->getRenderer();
115 // renderer->AddObserver(vtkCommand::StartEvent, this->mCallbackCommand, 1.0);
116 
117  this->clear();
118  this->setModified();
119 }
120 
122 {
123 // vtkRendererPtr renderer = mView->getRenderer();
124 // renderer->RemoveObserver(this->mCallbackCommand);
125 
126 // mView = NULL;
127  this->clear();
128 }
129 
131 {
132  if (!this->getView())
133  return;
134 
135  QString text = this->getText();
136 
137  if (text.isEmpty())
138  {
139  mText.reset();
140  return;
141  }
142 
143  if (!mText)
144  {
145  mText.reset(new CaptionText3D(this->getRenderer()));
146  }
147  mText->setColor(mMetric->getColor());
148  mText->setText(text);
149  mText->setPosition(mMetric->getRefCoord());
150  mText->setSize(mLabelSize / 100);
151 }
152 
154 {
155  if (!mShowAnnotation)
156  return "";
157  QStringList text;
158  if (mShowLabel)
159  text << mMetric->getName();
160  if (mMetric->showValueInGraphics())
161  text << mMetric->getValueAsString();
162  return text.join(" = ");
163 }
164 
166 {
167  if (!mMetric)
168  return Vector3D(1,1,1);
169 // QColor color = mMetric->getColor();
170 // Vector3D retval(color.redF(), color.greenF(), color.blueF());
171 // return retval;
172  return cx::getColorAsVector3D(mMetric->getColor());
173 }
174 
175 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:104
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:109
void setDataMetric(DataMetricPtr value)
Vector3D getColorAsVector3D(QColor color)
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:95
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:63
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:63
void removeRepActorsFromViewRenderer(ViewPtr view)
virtual QString getText()
void setLabelSize(double size)
DataMetricPtr mMetric
Vector3D getColorAsVector3D() const
void setModified()
Definition: cxRepImpl.cpp:132
void setGraphicsSize(double size)