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 #ifndef DIMOPXT_H
00031 #define DIMOPXT_H
00032
00033 #include "dcmtk/config/osconfig.h"
00034
00035 #include "dcmtk/ofstd/ofbmanip.h"
00036 #include "dcmtk/ofstd/ofcast.h"
00037
00038 #include "dcmtk/dcmimgle/dipxrept.h"
00039 #include "dcmtk/dcmimgle/dimopx.h"
00040 #include "dcmtk/dcmimgle/dimoopx.h"
00041
00042
00043
00044
00045
00046
00049 template<class T>
00050 class DiMonoPixelTemplate
00051 : public DiMonoPixel,
00052 public DiPixelRepresentationTemplate<T>
00053 {
00054
00055 public:
00056
00061 DiMonoPixelTemplate(const unsigned long count)
00062 : DiMonoPixel(count),
00063 Data(NULL)
00064 {
00065 MinValue[0] = 0;
00066 MinValue[1] = 0;
00067 MaxValue[0] = 0;
00068 MaxValue[1] = 0;
00069
00070 Data = new T[Count];
00071 }
00072
00078 DiMonoPixelTemplate(const DiInputPixel *pixel,
00079 DiMonoModality *modality)
00080 : DiMonoPixel(pixel, modality),
00081 Data(NULL)
00082 {
00083 MinValue[0] = 0;
00084 MinValue[1] = 0;
00085 MaxValue[0] = 0;
00086 MaxValue[1] = 0;
00087 }
00088
00094 DiMonoPixelTemplate(DiMonoOutputPixel *pixel,
00095 DiMonoModality *modality)
00096 : DiMonoPixel(pixel, modality),
00097 Data(OFstatic_cast(T *, pixel->getDataPtr()))
00098 {
00099 MinValue[0] = 0;
00100 MinValue[1] = 0;
00101 MaxValue[0] = 0;
00102 MaxValue[1] = 0;
00103 }
00104
00107 virtual ~DiMonoPixelTemplate()
00108 {
00109 delete[] Data;
00110 }
00111
00116 inline EP_Representation getRepresentation() const
00117 {
00118 return DiPixelRepresentationTemplate<T>::getRepresentation();
00119 }
00120
00125 inline const void *getData() const
00126 {
00127 return OFstatic_cast(const void *, Data);
00128 }
00129
00134 inline void *getDataPtr()
00135 {
00136 return OFstatic_cast(void *, Data);
00137 }
00138
00145 inline void *getDataArrayPtr()
00146 {
00147 return OFstatic_cast(void *, &Data);
00148 }
00149
00157 inline int getMinMaxValues(double &min,
00158 double &max) const
00159 {
00160 min = MinValue[0];
00161 max = MaxValue[0];
00162 return 1;
00163 }
00164
00173 inline int getMinMaxWindow(const int idx,
00174 double ¢er,
00175 double &width)
00176 {
00177 int result = 0;
00178 if ((idx >= 0) && (idx <= 1))
00179 {
00180 if ((idx == 1) && (MinValue[1] == 0) && (MaxValue[1] == 0))
00181 determineMinMax(0, 0, 0x2);
00182
00183
00184
00185 center = (OFstatic_cast(double, MinValue[idx]) + OFstatic_cast(double, MaxValue[idx]) + 1) / 2;
00186 width = OFstatic_cast(double, MaxValue[idx]) - OFstatic_cast(double, MinValue[idx]) + 1;
00187 result = (width > 0);
00188 }
00189 return result;
00190 }
00191
00206 virtual int getRoiWindow(const unsigned long left_pos,
00207 const unsigned long top_pos,
00208 const unsigned long width,
00209 const unsigned long height,
00210 const unsigned long columns,
00211 const unsigned long rows,
00212 const unsigned long frame,
00213 double &voiCenter,
00214 double &voiWidth)
00215 {
00216 int result = 0;
00217 if ((Data != NULL) && (left_pos < columns) && (top_pos < rows))
00218 {
00219 register T *p = Data + (columns * rows * frame) + (top_pos * columns) + left_pos;
00220 const unsigned long right_pos = (left_pos + width < columns) ? left_pos + width : columns;
00221 const unsigned long bottom = (top_pos + height < rows) ? top_pos + height : rows;
00222 const unsigned long skip_x = left_pos + (columns - right_pos);
00223 register unsigned long x;
00224 register unsigned long y;
00225 register T value = 0;
00226 register T min = *p;
00227 register T max = min;
00228 for (y = top_pos; y < bottom; ++y)
00229 {
00230 for (x = left_pos; x < right_pos; ++x)
00231 {
00232 value = *(p++);
00233 if (value < min)
00234 min = value;
00235 else if (value > max)
00236 max = value;
00237 }
00238 p += skip_x;
00239 }
00240
00241
00242
00243 voiCenter = (OFstatic_cast(double, min) + OFstatic_cast(double, max) + 1) / 2;
00244 voiWidth = OFstatic_cast(double, max) - OFstatic_cast(double, min) + 1;
00245 result = (width > 0);
00246 }
00247 return result;
00248 }
00249
00258 int getHistogramWindow(const double thresh,
00259 double ¢er,
00260 double &width)
00261 {
00262 if ((Data != NULL) && (MinValue[0] < MaxValue[0]))
00263 {
00264 const Uint32 count = OFstatic_cast(Uint32, MaxValue[0] - MinValue[0] + 1);
00265 Uint32 *quant = new Uint32[count];
00266 if (quant != NULL)
00267 {
00268 register unsigned long i;
00269 OFBitmanipTemplate<Uint32>::zeroMem(quant, count);
00270 for (i = 0; i < Count; ++i)
00271 {
00272 if ((Data[i] >= MinValue[0]) && (Data[i] <= MaxValue[0]))
00273 ++quant[OFstatic_cast(Uint32, Data[i] - MinValue[0])];
00274 #ifdef DEBUG
00275 else
00276 DCMIMGLE_WARN("invalid value (" << Data[i] << ") in DiMonoPixelTemplate<T>::getHistogramWindow()");
00277 #endif
00278 }
00279 const Uint32 threshvalue = OFstatic_cast(Uint32, thresh * OFstatic_cast(double, Count));
00280 register Uint32 t = 0;
00281 i = 0;
00282 while ((i < count) && (t < threshvalue))
00283 t += quant[i++];
00284 const T minvalue = (i < count) ? OFstatic_cast(T, MinValue[0] + i) : 0;
00285 t = 0;
00286 i = count;
00287 while ((i > 0) && (t < threshvalue))
00288 t += quant[--i];
00289 const T maxvalue = (i > 0) ? OFstatic_cast(T, MinValue[0] + i) : 0;
00290 delete[] quant;
00291 if (minvalue < maxvalue)
00292 {
00293
00294
00295
00296 center = (OFstatic_cast(double, minvalue) + OFstatic_cast(double, maxvalue) + 1) / 2;
00297 width = OFstatic_cast(double, maxvalue) - OFstatic_cast(double, minvalue) + 1;
00298 return (width > 0);
00299 }
00300 }
00301 }
00302 return 0;
00303 }
00304
00305
00306 protected:
00307
00313 DiMonoPixelTemplate(const DiPixel *pixel,
00314 DiMonoModality *modality)
00315 : DiMonoPixel(pixel, modality),
00316 Data(NULL)
00317 {
00318 MinValue[0] = 0;
00319 MinValue[1] = 0;
00320 MaxValue[0] = 0;
00321 MaxValue[1] = 0;
00322 }
00323
00329 DiMonoPixelTemplate(const DiMonoPixel *pixel,
00330 const unsigned long count)
00331 : DiMonoPixel(pixel, count),
00332 Data(NULL)
00333 {
00334 MinValue[0] = 0;
00335 MinValue[1] = 0;
00336 MaxValue[0] = 0;
00337 MaxValue[1] = 0;
00338 }
00339
00347 void determineMinMax(T minvalue = 0,
00348 T maxvalue = 0,
00349 const int mode = 0x1)
00350 {
00351 if (Data != NULL)
00352 {
00353 if (mode & 0x1)
00354 {
00355 if ((minvalue == 0) && (maxvalue == 0))
00356 {
00357 DCMIMGLE_DEBUG("determining global minimum and maximum pixel values for monochrome image");
00358 register T *p = Data;
00359 register T value = *p;
00360 register unsigned long i;
00361 minvalue = value;
00362 maxvalue = value;
00363 for (i = Count; i > 1; --i)
00364 {
00365 value = *(++p);
00366 if (value < minvalue)
00367 minvalue = value;
00368 else if (value > maxvalue)
00369 maxvalue = value;
00370 }
00371 }
00372 MinValue[0] = minvalue;
00373 MaxValue[0] = maxvalue;
00374 MinValue[1] = 0;
00375 MaxValue[1] = 0;
00376 } else {
00377 minvalue = MinValue[0];
00378 maxvalue = MaxValue[0];
00379 }
00380 if (mode & 0x2)
00381 {
00382 DCMIMGLE_DEBUG("determining next minimum and maximum pixel values for monochrome image");
00383 register T *p = Data;
00384 register T value;
00385 register int firstmin = 1;
00386 register int firstmax = 1;
00387 register unsigned long i;
00388 for (i = Count; i != 0; --i)
00389 {
00390 value = *(p++);
00391 if ((value > minvalue) && ((value < MinValue[1]) || firstmin))
00392 {
00393 MinValue[1] = value;
00394 firstmin = 0;
00395 }
00396 if ((value < maxvalue) && ((value > MaxValue[1]) || firstmax))
00397 {
00398 MaxValue[1] = value;
00399 firstmax = 0;
00400 }
00401 }
00402 }
00403 }
00404 }
00405
00407 T *Data;
00408
00409
00410 private:
00411
00413 T MinValue[2];
00415 T MaxValue[2];
00416
00417
00418
00419 DiMonoPixelTemplate(const DiMonoPixelTemplate<T> &);
00420 DiMonoPixelTemplate<T> &operator=(const DiMonoPixelTemplate<T> &);
00421 };
00422
00423
00424 #endif
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
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
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562