CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #include "cxVideoSourceGraphics.h"
35 
36 #include <vtkImageData.h>
37 #include <vtkPolyData.h>
38 
39 
40 #include "cxTool.h"
42 #include "cxVideoGraphics.h"
43 #include "cxVideoSource.h"
44 #include "cxSpaceProvider.h"
45 
46 namespace cx
47 {
48 
50 {
51  mSpaceProvider = spaceProvider;
52  mClipToSector = true;
53  mPipeline.reset(new VideoGraphics());
54  mShowInToolSpace = true;
55 }
56 
58 {
59 }
60 
62 {
63  mShowInToolSpace = on;
64 }
65 
67 {
68  return mPipeline->getActor();
69 }
70 
72 {
73  return mTool;
74 }
75 
77 {
78  return mProbeData;
79 }
80 
82 {
83  if (tool==mTool)
84  return;
85 
86  if (mTool)
87  {
88  disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(receiveTransforms(Transform3D, double)));
89  disconnect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(probeSectorChanged()));
90  }
91 
92  // accept only tool with a probe sector
93  if (tool && tool->getProbe())
94  {
95  mTool = tool;
96  }
97 
98  // setup new
99  if (mTool )
100  {
101  connect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(receiveTransforms(Transform3D, double)));
102  connect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(probeSectorChanged()));
103  }
104 
105  this->probeSectorChanged();
106 }
107 
109 {
110  mClipToSector = on;
111  this->probeSectorChanged();
112 }
113 
114 void VideoSourceGraphics::probeSectorChanged()
115 {
116  if (!mTool || !mTool->getProbe())
117  return;
118 
119  mProbeData.setData(mTool->getProbe()->getProbeData());
120  if (mClipToSector)
121  {
122  mPipeline->setClip(mProbeData.getSector());
123  }
124  else
125  {
126  mPipeline->setClip(NULL);
127  }
128  this->receiveTransforms(mTool->get_prMt(), 0);
129 
130  mPipeline->update();
131 }
132 
133 
135 {
136  //Don't do anything if data is unchanged
137  if (mData == data)
138  return;
139  if (mData)
140  {
141  disconnect(mData.get(), &VideoSource::newFrame, this, &VideoSourceGraphics::newDataSlot);
142  mPipeline->setInputVideo(NULL);
143  }
144 
145  mData = data;
146 
147  if (mData)
148  {
149  connect(mData.get(), &VideoSource::newFrame, this, &VideoSourceGraphics::newDataSlot);
150  mPipeline->setInputVideo(mData->getVtkImageData());
151  }
152 
153  this->newDataSlot();
154 }
155 
156 void VideoSourceGraphics::receiveTransforms(Transform3D prMt, double timestamp)
157 {
158  if (!mShowInToolSpace)
159  return;
160  Transform3D rMpr = mSpaceProvider->get_rMpr();
161  Transform3D tMu = mProbeData.get_tMu();
162  Transform3D rMu = rMpr * prMt * tMu;
163  mPipeline->setActorUserMatrix(rMu.getVtkMatrix());
164 }
165 
166 void VideoSourceGraphics::newDataSlot()
167 {
168  if (!mData || !mData->validData())
169  {
170  mPipeline->setVisibility(false);
171  emit newData();
172  return;
173  }
174 
175  mPipeline->update();
176 
177  bool visible = mData->validData();
178  if (mShowInToolSpace)
179  visible = visible && mTool && mTool->getVisible();
180  mPipeline->setVisibility(visible);
181 
182  emit newData();
183 }
184 
185 } // 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.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Utility functions for drawing an US Probe sector.
Definition: cxProbeSector.h:59
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)
boost::shared_ptr< class Tool > ToolPtr