| 745 | | namespace osgVolume |
| 746 | | { |
| 747 | | |
| 748 | | class PropertyAdjustmentCallback : public osgGA::GUIEventHandler, public osg::StateSet::Callback |
| 749 | | { |
| 750 | | public: |
| 751 | | |
| 752 | | PropertyAdjustmentCallback() |
| 753 | | { |
| 754 | | _transparencyKey = 't'; |
| 755 | | _alphaFuncKey = 'a'; |
| 756 | | _sampleDensityKey = 'd'; |
| 757 | | |
| 758 | | _updateTransparency = false; |
| 759 | | _updateAlphaCutOff = false; |
| 760 | | _updateSampleDensity = false; |
| 761 | | } |
| 762 | | |
| 763 | | PropertyAdjustmentCallback(const PropertyAdjustmentCallback&,const osg::CopyOp&) {} |
| 764 | | |
| 765 | | META_Object(osgVolume,PropertyAdjustmentCallback); |
| 766 | | |
| 767 | | void setKeyEventActivatesTransparenyAdjustment(int key) { _transparencyKey = key; } |
| 768 | | int getKeyEventActivatesTransparenyAdjustment() const { return _transparencyKey; } |
| 769 | | |
| 770 | | void setKeyEventActivatesSampleDensityAdjustment(int key) { _sampleDensityKey = key; } |
| 771 | | int getKeyEventActivatesSampleAdjustment() const { return _sampleDensityKey; } |
| 772 | | |
| 773 | | void setKeyEventActivatesAlphaFuncAdjustment(int key) { _alphaFuncKey = key; } |
| 774 | | int getKeyEventActivatesAlphaFuncAdjustment() const { return _alphaFuncKey; } |
| 775 | | |
| 776 | | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&, osg::Object* object, osg::NodeVisitor*) |
| 777 | | { |
| 778 | | osgVolume::VolumeTile* tile = dynamic_cast<osgVolume::VolumeTile*>(object); |
| 779 | | osgVolume::Layer* layer = tile ? tile->getLayer() : 0; |
| 780 | | osgVolume::Property* property = layer ? layer->getProperty() : 0; |
| 781 | | if (!property) return false; |
| 782 | | |
| 783 | | osgVolume::CollectPropertiesVisitor cpv; |
| 784 | | property->accept(cpv); |
| 785 | | |
| 786 | | switch(ea.getEventType()) |
| 787 | | { |
| 788 | | case(osgGA::GUIEventAdapter::MOVE): |
| 789 | | case(osgGA::GUIEventAdapter::DRAG): |
| 790 | | { |
| 791 | | float v = (ea.getY()-ea.getYmin())/(ea.getYmax()-ea.getYmin()); |
| 792 | | float v2 = v*v; |
| 793 | | float v4 = v2*v2; |
| 794 | | |
| 795 | | if (_updateAlphaCutOff && cpv._isoProperty.valid()) |
| 796 | | { |
| 797 | | osg::notify(osg::NOTICE)<<"Setting isoProperty to "<<v<<std::endl; |
| 798 | | cpv._isoProperty->setValue(v); |
| 799 | | } |
| 800 | | |
| 801 | | if (_updateAlphaCutOff && cpv._afProperty.valid()) |
| 802 | | { |
| 803 | | osg::notify(osg::NOTICE)<<"Setting afProperty to "<<v2<<std::endl; |
| 804 | | cpv._afProperty->setValue(v2); |
| 805 | | } |
| 806 | | |
| 807 | | if (_updateTransparency && cpv._transparencyProperty.valid()) |
| 808 | | { |
| 809 | | osg::notify(osg::NOTICE)<<"Setting transparency to "<<v2<<std::endl; |
| 810 | | cpv._transparencyProperty->setValue(v2); |
| 811 | | } |
| 812 | | |
| 813 | | if (_updateSampleDensity && cpv._sampleDensityProperty.valid()) |
| 814 | | { |
| 815 | | osg::notify(osg::NOTICE)<<"Setting sample density to "<<v4<<std::endl; |
| 816 | | cpv._sampleDensityProperty->setValue(v4); |
| 817 | | } |
| 818 | | } |
| 819 | | case(osgGA::GUIEventAdapter::KEYDOWN): |
| 820 | | { |
| 821 | | if (ea.getKey()=='t') _updateTransparency = true; |
| 822 | | if (ea.getKey()=='a') _updateAlphaCutOff = true; |
| 823 | | if (ea.getKey()=='d') _updateSampleDensity = true; |
| 824 | | break; |
| 825 | | } |
| 826 | | case(osgGA::GUIEventAdapter::KEYUP): |
| 827 | | { |
| 828 | | if (ea.getKey()=='t') _updateTransparency = false; |
| 829 | | if (ea.getKey()=='a') _updateAlphaCutOff = false; |
| 830 | | if (ea.getKey()=='d') _updateSampleDensity = false; |
| 831 | | break; |
| 832 | | } |
| 833 | | default: |
| 834 | | break; |
| 835 | | } |
| 836 | | return false; |
| 837 | | } |
| 838 | | |
| 839 | | int _transparencyKey; |
| 840 | | int _alphaFuncKey; |
| 841 | | int _sampleDensityKey; |
| 842 | | |
| 843 | | bool _updateTransparency; |
| 844 | | bool _updateAlphaCutOff; |
| 845 | | bool _updateSampleDensity; |
| 846 | | }; |
| 847 | | |
| 848 | | } |