]> Creatis software - gdcm.git/commitdiff
ENH: Adding proof of concept to replace current implementation of string VR by an...
authormalaterre <malaterre>
Wed, 9 Nov 2005 19:17:26 +0000 (19:17 +0000)
committermalaterre <malaterre>
Wed, 9 Nov 2005 19:17:26 +0000 (19:17 +0000)
Testing/CMakeLists.txt
Testing/TestEnumVR.cxx [new file with mode: 0644]

index ddf756f25c1af482a30411cb4763e7fbffdfe149..4b16fcb0eaf6efc7621f01d5f3579c0f2c6a5615 100644 (file)
@@ -20,6 +20,7 @@ SET(TEST_SOURCES
   TestImageSet.cxx
   TestDicomDirElement.cxx
   TestDicomString.cxx
+  TestEnumVR.cxx
 
 )
 IF(UNIX)
diff --git a/Testing/TestEnumVR.cxx b/Testing/TestEnumVR.cxx
new file mode 100644 (file)
index 0000000..a723515
--- /dev/null
@@ -0,0 +1,135 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: TestEnumVR.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/11/09 19:17:26 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html 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 notices for more information.
+                                                                                
+=========================================================================*/
+/*
+ * Proof of concept for using enum instead of string for representing VR
+ * This allows us to:
+ * 1. Qickly check against another VR (faster than string comparison)
+ * 2. Support the advance VR like 'OB or OW'
+ */
+
+#include <iostream>
+typedef enum VR {
+  AE = 1,
+  AS = 2,
+  AT = 4,
+  CS = 8,
+  DA = 16,
+  DS = 32,
+  DT = 64,
+  FL = 128,
+  FD = 256,
+  IS = 512,
+  LO = 1024,
+  LT = 2048,
+  OB = 4096,
+  OW = 8192,
+  PN = 16384,
+  SH = 32768,
+  SL = 65536,
+  SQ = 131072,
+  SS = 262144,
+  ST = 524288,
+  TM = 1048576,
+  UI = 2097152,
+  UL = 4194304,
+  UN = 8388608,
+  US = 16777216,
+  UT = 33554432,
+  OB_OW = OB | OW,
+  US_SS = US | SS,
+  US_SS_OW = US | SS | OW
+};
+
+static const char *VRStrings[] = {
+  "AE",
+  "AS",
+  "AT",
+  "CS",
+  "DA",
+  "DS",
+  "DT",
+  "FL",
+  "FD",
+  "IS",
+  "LO",
+  "LT",
+  "OB",
+  "OW",
+  "PN",
+  "SH",
+  "SL",
+  "SQ",
+  "SS",
+  "ST",
+  "TM",
+  "UI",
+  "UL",
+  "UN",
+  "US",
+  "UT",
+  "OB or OW",
+  "US or SS",
+  "US or SS or OW"
+};
+
+
+int get_index_vr(VR vr)
+{
+  int l;
+  switch(vr)
+    {
+  case OB_OW:
+    l =  26;
+    break;
+  case US_SS:
+    l =  27;
+    break;
+  case US_SS_OW:
+    l =  28;
+    break;
+  default:
+      {
+      int a = (int)vr;
+      for (l = 0; a > 1; ++l)
+        a >>= 1;
+      }
+    }
+  return l;
+}
+
+int TestEnumVR(int , char *[])
+{
+  for(int i=0; i<26; i++)
+    {
+    int j = 1 << i;
+    int k = get_index_vr((VR)j);
+    std::cout << k << "," << VRStrings[k] << std::endl;
+    }
+
+   VR vr = OB_OW;
+   int k = get_index_vr(vr);
+   std::cout << k << "," << VRStrings[k] << std::endl;
+   vr = US_SS;
+   k = get_index_vr(vr);
+   std::cout << k << "," << VRStrings[k] << std::endl;
+   vr = US_SS_OW;
+   k = get_index_vr(vr);
+   std::cout << k << "," << VRStrings[k] << std::endl;
+
+   return 0;
+}