00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef DIMOPXT_H
00035 #define DIMOPXT_H
00036
00037 #include "dcmtk/config/osconfig.h"
00038 #include "dcmtk/ofstd/ofconsol.h"
00039 #include "dcmtk/ofstd/ofbmanip.h"
00040 #include "dcmtk/ofstd/ofcast.h"
00041
00042 #include "dcmtk/dcmdata/dctypes.h"
00043 #include "dcmtk/dcmdata/dcdefine.h"
00044
00045 #include "dcmtk/dcmimgle/dimopx.h"
00046 #include "dcmtk/dcmimgle/dipxrept.h"
00047 #include "dcmtk/dcmimgle/dimomod.h"
00048 #include "dcmtk/dcmimgle/diinpx.h"
00049 #include "dcmtk/dcmimgle/dimoopx.h"
00050
00051
00052
00053
00054
00055
00058 template<class T>
00059 class DiMonoPixelTemplate
00060 : public DiMonoPixel,
00061 public DiPixelRepresentationTemplate<T>
00062 {
00063
00064 public:
00065
00070 DiMonoPixelTemplate(const unsigned long count)
00071 : DiMonoPixel(count),
00072 Data(NULL)
00073 {
00074 MinValue[0] = 0;
00075 MinValue[1] = 0;
00076 MaxValue[0] = 0;
00077 MaxValue[1] = 0;
00078
00079 Data = new T[Count];
00080 }
00081
00087 DiMonoPixelTemplate(const DiInputPixel *pixel,
00088 DiMonoModality *modality)
00089 : DiMonoPixel(pixel, modality),
00090 Data(NULL)
00091 {
00092 MinValue[0] = 0;
00093 MinValue[1] = 0;
00094 MaxValue[0] = 0;
00095 MaxValue[1] = 0;
00096 }
00097
00103 DiMonoPixelTemplate(DiMonoOutputPixel *pixel,
00104 DiMonoModality *modality)
00105 : DiMonoPixel(pixel, modality),
00106 Data(OFstatic_cast(T *, pixel->getDataPtr()))
00107 {
00108 MinValue[0] = 0;
00109 MinValue[1] = 0;
00110 MaxValue[0] = 0;
00111 MaxValue[1] = 0;
00112 }
00113
00116 virtual ~DiMonoPixelTemplate()
00117 {
00118 delete[] Data;
00119 }
00120
00125 inline EP_Representation getRepresentation() const
00126 {
00127 return DiPixelRepresentationTemplate<T>::getRepresentation();
00128 }
00129
00134 inline const void *getData() const
00135 {
00136 return OFstatic_cast(const void *, Data);
00137 }
00138
00143 inline void *getDataPtr()
00144 {
00145 return OFstatic_cast(void *, Data);
00146 }
00147
00154 inline void *getDataArrayPtr()
00155 {
00156 return OFstatic_cast(void *, &Data);
00157 }
00158
00166 inline int getMinMaxValues(double &min,
00167 double &max) const
00168 {
00169 min = MinValue[0];
00170 max = MaxValue[0];
00171 return 1;
00172 }
00173
00182 inline int getMinMaxWindow(const int idx,
00183 double ¢er,
00184 double &width)
00185 {
00186 int result = 0;
00187 if ((idx >= 0) && (idx <= 1))
00188 {
00189 if ((idx == 1) && (MinValue[1] == 0) && (MaxValue[1] == 0))
00190 determineMinMax(0, 0, 0x2);
00191
00192
00193
00194 center = (OFstatic_cast(double, MinValue[idx]) + OFstatic_cast(double, MaxValue[idx]) + 1) / 2;
00195 width = OFstatic_cast(double, MaxValue[idx]) - OFstatic_cast(double, MinValue[idx]) + 1;
00196 result = (width > 0);
00197 }
00198 return result;
00199 }
00200
00215 virtual int getRoiWindow(const unsigned long left_pos,
00216 const unsigned long top_pos,
00217 const unsigned long width,
00218 const unsigned long height,
00219 const unsigned long columns,
00220 const unsigned long rows,
00221 const unsigned long frame,
00222 double &voiCenter,
00223 double &voiWidth)
00224 {
00225 int result = 0;
00226 if ((Data != NULL) && (left_pos < columns) && (top_pos < rows))
00227 {
00228 register T *p = Data + (columns * rows * frame) + (top_pos * columns) + left_pos;
00229 const unsigned long right_pos = (left_pos + width < columns) ? left_pos + width : columns;
00230 const unsigned long bottom = (top_pos + height < rows) ? top_pos + height : rows;
00231 const unsigned long skip_x = left_pos + (columns - right_pos);
00232 register unsigned long x;
00233 register unsigned long y;
00234 register T value = 0;
00235 register T min = *p;
00236 register T max = min;
00237 for (y = top_pos; y < bottom; ++y)
00238 {
00239 for (x = left_pos; x < right_pos; ++x)
00240 {
00241 value = *(p++);
00242 if (value < min)
00243 min = value;
00244 else if (value > max)
00245 max = value;
00246 }
00247 p += skip_x;
00248 }
00249
00250
00251
00252 voiCenter = (OFstatic_cast(double, min) + OFstatic_cast(double, max) + 1) / 2;
00253 voiWidth = OFstatic_cast(double, max) - OFstatic_cast(double, min) + 1;
00254 result = (width > 0);
00255 }
00256 return result;
00257 }
00258
00267 int getHistogramWindow(const double thresh,
00268 double ¢er,
00269 double &width)
00270 {
00271 if ((Data != NULL) && (MinValue[0] < MaxValue[0]))
00272 {
00273 const Uint32 count = OFstatic_cast(Uint32, MaxValue[0] - MinValue[0] + 1);
00274 Uint32 *quant = new Uint32[count];
00275 if (quant != NULL)
00276 {
00277 register unsigned long i;
00278 OFBitmanipTemplate<Uint32>::zeroMem(quant, count);
00279 for (i = 0; i < Count; ++i)
00280 {
00281 if ((Data[i] >= MinValue[0]) && (Data[i] <= MaxValue[0]))
00282 ++quant[OFstatic_cast(Uint32, Data[i] - MinValue[0])];
00283 #ifdef DEBUG
00284 else if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings))
00285 {
00286 ofConsole.lockCerr() << "WARNING: invalid value (" << Data[i] << ") in "
00287 << "int DiMonoPixelTemplate<T>::getHistogramWindow() ! " << endl;
00288 ofConsole.unlockCerr();
00289 }
00290 #endif
00291 }
00292 const Uint32 threshvalue = OFstatic_cast(Uint32, thresh * OFstatic_cast(double, Count));
00293 register Uint32 t = 0;
00294 i = 0;
00295 while ((i < count) && (t < threshvalue))
00296 t += quant[i++];
00297 const T minvalue = (i < count) ? OFstatic_cast(T, MinValue[0] + i) : 0;
00298 t = 0;
00299 i = count;
00300 while ((i > 0) && (t < threshvalue))
00301 t += quant[--i];
00302 const T maxvalue = (i > 0) ? OFstatic_cast(T, MinValue[0] + i) : 0;
00303 delete[] quant;
00304 if (minvalue < maxvalue)
00305 {
00306
00307
00308
00309 center = (OFstatic_cast(double, minvalue) + OFstatic_cast(double, maxvalue) + 1) / 2;
00310 width = OFstatic_cast(double, maxvalue) - OFstatic_cast(double, minvalue) + 1;
00311 return (width > 0);
00312 }
00313 }
00314 }
00315 return 0;
00316 }
00317
00318
00319 protected:
00320
00326 DiMonoPixelTemplate(const DiPixel *pixel,
00327 DiMonoModality *modality)
00328 : DiMonoPixel(pixel, modality),
00329 Data(NULL)
00330 {
00331 MinValue[0] = 0;
00332 MinValue[1] = 0;
00333 MaxValue[0] = 0;
00334 MaxValue[1] = 0;
00335 }
00336
00342 DiMonoPixelTemplate(const DiMonoPixel *pixel,
00343 const unsigned long count)
00344 : DiMonoPixel(pixel, count),
00345 Data(NULL)
00346 {
00347 MinValue[0] = 0;
00348 MinValue[1] = 0;
00349 MaxValue[0] = 0;
00350 MaxValue[1] = 0;
00351 }
00352
00360 void determineMinMax(T minvalue = 0,
00361 T maxvalue = 0,
00362 const int mode = 0x1)
00363 {
00364 if (Data != NULL)
00365 {
00366 if (mode & 0x1)
00367 {
00368 if ((minvalue == 0) && (maxvalue == 0))
00369 {
00370 register T *p = Data;
00371 register T value = *p;
00372 register unsigned long i;
00373 minvalue = value;
00374 maxvalue = value;
00375 for (i = Count; i > 1; --i)
00376 {
00377 value = *(++p);
00378 if (value < minvalue)
00379 minvalue = value;
00380 else if (value > maxvalue)
00381 maxvalue = value;
00382 }
00383 }
00384 MinValue[0] = minvalue;
00385 MaxValue[0] = maxvalue;
00386 MinValue[1] = 0;
00387 MaxValue[1] = 0;
00388 } else {
00389 minvalue = MinValue[0];
00390 maxvalue = MaxValue[0];
00391 }
00392 if (mode & 0x2)
00393 {
00394 register T *p = Data;
00395 register T value;
00396 register int firstmin = 1;
00397 register int firstmax = 1;
00398 register unsigned long i;
00399 for (i = Count; i != 0; --i)
00400 {
00401 value = *(p++);
00402 if ((value > minvalue) && ((value < MinValue[1]) || firstmin))
00403 {
00404 MinValue[1] = value;
00405 firstmin = 0;
00406 }
00407 if ((value < maxvalue) && ((value > MaxValue[1]) || firstmax))
00408 {
00409 MaxValue[1] = value;
00410 firstmax = 0;
00411 }
00412 }
00413 }
00414 }
00415 }
00416
00418 T *Data;
00419
00420
00421 private:
00422
00424 T MinValue[2];
00426 T MaxValue[2];
00427
00428
00429
00430 DiMonoPixelTemplate(const DiMonoPixelTemplate<T> &);
00431 DiMonoPixelTemplate<T> &operator=(const DiMonoPixelTemplate<T> &);
00432 };
00433
00434
00435 #endif
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550