| | 1692 | |
| | 1693 | std::string vh_filename; |
| | 1694 | while (arguments.read("--vh", vh_filename)) |
| | 1695 | { |
| | 1696 | std::string raw_filename, transfer_filename; |
| | 1697 | int xdim(0), ydim(0), zdim(0); |
| | 1698 | |
| | 1699 | std::ifstream header(vh_filename.c_str()); |
| | 1700 | if (header) |
| | 1701 | { |
| | 1702 | header >> raw_filename >> transfer_filename >> xdim >> ydim >> zdim >> xSize >> ySize >> zSize; |
| | 1703 | } |
| | 1704 | |
| | 1705 | if (xdim*ydim*zdim==0) |
| | 1706 | { |
| | 1707 | std::cout<<"Error in reading volume header "<<vh_filename<<std::endl; |
| | 1708 | return 1; |
| | 1709 | } |
| | 1710 | |
| | 1711 | if (!raw_filename.empty()) |
| | 1712 | { |
| | 1713 | image_3d = readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename); |
| | 1714 | } |
| | 1715 | |
| | 1716 | if (!transfer_filename.empty()) |
| | 1717 | { |
| | 1718 | std::ifstream fin(transfer_filename.c_str()); |
| | 1719 | if (fin) |
| | 1720 | { |
| | 1721 | osg::TransferFunction1D::ValueMap valueMap; |
| | 1722 | float value = 0.0; |
| | 1723 | while(fin && value<1.0) |
| | 1724 | { |
| | 1725 | float red, green, blue, alpha; |
| | 1726 | fin >> red >> green >> blue >> alpha; |
| | 1727 | if (fin) |
| | 1728 | { |
| | 1729 | std::cout<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"<<std::endl; |
| | 1730 | valueMap[value] = osg::Vec4(red/255.0+0.5,green/255.0+0.5,blue/255.0+0.5,alpha/255.0+0.5); |
| | 1731 | } |
| | 1732 | value += 1/255.0; |
| | 1733 | } |
| | 1734 | |
| | 1735 | if (valueMap.empty()) |
| | 1736 | { |
| | 1737 | std::cout<<"Error: No values read from transfer function file: "<<transfer_filename<<std::endl; |
| | 1738 | return 0; |
| | 1739 | } |
| | 1740 | |
| | 1741 | transferFunction = new osg::TransferFunction1D; |
| | 1742 | transferFunction->assign(valueMap, true); |
| | 1743 | } |
| | 1744 | } |
| | 1745 | |
| | 1746 | } |
| | 1747 | |