Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

vtkGdcmWriter.cxx File Reference

#include "gdcmFile.h"
#include "gdcmFileHelper.h"
#include "gdcmDebug.h"
#include "gdcmUtil.h"
#include "vtkGdcmWriter.h"
#include <vtkObjectFactory.h>
#include <vtkImageData.h>
#include <vtkPointData.h>
#include <vtkLookupTable.h>

Go to the source code of this file.

Functions

 vtkCxxRevisionMacro (vtkGdcmWriter,"$Revision:1.16 $")
 vtkStandardNewMacro (vtkGdcmWriter)
size_t ReverseData (vtkImageData *image, unsigned char **data)
void SetImageInformation (gdcm::FileHelper *file, vtkImageData *image)


Function Documentation

size_t ReverseData vtkImageData *  image,
unsigned char **  data
 

Copy the image and reverse the Y axis

Definition at line 110 of file vtkGdcmWriter.cxx.

Referenced by SetImageInformation().

00111 {
00112    int inc[3];
00113    int *extent = image->GetUpdateExtent();
00114    int dim[3] = {extent[1]-extent[0]+1,
00115                  extent[3]-extent[2]+1,
00116                  extent[5]-extent[4]+1};
00117 
00118    size_t lineSize = dim[0] * image->GetScalarSize()
00119                    * image->GetNumberOfScalarComponents();
00120    size_t planeSize = dim[1] * lineSize;
00121    size_t size = dim[2] * planeSize;
00122 
00123    if( size>0 )
00124    {
00125       *data = new unsigned char[size];
00126 
00127       image->GetIncrements(inc);
00128       unsigned char *src = (unsigned char *)image->GetScalarPointerForExtent(extent);
00129       unsigned char *dst = *data + planeSize - lineSize;
00130       for (int plane = extent[4]; plane <= extent[5]; plane++)
00131       {
00132          for (int line = extent[2]; line <= extent[3]; line++)
00133          {
00134             // Copy one line at proper destination:
00135             memcpy((void*)dst, (void*)src, lineSize);
00136 
00137             src += inc[1] * image->GetScalarSize();
00138             dst -= lineSize;
00139          }
00140          dst += 2 * planeSize;
00141       }
00142    }
00143    else
00144    {
00145       *data = NULL;
00146    }
00147 
00148    return size;
00149 }

void SetImageInformation gdcm::FileHelper file,
vtkImageData *  image
 

Set the datas informations in the file

Definition at line 154 of file vtkGdcmWriter.cxx.

References gdcm::FileHelper::InsertValEntry(), ReverseData(), and gdcm::FileHelper::SetUserData().

Referenced by vtkGdcmWriter::WriteDcmFile().

00155 {
00156    std::ostringstream str;
00157 
00158    // Image size
00159    int *extent = image->GetUpdateExtent();
00160    int dim[3] = {extent[1]-extent[0]+1,
00161                  extent[3]-extent[2]+1,
00162                  extent[5]-extent[4]+1};
00163 
00164    str.str("");
00165    str << dim[0];
00166    file->InsertValEntry(str.str(),0x0028,0x0011); // Columns
00167 
00168    str.str("");
00169    str << dim[1];
00170    file->InsertValEntry(str.str(),0x0028,0x0010); // Rows
00171 
00172    if(dim[2]>1)
00173    {
00174       str.str("");
00175       str << dim[2];
00176       //file->Insert(str.str(),0x0028,0x0012); // Planes
00177       file->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames
00178    }
00179 
00180    // Pixel type
00181    str.str("");
00182    str << image->GetScalarSize()*8;
00183    file->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated
00184    file->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored
00185 
00186    str.str("");
00187    str << image->GetScalarSize()*8-1;
00188    file->InsertValEntry(str.str(),0x0028,0x0102); // High Bit
00189 
00190    // Pixel Repr
00191    // FIXME : what do we do when the ScalarType is 
00192    // VTK_UNSIGNED_INT or VTK_UNSIGNED_LONG
00193    str.str("");
00194    if( image->GetScalarType() == VTK_UNSIGNED_CHAR ||
00195        image->GetScalarType() == VTK_UNSIGNED_SHORT ||
00196        image->GetScalarType() == VTK_UNSIGNED_INT ||
00197        image->GetScalarType() == VTK_UNSIGNED_LONG )
00198    {
00199       str << "0"; // Unsigned
00200    }
00201    else
00202    {
00203       str << "1"; // Signed
00204    }
00205    file->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation
00206 
00207    // Samples per pixel
00208    str.str("");
00209    str << image->GetNumberOfScalarComponents();
00210    file->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel
00211 
00212    // Spacing
00213    double *sp = image->GetSpacing();
00214 
00215    str.str("");
00216    str << sp[0] << "\\" << sp[1];
00217    file->InsertValEntry(str.str(),0x0028,0x0030); // Pixel Spacing
00218    str.str("");
00219    str << sp[2];
00220    file->InsertValEntry(str.str(),0x0018,0x0088); // Spacing Between Slices
00221 
00222    // Origin
00223    double *org = image->GetOrigin();
00224 
00225    str.str("");
00226    str << org[0] << "\\" << org[1] << "\\" << org[2];
00227    file->InsertValEntry(str.str(),0x0020,0x0032); // Image Position Patient
00228 
00229    // Window / Level
00230    double *rng=image->GetScalarRange();
00231 
00232    str.str("");
00233    str << rng[1]-rng[0];
00234    file->InsertValEntry(str.str(),0x0028,0x1051); // Window Width
00235    str.str("");
00236    str << (rng[1]+rng[0])/2.0;
00237    file->InsertValEntry(str.str(),0x0028,0x1050); // Window Center
00238 
00239    // Pixels
00240    unsigned char *data;
00241    size_t size = ReverseData(image,&data);
00242    file->SetUserData(data,size);
00243 }

vtkCxxRevisionMacro vtkGdcmWriter  ,
"$Revision:1.16 $" 
 

vtkStandardNewMacro vtkGdcmWriter   ) 
 


Generated on Thu Feb 10 22:18:04 2005 for gdcm by doxygen 1.3.6