| 1775 | | // not found image, so fallback to plguins/callbacks to find the model. |
| 1776 | | image = osgDB::readImageFile( filename, _options.get() ); |
| 1777 | | if (image) recordOptionsFilePath(_options.get() ); |
| 1778 | | } |
| 1779 | | |
| 1780 | | if (!image) return; |
| 1781 | | |
| 1782 | | osg::ref_ptr<osgVolume::ImageDetails> details = dynamic_cast<osgVolume::ImageDetails*>(image->getUserData()); |
| 1783 | | osg::ref_ptr<osg::RefMatrix> matrix = details ? details->getMatrix() : dynamic_cast<osg::RefMatrix*>(image->getUserData()); |
| 1784 | | |
| 1785 | | osg::ref_ptr<osgVolume::Volume> volume = new osgVolume::Volume; |
| 1786 | | osg::ref_ptr<osgVolume::VolumeTile> tile = new osgVolume::VolumeTile; |
| 1787 | | volume->addChild(tile.get()); |
| 1788 | | |
| 1789 | | osg::ref_ptr<osgVolume::ImageLayer> layer = new osgVolume::ImageLayer(image.get()); |
| 1790 | | if (details) |
| 1791 | | { |
| 1792 | | layer->setTexelOffset(details->getTexelOffset()); |
| 1793 | | layer->setTexelScale(details->getTexelScale()); |
| 1794 | | } |
| 1795 | | layer->rescaleToZeroToOneRange(); |
| 1796 | | |
| 1797 | | if (matrix.valid()) |
| 1798 | | { |
| 1799 | | layer->setLocator(new osgVolume::Locator(*matrix)); |
| 1800 | | osg::Matrix tm = osg::Matrix::scale(volumeData.region[3]-volumeData.region[0], volumeData.region[4]-volumeData.region[1], volumeData.region[5]-volumeData.region[2]) * |
| 1801 | | osg::Matrix::translate(volumeData.region[0],volumeData.region[1],volumeData.region[2]); |
| 1802 | | tile->setLocator(new osgVolume::Locator(tm * (*matrix))); |
| 1803 | | } |
| 1804 | | |
| 1805 | | |
| 1806 | | tile->setLayer(layer.get()); |
| 1807 | | |
| 1808 | | osgVolume::SwitchProperty* sp = new osgVolume::SwitchProperty; |
| 1809 | | sp->setActiveProperty(0); |
| 1810 | | |
| 1811 | | osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(volumeData.cutoffValue); |
| 1812 | | osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(volumeData.alphaValue); |
| 1813 | | osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(volumeData.sampleDensityValue); |
| 1814 | | osgVolume::SampleDensityWhenMovingProperty* sdm = (volumeData.sampleDensityWhenMovingValue > 0.0f) ? (new osgVolume::SampleDensityWhenMovingProperty(volumeData.sampleDensityWhenMovingValue)) : 0; |
| 1815 | | osgVolume::TransferFunctionProperty* tfp = volumeData.transferFunction.valid() ? new osgVolume::TransferFunctionProperty(volumeData.transferFunction.get()) : 0; |
| 1816 | | |
| 1817 | | { |
| 1818 | | // Standard |
| 1819 | | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| 1820 | | cp->addProperty(ap); |
| 1821 | | cp->addProperty(sd); |
| 1822 | | cp->addProperty(tp); |
| 1823 | | if (sdm) cp->addProperty(sdm); |
| 1824 | | if (tfp) cp->addProperty(tfp); |
| 1825 | | |
| 1826 | | sp->addProperty(cp); |
| 1827 | | } |
| 1828 | | |
| 1829 | | { |
| 1830 | | // Light |
| 1831 | | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| 1832 | | cp->addProperty(ap); |
| 1833 | | cp->addProperty(sd); |
| 1834 | | cp->addProperty(tp); |
| 1835 | | cp->addProperty(new osgVolume::LightingProperty); |
| 1836 | | if (sdm) cp->addProperty(sdm); |
| 1837 | | if (tfp) cp->addProperty(tfp); |
| 1838 | | |
| 1839 | | sp->addProperty(cp); |
| 1840 | | } |
| 1841 | | |
| 1842 | | { |
| 1843 | | // Isosurface |
| 1844 | | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| 1845 | | cp->addProperty(sd); |
| 1846 | | cp->addProperty(tp); |
| 1847 | | cp->addProperty(new osgVolume::IsoSurfaceProperty(volumeData.cutoffValue)); |
| 1848 | | if (sdm) cp->addProperty(sdm); |
| 1849 | | if (tfp) cp->addProperty(tfp); |
| 1850 | | |
| 1851 | | sp->addProperty(cp); |
| 1852 | | } |
| 1853 | | |
| 1854 | | { |
| 1855 | | // MaximumIntensityProjection |
| 1856 | | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| 1857 | | cp->addProperty(ap); |
| 1858 | | cp->addProperty(sd); |
| 1859 | | cp->addProperty(tp); |
| 1860 | | cp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); |
| 1861 | | if (sdm) cp->addProperty(sdm); |
| 1862 | | if (tfp) cp->addProperty(tfp); |
| 1863 | | |
| 1864 | | sp->addProperty(cp); |
| 1865 | | } |
| 1866 | | |
| 1867 | | switch(volumeData.shadingModel) |
| 1868 | | { |
| 1869 | | case(VolumeData::Standard): sp->setActiveProperty(0); break; |
| 1870 | | case(VolumeData::Light): sp->setActiveProperty(1); break; |
| 1871 | | case(VolumeData::Isosurface): sp->setActiveProperty(2); break; |
| 1872 | | case(VolumeData::MaximumIntensityProjection): sp->setActiveProperty(3); break; |
| 1873 | | } |
| 1874 | | |
| 1875 | | layer->addProperty(sp); |
| 1876 | | tile->setVolumeTechnique(new osgVolume::RayTracedTechnique); |
| 1877 | | tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback()); |
| 1878 | | |
| | 1787 | osgDB::FileType fileType = osgDB::fileType(foundFile); |
| | 1788 | if (fileType == osgDB::FILE_NOT_FOUND) |
| | 1789 | { |
| | 1790 | foundFile = findFileAndRecordPath(foundFile); |
| | 1791 | fileType = osgDB::fileType(foundFile); |
| | 1792 | } |
| | 1793 | |
| | 1794 | if (fileType == osgDB::DIRECTORY) |
| | 1795 | { |
| | 1796 | image = osgDB::readImageFile(foundFile+".dicom", _options.get()); |
| | 1797 | } |
| | 1798 | else if (fileType == osgDB::REGULAR_FILE) |
| | 1799 | { |
| | 1800 | std::string ext = osgDB::getFileExtension(foundFile); |
| | 1801 | if (ext=="osg" || ext=="ive" || ext=="osgx" || ext=="osgb" || ext=="osgt") |
| | 1802 | { |
| | 1803 | osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(foundFile); |
| | 1804 | image = dynamic_cast<osg::Image*>(obj.get()); |
| | 1805 | volume = dynamic_cast<osgVolume::Volume*>(obj.get()); |
| | 1806 | } |
| | 1807 | else |
| | 1808 | { |
| | 1809 | image = osgDB::readImageFile( foundFile, _options.get() ); |
| | 1810 | } |
| | 1811 | } |
| | 1812 | else |
| | 1813 | { |
| | 1814 | // not found image, so fallback to plguins/callbacks to find the model. |
| | 1815 | image = osgDB::readImageFile( filename, _options.get() ); |
| | 1816 | if (image) recordOptionsFilePath(_options.get() ); |
| | 1817 | } |
| | 1818 | } |
| | 1819 | |
| | 1820 | if (!image && !volume) return; |
| | 1821 | |
| | 1822 | if (volume.valid()) |
| | 1823 | { |
| | 1824 | if (!tile) |
| | 1825 | { |
| | 1826 | if (volume->getNumChildren()>0) |
| | 1827 | { |
| | 1828 | tile = dynamic_cast<osgVolume::VolumeTile*>(volume->getChild(0)); |
| | 1829 | } |
| | 1830 | } |
| | 1831 | } |
| | 1832 | else |
| | 1833 | { |
| | 1834 | volume = new osgVolume::Volume; |
| | 1835 | } |
| | 1836 | |
| | 1837 | if (tile.valid()) |
| | 1838 | { |
| | 1839 | layer = dynamic_cast<osgVolume::ImageLayer*>(tile->getLayer()); |
| | 1840 | image = layer.valid() ? layer->getImage() : 0; |
| | 1841 | } |
| | 1842 | else |
| | 1843 | { |
| | 1844 | if (!image) return; |
| | 1845 | |
| | 1846 | tile = new osgVolume::VolumeTile; |
| | 1847 | volume->addChild(tile.get()); |
| | 1848 | } |
| | 1849 | |
| | 1850 | if (!layer) |
| | 1851 | { |
| | 1852 | if (!image) return; |
| | 1853 | |
| | 1854 | osg::ref_ptr<osgVolume::ImageDetails> details = dynamic_cast<osgVolume::ImageDetails*>(image->getUserData()); |
| | 1855 | osg::ref_ptr<osg::RefMatrix> matrix = details ? details->getMatrix() : dynamic_cast<osg::RefMatrix*>(image->getUserData()); |
| | 1856 | |
| | 1857 | osg::ref_ptr<osgVolume::ImageLayer> layer = new osgVolume::ImageLayer(image.get()); |
| | 1858 | if (details) |
| | 1859 | { |
| | 1860 | layer->setTexelOffset(details->getTexelOffset()); |
| | 1861 | layer->setTexelScale(details->getTexelScale()); |
| | 1862 | } |
| | 1863 | layer->rescaleToZeroToOneRange(); |
| | 1864 | |
| | 1865 | if (matrix.valid()) |
| | 1866 | { |
| | 1867 | layer->setLocator(new osgVolume::Locator(*matrix)); |
| | 1868 | osg::Matrix tm = osg::Matrix::scale(volumeData.region[3]-volumeData.region[0], volumeData.region[4]-volumeData.region[1], volumeData.region[5]-volumeData.region[2]) * |
| | 1869 | osg::Matrix::translate(volumeData.region[0],volumeData.region[1],volumeData.region[2]); |
| | 1870 | tile->setLocator(new osgVolume::Locator(tm * (*matrix))); |
| | 1871 | } |
| | 1872 | |
| | 1873 | |
| | 1874 | tile->setLayer(layer.get()); |
| | 1875 | |
| | 1876 | osgVolume::SwitchProperty* sp = new osgVolume::SwitchProperty; |
| | 1877 | sp->setActiveProperty(0); |
| | 1878 | |
| | 1879 | osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(volumeData.cutoffValue); |
| | 1880 | osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(volumeData.alphaValue); |
| | 1881 | osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(volumeData.sampleDensityValue); |
| | 1882 | osgVolume::SampleDensityWhenMovingProperty* sdm = (volumeData.sampleDensityWhenMovingValue > 0.0f) ? (new osgVolume::SampleDensityWhenMovingProperty(volumeData.sampleDensityWhenMovingValue)) : 0; |
| | 1883 | osgVolume::TransferFunctionProperty* tfp = volumeData.transferFunction.valid() ? new osgVolume::TransferFunctionProperty(volumeData.transferFunction.get()) : 0; |
| | 1884 | |
| | 1885 | { |
| | 1886 | // Standard |
| | 1887 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| | 1888 | cp->addProperty(ap); |
| | 1889 | cp->addProperty(sd); |
| | 1890 | cp->addProperty(tp); |
| | 1891 | if (sdm) cp->addProperty(sdm); |
| | 1892 | if (tfp) cp->addProperty(tfp); |
| | 1893 | |
| | 1894 | sp->addProperty(cp); |
| | 1895 | } |
| | 1896 | |
| | 1897 | { |
| | 1898 | // Light |
| | 1899 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| | 1900 | cp->addProperty(ap); |
| | 1901 | cp->addProperty(sd); |
| | 1902 | cp->addProperty(tp); |
| | 1903 | cp->addProperty(new osgVolume::LightingProperty); |
| | 1904 | if (sdm) cp->addProperty(sdm); |
| | 1905 | if (tfp) cp->addProperty(tfp); |
| | 1906 | |
| | 1907 | sp->addProperty(cp); |
| | 1908 | } |
| | 1909 | |
| | 1910 | { |
| | 1911 | // Isosurface |
| | 1912 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| | 1913 | cp->addProperty(sd); |
| | 1914 | cp->addProperty(tp); |
| | 1915 | cp->addProperty(new osgVolume::IsoSurfaceProperty(volumeData.cutoffValue)); |
| | 1916 | if (sdm) cp->addProperty(sdm); |
| | 1917 | if (tfp) cp->addProperty(tfp); |
| | 1918 | |
| | 1919 | sp->addProperty(cp); |
| | 1920 | } |
| | 1921 | |
| | 1922 | { |
| | 1923 | // MaximumIntensityProjection |
| | 1924 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
| | 1925 | cp->addProperty(ap); |
| | 1926 | cp->addProperty(sd); |
| | 1927 | cp->addProperty(tp); |
| | 1928 | cp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); |
| | 1929 | if (sdm) cp->addProperty(sdm); |
| | 1930 | if (tfp) cp->addProperty(tfp); |
| | 1931 | |
| | 1932 | sp->addProperty(cp); |
| | 1933 | } |
| | 1934 | |
| | 1935 | switch(volumeData.shadingModel) |
| | 1936 | { |
| | 1937 | case(VolumeData::Standard): sp->setActiveProperty(0); break; |
| | 1938 | case(VolumeData::Light): sp->setActiveProperty(1); break; |
| | 1939 | case(VolumeData::Isosurface): sp->setActiveProperty(2); break; |
| | 1940 | case(VolumeData::MaximumIntensityProjection): sp->setActiveProperty(3); break; |
| | 1941 | } |
| | 1942 | |
| | 1943 | layer->addProperty(sp); |
| | 1944 | tile->setVolumeTechnique(new osgVolume::RayTracedTechnique); |
| | 1945 | tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback()); |
| | 1946 | } |