/usr/include/dcmtk/dcmimgle/dimoopxt.h is in libdcmtk2-dev 3.6.0-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 | /*
*
* Copyright (C) 1996-2010, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmimgle
*
* Author: Joerg Riesmeier
*
* Purpose: DicomMonoOutputPixelTemplate (Header)
*
* Last Update: $Author: joergr $
* Update Date: $Date: 2010-10-28 10:58:38 $
* CVS/RCS Revision: $Revision: 1.54 $
* Status: $State: Exp $
*
* CVS/RCS Log at end of file
*
*/
#ifndef DIMOOPXT_H
#define DIMOOPXT_H
#include "dcmtk/config/osconfig.h"
#include "dcmtk/ofstd/ofcast.h"
#include "dcmtk/ofstd/ofbmanip.h"
#include "dcmtk/dcmimgle/dimoopx.h"
#include "dcmtk/dcmimgle/dimopx.h"
#include "dcmtk/dcmimgle/diluptab.h"
#include "dcmtk/dcmimgle/diovlay.h"
#include "dcmtk/dcmimgle/dipxrept.h"
#include "dcmtk/dcmimgle/didispfn.h"
#include "dcmtk/dcmimgle/didislut.h"
#ifdef PASTEL_COLOR_OUTPUT
#include "dimcopxt.h"
#endif
#define INCLUDE_CMATH
#include "dcmtk/ofstd/ofstdinc.h"
/*---------------------*
* class declaration *
*---------------------*/
/** Template class to create monochrome output data
*/
template<class T1, class T2, class T3>
class DiMonoOutputPixelTemplate
: public DiMonoOutputPixel,
public DiPixelRepresentationTemplate<T3>
{
public:
/** constructor
*
** @param buffer storage area for the output pixel data (optional, maybe NULL)
* @param pixel pointer to intermediate pixel representation
* @param overlays array of overlay management objects
* @param vlut VOI LUT (optional, maybe NULL)
* @param plut presentation LUT (optional, maybe NULL)
* @param disp display function (optional, maybe NULL)
* @param vfunc VOI LUT function (optional)
* @param center window center (optional, invalid if 'width' < 1)
* @param width window width (optional, invalid if < 1)
* @param low lowest pixel value for the output data (e.g. 0)
* @param high highest pixel value for the output data (e.g. 255)
* @param columns image's width (in pixels)
* @param rows image's height
* @param frame frame to be rendered
* (#)param frames total number of frames present in intermediate representation
* @param pastel flag indicating whether to use not only 'real' grayscale values (optional, experimental)
*/
DiMonoOutputPixelTemplate(void *buffer,
const DiMonoPixel *pixel,
DiOverlay *overlays[2],
const DiLookupTable *vlut,
const DiLookupTable *plut,
DiDisplayFunction *disp,
const EF_VoiLutFunction vfunc,
const double center,
const double width,
const Uint32 low,
const Uint32 high,
const Uint16 columns,
const Uint16 rows,
const unsigned long frame,
#ifdef PASTEL_COLOR_OUTPUT
const unsigned long frames,
#else
const unsigned long /*frames*/,
#endif
const int pastel = 0)
: DiMonoOutputPixel(pixel, OFstatic_cast(unsigned long, columns) * OFstatic_cast(unsigned long, rows), frame,
OFstatic_cast(unsigned long, fabs(OFstatic_cast(double, high - low)))),
Data(NULL),
DeleteData(buffer == NULL),
ColorData(NULL)
{
if ((pixel != NULL) && (Count > 0) && (FrameSize >= Count))
{
if (pastel)
#ifdef PASTEL_COLOR_OUTPUT
color(buffer, pixel, frame, frames);
#else
DCMIMGLE_ERROR("pastel color output not supported");
#endif
else
{
DCMIMGLE_TRACE("monochrome output image - columns: " << columns << ", rows: " << rows << ", frame: " << frame);
DCMIMGLE_TRACE("monochrome output values - low: " << OFstatic_cast(unsigned long, low) << ", high: "
<< OFstatic_cast(unsigned long, high) << ((low > high) ? " (inverted)" : ""));
Data = OFstatic_cast(T3 *, buffer);
if ((vlut != NULL) && (vlut->isValid())) // valid VOI LUT ?
voilut(pixel, frame * FrameSize, vlut, plut, disp, OFstatic_cast(T3, low), OFstatic_cast(T3, high));
else
{
if (width < 1) // no valid window according to supplement 33
nowindow(pixel, frame * FrameSize, plut, disp, OFstatic_cast(T3, low), OFstatic_cast(T3, high));
else if (vfunc == EFV_Sigmoid)
sigmoid(pixel, frame * FrameSize, plut, disp, center, width, OFstatic_cast(T3, low), OFstatic_cast(T3, high));
else // linear
window(pixel, frame * FrameSize, plut, disp, center, width, OFstatic_cast(T3, low), OFstatic_cast(T3, high));
}
overlay(overlays, disp, columns, rows, frame); // add (visible) overlay planes to output bitmap
}
}
}
/** destructor
*/
virtual ~DiMonoOutputPixelTemplate()
{
if (DeleteData)
delete[] Data;
delete ColorData;
}
/** get integer representation of output data
*
** @return integer representation
*/
inline EP_Representation getRepresentation() const
{
return DiPixelRepresentationTemplate<T3>::getRepresentation();
}
/** get size of one pixel / item in the pixel array
*
** @return item size
*/
inline size_t getItemSize() const
{
return (ColorData != NULL) ? ColorData->getItemSize() : sizeof(T3);
}
/** get pointer to output pixel data
*
** @return pointer to pixel data
*/
inline const void *getData() const
{
return (ColorData != NULL) ? ColorData->getData() : OFstatic_cast(const void *, Data);
}
/** get pointer to output pixel data
*
** @return pointer to pixel data
*/
virtual void *getDataPtr()
{
return (ColorData != NULL) ? ColorData->getDataPtr() : OFstatic_cast(void *, Data);
}
/** remove reference to (internally handled) pixel data (abstract)
*/
inline void removeDataReference()
{
Data = NULL;
DeleteData = 0;
}
/** write pixel data of selected frame to PPM/ASCII file
*
** @param stream open C++ output stream
*
** @return status, true if successful, false otherwise
*/
inline int writePPM(STD_NAMESPACE ostream& stream) const
{
if (Data != NULL)
{
register unsigned long i;
for (i = 0; i < FrameSize; ++i)
stream << OFstatic_cast(unsigned long, Data[i]) << " "; // typecast to resolve problems with 'char'
return 1;
}
if (ColorData != NULL)
return ColorData->writePPM(stream);
return 0;
}
/** write pixel data of selected frame to PPM/ASCII file
*
** @param stream open C file stream
*
** @return status, true if successful, false otherwise
*/
inline int writePPM(FILE *stream) const
{
if (Data != NULL)
{
register unsigned long i;
for (i = 0; i < FrameSize; ++i)
fprintf(stream, "%lu ", OFstatic_cast(unsigned long, Data[i]));
return 1;
}
if (ColorData != NULL)
return ColorData->writePPM(stream);
return 0;
}
protected:
/** examine which pixel values are actually used
*/
inline void determineUsedValues()
{
if ((UsedValues == NULL) && (MaxValue > 0) && (MaxValue < MAX_TABLE_ENTRY_COUNT))
{
UsedValues = new Uint8[MaxValue + 1];
if (UsedValues != NULL)
{
OFBitmanipTemplate<Uint8>::zeroMem(UsedValues, MaxValue + 1); // initialize array
register const T3 *p = Data;
register Uint8 *q = UsedValues;
register unsigned long i;
for (i = Count; i != 0; --i)
*(q + *(p++)) = 1; // mark used entries
}
}
}
private:
/** create a display LUT with the specified number of input bits
*
** @param dlut reference to storage area where the display LUT should be stored
* @param disp pointer to object describing the current display function
* @param bits number of bits defining the input width of the display LUT
*/
inline void createDisplayLUT(const DiDisplayLUT *&dlut,
DiDisplayFunction *disp,
const int bits)
{
if ((disp != NULL) && (disp->isValid()))
{ // create Display LUT
dlut = disp->getLookupTable(bits);
if ((dlut != NULL) && (dlut->isValid())) // LUT is valid
{
DCMIMGLE_DEBUG("using display transformation");
} else {
DCMIMGLE_WARN("can't create display LUT ... ignoring display transformation");
dlut = NULL;
}
}
}
/** initialize an optimization LUT if the optimization criteria is fulfilled
*
** @param lut reference to storage area where the optimization LUT should be stored
* @param ocnt number of entries for the optimization LUT
*/
inline int initOptimizationLUT(T3 *&lut,
const unsigned long ocnt)
{
int result = 0;
if ((sizeof(T1) <= 2) && (Count > 3 * ocnt)) // optimization criteria
{ // use LUT for optimization
lut = new T3[ocnt];
if (lut != NULL)
{
DCMIMGLE_DEBUG("using optimized routine with additional LUT (" << ocnt << " entries)");
result = 1;
}
}
return result;
}
#ifdef PASTEL_COLOR_OUTPUT
void color(void *buffer, // create true color pastel image
const DiMonoPixel *inter,
const unsigned long frame,
const unsigned long frames)
{
ColorData = new DiMonoColorOutputPixelTemplate<T1, T3>(buffer, inter, frame, frames);
if (ColorData != NULL)
DCMIMGLE_DEBUG(">>> COLOR <<<");
}
#endif
/** apply the currently active VOI LUT to the output data
*
** @param inter pointer to intermediate pixel representation
* @param start offset of the first pixel to be processed
* @param vlut VOI LUT
* @param plut presentation LUT (optional, maybe NULL)
* @param disp display function (optional, maybe NULL)
* @param low lowest pixel value for the output data (e.g. 0)
* @param high highest pixel value for the output data (e.g. 255)
*/
void voilut(const DiMonoPixel *inter,
const Uint32 start,
const DiLookupTable *vlut,
const DiLookupTable *plut,
DiDisplayFunction *disp,
const T3 low,
const T3 high)
{
const T1 *pixel = OFstatic_cast(const T1 *, inter->getData());
if ((pixel != NULL) && (vlut != NULL))
{
if (Data == NULL)
Data = new T3[FrameSize];
if (Data != NULL)
{
DCMIMGLE_DEBUG("applying VOI transformation with LUT (" << vlut->getCount() << " entries)");
const DiDisplayLUT *dlut = NULL;
const double minvalue = vlut->getMinValue();
const double outrange = OFstatic_cast(double, high) - OFstatic_cast(double, low) + 1;
register unsigned long i;
if (minvalue == vlut->getMaxValue()) // LUT has only one entry or all entries are equal
{
T3 value;
if ((plut != NULL) && (plut->isValid())) // has presentation LUT
{
DCMIMGLE_DEBUG("applying presentation LUT transformation");
createDisplayLUT(dlut, disp, plut->getBits());
const Uint32 value2 = OFstatic_cast(Uint32, (minvalue / OFstatic_cast(double, vlut->getAbsMaxRange())) * plut->getCount());
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #1 - UNTESTED");
if (low > high) // invers
value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, plut->getAbsMaxRange() - plut->getValue(value2) - 1)));
else // normal
value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, plut->getValue(value2))));
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #2");
value = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * outrange / OFstatic_cast(double, plut->getAbsMaxRange()));
}
} else { // has no presentation LUT
createDisplayLUT(dlut, disp, vlut->getBits());
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #3 - UNTESTED");
if (low > high) // invers
value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, vlut->getAbsMaxRange() - minvalue - 1)));
else // normal
value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, minvalue)));
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #4");
value = OFstatic_cast(T3, OFstatic_cast(double, low) + (minvalue / OFstatic_cast(double, vlut->getAbsMaxRange())) * outrange);
}
}
OFBitmanipTemplate<T3>::setMem(Data, value, Count); // set output pixels to LUT value
} else {
register T2 value = 0;
const T2 absmin = OFstatic_cast(T2, inter->getAbsMinimum());
const T2 firstentry = vlut->getFirstEntry(value); // choose signed/unsigned method
const T2 lastentry = vlut->getLastEntry(value);
const unsigned long ocnt = OFstatic_cast(unsigned long, inter->getAbsMaxRange()); // number of LUT entries
register const T1 *p = pixel + start;
register T3 *q = Data;
T3 *lut = NULL;
if ((plut != NULL) && (plut->isValid())) // has presentation LUT
{
DCMIMGLE_DEBUG("applying presentation LUT transformation");
createDisplayLUT(dlut, disp, plut->getBits());
register Uint32 value2; // presentation LUT is always unsigned
const Uint32 pcnt = plut->getCount();
const double gradient1 = OFstatic_cast(double, pcnt) / OFstatic_cast(double, vlut->getAbsMaxRange());
const Uint32 firstvalue = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getFirstValue()) * gradient1);
const Uint32 lastvalue = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getLastValue()) * gradient1);
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #5");
if (low > high) // inverse
{
const Uint16 maxvalue = OFstatic_cast(Uint16, plut->getAbsMaxRange() - 1);
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(T2, i) + absmin;
if (value <= firstentry)
value2 = firstvalue;
else if (value >= lastentry)
value2 = lastvalue;
else
value2 = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getValue(value)) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, maxvalue - plut->getValue(value2))));
}
} else { // normal
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(T2, i) + absmin;
if (value <= firstentry)
value2 = firstvalue;
else if (value >= lastentry)
value2 = lastvalue;
else
value2 = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getValue(value)) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(plut->getValue(value2)));
}
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #6");
const double gradient2 = outrange / OFstatic_cast(double, plut->getAbsMaxRange());
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(T2, i) + absmin;
if (value <= firstentry)
value2 = firstvalue;
else if (value >= lastentry)
value2 = lastvalue;
else
value2 = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getValue(value)) * gradient1);
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * gradient2);
}
}
const T3 *lut0 = lut - OFstatic_cast(T2, inter->getAbsMinimum()); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #7");
if (low > high) // inverse
{
const Uint16 maxvalue = OFstatic_cast(Uint16, vlut->getAbsMaxRange() - 1);
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(T2, *(p++)); // pixel value
if (value <= firstentry)
value2 = firstvalue;
else if (value >= lastentry)
value2 = lastvalue;
else
value2 = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getValue(value)) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, maxvalue - plut->getValue(value2))));
}
} else { // normal
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(T2, *(p++)); // pixel value
if (value <= firstentry)
value2 = firstvalue;
else if (value >= lastentry)
value2 = lastvalue;
else
value2 = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getValue(value)) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(plut->getValue(value2)));
}
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #8");
const double gradient2 = outrange / OFstatic_cast(double, plut->getAbsMaxRange());
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(T2, *(p++)); // pixel value
if (value <= firstentry)
value2 = firstvalue;
else if (value >= lastentry)
value2 = lastvalue;
else
value2 = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getValue(value)) * gradient1);
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * gradient2);
}
}
}
} else { // has no presentation LUT
createDisplayLUT(dlut, disp, vlut->getBits());
const double gradient = outrange / OFstatic_cast(double, vlut->getAbsMaxRange());
const T3 firstvalue = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, vlut->getFirstValue()) * gradient);
const T3 lastvalue = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, vlut->getLastValue()) * gradient);
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #9");
if (low > high) // inverse
{
const Uint16 maxvalue = OFstatic_cast(Uint16, vlut->getAbsMaxRange() - 1);
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(T2, i) + absmin;
if (value < firstentry)
value = firstentry;
else if (value > lastentry)
value = lastentry;
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, maxvalue - vlut->getValue(value))));
}
} else { // normal
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(T2, i) + absmin;
if (value < firstentry)
value = firstentry;
else if (value > lastentry)
value = lastentry;
*(q++) = OFstatic_cast(T3, dlut->getValue(vlut->getValue(value)));
}
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #10");
for (i = 0; i < ocnt; ++i) // calculating LUT entries
{
value = OFstatic_cast(T2, i) + absmin;
if (value <= firstentry)
*(q++) = firstvalue;
else if (value >= lastentry)
*(q++) = lastvalue;
else
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, vlut->getValue(value)) * gradient);
}
}
const T3 *lut0 = lut - OFstatic_cast(T2, inter->getAbsMinimum()); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #11");
if (low > high) // inverse
{
const Uint16 maxvalue = OFstatic_cast(Uint16, vlut->getAbsMaxRange() - 1);
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(T2, *(p++));
if (value < firstentry)
value = firstentry;
else if (value > lastentry)
value = lastentry;
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, maxvalue - vlut->getValue(value))));
}
} else { // normal
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(T2, *(p++));
if (value < firstentry)
value = firstentry;
else if (value > lastentry)
value = lastentry;
*(q++) = OFstatic_cast(T3, dlut->getValue(vlut->getValue(value)));
}
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LUT #12");
for (i = 0; i < Count; ++i)
{
value = OFstatic_cast(T2, *(p++));
if (value <= firstentry)
*(q++) = firstvalue;
else if (value >= lastentry)
*(q++) = lastvalue;
else
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, vlut->getValue(value)) * gradient);
}
}
}
}
delete[] lut;
}
if (Count < FrameSize)
OFBitmanipTemplate<T3>::zeroMem(Data + Count, FrameSize - Count); // set remaining pixels of frame to zero
}
} else
Data = NULL;
}
/** perform linear scaling to the output data (no windowing)
*
** @param inter pointer to intermediate pixel representation
* @param start offset of the first pixel to be processed
* @param plut presentation LUT (optional, maybe NULL)
* @param disp display function (optional, maybe NULL)
* @param low lowest pixel value for the output data (e.g. 0)
* @param high highest pixel value for the output data (e.g. 255)
*/
void nowindow(const DiMonoPixel *inter,
const Uint32 start,
const DiLookupTable *plut,
DiDisplayFunction *disp,
const T3 low,
const T3 high)
{
const DiDisplayLUT *dlut = NULL;
const T1 *pixel = OFstatic_cast(const T1 *, inter->getData());
if (pixel != NULL)
{
if (Data == NULL) // create new output buffer
Data = new T3[FrameSize];
if (Data != NULL)
{
DCMIMGLE_DEBUG("applying no VOI transformation (linear scaling)");
const double absmin = inter->getAbsMinimum();
const double absmax = inter->getAbsMaximum();
const double outrange = OFstatic_cast(double, high) - OFstatic_cast(double, low) + 1;
const unsigned long ocnt = OFstatic_cast(unsigned long, inter->getAbsMaxRange()); // number of LUT entries
register const T1 *p = pixel + start;
register T3 *q = Data;
register unsigned long i;
T3 *lut = NULL;
if ((plut != NULL) && (plut->isValid())) // has presentation LUT
{
DCMIMGLE_DEBUG("applying presentation LUT transformation");
createDisplayLUT(dlut, disp, plut->getBits());
register Uint32 value; // presentation LUT is always unsigned
const double gradient1 = OFstatic_cast(double, plut->getCount()) / inter->getAbsMaxRange();
const double gradient2 = outrange / OFstatic_cast(double, plut->getAbsMaxRange());
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #1");
if (low > high) // inverse
{
const Uint16 maxvalue = OFstatic_cast(Uint16, plut->getAbsMaxRange() - 1);
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(Uint32, OFstatic_cast(double, i) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, maxvalue - plut->getValue(value))));
}
} else { // normal
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(Uint32, OFstatic_cast(double, i) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(plut->getValue(value)));
}
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #2");
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(Uint32, OFstatic_cast(double, i) * gradient1);
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value)) * gradient2);
}
}
const T3 *lut0 = lut - OFstatic_cast(T2, inter->getAbsMinimum()); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #3");
if (low > high) // inverse
{
const Uint16 maxvalue = OFstatic_cast(Uint16, plut->getAbsMaxRange() - 1);
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(Uint32, (OFstatic_cast(double, *(p++)) - absmin) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, maxvalue - plut->getValue(value))));
}
} else { // normal
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(Uint32, (OFstatic_cast(double, *(p++)) - absmin) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(plut->getValue(value)));
}
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #4");
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(Uint32, (OFstatic_cast(double, *(p++)) - absmin) * gradient1);
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value)) * gradient2);
}
}
}
} else { // has no presentation LUT
createDisplayLUT(dlut, disp, inter->getBits());
register const double gradient = outrange / (inter->getAbsMaxRange());
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #5");
if (low > high) // inverse
{
for (i = ocnt; i != 0; --i) // calculating LUT entries
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, i - 1)));
} else { // normal
for (i = 0; i < ocnt; ++i) // calculating LUT entries
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, i)));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #6");
for (i = 0; i < ocnt; ++i) // calculating LUT entries
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, i) * gradient);
}
const T3 *lut0 = lut - OFstatic_cast(T2, inter->getAbsMinimum()); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #7");
if (low > high) // inverse
{
for (i = Count; i != 0; --i)
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, absmax - (OFstatic_cast(double, *(p++)) - absmin))));
} else { // normal
for (i = Count; i != 0; --i)
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, OFstatic_cast(double, *(p++)) - absmin)));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI NONE #8");
for (i = Count; i != 0; --i)
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + (OFstatic_cast(double, *(p++)) - absmin) * gradient);
}
}
}
delete[] lut;
if (Count < FrameSize)
OFBitmanipTemplate<T3>::zeroMem(Data + Count, FrameSize - Count); // set remaining pixels of frame to zero
}
} else
Data = NULL;
}
/** apply the currently active sigmoid VOI window to the output data
*
** @param inter pointer to intermediate pixel representation
* @param start offset of the first pixel to be processed
* @param plut presentation LUT (optional, maybe NULL)
* @param disp display function (optional, maybe NULL)
* @param center window center
* @param width window width (>= 1)
* @param low lowest pixel value for the output data (e.g. 0)
* @param high highest pixel value for the output data (e.g. 255)
*/
void sigmoid(const DiMonoPixel *inter,
const Uint32 start,
const DiLookupTable *plut,
DiDisplayFunction *disp,
const double center,
const double width,
const T3 low,
const T3 high)
{
const T1 *pixel = OFstatic_cast(const T1 *, inter->getData());
if (pixel != NULL)
{
if (Data == NULL)
Data = new T3[FrameSize]; // create new output buffer
if (Data != NULL)
{
DCMIMGLE_DEBUG("applying sigmoid VOI transformation with window center = " << center << ", width = " << width);
const DiDisplayLUT *dlut = NULL;
const double absmin = inter->getAbsMinimum();
const double outrange = OFstatic_cast(double, high) - OFstatic_cast(double, low); // output range
const unsigned long ocnt = OFstatic_cast(unsigned long, inter->getAbsMaxRange()); // number of LUT entries
register const T1 *p = pixel + start;
register T3 *q = Data;
register unsigned long i;
register double value;
T3 *lut = NULL;
if ((plut != NULL) && (plut->isValid())) // has presentation LUT
{
DCMIMGLE_DEBUG("applying presentation LUT transformation");
createDisplayLUT(dlut, disp, plut->getBits());
register Uint32 value2; // presentation LUT is always unsigned
const double plutcnt_1 = OFstatic_cast(double, plut->getCount() - 1);
const double plutmax_1 = OFstatic_cast(double, plut->getAbsMaxRange() - 1);
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #1");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double offset = (low > high) ? maxvalue : 0;
const double gradient = (low > high) ? (-maxvalue / plutmax_1) : (maxvalue / plutmax_1);
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(double, i) + absmin;
value2 = OFstatic_cast(Uint32, plutcnt_1 / (1 + exp(-4 * (value - center) / width)));
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + OFstatic_cast(double, plut->getValue(value2)) * gradient)));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #2");
const double gradient = outrange / plutmax_1;
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(double, i) + absmin;
value2 = OFstatic_cast(Uint32, plutcnt_1 / (1 + exp(-4 * (value - center) / width)));
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * gradient);
}
}
const T3 *lut0 = lut - OFstatic_cast(T2, absmin); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #3");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double offset = (low > high) ? maxvalue : 0;
const double gradient = (low > high) ? (-maxvalue / plutmax_1) : (maxvalue / plutmax_1);
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(double, *(p++));
value2 = OFstatic_cast(Uint32, plutcnt_1 / (1 + exp(-4 * (value - center) / width)));
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + OFstatic_cast(double, plut->getValue(value2)) * gradient)));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #4");
const double gradient = outrange / plutmax_1;
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(double, *(p++));
value2 = OFstatic_cast(Uint32, plutcnt_1 / (1 + exp(-4 * (value - center) / width)));
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * gradient);
}
}
}
} else { // has no presentation LUT
createDisplayLUT(dlut, disp, bitsof(T1));
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #5");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double outrange2 = (low > high) ? -maxvalue : maxvalue;
const double offset = (low > high) ? maxvalue : 0;
for (i = 0; i < ocnt; ++i) // calculating LUT entries
{
value = OFstatic_cast(double, i) + absmin;
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + outrange2 / (1 + exp(-4 * (value - center) / width)))));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #6");
for (i = 0; i < ocnt; ++i) // calculating LUT entries
{
value = OFstatic_cast(double, i) + absmin;
*(q++) = OFstatic_cast(T3, outrange / (1 + exp(-4 * (value - center) / width)));
}
}
const T3 *lut0 = lut - OFstatic_cast(T2, absmin); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #7");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double outrange2 = (low > high) ? -maxvalue : maxvalue;
const double offset = (low > high) ? maxvalue : 0;
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(double, *(p++));
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + outrange2 / (1 + exp(-4 * (value - center) / width)))));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI SIGMOID #8");
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(double, *(p++));
*(q++) = OFstatic_cast(T3, outrange / (1 + exp(-4 * (value - center) / width)));
}
}
}
}
delete[] lut;
if (Count < FrameSize)
OFBitmanipTemplate<T3>::zeroMem(Data + Count, FrameSize - Count); // set remaining pixels of frame to zero
}
} else
Data = NULL;
}
/** apply the currently active linear VOI window to the output data
*
** @param inter pointer to intermediate pixel representation
* @param start offset of the first pixel to be processed
* @param plut presentation LUT (optional, maybe NULL)
* @param disp display function (optional, maybe NULL)
* @param center window center
* @param width window width (>= 1)
* @param low lowest pixel value for the output data (e.g. 0)
* @param high highest pixel value for the output data (e.g. 255)
*/
void window(const DiMonoPixel *inter,
const Uint32 start,
const DiLookupTable *plut,
DiDisplayFunction *disp,
const double center,
const double width,
const T3 low,
const T3 high)
{
const T1 *pixel = OFstatic_cast(const T1 *, inter->getData());
if (pixel != NULL)
{
if (Data == NULL)
Data = new T3[FrameSize]; // create new output buffer
if (Data != NULL)
{
DCMIMGLE_DEBUG("applying linear VOI transformation with window center = " << center << ", width = " << width);
const DiDisplayLUT *dlut = NULL;
const double absmin = inter->getAbsMinimum();
const double width_1 = width - 1;
const double leftBorder = center - 0.5 - width_1 / 2; // window borders, according to supplement 33
const double rightBorder = center - 0.5 + width_1 / 2;
const double outrange = OFstatic_cast(double, high) - OFstatic_cast(double, low); // output range
const unsigned long ocnt = OFstatic_cast(unsigned long, inter->getAbsMaxRange()); // number of LUT entries
register const T1 *p = pixel + start;
register T3 *q = Data;
register unsigned long i;
register double value;
T3 *lut = NULL;
if ((plut != NULL) && (plut->isValid())) // has presentation LUT
{
DCMIMGLE_DEBUG("applying presentation LUT transformation");
createDisplayLUT(dlut, disp, plut->getBits());
register Uint32 value2; // presentation LUT is always unsigned
const Uint32 pcnt = plut->getCount();
const double plutmax_1 = OFstatic_cast(double, plut->getAbsMaxRange()) - 1;
const double gradient1 = (width_1 == 0) ? 0 : OFstatic_cast(double, pcnt - 1) / width_1;
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #1");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double offset = (low > high) ? maxvalue : 0;
const double gradient2 = (low > high) ? (-maxvalue / plutmax_1) : (maxvalue / plutmax_1);
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(double, i) + absmin; // pixel value
if (value <= leftBorder)
value2 = 0; // first LUT index
else if (value > rightBorder)
value2 = pcnt - 1; // last LUT index
else
value2 = OFstatic_cast(Uint32, (value - leftBorder) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + OFstatic_cast(double, plut->getValue(value2)) * gradient2)));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #2");
const double gradient2 = outrange / plutmax_1;
for (i = 0; i < ocnt; ++i)
{
value = OFstatic_cast(double, i) + absmin; // pixel value
if (value <= leftBorder)
value2 = 0; // first LUT index
else if (value > rightBorder)
value2 = pcnt - 1; // last LUT index
else
value2 = OFstatic_cast(Uint32, (value - leftBorder) * gradient1);
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * gradient2);
}
}
const T3 *lut0 = lut - OFstatic_cast(T2, absmin); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #3");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double offset = (low > high) ? maxvalue : 0;
const double gradient2 = (low > high) ? (-maxvalue / plutmax_1) : (maxvalue / plutmax_1);
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(double, *(p++)); // pixel value
if (value <= leftBorder)
value2 = 0; // first LUT index
else if (value > rightBorder)
value2 = pcnt - 1; // last LUT index
else
value2 = OFstatic_cast(Uint32, (value - leftBorder) * gradient1);
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + OFstatic_cast(double, plut->getValue(value2)) * gradient2)));
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #4");
const double gradient2 = outrange / plutmax_1;
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(double, *(p++)); // pixel value
if (value <= leftBorder)
value2 = 0; // first LUT index
else if (value > rightBorder)
value2 = pcnt - 1; // last LUT index
else
value2 = OFstatic_cast(Uint32, (value - leftBorder) * gradient1);
*(q++) = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * gradient2);
}
}
}
} else { // has no presentation LUT
createDisplayLUT(dlut, disp, bitsof(T1));
if (initOptimizationLUT(lut, ocnt))
{ // use LUT for optimization
q = lut;
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #5");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double offset = (low > high) ? maxvalue : 0;
const double gradient = (width_1 == 0) ? 0 : ((low > high) ? (-maxvalue / width_1) : (maxvalue / width_1));
for (i = 0; i < ocnt; ++i) // calculating LUT entries
{
value = OFstatic_cast(double, i) + absmin - leftBorder;
if (value < 0) // left border
value = 0;
else if (value > width_1) // right border
value = width_1;
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + value * gradient))); // calculate value
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #6");
const double offset = (width_1 == 0) ? 0 : (high - ((center - 0.5) / width_1 + 0.5) * outrange);
const double gradient = (width_1 == 0) ? 0 : outrange / width_1;
for (i = 0; i < ocnt; ++i) // calculating LUT entries
{
value = OFstatic_cast(double, i) + absmin;
if (value <= leftBorder)
*(q++) = low; // black/white
else if (value > rightBorder)
*(q++) = high; // white/black
else
*(q++) = OFstatic_cast(T3, offset + value * gradient); // gray value
}
}
const T3 *lut0 = lut - OFstatic_cast(T2, absmin); // points to 'zero' entry
q = Data;
for (i = Count; i != 0; --i) // apply LUT
*(q++) = *(lut0 + (*(p++)));
}
if (lut == NULL) // use "normal" transformation
{
if (dlut != NULL) // perform display transformation
{
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #7");
const double maxvalue = OFstatic_cast(double, dlut->getCount() - 1);
const double offset = (low > high) ? maxvalue : 0;
const double gradient = (width_1 == 0) ? 0 : ((low > high) ? (-maxvalue / width_1) : (maxvalue / width_1));
for (i = Count; i != 0; --i) // calculating LUT entries
{
value = OFstatic_cast(double, *(p++)) - leftBorder;
if (value < 0) // left border
value = 0;
else if (value > width_1) // right border
value = width_1;
*(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, offset + value * gradient))); // calculate value
}
} else { // don't use display: invalid or absent
DCMIMGLE_TRACE("monochrome rendering: VOI LINEAR #8");
const double offset = (width_1 == 0) ? 0 : (high - ((center - 0.5) / width_1 + 0.5) * outrange);
const double gradient = (width_1 == 0) ? 0 : outrange / width_1;
for (i = Count; i != 0; --i)
{
value = OFstatic_cast(double, *(p++));
if (value <= leftBorder)
*(q++) = low; // black/white
else if (value > rightBorder)
*(q++) = high; // white/black
else
*(q++) = OFstatic_cast(T3, offset + value * gradient); // gray value
}
}
}
}
delete[] lut;
if (Count < FrameSize)
OFBitmanipTemplate<T3>::zeroMem(Data + Count, FrameSize - Count); // set remaining pixels of frame to zero
}
} else
Data = NULL;
}
/** apply the currently active overlay planes to the output data
*
** @param overlays array of overlay management objects
* @param disp display function (optional, maybe NULL)
* @param columns image's width (in pixels)
* @param rows image's height (in pixels)
* @param frame number of frame to be rendered
*/
void overlay(DiOverlay *overlays[2],
DiDisplayFunction *disp,
const Uint16 columns,
const Uint16 rows,
const unsigned long frame)
{
if ((Data != NULL) && (overlays != NULL))
{
for (unsigned int j = 0; j < 2; ++j)
{
if (overlays[j] != NULL)
{
if (overlays[j]->getCount() > 0)
DCMIMGLE_DEBUG("applying " << ((j == 0) ? "built-in" : "additional") << " overlay planes");
const signed long left_pos = overlays[j]->getLeft();
const signed long top_pos = overlays[j]->getTop();
register DiOverlayPlane *plane;
for (unsigned int i = 0; i < overlays[j]->getCount(); ++i)
{
plane = overlays[j]->getPlane(i);
if ((plane != NULL) && plane->isVisible() && plane->reset(frame))
{
register T3 *q;
register Uint16 x;
register Uint16 y;
const Uint16 xmin = (plane->getLeft(left_pos) > 0) ? plane->getLeft(left_pos) : 0;
const Uint16 ymin = (plane->getTop(top_pos) > 0) ? plane->getTop(top_pos) : 0;
const Uint16 xmax = (plane->getRight(left_pos) < columns) ? plane->getRight(left_pos) : columns;
const Uint16 ymax = (plane->getBottom(top_pos) < rows) ? plane->getBottom(top_pos) : rows;
const T3 maxvalue = OFstatic_cast(T3, DicomImageClass::maxval(bitsof(T3)));
switch (plane->getMode())
{
case EMO_Replace:
{
DCMIMGLE_DEBUG("applying overlay plane " << (i + 1) << " with 'replace' mode");
const T3 fore = OFstatic_cast(T3, plane->getForeground() * maxvalue);
for (y = ymin; y < ymax; ++y)
{
plane->setStart(OFstatic_cast(Uint16, left_pos + xmin), OFstatic_cast(Uint16, top_pos + y));
q = Data + OFstatic_cast(unsigned long, y) * OFstatic_cast(unsigned long, columns) + OFstatic_cast(unsigned long, xmin);
for (x = xmin; x < xmax; ++x, ++q)
{
if (plane->getNextBit())
*q = fore;
}
}
break;
}
case EMO_ThresholdReplace:
{
DCMIMGLE_DEBUG("applying overlay plane " << (i + 1) << " with 'threshold replace' mode");
const T3 fore = OFstatic_cast(T3, plane->getForeground() * maxvalue);
const T3 thresh = OFstatic_cast(T3, plane->getThreshold() * maxvalue);
for (y = ymin; y < ymax; ++y)
{
plane->setStart(OFstatic_cast(Uint16, left_pos + xmin), OFstatic_cast(Uint16, top_pos + y));
q = Data + OFstatic_cast(unsigned long, y) * OFstatic_cast(unsigned long, columns) + OFstatic_cast(unsigned long, xmin);
for (x = xmin; x < xmax; ++x, ++q)
{
if (plane->getNextBit())
*q = (*q <= thresh) ? fore : 1;
}
}
break;
}
case EMO_Complement:
{
DCMIMGLE_DEBUG("applying overlay plane " << (i + 1) << " with 'complement' mode");
const T3 thresh = OFstatic_cast(T3, DicomImageClass::maxval(bitsof(T3) / 2));
for (y = ymin; y < ymax; ++y)
{
plane->setStart(OFstatic_cast(Uint16, left_pos + xmin), OFstatic_cast(Uint16, top_pos + y));
q = Data + OFstatic_cast(unsigned long, y) * OFstatic_cast(unsigned long, columns) + OFstatic_cast(unsigned long, xmin);
for (x = xmin; x < xmax; ++x, ++q)
{
if (plane->getNextBit())
*q = (*q <= thresh) ? maxvalue : 0;
}
}
break;
}
case EMO_InvertBitmap:
{
DCMIMGLE_DEBUG("applying overlay plane " << (i + 1) << " with 'invert bitmap' mode");
const T3 fore = OFstatic_cast(T3, plane->getForeground() * maxvalue);
for (y = ymin; y < ymax; ++y)
{
plane->setStart(OFstatic_cast(Uint16, left_pos + xmin), OFstatic_cast(Uint16, top_pos + y));
q = Data + OFstatic_cast(unsigned long, y) * OFstatic_cast(unsigned long, columns) + OFstatic_cast(unsigned long, xmin);
for (x = xmin; x < xmax; ++x, ++q)
{
if (!plane->getNextBit())
*q = fore;
}
}
break;
}
case EMO_RegionOfInterest:
{
DCMIMGLE_DEBUG("applying overlay plane " << (i + 1) << " with 'region of interest' mode");
const int dim = bitsof(T3) / 2;
for (y = ymin; y < ymax; ++y)
{
plane->setStart(OFstatic_cast(Uint16, left_pos + xmin), OFstatic_cast(Uint16, top_pos + y));
q = Data + OFstatic_cast(unsigned long, y) * OFstatic_cast(unsigned long, columns) + OFstatic_cast(unsigned long, xmin);
for (x = xmin; x < xmax; ++x, ++q)
{
if (!plane->getNextBit())
*q = *q >> dim;
}
}
break;
}
case EMO_BitmapShutter:
{
DCMIMGLE_DEBUG("applying overlay plane " << (i + 1) << " with 'bitmap shutter' mode");
register T3 fore = OFstatic_cast(T3, OFstatic_cast(double, maxvalue) * OFstatic_cast(double, plane->getPValue()) / OFstatic_cast(double, DicomImageClass::maxval(WIDTH_OF_PVALUES)));
if ((disp != NULL) && (disp->isValid()))
{
const DiDisplayLUT *dlut = disp->getLookupTable(WIDTH_OF_PVALUES);
if ((dlut != NULL) && (dlut->isValid()))
fore = OFstatic_cast(T3, dlut->getValue(plane->getPValue()));
}
for (y = ymin; y < ymax; ++y)
{
plane->setStart(OFstatic_cast(Uint16, left_pos + xmin), OFstatic_cast(Uint16, top_pos + y));
q = Data + OFstatic_cast(unsigned long, y) * OFstatic_cast(unsigned long, columns) + OFstatic_cast(unsigned long, xmin);
for (x = xmin; x < xmax; ++x, ++q)
{
if (plane->getNextBit())
*q = fore;
}
}
break;
}
default: /* e.g. EMO_Default */
DCMIMGLE_WARN("unhandled overlay mode (" << OFstatic_cast(int, plane->getMode()) << ")");
}
}
}
}
}
}
}
/// pointer to the storage area where the output data should be stored
T3 *Data;
/// flag indicating whether the output data buffer should be deleted in the destructor
int DeleteData;
#ifdef PASTEL_COLOR_OUTPUT
DiMonoColorOutputPixelTemplate<T1, T3> *ColorData;
#else
// dummy variable
DiMonoOutputPixel *ColorData;
#endif
// --- declarations to avoid compiler warnings
DiMonoOutputPixelTemplate(const DiMonoOutputPixelTemplate<T1,T2,T3> &);
DiMonoOutputPixelTemplate<T1,T2,T3> &operator=(const DiMonoOutputPixelTemplate<T1,T2,T3> &);
};
#endif
/*
*
* CVS/RCS Log:
* $Log: dimoopxt.h,v $
* Revision 1.54 2010-10-28 10:58:38 joergr
* Implemented missing rendering code for sigmoid VOI LUT function.
* Added more trace log messages which might be helpful for detailed debugging.
*
* Revision 1.53 2010-10-14 13:16:26 joergr
* Updated copyright header. Added reference to COPYRIGHT file.
*
* Revision 1.52 2010-10-05 15:25:10 joergr
* Added preliminary support for VOI LUT function. Please note, however, that
* the sigmoid transformation is not yet implemented.
* In debug mode, output more details on overlay plane to the logger.
*
* Revision 1.51 2010-03-01 09:08:47 uli
* Removed some unnecessary include directives in the headers.
*
* Revision 1.50 2009-11-25 16:08:26 joergr
* Removed inclusion of header file "ofconsol.h".
* Revised logging messages. Added more logging messages.
*
* Revision 1.49 2009-10-28 14:38:16 joergr
* Fixed minor issues in log output.
*
* Revision 1.48 2009-10-28 09:53:40 uli
* Switched to logging mechanism provided by the "new" oflog module.
*
* Revision 1.47 2006-08-15 16:30:11 meichel
* Updated the code in module dcmimgle to correctly compile when
* all standard C++ classes remain in namespace std.
*
* Revision 1.46 2005/12/08 16:47:54 meichel
* Changed include path schema for all DCMTK header files
*
* Revision 1.45 2005/03/09 17:30:42 joergr
* Added support for new overlay mode "invert bitmap".
*
* Revision 1.44 2004/02/06 11:07:50 joergr
* Distinguish more clearly between const and non-const access to pixel data.
*
* Revision 1.43 2003/12/23 15:53:22 joergr
* Replaced post-increment/decrement operators by pre-increment/decrement
* operators where appropriate (e.g. 'i++' by '++i').
*
* Revision 1.42 2003/12/23 10:51:52 joergr
* Updated documentation to get rid of doxygen warnings.
*
* Revision 1.41 2003/12/09 16:49:11 joergr
* Adapted type casts to new-style typecast operators defined in ofcast.h.
* Removed leading underscore characters from preprocessor symbols (reserved
* symbols). Updated copyright header.
*
* Revision 1.40 2003/06/12 15:08:34 joergr
* Fixed inconsistent API documentation reported by Doxygen.
*
* Revision 1.39 2002/12/09 13:32:53 joergr
* Renamed parameter/local variable to avoid name clashes with global
* declaration left and/or right (used for as iostream manipulators).
*
* Revision 1.38 2002/11/27 14:08:06 meichel
* Adapted module dcmimgle to use of new header file ofstdinc.h
*
* Revision 1.37 2002/06/19 08:12:01 meichel
* Added typecasts to avoid ambiguity with built-in functions on gcc 3.2
*
* Revision 1.36 2001/06/01 15:49:46 meichel
* Updated copyright header
*
* Revision 1.35 2000/05/03 09:46:28 joergr
* Removed most informational and some warning messages from release built
* (#ifndef DEBUG).
*
* Revision 1.34 2000/04/28 12:32:31 joergr
* DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
*
* Revision 1.33 2000/04/27 13:08:40 joergr
* Dcmimgle library code now consistently uses ofConsole for error output.
*
* Revision 1.32 2000/03/08 16:24:20 meichel
* Updated copyright header.
*
* Revision 1.31 2000/03/07 16:15:12 joergr
* Added explicit type casts to make Sun CC 2.0.1 happy.
*
* Revision 1.30 2000/03/06 18:19:36 joergr
* Moved get-method to base class, renamed method and made method virtual to
* avoid hiding of methods (reported by Sun CC 4.2).
*
* Revision 1.29 2000/03/03 14:09:13 meichel
* Implemented library support for redirecting error messages into memory
* instead of printing them to stdout/stderr for GUI applications.
*
* Revision 1.28 2000/02/01 10:52:37 meichel
* Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4,
* workaround for bug in compiler header files.
*
* Revision 1.27 1999/10/11 20:14:14 joergr
* Fixed bug in window() routine for cases where presentation LUT is active.
*
* Revision 1.26 1999/10/06 13:42:03 joergr
* Added method to remove reference to (internally handled) pixel data.
*
* Revision 1.25 1999/09/17 12:40:45 joergr
* Added/changed/completed DOC++ style comments in the header files.
* Enhanced efficiency of some "for" loops.
*
* Revision 1.24 1999/09/10 08:45:19 joergr
* Added support for CIELAB display function.
*
* Revision 1.23 1999/08/25 16:41:53 joergr
* Added new feature: Allow clipping region to be outside the image
* (overlapping).
*
* Revision 1.22 1999/08/17 10:26:08 joergr
* Commented unused parameter names to avoid compiler warnings.
*
* Revision 1.21 1999/07/23 14:08:44 joergr
* Changed implementation/interpretation of windows center/width (according to
* new letter ballot of supplement 33).
* Enhanced handling of corrupted pixel data (wrong length).
*
* Revision 1.20 1999/05/03 15:43:21 joergr
* Replaced method applyOptimizationLUT by its contents (method body) to avoid
* warnings (and possible errors) on Sun CC 2.0.1 :-/
*
* Revision 1.18 1999/04/30 16:10:50 meichel
* Minor code purifications to keep IBM xlC quiet
*
* Revision 1.17 1999/04/29 16:46:46 meichel
* Minor code purifications to keep DEC cxx 6 quiet.
*
* Revision 1.16 1999/04/29 09:38:34 joergr
* Changed position of "#ifdef" to avoid compiler warnings.
*
* Revision 1.15 1999/04/29 09:20:01 joergr
* Removed color related image files from public toolkit part.
*
* Revision 1.14 1999/04/28 18:56:07 joergr
* Removed support for pastel color output from public DCMTK part.
*
* Revision 1.13 1999/04/28 14:51:44 joergr
* Added experimental support to create grayscale images with more than 256
* shades of gray to be displayed on a consumer monitor (use pastel colors).
* Introduced new scheme for the debug level variable: now each level can be
* set separately (there is no "include" relationship).
*
* Revision 1.12 1999/03/24 17:20:14 joergr
* Added/Modified comments and formatting.
*
* Revision 1.11 1999/03/02 12:03:52 joergr
* Corrected bug in output routine of monochrome pixel data (wrong scaling when
* Barten transformation and windowing are active).
*
* Revision 1.10 1999/02/28 16:41:01 joergr
* Corrected bug: the output bits for bitmaps shutters were inverted (this was
* done due to an error in the used test images).
*
* Revision 1.9 1999/02/11 16:40:19 joergr
* Added routine to check whether particular grayscale values are unused in
* the output data.
* Removed two small memory leaks reported by dmalloc library.
*
* Revision 1.8 1999/02/05 16:44:52 joergr
* Corrected calculation of DDL value for bitmaps shutters (overlays).
*
* Revision 1.7 1999/02/05 15:13:36 joergr
* Added conversion P-Value to DDL when display function is absent.
*
* Revision 1.6 1999/02/03 17:32:43 joergr
* Added optimization LUT to transform pixel data.
* Added support for calibration according to Barten transformation (incl.
* a DISPLAY file describing the monitor characteristic).
*
* Revision 1.5 1999/01/20 15:11:05 joergr
* Replaced invocation of getCount() by member variable Count where possible.
* Added new output method to fill external memory buffer with rendered pixel
* data.
* Added new overlay plane mode for bitmap shutters.
* Added optimization to modality and VOI transformation (using additional
* LUTs).
*
* Revision 1.4 1998/12/23 12:40:01 joergr
* Removed unused parameter (BitsPerSample).
*
* Revision 1.3 1998/12/22 14:32:49 joergr
* Improved implementation of presentation LUT application (and other gray
* scale transformations). Tested with ECR test images from David Clunie.
*
* Revision 1.2 1998/12/14 17:25:55 joergr
* Added support for correct scaling of input/output values for grayscale
* transformations.
*
* Revision 1.1 1998/11/27 15:29:53 joergr
* Added copyright message.
* Introduced global debug level for dcmimage module to control error output.
* Corrected bug in VOI LUT transformation method.
* Changed behaviour: now window width of 0 is valid and negative width
* is invalid.
*
* Revision 1.6 1998/07/01 08:39:24 joergr
* Minor changes to avoid compiler warnings (gcc 2.8.1 with additional
* options), e.g. add copy constructors.
*
* Revision 1.5 1998/05/11 14:53:22 joergr
* Added CVS/RCS header to each file.
*
*
*/
|