Commit a65cc475 authored by saubatn's avatar saubatn
Browse files

FIXED Only shift scalar type of SIGNED scalar type, not UNSIGNED ones.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@2164 ec899d31-69d1-42ba-9299-647d76f65fb3
parent a8167415
......@@ -43,9 +43,8 @@ using namespace camitk;
#include <vtkBMPWriter.h>
#include <vtkPNMWriter.h>
#include <vtkMetaImageWriter.h>
/// NICO
#include <vtkImageShiftScale.h>
#include <vtkType.h>
// --------------- declare the plugin -------------------
Q_EXPORT_PLUGIN2(vtkimage, VtkImageComponentExtension)
......@@ -146,10 +145,37 @@ bool VtkImageComponentExtension::save(Component* component) const {
double *imgRange = image->GetScalarRange();
double scalarTypeMin = imgRange[0];
double scalarTypeMax = imgRange[1];
// shift according to the (un)signed type of the scalar
int scalarType = image->GetScalarType();
switch (scalarType){
case VTK_CHAR:
case VTK_SIGNED_CHAR:
case VTK_SHORT:
case VTK_INT:
case VTK_LONG:
case VTK_FLOAT:
case VTK_DOUBLE:
{
// shift only for signed scalar types
double shift = (scalarTypeMax - scalarTypeMin) / 2;
double scale = (double) 255.0 / (scalarTypeMax - scalarTypeMin);
castFilter->SetShift(shift);
}
break;
case VTK_UNSIGNED_CHAR:
case VTK_UNSIGNED_SHORT:
case VTK_UNSIGNED_INT:
case VTK_UNSIGNED_LONG:
default:
// do not shift, only scale
break;
}
// scale
double scale = (double) 255.0 / (scalarTypeMax - scalarTypeMin);
castFilter->SetScale(scale);
// convert to unsigned char
castFilter->SetOutputScalarTypeToUnsignedChar();
castFilter->SetInput(image);
castFilter->Update();
......
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