vtk-dicom  0.8.17
vtkDICOMDirectory.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2024 David Gobbi
6  All rights reserved.
7  See Copyright.txt or http://dgobbi.github.io/bsd3.txt for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef vtkDICOMDirectory_h
15 #define vtkDICOMDirectory_h
16 
17 #include "vtkAlgorithm.h"
18 #include "vtkDICOMModule.h" // For export macro
19 #include "vtkDICOMConfig.h" // For configuration details
20 #include "vtkDICOMCharacterSet.h" // For character sets
21 #include "vtkVersion.h" // For changes to pipeline API
22 
23 // Declare VTK classes within VTK's optional namespace
24 #if defined(VTK_ABI_NAMESPACE_BEGIN)
25 VTK_ABI_NAMESPACE_BEGIN
26 #endif
27 
28 class vtkStringArray;
29 class vtkIntArray;
30 
31 #if defined(VTK_ABI_NAMESPACE_BEGIN)
32 VTK_ABI_NAMESPACE_END
33 #endif
34 
35 class vtkDICOMMetaData;
36 class vtkDICOMItem;
37 class vtkDICOMTag;
38 
40 
46 class VTKDICOM_EXPORT vtkDICOMDirectory : public vtkAlgorithm
47 {
48 public:
50  void PrintSelf(ostream& os, vtkIndent indent) VTK_DICOM_OVERRIDE;
51  static vtkDICOMDirectory *New();
52 
54  enum {
55  PATIENT, STUDY, SERIES, IMAGE, FRAME
56  };
57 
59 
67  void SetDirectoryName(const char *name);
68  const char *GetDirectoryName() { return this->DirectoryName; }
70 
72 
76  void SetInputFileNames(vtkStringArray *sa);
77  vtkStringArray *GetInputFileNames() { return this->InputFileNames; }
78 
80 
86  void AddInputFileNames(vtkStringArray *sa);
88 
90 
95  void SetFilePattern(const char *pattern);
96  const char *GetFilePattern() { return this->FilePattern; }
98 
100 
106  vtkSetMacro(ScanDepth, int);
107  int GetScanDepth() { return this->ScanDepth; }
109 
111  void SetFindQuery(const vtkDICOMItem& query);
114 
116 
123  void SetFindLevel(int level);
124  void SetFindLevelToImage() { this->SetFindLevel(IMAGE); }
125  void SetFindLevelToSeries() { this->SetFindLevel(SERIES); }
126  int GetFindLevel() { return this->FindLevel; }
128 
130 
135  void Update() VTK_DICOM_OVERRIDE { this->Update(0); }
136  void Update(int) VTK_DICOM_OVERRIDE;
137 #if (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION > 0) || VTK_MAJOR_VERSION > 7
138  vtkTypeBool Update(vtkInformation *) VTK_DICOM_OVERRIDE {
139  this->Update(); return 1; }
140  vtkTypeBool Update(int i, vtkInformationVector *) VTK_DICOM_OVERRIDE {
141  this->Update(i); return 1; }
142 #endif
144 
146  int GetNumberOfSeries();
148 
150  const vtkDICOMItem& GetSeriesRecord(int series);
151 
154 
156  const vtkDICOMItem& GetStudyRecord(int study);
157 
159 
165 
168 
170  const vtkDICOMItem& GetPatientRecord(int patient);
171 
173  vtkIntArray *GetStudiesForPatient(int patient);
175 
177  int GetFirstSeriesForStudy(int study);
179 
181  int GetLastSeriesForStudy(int study);
182 
184  vtkStringArray *GetFileNamesForSeries(int i);
185 
187 
195 
197 
208  void SetQueryFilesToAlways() { this->SetQueryFiles(1); }
209  void SetQueryFilesToNever() { this->SetQueryFiles(0); }
210  void SetQueryFilesToDefault() { this->SetQueryFiles(-1); }
211  vtkSetMacro(QueryFiles, int);
212  int GetQueryFiles() { return this->QueryFiles; }
213 
215  const char *GetFileSetID() { return this->FileSetID; }
218 
220  const char *GetInternalFileName() { return this->InternalFileName; }
223 
225 
230  vtkSetMacro(IgnoreDicomdir, int);
231  vtkBooleanMacro(IgnoreDicomdir, int);
232  int GetIgnoreDicomdir() { return this->IgnoreDicomdir; }
234 
236 
241  vtkSetMacro(RequirePixelData, int);
242  vtkBooleanMacro(RequirePixelData, int);
243  int GetRequirePixelData() { return this->RequirePixelData; }
245 
247  vtkSetMacro(FollowSymlinks, int);
249  vtkBooleanMacro(FollowSymlinks, int);
250  int GetFollowSymlinks() { return this->FollowSymlinks; }
252 
254 
259  vtkSetMacro(ShowHidden, int);
260  vtkBooleanMacro(ShowHidden, int);
261  int GetShowHidden() { return this->ShowHidden; }
263 
265 
274  vtkDICOMCharacterSet GetDefaultCharacterSet() {
275  return this->DefaultCharacterSet; }
276 
278 
283  vtkSetMacro(OverrideCharacterSet, bool);
284  vtkBooleanMacro(OverrideCharacterSet, bool);
285  bool GetOverrideCharacterSet() {
286  return this->OverrideCharacterSet; }
288 
289 protected:
291  ~vtkDICOMDirectory() VTK_DICOM_OVERRIDE;
292 
293  const char *DirectoryName;
294  vtkStringArray *InputFileNames;
295  const char *FilePattern;
296  int QueryFiles;
297  int IgnoreDicomdir;
298  int RequirePixelData;
299  int FollowSymlinks;
300  int ShowHidden;
301  int ScanDepth;
302  vtkDICOMCharacterSet DefaultCharacterSet;
303  bool OverrideCharacterSet;
304 
305  vtkTimeStamp UpdateTime;
306  char *InternalFileName;
307 
309  virtual void Execute();
310 
312  virtual void FillImageRecord(vtkDICOMItem *item, vtkDICOMMetaData *meta,
313  const vtkDICOMTag *skip, size_t nskip);
314 
316  virtual void FillSeriesRecord(vtkDICOMItem *item, vtkDICOMMetaData *meta);
317 
319  virtual void FillStudyRecord(vtkDICOMItem *item, vtkDICOMMetaData *meta);
320 
322  virtual void FillPatientRecord(vtkDICOMItem *item, vtkDICOMMetaData *meta);
323 
325  virtual void SortFiles(vtkStringArray *input);
326 
328 
334  void AddSeriesFileNames(
335  int patient, int study, vtkStringArray *files,
336  const vtkDICOMItem& patientRecord,
337  const vtkDICOMItem& studyRecord,
338  const vtkDICOMItem& seriesRecord,
339  const vtkDICOMItem *imageRecords[]);
340 
342  void AddSeriesWithQuery(
343  int patient, int study, vtkStringArray *files,
344  const vtkDICOMItem& patientRecord,
345  const vtkDICOMItem& studyRecord,
346  const vtkDICOMItem& seriesRecord,
347  const vtkDICOMItem *imageRecords[]);
348 
350 
353  bool MatchesQuery(
354  const vtkDICOMItem& record, vtkDICOMItem& result);
355 
357 
366  int MatchesImageQuery(
367  const vtkDICOMItem& record, const vtkDICOMItem& result);
368 
370  void RelayError(vtkObject *o, unsigned long e, void *data);
371 
373  void SetInternalFileName(const char *fname);
374 
376  void SetErrorCode(unsigned long e) VTK_DICOM_OVERRIDE {
377  this->ErrorCode = e; }
378 
380 
385  void ProcessDirectoryFile(const char *dirname, vtkDICOMMetaData *meta);
386 
389  const char *dirname, int depth, vtkStringArray *files);
390 
392  void ProcessOsirixDatabase(const char *fname);
393 
396  vtkDICOMMetaData *meta, const vtkDICOMItem *item, int instance);
397 
398 private:
399 #ifdef VTK_DICOM_DELETE
400  vtkDICOMDirectory(const vtkDICOMDirectory&) VTK_DICOM_DELETE;
401  void operator=(const vtkDICOMDirectory&) VTK_DICOM_DELETE;
402 #else
403  vtkDICOMDirectory(const vtkDICOMDirectory&) = delete;
404  void operator=(const vtkDICOMDirectory&) = delete;
405 #endif
406 
407  struct SeriesItem;
408  struct StudyItem;
409  struct PatientItem;
410  class SeriesVector;
411  class StudyVector;
412  class PatientVector;
413  struct FileInfo;
414  struct FileInfoPair;
415  struct SeriesInfo;
416  class SeriesInfoList;
417  class SeriesInfoVector;
418  class VisitedVector;
419 
420  vtkDICOMItem *Query;
421  int FindLevel;
422  SeriesVector *Series;
423  StudyVector *Studies;
424  PatientVector *Patients;
425  VisitedVector *Visited;
426  char *FileSetID;
427  bool UsingOsirixDatabase;
428 
429  const vtkDICOMItem *CurrentPatientRecord;
430  const vtkDICOMItem *CurrentStudyRecord;
431  const vtkDICOMItem *CurrentSeriesRecord;
432  const vtkDICOMItem *CurrentImageRecord;
433 
435  static bool CompareInstance(const FileInfo &fi1, const FileInfo &fi2);
436 
438  static bool CompareSeriesUIDs(const SeriesInfo *si, const char *uid);
439 
441  static bool CompareSeriesIds(const SeriesInfo *li1, const SeriesInfo *li2);
442 
444  static bool CompareSeriesInfo(const SeriesInfo &li1, const SeriesInfo &li2);
445 
447  static bool CompareInstanceUIDs(const FileInfoPair& p, const char *uid);
448 };
449 
450 #endif
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:54
Character sets.
Definition: vtkDICOMCharacterSet.h:55
Get information about all DICOM files within a directory.
Definition: vtkDICOMDirectory.h:47
void ProcessOsirixDatabase(const char *fname)
Process an OsiriX sqlite database file.
void Update(int) VTK_DICOM_OVERRIDE
void SetInputFileNames(vtkStringArray *sa)
Set a list of filenames (or files and directories) to read.
const vtkDICOMItem & GetPatientRecord(int patient)
Get the directory attributes for a patient.
void AddInputFileNames(vtkStringArray *sa)
Add more filenames to be read.
void SetQueryFilesToAlways()
Set when to query the files, rather than just the DICOMDIR index.
Definition: vtkDICOMDirectory.h:208
void Update() VTK_DICOM_OVERRIDE
Update the information about the files.
Definition: vtkDICOMDirectory.h:135
int GetNumberOfPatients()
Get the number of patients that were found.
vtkIntArray * GetStudiesForPatient(int patient)
Get the studies for this patient.
vtkDICOMMetaData * GetMetaDataForSeries(int i)
Get the meta data for a specific series.
int GetLastSeriesForStudy(int study)
Get the last series in a particular study.
int GetNumberOfStudies()
Get the number of studies that were found.
vtkTypeBool Update(vtkInformation *) VTK_DICOM_OVERRIDE
Definition: vtkDICOMDirectory.h:138
void SetFilePattern(const char *pattern)
Set a pattern to match for the filenames.
vtkStringArray * GetFileNamesForSeries(int i)
Get the file names for a specific series.
void ProcessDirectoryFile(const char *dirname, vtkDICOMMetaData *meta)
Add all of the series listed in a DICOMDIR file.
void SetFindLevel(int level)
Specify the find level.
const vtkDICOMItem & GetPatientRecordForStudy(int study)
Get the patient-related attributes for a specific study.
void PrintSelf(ostream &os, vtkIndent indent) VTK_DICOM_OVERRIDE
void CopyRecord(vtkDICOMMetaData *meta, const vtkDICOMItem *item, int instance)
Copy attributes into a meta data object.
const vtkDICOMItem & GetStudyRecord(int study)
Get the directory attributes for a study.
const vtkDICOMItem & GetSeriesRecord(int series)
Get the directory attributes for a series.
void SetDefaultCharacterSet(vtkDICOMCharacterSet cs)
Set the character set to use if SpecificCharacterSet is missing.
vtkTypeBool Update(int i, vtkInformationVector *) VTK_DICOM_OVERRIDE
Definition: vtkDICOMDirectory.h:140
void SetDirectoryName(const char *name)
Set the input directory.
void ProcessDirectory(const char *dirname, int depth, vtkStringArray *files)
Process a directory, and subdirs to the specified depth.
An item in a DICOM sequence (type SQ).
Definition: vtkDICOMItem.h:34
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
A (group,element) identifier tag for DICOM attributes.
Definition: vtkDICOMTag.h:23
abstract base class for most VTK objects
Definition: vtkObject.h:54