Fraxinus  18.10
An IGT application
cxOrientationAnnotation2DRep.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 
14 
15 #include <vtkTextProperty.h>
16 #include <vtkRenderer.h>
17 #include <vtkTextMapper.h>
18 #include <vtkObjectFactory.h>
19 #include <vtkCornerAnnotation.h>
20 
21 #include "cxView.h"
22 #include "cxSliceProxy.h"
23 #include "cxVtkHelperClasses.h"
24 #include "cxTypeConversions.h"
25 
26 // --------------------------------------------------------
27 namespace cx
28 // --------------------------------------------------------
29 {
30 
32  RepImpl()
33 {
34  mAngle = M_PI*60/180;
35  mOrientation = OrientationAnnotationPtr::New();
36  mOrientation->SetNonlinearFontScaleFactor(0.35);
37  mOrientation->GetTextProperty()->SetColor(0.7372, 0.815, 0.6039);
38 
39  mDCMDirections_r["P"] = Vector3D( 0, 1, 0); // Posterior
40  mDCMDirections_r["A"] = Vector3D( 0,-1, 0); // Anterior
41  mDCMDirections_r["R"] = Vector3D(-1, 0, 0); // Right
42  mDCMDirections_r["L"] = Vector3D( 1, 0, 0); // Left
43  mDCMDirections_r["S"] = Vector3D( 0, 0, 1); // Superior
44  mDCMDirections_r["I"] = Vector3D( 0, 0,-1); // Inferior
45 
46  mPlaneDirections_s.resize(4);
47  mPlaneDirections_s[0] = Vector3D( 1, 0, 0); // East
48  mPlaneDirections_s[1] = Vector3D( 0, 1, 0); // North
49  mPlaneDirections_s[2] = Vector3D(-1, 0, 0); // West
50  mPlaneDirections_s[3] = Vector3D( 0,-1, 0); // South
51 }
52 
53 
54 
56 {
57  return wrap_new(new OrientationAnnotationSmartRep(), uid);
58 }
59 
61 {
62 
63 }
64 
66 {
67  mOrientation->SetVisibility(visible);
68 }
69 
71 {
72  if (mSlicer)
73  {
74  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
75  }
76  mSlicer = slicer;
77  if (mSlicer)
78  {
79  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
80  this->transformChangedSlot();
81  }
82 }
83 
84 void OrientationAnnotationSmartRep::transformChangedSlot()
85 {
86  this->createAnnotation();
87 }
88 
90 {
91  Vector3D planeDir_r = rMs.vector(planeDir_s);
92 
93  QString text;
94  double threshold = cos(mAngle);
95 // double threshold = 0.5;
96 
97  for (std::map<QString, Vector3D>::iterator iter=mDCMDirections_r.begin(); iter!=mDCMDirections_r.end(); ++iter)
98  {
99  double w = dot(planeDir_r, iter->second);
100  if (w > threshold)
101  text += iter->first;
102  }
103 
104  return text;
105 // return "test_"+qstring_cast(planeDir_s);
106 }
107 
109 {
110  this->transformChangedSlot();
111  view->getRenderer()->AddActor(mOrientation);
112 }
113 
115 {
116  view->getRenderer()->RemoveActor(mOrientation);
117 }
118 
120 {
121  mAngle = angle;
122  this->createAnnotation();
123 }
124 
126 {
127  return mAngle;
128 }
129 
131 {
132  if (!mSlicer)
133  return;
134 
135  Transform3D rMs = mSlicer->get_sMr().inv();
136 
137  // update texts
138  for (unsigned int i=0; i<mPlaneDirections_s.size(); ++i)
139  {
140  QString text = this->determineAnnotation(mPlaneDirections_s[i], rMs);
141  mOrientation->SetText(i, cstring_cast(text));
142  }
143 }
144 
145 
146 // --------------------------------------------------------
147 } //end namespace
148 // --------------------------------------------------------
149 
150 
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
std::vector< Vector3D > mPlaneDirections_s
the four directions in the slice plane
cstring_cast_Placeholder cstring_cast(const T &val)
virtual void addRepActorsToViewRenderer(ViewPtr view)
boost::shared_ptr< class View > ViewPtr
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
static OrientationAnnotationSmartRepPtr New(const QString &uid="")
boost::shared_ptr< class OrientationAnnotationSmartRep > OrientationAnnotationSmartRepPtr
std::map< QString, Vector3D > mDCMDirections_r
directions of DICOM labels APSILR
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Definition: cxVector3D.cpp:46
Default implementation of Rep.
Definition: cxRepImpl.h:42
QString determineAnnotation(Vector3D planeDir_s, Transform3D rMs)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
#define M_PI
Namespace for all CustusX production code.