35 #include <vtkUnsignedCharArray.h> 36 #include <vtkImageData.h> 37 #include <vtkPointData.h> 38 #include <vtkDoubleArray.h> 39 #include <vtkImageResample.h> 40 #include <vtkImageClip.h> 41 #include <vtkImageShiftScale.h> 42 #include <vtkImageAccumulate.h> 43 #include <vtkImageLuminance.h> 44 #include <vtkImageExtractComponents.h> 45 #include <vtkImageAppendComponents.h> 65 template<
class TYPE,
int TYPE_FROM_VTK>
72 data->SetSpacing(spacing[0], spacing[1], spacing[2]);
73 data->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
77 data->AllocateScalars(TYPE_FROM_VTK, components);
79 int scalarSize = dim[0]*dim[1]*dim[2]*components;
81 TYPE* ptr =
reinterpret_cast<TYPE*
>(data->GetScalarPointer());
82 std::fill(ptr, ptr+scalarSize, initValue);
107 const unsigned char initValue,
110 return generateVtkImageDataGeneric<unsigned char, VTK_UNSIGNED_CHAR>(dim, spacing, initValue, components);
115 const unsigned short initValue,
118 return generateVtkImageDataGeneric<unsigned short, VTK_UNSIGNED_SHORT>(dim, spacing, initValue, components);
123 const short initValue,
126 return generateVtkImageDataGeneric<short, VTK_SHORT>(dim, spacing, initValue, components);
133 return generateVtkImageDataGeneric<double, VTK_DOUBLE>(dim, spacing, initValue, 1);
138 Eigen::Array3i dim(data->GetDimensions());
140 unsigned short* ptr =
reinterpret_cast<unsigned short*
>(data->GetScalarPointer());
143 for (
int z=0; z<dim[2]; ++z)
144 for (
int y=0; y<dim[1]; ++y)
145 for (
int x=0; x<dim[0]; ++x)
148 int val = int((
double(z)/dim[2]*mod*6))%mod;
151 ptr[z*dim[0]*dim[1] + y*dim[0] + x] = val;
174 ImagePtr retval = dataManager->createSpecificData<
Image>(uid, name);
176 retval->intitializeFromParentImage(parent);
194 if (input->GetScalarTypeMin() >= 0)
198 int shift = -input->GetScalarRange()[0];
200 if (image->getModality().contains(
"CT", Qt::CaseInsensitive))
206 if (!convertedImageData)
209 cast->SetInputData(input);
210 cast->ClampOverflowOn();
212 cast->SetShift(shift);
215 double range = input->GetScalarRange()[1] - input->GetScalarRange()[0];
218 if (range <= VTK_UNSIGNED_SHORT_MAX-VTK_UNSIGNED_SHORT_MIN)
219 cast->SetOutputScalarType(VTK_UNSIGNED_SHORT);
220 else if (range <= VTK_UNSIGNED_INT_MAX-VTK_UNSIGNED_INT_MIN)
221 cast->SetOutputScalarType(VTK_UNSIGNED_INT);
225 cast->SetOutputScalarType(VTK_UNSIGNED_INT);
229 report(QString(
"Converting image %1 from %2 to %3, shift=%4")
230 .arg(image->getName())
231 .arg(input->GetScalarTypeAsString())
232 .arg(cast->GetOutput()->GetScalarTypeAsString())
234 convertedImageData = cast->GetOutput();
238 image->getUid()+
"_u", image->getName()+
" u",
239 convertedImageData, image);
241 ImageTF3DPtr TF3D = retval->getTransferFunctions3D()->createCopy();
242 ImageLUT2DPtr LUT2D = retval->getLookupTable2D()->createCopy();
247 retval->setLookupTable2D(LUT2D);
248 retval->setTransferFunctions3D(TF3D);
255 std::map<std::string, std::string> retval;
260 retval[
"Filename"] = image->getFilename().toStdString();
261 retval[
"Coordinate system"] = image->getCoordinateSystem().toString().toStdString();
262 retval[
"Image type"] = image->getImageType().toStdString();
263 retval[
"Scalar minimum"] =
string_cast(image->getMin());
264 retval[
"Scalar maximum"] =
string_cast(image->getMax());
265 retval[
"Range (max - min)"] =
string_cast(image->getRange());
266 retval[
"Maximum alpha value"] =
string_cast(image->getMaxAlphaValue());
267 retval[
"VTK type min value"] =
string_cast(image->getVTKMinValue());
268 retval[
"VTK type max value"] =
string_cast(image->getVTKMaxValue());
269 retval[
"Modality"] = image->getModality().toStdString();
270 retval[
"Name"] = image->getName().toStdString();
271 retval[
"Parent space"] = image->getParentSpace().toStdString();
272 retval[
"Shading"] = image->getShadingOn() ?
"on" :
"off";
273 retval[
"Space"] = image->getSpace().toStdString();
274 retval[
"Type"] = image->getType().toStdString();
275 retval[
"Uid"] = image->getUid().toStdString();
282 retval.insert(volumeMap.begin(), volumeMap.end());
289 std::map<std::string, std::string> retval;
293 double spacing_x, spacing_y, spacing_z;
294 image->GetSpacing(spacing_x, spacing_y, spacing_z);
297 image->GetDimensions(dims);
300 float actualMemorySizeKB = (float)image->GetActualMemorySize();
302 retval[
"Scalar components"] =
string_cast(image->GetNumberOfScalarComponents());
303 retval[
"Number of components for points"] =
string_cast(image->GetPointData()->GetNumberOfComponents());
304 retval[
"Scalar type"] =
string_cast(image->GetScalarTypeAsString());
305 retval[
"Scalar size"] =
string_cast(image->GetScalarSize());
307 image->GetExtent(extent);
315 report(
"----- DisplayFriendlyInfo -----");
316 std::map<std::string, std::string>::iterator it;
317 for(it = map.begin(); it != map.end(); ++it)
319 QString message((it->first+
": "+it->second).c_str());
322 report(
"-------------------------------");
327 return static_cast<int*
>(image->getHistogram()->GetOutput()->GetScalarPointer(image->getRange(), 0, 0))[0];
331 return static_cast<int*
>(image->getHistogram()->GetOutput()->GetScalarPointer(0,0,0))[0];
339 std::vector<Vector3D> corners_r;
341 for (
unsigned i = 0; i < data.size(); ++i)
346 corners_r.push_back(qMd.coord(bb.
corner(0, 0, 0)));
347 corners_r.push_back(qMd.coord(bb.
corner(0, 0, 1)));
348 corners_r.push_back(qMd.coord(bb.
corner(0, 1, 0)));
349 corners_r.push_back(qMd.coord(bb.
corner(0, 1, 1)));
350 corners_r.push_back(qMd.coord(bb.
corner(1, 0, 0)));
351 corners_r.push_back(qMd.coord(bb.
corner(1, 0, 1)));
352 corners_r.push_back(qMd.coord(bb.
corner(1, 1, 0)));
353 corners_r.push_back(qMd.coord(bb.
corner(1, 1, 1)));
362 std::vector<DataPtr> datas(images.size());
363 for (
unsigned i = 0; i < images.size(); ++i)
364 datas[i] = images[i];
375 if (input->GetNumberOfScalarComponents() > 2)
377 vtkSmartPointer<vtkImageLuminance> luminance = vtkSmartPointer<vtkImageLuminance>::New();
378 luminance->SetInputData(input);
380 retval = luminance->GetOutput();
390 if (image->GetNumberOfScalarComponents() >= 4)
394 splitterRGBA->SetInputData(image);
395 splitterRGBA->SetComponents(0, 1, 2);
396 merger->AddInputConnection(splitterRGBA->GetOutputPort());
399 retval = merger->GetOutput();
407 if (image->GetScalarSize() > 1)
410 imageCast->SetInputData(image);
413 double scalarMin = windowWidth/2.0 - windowLevel;
415 double addToScalarValue = -scalarMin;
416 double multiplyToScalarValue = 255/windowWidth;
418 imageCast->SetShift(addToScalarValue);
419 imageCast->SetScale(multiplyToScalarValue);
420 imageCast->SetOutputScalarTypeToUnsignedChar();
421 imageCast->ClampOverflowOn();
423 retval = imageCast->GetOutput();
432 image->GetPointData()->Modified();
433 image->GetPointData()->GetScalars()->Modified();
std::map< std::string, std::string > getDisplayFriendlyInfo(MeshPtr mesh)
Vector3D corner(int x, int y, int z) const
vtkSmartPointer< class vtkImageShiftScale > vtkImageShiftScalePtr
vtkImageDataPtr generateVtkImageDataUnsignedShort(Eigen::Array3i dim, Vector3D spacing, const unsigned short initValue, int components)
virtual void setVtkImageData(const vtkImageDataPtr &data, bool resetTransferFunctions=true)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
std::string matrixAsSingleLineString(cx::Transform3D transform)
boost::shared_ptr< class Image > ImagePtr
QString timestampSecondsFormatNice()
int calculateNumVoxelsWithMinValue(ImagePtr image)
Find number of voxels containing min scalar value.
DoubleBoundingBox3D findEnclosingBoundingBox(std::vector< DataPtr > data, Transform3D qMr)
vtkImageDataPtr generateVtkImageDataSignedShort(Eigen::Array3i dim, Vector3D spacing, const short initValue, int components)
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
std::string string_cast(const T &val)
ImagePtr convertImageToUnsigned(PatientModelServicePtr dataManager, ImagePtr image, vtkImageDataPtr suggestedConvertedVolume, bool verbose)
ImagePtr createDerivedImage(PatientModelServicePtr dataManager, QString uid, QString name, vtkImageDataPtr raw, ImagePtr parent)
boost::shared_ptr< class ImageLUT2D > ImageLUT2DPtr
vtkSmartPointer< class vtkImageAppendComponents > vtkImageAppendComponentsPtr
vtkImageDataPtr convertImageDataTo8Bit(vtkImageDataPtr image, double windowWidth, double windowLevel)
Have never been used or tested. Create a test for it.
vtkImageDataPtr convertFrom4To3Components(vtkImageDataPtr image)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void fillShortImageDataWithGradient(vtkImageDataPtr data, int maxValue)
int calculateNumVoxelsWithMaxValue(ImagePtr image)
Find number of voxels containing max scalar value.
vtkSmartPointer< vtkDoubleArray > vtkDoubleArrayPtr
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.
vtkImageDataPtr generateVtkImageData(Eigen::Array3i dim, Vector3D spacing, const unsigned char initValue, int components)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
vtkSmartPointer< class vtkImageExtractComponents > vtkImageExtractComponentsPtr
vtkImageDataPtr convertImageDataToGrayScale(vtkImageDataPtr image)
void setDeepModified(vtkImageDataPtr image)
void printDisplayFriendlyInfo(std::map< std::string, std::string > map)
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
vtkImageDataPtr generateVtkImageDataDouble(Eigen::Array3i dim, Vector3D spacing, double initValue)
Namespace for all CustusX production code.