vtk-dicom  0.8.17
vtkDICOMUtilities.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 vtkDICOMUtilities_h
15 #define vtkDICOMUtilities_h
16 
17 #include "vtkObject.h"
18 #include "vtkStdString.h" // For std::string
19 #include "vtkDICOMModule.h" // For export macro
20 #include "vtkDICOMConfig.h" // For configuration details
21 #include "vtkDICOMTag.h" // For method parameter
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 
30 #if defined(VTK_ABI_NAMESPACE_BEGIN)
31 VTK_ABI_NAMESPACE_END
32 #endif
33 
35 class VTKDICOM_EXPORT vtkDICOMUtilities : public vtkObject
36 {
37 public:
39  static vtkDICOMUtilities *New();
41 
43  vtkTypeMacro(vtkDICOMUtilities, vtkObject);
44 
46  void PrintSelf(ostream& os, vtkIndent indent) VTK_DICOM_OVERRIDE;
48 
50 
55  static void SetUIDPrefix(const char *prefix);
56  static const char *GetUIDPrefix();
58 
60  static std::string GenerateUID(vtkDICOMTag tag);
62 
64 
71  static void GenerateUIDs(vtkDICOMTag tag, vtkStringArray *uids);
72 
74  static int CompareUIDs(const char *u1, const char *u2);
76 
78 
85  static std::string GenerateDateTime(const char *zone);
86 
88 
95  static std::string GenerateDateTime(long long microsecs, const char *zone);
96 
98 
107  static long long ConvertDateTime(const char *datetime);
108 
110 
114  static long long GetUniversalTime();
116 
118  static long long GetUTC(long long *offset);
119 
121 
127  static bool IsDICOMFile(const char *filename);
129 
131  static const char *GetImplementationClassUID();
133 
135 
140  static void SetImplementationClassUID(const char *uid);
141 
143  static const char *GetImplementationVersionName();
144 
146 
151  static void SetImplementationVersionName(const char *name);
153 
155 
160  static unsigned int UnpackUnsignedInt(const unsigned char *cp) {
161  return cp[0] + (cp[1] << 8) + (cp[2] << 16) + (cp[3] << 24); }
162 
164 
168  static void PackUnsignedInt(unsigned int i, unsigned char *cp) {
169  cp[0] = static_cast<unsigned char>(i);
170  cp[1] = static_cast<unsigned char>(i >> 8);
171  cp[2] = static_cast<unsigned char>(i >> 16);
172  cp[3] = static_cast<unsigned char>(i >> 24); }
174 
176 
182  static bool PatternMatches(const char *pattern, const char *val);
183 
185  static bool PatternMatches(
186  const char *pattern, size_t pl, const char *val, size_t vl);
188 
190 
197  static bool IsValidUTF8(const char *text, size_t l);
199 
201  static const char *GetUIDName(const char *uid);
203 
205  unsigned short GetCIDFromUID(const char *uid);
207 
208 protected:
209  vtkDICOMUtilities() {}
210  ~vtkDICOMUtilities() VTK_DICOM_OVERRIDE {}
211 
212  static long long GetLocalOffset(long long t);
213 
214  static char UIDPrefix[64];
215  static char ImplementationClassUID[65];
216  static char ImplementationVersionName[17];
217 
218 private:
219 #ifdef VTK_DICOM_DELETE
220  vtkDICOMUtilities(const vtkDICOMUtilities&) VTK_DICOM_DELETE;
221  void operator=(const vtkDICOMUtilities&) VTK_DICOM_DELETE;
222 #else
223  vtkDICOMUtilities(const vtkDICOMUtilities&) = delete;
224  void operator=(const vtkDICOMUtilities&) = delete;
225 #endif
226 };
227 
228 #endif /* vtkDICOMUtilities_h */
A (group,element) identifier tag for DICOM attributes.
Definition: vtkDICOMTag.h:23
Utility functions for use with DICOM classes.
Definition: vtkDICOMUtilities.h:36
static long long ConvertDateTime(const char *datetime)
Convert a DICOM data time string into a long integer.
static bool IsValidUTF8(const char *text, size_t l)
Check that a string is valid utf-8.
static std::string GenerateDateTime(const char *zone)
Generate a DICOM date time string in the given timezone.
static std::string GenerateDateTime(long long microsecs, const char *zone)
Generate a DICOM date time string from long integer.
static const char * GetImplementationVersionName()
Get the versioned name for this DICOM implementation.
unsigned short GetCIDFromUID(const char *uid)
Get the CID from the UID.
static void PackUnsignedInt(unsigned int i, unsigned char *cp)
Pack one little-endian int into a stream of bytes.
Definition: vtkDICOMUtilities.h:168
static bool IsDICOMFile(const char *filename)
Check if the specified file is a DICOM file.
static int CompareUIDs(const char *u1, const char *u2)
Numerically compare two UIDs, returns -1, 0, or +1.
static void SetUIDPrefix(const char *prefix)
Set a UID prefix to use when generating UIDs.
static void SetImplementationVersionName(const char *name)
Set the versioned name for this DICOM implementation.
static long long GetUniversalTime()
Get the current time in microseconds.
static bool PatternMatches(const char *pattern, size_t pl, const char *val, size_t vl)
Match patterns on non-terminated strings.
static void GenerateUIDs(vtkDICOMTag tag, vtkStringArray *uids)
Generate a series of UIDs, sorted from low to high.
static bool PatternMatches(const char *pattern, const char *val)
Return true if the pattern matches the given string (utf-8).
static long long GetUTC(long long *offset)
Deprecated method, do not use.
static unsigned int UnpackUnsignedInt(const unsigned char *cp)
Unpack one little-endian int from a stream of bytes.
Definition: vtkDICOMUtilities.h:160
static void SetImplementationClassUID(const char *uid)
Set the UID for this DICOM implementation.
void PrintSelf(ostream &os, vtkIndent indent) VTK_DICOM_OVERRIDE
Print a summary of the contents of this object.
abstract base class for most VTK objects
Definition: vtkObject.h:54
static vtkObject * New()