CustusX  2023.01.05-dev+develop.0da12
An IGT application
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) 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 /*
14  * vmCrossHairRep2D.cpp
15  *
16  * Created on: Jan 13, 2009
17  * Author: christiana
18  */
19 
20 #include "cxCrossHairRep2D.h"
21 
22 #include <vtkActor2D.h>
23 #include <vtkRenderer.h>
24 
25 #include "cxTool.h"
26 #include "cxView.h"
27 #include "cxSliceProxy.h"
28 #include "cxVtkHelperClasses.h"
29 #include "cxSpaceProvider.h"
30 
31 namespace cx
32 {
33 
35  RepImpl(),
36  m_vpMs(Transform3D::Identity()),
37  mSpaceProvider(spaceProvider)
38 {
39 }
40 
42 {
43 }
44 
45 CrossHairRep2DPtr CrossHairRep2D::New(SpaceProviderPtr spaceProvider, const QString& uid)
46 {
47  return wrap_new(new CrossHairRep2D(spaceProvider), uid);
48 }
49 
50 QString CrossHairRep2D::getType() const
51 {
52  return "vm::CrossHairRep2D";
53 }
54 
56 {
57  m_vpMs = vpMs;
58  update();
59 }
60 
62 {
63  if (mSlicer)
64  {
65  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(sliceTransformChangedSlot(Transform3D)));
66  disconnect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
67  disconnect(mSlicer.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
68  }
69 
70  mSlicer = slicer;
71 
72  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(sliceTransformChangedSlot(Transform3D)));
73  connect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
74  connect(mSlicer.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
75 
76  update();
77 }
78 
80 {
81  mCursor.reset( new CrossHair2D(view->getRenderer()) ) ;
82  double bordarOffset = 150.0;
83  RGBColor color( 1.0, 0.8, 0.0 );
84  mCursor->setValue( Vector3D(0,0,0), 100, 100, bordarOffset, color );
85  update();
86 }
87 
89 {
90  mCursor.reset();
91 }
92 
93 void CrossHairRep2D::sliceTransformChangedSlot(Transform3D sMr)
94 {
95  update();
96 }
97 void CrossHairRep2D::toolTransformAndTimestampSlot(Transform3D prMt, double timestamp)
98 {
99  update();
100 }
101 void CrossHairRep2D::toolVisibleSlot(bool visible)
102 {
103  update();
104 }
105 
106 void CrossHairRep2D::update()
107 {
108  if (!mSlicer || !mSlicer->getTool())
109  return;
110 
111  Transform3D prMt = mSlicer->getTool()->get_prMt();
112  Transform3D rMpr = mSpaceProvider->get_rMpr();
113  Transform3D sMr = mSlicer->get_sMr();
114 
115  if (mCursor)
116  {
117  Transform3D vpMt = m_vpMs*sMr*rMpr*prMt;
118  mCursor->updateRegCross( vpMt.coord(Vector3D(0,0,0)) );
119  //Logger::log("vm.log", "CrossHairRep2D::update(), center=" + string_cast(vpMt.coord(Vector3D(0,0,0))));
120  }
121 }
122 
123 }
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:62
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:42
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
static CrossHairRep2DPtr New(SpaceProviderPtr spaceProvider, const QString &uid="")
Helper for drawing a crosshair in 2D.
Namespace for all CustusX production code.