00001 /* 00002 * 00003 * Copyright (C) 1998-2005, OFFIS 00004 * 00005 * This software and supporting documentation were developed by 00006 * 00007 * Kuratorium OFFIS e.V. 00008 * Healthcare Information and Communication Systems 00009 * Escherweg 2 00010 * D-26121 Oldenburg, Germany 00011 * 00012 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 00013 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00014 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 00015 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 00016 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 00017 * 00018 * Module: dcmpstat 00019 * 00020 * Author: Joerg Riesmeier 00021 * 00022 * Purpose: Classes for caching of the image database (Header/Source) 00023 * 00024 * Last Update: $Author: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:03:30 $ 00026 * Source File: $Source: /share/dicom/cvs-depot/dcmtk/dcmpstat/include/dcmtk/dcmpstat/dvcache.h,v $ 00027 * CVS/RCS Revision: $Revision: 1.16 $ 00028 * Status: $State: Exp $ 00029 * 00030 * CVS/RCS Log at end of file 00031 * 00032 */ 00033 00034 00035 #ifndef __DVCACHE_H 00036 #define __DVCACHE_H 00037 00038 #include "dcmtk/config/osconfig.h" 00039 00040 #include "dcmtk/ofstd/oflist.h" 00041 #include "dcmtk/ofstd/ofstring.h" 00042 #include "dcmtk/dcmqrdb/dcmqrdbi.h" /* for DVIFhierarchyStatus */ 00043 00044 /*--------------------* 00045 * type definitions * 00046 *--------------------*/ 00047 00050 enum DVPSInstanceType 00051 { 00053 DVPSI_image, 00055 DVPSI_presentationState, 00057 DVPSI_structuredReport, 00059 DVPSI_storedPrint, 00061 DVPSI_hardcopyGrayscale 00062 }; 00063 00064 00065 /*---------------------* 00066 * class declaration * 00067 *---------------------*/ 00068 00074 class DVInstanceCache 00075 { 00076 00077 public: 00078 00081 struct ItemStruct 00082 { 00093 ItemStruct(const OFString &uid, 00094 const int pos, 00095 const DVIFhierarchyStatus status, 00096 const DVPSInstanceType type, 00097 const int size, 00098 const OFString &filename) 00099 : UID(uid), 00100 Pos(pos), 00101 Status(status), 00102 Type(type), 00103 ImageSize(size), 00104 Filename(filename), 00105 Checked(OFFalse), 00106 Description(), 00107 Label(), 00108 List() 00109 {} 00110 00112 OFString UID; 00114 int Pos; 00116 DVIFhierarchyStatus Status; 00118 DVPSInstanceType Type; 00120 int ImageSize; 00122 OFString Filename; 00124 OFBool Checked; 00126 OFString Description; 00128 OFString Label; 00130 OFList<ItemStruct *> List; 00131 }; 00132 00135 DVInstanceCache() 00136 : List(), 00137 Iterator(), 00138 OldIterator() 00139 { 00140 Iterator = OldIterator = List.end(); 00141 } 00142 00145 virtual ~DVInstanceCache() 00146 { 00147 clear(); 00148 } 00149 00153 inline void clear() 00154 { 00155 Iterator = List.begin(); 00156 OFListIterator(ItemStruct *) last = List.end(); 00157 while (Iterator != last) 00158 { 00159 delete (*Iterator); 00160 Iterator = List.erase(Iterator); 00161 } 00162 List.clear(); 00163 Iterator = OldIterator = List.end(); 00164 } 00165 00170 inline OFBool empty() const 00171 { 00172 return List.empty(); 00173 } 00174 00179 inline Uint32 getCount() const 00180 { 00181 return List.size(); 00182 } 00183 00190 inline OFBool gotoItem(Uint32 idx) 00191 { 00192 OFBool result = OFFalse; 00193 Iterator = List.begin(); 00194 OFListIterator(ItemStruct *) last = List.end(); 00195 while (Iterator != last) 00196 { 00197 if (idx == 0) 00198 { 00199 result = OFTrue; 00200 break; 00201 } 00202 idx--; 00203 ++Iterator; 00204 } 00205 return result; 00206 } 00207 00212 inline OFBool gotoFirst() 00213 { 00214 OldIterator = Iterator; 00215 Iterator = List.begin(); 00216 return (Iterator != List.end()); 00217 } 00218 00223 inline OFBool gotoNext() 00224 { 00225 OFListIterator(ItemStruct *) last = List.end(); 00226 if (Iterator != last) 00227 Iterator++; 00228 return (Iterator != last); 00229 } 00230 00236 inline OFBool reset() 00237 { 00238 OFBool result = OFFalse; 00239 OFListIterator(ItemStruct *) last = List.end(); 00240 if (OldIterator != last) 00241 { 00242 Iterator = OldIterator; 00243 OldIterator = last; 00244 result = OFTrue; 00245 } 00246 return result; 00247 } 00248 00255 inline OFBool isElem(const OFString &uid) 00256 { 00257 OFBool result = OFFalse; 00258 Iterator = List.begin(); 00259 OFListIterator(ItemStruct *) last = List.end(); 00260 while (Iterator != last) 00261 { 00262 const ItemStruct *item = (*Iterator); 00263 if (item != NULL) 00264 { 00265 if (item->UID == uid) 00266 { 00267 result = OFTrue; 00268 break; 00269 } 00270 } 00271 ++Iterator; 00272 } 00273 return result; 00274 } 00275 00280 inline int getPos() const 00281 { 00282 const ItemStruct *item = getItem(); 00283 return (item != NULL) ? item->Pos : 0; 00284 } 00285 00290 inline DVIFhierarchyStatus getStatus() const 00291 { 00292 const ItemStruct *item = getItem(); 00293 return (item != NULL) ? item->Status : DVIF_objectIsNew; 00294 } 00295 00300 inline DVPSInstanceType getType() const 00301 { 00302 const ItemStruct *item = getItem(); 00303 return (item != NULL) ? item->Type : DVPSI_image; 00304 } 00305 00310 inline int getImageSize() const 00311 { 00312 const ItemStruct *item = getItem(); 00313 return (item != NULL) ? item->ImageSize : 0; 00314 } 00315 00320 inline const char *getFilename() const 00321 { 00322 const ItemStruct *item = getItem(); 00323 return (item != NULL) ? item->Filename.c_str() : (const char *)NULL; 00324 } 00325 00330 inline ItemStruct *getItem() const 00331 { 00332 return (Iterator != List.end()) ? (*Iterator) : (ItemStruct *)NULL; 00333 } 00334 00345 inline void addItem(const OFString &uid, 00346 const int pos, 00347 const DVIFhierarchyStatus status, 00348 const DVPSInstanceType type, 00349 const int size, 00350 const OFString &filename) 00351 { 00352 ItemStruct *item = new ItemStruct(uid, pos, status, type, size, filename); 00353 List.push_back(item); 00354 Iterator = --List.end(); // set to new position 00355 } 00356 00361 inline DVIFhierarchyStatus updateStatus() 00362 { 00363 OFListIterator(ItemStruct *) first = List.begin(); 00364 OFListIterator(ItemStruct *) last = List.end(); 00365 OFListIterator(ItemStruct *) iter = first; 00366 DVIFhierarchyStatus status = DVIF_objectIsNew; 00367 while (iter != last) 00368 { 00369 ItemStruct *item = (*iter); 00370 if (item != NULL) 00371 { 00372 switch (item->Status) 00373 { 00374 case DVIF_objectIsNew: 00375 if (status == DVIF_objectIsNotNew) 00376 status = DVIF_objectContainsNewSubobjects; 00377 break; 00378 case DVIF_objectIsNotNew: 00379 case DVIF_objectContainsNewSubobjects: 00380 if (iter == first) 00381 status = DVIF_objectIsNotNew; 00382 else if (status == DVIF_objectIsNew) 00383 status = DVIF_objectContainsNewSubobjects; 00384 break; 00385 } 00386 } 00387 ++iter; 00388 } 00389 return status; 00390 } 00391 00392 00393 protected: 00394 00396 OFList<ItemStruct *> List; 00398 OFListIterator(ItemStruct *) Iterator; 00400 OFListIterator(ItemStruct *) OldIterator; 00401 }; 00402 00403 00404 /* ------------------------------ */ 00405 00406 00412 class DVSeriesCache 00413 { 00414 00415 public: 00416 00419 struct ItemStruct 00420 { 00428 ItemStruct(const OFString &uid, 00429 const DVIFhierarchyStatus status = DVIF_objectIsNew, 00430 const DVPSInstanceType type = DVPSI_image) 00431 : UID(uid), 00432 Status(status), 00433 Type(type), 00434 List() 00435 {} 00436 00438 OFString UID; 00440 DVIFhierarchyStatus Status; 00442 DVPSInstanceType Type; 00444 DVInstanceCache List; 00445 }; 00446 00449 DVSeriesCache() 00450 : List(), 00451 Iterator(), 00452 OldIterator() 00453 { 00454 Iterator = OldIterator = List.end(); 00455 } 00456 00459 virtual ~DVSeriesCache() 00460 { 00461 clear(); 00462 } 00463 00467 inline void clear() 00468 { 00469 Iterator = List.begin(); 00470 OFListIterator(ItemStruct *) last = List.end(); 00471 while (Iterator != last) 00472 { 00473 delete (*Iterator); 00474 Iterator = List.erase(Iterator); 00475 } 00476 List.clear(); 00477 Iterator = OldIterator = List.end(); 00478 } 00479 00484 inline OFBool empty() const 00485 { 00486 return List.empty(); 00487 } 00488 00493 inline Uint32 getCount() const 00494 { 00495 return List.size(); 00496 } 00497 00504 inline OFBool gotoItem(Uint32 idx) 00505 { 00506 OFBool result = OFFalse; 00507 Iterator = List.begin(); 00508 OFListIterator(ItemStruct *) last = List.end(); 00509 while (Iterator != last) 00510 { 00511 if (idx == 0) 00512 { 00513 result = OFTrue; 00514 break; 00515 } 00516 idx--; 00517 ++Iterator; 00518 } 00519 return result; 00520 } 00521 00526 inline OFBool gotoFirst() 00527 { 00528 OldIterator = Iterator; 00529 Iterator = List.begin(); 00530 return (Iterator != List.end()); 00531 } 00532 00537 inline OFBool gotoNext() 00538 { 00539 OFListIterator(ItemStruct *) last = List.end(); 00540 if (Iterator != last) 00541 Iterator++; 00542 return (Iterator != last); 00543 } 00544 00550 inline OFBool reset() 00551 { 00552 OFBool result = OFFalse; 00553 OFListIterator(ItemStruct *) last = List.end(); 00554 if (OldIterator != last) 00555 { 00556 Iterator = OldIterator; 00557 OldIterator = last; 00558 result = OFTrue; 00559 } 00560 return result; 00561 } 00562 00569 inline OFBool isElem(const OFString &uid) 00570 { 00571 OFBool result = OFFalse; 00572 Iterator = List.begin(); 00573 OFListIterator(ItemStruct *) last = List.end(); 00574 while (Iterator != last) 00575 { 00576 const ItemStruct *item = (*Iterator); 00577 if (item != NULL) 00578 { 00579 if (item->UID == uid) 00580 { 00581 result = OFTrue; 00582 break; 00583 } 00584 } 00585 ++Iterator; 00586 } 00587 return result; 00588 } 00589 00594 inline DVIFhierarchyStatus getStatus() const 00595 { 00596 const ItemStruct *item = getItem(); 00597 return (item != NULL) ? item->Status : DVIF_objectIsNew; 00598 } 00599 00604 inline DVPSInstanceType getType() const 00605 { 00606 const ItemStruct *item = getItem(); 00607 return (item != NULL) ? item->Type : DVPSI_image; 00608 } 00609 00614 inline ItemStruct *getItem() const 00615 { 00616 return (Iterator != List.end()) ? (*Iterator) : (ItemStruct *)NULL; 00617 } 00618 00625 inline void addItem(const OFString &uid, 00626 const DVIFhierarchyStatus status = DVIF_objectIsNew) 00627 { 00628 ItemStruct *item = new ItemStruct(uid, status); 00629 List.push_back(item); 00630 Iterator = --List.end(); // set to new position 00631 } 00632 00637 inline DVIFhierarchyStatus updateStatus() 00638 { 00639 OFListIterator(ItemStruct *) first = List.begin(); 00640 OFListIterator(ItemStruct *) last = List.end(); 00641 OFListIterator(ItemStruct *) iter = first; 00642 DVIFhierarchyStatus status = DVIF_objectIsNew; 00643 while (iter != last) 00644 { 00645 ItemStruct *item = (*iter); 00646 if (item != NULL) 00647 { 00648 item->Status = item->List.updateStatus(); 00649 switch (item->Status) 00650 { 00651 case DVIF_objectIsNew: 00652 if (status == DVIF_objectIsNotNew) 00653 status = DVIF_objectContainsNewSubobjects; 00654 break; 00655 case DVIF_objectIsNotNew: 00656 if (iter == first) 00657 status = DVIF_objectIsNotNew; 00658 else if (status == DVIF_objectIsNew) 00659 status = DVIF_objectContainsNewSubobjects; 00660 break; 00661 case DVIF_objectContainsNewSubobjects: 00662 status = DVIF_objectContainsNewSubobjects; 00663 break; 00664 } 00665 } 00666 ++iter; 00667 } 00668 return status; 00669 } 00670 00671 00672 protected: 00673 00675 OFList<ItemStruct *> List; 00677 OFListIterator(ItemStruct *) Iterator; 00679 OFListIterator(ItemStruct *) OldIterator; 00680 }; 00681 00682 00683 /* ------------------------------ */ 00684 00685 00691 class DVStudyCache 00692 { 00693 00694 public: 00695 00698 struct ItemStruct 00699 { 00706 ItemStruct(const OFString &uid, 00707 const DVIFhierarchyStatus status = DVIF_objectIsNew) 00708 : UID(uid), 00709 Status(status), 00710 List() 00711 {} 00712 00714 OFString UID; 00716 DVIFhierarchyStatus Status; 00718 DVSeriesCache List; 00719 }; 00720 00723 DVStudyCache() 00724 : List(), 00725 Iterator() 00726 { 00727 Iterator = List.end(); 00728 } 00729 00732 virtual ~DVStudyCache() 00733 { 00734 clear(); 00735 } 00736 00740 inline void clear() 00741 { 00742 Iterator = List.begin(); 00743 OFListIterator(ItemStruct *) last = List.end(); 00744 while (Iterator != last) 00745 { 00746 delete (*Iterator); 00747 Iterator = List.erase(Iterator); 00748 } 00749 List.clear(); 00750 Iterator = List.end(); 00751 } 00752 00757 inline OFBool empty() const 00758 { 00759 return List.empty(); 00760 } 00761 00766 inline Uint32 getCount() const 00767 { 00768 return List.size(); 00769 } 00770 00777 inline OFBool gotoItem(Uint32 idx) 00778 { 00779 OFBool result = OFFalse; 00780 Iterator = List.begin(); 00781 OFListIterator(ItemStruct *) last = List.end(); 00782 while (Iterator != last) 00783 { 00784 if (idx == 0) 00785 { 00786 result = OFTrue; 00787 break; 00788 } 00789 idx--; 00790 ++Iterator; 00791 } 00792 return result; 00793 } 00794 00799 inline OFBool gotoFirst() 00800 { 00801 //OldIterator = Iterator; 00802 Iterator = List.begin(); 00803 return (Iterator != List.end()); 00804 } 00805 00810 inline OFBool gotoNext() 00811 { 00812 OFListIterator(ItemStruct *) last = List.end(); 00813 if (Iterator != last) 00814 Iterator++; 00815 return (Iterator != last); 00816 } 00817 00824 inline OFBool isElem(const OFString &uid) 00825 { 00826 OFBool result = OFFalse; 00827 Iterator = List.begin(); 00828 OFListIterator(ItemStruct *) last = List.end(); 00829 while (Iterator != last) 00830 { 00831 const ItemStruct *item = (*Iterator); 00832 if (item != NULL) 00833 { 00834 if (item->UID == uid) 00835 { 00836 result= OFTrue; 00837 break; 00838 } 00839 } 00840 ++Iterator; 00841 } 00842 return result; 00843 } 00844 00849 inline DVIFhierarchyStatus getStatus() const 00850 { 00851 const ItemStruct *item = getItem(); 00852 return (item != NULL) ? item->Status : DVIF_objectIsNew; 00853 } 00854 00859 inline ItemStruct *getItem() const 00860 { 00861 return (Iterator != List.end()) ? (*Iterator) : (ItemStruct *)NULL; 00862 } 00863 00870 inline void addItem(const OFString &uid, 00871 const DVIFhierarchyStatus status = DVIF_objectIsNew) 00872 { 00873 ItemStruct *item = new ItemStruct(uid, status); 00874 List.push_back(item); 00875 Iterator = --List.end(); // set to new position 00876 } 00877 00882 inline void updateStatus() 00883 { 00884 OFListIterator(ItemStruct *) iter = List.begin(); 00885 OFListIterator(ItemStruct *) last = List.end(); 00886 while (iter != last) 00887 { 00888 ItemStruct *item = (*iter); 00889 if (item != NULL) 00890 item->Status = item->List.updateStatus(); 00891 ++iter; 00892 } 00893 } 00894 00895 00896 protected: 00897 00899 OFList<ItemStruct *> List; 00901 OFListIterator(ItemStruct *) Iterator; 00902 }; 00903 00904 00905 #endif 00906 00907 00908 /* 00909 * 00910 * CVS/RCS Log: 00911 * $Log: dvcache.h,v $ 00912 * Revision 1.16 2005/12/08 16:03:30 meichel 00913 * Changed include path schema for all DCMTK header files 00914 * 00915 * Revision 1.15 2005/04/04 10:11:57 meichel 00916 * Module dcmpstat now uses the dcmqrdb API instead of imagectn for maintaining 00917 * the index database 00918 * 00919 * Revision 1.14 2001/06/01 15:50:11 meichel 00920 * Updated copyright header 00921 * 00922 * Revision 1.13 2000/10/16 11:39:10 joergr 00923 * Added method allowing to select an instance by instance UID and SOP class 00924 * UID (without series and study UID). Required for composite references in 00925 * DICOM SR. 00926 * 00927 * Revision 1.12 2000/06/30 09:08:39 joergr 00928 * Fixed bug in database cache routines (re. study status). 00929 * 00930 * Revision 1.11 2000/05/30 13:37:15 joergr 00931 * Renamed GrayscaleHardcopy to HardcopyGrayscale (which is the correct term 00932 * according to the DICOM standard). 00933 * 00934 * Revision 1.10 2000/03/08 16:28:47 meichel 00935 * Updated copyright header. 00936 * 00937 * Revision 1.9 1999/09/08 17:03:00 joergr 00938 * Added support for new instance types in database (grayscale hardcopy and 00939 * stored print). 00940 * 00941 * Revision 1.8 1999/08/17 10:32:54 joergr 00942 * Added Doc++ styled comments. 00943 * Corrected wrong return type for method 'getImageSize()'. 00944 * 00945 * Revision 1.7 1999/05/03 11:01:08 joergr 00946 * Minor code purifications to keep Sun CC 2.0.1 quiet. 00947 * 00948 * Revision 1.6 1999/04/29 15:25:36 joergr 00949 * Added PresentationLabel to index file. 00950 * 00951 * Revision 1.5 1999/04/27 11:20:49 joergr 00952 * Add remaining member variables to member initialization list to avoid 00953 * compiler warnings. 00954 * 00955 * Revision 1.4 1999/02/24 20:14:39 joergr 00956 * Added support for presentation state caching (e.g. pstate description). 00957 * Removed unused methods. 00958 * 00959 * Revision 1.3 1999/02/19 18:56:08 joergr 00960 * Added new methods to interate through Caches (getFirst/getNext) - needed 00961 * for delete routines in Interface class. 00962 * 00963 * Revision 1.2 1999/02/19 09:45:19 joergr 00964 * Changed some comments, corrected typos and formatting. 00965 * 00966 * Revision 1.1 1999/02/18 18:50:18 joergr 00967 * Re-implemented methods to access index file (delete methods are still 00968 * missing). 00969 * 00970 * 00971 */