14 #include <vtkImageData.h> 15 #include <vtkImageReslice.h> 16 #include <vtkMatrix4x4.h> 18 #include <vtkImageResample.h> 19 #include <vtkImageClip.h> 20 #include <vtkImageChangeInformation.h> 52 orientator->SetInputData(image->getBaseVtkImageData());
53 orientator->SetInterpolationModeToLinear();
54 orientator->SetOutputDimensionality(3);
55 orientator->SetResliceAxes(qMd.inv().getVtkMatrix());
56 orientator->AutoCropOutputOn();
62 QString uid = image->getUid() +
"_or%1";
63 QString name = image->getName()+
" or%1";
70 oriented->get_rMd_History()->setRegistration(image->get_rMd() * qMd.inv());
71 oriented->mergevtkSettingsIntosscTransform();
82 resampler->SetInputData(image->getBaseVtkImageData());
83 resampler->SetAxisOutputSpacing(0, spacing[0]);
84 resampler->SetAxisOutputSpacing(1, spacing[1]);
85 resampler->SetAxisOutputSpacing(2, spacing[2]);
91 uid = image->getUid() +
"_res%1";
92 name = image->getName()+
" res%1";
106 Vector3D spacing(image->getBaseVtkImageData()->GetSpacing());
107 return resampleImage(dataManager, image, spacing, image->getUid()+
"_copy%1", image->getName()+
" copy%1");
116 clip->SetInputData(input);
117 clip->SetOutputWholeExtent(cropbox.begin());
124 rawResult->ComputeBounds();
134 double* sp = image->getBaseVtkImageData()->GetSpacing();
136 static_cast<int>(bb[0]/sp[0]+0.5), static_cast<int>(bb[1]/sp[0]+0.5),
137 static_cast<int>(bb[2]/sp[1]+0.5), static_cast<int>(bb[3]/sp[1]+0.5),
138 static_cast<int>(bb[4]/sp[2]+0.5), static_cast<int>(bb[5]/sp[2]+0.5));
141 QString uid = image->getUid() +
"_crop%1";
142 QString name = image->getName()+
" crop%1";
146 result->mergevtkSettingsIntosscTransform();
156 QRegExp tsReg(
"[0-9]{8}T[0-9]{6}");
157 if (tsReg.indexIn(text)>0)
168 if ( !imageData ) {
return QImage(); }
170 int width = imageData->GetDimensions()[0];
171 int height = imageData->GetDimensions()[1];
173 QImage image( width, height, QImage::Format_ARGB32 );
174 QRgb *rgbPtr =
reinterpret_cast<QRgb *
>( image.bits() ) + width * ( height - 1 );
175 unsigned char *colorsPtr =
reinterpret_cast<unsigned char *
>( imageData->GetScalarPointer() );
178 for (
int row = 0; row < height; row++ )
180 for (
int col = 0; col < width; col++ )
185 colorsPtr += imageData->GetNumberOfScalarComponents();
201 rgb = QColor(colorsPtr[0], colorsPtr[1], colorsPtr[2], colorsPtr[3] ).rgba();
209 unsigned char threshold = 10;
210 if (colorsPtr[0] < threshold &&
211 colorsPtr[1] < threshold &&
212 colorsPtr[2] < threshold)
220 overlayColor.setAlpha(0);
222 QRgb retval = overlayColor.rgba();
230 if(!image || !patientModel)
238 proxy->setTool(sliceTool);
240 imageSlicer->setSliceProxy(proxy);
241 imageSlicer->setImage(image);
243 proxy->initializeFromPlane(planeType,
false,
false, 1, 0);
247 double screenX = outputDimensions[0]*outputSpacing[0] / 2;
248 double screenY = outputDimensions[1]*outputSpacing[1] / 2;
250 imageSlicer->setOutputFormat(
Vector3D(-screenX,-screenY,0), outputDimensions, outputSpacing);
252 imageSlicer->update();
255 imageSlicer->getOutputPort()->Update();
256 retval->DeepCopy(imageSlicer->getOutput());
260 imageSlicer->getOutputPortWithoutLUT()->Update();
261 retval->DeepCopy(imageSlicer->getOutputWithoutLUT());
274 imageReslicer->SetInputData(image->getBaseVtkImageData());
275 imageReslicer->SetBackgroundLevel(image->getMin());
277 imageReslicer->SetInterpolationModeToLinear();
278 imageReslicer->SetOutputDimensionality(2);
281 Eigen::Array3d inputSpacing = image->getSpacing();
289 image->getBaseVtkImageData()->GetExtent(extent);
296 vtkSmartPointer<vtkMatrix4x4> resliceAxes = vtkSmartPointer<vtkMatrix4x4>::New();
308 resliceAxes->SetElement(0, 0, 1);
309 resliceAxes->SetElement(0, 1, 0);
310 resliceAxes->SetElement(0, 2, 0);
311 resliceAxes->SetElement(0, 3, 0);
312 resliceAxes->SetElement(1, 0, 0);
313 resliceAxes->SetElement(1, 1, -1);
314 resliceAxes->SetElement(1, 2, 0);
315 resliceAxes->SetElement(1, 3, 0);
316 resliceAxes->SetElement(2, 0, 0);
317 resliceAxes->SetElement(2, 1, 0);
318 resliceAxes->SetElement(2, 2, 1);
319 resliceAxes->SetElement(2, 3, positionTransform_d(2,3) + offset);
320 resliceAxes->SetElement(3, 0, 0);
321 resliceAxes->SetElement(3, 1, 0);
322 resliceAxes->SetElement(3, 2, 0);
323 resliceAxes->SetElement(3, 3, 1);
324 imageReslicer->SetResliceAxes(resliceAxes);
325 imageReslicer->SetOutputExtent(extent[0], extent[1], extent[2], extent[3], 0, 0);
326 imageReslicer->SetOutputSpacing(inputSpacing[0], inputSpacing[1], 0);
329 resliceAxes->SetElement(0, 0, 1);
330 resliceAxes->SetElement(0, 1, 0);
331 resliceAxes->SetElement(0, 2, 0);
332 resliceAxes->SetElement(0, 3, 0);
333 resliceAxes->SetElement(1, 0, 0);
334 resliceAxes->SetElement(1, 1, 0);
335 resliceAxes->SetElement(1, 2, 1);
336 resliceAxes->SetElement(1, 3, positionTransform_d(1,3) + offset);
337 resliceAxes->SetElement(2, 0, 0);
338 resliceAxes->SetElement(2, 1, 1);
339 resliceAxes->SetElement(2, 2, 0);
340 resliceAxes->SetElement(2, 3, 0);
341 resliceAxes->SetElement(3, 0, 0);
342 resliceAxes->SetElement(3, 1, 0);
343 resliceAxes->SetElement(3, 2, 0);
344 resliceAxes->SetElement(3, 3, 1);
345 imageReslicer->SetResliceAxes(resliceAxes);
346 imageReslicer->SetOutputExtent(extent[0], extent[1], extent[4], extent[5], 0, 0);
347 imageReslicer->SetOutputSpacing(inputSpacing[0], inputSpacing[2], 0);
350 resliceAxes->SetElement(0, 0, 0);
351 resliceAxes->SetElement(0, 1, 0);
352 resliceAxes->SetElement(0, 2, -1);
353 resliceAxes->SetElement(0, 3, positionTransform_d(0,3));
354 resliceAxes->SetElement(1, 0, 1);
355 resliceAxes->SetElement(1, 1, 0);
356 resliceAxes->SetElement(1, 2, 0);
357 resliceAxes->SetElement(1, 3, 0);
358 resliceAxes->SetElement(2, 0, 0);
359 resliceAxes->SetElement(2, 1, 1);
360 resliceAxes->SetElement(2, 2, 0);
361 resliceAxes->SetElement(2, 3, 0);
362 resliceAxes->SetElement(3, 0, 0);
363 resliceAxes->SetElement(3, 1, 0);
364 resliceAxes->SetElement(3, 2, 0);
365 resliceAxes->SetElement(3, 3, 1);
366 imageReslicer->SetResliceAxes(resliceAxes);
367 imageReslicer->SetOutputExtent(extent[2], extent[3], extent[4], extent[5], 0, 0);
368 imageReslicer->SetOutputSpacing(inputSpacing[1], inputSpacing[2], 0);
372 direction(0) = targetTransform_d(0,3) - positionTransform_d(0,3);
373 direction(1) = targetTransform_d(1,3) - positionTransform_d(1,3);
374 direction(2) = targetTransform_d(2,3) - positionTransform_d(2,3);
375 direction = direction.normalized();
376 xAxis = up.cross(direction).normalized();
377 yAxis = direction.cross(xAxis).normalized();
379 resliceAxes->SetElement(0, 0, xAxis(0));
380 resliceAxes->SetElement(0, 1, yAxis(0));
381 resliceAxes->SetElement(0, 2, direction(0));
382 resliceAxes->SetElement(0, 3, positionTransform_d(0,3) + offset*direction(0));
383 resliceAxes->SetElement(1, 0, xAxis(1));
384 resliceAxes->SetElement(1, 1, yAxis(1));
385 resliceAxes->SetElement(1, 2, direction(1));
386 resliceAxes->SetElement(1, 3, positionTransform_d(1,3) + offset*direction(1));
387 resliceAxes->SetElement(2, 0, xAxis(2));
388 resliceAxes->SetElement(2, 1, yAxis(2));
389 resliceAxes->SetElement(2, 2, direction(2));
390 resliceAxes->SetElement(2, 3, positionTransform_d(2,3) + offset*direction(2));
391 resliceAxes->SetElement(3, 0, 0);
392 resliceAxes->SetElement(3, 1, 0);
393 resliceAxes->SetElement(3, 2, 0);
394 resliceAxes->SetElement(3, 3, 1);
395 imageReslicer->SetResliceAxes(resliceAxes);
396 imageReslicer->SetOutputExtent(extent[0], extent[1], extent[2], extent[3], 0, 0);
397 imageReslicer->SetOutputSpacing(inputSpacing[0], inputSpacing[1], 0);
403 imageReslicer->Update();
409 redirecterPtr->SetInputConnection(imageReslicer->GetOutputPort());
411 imageWithLUTProxyPtr->setInput(redirecterPtr, image->getLookupTable2D()->getOutputLookupTable());
413 imageWithLUTProxyPtr->getOutputPort()->Update();
414 slicedImage->DeepCopy(imageWithLUTProxyPtr->getOutput());
417 slicedImage = imageReslicer->GetOutput();
424 std::vector<int> voxel(2,0);
427 Eigen::Array3d spacing = image->getSpacing();
429 int xVoxel =
std::round( positionTransform_d(0,3) / spacing(0) );
430 int yVoxel =
std::round( positionTransform_d(1,3) / spacing(1) );
431 int zVoxel =
std::round( positionTransform_d(2,3) / spacing(2) );
458 Eigen::Array3d spacing = image->getSpacing();
464 sliceNumber =
std::round( positionTransform_d(2,3) / spacing(2) );
467 sliceNumber =
std::round( positionTransform_d(1,3) / spacing(1) );
470 sliceNumber =
std::round( positionTransform_d(0,3) / spacing(0) );
483 Eigen::Array3d spacing = image->getSpacing();
489 position_d(0) = voxel[0]*spacing(0);
490 position_d(1) = voxel[1]*spacing(1);
491 position_d(2) = sliceNumber*spacing(2);
494 position_d(0) = voxel[0]*spacing(0);
495 position_d(1) = sliceNumber*spacing(1);
496 position_d(2) = voxel[1]*spacing(2);
499 position_d(0) = sliceNumber*spacing(0);
500 position_d(1) = voxel[0]*spacing(1);
501 position_d(2) = voxel[1]*spacing(2);
509 position_r(0) = positionTransform_r(0,3);
510 position_r(1) = positionTransform_r(1,3);
511 position_r(2) = positionTransform_r(2,3);
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
int getSliceNumberFrom3Dposition(ImagePtr image, PLANE_TYPE planeType, Vector3D position_r)
QRgb modifyOverlayColor(unsigned char *colorsPtr, QColor overlayColor)
ImagePtr resampleImage(PatientModelServicePtr dataManager, ImagePtr image, Transform3D qMd)
ptCORONAL
a slice seen from the front of the patient
static SliceProxyPtr create(PatientModelServicePtr dataManager)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
QRgb convertToQColor(unsigned char *colorsPtr, bool overlay, QColor overlayColor)
vtkImageDataPtr cropImage(vtkImageDataPtr input, IntBoundingBox3D cropbox)
boost::shared_ptr< class Image > ImagePtr
vtkSmartPointer< vtkImageChangeInformation > vtkImageChangeInformationPtr
boost::shared_ptr< class SlicedImageProxy > SlicedImageProxyPtr
ptAXIAL
a slice seen from the top of the patient
QString timestampSecondsFormat()
Helper class for slicing an image given a SliceProxy and an image.
boost::shared_ptr< class ApplyLUTToImage2DProxy > ApplyLUTToImage2DProxyPtr
vtkImageDataPtr createSlice(ImagePtr image, PLANE_TYPE planeType, Vector3D outputSpacing, Eigen::Array3i outputDimensions, ToolPtr sliceTool, PatientModelServicePtr patientModel, bool applyLUT)
createSlice Creates a 2D slice through a 3D volume. Result slice will be oriented for radiological vi...
bool isDark(unsigned char *colorsPtr)
ptSAGITTAL
a slice seen from the side of the patient
ImagePtr duplicateImage(PatientModelServicePtr dataManager, ImagePtr image)
ImagePtr createDerivedImage(PatientModelServicePtr dataManager, QString uid, QString name, vtkImageDataPtr raw, ImagePtr parent)
vtkSmartPointer< class vtkImageReslice > vtkImageReslicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Vector3D get3DpositionFromSliceVoxel(ImagePtr image, PLANE_TYPE planeType, std::vector< int > voxel, int sliceNumber)
Transform3D createTransformTranslate(const Vector3D &translation)
Representation of an integer bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
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< class vtkImageResample > vtkImageResamplePtr
QImage vtkImageDataToQImage(vtkImageDataPtr imageData, bool overlay, QColor overlayColor)
vtkSmartPointer< class vtkImageClip > vtkImageClipPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
ptRADIALPLANE
y-rotated 90* relative to anyplane (bird's view)
QDateTime extractTimestamp(QString text)
std::vector< int > getSliceVoxelFrom3Dposition(ImagePtr image, PLANE_TYPE planeType, Vector3D position_r)
QString enum2string(const ENUM &val)
Vector3D round(const Vector3D &a)
Helper class for applying sscLUT2D to an image.
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr