14 #include <vtkUnsignedCharArray.h> 15 #include <vtkImageData.h> 16 #include <vtkPointData.h> 17 #include <vtkDoubleArray.h> 18 #include <vtkImageResample.h> 19 #include <vtkImageClip.h> 20 #include <vtkImageShiftScale.h> 21 #include <vtkImageAccumulate.h> 22 #include <vtkImageLuminance.h> 23 #include <vtkImageExtractComponents.h> 24 #include <vtkImageAppendComponents.h> 44 template<
class TYPE,
int TYPE_FROM_VTK>
51 data->SetSpacing(spacing[0], spacing[1], spacing[2]);
52 data->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
56 data->AllocateScalars(TYPE_FROM_VTK, components);
58 int scalarSize = dim[0]*dim[1]*dim[2]*components;
60 TYPE* ptr =
reinterpret_cast<TYPE*
>(data->GetScalarPointer());
61 std::fill(ptr, ptr+scalarSize, initValue);
86 const unsigned char initValue,
89 return generateVtkImageDataGeneric<unsigned char, VTK_UNSIGNED_CHAR>(dim, spacing, initValue, components);
94 const unsigned short initValue,
97 return generateVtkImageDataGeneric<unsigned short, VTK_UNSIGNED_SHORT>(dim, spacing, initValue, components);
102 const short initValue,
105 return generateVtkImageDataGeneric<short, VTK_SHORT>(dim, spacing, initValue, components);
112 return generateVtkImageDataGeneric<double, VTK_DOUBLE>(dim, spacing, initValue, 1);
117 Eigen::Array3i dim(data->GetDimensions());
119 unsigned short* ptr =
reinterpret_cast<unsigned short*
>(data->GetScalarPointer());
122 for (
int z=0; z<dim[2]; ++z)
123 for (
int y=0; y<dim[1]; ++y)
124 for (
int x=0; x<dim[0]; ++x)
127 int val = int((
double(z)/dim[2]*mod*6))%mod;
130 ptr[z*dim[0]*dim[1] + y*dim[0] + x] = val;
153 ImagePtr retval = dataManager->createSpecificData<
Image>(uid, name);
155 retval->intitializeFromParentImage(parent);
173 if (input->GetScalarTypeMin() >= 0)
177 int shift = -input->GetScalarRange()[0];
179 if (image->getModality() ==
imCT)
185 if (!convertedImageData)
188 cast->SetInputData(input);
189 cast->ClampOverflowOn();
191 cast->SetShift(shift);
194 double range = input->GetScalarRange()[1] - input->GetScalarRange()[0];
197 if (range <= VTK_UNSIGNED_SHORT_MAX-VTK_UNSIGNED_SHORT_MIN)
198 cast->SetOutputScalarType(VTK_UNSIGNED_SHORT);
199 else if (range <= VTK_UNSIGNED_INT_MAX-VTK_UNSIGNED_INT_MIN)
200 cast->SetOutputScalarType(VTK_UNSIGNED_INT);
204 cast->SetOutputScalarType(VTK_UNSIGNED_INT);
208 report(QString(
"Converting image %1 from %2 to %3, shift=%4")
209 .arg(image->getName())
210 .arg(input->GetScalarTypeAsString())
211 .arg(cast->GetOutput()->GetScalarTypeAsString())
213 convertedImageData = cast->GetOutput();
217 image->getUid()+
"_u", image->getName()+
" u",
218 convertedImageData, image);
220 ImageTF3DPtr TF3D = retval->getTransferFunctions3D()->createCopy();
221 ImageLUT2DPtr LUT2D = retval->getLookupTable2D()->createCopy();
226 retval->setLookupTable2D(LUT2D);
227 retval->setTransferFunctions3D(TF3D);
234 std::map<std::string, std::string> retval;
239 retval[
"Filename"] = image->getFilename().toStdString();
240 retval[
"Coordinate system"] = image->getCoordinateSystem().toString().toStdString();
241 retval[
"Image type"] =
enum2string(image->getImageType()).toStdString();
242 retval[
"Scalar minimum"] =
string_cast(image->getMin());
243 retval[
"Scalar maximum"] =
string_cast(image->getMax());
244 retval[
"Range (max - min)"] =
string_cast(image->getRange());
245 retval[
"Maximum alpha value"] =
string_cast(image->getMaxAlphaValue());
246 retval[
"VTK type min value"] =
string_cast(image->getVTKMinValue());
247 retval[
"VTK type max value"] =
string_cast(image->getVTKMaxValue());
248 retval[
"Modality"] =
enum2string(image->getModality()).toStdString();
249 retval[
"Name"] = image->getName().toStdString();
250 retval[
"Parent space"] = image->getParentSpace().toStdString();
251 retval[
"Shading"] = image->getShadingOn() ?
"on" :
"off";
252 retval[
"Space"] = image->getSpace().toStdString();
253 retval[
"Type"] = image->getType().toStdString();
254 retval[
"Uid"] = image->getUid().toStdString();
261 retval.insert(volumeMap.begin(), volumeMap.end());
268 std::map<std::string, std::string> retval;
272 double spacing_x, spacing_y, spacing_z;
273 image->GetSpacing(spacing_x, spacing_y, spacing_z);
276 image->GetDimensions(dims);
279 float actualMemorySizeKB = (float)image->GetActualMemorySize();
281 retval[
"Scalar components"] =
string_cast(image->GetNumberOfScalarComponents());
282 retval[
"Number of components for points"] =
string_cast(image->GetPointData()->GetNumberOfComponents());
283 retval[
"Scalar type"] =
string_cast(image->GetScalarTypeAsString());
284 retval[
"Scalar size"] =
string_cast(image->GetScalarSize());
286 image->GetExtent(extent);
294 report(
"----- DisplayFriendlyInfo -----");
295 std::map<std::string, std::string>::iterator it;
296 for(it = map.begin(); it != map.end(); ++it)
298 QString message((it->first+
": "+it->second).c_str());
301 report(
"-------------------------------");
306 return static_cast<int*
>(image->getHistogram()->GetOutput()->GetScalarPointer(image->getRange(), 0, 0))[0];
310 return static_cast<int*
>(image->getHistogram()->GetOutput()->GetScalarPointer(0,0,0))[0];
318 std::vector<Vector3D> corners_r;
320 for (
unsigned i = 0; i < data.size(); ++i)
325 corners_r.push_back(qMd.coord(bb.
corner(0, 0, 0)));
326 corners_r.push_back(qMd.coord(bb.
corner(0, 0, 1)));
327 corners_r.push_back(qMd.coord(bb.
corner(0, 1, 0)));
328 corners_r.push_back(qMd.coord(bb.
corner(0, 1, 1)));
329 corners_r.push_back(qMd.coord(bb.
corner(1, 0, 0)));
330 corners_r.push_back(qMd.coord(bb.
corner(1, 0, 1)));
331 corners_r.push_back(qMd.coord(bb.
corner(1, 1, 0)));
332 corners_r.push_back(qMd.coord(bb.
corner(1, 1, 1)));
341 std::vector<DataPtr> datas(images.size());
342 for (
unsigned i = 0; i < images.size(); ++i)
343 datas[i] = images[i];
354 if (input->GetNumberOfScalarComponents() > 2)
356 vtkSmartPointer<vtkImageLuminance> luminance = vtkSmartPointer<vtkImageLuminance>::New();
357 luminance->SetInputData(input);
359 retval = luminance->GetOutput();
369 if (image->GetNumberOfScalarComponents() >= 4)
373 splitterRGBA->SetInputData(image);
374 splitterRGBA->SetComponents(0, 1, 2);
375 merger->AddInputConnection(splitterRGBA->GetOutputPort());
378 retval = merger->GetOutput();
386 if (image->GetScalarSize() > 1)
389 imageCast->SetInputData(image);
392 double scalarMin = windowWidth/2.0 - windowLevel;
394 double addToScalarValue = -scalarMin;
395 double multiplyToScalarValue = 255/windowWidth;
397 imageCast->SetShift(addToScalarValue);
398 imageCast->SetScale(multiplyToScalarValue);
399 imageCast->SetOutputScalarTypeToUnsignedChar();
400 imageCast->ClampOverflowOn();
402 retval = imageCast->GetOutput();
411 image->GetPointData()->Modified();
412 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)
QString enum2string(const ENUM &val)
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
vtkImageDataPtr generateVtkImageDataDouble(Eigen::Array3i dim, Vector3D spacing, double initValue)
Namespace for all CustusX production code.