From 0b9694d267e7eab6b1b8fb25d59fde201ccb1000 Mon Sep 17 00:00:00 2001 From: malaterre Date: Wed, 9 Nov 2005 19:17:26 +0000 Subject: [PATCH] ENH: Adding proof of concept to replace current implementation of string VR by an enum type --- Testing/CMakeLists.txt | 1 + Testing/TestEnumVR.cxx | 135 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 Testing/TestEnumVR.cxx diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index ddf756f2..4b16fcb0 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -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 index 00000000..a723515b --- /dev/null +++ b/Testing/TestEnumVR.cxx @@ -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 +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; +} -- 2.45.1