NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxCrossHairRep2D.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 /*
35  * vmCrossHairRep2D.cpp
36  *
37  * Created on: Jan 13, 2009
38  * Author: christiana
39  */
40 
41 #include "cxCrossHairRep2D.h"
42 
43 #include <vtkActor2D.h>
44 #include <vtkRenderer.h>
45 
46 #include "cxTool.h"
47 #include "cxView.h"
48 #include "cxSliceProxy.h"
49 #include "cxVtkHelperClasses.h"
50 #include "cxSpaceProvider.h"
51 
52 namespace cx
53 {
54 
56  RepImpl(),
57  m_vpMs(Transform3D::Identity()),
58  mSpaceProvider(spaceProvider)
59 {
60 }
61 
63 {
64 }
65 
67 {
68  return wrap_new(new CrossHairRep2D(spaceProvider), uid);
69 }
70 
71 QString CrossHairRep2D::getType() const
72 {
73  return "vm::CrossHairRep2D";
74 }
75 
77 {
78  m_vpMs = vpMs;
79  update();
80 }
81 
83 {
84  if (mSlicer)
85  {
86  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(sliceTransformChangedSlot(Transform3D)));
87  disconnect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
88  disconnect(mSlicer.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
89  }
90 
91  mSlicer = slicer;
92 
93  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(sliceTransformChangedSlot(Transform3D)));
94  connect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
95  connect(mSlicer.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
96 
97  update();
98 }
99 
101 {
102  mCursor.reset( new CrossHair2D(view->getRenderer()) ) ;
103  double bordarOffset = 150.0;
104  RGBColor color( 1.0, 0.8, 0.0 );
105  mCursor->setValue( Vector3D(0,0,0), 100, 100, bordarOffset, color );
106  update();
107 }
108 
110 {
111  mCursor.reset();
112 }
113 
114 void CrossHairRep2D::sliceTransformChangedSlot(Transform3D sMr)
115 {
116  update();
117 }
118 void CrossHairRep2D::toolTransformAndTimestampSlot(Transform3D prMt, double timestamp)
119 {
120  update();
121 }
122 void CrossHairRep2D::toolVisibleSlot(bool visible)
123 {
124  update();
125 }
126 
127 void CrossHairRep2D::update()
128 {
129  if (!mSlicer || !mSlicer->getTool())
130  return;
131 
132  Transform3D prMt = mSlicer->getTool()->get_prMt();
133  Transform3D rMpr = mSpaceProvider->get_rMpr();
134  Transform3D sMr = mSlicer->get_sMr();
135 
136  if (mCursor)
137  {
138  Transform3D vpMt = m_vpMs*sMr*rMpr*prMt;
139  mCursor->updateRegCross( vpMt.coord(Vector3D(0,0,0)) );
140  //Logger::log("vm.log", "CrossHairRep2D::update(), center=" + string_cast(vpMt.coord(Vector3D(0,0,0))));
141  }
142 }
143 
144 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
virtual void addRepActorsToViewRenderer(ViewPtr view)
boost::shared_ptr< class CrossHairRep2D > CrossHairRep2DPtr
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
void setSliceProxy(SliceProxyPtr slicer)
virtual QString getType() const
CrossHairRep2D(SpaceProviderPtr spaceProvider)
boost::shared_ptr< class View > ViewPtr
RGB color data.
void set_vpMs(const Transform3D &vpMs)
Default implementation of Rep.
Definition: cxRepImpl.h:63
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
static CrossHairRep2DPtr New(SpaceProviderPtr spaceProvider, const QString &uid="")
Helper for drawing a crosshair in 2D.