Fraxinus  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
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
void setRealtimeStream(VideoSourcePtr data)
vtkSmartPointer< class vtkActor > vtkActorPtr
Wrap vtkActor displaying a video image, possibly clipped by a sector.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkPolyDataPtr getSector()
get a polydata representation of the us sector
VideoSourceGraphics(SpaceProviderPtr spaceProvider, bool useMaskFilter=false)
boost::shared_ptr< class VideoSource > VideoSourcePtr
Transform3D get_tMu() const
get transform from image space u to probe tool space t.
Utility functions for drawing an US Probe sector.
Definition: cxProbeSector.h:38
void setClipToSector(bool on)
Turn sector clipping on/off. If on, only the area inside the probe sector is shown.
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
void setData(ProbeDefinition data)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr