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 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993
|
/*
* $Id: menucb.cxx,v 4.15 2005/02/05 14:45:59 hut66au Exp $
*
* Imview, the portable image analysis application
* http://www.cmis.csiro.au/Hugues.Talbot/imview
* ----------------------------------------------------------
*
* Imview is an attempt to provide an image display application
* suitable for professional image analysis. It was started in
* 1997 and is mostly the result of the efforts of Hugues Talbot,
* Image Analysis Project, CSIRO Mathematical and Information
* Sciences, with help from others (see the CREDITS files for
* more information)
*
* Imview is Copyrighted (C) 1997-2001 by Hugues Talbot and was
* supported in parts by the Australian Commonwealth Science and
* Industry Research Organisation. Please see the COPYRIGHT file
* for full details. Imview also includes the contributions of
* many others. Please see the CREDITS file for full details.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
* */
/*------------------------------------------------------------------------
*
* This file contains all the global functions called by the menu
* callbacks and keyboard accelerators.
*
*
*-----------------------------------------------------------------------*/
#include "imnmspc.hxx" // contains namespace definition, if needed
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_File_Chooser.H>
#include <FL/Fl_Help_Dialog.H>
#include <FL/fl_ask.H>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "imunistd.h"
#include <errno.h>
#include <sys/types.h>
#include <map> // C++ stl container.
#include <string> // C++ strings
#include "imview.hxx"
#include "nocase.hxx"
#include "imageIO.hxx"
#include "pointfile.hxx"
#include "imageViewer.hxx"
#include "menubar.hxx"
#include "printPrefs.hxx"
#include "savePrefs.hxx"
#include "imageInfo.hxx"
#include "spectraBox.hxx"
#include "transferFunction.hxx"
#include "transferRGBFunction.hxx"
#include "profileBox.hxx"
#include "userPrefs.hxx"
#include "progressInfo.hxx"
#include "bivHist.hxx"
#include "machine.hxx"
#include "StatusBox.hxx"
#include "toolbar.hxx"
#include "io/newprefio.hxx"
#include "sliceSlider.hxx"
using std::map;
typedef map<string,image_psfile>::iterator mi; // Map iterator (can't be const)
// components of the application
extern imviewWindow *mainWindow;
extern imageViewer *mainViewer;
extern imViewMenuBar *mainMenuBar;
extern imageIO *IOBlackBox;
extern pointfile *PtFileMngr;
extern Fl_File_Chooser *ImviewFC;
extern int debugIsOn;
extern int stopDebug;
extern bool lutWraparound;
extern volatile bool syncDisplay;
extern int makeImageCharIfFits;
extern int RGBdisplaysRGB;
extern int fitCharOverAllSamples;
extern int fitCharOverAllSlices;
extern const char *patchlevel;
extern int totalbnb;
extern char *builder;
extern int deleteAfter;
extern const char *psonlyfile;
extern map<string,image_psfile> psfilemap;
extern int appMaxHeight;
// fluid-generated
extern printprefs *printPrefsPanel;
extern saveprefs *savePrefsPanel;
extern imageinfo *imageInfoPanel;
extern transfer *transferEditorPanel;
extern transferRGB *transferRGBEditorPanel;
extern spectra *spectraPanel;
extern spectra *depthProfile;
extern profile *profilePanel;
extern userprefs *userprefsPanel;
extern bivhist *bivHistPanel;
extern progress *progressPanel;
extern Fl_Help_Dialog *help;
extern toolbar *toolbarPanel;
extern slideinput *slice3D, *sliceComponent, *sliceSeries;
// others
extern imprefs *fileprefs;
extern int applyTransferToAll;
extern bool main_terminate;
extern bool hideMainMenu;
extern bool fullScreen;
int keepPoints = 0; // a local preference
// openimage is a wrapper for all the read() calls
int openimage(const char *imname, int frame)
{
int ret;
static char clutname[DFLTSTRLEN+1];
const char *pf;
int nbframes=0;
IMAGEPARM *p;
if (IOBlackBox->isOverlay(imname)) { // are we opening an overlay?
dbgprintf("Image %s is an overlay\n", imname);
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
p->ovlpath = strdup(imname);
// apply overlay to current image
int retval = IOBlackBox->readOverlay(imname);
if (retval == 0) {
// redisplay image with overlay present
IOBlackBox->applyImageParameters(p, 0, 0, true);
mainViewer->displayCurrentImage();
}
return retval; // don't go any further in reading this image!
} else {
// close the overlay, it can never be displayed
IOBlackBox->closeHeader(imname);
return 20;
}
} else if (mainMenuBar->isAlreadyInItemList(imname, IMAGE_LIST_ID)) { // are we opening a new image?
// image may have already been opened once, but we are not sure yet
// selects that item
mainMenuBar->addToItemList(imname, IMAGE_LIST_ID);
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p->nbframes > 0) {
// now we are quite sure that the image has been opened before
if (frame == -1) // default is wrong here
frame = p->frame;
nbframes = p->nbframes;
} else {
// image has never been opened before
nbframes = IOBlackBox->getNbFrames(imname);
}
} else {
// image has never been opened before
nbframes = IOBlackBox->getNbFrames(imname);
}
if (nbframes <= -10) {
return (nbframes); // don't go any further, waste of time...
} else if (nbframes > 1) {
// enable the menu items
mainMenuBar->setFlagsByName(NEXTFRAME_ITEM, 0);
mainMenuBar->setFlagsByName(PREVIOUSFRAME_ITEM, 0);
mainMenuBar->setFlagsByName(SELECTFRAME_ITEM, FL_MENU_DIVIDER);
} else {
mainMenuBar->setFlagsByName(NEXTFRAME_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(PREVIOUSFRAME_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(SELECTFRAME_ITEM, FL_PUP_INVISIBLE | FL_MENU_DIVIDER);
}
// correct the default if by that time it hasn't been done yet
if (frame == -1) frame = 0;
// before image switch, backup the points
PtFileMngr->savelist(false);
if ((ret = IOBlackBox->read(imname, frame)) == 0) {
// we have successfully read the image
// remove the titleBox if it is still present
removeSimpleBanner();
// selects this file in the image list
mainMenuBar->addToItemList(imname, IMAGE_LIST_ID);
if (mainMenuBar->getNbImagesInList() > 1) {
mainMenuBar->setFlagsByName(NEXTIMAGE_ITEM, 0);
mainMenuBar->setFlagsByName(PREVIOUSIMAGE_ITEM, FL_MENU_DIVIDER);
} else {
mainMenuBar->setFlagsByName(NEXTIMAGE_ITEM, FL_PUP_GREY);
mainMenuBar->setFlagsByName(PREVIOUSIMAGE_ITEM, FL_PUP_GREY | FL_MENU_DIVIDER);
}
// check for LUT being attached to this image.
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
// records the number of frames (computed earlier)
p->nbframes = nbframes;
// re-set this, because the number of frame is only
// computed the first time the image is read.
IOBlackBox->setCurrImgNbFrames(nbframes);
// apply the gamma, contrast, etc, that have been saved for this image
// except if the `apply gamma to all images' has been checked, in which
// case the stored values for the image don't apply.
if (transferEditorPanel && !applyTransferToAll) {
char cval[100];
dbgprintf("Setting editor panel values\n");
transferEditorPanel->setGammaSliderValue(log(p->gamma));
sprintf(cval, "%1.4g", p->gamma);
transferEditorPanel->setGammaInputValue((const char *)cval);
transferEditorPanel->setContrastSliderValue(p->contrast);
transferEditorPanel->setBrightnessSliderValue(p->brightness);
transferEditorPanel->setDrawingParms();
transferEditorPanel->redrawWindowIfNeeded();
dbgprintf("Values found for %s:\ngamma=%g, contrast=%g, brightness=%g\n",
p->itempath,
p->gamma, p->contrast, p->brightness
);
}
// same thing for RGB panel
if (transferRGBEditorPanel && !applyTransferToAll) {
char cval[100];
dbgprintf("Setting RGB editor panel values\n");
// Gamma sliders
transferRGBEditorPanel->setRGammaSliderValue(log(p->Rgamma));
transferRGBEditorPanel->setGGammaSliderValue(log(p->Ggamma));
transferRGBEditorPanel->setBGammaSliderValue(log(p->Bgamma));
// Gamma inputs
sprintf(cval, "%1.4g", p->Rgamma);
transferRGBEditorPanel->setRGammaInputValue((const char *)cval);
sprintf(cval, "%1.4g", p->Ggamma);
transferRGBEditorPanel->setGGammaInputValue((const char *)cval);
sprintf(cval, "%1.4g", p->Bgamma);
transferRGBEditorPanel->setBGammaInputValue((const char *)cval);
// Contrast sliders
transferRGBEditorPanel->setRContrastSliderValue(p->Rcontrast);
transferRGBEditorPanel->setGContrastSliderValue(p->Gcontrast);
transferRGBEditorPanel->setBContrastSliderValue(p->Bcontrast);
// Brightness sliders
transferRGBEditorPanel->setRBrightnessSliderValue(p->Rbrightness);
transferRGBEditorPanel->setGBrightnessSliderValue(p->Gbrightness);
transferRGBEditorPanel->setBBrightnessSliderValue(p->Bbrightness);
//
transferRGBEditorPanel->setDrawingParms();
transferRGBEditorPanel->redrawWindowIfNeeded();
dbgprintf("Values found for %s:\ngamma=%g, contrast=%g, brightness=%g\n",
p->itempath,
p->gamma, p->contrast, p->brightness
);
}
// check if pointfile name has been set
if (p->pfpath==0) {
// check if an image specific pointfile exists
if ((pf=PtFileMngr->getPtFileNameIfPresent(imname)) != 0)
PtFileMngr->setPtFileName(pf);
// set the pointfile name accordingly, default = pointfile
p->pfpath = strdup(PtFileMngr->getPtFileName());
}
// clears the pointfile
if (!fileprefs->keepPoints())
PtFileMngr->rmAllPoints();
PtFileMngr->imageName(imname);
// read the overlay, if any
if (p->ovlpath)
IOBlackBox->readOverlay(p->ovlpath);
else // else remove it
IOBlackBox->setOverlay(0);
// apply the display parameters that have been saved for this image
// IOBlackBox->applyImageParameters(p, imname, clutname, false);
if ((p->gamma != 1.0) || (p->contrast != 0.5) || (p->brightness != 0.5))
IOBlackBox->applyImageParameters(p, imname, clutname, true);
else
IOBlackBox->applyImageParameters(p, imname, clutname, false);
// selects the CLUT or unselects it (if no CLUT)
mainMenuBar->addToItemList((const char *)clutname, CLUT_LIST_ID);
// now let's use some information on the image
// first of all, is the image 3-d?
if (IOBlackBox->getCurrImgThickness() > 1) {
// image is 3-d, we'll want to wade through the Z plane
mainMenuBar->setFlagsByName(NEXTPLANE_ITEM, 0);
mainMenuBar->setFlagsByName(PREVIOUSPLANE_ITEM, 0);
mainMenuBar->setFlagsByName(SELECTPLANE_ITEM, FL_MENU_DIVIDER);
// allow 3D rotations
mainMenuBar->setFlagsByName(ROTATE3DMENU_ITEM, FL_SUBMENU);
// allow 3D images to behave as hyperspectral images for some
// applications
if (IOBlackBox->getCurrImgThickness() > 1) {
mainMenuBar->setFlagsByName(DEPTHPROFILE_ITEM, 0);
} else {
mainMenuBar->setFlagsByName(DEPTHPROFILE_ITEM, FL_PUP_INVISIBLE);
}
} else {
// image is not 3-d, no point in confusing the user
mainMenuBar->setFlagsByName(NEXTPLANE_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(PREVIOUSPLANE_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(SELECTPLANE_ITEM, FL_PUP_INVISIBLE | FL_MENU_DIVIDER);
// disallow 3D rotations
mainMenuBar->setFlagsByName(ROTATE3DMENU_ITEM, FL_SUBMENU|FL_PUP_INVISIBLE);
}
// next: is the image multispectral?
if (IOBlackBox->getCurrImgNbSamples() > 1) {
// image is multispectral we'll want to wade through the components
mainMenuBar->setFlagsByName(NEXTCOMPONENT_ITEM, 0);
mainMenuBar->setFlagsByName(PREVIOUSCOMPONENT_ITEM, 0);
mainMenuBar->setFlagsByName(SELECTCOMPONENT_ITEM, FL_MENU_DIVIDER);
mainMenuBar->setFlagsByName(BIVHIST_ITEM, 0);
// Re-enable when it works
mainMenuBar->setFlagsByName(RGBTRANSFER_ITEM, 0);
if (IOBlackBox->getCurrImgNbSamples() >= 3) {
mainMenuBar->setFlagsByName(HYPERSPECTRAL_ITEM, 0);
} else {
mainMenuBar->setFlagsByName(HYPERSPECTRAL_ITEM, FL_PUP_INVISIBLE);
}
} else {
// image is not multispectral, no point in confusing the user
mainMenuBar->setFlagsByName(NEXTCOMPONENT_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(PREVIOUSCOMPONENT_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(BIVHIST_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(RGBTRANSFER_ITEM, FL_PUP_INVISIBLE);
// same as above, we want to allow 3D images to behave as hyperspectral images
// sometimes
if (IOBlackBox->getCurrImgThickness() <= 3) {
mainMenuBar->setFlagsByName(HYPERSPECTRAL_ITEM, FL_PUP_INVISIBLE);
mainMenuBar->setFlagsByName(SELECTCOMPONENT_ITEM, FL_PUP_INVISIBLE | FL_MENU_DIVIDER);
}
}
// actually display the image
mainViewer->displayCurrentImage();
} else {
errprintf("Read of %s failed, error=%d\n", imname, ret);
}
return ret;
}
// all the callback functions: they have to be globals
// menu callback functions
void test_cb(Fl_Object *,void *i)
{
dbgprintf("Not implemented yet, sorry! userdata = %ld\n",(long)i);
}
// Zoom in
void zoomin_cb(Fl_Object *, void *)
{
double zf;
zf = mainViewer->zoomFactor();
dbgprintf("Zoom factor = %f\n", (double)(mainViewer->zoomFactor(zf * 2.0)));
}
void smallzoomin_cb(Fl_Object *, void *)
{
double zf;
zf = mainViewer->zoomFactor();
dbgprintf("Zoom factor = %f\n", (double)(mainViewer->zoomFactor(zf * 1.1)));
}
// Zoom out
void zoomout_cb(Fl_Object *, void *)
{
double zf;
zf = mainViewer->zoomFactor();
dbgprintf("Zoom factor = %f\n", (double)(mainViewer->zoomFactor(zf / 2.0)));
}
void smallzoomout_cb(Fl_Object *, void *)
{
double zf;
zf = mainViewer->zoomFactor();
dbgprintf("Zoom factor = %f\n", (double)(mainViewer->zoomFactor(zf / 1.1)));
}
void unzoom_cb(Fl_Object *, void *)
{
dbgprintf("Zoom factor = %f\n", (double)(mainViewer->applyDefaultZoomFactor()));
}
void selectzoom_cb(Fl_Object *, void *)
{
static char currzoomtxt[100];
sprintf(currzoomtxt, "%f", (double)(mainViewer->zoomFactor()));
const char *zoomtxt = fl_input("Enter zoom factor", currzoomtxt);
double newzoom = (zoomtxt != 0) ? atof(zoomtxt):mainViewer->zoomFactor();
// minimal check
if (newzoom > 0)
mainViewer->zoomFactor(newzoom);
else
errprintf("Zoom factor must be strictly positive\n");
return;
}
void thiszoom_cb(Fl_Object *, void *)
{
dbgprintf("Current zoom factor %f is new the default\n",
mainViewer->setDefaultZoomFactor(mainViewer->zoomFactor()));
return;
}
void selectdefaultzoom_cb(Fl_Object *, void *)
{
static char currzoomtxt[100];
sprintf(currzoomtxt, "%f", (double)(mainViewer->zoomFactor()));
const char *zoomtxt = fl_input("Enter default zoom factor", currzoomtxt);
double newzoom = (zoomtxt != 0) ? atof(zoomtxt):mainViewer->zoomFactor();
// minimal check
if (newzoom > 0)
mainViewer->setDefaultZoomFactor(newzoom);
else
errprintf("Zoom factor must be strictly positive\n");
return;
}
// rotations
static float mymodulo(float &f)
{
// modulo is not portable enough in this case
while (f >= 360)
f -= 360;
while (f < 0)
f += 360;
dbgprintf("Picture angle is %d\n", f);
return f;
}
void rotate90right_cb(Fl_Object *, void *)
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
IOBlackBox->rotateRight();
IOBlackBox->applyImageParameters(p, 0, 0, true);
p->angle += 90;
mymodulo(p->angle);
mainViewer->displayCurrentImage();
}
return;
}
void rotate90left_cb(Fl_Object *, /*g */
void *) /* */
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
IOBlackBox->rotateLeft();
IOBlackBox->applyImageParameters(p, 0, 0, true);
p->angle -= 90;
mymodulo(p->angle);
mainViewer->displayCurrentImage();
}
return;
}
void rotate180_cb(Fl_Object *, void *)
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
IOBlackBox->rotate180();
IOBlackBox->applyImageParameters(p, 0, 0, true);
p->angle += 180;
mymodulo(p->angle);
mainViewer->displayCurrentImage();
}
return;
}
void rotate3dup_cb(Fl_Object *, void *)
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
IOBlackBox->rotate3Dup();
IOBlackBox->applyImageParameters(p, 0, 0, true);
// This will complicate matters...
//p->angle += 180;
//mymodulo(p->angle);
mainViewer->displayCurrentImage();
}
return;
}
void rotate3ddown_cb(Fl_Object *, void *)
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
IOBlackBox->rotate3Ddown();
IOBlackBox->applyImageParameters(p, 0, 0, true);
// This will complicate matters...
//p->angle += 180;
//mymodulo(p->angle);
mainViewer->displayCurrentImage();
}
return;
}
// flips
void flipv_cb(Fl_Object *, void *)
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
IOBlackBox->flipv();
IOBlackBox->applyImageParameters(p, 0, 0, true);
if ((p->angle == 90)
|| (p->angle == 270)) {
p->angle += 180;
mymodulo(p->angle);
}
p->mirror = 1 - p->mirror; // swap the `mirror' status
mainViewer->displayCurrentImage();
}
return;
}
void fliph_cb(Fl_Object *, void *)
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p) {
IOBlackBox->fliph();
IOBlackBox->applyImageParameters(p, 0, 0, true);
if ((p->angle == 0)
|| (p->angle == 180)) {
p->angle += 180;
mymodulo(p->angle);
}
p->mirror = 1 - p->mirror; // swap the `mirror' status
mainViewer->displayCurrentImage();
}
return;
}
void filechoosernew_cb(Fl_File_Chooser *fc, void *data)
{
dbgprintf("new file_chooser callback (fc=%p, data=%p)\n", fc, data);
dbgprintf(" filename = \"%s\"\n", fc->value());
}
void create_fc(void)
{
const static char *file_filter = \
"Image Files (*.{bmp,gif,jpg,png,tif,tiff})\t"
"Pointfiles (*.pf)";
if (ImviewFC == 0) {
ImviewFC = new Fl_File_Chooser(".", "*", Fl_File_Chooser::MULTI|Fl_File_Chooser::CREATE, "Imview File Chooser");
ImviewFC->callback(filechoosernew_cb);
ImviewFC->filter(file_filter);
}
assert(ImviewFC != 0); // eh.
}
// Lauches the openfile dialog
void open_cb(Fl_Object *, void *i)
{
int count;
char locfilename[DFLTSTRLEN];
dbgprintf("Open dialog callback with option %ld\n", (long) i);
create_fc();
ImviewFC->show();
// modal
while (ImviewFC->visible())
Fl::wait();
count = ImviewFC->count();
// add all the files to the item list and open the last one
if (count > 0) {
for (int i = 1 ; i <= count ; ++i) {
if (!ImviewFC->value(i))
break;
fl_filename_expand(locfilename, sizeof(locfilename), ImviewFC->value(i));
mainMenuBar->addToItemList(locfilename, IMAGE_LIST_ID);
}
// truly open the last one
openimage(locfilename);
}
#if 0
p = fl_file_chooser("Open Image","*",currentfile);
if (p)
currentfile = p;
if (p == 0) {
dbgprintf("User cancelled choice\n");
} else {
dbgprintf("User chose %s\n", currentfile);
// open an image
openimage(currentfile);
}
#endif
return;
}
// Opens an overlay
void openoverlay_cb(Fl_Object *, void *i)
{
IMAGEPARM *pp = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
static const char *currentfile = 0, *p = 0;
dbgprintf("Open overlay dialog callback with option %ld\n", (long) i);
p = fl_file_chooser("Open Overlay Image","*",currentfile);
if (p)
currentfile = p;
if (p == 0) {
dbgprintf("User cancelled choice\n");
} else {
dbgprintf("User chose %s\n", currentfile);
pp->ovlpath = strdup(p);
// apply overlay to current image
int retval = IOBlackBox->readOverlay(currentfile);
if (retval == 0) {
// redisplay image with overlay present
// don't call this
//IOBlackBox->applyOverlayToCurrentImage();
// call that instead
IOBlackBox->applyImageParameters(pp, 0, 0, true);
mainViewer->displayCurrentImage();
}
}
return;
}
// close overlay by hand
void closeoverlay_cb(Fl_Object *, void *i)
{
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
// this call free extra buffers associated with socket I/O
// this is the logical place for this to happen, as the image can't be
// recalled if its name drops from the list.
IOBlackBox->closeHeader(p->ovlpath);
if (p->ovlpath) {
free(p->ovlpath);
p->ovlpath = 0;
}
IOBlackBox->setOverlay(0);
IOBlackBox->applyImageParameters(p, 0, 0, true);
mainViewer->displayCurrentImage();
}
// launches the save preferences dialog, and then the savefile dialog
void save_cb(Fl_Object *, void *)
{
dbgprintf("Save preferences callback\n");
if (savePrefsPanel == 0) {
savePrefsPanel = new saveprefs;
saveprefs &saveref = *savePrefsPanel;
// initializes the fluid-generated panel
saveprefs_panel(saveref);
// do our own private initialisation
savePrefsPanel->setDefaults();
}
// show the panel
savePrefsPanel->show();
return;
}
void printprefs_cb(Fl_Object *, void *)
{
// get the name of the image currently being displayed
IMAGEPARM *p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
char *shortname = strrchr(p->itempath, '/');
if (shortname == NULL)
shortname = p->itempath; // revert to full name if name is local
else
shortname++; // go beyond the last `/'
dbgprintf("Print preferences callback\n");
if (printPrefsPanel == 0) {
// initializes the fluid-generated panel
printPrefsPanel = new printprefs;
printprefs &printref = *printPrefsPanel;
printprefs_panel(printref);
// do our own initialisation
printPrefsPanel->setDefaults();
}
// shows the panel
printPrefsPanel->setTitle((const char*)shortname);
printPrefsPanel->show();
return;
}
void imageinfo_cb(Fl_Object *, void *)
{
dbgprintf("Image info callback\n");
if (imageInfoPanel == 0) {
// initializes the fluid-generated panel
imageInfoPanel = new imageinfo;
imageinfo &imageref = *imageInfoPanel;
imageinfo_panel(imageref);
// do our own initialisation
imageInfoPanel->setDefaults();
}
// shows the panel
imageInfoPanel->show();
return;
}
void toolbar_cb(Fl_Object *, void *)
{
dbgprintf("Toolbar callback\n");
if (toolbarPanel == 0) {
// initializes the fluid-generated panel
toolbarPanel = new toolbar;
toolbar_panel(*toolbarPanel);
// init
toolbarPanel->setDefaults();
}
// Show the panel
toolbarPanel->show();
return;
}
void transfer_cb(Fl_Object *, void *)
{
dbgprintf("Transfer function editor callback\n");
if (transferEditorPanel == 0) {
transferEditorPanel = new transfer;
transfer &transferref = *transferEditorPanel;
// initializes the fluid-generated panel
transfer_panel(transferref);
// do our own initialisation
transferEditorPanel->setDefaults();
}
// shows the panel
transferEditorPanel->show();
return;
}
void transferRGB_cb(Fl_Object *, void *)
{
dbgprintf("RGB Transfer function editor callback\n");
if (transferRGBEditorPanel == 0) {
transferRGBEditorPanel = new transferRGB;
// initializes the fluid-generated panel
RGB_transfer_panel(*transferRGBEditorPanel);
// do our own initialisation
transferRGBEditorPanel->setDefaults();
}
// shows the panel
transferRGBEditorPanel->show();
return;
}
void threshold_cb(Fl_Object *, void *)
{
return;
}
// who is responsible for this heap of crap?
void whodunit_cb(Fl_Object *, void *)
{
static char buff[300];
sprintf(buff,
"Imview version %s build #%d for %s\n"
"Made on %s by %s\n"
"Copyright Hugues Talbot, CMIS Image Analysis 1997-2003",
patchlevel,
totalbnb,
systemName(),
__DATE__,
builder);
fl_message((const char *)buff);
return;
}
// online help: just loading a pre-defined image
// void onlinehelp_cb(Fl_Object *, void *)
// {
// // for now, online help is only an image...
// openimage(ONLINEHELP);
// // this is a bit brutal, but we want to be able to view
// // the damn thing...
// mainViewer->zoomFactor(1.0);
// mainViewer->resetDisplay(false);
// return;
// }
int starthelp(char *returnPath, char *fileToShow)
{
const char *p;
static char pathToHelp[DFLTSTRLEN], tmppath[DFLTSTRLEN], basePath[DFLTSTRLEN];
int result = 0;
if (help == 0) {
int i, j;
// make up the directories where we might look for
// the documentation
strcpy(pathToHelp, "."); // first look in present directory
if ((p = getenv("IMVIEWHOME")) != 0) { // then in ~/.imview, etc
snprintf(tmppath, DFLTSTRLEN, "%c%s", PATHSEP, p);
strncat(pathToHelp, tmppath, DFLTSTRLEN);
}
snprintf(tmppath, DFLTSTRLEN-4, "%c%c%s", PATHSEP, SLASH, PrefPath);
strncat(pathToHelp, tmppath, DFLTSTRLEN); // then in install directory
// hunt for documentation now
for ( i = 0, j = 0; ; ) { // ever
if ((pathToHelp[i] != PATHSEP) && (pathToHelp[i] != '\0')) {
tmppath[j++] = pathToHelp[i++];
} else {
tmppath[j] = '\0';
strcat(tmppath,"/");
strcat(tmppath, fileToShow);
dbgprintf("looking in %s\n", tmppath);
if (access(tmppath, R_OK) == 0) {
help = new Fl_Help_Dialog;
strncpy(returnPath, tmppath, DFLTSTRLEN);
tmppath[j] = '\0';
strcat(tmppath,"/");
strncpy(basePath, tmppath, DFLTSTRLEN); // to keep (static)
result = 1;
break; // found preferences, finished
}
// try with doc/blablab.html
tmppath[j] = '\0';
strcat(tmppath,"/doc/");
strcat(tmppath, fileToShow);
dbgprintf("looking in %s\n", tmppath);
if (access(tmppath, R_OK) == 0) {
help = new Fl_Help_Dialog;
strncpy(returnPath, tmppath, DFLTSTRLEN);
result = 1; // success!
tmppath[j] = '\0';
strcat(tmppath,"/doc/");
strncpy(basePath, tmppath, DFLTSTRLEN); // to keep (static)
break; // found preferences, finished
}
// no joy there, try next string if possible
if (pathToHelp[i] != '\0') {
j = 0;
i++;
} else {
strncpy(returnPath, pathToHelp, DFLTSTRLEN);
basePath[0] = '\0';
result = 0; // failure
break;
}
}
}
} else {
// help has been started already, but check that the file we want it still there
strncpy(tmppath, basePath, DFLTSTRLEN); // ends with a `/'
strncat(tmppath, fileToShow, DFLTSTRLEN);
dbgprintf("Looking in %s\n", tmppath);
if (access(tmppath, R_OK) == 0) {
strncpy(returnPath, tmppath, DFLTSTRLEN);
result = 1; // success!
} else {
result = 0;
}
}
return result;
}
void onlinehelp_cb(Fl_Object *, void *)
{
const char *p;
static char pathToHelp[DFLTSTRLEN];
int helpStarted;
helpStarted = starthelp(pathToHelp, ONLINEHELP);
if (help && helpStarted) {
help->load(pathToHelp);
help->show();
} else {
if ((p = getenv("IMVIEWHOME")) == 0) {
errprintf("On-line help not found anywhere,\n"
"try setting IMVIEWHOME. Sorry\n");
} else {
errprintf("On-line help not found anywhere in\n%s", pathToHelp);
}
}
}
// lauches a browser to read the full documentation
void fulldocument_cb(Fl_Object *, void *)
{
static char command[1024];
char helpurl[1024];
FILE *helpfile;
if((helpfile = fopen(LOCALHELP, "r")) != NULL) {
fclose(helpfile);
strncpy(helpurl, "file://", 1024);
strncat(helpurl, LOCALHELP, 1016);
} else {
strncpy(helpurl, HELPURL, 1024);
}
sprintf(command,
"sensible-browser %s &", helpurl);
int ret = system((const char *)command);
if (ret != 0) {
// try calling mozilla directly!
sprintf(command,
"mozilla %s &", helpurl);
ret = system((const char *)command);
if (ret != 0)
errprintf("Sorry, can't start browser\n"
"Help URL is:\n"
"%s",
helpurl);
}
}
// GNU Public Licence
void licence_cb(Fl_Object *, void *)
{
const char *p;
static char pathToLicense[DFLTSTRLEN];
int helpStarted;
helpStarted = starthelp(pathToLicense, LICENSE);
if (help && helpStarted) {
help->load(pathToLicense);
help->show();
} else {
if ((p = getenv("IMVIEWHOME")) == 0) {
errprintf("License file not found anywhere,\n"
"try setting IMVIEWHOME Sorry\n");
} else {
errprintf("License file not found anywhere in\n%s", pathToLicense);
}
}
}
// NO WARRANTY
void warranty_cb(Fl_Object *, void *)
{
const char *p;
static char pathToWarranty[DFLTSTRLEN];
int helpStarted;
helpStarted = starthelp(pathToWarranty, WARRANTY);
if (help && helpStarted) {
help->load(pathToWarranty);
help->show();
} else {
if ((p = getenv("IMVIEWHOME")) == 0) {
errprintf("Warranty file not found anywhere,\n"
"try setting IMVIEWHOME Sorry\n");
} else {
errprintf("Warranty file not found anywhere in\n%s", pathToWarranty);
}
}
}
void close_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
mi q;
const char *imTempPSFileName;
dbgprintf("Close dialog callback\n");
// replace the image being displayed
do {
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID); // this is the image being displayed at present
if (p == 0)
return; // this is possible if called from the interpreter
// case when the file is a Postscript file, rendered into
// a different file...
if ((q = psfilemap.find(p->itempath)) != psfilemap.end()) {
// if (psonlyfile && (strcmp(p->itempath, psonlyfile) == 0)) {
// erase the temp file
imTempPSFileName = (q->second).getfilename().c_str();
dbgprintf("Erasing the rendered PS file %s\n", imTempPSFileName);
unlink(imTempPSFileName);
psfilemap.erase(q); // get rid of it
} else if (deleteAfter) {
// be a bit conservative: remove the image only if it is in one of the tmp directories
if (strstr(p->itempath, "/tmp/") != 0) {
dbgprintf("Physically deleting the image %s\n", p->itempath);
unlink(p->itempath);
} else {
dbgprintf("Not deleting %s after all\n", p->itempath);
}
}
// this call free extra buffers associated with socket I/O
// this is the logical place for this to happen, as the image can't be
// recalled if its name drops from the list.
IOBlackBox->closeHeader(p->itempath);
// normal menu handling
mainMenuBar->removeFromItemList(p->itempath, IMAGE_LIST_ID); // this will change the selection...
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID); // therefore it is NO LONGER the same image as above
} while ((p != 0) && (openimage(p->itempath) != 0));
if (p == 0) {
// there isn't any image left in the list: show the simple banner instead
mainViewer->close();
showSimpleBanner();
}
return;
}
void filechooser_cb(const char *name)
{
dbgprintf("File chooser callback '%s'\n",name);
}
// called when a image name is selected from the image menu
void image_cb(Fl_Object *, void *arg)
{
IMAGEPARM *p;
p = (IMAGEPARM *)arg;
dbgprintf("Image callback with argument %s\n", p->itempath);
if (openimage(p->itempath) != 0) {
// this image couldn't be opened: remove it from the list!
do {
mainMenuBar->removeFromItemList(p->itempath, IMAGE_LIST_ID);
// this will get the new selection...
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
} while ((p != 0) && (openimage(p->itempath) != 0));
if (p == 0) {
// there isn't any image left in the list: show the simple banner instead
mainViewer->close();
showSimpleBanner();
}
}
}
// get the next image on the list if any
void nextimage_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
dbgprintf("Next image callback\n");
if ((p = (IMAGEPARM *)mainMenuBar->getNextItemInList(IMAGE_LIST_ID)) != 0) {
if (openimage(p->itempath) != 0) {
// this image couldn't be opened: remove it from the list!
do {
mainMenuBar->removeFromItemList(p->itempath, IMAGE_LIST_ID);
// this will get the new selection...
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
} while ((p != 0) && (openimage(p->itempath) != 0));
if (p == 0) {
// there isn't any image left in the list: show the simple banner instead
mainViewer->close();
showSimpleBanner();
}
}
} else {
warnprintf("Null pointer in image list: this is a bug\n");
}
return;
}
void previousimage_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
dbgprintf("Previous image callback\n");
if ((p = (IMAGEPARM *)mainMenuBar->getPreviousItemInList(IMAGE_LIST_ID)) != 0) {
if (openimage(p->itempath) != 0) {
// this image couldn't be opened: remove it from the list!
do {
mainMenuBar->removeFromItemList(p->itempath, IMAGE_LIST_ID);
// this will get the new selection...
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
} while ((p != 0) && (openimage(p->itempath) != 0));
if (p == 0) {
// there isn't any image left in the list: show the simple banner instead
mainViewer->close();
showSimpleBanner();
}
}
} else {
warnprintf("Null pointer in image list: this is a bug\n");
}
return;
}
// Walk down the list of images and save them to file...
void saveimagelist_cb(Fl_Object *, void *)
{
static char currSavePath[100], errmsg[300];
int nbitems;
char *res = mainMenuBar->getItemListContent(IMAGE_LIST_ID, nbitems);
strcpy(currSavePath, "/usr/tmp/imagelist");
const char *savePathTxt = fl_input("Enter list save path", currSavePath);
FILE *saveListFile = fopen(savePathTxt, "w");
if (saveListFile != NULL) {
fprintf(saveListFile, res);
fclose(saveListFile);
dbgprintf("Saving %d image names to %s\n", nbitems, savePathTxt);
} else {
sprintf(errmsg, "Error saving list to %s\n%s", savePathTxt, strerror(errno));
fl_alert(errmsg);
}
delete[] res;
return;
}
// 1-D profiles handling
void showprofile_cb(Fl_Object *, void *)
{
dbgprintf("Profile panel callback\n");
if (profilePanel == 0) {
profilePanel = new profile;
profile &profileref = *profilePanel;
profile_panel(profileref);
// do our own init
profilePanel->setDefaults();
}
// shows the panel
profilePanel->show();
return;
}
void startserver_cb(Fl_Object *, void *)
{
}
void stopserver_cb(Fl_Object *, void *)
{
}
// server download progress panel
void showprogress_cb(Fl_Object *, void *)
{
dbgprintf("Progress panel callback\n");
if (progressPanel == 0) {
progressPanel = new progress;
progress_panel(*progressPanel);
// standard init
progressPanel->setDefaults();
}
// show the panel
progressPanel->show();
return;
}
// multispectral image handling
void nextcomponent_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
dbgprintf("Next sample\n");
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p->comp < (IOBlackBox->getCurrImgNbSamples()-1)) {
p->comp++;
if (sliceComponent) {
sliceComponent->setSlice(p->comp);
} else {
IOBlackBox->applyImageParameters(p, 0, 0, true); // we keep the current gamma
// actually display the image
mainViewer->displayCurrentImage();
}
}
return;
}
void previouscomponent_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
dbgprintf("Previous sample\n");
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p->comp > 0) {
p->comp--;
if (sliceComponent) {
sliceComponent->setSlice(p->comp);
} else {
IOBlackBox->applyImageParameters(p, 0, 0, true); // we keep the current gamma if defined
// actually display the image
mainViewer->displayCurrentImage();
}
}
return;
}
void showspectrum_cb(Fl_Object *, void *)
{
dbgprintf("Spectra panel callback\n");
if (spectraPanel == 0) {
spectraPanel = new spectra;
spectra &spectraref = *spectraPanel;
spectra_panel(spectraref);
// do our own init
spectraPanel->setDefaults();
}
// shows the panel
spectraPanel->show();
return;
}
void showbivhist_cb(Fl_Object *, void *)
{
dbgprintf("Bivariate histogram panel callback\n");
if (bivHistPanel == 0) {
bivHistPanel = new bivhist;
bivhist &bivhistref = *bivHistPanel;
bivhist_panel(bivhistref);
// do our own init
bivHistPanel->setDefaults();
}
// shows the panel
bivHistPanel->show();
return;
}
void setcomponentvalue(int v)
{
IMAGEPARM *p;
dbgprintf("Set sample to %d\n", v);
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
// minimal check
if ((v >= 0) && (v < IOBlackBox->getCurrImgNbSamples())) {
p->comp = v;
IOBlackBox->applyImageParameters(p, 0, 0, true); // we keep the gamma if defined
mainViewer->displayCurrentImage();
} else {
errprintf("Sample number is out of bounds\n");
}
return;
}
void selectcomponent_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
int cmin, cmax;
dbgprintf("Select sample\n");
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (sliceComponent == 0) {
sliceComponent = new slideinput;
slider_panel(*sliceComponent);
sliceComponent->setDefaults(); // own init
sliceComponent->setWindowTitle("Select sample");
sliceComponent->setValueTitle("sample:");
sliceComponent->setSliceCB(setcomponentvalue);
}
cmin = 0;
cmax = IOBlackBox->getCurrImgNbSamples()-1;
sliceComponent->setLimits(cmin, cmax);
sliceComponent->setSlice(p->comp);
sliceComponent->show();
return;
}
// 3-D bare bone functions
void showdepthprofile_cb(Fl_Object *, void *)
{
dbgprintf("Depth profile panel callback\n");
if (depthProfile == 0) {
depthProfile = new spectra;
spectra_panel(*depthProfile);
// do our own init
depthProfile->setDefaults();
depthProfile->setWindowTitle("Depth profile panel");
depthProfile->setXValueLabel("Plane:");
}
// shows the panel
depthProfile->show();
return;
}
void nextplane_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
dbgprintf("Next plane\n");
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p->zslice < (IOBlackBox->getCurrImgThickness()-1)) {
p->zslice++;
if (slice3D) {
slice3D->setSlice(p->zslice);
} else {
IOBlackBox->applyImageParameters(p, 0, 0, true); // we keep the current gamma if defined
// actually display the image
mainViewer->displayCurrentImage();
}
}
return;
}
void previousplane_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
dbgprintf("Previous plane\n");
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p->zslice > 0) {
p->zslice--;
if (slice3D) {
slice3D->setSlice(p->zslice);
} else {
IOBlackBox->applyImageParameters(p, 0, 0, true); // we keep the current gamma if defined
// actually display the image
mainViewer->displayCurrentImage();
}
}
return;
}
// Z offset is not dealt with as it should here
void setplanevalue(int v)
{
IMAGEPARM *p;
int zt = IOBlackBox->getCurrImgThickness();
dbgprintf("Set plane to %d\n", v);
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
// minimal check
if ((v >= 0) && (v < zt)) {
p->zslice = v;
IOBlackBox->applyImageParameters(p, 0, 0, true); // we keep the current gamma if defined
mainViewer->displayCurrentImage();
} else {
errprintf("Plane number is out of bounds\n");
}
return;
}
void selectplane_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
int cmin, cmax, zt = IOBlackBox->getCurrImgThickness();
dbgprintf("Select plane\n");
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (slice3D == 0) {
slice3D = new slideinput;
slider_panel(*slice3D);
slice3D->setDefaults();
slice3D->setWindowTitle("Select plane");
slice3D->setValueTitle("plane:");
slice3D->setSliceCB(setplanevalue);
}
cmin = 0;
cmax = zt-1;
slice3D->setLimits(cmin, cmax);
slice3D->setSlice(p->zslice);
slice3D->show();
return;
}
// unlike the other slices, this one allows loops (time loops
// are frequent, think of GIF animations.
void nextframe_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p != 0) {
if (p->frame < p->nbframes-1)
p->frame++;
else
p->frame = 0;
dbgprintf("Opening frame #%d for file %s\n",
p->frame, p->itempath);
if (sliceSeries) {
sliceSeries->setSlice(p->frame);
}
openimage(p->itempath, p->frame);
}
return;
}
void previousframe_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p != 0) {
if (p->frame > 0)
p->frame--;
else
p->frame = p->nbframes -1;
dbgprintf("Opening frame #%d for file %s\n",
p->frame, p->itempath);
if (sliceSeries) {
sliceSeries->setSlice(p->frame);
}
openimage(p->itempath, p->frame);
}
return;
}
void setframevalue(int v)
{
IMAGEPARM *p;
int pt;
dbgprintf("Set frame to %d\n", v);
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p != 0) {
pt = p->nbframes; // minimal check
// minimal check
if ((v >= 0) && (v < pt)) {
p->frame = v;
openimage(p->itempath, p->frame);
} else {
errprintf("Frame number is out of bounds\n");
}
}
return;
}
void selectframe_cb(Fl_Object *, void *)
{
IMAGEPARM *p;
int cmin, cmax, pt;
dbgprintf("Select frame\n");
p = (IMAGEPARM *)mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (p != 0) {
pt = p->nbframes;
if (sliceSeries == 0) {
sliceSeries = new slideinput;
slider_panel(*sliceSeries);
sliceSeries->setDefaults();
sliceSeries->setWindowTitle("Select frame");
sliceSeries->setSliceCB(setframevalue);
}
cmin = 0;
cmax = pt-1;
sliceSeries->setLimits(cmin, cmax);
sliceSeries->setSlice(p->frame);
sliceSeries->show();
}
return;
}
// Hmmmm.
int setClut(const char *label)
{
int res = 0;
IMAGEPARM *xlut;
xlut = (IMAGEPARM *)mainMenuBar->getItemByLabel(label, CLUT_LIST_ID);
if (xlut != 0)
clut_cb(0, xlut); // hmmm
else
res = 1;
return res;
}
// called when a CLUT is chosen for the current image
void clut_cb(Fl_Object *,void *arg)
{
IMAGEPARM *xlut, *ximg;
xlut = (IMAGEPARM *)arg;
dbgprintf("CLUT callback called with argument %s\n", xlut->itempath);
if (IOBlackBox->applyCLUTtoCurrentImage((const char *)xlut->itempath) == 0) {
// we have successfully opened the image
// remove the titleBox if it is still present
removeSimpleBanner();
// selects the CLUT
mainMenuBar->addToItemList(xlut->itempath, CLUT_LIST_ID);
// specify that we always want to display the current image with
// the chosen LUT in the future.
ximg = (IMAGEPARM *) mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID);
if (ximg->clutpath != 0)
free(ximg->clutpath);
ximg->clutpath = strdup(xlut->itempath); // this should work.
dbgprintf("Attaching clut %s to image%s\n", ximg->clutpath, ximg->itempath);
// let us not forget to display the image!
mainViewer->displayCurrentImage();
}
return;
}
// Remove all colour use with the image
void noclut_cb(Fl_Object *,void *)
{
IMAGEPARM *ximg;
Fl_Menu_Item *selectedMenu;
const char *currentfile;
// get the selected image ID
if ((ximg = (IMAGEPARM *) mainMenuBar->getSelectedItemArgument(IMAGE_LIST_ID)) != 0) {
// delete the association with any colour map...
if (ximg->clutpath != 0) {
free(ximg->clutpath);
ximg->clutpath = 0;
}
// unselects the current CLUT
if ((selectedMenu = mainMenuBar->getSelectedMenuItem(CLUT_LIST_ID)) != 0) {
// uncheck the thing
selectedMenu->flags &= ~FL_PUP_CHECK;
}
currentfile = ximg->itempath;
dbgprintf("Removing colour map associated with image%s\n", currentfile);
// let us not forget to display the image!
bool oldkeepPoints = fileprefs->keepPoints();
fileprefs->keepPoints(true);
openimage(currentfile);
if (!oldkeepPoints)
fileprefs->keepPoints(false); // otherwise no change needed
}
return;
}
void userprefspanel_cb(Fl_Object *, void *)
{
dbgprintf("User preferences panel callback\n");
if (userprefsPanel == 0) {
userprefsPanel = new userprefs;
userprefs &userprefsref = *userprefsPanel;
userprefs_panel(userprefsref);
// do our own init
userprefsPanel->setDefaults();
}
// shows the panel
userprefsPanel->show();
// set the debug stuff
userprefsPanel->setDebug(debugIsOn);
userprefsPanel->setStopDebug(stopDebug);
return;
}
// sets or unsets the individual preferences
void preference_cb(Fl_Object *obj, void *arg)
{
long intarg;
Fl_Menu_ *m = (Fl_Menu_*)obj;
Fl_Menu_Item* i = (Fl_Menu_Item*)(m->mvalue()); // get the menu item
bool currentMenuHideStatus = hideMainMenu;
intarg = (long)(arg);
// non-toggle ones
if (intarg == PREF_WARNING)
StatusBox::Instance()->show(); // easy...
if (i->value()) {
switch (intarg) {
case PREF_SMOOTHUNZOOM:
mainViewer->drawSmooth(1);
break;
case PREF_DEBUG:
debugIsOn = 1;
break;
case PREF_STOPDEBUG:
stopDebug = 1;
break;
case PREF_KEEPPOINTS:
keepPoints = 1;
break;
case PREF_WRAPAROUND:
lutWraparound = true;
break;
case PREF_MAKECHAR:
makeImageCharIfFits = 1;
break;
case PREF_RGBRGB:
RGBdisplaysRGB = 1;
break;
case PREF_FITALL:
fitCharOverAllSamples = 1;
IOBlackBox->flush_minmax_cache();
break;
case PREF_FIT3D:
fitCharOverAllSlices = 1;
IOBlackBox->flush_minmax_cache();
break;
case PREF_SYNCDISP:
syncDisplay = true;
break;
case PREF_HIDEMENU:
hideMainMenu = true;
break;
case PREF_FULLSCREEN:
fullscreen_cb(0,0);
break;
default:
warnprintf("Unknown preference argument %d\n", intarg);
break;
}
} else {
switch (intarg) {
case PREF_SMOOTHUNZOOM:
mainViewer->drawSmooth(0);
break;
case PREF_DEBUG:
debugIsOn = 0;
break;
case PREF_STOPDEBUG:
stopDebug = 0;
break;
case PREF_KEEPPOINTS:
keepPoints = 0;
break;
case PREF_WRAPAROUND:
lutWraparound = false;
break;
case PREF_MAKECHAR:
makeImageCharIfFits = 0;
break;
case PREF_RGBRGB:
RGBdisplaysRGB = 0;
break;
case PREF_FITALL:
fitCharOverAllSamples = 0;
IOBlackBox->flush_minmax_cache();
break;
case PREF_FIT3D:
fitCharOverAllSlices = 0;
IOBlackBox->flush_minmax_cache();
break;
case PREF_SYNCDISP:
syncDisplay = false;
break;
case PREF_HIDEMENU:
hideMainMenu = false;
break;
case PREF_FULLSCREEN:
fullscreen_cb(0,0);
break;
default:
warnprintf("Unknown preference argument %d\n", intarg);
break;
}
}
if (hideMainMenu != currentMenuHideStatus) { // avoid infinite loop
dbgprintf("Hiding menu requested\n");
if (hideMainMenu)
mainWindow->removeMainMenu();
else
mainWindow->addMainMenu();
}
mainMenuBar->redraw();
mainViewer->redraw();
return;
}
void displaymode_cb(Fl_Object *obj, void *arg)
{
long chosenmode = reinterpret_cast<long>(arg);
dbgprintf("Display mode = %ld\n", chosenmode);
mainViewer->setdisplaymode(static_cast<displaymode>(chosenmode));
return;
}
// this acts as a toggle.
void fullscreen_cb(Fl_Object *, void *arg)
{
static bool save_hidemenu_status = false;
static double save_zoomfactor = 1.0;
if (!fullScreen) {
// coming into fullscreen, hide the main menu regardless of user preference
save_hidemenu_status = hideMainMenu;
hidemainmenu_cb(0,0);
} else {
if (!save_hidemenu_status)
// but only restablish it coming out of fs if the user wants the menu.
showmainmenu_cb(0,0);
}
mainViewer->toggle_fullscreen();
if (fullScreen) {
save_zoomfactor = mainViewer->zoomFactor();
mainViewer->applyMaxZoomFactor(); // fill the screen!
} else
mainViewer->setDefaultZoomFactor(save_zoomfactor); // restore previous zoom
dbgprintf("Fullscreen-status is now %s\n", (fullScreen) ? "on":"off");
return;
}
void hidemainmenu_cb(Fl_Object *obj, void *arg)
{
hideMainMenu = true;
mainWindow->removeMainMenu();
appMaxHeight += MENUHEIGHT;
if (arg) {
mainMenuBar->redraw();
mainViewer->redraw();
}
return;
}
void showmainmenu_cb(Fl_Object *obj, void *arg)
{
hideMainMenu = false;
mainWindow->addMainMenu();
appMaxHeight -= MENUHEIGHT;
if (arg) {
mainMenuBar->redraw();
mainViewer->redraw();
}
return;
}
void mode_cb(Fl_Object *obj, void *arg)
{
long intarg;
Fl_Menu_ *m = (Fl_Menu_*)obj;
Fl_Menu_Item* i = (Fl_Menu_Item*)(m->mvalue()); // get the menu item
intarg = (long)(arg);
if (i->value()) {
switch (intarg) {
case MODE_POINTFILE:
mainViewer->setPointMode(true);
break;
}
} else {
switch (intarg) {
case MODE_POINTFILE:
mainViewer->setPointMode(false);
break;
}
}
mainMenuBar->redraw();
mainViewer->redraw();
return;
}
// pointfile management
// open an existing pointfile
void openpointfile_cb(Fl_Object *,void *)
{
static const char *currentfile = 0, *p = 0;
dbgprintf("Opening new point file\n");
p = fl_file_chooser("Open New Point File","*",currentfile);
if (p)
currentfile = p;
if (p == 0) {
dbgprintf("User cancelled choice\n");
} else {
dbgprintf("User chose %s\n", currentfile);
// open a pointfile
PtFileMngr->setPtFileName((char *)currentfile);
// interpret its content
PtFileMngr->readlist();
}
return;
}
void newpointfile_cb(Fl_Object *,void *)
{
static const char *currentfile = 0, *p = 0;
dbgprintf("Opening new point file\n");
p = fl_file_chooser("Open New Point File","*",currentfile);
if (p)
currentfile = p;
if (p == 0) {
dbgprintf("User cancelled choice\n");
} else {
dbgprintf("User chose %s\n", currentfile);
// open a pointfile
PtFileMngr->setPtFileName((char *)currentfile);
}
return;
}
void closepointfile_cb(Fl_Object *,void *)
{
static char buff[300];
dbgprintf("Closing point file\n");
if (PtFileMngr->savelist() == 0) {
int nbpts = PtFileMngr->nbPointsInList();
int nbbrks = PtFileMngr->nbBreaksInList();
const char *pts = (nbpts > 1) ? "points":"point";
const char *brks = (nbbrks > 1) ? "groups":"group";
sprintf(buff, "%d %s in %d %s saved to\n%s\n",
nbpts,
pts,
nbbrks,
brks,
PtFileMngr->getPtFileName());
fl_message((const char *)buff);
}
return;
}
void deleteallpoints_cb(Fl_Object *,void *)
{
PtFileMngr->rmAllPoints();
mainViewer->displayCurrentImage(); // stronger than just redraw
dbgprintf("Deleting all currently defined points\n");
return;
}
void deletelastpoint_cb(Fl_Object *,void *)
{
if (!PtFileMngr->rmSelectedPoints())
PtFileMngr->rmLastPoint(); // delete the last point if none selected
mainViewer->displayCurrentImage();
dbgprintf("Deleting point from pointfile\n");
return;
}
// set the XOR value when drawing a xor line
void setxorvalue_cb(Fl_Object *,void *)
{
static char currxortxt[100];
sprintf(currxortxt, "%#x", PtFileMngr->xorValueForLines());
const char *xortxt = fl_input("Enter xor value", currxortxt);
int newxor = (xortxt != 0) ? (int)strtol(xortxt, 0, 0):PtFileMngr->xorValueForLines();
// minimal check
if (newxor > 0)
PtFileMngr->xorValueForLines(newxor);
else
errprintf("Xor value must be positive\n");
PtFileMngr->xorValueForLines(newxor);
return;
}
// quits the application
void quit_cb(Fl_Object *,void *)
{
// The End.
// imview_exit(0);
main_terminate = true;
}
// never quits the application
void noquit_cb(Fl_Object *,void *)
{
dbgprintf("I will not quit!\n");
// nothing
}
|