CustusX  18.04
An IGT application
cxAngleMetricRep.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 #include "cxAngleMetricRep.h"
14 
15 #include "cxView.h"
16 
17 #include <vtkVectorText.h>
18 #include <vtkFollower.h>
19 #include <vtkPolyDataMapper.h>
20 #include <vtkProperty.h>
21 #include <vtkRenderer.h>
22 #include <vtkCamera.h>
23 #include <vtkRenderWindow.h>
24 #include "cxTypeConversions.h"
25 #include "vtkTextActor.h"
26 #include "cxGraphicalPrimitives.h"
27 #include "cxAngleMetric.h"
28 #include "cxGraphicalPrimitives.h"
29 
30 namespace cx
31 {
32 
34 {
35  return wrap_new(new AngleMetricRep(), uid);
36 }
37 
38 AngleMetricRep::AngleMetricRep()
39 {
40 }
41 
43 {
45  mLine0.reset();
46  mLine1.reset();
47  mArc.reset();
48 }
49 
50 AngleMetricPtr AngleMetricRep::getAngleMetric()
51 {
52  return boost::dynamic_pointer_cast<AngleMetric>(mMetric);
53 }
54 
56 {
57  AngleMetricPtr angleMetric = this->getAngleMetric();
58 
59  if (!angleMetric || !mMetric->isValid())
60  return;
61  if (!mMetric)
62  return;
63  if (!this->getView())
64  return;
65 
66  std::vector<Vector3D> p = angleMetric->getEndpoints();
67 
68  if (angleMetric->getUseSimpleVisualization())
69  {
70  mLine0.reset();
71  mLine1.reset();
72  }
73  else
74  {
75  if (!mLine0)
76  {
77  mLine0.reset(new GraphicalLine3D(this->getRenderer()));
78  }
79  mLine0->setColor(mMetric->getColor());
80  mLine0->setStipple(0x0F0F);
81  mLine0->setValue(p[0], p[1]);
82 
83  if (!mLine1)
84  {
85  mLine1.reset(new GraphicalLine3D(this->getRenderer()));
86  }
87  mLine1->setColor(mMetric->getColor());
88  mLine1->setStipple(0x0F0F);
89  mLine1->setValue(p[2], p[3]);
90  }
91 
92  if (!mArc)
93  {
94  mArc.reset(new GraphicalArc3D(this->getRenderer()));
95  }
96  mArc->setColor(mMetric->getColor());
97  mArc->setStipple(0xF0FF);
98  Vector3D a_center = (p[1] + p[2]) / 2;
99  Vector3D l0 = p[0] - p[1];
100  Vector3D l1 = p[3] - p[2];
101  double d = (l0.length() + l1.length()) / 2 * 0.5;
102  Vector3D a_start = a_center + l0.normalized() * d;
103  Vector3D a_end = a_center + l1.normalized() * d;
104  mArc->setValue(a_start, a_end, a_center);
105 
106  this->drawText();
107 }
108 
109 
110 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
Helper for rendering a line in 3D.
virtual void clear()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
static AngleMetricRepPtr New(const QString &uid="")
boost::shared_ptr< class AngleMetric > AngleMetricPtr
Definition: cxAngleMetric.h:33
boost::shared_ptr< class AngleMetricRep > AngleMetricRepPtr
Helper for rendering a line in 3D.
virtual void onModifiedStartRender()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
virtual void clear()
DataMetricPtr mMetric
Data class that represents an angle between two lines.
Definition: cxAngleMetric.h:46
Namespace for all CustusX production code.