NorMIT-nav  22.09
An IGT application
cxVideoSourceGraphics.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 #include "cxVideoSourceGraphics.h"
14 
15 #include <vtkImageData.h>
16 #include <vtkPolyData.h>
17 
18 
19 #include "cxTool.h"
21 #include "cxVideoGraphics.h"
22 #include "cxVideoSource.h"
23 #include "cxSpaceProvider.h"
24 #include "cxLogger.h"
25 
26 namespace cx
27 {
28 
30 {
31  mSpaceProvider = spaceProvider;
32  mClipToSector = true;
33  mPipeline.reset(new VideoGraphics());
34  mShowInToolSpace = true;
35 }
36 
38 {
39 }
40 
42 {
43  mShowInToolSpace = on;
44 }
45 
47 {
48  return mPipeline->getActor();
49 }
50 
52 {
53  return mTool;
54 }
55 
57 {
58  return mProbeDefinition;
59 }
60 
62 {
63  if (tool==mTool)
64  return;
65 
66  if (mTool)
67  {
68  disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(receiveTransforms(Transform3D, double)));
69  disconnect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(probeSectorChanged()));
70  }
71 
72  // accept only tool with a probe sector
73  if (tool && tool->getProbe())
74  {
75  mTool = tool;
76  }
77 
78  // setup new
79  if (mTool )
80  {
81  connect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(receiveTransforms(Transform3D, double)));
82  connect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(probeSectorChanged()));
83  }
84 
85  this->probeSectorChanged();
86 }
87 
89 {
90  mClipToSector = on;
91  this->probeSectorChanged();
92 }
93 
94 void VideoSourceGraphics::probeSectorChanged()
95 {
96  if (!mTool || !mTool->getProbe())
97  return;
98 
99  mProbeDefinition.setData(mTool->getProbe()->getProbeDefinition());
100  if (mClipToSector)
101  {
102  mPipeline->setClip(mProbeDefinition.getSector());
103  }
104  else
105  {
106  mPipeline->setClip(NULL);
107  }
108  this->receiveTransforms(mTool->get_prMt(), 0);
109 
110  mPipeline->update();
111 }
112 
113 
115 {
116  //Don't do anything if data is unchanged
117  if (mData == data)
118  return;
119  if (mData)
120  {
121  disconnect(mData.get(), &VideoSource::newFrame, this, &VideoSourceGraphics::newDataSlot);
122  mPipeline->setInputVideo(NULL);
123  }
124 
125  mData = data;
126 
127  if (mData)
128  {
129  connect(mData.get(), &VideoSource::newFrame, this, &VideoSourceGraphics::newDataSlot);
130  mPipeline->setInputVideo(mData->getVtkImageData());
131  }
132 
133  this->newDataSlot();
134 }
135 
136 void VideoSourceGraphics::receiveTransforms(Transform3D prMt, double timestamp)
137 {
138  if (!mShowInToolSpace)
139  return;
140  Transform3D rMpr = mSpaceProvider->get_rMpr();
141  Transform3D tMu = mProbeDefinition.get_tMu();
142  Transform3D rMu = rMpr * prMt * tMu;
143  mPipeline->setActorUserMatrix(rMu.getVtkMatrix());
144 }
145 
146 void VideoSourceGraphics::newDataSlot()
147 {
148  if (!mData || !mData->validData())
149  {
150  mPipeline->setVisibility(false);
151  emit newData();
152  return;
153  }
154 
155  mPipeline->update();
156 
157  bool visible = mData->validData();
158  if (mShowInToolSpace)
159  visible = visible && mTool && mTool->getVisible();
160  mPipeline->setVisibility(visible);
161 
162  emit newData();
163 }
164 
165 } // namespace cx
cx::VideoSource::newFrame
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
cx::VideoSourceGraphics::setShowInToolSpace
void setShowInToolSpace(bool on)
Definition: cxVideoSourceGraphics.cpp:41
cxLogger.h
cx::ProbeSector::get_tMu
Transform3D get_tMu() const
get transform from image space u to probe tool space t.
Definition: cxProbeSector.cpp:175
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::VideoSourceGraphics::getTool
ToolPtr getTool()
Definition: cxVideoSourceGraphics.cpp:51
cx::VideoSourceGraphics::setRealtimeStream
void setRealtimeStream(VideoSourcePtr data)
Definition: cxVideoSourceGraphics.cpp:114
cx::VideoSourceGraphics::VideoSourceGraphics
VideoSourceGraphics(SpaceProviderPtr spaceProvider, bool useMaskFilter=false)
Definition: cxVideoSourceGraphics.cpp:29
cxVideoSourceGraphics.h
cx::VideoSourcePtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
Definition: cxForwardDeclarations.h:109
cxVideoSource.h
cxVideoGraphics.h
cx::ProbeSector::setData
void setData(ProbeDefinition data)
Definition: cxProbeSector.cpp:48
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cxTool.h
cx::VideoGraphics
Wrap vtkActor displaying a video image, possibly clipped by a sector.
Definition: cxVideoGraphics.h:41
cx::VideoSourceGraphics::getProbeDefinition
ProbeSector getProbeDefinition()
Definition: cxVideoSourceGraphics.cpp:56
cxRegistrationTransform.h
vtkActorPtr
vtkSmartPointer< class vtkActor > vtkActorPtr
Definition: vtkForwardDeclarations.h:31
cx::ProbeSector
Utility functions for drawing an US Probe sector.
Definition: cxProbeSector.h:38
cx::VideoSourceGraphics::getActor
vtkActorPtr getActor()
Definition: cxVideoSourceGraphics.cpp:46
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::ProbeSector::getSector
vtkPolyDataPtr getSector()
get a polydata representation of the us sector
Definition: cxProbeSector.cpp:193
cx::VideoSourceGraphics::setTool
void setTool(ToolPtr tool)
Definition: cxVideoSourceGraphics.cpp:61
cx::VideoSourceGraphics::newData
void newData()
cx::VideoSourceGraphics::~VideoSourceGraphics
virtual ~VideoSourceGraphics()
Definition: cxVideoSourceGraphics.cpp:37
cx::SpaceProviderPtr
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Definition: cxLogicManager.h:23
cx::VideoSourceGraphics::setClipToSector
void setClipToSector(bool on)
Turn sector clipping on/off. If on, only the area inside the probe sector is shown.
Definition: cxVideoSourceGraphics.cpp:88
cxSpaceProvider.h