1 /*=========================================================================
4 Module: $RCSfile: vtkGdcmReader.cxx,v $
6 Date: $Date: 2005/06/06 08:38:29 $
7 Version: $Revision: 1.71 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 //-----------------------------------------------------------------------------
20 // //////////////////////////////////////////////////////////////
21 // WARNING TODO CLEANME
22 // Actual limitations of this code:
24 // /////// Redundant and unnecessary header parsing
25 // In it's current state this code actually parses three times the Dicom
26 // header of a file before the corresponding image gets loaded in the
28 // Here is the process:
29 // 1/ First loading happens in ExecuteInformation which, in order to
30 // positionate the vtk extents, calls CheckFileCoherence. The purpose
31 // of CheckFileCoherence is to make sure all the images in the future
32 // stack are "homogenous" (same size, same representation...).
33 // This can only be achieved by parsing all the Dicom headers...
34 // --> to avoid loosing too much time :
35 // If user is 150% sure *all* the files are coherent, that is to say :
36 // they may be open, they are gdcm-readable, they have the same sizes,
37 // they have the same 'pixel' type, they are single frame,
38 // they have the same color convention ...
39 // he may use SetCheckFileCoherenceLight() to request a 'light' coherence
41 // 2/ ExecuteData is then responsible for the next two loadings - 2 ?!?-:
42 // 2a/ ExecuteData calls AllocateOutputData that in turn seems to
43 // (indirectely call) ExecuteInformation which ends up in a second
45 // This is fixed by adding a test at the beginning of ExecuteInformation
46 // on the modification of the object instance. If a modification have been
47 // made (method Modified() ), the MTime value is increased. The fileTime
48 // is compared to this new value to find a modification in the class
50 // 2b/ the core of ExecuteData then needs gdcmFile (which in turns
51 // initialises gdcmFile in the constructor) in order to access
55 // maintain a list of gdcmFiles (created by say ExecuteInformation) created
56 // once and for all accross the life of vtkGdcmFile (it would only load
57 // new gdcmFile if the user changes the list). ExecuteData would then use
58 // those gdcmFile and hence avoid calling the construtor:
59 // - advantage: the header of the files would only be parser once.
60 // - drawback: once execute information is called (i.e. on creation of
61 // a vtkGdcmFile) the gdcmFile structure is loaded in memory.
62 // The average size of a gdcm::File being of 100Ko,
63 // - 100 Ko ? Better say 1 Mo; we are in 2005 ! -
64 // if oneloads 10 stacks of images with say 200 images each,
65 // you end-up with a loss of 200Mo...
67 // /////// Never unallocated memory:
68 // ExecuteData allocates space for the pixel data [which will get pointed
69 // by the vtkPointData() through the call
70 // data->GetPointData()->GetScalars()->SetVoidArray(mem, StackNumPixels, 0);]
71 // This data is never "freed" neither in the destructor nor when the
72 // filename list is extended, ExecuteData is called a second (or third)
74 // //////////////////////////////////////////////////////////////
76 #include "gdcmFileHelper.h"
78 #include "vtkGdcmReader.h"
81 #include <vtkObjectFactory.h>
82 #include <vtkImageData.h>
83 #include <vtkPointData.h>
84 #include <vtkLookupTable.h>
86 vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.71 $");
87 vtkStandardNewMacro(vtkGdcmReader);
89 //-----------------------------------------------------------------------------
90 // Constructor / Destructor
91 vtkGdcmReader::vtkGdcmReader()
93 this->LookupTable = NULL;
94 this->AllowLookupTable = 0;
95 this->LightChecking = false;
98 vtkGdcmReader::~vtkGdcmReader()
100 this->RemoveAllFileName();
101 this->InternalFileNameList.clear();
102 if(this->LookupTable)
103 this->LookupTable->Delete();
106 //-----------------------------------------------------------------------------
108 void vtkGdcmReader::PrintSelf(ostream& os, vtkIndent indent)
110 this->Superclass::PrintSelf(os,indent);
111 os << indent << "Filenames : " << endl;
112 vtkIndent nextIndent = indent.GetNextIndent();
113 for (std::list<std::string>::iterator it = FileNameList.begin();
114 it != FileNameList.end();
117 os << nextIndent << it->c_str() << endl ;
121 //-----------------------------------------------------------------------------
124 * Remove all files from the list of images to read.
126 void vtkGdcmReader::RemoveAllFileName(void)
128 this->FileNameList.clear();
133 * Adds a file name to the list of images to read.
135 void vtkGdcmReader::AddFileName(const char* name)
137 // We need to bypass the const pointer [since list<>.push_bash() only
138 // takes a char* (but not a const char*)] by making a local copy:
139 char *LocalName = new char[strlen(name) + 1];
140 strcpy(LocalName, name);
141 this->FileNameList.push_back(LocalName);
147 * Sets up a filename to be read.
149 void vtkGdcmReader::SetFileName(const char *name)
151 vtkImageReader2::SetFileName(name);
152 // Since we maintain a list of filenames, when building a volume,
153 // (see vtkGdcmReader::AddFileName), we additionaly need to purge
154 // this list when we manually positionate the filename.
155 vtkDebugMacro(<< "Clearing all files given with AddFileName");
156 this->FileNameList.clear();
161 * Ask for a 'light' checking - actually : just initializing-
162 *if you are 150% sure *all* the files are coherent
164 void vtkGdcmReader::SetCheckFileCoherenceLight()
166 LightChecking = true;
169 //-----------------------------------------------------------------------------
172 * Configure the output e.g. WholeExtent, spacing, origin, scalar type...
174 void vtkGdcmReader::ExecuteInformation()
176 if(this->MTime>this->fileTime)
178 if ( this->LightChecking )
179 this->TotalNumberOfPlanes = this->CheckFileCoherenceLight();
181 this->TotalNumberOfPlanes = this->CheckFileCoherence();
183 if ( this->TotalNumberOfPlanes == 0)
185 vtkErrorMacro(<< "File set is not coherent. Exiting...");
189 // if the user has not set the extent, but has set the VOI
190 // set the z axis extent to the VOI z axis
191 if (this->DataExtent[4]==0 && this->DataExtent[5] == 0 &&
192 (this->DataVOI[4] || this->DataVOI[5]))
194 this->DataExtent[4] = this->DataVOI[4];
195 this->DataExtent[5] = this->DataVOI[5];
198 // When the user has set the VOI, check it's coherence with the file content.
199 if (this->DataVOI[0] || this->DataVOI[1] ||
200 this->DataVOI[2] || this->DataVOI[3] ||
201 this->DataVOI[4] || this->DataVOI[5])
203 if ((this->DataVOI[0] < 0) ||
204 (this->DataVOI[1] >= this->NumColumns) ||
205 (this->DataVOI[2] < 0) ||
206 (this->DataVOI[3] >= this->NumLines) ||
207 (this->DataVOI[4] < 0) ||
208 (this->DataVOI[5] >= this->TotalNumberOfPlanes ))
210 vtkWarningMacro(<< "The requested VOI is larger than expected extent.");
211 this->DataVOI[0] = 0;
212 this->DataVOI[1] = this->NumColumns - 1;
213 this->DataVOI[2] = 0;
214 this->DataVOI[3] = this->NumLines - 1;
215 this->DataVOI[4] = 0;
216 this->DataVOI[5] = this->TotalNumberOfPlanes - 1;
220 // Positionate the Extent.
221 this->DataExtent[0] = 0;
222 this->DataExtent[1] = this->NumColumns - 1;
223 this->DataExtent[2] = 0;
224 this->DataExtent[3] = this->NumLines - 1;
225 this->DataExtent[4] = 0;
226 this->DataExtent[5] = this->TotalNumberOfPlanes - 1;
228 // We don't need to positionate the Endian related stuff (by using
229 // this->SetDataByteOrderToBigEndian() or SetDataByteOrderToLittleEndian()
230 // since the reading of the file is done by gdcm.
231 // But we do need to set up the data type for downstream filters:
232 if ( ImageType == "8U" )
234 vtkDebugMacro(<< "8 bits unsigned image");
235 this->SetDataScalarTypeToUnsignedChar();
237 else if ( ImageType == "8S" )
239 vtkErrorMacro(<< "Cannot handle 8 bit signed files");
242 else if ( ImageType == "16U" )
244 vtkDebugMacro(<< "16 bits unsigned image");
245 this->SetDataScalarTypeToUnsignedShort();
247 else if ( ImageType == "16S" )
249 vtkDebugMacro(<< "16 bits signed image");
250 this->SetDataScalarTypeToShort();
252 else if ( ImageType == "32U" )
254 vtkDebugMacro(<< "32 bits unsigned image");
255 vtkDebugMacro(<< "WARNING: forced to signed int !");
256 this->SetDataScalarTypeToInt();
258 else if ( ImageType == "32S" )
260 vtkDebugMacro(<< "32 bits signed image");
261 this->SetDataScalarTypeToInt();
263 else if ( ImageType == "FD" )
265 vtkDebugMacro(<< "64 bits Double image");
266 this->SetDataScalarTypeToDouble();
268 //Set number of scalar components:
269 this->SetNumberOfScalarComponents(this->NumComponents);
271 this->fileTime=this->MTime;
274 this->Superclass::ExecuteInformation();
278 * Update => ouput->Update => UpdateData => Execute => ExecuteData
279 * (see vtkSource.cxx for last step).
280 * This function (redefinition of vtkImageReader::ExecuteData, see
281 * VTK/IO/vtkImageReader.cxx) reads a data from a file. The data
282 * extent/axes are assumed to be the same as the file extent/order.
284 void vtkGdcmReader::ExecuteData(vtkDataObject *output)
286 if (this->InternalFileNameList.empty())
288 vtkErrorMacro(<< "A least a valid FileName must be specified.");
292 // FIXME : extraneous parsing of header is made when allocating OuputData
294 vtkImageData *data = this->AllocateOutputData(output);
295 data->SetExtent(this->DataExtent);
296 data->GetPointData()->GetScalars()->SetName("DicomImage-Volume");
298 // Test if output has valid extent
299 // Prevent memory errors
300 if((this->DataExtent[1]-this->DataExtent[0]>=0) &&
301 (this->DataExtent[3]-this->DataExtent[2]>=0) &&
302 (this->DataExtent[5]-this->DataExtent[4]>=0))
304 // The memory size for a full stack of images of course depends
305 // on the number of planes and the size of each image:
306 //size_t StackNumPixels = this->NumColumns * this->NumLines
307 // * this->TotalNumberOfPlanes * this->NumComponents;
308 //size_t stack_size = StackNumPixels * this->PixelSize; //not used
309 // Allocate pixel data space itself.
311 // Variables for the UpdateProgress. We shall use 50 steps to signify
312 // the advance of the process:
313 unsigned long UpdateProgressTarget = (unsigned long) ceil (this->NumLines
314 * this->TotalNumberOfPlanes
316 // The actual advance measure:
317 unsigned long UpdateProgressCount = 0;
319 // Filling the allocated memory space with each image/volume:
320 unsigned char *Dest = (unsigned char *)data->GetScalarPointer();
321 for (std::list<std::string>::iterator filename = InternalFileNameList.begin();
322 filename != InternalFileNameList.end();
325 // Images that were tagged as unreadable in CheckFileCoherence()
326 // are substituted with a black image to let the caller visually
327 // notice something wrong is going on:
328 if (*filename != "GDCM_UNREADABLE")
330 // Update progress related for good files is made in LoadImageInMemory
331 Dest += this->LoadImageInMemory(*filename, Dest,
332 UpdateProgressTarget,
333 UpdateProgressCount);
337 // We insert a black image in the stack for the user to be aware that
338 // this image/volume couldn't be loaded. We simply skip one image
340 Dest += this->NumColumns * this->NumLines * this->PixelSize;
342 // Update progress related for bad files:
343 UpdateProgressCount += this->NumLines;
344 if (UpdateProgressTarget > 0)
346 if (!(UpdateProgressCount%UpdateProgressTarget))
348 this->UpdateProgress(UpdateProgressCount/(50.0*UpdateProgressTarget));
351 } // Else, file not loadable
357 * vtkGdcmReader can have the file names specified through two ways:
358 * (1) by calling the vtkImageReader2::SetFileName(), SetFilePrefix() and
360 * (2) By successive calls to vtkGdcmReader::AddFileName()
361 * When the first method was used by caller we need to update the local
364 void vtkGdcmReader::BuildFileListFromPattern()
366 this->RemoveAllInternalFileName();
368 if ((! this->FileNameList.empty()) && this->FileName )
370 vtkErrorMacro(<< "Both AddFileName and SetFileName schemes were used");
371 vtkErrorMacro(<< "No images loaded ! ");
375 if ((! this->FileNameList.empty()) && this->FilePrefix )
377 vtkErrorMacro(<< "Both AddFileName and SetFilePrefix schemes were used");
378 vtkErrorMacro(<< "No images loaded ! ");
382 if (this->FileName && this->FilePrefix)
384 vtkErrorMacro(<< "Both SetFileName and SetFilePrefix schemes were used");
385 vtkErrorMacro(<< "No images loaded ! ");
389 if (! this->FileNameList.empty() )
391 vtkDebugMacro(<< "Using the AddFileName specified files");
392 this->InternalFileNameList=this->FileNameList;
396 if (!this->FileName && !this->FilePrefix)
398 vtkErrorMacro(<< "FileNames are not set. Either use AddFileName() or");
399 vtkErrorMacro(<< "specify a FileName or FilePrefix.");
405 // Single file loading (as given with ::SetFileName()):
406 // Case of multi-frame file considered here
407 this->ComputeInternalFileName(this->DataExtent[4]);
408 vtkDebugMacro(<< "Adding file " << this->InternalFileName);
409 this->AddInternalFileName(this->InternalFileName);
413 // Multi file loading (as given with ::SetFilePattern()):
414 for (int idx = this->DataExtent[4]; idx <= this->DataExtent[5]; ++idx)
416 this->ComputeInternalFileName(idx);
417 vtkDebugMacro(<< "Adding file " << this->InternalFileName);
418 this->AddInternalFileName(this->InternalFileName);
424 * When more than one filename is specified (i.e. we expect loading
425 * a stack or volume) we need to check that the corresponding images/volumes
426 * to be loaded are coherent i.e. to make sure:
427 * - they all share the same X dimensions
428 * - they all share the same Y dimensions
429 * - they all share the same ImageType ( 8 bit signed, or unsigned...)
431 * Eventually, we emit a warning when all the files do NOT share the
432 * Z dimension, since we can still build a stack but the
433 * files are not coherent in Z, which is probably a source a trouble...
434 * When files are not readable (either the file cannot be opened or
435 * because gdcm cannot parse it), they are flagged as "GDCM_UNREADABLE".
436 * This method returns the total number of planar images to be loaded
437 * (i.e. an image represents one plane, but a volume represents many planes)
439 int vtkGdcmReader::CheckFileCoherence()
441 int ReturnedTotalNumberOfPlanes = 0; // The returned value.
443 this->BuildFileListFromPattern();
444 if (this->InternalFileNameList.empty())
446 vtkErrorMacro(<< "FileNames are not set.");
450 bool FoundReferenceFile = false;
453 // Loop on the filenames:
454 // - check for their existence and gdcm "parsability"
455 // - get the coherence check done:
456 for (std::list<std::string>::iterator filename = InternalFileNameList.begin();
457 filename != InternalFileNameList.end();
460 // The file is always added in the number of planes
461 // - If file doesn't exist, it will be replaced by a black plane in the
462 // ExecuteData method
463 // - If file has more than 1 plane, other planes will be added later to
464 // to the ReturnedTotalNumberOfPlanes variable counter
465 ReturnedTotalNumberOfPlanes += 1;
467 /////// Stage 0: check for file name:
469 // fixme : how can the filename be equal to "GDCM_UNREADABLE"
472 if(*filename == std::string("GDCM_UNREADABLE"))
475 /////// Stage 1: check for file readability:
476 // Stage 1.1: check for file existence.
478 fp = fopen(filename->c_str(),"rb");
481 vtkErrorMacro(<< "Unable to open file " << filename->c_str());
482 vtkErrorMacro(<< "Removing this file from read files: "
483 << filename->c_str());
484 *filename = "GDCM_UNREADABLE";
489 // Stage 1.2: check for Gdcm parsability
491 //gdcm::File GdcmFile( filename->c_str() );
492 // to save some parsing time.
494 // Some images have a wrong length for 0x0000 element of private groups
495 // Better we don't use NO_SHADOW as a default option
496 //GdcmFile.SetLoadMode( NO_SEQ | NO_SHADOW );
497 GdcmFile.SetLoadMode( NO_SEQ );
498 GdcmFile.Load(filename->c_str() );
499 if (!GdcmFile.IsReadable())
501 vtkErrorMacro(<< "Gdcm cannot parse file " << filename->c_str());
502 vtkErrorMacro(<< "Removing this file from read files: "
503 << filename->c_str());
504 *filename = "GDCM_UNREADABLE";
508 // Stage 1.3: further gdcm compatibility on PixelType
509 std::string type = GdcmFile.GetPixelType();
510 if ( (type != "8U") && (type != "8S")
511 && (type != "16U") && (type != "16S")
512 && (type != "32U") && (type != "32S") )
514 vtkErrorMacro(<< "Bad File Type for file " << filename->c_str() << "\n"
515 << " File type found : " << type.c_str()
516 << " (might be 8U, 8S, 16U, 16S, 32U, 32S) \n"
517 << " Removing this file from readed files");
518 *filename = "GDCM_UNREADABLE";
522 // Stage 2: check coherence of the set of files
523 int NX = GdcmFile.GetXSize();
524 int NY = GdcmFile.GetYSize();
525 int NZ = GdcmFile.GetZSize();
526 if (FoundReferenceFile)
528 // Stage 2.1: mandatory coherence stage:
529 if ( ( NX != this->NumColumns )
530 || ( NY != this->NumLines )
531 || ( type != this->ImageType ) )
533 vtkErrorMacro(<< "This file is not coherent with previous ones: "
534 << filename->c_str());
535 vtkErrorMacro(<< "Removing this file from readed files: "
536 << filename->c_str());
537 *filename = "GDCM_UNREADABLE";
541 // Stage 2.2: optional coherence stage
542 if ( NZ != ReferenceNZ )
544 vtkErrorMacro(<< "File is not coherent in Z with previous ones: "
545 << filename->c_str());
549 vtkDebugMacro(<< "File is coherent with previous ones: "
550 << filename->c_str());
553 // Stage 2.3: when the file is 'multiframe', notify the caller.
556 vtkErrorMacro(<< "This file is a 'Multiframe' one: "
557 << filename->c_str());
560 // Eventually, this file can be added on the stack. Update the
561 // full size of the stack
562 vtkDebugMacro("Number of planes added to the stack: " << NZ);
563 ReturnedTotalNumberOfPlanes += NZ - 1; // First plane already added
569 // We didn't have a workable reference file yet.
570 // Set this one as the reference.
571 FoundReferenceFile = true;
572 vtkDebugMacro(<< "This file taken as coherence reference:"
573 << filename->c_str());
574 vtkDebugMacro(<< "Image dimensions of reference file as read from Gdcm:"
575 << NX << " " << NY << " " << NZ);
576 vtkDebugMacro(<< "Number of planes added to the stack: " << NZ);
577 // Set aside the size of the image
578 this->NumColumns = NX;
581 ReturnedTotalNumberOfPlanes += NZ - 1; // First plane already added
582 this->ImageType = type;
583 this->PixelSize = GdcmFile.GetPixelSize();
585 if( GdcmFile.HasLUT() && this->AllowLookupTable )
587 // I could raise an error is AllowLookupTable is on and HasLUT() off
588 this->NumComponents = GdcmFile.GetNumberOfScalarComponentsRaw();
592 this->NumComponents = GdcmFile.GetNumberOfScalarComponents(); //rgb or mono
595 this->DataSpacing[0] = GdcmFile.GetXSpacing();
596 this->DataSpacing[1] = GdcmFile.GetYSpacing();
597 this->DataSpacing[2] = GdcmFile.GetZSpacing();
599 } // End of loop on filename
601 ///////// The files we CANNOT load are flaged. On debugging purposes
602 // count the loadable number of files and display their number:
603 int NumberCoherentFiles = 0;
604 for (std::list<std::string>::iterator it = InternalFileNameList.begin();
605 it != InternalFileNameList.end();
608 if (*it != "GDCM_UNREADABLE")
610 NumberCoherentFiles++;
613 vtkDebugMacro(<< "Number of coherent files: " << NumberCoherentFiles);
615 if (ReturnedTotalNumberOfPlanes == 0)
617 vtkErrorMacro(<< "No loadable file.");
620 vtkDebugMacro(<< "Total number of planes on the stack: "
621 << ReturnedTotalNumberOfPlanes);
623 return ReturnedTotalNumberOfPlanes;
626 //-----------------------------------------------------------------------------
629 * Remove all file names to the internal list of images to read.
631 void vtkGdcmReader::RemoveAllInternalFileName(void)
633 this->InternalFileNameList.clear();
637 * Adds a file name to the internal list of images to read.
639 void vtkGdcmReader::AddInternalFileName(const char *name)
641 char *LocalName = new char[strlen(name) + 1];
642 strcpy(LocalName, name);
643 this->InternalFileNameList.push_back(LocalName);
648 * Loads the contents of the image/volume contained by Filename at
649 * the Dest memory address. Returns the size of the data loaded.
651 size_t vtkGdcmReader::LoadImageInMemory(
652 std::string fileName,
654 const unsigned long updateProgressTarget,
655 unsigned long & updateProgressCount)
657 vtkDebugMacro(<< "Copying to memory image [" << fileName.c_str() << "]");
658 gdcm::FileHelper file( fileName.c_str() );
661 // If the data structure of vtk for image/volume representation
662 // were straigthforwards the following would be enough:
663 // GdcmFile.GetImageDataIntoVector((void*)Dest, size);
664 // But vtk chooses to invert the lines of an image, that is the last
665 // line comes first (for some axis related reasons?). Hence we need
666 // to load the image line by line, starting from the end.
668 int numColumns = file.GetFile()->GetXSize();
669 int numLines = file.GetFile()->GetYSize();
670 int numPlanes = file.GetFile()->GetZSize();
671 int lineSize = NumComponents * numColumns * file.GetFile()->GetPixelSize();
672 int planeSize = lineSize * numLines;
676 if( file.GetFile()->HasLUT() && AllowLookupTable )
678 size = file.GetImageDataSize();
679 src = (unsigned char*) file.GetImageDataRaw();
680 unsigned char *lut = (unsigned char*) file.GetLutRGBA();
682 if(!this->LookupTable)
684 this->LookupTable = vtkLookupTable::New();
687 this->LookupTable->SetNumberOfTableValues(256);
688 for (int tmp=0; tmp<256; tmp++)
690 this->LookupTable->SetTableValue(tmp,
691 (float)lut[4*tmp+0]/255.0,
692 (float)lut[4*tmp+1]/255.0,
693 (float)lut[4*tmp+2]/255.0,
696 this->LookupTable->SetRange(0,255);
697 vtkDataSetAttributes *a = this->GetOutput()->GetPointData();
698 a->GetScalars()->SetLookupTable(this->LookupTable);
703 size = file.GetImageDataSize();
704 src = (unsigned char*)file.GetImageData();
707 unsigned char *dst = dest + planeSize - lineSize;
708 for (int plane = 0; plane < numPlanes; plane++)
710 for (int line = 0; line < numLines; line++)
712 // Copy one line at proper destination:
713 memcpy((void*)dst, (void*)src, lineSize);
716 // Update progress related:
717 if (!(updateProgressCount%updateProgressTarget))
719 this->UpdateProgress(updateProgressCount/(50.0*updateProgressTarget));
721 updateProgressCount++;
723 dst += 2 * planeSize;
728 // -------------------------------------------------------------------------
730 // We assume the use *does* know all the files whose names
731 // are in InternalFileNameList exist, may be open, are gdcm-readable
732 // have the same sizes, have the same 'pixel' type, are single frame
733 // have the same color convention, ..., anything else ?
735 int vtkGdcmReader::CheckFileCoherenceLight()
737 std::list<std::string>::iterator filename = InternalFileNameList.begin();
740 GdcmFile.SetLoadMode( NO_SEQ | NO_SHADOW );
741 GdcmFile.Load(filename->c_str() );
742 if (!GdcmFile.IsReadable())
744 vtkErrorMacro(<< "Gdcm cannot parse file " << filename->c_str());
745 vtkErrorMacro(<< "you should try vtkGdcmReader::CheckFileCoherence "
746 << "instead of try vtkGdcmReader::CheckFileCoherenceLight");
749 int NX = GdcmFile.GetXSize();
750 int NY = GdcmFile.GetYSize();
751 // CheckFileCoherenceLight should be called *only* when user knows
752 // he deals with single frames files.
753 // Z size is then the number of files.
754 int NZ = InternalFileNameList.size();
755 std::string type = GdcmFile.GetPixelType();
756 vtkDebugMacro(<< "The first file is taken as reference: "
757 << filename->c_str());
758 vtkDebugMacro(<< "Image dimensions of reference file as read from Gdcm:"
759 << NX << " " << NY << " " << NZ);
760 vtkDebugMacro(<< "Number of planes added to the stack: " << NZ);
761 // Set aside the size of the image
762 this->NumColumns = NX;
764 this->ImageType = type;
765 this->PixelSize = GdcmFile.GetPixelSize();
767 if( GdcmFile.HasLUT() && this->AllowLookupTable )
769 // I could raise an error is AllowLookupTable is on and HasLUT() off
770 this->NumComponents = GdcmFile.GetNumberOfScalarComponentsRaw();
774 this->NumComponents = GdcmFile.GetNumberOfScalarComponents(); //rgb or mono
778 this->DataSpacing[0] = GdcmFile.GetXSpacing();
779 this->DataSpacing[1] = GdcmFile.GetYSpacing();
780 this->DataSpacing[2] = GdcmFile.GetZSpacing();
782 return InternalFileNameList.size();
784 //-----------------------------------------------------------------------------