Fraxinus  17.12-rc2
An IGT application
cxDonutMetricRep.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 "cxDonutMetricRep.h"
34 
35 #include "cxView.h"
36 
37 #include <vtkVectorText.h>
38 #include <vtkFollower.h>
39 #include <vtkPolyDataMapper.h>
40 #include <vtkProperty.h>
41 #include <vtkRenderer.h>
42 #include <vtkCamera.h>
43 #include <vtkRenderWindow.h>
44 #include "cxTypeConversions.h"
45 #include "vtkTextActor.h"
46 #include "cxGraphicalPrimitives.h"
47 #include "cxShapedMetric.h"
48 #include "cxGraphicalPrimitives.h"
49 #include "vtkMatrix4x4.h"
50 #include "cxGraphicalTorus3D.h"
51 #include "cxGraphicalDisk.h"
52 
53 namespace cx
54 {
55 
57 {
58  return wrap_new(new DonutMetricRep(), uid);
59 }
60 
61 DonutMetricRep::DonutMetricRep()
62 {
63 }
64 
66 {
68  mTorus.reset();
69  mDisk.reset();
70 }
71 
72 DonutMetricPtr DonutMetricRep::getDonutMetric()
73 {
74  return boost::dynamic_pointer_cast<DonutMetric>(mMetric);
75 }
76 
78 {
79  if (!mMetric)
80  return;
81 
82  this->updateTorus();
83  this->updateDisc();
84 
85  this->drawText();
86 }
87 
88 void DonutMetricRep::updateTorus()
89 {
90  if (!mMetric)
91  return;
92 
93  DonutMetricPtr donut = this->getDonutMetric();
94 
95  if (donut->getFlat())
96  {
97  mTorus.reset();
98  return;
99  }
100 
101  if (!mTorus && this->getView() && mMetric)
102  mTorus.reset(new GraphicalTorus3D(this->getRenderer()));
103 
104  if (!mTorus)
105  return;
106 
107  mTorus->setPosition(donut->getPosition());
108  mTorus->setDirection(donut->getDirection());
109  mTorus->setRadius(donut->getRadius());
110  mTorus->setThickness(donut->getThickness());
111  mTorus->setColor(donut->getColor());
112 }
113 
114 void DonutMetricRep::updateDisc()
115 {
116  if (!mMetric)
117  return;
118 
119  DonutMetricPtr donut = this->getDonutMetric();
120 
121  if (!donut->getFlat())
122  {
123  mDisk.reset();
124  return;
125  }
126 
127  if (!mDisk && this->getView() && mMetric)
128  {
129  mDisk.reset(new GraphicalDisk());
130  mDisk->setRenderer(this->getRenderer());
131  }
132 
133  if (!mDisk)
134  return;
135 
136  mDisk->setPosition(donut->getPosition());
137  mDisk->setDirection(donut->getDirection());
138  mDisk->setRadius(donut->getRadius());
139  mDisk->setHeight(donut->getHeight());
140  mDisk->setColor(donut->getColor());
141  mDisk->setOutlineColor(donut->getColor());
142  mDisk->setOutlineWidth(donut->getThickness());
143  mDisk->setFillVisible(false);
144  mDisk->setLighting(true);
145 
146  mDisk->update();
147 }
148 
149 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:104
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:109
static DonutMetricRepPtr New(const QString &uid="")
boost::shared_ptr< class DonutMetric > DonutMetricPtr
Helper for rendering a torus in 3D.
virtual void clear()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
virtual void clear()
virtual void onModifiedStartRender()
Data class that represents a donut.
DataMetricPtr mMetric
boost::shared_ptr< class DonutMetricRep > DonutMetricRepPtr
Namespace for all CustusX production code.