Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #include "cxAngleMetricRep.h"
35 
36 #include "cxView.h"
37 
38 #include <vtkVectorText.h>
39 #include <vtkFollower.h>
40 #include <vtkPolyDataMapper.h>
41 #include <vtkProperty.h>
42 #include <vtkRenderer.h>
43 #include <vtkCamera.h>
44 #include <vtkRenderWindow.h>
45 #include "cxTypeConversions.h"
46 #include "vtkTextActor.h"
47 #include "cxGraphicalPrimitives.h"
48 #include "cxAngleMetric.h"
49 #include "cxGraphicalPrimitives.h"
50 
51 namespace cx
52 {
53 
55 {
56  return wrap_new(new AngleMetricRep(), uid);
57 }
58 
59 AngleMetricRep::AngleMetricRep()
60 {
61 }
62 
64 {
66  mLine0.reset();
67  mLine1.reset();
68  mArc.reset();
69 }
70 
71 AngleMetricPtr AngleMetricRep::getAngleMetric()
72 {
73  return boost::dynamic_pointer_cast<AngleMetric>(mMetric);
74 }
75 
77 {
78  AngleMetricPtr angleMetric = this->getAngleMetric();
79 
80  if (!angleMetric || !mMetric->isValid())
81  return;
82  if (!mMetric)
83  return;
84  if (!this->getView())
85  return;
86 
87  std::vector<Vector3D> p = angleMetric->getEndpoints();
88 
89  if (angleMetric->getUseSimpleVisualization())
90  {
91  mLine0.reset();
92  mLine1.reset();
93  }
94  else
95  {
96  if (!mLine0)
97  {
98  mLine0.reset(new GraphicalLine3D(this->getRenderer()));
99  }
100  mLine0->setColor(mMetric->getColor());
101  mLine0->setStipple(0x0F0F);
102  mLine0->setValue(p[0], p[1]);
103 
104  if (!mLine1)
105  {
106  mLine1.reset(new GraphicalLine3D(this->getRenderer()));
107  }
108  mLine1->setColor(mMetric->getColor());
109  mLine1->setStipple(0x0F0F);
110  mLine1->setValue(p[2], p[3]);
111  }
112 
113  if (!mArc)
114  {
115  mArc.reset(new GraphicalArc3D(this->getRenderer()));
116  }
117  mArc->setColor(mMetric->getColor());
118  mArc->setStipple(0xF0FF);
119  Vector3D a_center = (p[1] + p[2]) / 2;
120  Vector3D l0 = p[0] - p[1];
121  Vector3D l1 = p[3] - p[2];
122  double d = (l0.length() + l1.length()) / 2 * 0.5;
123  Vector3D a_start = a_center + l0.normalized() * d;
124  Vector3D a_end = a_center + l1.normalized() * d;
125  mArc->setValue(a_start, a_end, a_center);
126 
127  this->drawText();
128 }
129 
130 
131 }
ViewPtr getView() const
Definition: cxRepImpl.cpp:104
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:109
Helper for rendering a line in 3D.
virtual void clear()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
static AngleMetricRepPtr New(const QString &uid="")
boost::shared_ptr< class AngleMetric > AngleMetricPtr
Definition: cxAngleMetric.h:54
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:63
virtual void clear()
DataMetricPtr mMetric
Data class that represents an angle between two lines.
Definition: cxAngleMetric.h:67