Changeset 10522
- Timestamp:
- 08/05/09 16:37:56 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 4 modified
-
include/osgPresentation/SlideShowConstructor (modified) (4 diffs)
-
src/osgPlugins/p3d/ReaderWriterP3D.cpp (modified) (3 diffs)
-
src/osgPresentation/CMakeLists.txt (modified) (1 diff)
-
src/osgPresentation/SlideShowConstructor.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgPresentation/SlideShowConstructor
r10396 r10522 20 20 #include <osg/Switch> 21 21 #include <osg/AnimationPath> 22 #include <osg/TransferFunction> 22 23 #include <osg/ImageStream> 23 24 #include <osgText/Text> … … 205 206 }; 206 207 208 struct VolumeData 209 { 210 enum ShadingModel 211 { 212 Standard, 213 Light, 214 Isosurface, 215 MaximumIntensityProjection 216 }; 217 218 VolumeData(): 219 shadingModel(Standard), 220 useTabbedDragger(false), 221 useTrackballDragger(false) {} 222 223 ShadingModel shadingModel; 224 osg::ref_ptr<osg::TransferFunction1D> transferFunction; 225 bool useTabbedDragger; 226 bool useTrackballDragger; 227 }; 228 229 207 230 struct FontData 208 231 { … … 317 340 void addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData); 318 341 319 void addVolume(const std::string& filename, const PositionData& positionData );342 void addVolume(const std::string& filename, const PositionData& positionData, const VolumeData& volumeData); 320 343 321 344 osg::Group* takePresentation() { return _root.release(); } … … 334 357 void setAutoSteppingActive(bool flag = true) { _autoSteppingActive = flag; } 335 358 bool getAutoSteppingActive() const { return _autoSteppingActive; } 359 336 360 337 361 protected: -
OpenSceneGraph/trunk/src/osgPlugins/p3d/ReaderWriterP3D.cpp
r10510 r10522 121 121 void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; 122 122 123 osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename) const; 123 124 void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; 124 125 … … 832 833 } 833 834 834 void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const 835 836 837 osg::TransferFunction1D* ReaderWriterP3DXML::readTransferFunctionFile(const std::string& filename) const 838 { 839 std::string foundFile = osgDB::findDataFile(filename); 840 if (foundFile.empty()) 841 { 842 std::cout<<"Error: could not find transfer function file : "<<filename<<std::endl; 843 return 0; 844 } 845 846 std::cout<<"Reading transfer function "<<filename<<std::endl; 847 848 osg::TransferFunction1D::ColorMap colorMap; 849 osgDB::ifstream fin(foundFile.c_str()); 850 while(fin) 851 { 852 float value, red, green, blue, alpha; 853 fin >> value >> red >> green >> blue >> alpha; 854 if (fin) 855 { 856 std::cout<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"<<std::endl; 857 colorMap[value] = osg::Vec4(red,green,blue,alpha); 858 } 859 } 860 861 if (colorMap.empty()) 862 { 863 std::cout<<"Error: No values read from transfer function file: "<<filename<<std::endl; 864 return 0; 865 } 866 867 osg::TransferFunction1D* tf = new osg::TransferFunction1D; 868 tf->assign(colorMap); 869 870 return tf; 871 } 872 873 874 void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur) const 835 875 { 836 876 … … 838 878 bool positionRead = getProperties(cur,positionData); 839 879 880 osgPresentation::SlideShowConstructor::VolumeData volumeData; 881 882 // check the rendering technique/shading model to use 883 std::string technique; 884 if (getProperty(cur, "technique", technique)) 885 { 886 if (technique=="standard") volumeData.shadingModel = osgPresentation::SlideShowConstructor::VolumeData::Standard; 887 else if (technique=="mip") volumeData.shadingModel = osgPresentation::SlideShowConstructor::VolumeData::MaximumIntensityProjection; 888 else if (technique=="isosurface" || technique=="iso" ) volumeData.shadingModel = osgPresentation::SlideShowConstructor::VolumeData::Isosurface; 889 else if (technique=="light") volumeData.shadingModel = osgPresentation::SlideShowConstructor::VolumeData::Light; 890 } 891 892 // check for any transfer function required 893 std::string transferFunctionFile; 894 if (getProperty(cur, "tf", transferFunctionFile)) 895 { 896 volumeData.transferFunction = readTransferFunctionFile(transferFunctionFile); 897 } 898 899 // check for draggers required 900 std::string dragger; 901 if (getProperty(cur, "dragger", dragger)) 902 { 903 if (dragger=="trackball") 904 { 905 volumeData.useTabbedDragger = false; 906 volumeData.useTrackballDragger = true; 907 } 908 else 909 { 910 volumeData.useTabbedDragger = true; 911 volumeData.useTrackballDragger = false; 912 } 913 } 914 840 915 std::string filename = cur->contents; 841 842 916 if (!filename.empty()) 843 917 { 844 918 constructor.addVolume(filename, 845 positionRead ? positionData : constructor.getModelPositionData()); 919 positionRead ? positionData : constructor.getModelPositionData(), 920 volumeData); 846 921 } 847 922 } -
OpenSceneGraph/trunk/src/osgPresentation/CMakeLists.txt
r10437 r10522 30 30 LINK_INTERNAL(${LIB_NAME} 31 31 osgViewer 32 osgManipulator 32 33 osgVolume 33 34 osgFX -
OpenSceneGraph/trunk/src/osgPresentation/SlideShowConstructor.cpp
r10396 r10522 50 50 #include <osgPresentation/AnimationMaterial> 51 51 #include <osgPresentation/PickEventHandler> 52 53 #include <osgManipulator/TabBoxDragger> 54 #include <osgManipulator/TabPlaneTrackballDragger> 55 #include <osgManipulator/TrackballDragger> 52 56 53 57 using namespace osgPresentation; … … 1430 1434 } 1431 1435 1432 1433 void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& positionData) 1436 class DraggerVolumeTileCallback : public osgManipulator::DraggerCallback 1437 { 1438 public: 1439 1440 DraggerVolumeTileCallback(osgVolume::VolumeTile* volume, osgVolume::Locator* locator): 1441 _volume(volume), 1442 _locator(locator) {} 1443 1444 1445 virtual bool receive(const osgManipulator::MotionCommand& command); 1446 1447 1448 osg::observer_ptr<osgVolume::VolumeTile> _volume; 1449 osg::ref_ptr<osgVolume::Locator> _locator; 1450 1451 osg::Matrix _startMotionMatrix; 1452 1453 osg::Matrix _localToWorld; 1454 osg::Matrix _worldToLocal; 1455 1456 }; 1457 1458 bool DraggerVolumeTileCallback::receive(const osgManipulator::MotionCommand& command) 1459 { 1460 if (!_locator) return false; 1461 1462 switch (command.getStage()) 1463 { 1464 case osgManipulator::MotionCommand::START: 1465 { 1466 // Save the current matrix 1467 _startMotionMatrix = _locator->getTransform(); 1468 1469 // Get the LocalToWorld and WorldToLocal matrix for this node. 1470 osg::NodePath nodePathToRoot; 1471 osgManipulator::computeNodePathToRoot(*_volume,nodePathToRoot); 1472 _localToWorld = _startMotionMatrix * osg::computeLocalToWorld(nodePathToRoot); 1473 _worldToLocal = osg::Matrix::inverse(_localToWorld); 1474 1475 return true; 1476 } 1477 case osgManipulator::MotionCommand::MOVE: 1478 { 1479 // Transform the command's motion matrix into local motion matrix. 1480 osg::Matrix localMotionMatrix = _localToWorld * command.getWorldToLocal() 1481 * command.getMotionMatrix() 1482 * command.getLocalToWorld() * _worldToLocal; 1483 1484 // Transform by the localMotionMatrix 1485 _locator->setTransform(localMotionMatrix * _startMotionMatrix); 1486 1487 // osg::notify(osg::NOTICE)<<"New locator matrix "<<_locator->getTransform()<<std::endl; 1488 1489 return true; 1490 } 1491 case osgManipulator::MotionCommand::FINISH: 1492 { 1493 return true; 1494 } 1495 case osgManipulator::MotionCommand::NONE: 1496 default: 1497 return false; 1498 } 1499 } 1500 1501 void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& positionData, const VolumeData& volumeData) 1434 1502 { 1435 1503 // osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC … … 1473 1541 if (matrix) 1474 1542 { 1475 osgVolume::Locator* locator = new osgVolume::Locator(*matrix); 1476 layer->setLocator(locator); 1477 tile->setLocator(locator); 1543 layer->setLocator(new osgVolume::Locator(*matrix)); 1544 tile->setLocator(new osgVolume::Locator(*matrix)); 1478 1545 } 1479 1546 … … 1488 1555 osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005); 1489 1556 osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0); 1557 osgVolume::TransferFunctionProperty* tfp = volumeData.transferFunction.valid() ? new osgVolume::TransferFunctionProperty(volumeData.transferFunction.get()) : 0; 1490 1558 1491 1559 { … … 1495 1563 cp->addProperty(sd); 1496 1564 cp->addProperty(tp); 1565 if (tfp) cp->addProperty(tfp); 1497 1566 1498 1567 sp->addProperty(cp); … … 1506 1575 cp->addProperty(tp); 1507 1576 cp->addProperty(new osgVolume::LightingProperty); 1577 if (tfp) cp->addProperty(tfp); 1508 1578 1509 1579 sp->addProperty(cp); … … 1516 1586 cp->addProperty(tp); 1517 1587 cp->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc)); 1588 if (tfp) cp->addProperty(tfp); 1518 1589 1519 1590 sp->addProperty(cp); … … 1527 1598 cp->addProperty(tp); 1528 1599 cp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); 1600 if (tfp) cp->addProperty(tfp); 1529 1601 1530 1602 sp->addProperty(cp); 1603 } 1604 1605 switch(volumeData.shadingModel) 1606 { 1607 case(VolumeData::Standard): sp->setActiveProperty(0); break; 1608 case(VolumeData::Light): sp->setActiveProperty(1); break; 1609 case(VolumeData::Isosurface): sp->setActiveProperty(2); break; 1610 case(VolumeData::MaximumIntensityProjection): sp->setActiveProperty(3); break; 1531 1611 } 1532 1612 … … 1535 1615 tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback()); 1536 1616 1617 1618 osg::ref_ptr<osg::Node> model = volume.get(); 1619 1620 if (volumeData.useTabbedDragger || volumeData.useTrackballDragger) 1621 { 1622 osg::ref_ptr<osg::Group> group = new osg::Group; 1623 1624 osg::ref_ptr<osgManipulator::Dragger> dragger; 1625 if (volumeData.useTabbedDragger) 1626 dragger = new osgManipulator::TabBoxDragger; 1627 else 1628 dragger = new osgManipulator::TrackballDragger(); 1629 1630 dragger->setupDefaultGeometry(); 1631 dragger->setHandleEvents(true); 1632 dragger->setActivationModKeyMask(osgGA::GUIEventAdapter::MODKEY_SHIFT); 1633 dragger->addDraggerCallback(new DraggerVolumeTileCallback(tile.get(), tile->getLocator())); 1634 dragger->setMatrix(osg::Matrix::translate(0.5,0.5,0.5)*tile->getLocator()->getTransform()); 1635 1636 1637 group->addChild(dragger.get()); 1638 1639 //dragger->addChild(volume.get()); 1640 1641 group->addChild(volume.get()); 1642 1643 model = group.get(); 1644 } 1645 1646 1647 1537 1648 ModelData modelData; 1538 addModel( volume.get(), positionData, modelData);1649 addModel(model.get(), positionData, modelData); 1539 1650 } 1540 1651
