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 "osconfig.h"
00038
#include "ofconsol.h"
00039
#include "ofbmanip.h"
00040
#include "ofcast.h"
00041
00042
#include "dctypes.h"
00043
#include "dcdefine.h"
00044
00045
#include "dimopx.h"
00046
#include "dipxrept.h"
00047
#include "dimomod.h"
00048
#include "diinpx.h"
00049
#include "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
00152 inline void *
getDataArrayPtr()
00153 {
00154
return OFstatic_cast(
void *, &Data);
00155 }
00156
00164 inline int getMinMaxValues(
double &min,
00165
double &max)
const
00166
{
00167 min = MinValue[0];
00168 max = MaxValue[0];
00169
return 1;
00170 }
00171
00180 inline int getMinMaxWindow(
const int idx,
00181
double ¢er,
00182
double &width)
00183 {
00184
int result = 0;
00185
if ((idx >= 0) && (idx <= 1))
00186 {
00187
if ((idx == 1) && (MinValue[1] == 0) && (MaxValue[1] == 0))
00188
determineMinMax(0, 0, 0x2);
00189
00190
00191
00192 center = (OFstatic_cast(
double, MinValue[idx]) + OFstatic_cast(
double, MaxValue[idx]) + 1) / 2;
00193 width = OFstatic_cast(
double, MaxValue[idx]) - OFstatic_cast(
double, MinValue[idx]) + 1;
00194 result = (width > 0);
00195 }
00196
return result;
00197 }
00198
00213 virtual int getRoiWindow(
const unsigned long left_pos,
00214
const unsigned long top_pos,
00215
const unsigned long width,
00216
const unsigned long height,
00217
const unsigned long columns,
00218
const unsigned long rows,
00219
const unsigned long frame,
00220
double &voiCenter,
00221
double &voiWidth)
00222 {
00223
int result = 0;
00224
if ((Data != NULL) && (left_pos < columns) && (top_pos < rows))
00225 {
00226
register T *p = Data + (columns * rows * frame) + (top_pos * columns) + left_pos;
00227
const unsigned long right_pos = (left_pos + width < columns) ? left_pos + width : columns;
00228
const unsigned long bottom = (top_pos + height < rows) ? top_pos + height : rows;
00229
const unsigned long skip_x = left_pos + (columns - right_pos);
00230
register unsigned long x;
00231
register unsigned long y;
00232
register T value = 0;
00233
register T min = *p;
00234
register T max = min;
00235
for (y = top_pos; y < bottom; ++y)
00236 {
00237
for (x = left_pos; x < right_pos; ++x)
00238 {
00239 value = *(p++);
00240
if (value < min)
00241 min = value;
00242
else if (value > max)
00243 max = value;
00244 }
00245 p += skip_x;
00246 }
00247
00248
00249
00250 voiCenter = (OFstatic_cast(
double, min) + OFstatic_cast(
double, max) + 1) / 2;
00251 voiWidth = OFstatic_cast(
double, max) - OFstatic_cast(
double, min) + 1;
00252 result = (width > 0);
00253 }
00254
return result;
00255 }
00256
00265 int getHistogramWindow(
const double thresh,
00266
double ¢er,
00267
double &width)
00268 {
00269
if ((Data != NULL) && (MinValue[0] < MaxValue[0]))
00270 {
00271
const Uint32 count = OFstatic_cast(Uint32, MaxValue[0] - MinValue[0] + 1);
00272 Uint32 *quant =
new Uint32[count];
00273
if (quant != NULL)
00274 {
00275
register unsigned long i;
00276
OFBitmanipTemplate<Uint32>::zeroMem(quant, count);
00277
for (i = 0; i < Count; ++i)
00278 {
00279
if ((Data[i] >= MinValue[0]) && (Data[i] <= MaxValue[0]))
00280 ++quant[OFstatic_cast(Uint32, Data[i] - MinValue[0])];
00281
#ifdef DEBUG
00282
else if (
DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings))
00283 {
00284 ofConsole.lockCerr() <<
"WARNING: invalid value (" << Data[i] <<
") in "
00285 <<
"int DiMonoPixelTemplate<T>::getHistogramWindow() ! " << endl;
00286 ofConsole.unlockCerr();
00287 }
00288
#endif
00289
}
00290
const Uint32 threshvalue = OFstatic_cast(Uint32, thresh * OFstatic_cast(
double, Count));
00291
register Uint32 t = 0;
00292 i = 0;
00293
while ((i < count) && (t < threshvalue))
00294 t += quant[i++];
00295
const T minvalue = (i < count) ? OFstatic_cast(T, MinValue[0] + i) : 0;
00296 t = 0;
00297 i = count;
00298
while ((i > 0) && (t < threshvalue))
00299 t += quant[--i];
00300
const T maxvalue = (i > 0) ? OFstatic_cast(T, MinValue[0] + i) : 0;
00301
delete[] quant;
00302
if (minvalue < maxvalue)
00303 {
00304
00305
00306
00307 center = (OFstatic_cast(
double, minvalue) + OFstatic_cast(
double, maxvalue) + 1) / 2;
00308 width = OFstatic_cast(
double, maxvalue) - OFstatic_cast(
double, minvalue) + 1;
00309
return (width > 0);
00310 }
00311 }
00312 }
00313
return 0;
00314 }
00315
00316
00317
protected:
00318
00324 DiMonoPixelTemplate(
const DiPixel *pixel,
00325
DiMonoModality *modality)
00326 :
DiMonoPixel(pixel, modality),
00327 Data(NULL)
00328 {
00329 MinValue[0] = 0;
00330 MinValue[1] = 0;
00331 MaxValue[0] = 0;
00332 MaxValue[1] = 0;
00333 }
00334
00340 DiMonoPixelTemplate(
const DiMonoPixel *pixel,
00341
const unsigned long count)
00342 :
DiMonoPixel(pixel, count),
00343 Data(NULL)
00344 {
00345 MinValue[0] = 0;
00346 MinValue[1] = 0;
00347 MaxValue[0] = 0;
00348 MaxValue[1] = 0;
00349 }
00350
00358 void determineMinMax(T minvalue = 0,
00359 T maxvalue = 0,
00360
const int mode = 0x1)
00361 {
00362
if (Data != NULL)
00363 {
00364
if (mode & 0x1)
00365 {
00366
if ((minvalue == 0) && (maxvalue == 0))
00367 {
00368
register T *p = Data;
00369
register T value = *p;
00370
register unsigned long i;
00371 minvalue = value;
00372 maxvalue = value;
00373
for (i = Count; i > 1; --i)
00374 {
00375 value = *(++p);
00376
if (value < minvalue)
00377 minvalue = value;
00378
else if (value > maxvalue)
00379 maxvalue = value;
00380 }
00381 }
00382 MinValue[0] = minvalue;
00383 MaxValue[0] = maxvalue;
00384 MinValue[1] = 0;
00385 MaxValue[1] = 0;
00386 }
else {
00387 minvalue = MinValue[0];
00388 maxvalue = MaxValue[0];
00389 }
00390
if (mode & 0x2)
00391 {
00392
register T *p = Data;
00393
register T value;
00394
register int firstmin = 1;
00395
register int firstmax = 1;
00396
register unsigned long i;
00397
for (i = Count; i != 0; --i)
00398 {
00399 value = *(p++);
00400
if ((value > minvalue) && ((value < MinValue[1]) || firstmin))
00401 {
00402 MinValue[1] = value;
00403 firstmin = 0;
00404 }
00405
if ((value < maxvalue) && ((value > MaxValue[1]) || firstmax))
00406 {
00407 MaxValue[1] = value;
00408 firstmax = 0;
00409 }
00410 }
00411 }
00412 }
00413 }
00414
00416 T *Data;
00417
00418
00419
private:
00420
00422 T MinValue[2];
00424 T MaxValue[2];
00425
00426
00427
00428
DiMonoPixelTemplate(
const DiMonoPixelTemplate<T> &);
00429
DiMonoPixelTemplate<T> &operator=(
const DiMonoPixelTemplate<T> &);
00430 };
00431
00432
00433
#endif
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