Commit f3369d40 authored by David Gobbi's avatar David Gobbi

ENH: Add option to rescale real-valued data to VTK_FLOAT. Change...

ENH: Add option to rescale real-valued data to VTK_FLOAT.  Change ImageOrientation method to DirectionCosines to be more MINC-like, since ImageOrientation is not VTK-standard.
parent 75bc07ca
......@@ -3,6 +3,17 @@
Program: Visualization Toolkit
Module: vtkMINC.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*=========================================================================
Copyright (c) 2006 Atamai, Inc.
Use, modification and redistribution of the software, in source or
......@@ -39,8 +50,8 @@ POSSIBILITY OF SUCH DAMAGES.
This file has been modified from the original "minc.h" that was
distributed with minc version 1.4. All of the prototype
declarations have been removed. This modification was made in
support of the use of this file with the vtkMINCImageReader
and vtkMINCImageWriter.
support of the use of this file with the vtkMINCReader
and vtkMINCWriter.
David Gobbi, Atamai Inc..
*/
......@@ -76,7 +87,13 @@ POSSIBILITY OF SUCH DAMAGES.
MI acquisition variable
@CREATED : July 24, 1992. (Peter Neelin, Montreal Neurological Institute)
@MODIFIED :
* Log: minc.h
* Log: vtkMINC.h
* Revision 1.1 2006/09/03 01:01:21 dgobbi
* ENH: move the MINC attributes into a separate file to make it easy to copy from the reader to the writer
*
* Revision 1.1 2006/08/30 16:03:22 dgobbi
* ENH: Add a vtkMINC.h that contains all the MINC constants. Make the MINCReader and MINCWriter use it.
*
* Revision 6.11.2.2 2004/09/28 20:23:40 bert
* Minor portability fixes for Windows
*
......
......@@ -3,6 +3,17 @@
Program: Visualization Toolkit
Module: vtkMINCImageAttributes.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*=========================================================================
Copyright (c) 2006 Atamai, Inc.
Use, modification and redistribution of the software, in source or
......@@ -110,7 +121,7 @@ private:
};
//--------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkMINCImageAttributes, "1.3");
vtkCxxRevisionMacro(vtkMINCImageAttributes, "1.4");
vtkStandardNewMacro(vtkMINCImageAttributes);
vtkCxxSetObjectMacro(vtkMINCImageAttributes,ImageMin,vtkDoubleArray);
......@@ -133,7 +144,7 @@ vtkMINCImageAttributes::vtkMINCImageAttributes()
this->ImageMax = 0;
this->Name = 0;
this->DataType = VTK_SHORT;
this->DataType = VTK_VOID;
}
//-------------------------------------------------------------------------
......@@ -204,7 +215,7 @@ void vtkMINCImageAttributes::PrintSelf(ostream& os, vtkIndent indent)
void vtkMINCImageAttributes::Reset()
{
this->SetName(0);
this->SetDataType(VTK_SHORT);
this->SetDataType(VTK_VOID);
this->SetImageMin(0);
this->SetImageMax(0);
this->AttributeValues->Clear();
......@@ -612,7 +623,7 @@ void vtkMINCImageAttributes::PrintFileHeader(ostream &os)
}
else
{
os << "0 ;\n";
os << "_ ;\n";
}
}
......
......@@ -3,6 +3,17 @@
Program: Visualization Toolkit
Module: vtkMINCImageAttributes.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*=========================================================================
Copyright (c) 2006 Atamai, Inc.
Use, modification and redistribution of the software, in source or
......@@ -45,6 +56,8 @@ POSSIBILITY OF SUCH DAMAGES.
// want to change any of the header information, you must
// use ShallowCopy to make a copy of the reader's attributes
// and then modify only the copy.
// .SECTION See Also
// vtkMINCImageReader vtkMINCImageWriter
// .SECTION Thanks
// Thanks to David Gobbi for writing this class and Atamai Inc. for
// contributing it to VTK.
......@@ -77,13 +90,17 @@ public:
virtual void Reset();
// Description:
// Get the name of the image.
// Get the name of the image, not including the path or
// the extension. This is only needed for printing the
// header and there is usually no need to set it.
vtkSetStringMacro(Name);
vtkGetStringMacro(Name);
// Description:
// Get the image data type, as stored on disk. This will not
// always be the same as the data type of the reader's output.
// Get the image data type, as stored on disk. This information
// is useful if the file was converted to floating-point when it
// was loaded. When writing a file from float or double image data,
// you can use this method to prescribe the output type.
vtkSetMacro(DataType, int);
vtkGetMacro(DataType, int);
......@@ -106,7 +123,9 @@ public:
return this->DimensionNames; };
// Description:
// Get the lengths of all the dimensions.
// Get the lengths of all the dimensions. The dimension lengths
// are informative, the vtkMINCImageWriter does not look at these values
// but instead uses the dimension sizes of its input.
virtual vtkIdTypeArray *GetDimensionLengths() {
return this->DimensionLengths; };
......@@ -117,11 +136,13 @@ public:
// Description:
// List the attribute names for a variable. Set the variable
// to the empty string to get global attributes.
// to the empty string to get a list of the global attributes.
virtual vtkStringArray *GetAttributeNames(const char *variable);
// Description:
// Get the image min and max arrays.
// Get the image min and max arrays. These are set by the reader,
// but they aren't used by the writer except to compute the full
// real data range of the original file.
virtual void SetImageMin(vtkDoubleArray *imageMin);
virtual void SetImageMax(vtkDoubleArray *imageMax);
virtual vtkDoubleArray *GetImageMin() { return this->ImageMin; };
......@@ -138,9 +159,7 @@ public:
// Description:
// Set attribute values for a variable as a vtkDataArray.
// Set the variable to the empty string to set global attributes.
// If StrictValidation is set, then you may only set valid minc
// attributes for valid minc variables,
// Set the variable to the empty string to access global attributes.
virtual void SetAttributeValueAsArray(const char *variable,
const char *attribute,
vtkDataArray *array);
......@@ -149,7 +168,7 @@ public:
// Description:
// Set an attribute value as a string. Set the variable
// to the empty string to set global attributes.
// to the empty string to access global attributes.
// If you specify a variable that does not exist, it will be
// created.
virtual void SetAttributeValueAsString(const char *variable,
......@@ -160,7 +179,7 @@ public:
// Description:
// Set an attribute value as an int. Set the variable
// to the empty string to set global attributes.
// to the empty string to access global attributes.
// If you specify a variable that does not exist, it will be
// created.
virtual void SetAttributeValueAsInt(const char *variable,
......@@ -171,7 +190,7 @@ public:
// Description:
// Set an attribute value as a double. Set the variable
// to the empty string to set global attributes.
// to the empty string to access global attributes.
// If you specify a variable that does not exist, it will be
// created.
virtual void SetAttributeValueAsDouble(const char *variable,
......@@ -196,10 +215,10 @@ public:
// Description:
// Do a shallow copy. This will copy all the attributes
// from the source. It is much more efficient than a DeepCopy
// would be, since it only copies the pointers and not the
// entire arrays. You must make a copy if you want to modify
// any MINC attributes from a MINCReader before you pass them to
// a MINCWriter.
// would be, since it only copies pointers to the attribute values
// instead of copying the arrays themselves. You must use this
// method to make a copy if you want to modify any MINC attributes
// from a MINCReader before you pass them to a MINCWriter.
virtual void ShallowCopy(vtkMINCImageAttributes *source);
// Description:
......
This diff is collapsed.
......@@ -3,6 +3,17 @@
Program: Visualization Toolkit
Module: vtkMINCImageReader.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*=========================================================================
Copyright (c) 2006 Atamai, Inc.
Use, modification and redistribution of the software, in source or
......@@ -36,8 +47,20 @@ POSSIBILITY OF SUCH DAMAGES.
=========================================================================*/
// .NAME vtkMINCImageReader - A reader for MINC files.
// .SECTION Description
// MINC is a medical image file format that was developed at the Montreal
// Neurological Institute in 1992. It is based on the NetCDF format.
// MINC is a NetCDF-based medical image file format that was developed
// at the Montreal Neurological Institute in 1992.
// This class will read a MINC file into VTK, rearranging the data to
// match the VTK x, y, and z dimensions and optionally rescaling
// real-valued data to VTK_FLOAT via the SetRescaleRealValues()
// method. If this method is not used, then the data will be stored
// in its original data type and the GetRescaleSlope(),
// GetRescaleIntercept() method can be used to retrieve global
// rescaling parameters. If the original file had a time dimension,
// the SetTimeStep() method can be used to specify a time step to read.
// All of the original header information can be accessed though the
// GetImageAttributes() method.
// .SECTION See Also
// vtkMINCImageWriter vtkMINCImageAttributes
// .SECTION Thanks
// Thanks to David Gobbi for writing this class and Atamai Inc. for
// contributing it to VTK.
......@@ -85,20 +108,31 @@ public:
// Get a matrix that describes the orientation of the data.
// The three columns of the matrix are the direction cosines
// for the x, y and z dimensions respectively.
virtual vtkMatrix4x4 *GetOrientationMatrix();
virtual vtkMatrix4x4 *GetDirectionCosines();
// Description:
// Get the slope and intercept for rescaling the scalar values
// to real data values.
// to real data values. To convert scalar values to real values,
// use the equation y = x*RescaleSlope + RescaleIntercept.
virtual double GetRescaleSlope();
virtual double GetRescaleIntercept();
// Description:
// Get the ValidRange of the data as stored in the file.
// The ScalarRange of the output data will be equal to this.
virtual double *GetValidRange();
virtual void GetValidRange(double range[2]) {
double *r = this->GetValidRange();
// Rescale real data values to float. If this is done, the
// RescaleSlope and RescaleIntercept will be set to 1 and 0
// respectively. This is off by default.
vtkSetMacro(RescaleRealValues, int);
vtkBooleanMacro(RescaleRealValues, int);
vtkGetMacro(RescaleRealValues, int);
// Description:
// Get the range of the output as specified in the header.
// The ScalarRange of the output data will be equal to this
// in most cases, but if the MINC file stores an incorrect
// valid_range then the DataRange will be incorrect.
virtual double *GetDataRange();
virtual void GetDataRange(double range[2]) {
double *r = this->GetDataRange();
range[0] = r[0]; range[1] = r[1]; };
// Description:
......@@ -124,12 +158,14 @@ protected:
double ValidRange[2];
double ImageRange[2];
double DataRange[2];
int NumberOfTimeSteps;
int TimeStep;
vtkMatrix4x4 *OrientationMatrix;
vtkMatrix4x4 *DirectionCosines;
double RescaleSlope;
double RescaleIntercept;
int RescaleRealValues;
vtkMINCImageAttributes *ImageAttributes;
int FileNameHasChanged;
......@@ -138,6 +174,7 @@ protected:
virtual int CloseNetCDFFile(int ncid);
virtual int IndexFromDimensionName(const char *dimName);
virtual int ReadMINCFileAttributes();
virtual void FindRangeAndRescaleValues();
const char *ConvertDataArrayToString(vtkDataArray *array);
static int ConvertMINCTypeToVTKType(int minctype, int mincsigned);
......
This diff is collapsed.
......@@ -3,6 +3,17 @@
Program: Visualization Toolkit
Module: vtkMINCImageWriter.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*=========================================================================
Copyright (c) 2006 Atamai, Inc.
Use, modification and redistribution of the software, in source or
......@@ -36,16 +47,20 @@ POSSIBILITY OF SUCH DAMAGES.
=========================================================================*/
// .NAME vtkMINCImageWriter - A writer for MINC files.
// .SECTION Description
// MINC is a medical image file format that was developed at the Montreal
// Neurological Institute in 1992. It is based on the NetCDF format.
// MINC is a NetCDF-based medical image file format that was developed
// at the Montreal Neurological Institute in 1992.
// The data is written slice-by-slice, and this writer is therefore
// suitable for streaming MINC data that is larger than the memory
// size through VTK. This writer can also produce files with up to
// 4 dimensions, where the fourth dimension is provided by using
// AddInput() to specify multiple input data sets.
// AddInput() to specify multiple input data sets. If you want to
// set header information for the file, you must supply a
// vtkMINCImageAttributes
// .SECTION See Also
// vtkMINCImageReader vtkMINCImageAttributes
// .SECTION Thanks
// Thanks to Atamai Inc. for contributing this class to VTK. Written
// by David Gobbi.
// Thanks to David Gobbi for writing this class and Atamai Inc. for
// contributing it to VTK.
#ifndef __vtkMINCImageWriter_h
#define __vtkMINCImageWriter_h
......@@ -99,8 +114,8 @@ public:
// back-to-front to ensure that no MINC dimension ends up with
// a direction cosines vector whose dot product with the canonical
// unit vector for that dimension is negative.
virtual void SetOrientationMatrix(vtkMatrix4x4 *matrix);
vtkGetObjectMacro(OrientationMatrix, vtkMatrix4x4);
virtual void SetDirectionCosines(vtkMatrix4x4 *matrix);
vtkGetObjectMacro(DirectionCosines, vtkMatrix4x4);
// Description:
// Set the slope and intercept for rescaling the intensities. The
......@@ -125,6 +140,12 @@ public:
vtkBooleanMacro(StrictValidation, int);
vtkGetMacro(StrictValidation, int);
// Description:
// Set a string value to append to the history of the file. This
// string should describe, briefly, how the file was processed.
vtkSetStringMacro(HistoryAddition);
vtkGetStringMacro(HistoryAddition);
protected:
vtkMINCImageWriter();
~vtkMINCImageWriter();
......@@ -133,7 +154,7 @@ protected:
int MINCImageTypeSigned;
int MINCImageMinMaxDims;
vtkMatrix4x4 *OrientationMatrix;
vtkMatrix4x4 *DirectionCosines;
double RescaleSlope;
double RescaleIntercept;
int StrictValidation;
......@@ -142,6 +163,7 @@ protected:
double InternalValidRange[2];
double InternalRescaleSlope;
double InternalRescaleIntercept;
int InternalDataType;
vtkStringArray *InternalDimensionNames;
......@@ -153,6 +175,8 @@ protected:
int MismatchedInputs;
int MINCFileId;
char *HistoryAddition;
virtual int OpenNetCDFFile(const char *filename, int& ncid);
virtual int CloseNetCDFFile(int ncid);
......@@ -160,12 +184,12 @@ protected:
virtual void ComputePermutationFromOrientation(int permutation[3],
int flip[3]);
virtual int CreateMINCDimensions(int wholeExtent[6], int numComponents,
int numTimeSteps, int *dimids);
int timeStep, int *dimids);
virtual int CreateMINCVariables(int wholeExtent[6], int numComponents,
double origin[3], double spacing[3],
int *dimids);
virtual int WriteMINCFileAttributes(vtkImageData *input, int numTimeSteps);
virtual int WriteMINCData(vtkImageData *input, int timeStep);
virtual int WriteMINCFileAttributes(vtkImageData *input, int timeStep);
virtual int WriteMINCData(vtkImageData *input, int frameNumber);
virtual void FindRescale(double &rescaleSlope, double &rescaleIntercept);
virtual void FindMINCValidRange(double range[2]);
......
Markdown is supported
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