Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
35 
36 #include <vtkTextProperty.h>
37 #include <vtkRenderer.h>
38 #include <vtkTextMapper.h>
39 #include <vtkObjectFactory.h>
40 #include <vtkCornerAnnotation.h>
41 
42 #include "cxView.h"
43 #include "cxSliceProxy.h"
44 #include "cxVtkHelperClasses.h"
45 #include "cxTypeConversions.h"
46 
47 // --------------------------------------------------------
48 namespace cx
49 // --------------------------------------------------------
50 {
51 
53  RepImpl()
54 {
55  mAngle = M_PI*60/180;
56  mOrientation = OrientationAnnotationPtr::New();
57  mOrientation->SetNonlinearFontScaleFactor(0.35);
58  mOrientation->GetTextProperty()->SetColor(0.7372, 0.815, 0.6039);
59 
60  mDCMDirections_r["P"] = Vector3D( 0, 1, 0); // Posterior
61  mDCMDirections_r["A"] = Vector3D( 0,-1, 0); // Anterior
62  mDCMDirections_r["R"] = Vector3D(-1, 0, 0); // Right
63  mDCMDirections_r["L"] = Vector3D( 1, 0, 0); // Left
64  mDCMDirections_r["S"] = Vector3D( 0, 0, 1); // Superior
65  mDCMDirections_r["I"] = Vector3D( 0, 0,-1); // Inferior
66 
67  mPlaneDirections_s.resize(4);
68  mPlaneDirections_s[0] = Vector3D( 1, 0, 0); // East
69  mPlaneDirections_s[1] = Vector3D( 0, 1, 0); // North
70  mPlaneDirections_s[2] = Vector3D(-1, 0, 0); // West
71  mPlaneDirections_s[3] = Vector3D( 0,-1, 0); // South
72 }
73 
74 
75 
77 {
78  return wrap_new(new OrientationAnnotationSmartRep(), uid);
79 }
80 
82 {
83 
84 }
85 
87 {
88  mOrientation->SetVisibility(visible);
89 }
90 
92 {
93  if (mSlicer)
94  {
95  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
96  }
97  mSlicer = slicer;
98  if (mSlicer)
99  {
100  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
101  this->transformChangedSlot();
102  }
103 }
104 
105 void OrientationAnnotationSmartRep::transformChangedSlot()
106 {
107  this->createAnnotation();
108 }
109 
111 {
112  Vector3D planeDir_r = rMs.vector(planeDir_s);
113 
114  QString text;
115  double threshold = cos(mAngle);
116 // double threshold = 0.5;
117 
118  for (std::map<QString, Vector3D>::iterator iter=mDCMDirections_r.begin(); iter!=mDCMDirections_r.end(); ++iter)
119  {
120  double w = dot(planeDir_r, iter->second);
121  if (w > threshold)
122  text += iter->first;
123  }
124 
125  return text;
126 // return "test_"+qstring_cast(planeDir_s);
127 }
128 
130 {
131  this->transformChangedSlot();
132  view->getRenderer()->AddActor(mOrientation);
133 }
134 
136 {
137  view->getRenderer()->RemoveActor(mOrientation);
138 }
139 
141 {
142  mAngle = angle;
143  this->createAnnotation();
144 }
145 
147 {
148  return mAngle;
149 }
150 
152 {
153  if (!mSlicer)
154  return;
155 
156  Transform3D rMs = mSlicer->get_sMr().inv();
157 
158  // update texts
159  for (unsigned int i=0; i<mPlaneDirections_s.size(); ++i)
160  {
161  QString text = this->determineAnnotation(mPlaneDirections_s[i], rMs);
162  mOrientation->SetText(i, cstring_cast(text));
163  }
164 }
165 
166 
167 // --------------------------------------------------------
168 } //end namespace
169 // --------------------------------------------------------
170 
171 
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:83
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:67
Default implementation of Rep.
Definition: cxRepImpl.h:63
QString determineAnnotation(Vector3D planeDir_s, Transform3D rMs)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
#define M_PI