Fraxinus  22.04-rc5
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) 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 #include "cxDonutMetricRep.h"
13 
14 #include "cxView.h"
15 
16 #include <vtkVectorText.h>
17 #include <vtkFollower.h>
18 #include <vtkPolyDataMapper.h>
19 #include <vtkProperty.h>
20 #include <vtkRenderer.h>
21 #include <vtkCamera.h>
22 #include <vtkRenderWindow.h>
23 #include "cxTypeConversions.h"
24 #include "vtkTextActor.h"
25 #include "cxGraphicalPrimitives.h"
26 #include "cxShapedMetric.h"
27 #include "cxGraphicalPrimitives.h"
28 #include "vtkMatrix4x4.h"
29 #include "cxGraphicalTorus3D.h"
30 #include "cxGraphicalDisk.h"
31 
32 namespace cx
33 {
34 
36 {
37  return wrap_new(new DonutMetricRep(), uid);
38 }
39 
40 DonutMetricRep::DonutMetricRep()
41 {
42 }
43 
45 {
47  mTorus.reset();
48  mDisk.reset();
49 }
50 
51 DonutMetricPtr DonutMetricRep::getDonutMetric()
52 {
53  return boost::dynamic_pointer_cast<DonutMetric>(mMetric);
54 }
55 
57 {
58  if (!mMetric)
59  return;
60 
61  this->updateTorus();
62  this->updateDisc();
63 
64  this->drawText();
65 }
66 
67 void DonutMetricRep::updateTorus()
68 {
69  if (!mMetric)
70  return;
71 
72  DonutMetricPtr donut = this->getDonutMetric();
73 
74  if (donut->getFlat())
75  {
76  mTorus.reset();
77  return;
78  }
79 
80  if (!mTorus && this->getView() && mMetric)
81  mTorus.reset(new GraphicalTorus3D(this->getRenderer()));
82 
83  if (!mTorus)
84  return;
85 
86  mTorus->setPosition(donut->getPosition());
87  mTorus->setDirection(donut->getDirection());
88  mTorus->setRadius(donut->getRadius());
89  mTorus->setThickness(donut->getThickness());
90  mTorus->setColor(donut->getColor());
91 }
92 
93 void DonutMetricRep::updateDisc()
94 {
95  if (!mMetric)
96  return;
97 
98  DonutMetricPtr donut = this->getDonutMetric();
99 
100  if (!donut->getFlat())
101  {
102  mDisk.reset();
103  return;
104  }
105 
106  if (!mDisk && this->getView() && mMetric)
107  {
108  mDisk.reset(new GraphicalDisk());
109  mDisk->setRenderer(this->getRenderer());
110  }
111 
112  if (!mDisk)
113  return;
114 
115  mDisk->setPosition(donut->getPosition());
116  mDisk->setDirection(donut->getDirection());
117  mDisk->setRadius(donut->getRadius());
118  mDisk->setHeight(donut->getHeight());
119  mDisk->setColor(donut->getColor());
120  mDisk->setOutlineColor(donut->getColor());
121  mDisk->setOutlineWidth(donut->getThickness());
122  mDisk->setFillVisible(false);
123  mDisk->setLighting(true);
124 
125  mDisk->update();
126 }
127 
128 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
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:62
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.