NorMIT-nav  16.5
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 #include "cxLogger.h"
46 
47 namespace cx
48 {
49 
51 {
52  mSpaceProvider = spaceProvider;
53  mClipToSector = true;
54  mPipeline.reset(new VideoGraphics());
55  mShowInToolSpace = true;
56 }
57 
59 {
60 }
61 
63 {
64  mShowInToolSpace = on;
65 }
66 
68 {
69  return mPipeline->getActor();
70 }
71 
73 {
74  return mTool;
75 }
76 
78 {
79  return mProbeDefinition;
80 }
81 
83 {
84  if (tool==mTool)
85  return;
86 
87  if (mTool)
88  {
89  disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(receiveTransforms(Transform3D, double)));
90  disconnect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(probeSectorChanged()));
91  }
92 
93  // accept only tool with a probe sector
94  if (tool && tool->getProbe())
95  {
96  mTool = tool;
97  }
98 
99  // setup new
100  if (mTool )
101  {
102  connect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(receiveTransforms(Transform3D, double)));
103  connect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(probeSectorChanged()));
104  }
105 
106  this->probeSectorChanged();
107 }
108 
110 {
111  mClipToSector = on;
112  this->probeSectorChanged();
113 }
114 
115 void VideoSourceGraphics::probeSectorChanged()
116 {
117  if (!mTool || !mTool->getProbe())
118  return;
119 
120  mProbeDefinition.setData(mTool->getProbe()->getProbeDefinition());
121  if (mClipToSector)
122  {
123  mPipeline->setClip(mProbeDefinition.getSector());
124  }
125  else
126  {
127  mPipeline->setClip(NULL);
128  }
129  this->receiveTransforms(mTool->get_prMt(), 0);
130 
131  mPipeline->update();
132 }
133 
134 
136 {
137  //Don't do anything if data is unchanged
138  if (mData == data)
139  return;
140  if (mData)
141  {
142  disconnect(mData.get(), &VideoSource::newFrame, this, &VideoSourceGraphics::newDataSlot);
143  mPipeline->setInputVideo(NULL);
144  }
145 
146  mData = data;
147 
148  if (mData)
149  {
150  connect(mData.get(), &VideoSource::newFrame, this, &VideoSourceGraphics::newDataSlot);
151  mPipeline->setInputVideo(mData->getVtkImageData());
152  }
153 
154  this->newDataSlot();
155 }
156 
157 void VideoSourceGraphics::receiveTransforms(Transform3D prMt, double timestamp)
158 {
159  if (!mShowInToolSpace)
160  return;
161  Transform3D rMpr = mSpaceProvider->get_rMpr();
162  Transform3D tMu = mProbeDefinition.get_tMu();
163  Transform3D rMu = rMpr * prMt * tMu;
164  mPipeline->setActorUserMatrix(rMu.getVtkMatrix());
165 }
166 
167 void VideoSourceGraphics::newDataSlot()
168 {
169  if (!mData || !mData->validData())
170  {
171  mPipeline->setVisibility(false);
172  emit newData();
173  return;
174  }
175 
176  mPipeline->update();
177 
178  bool visible = mData->validData();
179  if (mShowInToolSpace)
180  visible = visible && mTool && mTool->getVisible();
181  mPipeline->setVisibility(visible);
182 
183  emit newData();
184 }
185 
186 } // 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