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>
63 template<
class TYPE,
int TYPE_FROM_VTK>
70 data->SetSpacing(spacing[0], spacing[1], spacing[2]);
71 data->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
75 data->AllocateScalars(TYPE_FROM_VTK, components);
77 int scalarSize = dim[0]*dim[1]*dim[2]*components;
79 TYPE* ptr =
reinterpret_cast<TYPE*
>(data->GetScalarPointer());
80 std::fill(ptr, ptr+scalarSize, initValue);
105 const unsigned char initValue,
108 return generateVtkImageDataGeneric<unsigned char, VTK_UNSIGNED_CHAR>(dim, spacing, initValue, components);
113 const unsigned short initValue,
116 return generateVtkImageDataGeneric<unsigned short, VTK_UNSIGNED_SHORT>(dim, spacing, initValue, components);
121 const short initValue,
124 return generateVtkImageDataGeneric<short, VTK_SHORT>(dim, spacing, initValue, components);
131 return generateVtkImageDataGeneric<double, VTK_DOUBLE>(dim, spacing, initValue, 1);
136 Eigen::Array3i dim(data->GetDimensions());
138 unsigned short* ptr =
reinterpret_cast<unsigned short*
>(data->GetScalarPointer());
141 for (
int z=0; z<dim[2]; ++z)
142 for (
int y=0; y<dim[1]; ++y)
143 for (
int x=0; x<dim[0]; ++x)
146 int val = int((
double(z)/dim[2]*mod*6))%mod;
149 ptr[z*dim[0]*dim[1] + y*dim[0] + x] = val;
172 ImagePtr retval = dataManager->createSpecificData<
Image>(uid, name);
174 retval->intitializeFromParentImage(parent);
192 if (input->GetScalarTypeMin() >= 0)
196 int shift = -input->GetScalarRange()[0];
198 if (image->getModality().contains(
"CT", Qt::CaseInsensitive))
204 if (!convertedImageData)
207 cast->SetInputData(input);
208 cast->ClampOverflowOn();
210 cast->SetShift(shift);
213 double range = input->GetScalarRange()[1] - input->GetScalarRange()[0];
216 if (range <= VTK_UNSIGNED_SHORT_MAX-VTK_UNSIGNED_SHORT_MIN)
217 cast->SetOutputScalarType(VTK_UNSIGNED_SHORT);
218 else if (range <= VTK_UNSIGNED_INT_MAX-VTK_UNSIGNED_INT_MIN)
219 cast->SetOutputScalarType(VTK_UNSIGNED_INT);
223 cast->SetOutputScalarType(VTK_UNSIGNED_INT);
227 report(QString(
"Converting image %1 from %2 to %3, shift=%4")
228 .arg(image->getName())
229 .arg(input->GetScalarTypeAsString())
230 .arg(cast->GetOutput()->GetScalarTypeAsString())
232 convertedImageData = cast->GetOutput();
236 image->getUid()+
"_u", image->getName()+
" u",
237 convertedImageData, image);
239 ImageTF3DPtr TF3D = retval->getTransferFunctions3D()->createCopy();
240 ImageLUT2DPtr LUT2D = retval->getLookupTable2D()->createCopy();
245 retval->setLookupTable2D(LUT2D);
246 retval->setTransferFunctions3D(TF3D);
253 std::map<std::string, std::string> retval;
258 retval[
"Filename"] = image->getFilename().toStdString();
259 retval[
"Coordinate system"] = image->getCoordinateSystem().toString().toStdString();
260 retval[
"Image type"] = image->getImageType().toStdString();
261 retval[
"Scalar minimum"] =
string_cast(image->getMin());
262 retval[
"Scalar maximum"] =
string_cast(image->getMax());
263 retval[
"Range (max - min)"] =
string_cast(image->getRange());
264 retval[
"Maximum alpha value"] =
string_cast(image->getMaxAlphaValue());
265 retval[
"Modality"] = image->getModality().toStdString();
266 retval[
"Name"] = image->getName().toStdString();
267 retval[
"Parent space"] = image->getParentSpace().toStdString();
268 retval[
"Shading"] = image->getShadingOn() ?
"on" :
"off";
269 retval[
"Space"] = image->getSpace().toStdString();
270 retval[
"Type"] = image->getType().toStdString();
271 retval[
"Uid"] = image->getUid().toStdString();
278 retval.insert(volumeMap.begin(), volumeMap.end());
285 std::map<std::string, std::string> retval;
289 double spacing_x, spacing_y, spacing_z;
290 image->GetSpacing(spacing_x, spacing_y, spacing_z);
293 image->GetDimensions(dims);
296 float actualMemorySizeKB = (float)image->GetActualMemorySize();
298 retval[
"Scalar components"] =
string_cast(image->GetNumberOfScalarComponents());
299 retval[
"Number of components for points"] =
string_cast(image->GetPointData()->GetNumberOfComponents());
300 retval[
"Scalar type"] =
string_cast(image->GetScalarTypeAsString());
301 retval[
"Scalar size"] =
string_cast(image->GetScalarSize());
303 image->GetExtent(extent);
311 report(
"----- DisplayFriendlyInfo -----");
312 std::map<std::string, std::string>::iterator it;
313 for(it = map.begin(); it != map.end(); ++it)
315 QString message((it->first+
": "+it->second).c_str());
318 report(
"-------------------------------");
323 return static_cast<int*
>(image->getHistogram()->GetOutput()->GetScalarPointer())[image->getRange()];
327 return static_cast<int*
>(image->getHistogram()->GetOutput()->GetScalarPointer())[0];
335 std::vector<Vector3D> corners_r;
337 for (
unsigned i = 0; i < data.size(); ++i)
342 corners_r.push_back(qMd.coord(bb.
corner(0, 0, 0)));
343 corners_r.push_back(qMd.coord(bb.
corner(0, 0, 1)));
344 corners_r.push_back(qMd.coord(bb.
corner(0, 1, 0)));
345 corners_r.push_back(qMd.coord(bb.
corner(0, 1, 1)));
346 corners_r.push_back(qMd.coord(bb.
corner(1, 0, 0)));
347 corners_r.push_back(qMd.coord(bb.
corner(1, 0, 1)));
348 corners_r.push_back(qMd.coord(bb.
corner(1, 1, 0)));
349 corners_r.push_back(qMd.coord(bb.
corner(1, 1, 1)));
358 std::vector<DataPtr> datas(images.size());
359 for (
unsigned i = 0; i < images.size(); ++i)
360 datas[i] = images[i];
367 if (image->GetNumberOfScalarComponents() > 2)
369 vtkSmartPointer<vtkImageLuminance> luminance = vtkSmartPointer<vtkImageLuminance>::New();
370 luminance->SetInputData(image);
372 retval = luminance->GetOutput();
381 if (image->GetScalarSize() > 1)
384 imageCast->SetInputData(image);
387 double scalarMin = windowWidth/2.0 - windowLevel;
389 double addToScalarValue = -scalarMin;
390 double multiplyToScalarValue = 255/windowWidth;
392 imageCast->SetShift(addToScalarValue);
393 imageCast->SetScale(multiplyToScalarValue);
394 imageCast->SetOutputScalarTypeToUnsignedChar();
395 imageCast->ClampOverflowOn();
397 retval = imageCast->GetOutput();
406 image->GetPointData()->Modified();
407 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.
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
vtkImageDataPtr convertImageDataTo8Bit(vtkImageDataPtr image, double windowWidth, double windowLevel)
Have never been used or tested. Create a test for it.
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.
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)