Commit c6e5246f authored by saubatn's avatar saubatn
Browse files

FIXED BUG 143

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@2161 ec899d31-69d1-42ba-9299-647d76f65fb3
parent b78a5f3b
......@@ -44,6 +44,9 @@ using namespace camitk;
#include <vtkPNMWriter.h>
#include <vtkMetaImageWriter.h>
/// NICO
#include <vtkImageShiftScale.h>
// --------------- declare the plugin -------------------
Q_EXPORT_PLUGIN2(vtkimage, VtkImageComponentExtension)
......@@ -133,8 +136,23 @@ bool VtkImageComponentExtension::save(Component* component) const {
QString fileExt = fileInfo.completeSuffix();
// filename prefix (for 2D image series)
QString filePattern = fileInfo.absoluteDir().absolutePath() + fileInfo.baseName();
QString filePattern = fileInfo.absoluteDir().absolutePath() + "/" + fileInfo.baseName();
filePattern.append("_%04u.").append(fileExt);
// for any file format, image should be unsigned char casted (see vtk image writers doc).
// to cast an image into another scalar type, use vtkImageShiftScale instead of vtkImageCast (see doc).
vtkSmartPointer<vtkImageShiftScale> castFilter = vtkSmartPointer<vtkImageShiftScale>::New();
// get image scalar range
double *imgRange = image->GetScalarRange();
double scalarTypeMin = imgRange[0];
double scalarTypeMax = imgRange[1];
double shift = (scalarTypeMax - scalarTypeMin) / 2;
double scale = 255.0d / (scalarTypeMax - scalarTypeMin);
castFilter->SetShift(shift);
castFilter->SetScale(scale);
castFilter->SetOutputScalarTypeToUnsignedChar();
castFilter->SetInput(image);
castFilter->Update();
// Writer initialization, depending on file extension
if (QString::compare(fileExt, "jpg", Qt::CaseInsensitive) == 0) {
......@@ -146,7 +164,7 @@ bool VtkImageComponentExtension::save(Component* component) const {
} else if ((QString::compare(fileExt, "tiff", Qt::CaseInsensitive) == 0) ||
(QString::compare(fileExt, "tif", Qt::CaseInsensitive) == 0)) {
writer = vtkSmartPointer<vtkTIFFWriter>::New();
writer->SetFileDimensionality(2);
writer->SetFileDimensionality(2);
} else if (QString::compare(fileExt, "bmp", Qt::CaseInsensitive) == 0) {
writer = vtkSmartPointer<vtkBMPWriter>::New();
writer->SetFileDimensionality(2);
......@@ -174,9 +192,10 @@ bool VtkImageComponentExtension::save(Component* component) const {
else
writer->SetFilePattern(filePattern.toStdString().c_str());
writer->SetInput(image);
// we save the unsigned char casted image
writer->SetInputConnection(castFilter->GetOutputPort());
writer->Write();
// Save image orientation for compatible header (as it is not possible to store it either in
// vtkImageData or vtkMetaImageWriter classes
// we are obliged to open the whole image, as a text, replace the anatomical orientation string
......
......@@ -37,11 +37,11 @@
**/
class VtkImageComponentExtension : public camitk::ImageComponentExtension {
Q_OBJECT
Q_INTERFACES(camitk::ComponentExtension);
Q_INTERFACES(camitk::ComponentExtension)
public:
/// the constructor (do nothing really)
VtkImageComponentExtension() : ImageComponentExtension() {};
VtkImageComponentExtension() : ImageComponentExtension() {}
/// get the plugin name
virtual QString getName() const;
......@@ -62,7 +62,7 @@ public:
protected:
/// the destructor
virtual ~VtkImageComponentExtension() {};
virtual ~VtkImageComponentExtension() {}
};
#endif // VTK_IMAGE_COMPONENT_EXTENSION_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment