16 #include <vtkImageData.h> 17 #include <vtkPlaneSource.h> 18 #include <vtkTransformTextureCoords.h> 19 #include <vtkTextureMapToPlane.h> 20 #include <vtkDataSetMapper.h> 21 #include <vtkTexture.h> 22 #include <vtkProperty.h> 23 #include <vtkImageMask.h> 24 #include <vtkPointData.h> 25 #include <vtkMatrix4x4.h> 26 #include <vtkLookupTable.h> 27 #include <vtkImageThreshold.h> 28 #include <vtkImageChangeInformation.h> 29 #include <vtkExtractVOI.h> 40 mPlaneActor = vtkActorPtr::New();
41 mPlaneSource = vtkPlaneSourcePtr::New();
43 mDataRedirecter = vtkImageChangeInformationPtr::New();
44 mUSSource = UltrasoundSectorSourcePtr::New();
48 mMapZeroToOne = vtkImageThresholdPtr::New();
49 mMapZeroToOne->ThresholdByLower(1.0);
50 mMapZeroToOne->SetInValue(1);
51 mMapZeroToOne->SetReplaceIn(
true);
54 mMaskFilter = vtkImageMaskPtr::New();
56 mMaskFilter->SetMaskedOutputValue(0.0);
59 mTextureMapToPlane = vtkTextureMapToPlanePtr::New();
61 mTransformTextureCoords = vtkTransformTextureCoordsPtr::New();
62 mTransformTextureCoords->SetOrigin( 0, 0.5, 0);
63 mTransformTextureCoords->SetScale( 1, 1, 0);
64 mTransformTextureCoords->FlipROn();
66 mTexture = vtkTexturePtr::New();
67 mTexture->RepeatOff();
69 mDataSetMapper = vtkDataSetMapperPtr::New();
71 mPlaneActor->SetTexture(mTexture);
72 mPlaneActor->SetMapper(mDataSetMapper);
73 mPlaneActor->SetVisibility(
false);
74 mPlaneActor->GetProperty()->LightingOff();
84 mTransformTextureCoords->SetFlipR(on);
89 return mTransformTextureCoords->GetFlipR();
100 void VideoGraphics::setupPipeline()
104 mTexture->SetInputData(NULL);
110 mTextureMapToPlane->SetInputConnection(mPlaneSource->GetOutputPort());
111 mTransformTextureCoords->SetInputConnection(mTextureMapToPlane->GetOutputPort() );
112 mDataSetMapper->SetInputConnection(mTransformTextureCoords->GetOutputPort() );
114 mMaskFilter->SetMaskInputData(mInputMask);
115 mMapZeroToOne->SetInputConnection(mDataRedirecter->GetOutputPort());
116 mMaskFilter->SetInputConnection(0, mMapZeroToOne->GetOutputPort());
117 mTexture->SetInputConnection(mMaskFilter->GetOutputPort());
119 else if (mInputSector)
121 mUSSource->setProbeSector(mInputSector);
122 mTransformTextureCoords->SetInputConnection(mUSSource->GetOutputPort() );
123 mDataSetMapper->SetInputConnection(mTransformTextureCoords->GetOutputPort() );
125 mTexture->SetInputConnection(mDataRedirecter->GetOutputPort());
129 mTextureMapToPlane->SetInputConnection(mPlaneSource->GetOutputPort());
130 mTransformTextureCoords->SetInputConnection(mTextureMapToPlane->GetOutputPort() );
131 mDataSetMapper->SetInputConnection(mTransformTextureCoords->GetOutputPort() );
133 mTexture->SetInputConnection(mDataRedirecter->GetOutputPort());
136 this->setLookupTable();
137 mPlaneActor->SetTexture(mTexture);
138 mPlaneActor->SetMapper(mDataSetMapper);
143 if (mInputMask==mask)
147 this->setupPipeline();
152 if (mInputSector==sector)
155 mInputSector = sector;
156 this->setupPipeline();
161 if (mInputVideo==video)
164 this->setupPipeline();
169 mPlaneActor->SetUserMatrix(rMu);
174 mPlaneActor->SetVisibility(visible);
175 mPlaneActor->Modified();
180 if (this->inputImageIsEmpty())
186 this->connectVideoImageToPipeline();
188 this->updatePlaneSourceBounds();
190 mPlaneActor->Modified();
193 void VideoGraphics::connectVideoImageToPipeline()
195 if (mInputVideo == NULL)
197 mTexture->SetInputData(NULL);
202 int* extent = mInputVideo->GetExtent();
203 if(extent[5] - extent[4] > 0)
205 int slice = floor(extent[4]+0.5f*(extent[5]-extent[4]));
206 if (slice < 0) slice = 0;
208 vtkSmartPointer<vtkExtractVOI> extractVOI = vtkSmartPointer<vtkExtractVOI>::New();
209 extractVOI->SetInputData(mInputVideo);
210 extractVOI->SetVOI(extent[0], extent[1], extent[2], extent[3], slice, slice);
211 extractVOI->Update();
212 mDataRedirecter->SetInputConnection(extractVOI->GetOutputPort());
216 mDataRedirecter->SetInputData(mInputVideo);
219 mDataRedirecter->UpdateWholeExtent();
220 mDataRedirecter->Update();
224 void VideoGraphics::updatePlaneSourceBounds()
229 if (!
similar(bounds.range()[0], 0.0) || !
similar(bounds.range()[1], 0.0))
231 mPlaneSource->SetOrigin(bounds.corner(0,0,0).begin());
232 mPlaneSource->SetPoint1(bounds.corner(1,0,0).begin());
233 mPlaneSource->SetPoint2(bounds.corner(0,1,0).begin());
234 mPlaneSource->GetOutput()->GetPointData()->Modified();
235 mPlaneSource->GetOutput()->Modified();
239 void VideoGraphics::updateLUT()
241 this->setLookupTable();
242 mTexture->SetLookupTable(mLUT);
245 int numComp = mDataRedirecter->GetOutput()->GetNumberOfScalarComponents();
246 bool is8bit = mDataRedirecter->GetOutput()->GetScalarType()==VTK_UNSIGNED_CHAR;
257 mDataRedirecter->GetOutput()->GetScalarRange(srange);
260 mTexture->GetLookupTable()->SetRange(srange[0], srange[1]);
261 mTexture->MapColorScalarsThroughLookupTableOn();
265 mTexture->MapColorScalarsThroughLookupTableOff();
271 void VideoGraphics::setLookupTable()
281 lut->SetNumberOfTableValues(1000);
283 lut->SetTableRange (0, 255);
284 lut->SetSaturationRange (0, 0);
285 lut->SetHueRange (0, 0);
286 lut->SetValueRange (0, 1);
287 lut->SetRampToLinear();
292 lut->SetTableValue(0, 0, 0, 0, 0);
299 bool VideoGraphics::inputImageIsEmpty()
301 if (mInputVideo == NULL)
305 int* dim = mInputVideo->GetDimensions();
306 if(dim[0] == 0 || dim[1] == 0)
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
vtkSmartPointer< class vtkActor > vtkActorPtr
void setActorUserMatrix(vtkMatrix4x4Ptr rMu)
void setClip(vtkPolyDataPtr sector)
void setFlipVertical(bool on)
void setVisibility(bool visible)
vtkSmartPointer< class vtkLookupTable > vtkLookupTablePtr
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void setInputVideo(vtkImageDataPtr video)
void setMask(vtkImageDataPtr mask)
Namespace for all CustusX production code.