37 #include <vtkImageData.h>
38 #include <vtkPlaneSource.h>
39 #include <vtkTransformTextureCoords.h>
40 #include <vtkTextureMapToPlane.h>
41 #include <vtkDataSetMapper.h>
42 #include <vtkTexture.h>
43 #include <vtkProperty.h>
44 #include <vtkImageMask.h>
45 #include <vtkPointData.h>
46 #include <vtkMatrix4x4.h>
47 #include <vtkLookupTable.h>
48 #include <vtkImageThreshold.h>
49 #include <vtkImageChangeInformation.h>
50 #include <vtkExtractVOI.h>
61 mPlaneActor = vtkActorPtr::New();
62 mPlaneSource = vtkPlaneSourcePtr::New();
64 mDataRedirecter = vtkImageChangeInformationPtr::New();
65 mUSSource = UltrasoundSectorSourcePtr::New();
69 mMapZeroToOne = vtkImageThresholdPtr::New();
70 mMapZeroToOne->ThresholdByLower(1.0);
71 mMapZeroToOne->SetInValue(1);
72 mMapZeroToOne->SetReplaceIn(
true);
75 mMaskFilter = vtkImageMaskPtr::New();
77 mMaskFilter->SetMaskedOutputValue(0.0);
80 mTextureMapToPlane = vtkTextureMapToPlanePtr::New();
82 mTransformTextureCoords = vtkTransformTextureCoordsPtr::New();
83 mTransformTextureCoords->SetOrigin( 0, 0.5, 0);
84 mTransformTextureCoords->SetScale( 1, 1, 0);
85 mTransformTextureCoords->FlipROn();
87 mTexture = vtkTexturePtr::New();
88 mTexture->RepeatOff();
90 mDataSetMapper = vtkDataSetMapperPtr::New();
92 mPlaneActor->SetTexture(mTexture);
93 mPlaneActor->SetMapper(mDataSetMapper);
94 mPlaneActor->SetVisibility(
false);
95 mPlaneActor->GetProperty()->LightingOff();
105 mTransformTextureCoords->SetFlipR(on);
110 return mTransformTextureCoords->GetFlipR();
121 void VideoGraphics::setupPipeline()
125 mTexture->SetInputData(NULL);
131 mTextureMapToPlane->SetInputConnection(mPlaneSource->GetOutputPort());
132 mTransformTextureCoords->SetInputConnection(mTextureMapToPlane->GetOutputPort() );
133 mDataSetMapper->SetInputConnection(mTransformTextureCoords->GetOutputPort() );
135 mMaskFilter->SetMaskInputData(mInputMask);
136 mMapZeroToOne->SetInputConnection(mDataRedirecter->GetOutputPort());
137 mMaskFilter->SetInputConnection(0, mMapZeroToOne->GetOutputPort());
138 mTexture->SetInputConnection(mMaskFilter->GetOutputPort());
140 else if (mInputSector)
142 mUSSource->setProbeSector(mInputSector);
143 mTransformTextureCoords->SetInputConnection(mUSSource->GetOutputPort() );
144 mDataSetMapper->SetInputConnection(mTransformTextureCoords->GetOutputPort() );
146 mTexture->SetInputConnection(mDataRedirecter->GetOutputPort());
150 mTextureMapToPlane->SetInputConnection(mPlaneSource->GetOutputPort());
151 mTransformTextureCoords->SetInputConnection(mTextureMapToPlane->GetOutputPort() );
152 mDataSetMapper->SetInputConnection(mTransformTextureCoords->GetOutputPort() );
154 mTexture->SetInputConnection(mDataRedirecter->GetOutputPort());
157 this->setLookupTable();
158 mPlaneActor->SetTexture(mTexture);
159 mPlaneActor->SetMapper(mDataSetMapper);
164 if (mInputMask==mask)
168 this->setupPipeline();
173 if (mInputSector==sector)
176 mInputSector = sector;
177 this->setupPipeline();
182 if (mInputVideo==video)
185 this->setupPipeline();
190 mPlaneActor->SetUserMatrix(rMu);
195 mPlaneActor->SetVisibility(visible);
196 mPlaneActor->Modified();
201 if (this->inputImageIsEmpty())
207 this->connectVideoImageToPipeline();
209 this->updatePlaneSourceBounds();
211 mPlaneActor->Modified();
214 void VideoGraphics::connectVideoImageToPipeline()
216 if (mInputVideo == NULL)
218 mTexture->SetInputData(NULL);
223 int* extent = mInputVideo->GetExtent();
224 if(extent[5] - extent[4] > 0)
226 int slice = floor(extent[4]+0.5f*(extent[5]-extent[4]));
227 if (slice < 0) slice = 0;
229 vtkSmartPointer<vtkExtractVOI> extractVOI = vtkSmartPointer<vtkExtractVOI>::New();
230 extractVOI->SetInputData(mInputVideo);
231 extractVOI->SetVOI(extent[0], extent[1], extent[2], extent[3], slice, slice);
232 extractVOI->Update();
233 mDataRedirecter->SetInputConnection(extractVOI->GetOutputPort());
237 mDataRedirecter->SetInputData(mInputVideo);
240 mDataRedirecter->UpdateWholeExtent();
241 mDataRedirecter->Update();
245 void VideoGraphics::updatePlaneSourceBounds()
249 DoubleBoundingBox3D bounds(mDataRedirecter->GetOutput()->GetBounds());
250 if (!
similar(bounds.range()[0], 0.0) || !
similar(bounds.range()[1], 0.0))
252 mPlaneSource->SetOrigin(bounds.corner(0,0,0).begin());
253 mPlaneSource->SetPoint1(bounds.corner(1,0,0).begin());
254 mPlaneSource->SetPoint2(bounds.corner(0,1,0).begin());
255 mPlaneSource->GetOutput()->GetPointData()->Modified();
256 mPlaneSource->GetOutput()->Modified();
260 void VideoGraphics::updateLUT()
262 this->setLookupTable();
263 mTexture->SetLookupTable(mLUT);
266 int numComp = mDataRedirecter->GetOutput()->GetNumberOfScalarComponents();
267 bool is8bit = mDataRedirecter->GetOutput()->GetScalarType()==VTK_UNSIGNED_CHAR;
278 mDataRedirecter->GetOutput()->GetScalarRange(srange);
281 mTexture->GetLookupTable()->SetRange(srange[0], srange[1]);
282 mTexture->MapColorScalarsThroughLookupTableOn();
286 mTexture->MapColorScalarsThroughLookupTableOff();
292 void VideoGraphics::setLookupTable()
302 lut->SetNumberOfTableValues(1000);
304 lut->SetTableRange (0, 255);
305 lut->SetSaturationRange (0, 0);
306 lut->SetHueRange (0, 0);
307 lut->SetValueRange (0, 1);
308 lut->SetRampToLinear();
313 lut->SetTableValue(0, 0, 0, 0, 0);
320 bool VideoGraphics::inputImageIsEmpty()
322 if (mInputVideo == NULL)
326 int* dim = mInputVideo->GetDimensions();
327 if(dim[0] == 0 || dim[1] == 0)
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
vtkSmartPointer< class vtkActor > vtkActorPtr
void setActorUserMatrix(vtkMatrix4x4Ptr rMu)
void setClip(vtkPolyDataPtr sector)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
void setFlipVertical(bool on)
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
void setVisibility(bool visible)
vtkSmartPointer< class vtkLookupTable > vtkLookupTablePtr
void setInputVideo(vtkImageDataPtr video)
void setMask(vtkImageDataPtr mask)