Changeset 10207
- Timestamp:
- 05/14/09 15:40:02 (4 years ago)
- Location:
- OpenSceneGraph/trunk/applications/present3D
- Files:
-
- 1 added
- 6 modified
-
CMakeLists.txt (modified) (1 diff)
-
PickEventHandler.cpp (modified) (5 diffs)
-
ReaderWriterP3D.cpp (modified) (8 diffs)
-
ReaderWriterPaths.cpp (added)
-
SlideEventHandler.cpp (modified) (6 diffs)
-
SlideShowConstructor.cpp (modified) (20 diffs)
-
SlideShowConstructor.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/applications/present3D/CMakeLists.txt
r10165 r10207 8 8 present3D.cpp 9 9 ReaderWriterP3D.cpp 10 ReaderWriterPaths.cpp 10 11 ReadShowFile.cpp 11 12 ShowEventHandler.cpp -
OpenSceneGraph/trunk/applications/present3D/PickEventHandler.cpp
r10117 r10207 131 131 #endif 132 132 std::string filepath("OSG_FILE_PATH="); 133 133 134 134 bool needDeliminator = false; 135 135 for(osgDB::FilePathList::iterator itr = paths.begin(); … … 146 146 char* path = getenv("PATH"); 147 147 if (path) binpath += path; 148 148 149 149 needDeliminator = true; 150 150 for(osgDB::FilePathList::iterator itr = paths.begin(); … … 159 159 160 160 } 161 #endif 161 #endif 162 162 int result = system(_command.c_str()); 163 164 osg::notify(osg::INFO)<<"system("<<_command<<") result "<<result<<std::endl;163 164 osg::notify(osg::INFO)<<"system("<<_command<<") result "<<result<<std::endl; 165 165 166 166 break; … … 187 187 { 188 188 osg::notify(osg::NOTICE)<<"Requires jump "<<_relativeJump<<", "<<_slideNum<<", "<<_layerNum<<std::endl; 189 189 190 190 if (_relativeJump) 191 191 { … … 198 198 newLayer = 0; 199 199 } 200 200 201 201 osg::notify(osg::NOTICE)<<" jump to "<<newSlide<<", "<<newLayer<<std::endl; 202 202 -
OpenSceneGraph/trunk/applications/present3D/ReaderWriterP3D.cpp
r10125 r10207 114 114 virtual ReadResult readNode(std::istream& fin, const Options* options) const; 115 115 116 ReadResult readNode(osgDB::XmlNode::Input& input, constosgDB::ReaderWriter::Options* options) const;116 ReadResult readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const; 117 117 118 118 void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; … … 871 871 } 872 872 } 873 873 874 874 if (!filenameLeft.empty() && !filenameRight.empty()) 875 875 constructor.addStereoImagePair(filenameLeft,imageDataLeft, 876 filenameRight, imageDataRight,876 filenameRight, imageDataRight, 877 877 positionRead ? positionData : constructor.getImagePositionData()); 878 878 … … 1386 1386 #include <iostream> 1387 1387 1388 1389 struct MyFindFileCallback : public osgDB::FindFileCallback 1390 { 1391 virtual std::string findDataFile(const std::string& filename, const osgDB::Options* options, osgDB::CaseSensitivity caseSensitivity) 1392 { 1393 osg::notify(osg::NOTICE)<<std::endl<<std::endl<<"find file "<<filename<<std::endl; 1394 1395 const osgDB::FilePathList& paths = options ? options->getDatabasePathList() : osgDB::getDataFilePathList(); 1396 1397 for(osgDB::FilePathList::const_iterator itr = paths.begin(); 1398 itr != paths.end(); 1399 ++itr) 1400 { 1401 const std::string& path = *itr; 1402 std::string newpath = osgDB::concatPaths(path, filename); 1403 if (osgDB::containsServerAddress(path)) 1404 { 1405 osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension("curl"); 1406 osg::notify(osg::NOTICE)<<" file on server "<<*itr<<", try path "<<newpath<<std::endl; 1407 osg::notify(osg::NOTICE)<<" we have curl rw= "<<rw<<std::endl; 1408 if (rw && rw->fileExists(newpath, options)) 1409 { 1410 osg::notify(osg::NOTICE)<<" FOUND on server "<<newpath<<std::endl; 1411 return newpath; 1412 } 1413 } 1414 else 1415 { 1416 if(osgDB::fileExists(newpath)) 1417 { 1418 osg::notify(osg::NOTICE)<<" FOUND "<<newpath<<std::endl; 1419 return newpath; 1420 } 1421 } 1422 } 1423 1424 return osgDB::Registry::instance()->findDataFileImplementation(filename, options, caseSensitivity); 1425 } 1426 }; 1427 1428 class OSGDB_EXPORT MyReadFileCallback : public virtual osgDB::ReadFileCallback 1429 { 1430 public: 1431 1432 osgDB::FilePathList _paths; 1433 1434 typedef std::map< std::string, osg::ref_ptr<osg::Object> > ObjectCache; 1435 1436 enum ObjectType 1437 { 1438 OBJECT, 1439 IMAGE, 1440 HEIGHT_FIELD, 1441 NODE, 1442 SHADER 1443 }; 1444 1445 osgDB::ReaderWriter::ReadResult readLocal(ObjectType type, const std::string& filename, const osgDB::Options* options) 1446 { 1447 osg::notify(osg::INFO)<<"Trying local file "<<filename<<std::endl; 1448 1449 switch(type) 1450 { 1451 case(OBJECT): return osgDB::Registry::instance()->readObjectImplementation(filename,options); 1452 case(IMAGE): return osgDB::Registry::instance()->readImageImplementation(filename,options); 1453 case(HEIGHT_FIELD): return osgDB::Registry::instance()->readHeightFieldImplementation(filename,options); 1454 case(NODE): return osgDB::Registry::instance()->readNodeImplementation(filename,options); 1455 case(SHADER): return osgDB::Registry::instance()->readShaderImplementation(filename,options); 1456 } 1457 return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED; 1458 } 1459 1460 1461 osgDB::ReaderWriter::ReadResult readFileCache(ObjectType type, const std::string& filename, const osgDB::Options* options) 1462 { 1463 1464 osgDB::FileCache* fileCache = options ? options->getFileCache() : 0; 1465 if (!fileCache) fileCache = osgDB::Registry::instance()->getFileCache(); 1466 if (!fileCache) return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; 1467 1468 osg::notify(osg::INFO)<<"Trying fileCache "<<filename<<std::endl; 1469 1470 osgDB::ReaderWriter::ReadResult result; 1471 if (fileCache && fileCache->isFileAppropriateForFileCache(filename)) 1472 { 1473 if (fileCache->existsInCache(filename)) 1474 { 1475 switch(type) 1476 { 1477 case(OBJECT): 1478 result = fileCache->readObject(filename, 0); 1479 break; 1480 case(IMAGE): 1481 result = fileCache->readImage(filename, 0); 1482 break; 1483 case(HEIGHT_FIELD): 1484 result = fileCache->readHeightField(filename, 0); 1485 break; 1486 case(NODE): 1487 result = fileCache->readNode(filename,0); 1488 break; 1489 case(SHADER): 1490 result = fileCache->readShader(filename, 0); 1491 break; 1492 } 1493 1494 if (result.success()) 1495 { 1496 osg::notify(osg::INFO)<<" File read from FileCache."<<std::endl; 1497 return result; 1498 } 1499 1500 osg::notify(osg::NOTICE)<<" File in FileCache, but not successfully read"<<std::endl; 1501 } 1502 else 1503 { 1504 osg::notify(osg::INFO)<<" File does not exist in FileCache: "<<fileCache->createCacheFileName(filename)<<std::endl; 1505 } 1506 } 1507 1508 return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; 1509 1510 } 1511 1512 osgDB::ReaderWriter::ReadResult readServer(ObjectType type, const std::string& filename, const osgDB::Options* options) 1513 { 1514 osg::notify(osg::INFO)<<"Trying server file "<<filename<<std::endl; 1515 1516 osgDB::ReaderWriter::ReadResult result; 1517 osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension("curl"); 1518 if (!rw) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED; 1519 1520 switch(type) 1521 { 1522 case(OBJECT): 1523 result = rw->readObject(filename,options); 1524 break; 1525 case(IMAGE): 1526 result = rw->readImage(filename,options); 1527 break; 1528 case(HEIGHT_FIELD): 1529 result = rw->readHeightField(filename,options); 1530 break; 1531 case(NODE): 1532 result = rw->readNode(filename,options); 1533 break; 1534 case(SHADER): 1535 result = rw->readShader(filename,options); 1536 break; 1537 } 1538 1539 if (result.success()) 1540 { 1541 osgDB::FileCache* fileCache = options ? options->getFileCache() : 0; 1542 if (!fileCache) fileCache = osgDB::Registry::instance()->getFileCache(); 1543 1544 if (fileCache && fileCache->isFileAppropriateForFileCache(filename)) 1545 { 1546 switch(type) 1547 { 1548 case(OBJECT): 1549 fileCache->writeObject(*result.getObject(),filename,options); 1550 break; 1551 case(IMAGE): 1552 result.getImage()->setFileName(filename); 1553 fileCache->writeImage(*result.getImage(),filename,options); 1554 break; 1555 case(HEIGHT_FIELD): 1556 fileCache->writeHeightField(*result.getHeightField(),filename,options); 1557 break; 1558 case(NODE): 1559 fileCache->writeNode(*result.getNode(),filename,options); 1560 break; 1561 case(SHADER): 1562 fileCache->writeShader(*result.getShader(),filename,options); 1563 break; 1564 } 1565 } 1566 1567 return result; 1568 } 1569 return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; 1570 } 1571 1572 1573 osgDB::ReaderWriter::ReadResult read(const osgDB::FilePathList& filePathList, ObjectType type, const std::string& filename, const osgDB::Options* options, bool checkLocalFiles) 1574 { 1575 // go look in http paths 1576 for(osgDB::FilePathList::const_iterator itr = filePathList.begin(); 1577 itr != filePathList.end(); 1578 ++itr) 1579 { 1580 const std::string& path = *itr; 1581 std::string newpath = path.empty() ? filename : osgDB::concatPaths(path, filename); 1582 osgDB::ReaderWriter::ReadResult result; 1583 if (osgDB::containsServerAddress(newpath)) 1584 { 1585 if (checkLocalFiles) result = readFileCache(type, newpath, options); 1586 else result = readServer(type, newpath, options); 1587 } 1588 else if (checkLocalFiles && osgDB::fileExists(newpath)) 1589 { 1590 result = readLocal(type, newpath, options); 1591 } 1592 1593 if (result.success()) 1594 { 1595 osg::notify(osg::INFO)<<" inserting object into file cache "<<filename<<", "<<result.getObject()<<std::endl; 1596 _objectCache[filename] = result.getObject(); 1597 1598 options->setPluginStringData("filename",newpath); 1599 return result; 1600 } 1601 } 1602 return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; 1603 } 1604 1605 osgDB::ReaderWriter::ReadResult read(ObjectType type, const std::string& filename, const osgDB::Options* options) 1606 { 1607 osgDB::FileCache* fileCache = options ? options->getFileCache() : 0; 1608 if (!fileCache) fileCache = osgDB::Registry::instance()->getFileCache(); 1609 if (fileCache && !fileCache->isFileAppropriateForFileCache(filename)) fileCache = 0; 1610 1611 osg::notify(osg::INFO)<<"reading file "<<filename<<std::endl; 1612 ObjectCache::iterator itr = _objectCache.find(filename); 1613 if (itr != _objectCache.end()) 1614 { 1615 // object is in cache, just retrieve it. 1616 if (itr->second.valid()) 1617 { 1618 osg::notify(osg::INFO)<<"File retrieved from cache, filename="<<filename<<std::endl; 1619 return itr->second.get(); 1620 } 1621 else 1622 { 1623 osg::notify(osg::INFO)<<"File failed to load previously, won't attempt a second time "<<filename<<std::endl; 1624 return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; 1625 } 1626 } 1627 1628 { 1629 bool checkLocalFiles = true; 1630 osgDB::ReaderWriter::ReadResult result = read(_paths, type, filename, options, checkLocalFiles); 1631 if (result.success()) return result; 1632 1633 if (options && !(options->getDatabasePathList().empty())) 1634 { 1635 result = read(options->getDatabasePathList(), type, filename, options, checkLocalFiles); 1636 if (result.success()) return result; 1637 } 1638 1639 result = read(osgDB::Registry::instance()->getDataFilePathList(), type, filename, options, checkLocalFiles); 1640 if (result.success()) return result; 1641 } 1642 1643 { 1644 bool checkLocalFiles = false; 1645 osgDB::ReaderWriter::ReadResult result = read(_paths, type, filename, options, checkLocalFiles); 1646 if (result.success()) return result; 1647 1648 if (options && !(options->getDatabasePathList().empty())) 1649 { 1650 result = read(options->getDatabasePathList(), type, filename, options, checkLocalFiles); 1651 if (result.success()) return result; 1652 } 1653 1654 result = read(osgDB::Registry::instance()->getDataFilePathList(), type, filename, options, checkLocalFiles); 1655 if (result.success()) return result; 1656 } 1657 1658 _objectCache[filename] = 0; 1659 1660 return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; 1661 } 1662 1663 virtual osgDB::ReaderWriter::ReadResult readObject(const std::string& filename, const osgDB::Options* options) 1664 { 1665 return read(OBJECT, filename, options); 1666 } 1667 1668 virtual osgDB::ReaderWriter::ReadResult readImage(const std::string& filename, const osgDB::Options* options) 1669 { 1670 return read(IMAGE, filename, options); 1671 } 1672 1673 virtual osgDB::ReaderWriter::ReadResult readHeightField(const std::string& filename, const osgDB::Options* options) 1674 { 1675 return read(HEIGHT_FIELD, filename, options); 1676 } 1677 1678 virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& filename, const osgDB::Options* options) 1679 { 1680 return read(NODE, filename, options); 1681 } 1682 1683 virtual osgDB::ReaderWriter::ReadResult readShader(const std::string& filename, const osgDB::Options* options) 1684 { 1685 return read(SHADER, filename, options); 1686 } 1687 1688 protected: 1689 virtual ~MyReadFileCallback() {} 1690 1691 ObjectCache _objectCache; 1692 }; 1693 1388 1694 osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& file, 1389 1695 const osgDB::ReaderWriter::Options* options) const … … 1394 1700 std::string fileName = osgDB::findDataFile( file ); 1395 1701 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 1702 1703 // code for setting up the database path so that internally referenced file are searched for on relative paths. 1704 osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ? static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 1705 local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); 1706 //local_opt->setFindFileCallback(new MyFindFileCallback); 1707 local_opt->setReadFileCallback(new MyReadFileCallback); 1396 1708 1397 1709 osgDB::XmlNode::Input input; … … 1399 1711 input.readAllDataIntoBuffer(); 1400 1712 1401 return readNode(input, options);1713 return readNode(input, local_opt); 1402 1714 } 1403 1715 … … 1408 1720 input.readAllDataIntoBuffer(); 1409 1721 1410 return readNode(input, options); 1411 } 1412 1413 osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, const osgDB::ReaderWriter::Options* options) const 1722 osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ? static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 1723 //local_opt->setFindFileCallback(new MyFindFileCallback); 1724 local_opt->setReadFileCallback(new MyReadFileCallback); 1725 1726 return readNode(input, local_opt); 1727 } 1728 1729 osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const 1414 1730 { 1415 1731 bool readOnlyHoldingPage = options ? options->getOptionString()=="holding_slide" : false; … … 1423 1739 1424 1740 doc->read(input); 1741 1742 1743 osg::notify(osg::NOTICE)<<"P3D parsing"<<std::endl; 1425 1744 1426 1745 // doc->write(std::cout); … … 1451 1770 } 1452 1771 1453 osgPresentation::SlideShowConstructor constructor ;1772 osgPresentation::SlideShowConstructor constructor(options); 1454 1773 1455 1774 osgDB::FilePathList previousPaths = osgDB::getDataFilePathList(); 1456 1775 1457 1776 bool readSlide = false; 1777 1778 1779 for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); 1780 itr != root->children.end(); 1781 ++itr) 1782 { 1783 osgDB::XmlNode* cur = itr->get(); 1784 1785 if (cur->name=="env") 1786 { 1787 char* str = strdup(cur->contents.c_str()); 1788 osg::notify(osg::INFO)<<"putenv("<<str<<")"<<std::endl; 1789 putenv(str); 1790 } 1791 } 1792 1793 std::string pathToPresentation; 1794 MyReadFileCallback* readFileCallback = options ? dynamic_cast<MyReadFileCallback*>(options->getReadFileCallback()) : 0; 1795 1796 if (options && !(options->getDatabasePathList().empty())) 1797 { 1798 pathToPresentation = options->getDatabasePathList().front(); 1799 1800 if (readFileCallback) readFileCallback->_paths.push_front(pathToPresentation); 1801 } 1802 1803 1804 for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); 1805 itr != root->children.end(); 1806 ++itr) 1807 { 1808 osgDB::XmlNode* cur = itr->get(); 1809 1810 if (cur->name == "path") 1811 { 1812 std::string newpath = expandEnvVarsInFileName(cur->contents); 1813 1814 // now check if an absolue or http path 1815 std::string::size_type colonPos = newpath.find_first_of(':'); 1816 std::string::size_type backslashPos = newpath.find_first_of('/'); 1817 std::string::size_type forwardslashPos = newpath.find_first_of('\\'); 1818 bool relativePath = colonPos == std::string::npos && 1819 backslashPos != 0 && 1820 forwardslashPos != 0; 1821 1822 if (relativePath && !pathToPresentation.empty()) 1823 { 1824 newpath = osgDB::concatPaths(pathToPresentation, newpath); 1825 osg::notify(osg::NOTICE)<<"relative path = "<<cur->contents<<", newpath="<<newpath<<std::endl; 1826 } 1827 else 1828 { 1829 osg::notify(osg::NOTICE)<<"absolute path = "<<cur->contents<<", newpath="<<newpath<<std::endl; 1830 } 1831 1832 if (readFileCallback) readFileCallback->_paths.push_back(newpath); 1833 else options->getDatabasePathList().push_back(newpath); 1834 } 1835 } 1836 1458 1837 1459 1838 for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); -
OpenSceneGraph/trunk/applications/present3D/SlideEventHandler.cpp
r10132 r10207 137 137 virtual void setPause(bool pause) 138 138 { 139 osg::AnimationPathCallback* apc = dynamic_cast<osg::AnimationPathCallback*>(_callback.get());140 osgUtil::TransformCallback* tc = dynamic_cast<osgUtil::TransformCallback*>(_callback.get());141 ss3d::AnimationMaterialCallback* amc = dynamic_cast<ss3d::AnimationMaterialCallback*>(_callback.get());142 if (apc)143 {139 osg::AnimationPathCallback* apc = dynamic_cast<osg::AnimationPathCallback*>(_callback.get()); 140 osgUtil::TransformCallback* tc = dynamic_cast<osgUtil::TransformCallback*>(_callback.get()); 141 ss3d::AnimationMaterialCallback* amc = dynamic_cast<ss3d::AnimationMaterialCallback*>(_callback.get()); 142 if (apc) 143 { 144 144 osg::notify(osg::INFO)<<"apc->setPause("<<pause<<")"<<std::endl; 145 145 apc->setPause(pause); 146 }147 if (tc)148 {146 } 147 if (tc) 148 { 149 149 osg::notify(osg::INFO)<<"tc->setPause("<<pause<<")"<<std::endl; 150 150 tc->setPause(pause); 151 }152 if (amc)153 {151 } 152 if (amc) 153 { 154 154 osg::notify(osg::INFO)<<"amc->setPause("<<pause<<")"<<std::endl; 155 155 amc->setPause(pause); 156 }156 } 157 157 } 158 158 159 159 virtual void reset() 160 160 { 161 osg::AnimationPathCallback* apc = dynamic_cast<osg::AnimationPathCallback*>(_callback.get());162 osgUtil::TransformCallback* tc = dynamic_cast<osgUtil::TransformCallback*>(_callback.get());163 ss3d::AnimationMaterialCallback* amc = dynamic_cast<ss3d::AnimationMaterialCallback*>(_callback.get());164 if (apc)165 {161 osg::AnimationPathCallback* apc = dynamic_cast<osg::AnimationPathCallback*>(_callback.get()); 162 osgUtil::TransformCallback* tc = dynamic_cast<osgUtil::TransformCallback*>(_callback.get()); 163 ss3d::AnimationMaterialCallback* amc = dynamic_cast<ss3d::AnimationMaterialCallback*>(_callback.get()); 164 if (apc) 165 { 166 166 apc->reset(); 167 167 apc->update(*_node); 168 }169 if (tc)170 {171 }172 if (amc)173 {168 } 169 if (tc) 170 { 171 } 172 if (amc) 173 { 174 174 amc->reset(); 175 175 amc->update(*_node); 176 }176 } 177 177 } 178 178 … … 221 221 int result = system(itr->c_str()); 222 222 223 osg::notify(osg::INFO)<<"system("<<*itr<<") result "<<result<<std::endl;223 osg::notify(osg::INFO)<<"system("<<*itr<<") result "<<result<<std::endl; 224 224 225 225 double timeForRun = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); … … 267 267 osg::NodeVisitor(tm), 268 268 _operatorList(operatorList) {} 269 270 void apply(osg::Node& node) 271 { 272 if (node.getStateSet()) process(node.getStateSet());273 274 if (node.getUpdateCallback())275 {269 270 void apply(osg::Node& node) 271 { 272 if (node.getStateSet()) process(node.getStateSet()); 273 274 if (node.getUpdateCallback()) 275 { 276 276 _operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback())); 277 }277 } 278 278 279 279 LayerAttributes* la = dynamic_cast<LayerAttributes*>(node.getUserData()); … … 282 282 _operatorList.insert(new LayerAttributesOperator(&node, la)); 283 283 } 284 284 285 285 traverse(node); 286 286 } … … 289 289 { 290 290 apply((osg::Node&)node); 291 292 291 for(unsigned int i=0;i<node.getNumDrawables();++i) 293 292 { … … 309 308 } 310 309 } 311 } 312 310 } 311 313 312 ActiveOperators::OperatorList& _operatorList; 314 313 }; -
OpenSceneGraph/trunk/applications/present3D/SlideShowConstructor.cpp
r10117 r10207 87 87 }; 88 88 89 SlideShowConstructor::SlideShowConstructor() 89 SlideShowConstructor::SlideShowConstructor(const osgDB::ReaderWriter::Options* options): 90 _options(options) 90 91 { 91 92 _slideDistance = osg::DisplaySettings::instance()->getScreenDistance(); … … 322 323 323 324 osg::ref_ptr<osg::Image> image = !_slideBackgroundImageFileName.empty() ? 324 osgDB::readImageFile(_slideBackgroundImageFileName ) :325 osgDB::readImageFile(_slideBackgroundImageFileName, _options.get()) : 325 326 0; 326 327 … … 636 637 FindImageStreamsVisitor(): 637 638 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} 638 639 639 640 virtual void apply(osg::Node& node) 640 641 { 641 if (node.getStateSet())642 {643 process(node.getStateSet());644 }645 traverse(node);646 } 642 if (node.getStateSet()) 643 { 644 process(node.getStateSet()); 645 } 646 traverse(node); 647 } 647 648 648 649 virtual void apply(osg::Geode& node) 649 650 { 650 if (node.getStateSet())651 {652 process(node.getStateSet());653 }654 651 if (node.getStateSet()) 652 { 653 process(node.getStateSet()); 654 } 655 655 656 for(unsigned int i=0;i<node.getNumDrawables();++i) 656 657 { … … 681 682 } 682 683 } 683 684 684 685 }; 685 686 … … 775 776 if (!_currentLayer) addLayer(); 776 777 777 osg::Image* image = osgDB::readImageFile(filename); 778 778 osg::Image* image = osgDB::readImageFile(filename, _options.get()); 779 if (image) recordOptionsFilePath(_options.get()); 780 779 781 if (!image) return; 780 782 … … 889 891 890 892 891 osg::ref_ptr<osg::Image> imageLeft = osgDB::readImageFile(filenameLeft); 892 osg::ref_ptr<osg::Image> imageRight = (filenameRight==filenameLeft) ? imageLeft.get() : osgDB::readImageFile(filenameRight); 893 osg::ref_ptr<osg::Image> imageLeft = osgDB::readImageFile(filenameLeft, _options.get()); 894 if (imageLeft.valid()) recordOptionsFilePath(_options.get()); 895 896 osg::ref_ptr<osg::Image> imageRight = (filenameRight==filenameLeft) ? imageLeft.get() : osgDB::readImageFile(filenameRight, _options.get()); 897 if (imageRight.valid()) recordOptionsFilePath(_options.get()); 893 898 894 899 if (!imageLeft && !imageRight) return; … … 962 967 } 963 968 964 attachTexMat(pictureLeftStateSet, imageDataLeft, s, t, usedTextureRectangle);969 attachTexMat(pictureLeftStateSet, imageDataLeft, s, t, usedTextureRectangle); 965 970 966 971 pictureLeft->addDrawable(pictureLeftQuad); … … 980 985 } 981 986 982 attachTexMat(pictureRightStateSet, imageDataRight, s, t, usedTextureRectangle);987 attachTexMat(pictureRightStateSet, imageDataRight, s, t, usedTextureRectangle); 983 988 984 989 pictureRight->addDrawable(pictureRightQuad); … … 1084 1089 if (!_currentLayer) addLayer(); 1085 1090 1086 osg::Image* image = osgDB::readImageFile(filename );1091 osg::Image* image = osgDB::readImageFile(filename, _options.get()); 1087 1092 1088 1093 osg::notify(osg::INFO)<<"addInteractiveImage("<<filename<<") "<<image<<std::endl; … … 1203 1208 std::string SlideShowConstructor::findFileAndRecordPath(const std::string& filename) 1204 1209 { 1205 std::string foundFile = osgDB::findDataFile(filename );1210 std::string foundFile = osgDB::findDataFile(filename, _options.get()); 1206 1211 if (foundFile.empty()) return foundFile; 1207 1212 … … 1225 1230 void SlideShowConstructor::addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData) 1226 1231 { 1232 osg::notify(osg::INFO)<<"SlideShowConstructor::addModel("<<filename<<")"<<std::endl; 1233 1227 1234 osg::Node* subgraph = 0; 1228 1235 … … 1243 1250 else 1244 1251 { 1245 std::string foundFile = findFileAndRecordPath(filename); 1246 if (foundFile.empty()) return; 1247 1248 subgraph = osgDB::readNodeFile(foundFile); 1249 } 1250 1251 if (!subgraph) return; 1252 1253 addModel(subgraph, positionData, modelData); 1252 subgraph = osgDB::readNodeFile(filename, _options.get()); 1253 if (subgraph) recordOptionsFilePath(_options.get()); 1254 } 1255 1256 if (subgraph) 1257 { 1258 addModel(subgraph, positionData, modelData); 1259 } 1260 1261 osg::notify(osg::INFO)<<"end of SlideShowConstructor::addModel("<<filename<<")"<<std::endl<<std::endl; 1262 1254 1263 } 1255 1264 … … 1315 1324 subgraph = attachMaterialAnimation(subgraph,positionData); 1316 1325 1317 1318 1326 // attached any rotation 1319 1327 if (positionData.rotation[0]!=0.0) … … 1325 1333 osg::Vec3(positionData.rotation[1],positionData.rotation[2],positionData.rotation[3]), 1326 1334 osg::DegreesToRadians(positionData.rotation[0]))); 1327 1335 1328 1336 animation_transform->addChild(subgraph); 1329 1337 1330 1338 osg::notify(osg::INFO)<<"Rotation Matrix "<<animation_transform->getMatrix()<<std::endl; 1331 1339 … … 1339 1347 { 1340 1348 osg::notify(osg::INFO)<<"Have animation path for model"<<std::endl; 1341 1349 1342 1350 osg::Vec3 pivot = positionData.absolute_path ? osg::Vec3(0.0f,0.0f,0.0f) : subgraph->getBound().center(); 1343 1351 1344 1352 osg::AnimationPath* path = animation->getAnimationPath(); 1345 1353 if (positionData.animation_name=="wheel" && (path->getTimeControlPointMap()).size()>=2) … … 1439 1447 if (fileType == osgDB::DIRECTORY) 1440 1448 { 1441 image = osgDB::readImageFile(foundFile+".dicom" );1449 image = osgDB::readImageFile(foundFile+".dicom", _options.get()); 1442 1450 } 1443 1451 else if (fileType == osgDB::REGULAR_FILE) 1444 1452 { 1445 image = osgDB::readImageFile( foundFile ); 1453 image = osgDB::readImageFile( foundFile, _options.get() ); 1454 } 1455 else 1456 { 1457 // not found image, so fallback to plguins/callbacks to find the model. 1458 image = osgDB::readImageFile( filename, _options.get() ); 1459 if (image) recordOptionsFilePath(_options.get() ); 1446 1460 } 1447 1461 … … 1562 1576 if (!positionData.animation_material_filename.empty()) 1563 1577 { 1564 std::string absolute_animation_file_path = osgDB::findDataFile(positionData.animation_material_filename); 1578 #if 0 1579 std::string absolute_animation_file_path = osgDB::findDataFile(positionData.animation_material_filename, _options.get()); 1565 1580 if (!absolute_animation_file_path.empty()) 1566 1581 { … … 1572 1587 } 1573 1588 } 1589 #else 1590 osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(positionData.animation_material_filename, _options.get()); 1591 animationMaterial = dynamic_cast<ss3d::AnimationMaterial*>(object.get()); 1592 #endif 1593 1574 1594 } 1575 1595 else if (!positionData.fade.empty()) … … 1617 1637 } 1618 1638 1619 osg::AnimationPath* SlideShowConstructor::readPivotPath(const std::string& filename) const 1620 { 1621 std::ifstream in(filename.c_str()); 1622 if (!in.eof()) 1623 { 1624 osg::AnimationPath* animation = new osg::AnimationPath; 1625 1626 while (!in.eof()) 1627 { 1628 double time; 1629 osg::Vec3 pivot; 1630 osg::Vec3 position; 1631 float scale; 1632 osg::Quat rotation; 1633 in >> time >> pivot.x() >> pivot.y() >> pivot.z() >> position.x() >> position.y() >> position.z() >> rotation.x() >> rotation.y() >> rotation.z() >> rotation.w() >> scale; 1634 if(!in.eof()) 1639 osg::AnimationPathCallback* SlideShowConstructor::getAnimationPathCallback(const PositionData& positionData) 1640 { 1641 if (!positionData.path.empty()) 1642 { 1643 osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(positionData.path, _options.get()); 1644 osg::AnimationPath* animation = dynamic_cast<osg::AnimationPath*>(object.get()); 1645 if (animation) 1646 { 1647 if (positionData.frame==SlideShowConstructor::SLIDE) 1635 1648 { 1636 osg::Matrix SR = osg::Matrix::scale(scale,scale,scale)* 1637 osg::Matrixf::rotate(rotation); 1638 1639 osg::Matrix invSR; 1640 invSR.invert(SR); 1641 1642 position += (invSR*pivot)*SR; 1643 1644 animation->insert(time,osg::AnimationPath::ControlPoint(position,rotation,osg::Vec3(scale,scale,scale))); 1645 } 1646 } 1647 1648 return animation; 1649 } 1650 return 0; 1651 } 1652 1653 struct RotationPathData 1654 { 1655 RotationPathData(): 1656 time(0.0), 1657 scale(1.0f), 1658 azim(0.0f), 1659 elevation(0.0f) {} 1660 1661 double time; 1662 osg::Vec3 pivot; 1663 osg::Vec3 position; 1664 float scale; 1665 float azim; 1666 float elevation; 1667 1668 void addToPath(osg::AnimationPath* animation) const 1669 { 1670 osg::Quat Rx, Rz, rotation; 1671 1672 Rx.makeRotate(osg::DegreesToRadians(elevation),1.0f,0.0f,0.0f); 1673 Rz.makeRotate(osg::DegreesToRadians(azim),0.0f,0.0f,1.0f); 1674 rotation = Rz * Rx; // note, I believe this is the wrong way round, but I had to put it in this order to fix the Quat properly. 1675 1676 osg::Matrix SR = osg::Matrix::scale(scale,scale,scale)* 1677 osg::Matrixf::rotate(rotation); 1678 1679 osg::Matrix invSR; 1680 invSR.invert(SR); 1681 1682 osg::Vec3 local_position = position + (invSR*pivot)*SR; 1683 1684 animation->insert(time,osg::AnimationPath::ControlPoint(local_position,rotation,osg::Vec3(scale,scale,scale))); 1685 } 1686 1687 }; 1688 osg::AnimationPath* SlideShowConstructor::readRotationPath(const std::string& filename) const 1689 { 1690 std::ifstream in(filename.c_str()); 1691 if (!in.eof()) 1692 { 1693 osg::AnimationPath* animation = new osg::AnimationPath; 1694 1695 RotationPathData prevValue; 1696 bool first = true; 1697 while (!in.eof()) 1698 { 1699 RotationPathData currValue; 1700 in >> currValue.time >> currValue.pivot.x() >> currValue.pivot.y() >> currValue.pivot.z() >> currValue.position.x() >> currValue.position.y() >> currValue.position.z() >> currValue.azim >> currValue.elevation >> currValue.scale; 1701 if(!in.eof()) 1702 { 1703 1704 if (!first) 1649 osg::AnimationPath::TimeControlPointMap& controlPoints = animation->getTimeControlPointMap(); 1650 for(osg::AnimationPath::TimeControlPointMap::iterator itr=controlPoints.begin(); 1651 itr!=controlPoints.end(); 1652 ++itr) 1705 1653 { 1706 1707 unsigned int num = 20; 1708 float dr = 1.0f/(float)num; 1709 float r=dr; 1710 for(unsigned int i=0; 1711 i<num; 1712 ++i, r+=dr) 1713 { 1714 RotationPathData localValue; 1715 localValue.time = currValue.time *r + prevValue.time * (1.0f-r); 1716 localValue.pivot = currValue.pivot *r + prevValue.pivot * (1.0f-r); 1717 localValue.position = currValue.position *r + prevValue.position * (1.0f-r); 1718 localValue.scale = currValue.scale *r + prevValue.scale * (1.0f-r); 1719 localValue.azim = currValue.azim *r + prevValue.azim * (1.0f-r); 1720 localValue.elevation = currValue.elevation *r + prevValue.elevation * (1.0f-r); 1721 1722 localValue.addToPath(animation); 1723 } 1724 } 1725 else 1726 { 1727 currValue.addToPath(animation); 1728 } 1729 prevValue = currValue; 1730 first = false; 1731 } 1732 1733 } 1734 1735 return animation; 1736 } 1737 return 0; 1738 } 1739 1740 osg::AnimationPathCallback* SlideShowConstructor::getAnimationPathCallback(const PositionData& positionData) 1741 { 1742 if (!positionData.path.empty()) 1743 { 1744 std::string absolute_animation_file_path = osgDB::findDataFile(positionData.path); 1745 if (!absolute_animation_file_path.empty()) 1746 { 1747 1748 osg::AnimationPath* animation = 0; 1749 1750 std::string extension = osgDB::getLowerCaseFileExtension(absolute_animation_file_path); 1751 if (osgDB::equalCaseInsensitive(extension,"pivot_path")) 1752 { 1753 animation = readPivotPath(absolute_animation_file_path); 1754 } 1755 else if (osgDB::equalCaseInsensitive(extension,"rotation_path")) 1756 { 1757 animation = readRotationPath(absolute_animation_file_path); 1758 } 1759 else if (osgDB::equalCaseInsensitive(extension,"path")) 1760 { 1761 std::ifstream animation_filestream(absolute_animation_file_path.c_str()); 1762 if (!animation_filestream.eof()) 1763 { 1764 animation = new osg::AnimationPath; 1765 animation->read(animation_filestream); 1654 osg::AnimationPath::ControlPoint& cp = itr->second; 1655 cp.setPosition(convertSlideToModel(cp.getPosition()+positionData.position)); 1766 1656 } 1767 1657 } 1768 else 1769 { 1770 std::ifstream animation_filestream(absolute_animation_file_path.c_str()); 1771 1772 osgDB::Input fr; 1773 fr.attach(&animation_filestream); 1774 1775 static osg::ref_ptr<osg::AnimationPath> s_path = new osg::AnimationPath; 1776 osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(absolute_animation_file_path); // fr.readObjectOfType(*s_path); 1777 object = fr.readObject(); // fr.readObjectOfType(*s_path); 1778 if (object.valid()) 1779 { 1780 animation = dynamic_cast<osg::AnimationPath*>(object.get()); 1781 } 1782 } 1783 1784 if (animation) 1785 { 1786 if (positionData.frame==SlideShowConstructor::SLIDE) 1787 { 1788 osg::AnimationPath::TimeControlPointMap& controlPoints = animation->getTimeControlPointMap(); 1789 for(osg::AnimationPath::TimeControlPointMap::iterator itr=controlPoints.begin(); 1790 itr!=controlPoints.end(); 1791 ++itr) 1792 { 1793 osg::AnimationPath::ControlPoint& cp = itr->second; 1794 cp.setPosition(convertSlideToModel(cp.getPosition()+positionData.position)); 1795 } 1796 } 1797 1798 animation->setLoopMode(positionData.path_loop_mode); 1799 1800 osg::AnimationPathCallback* apc = new osg::AnimationPathCallback(animation); 1801 apc->setTimeOffset(positionData.path_time_offset); 1802 apc->setTimeMultiplier(positionData.path_time_multiplier); 1803 apc->setUseInverseMatrix(positionData.inverse_path); 1804 1805 osg::notify(osg::INFO)<<"UseInverseMatrix "<<positionData.inverse_path<<std::endl; 1806 1807 return apc; 1808 1809 } 1810 } 1658 1659 animation->setLoopMode(positionData.path_loop_mode); 1660 1661 osg::AnimationPathCallback* apc = new osg::AnimationPathCallback(animation); 1662 apc->setTimeOffset(positionData.path_time_offset); 1663 apc->setTimeMultiplier(positionData.path_time_multiplier); 1664 apc->setUseInverseMatrix(positionData.inverse_path); 1665 1666 osg::notify(osg::INFO)<<"UseInverseMatrix "<<positionData.inverse_path<<std::endl; 1667 1668 return apc; 1669 1670 } 1671 1811 1672 } 1812 1673 return 0; 1813 1674 } 1814 1815 1816 1675 1817 1676 osg::Vec3 SlideShowConstructor::computePositionInModelCoords(const PositionData& positionData) const … … 1852 1711 } 1853 1712 } 1713 1714 void SlideShowConstructor::recordOptionsFilePath(const osgDB::Options* options) 1715 { 1716 if (options) 1717 { 1718 std::string filename_used = _options->getPluginStringData("filename"); 1719 std::string path = osgDB::getFilePath(filename_used); 1720 if (!path.empty() && _filePathData.valid()) 1721 { 1722 osgDB::FilePathList::iterator itr = std::find(_filePathData->filePathList.begin(),_filePathData->filePathList.end(),path); 1723 if (itr==_filePathData->filePathList.end()) 1724 { 1725 osg::notify(osg::INFO)<<"SlideShowConstructor::recordOptionsFilePath(..) - new path to record path="<<path<<" filename_used="<<filename_used<<std::endl; 1726 _filePathData->filePathList.push_front(path); 1727 } 1728 } 1729 } 1730 } 1731 -
OpenSceneGraph/trunk/applications/present3D/SlideShowConstructor.h
r10117 r10207 115 115 struct PositionData 116 116 { 117 PositionData():117 PositionData(): 118 118 frame(SlideShowConstructor::SLIDE), 119 119 position(0.0f,1.0f,0.0f), … … 123 123 rotation(0.0f,0.0f,1.0f,0.0f), 124 124 absolute_path(false), 125 inverse_path(false),125 inverse_path(false), 126 126 path_time_offset(0.0), 127 127 path_time_multiplier(1.0f), … … 156 156 } 157 157 158 CoordinateFrame frame;159 osg::Vec3 position;160 osg::Vec3 scale;161 osg::Vec4 rotate;162 osg::Vec4 rotation;158 CoordinateFrame frame; 159 osg::Vec3 position; 160 osg::Vec3 scale; 161 osg::Vec4 rotate; 162 osg::Vec4 rotation; 163 163 std::string animation_name; 164 bool absolute_path;165 bool inverse_path;164 bool absolute_path; 165 bool inverse_path; 166 166 double path_time_offset; 167 167 double path_time_multiplier; 168 168 osg::AnimationPath::LoopMode path_loop_mode; 169 std::string path;169 std::string path; 170 170 double animation_material_time_offset; 171 171 double animation_material_time_multiplier; 172 172 ss3d::AnimationMaterial::LoopMode animation_material_loop_mode; 173 std::string animation_material_filename;174 std::string fade;173 std::string animation_material_filename; 174 std::string fade; 175 175 }; 176 176 … … 207 207 struct FontData 208 208 { 209 FontData():210 font("fonts/arial.ttf"),211 layout(osgText::Text::LEFT_TO_RIGHT),212 alignment(osgText::Text::LEFT_BASE_LINE),213 axisAlignment(osgText::Text::XZ_PLANE),214 characterSize(0.04f),215 maximumHeight(1.0f),216 maximumWidth(1.0f),217 color(1.0f,1.0f,1.0f,1.0f) {}218 219 std::stringfont;220 osgText::Text::Layoutlayout;221 osgText::Text::AlignmentTypealignment;222 osgText::Text::AxisAlignmentaxisAlignment;223 floatcharacterSize;224 floatmaximumHeight;225 floatmaximumWidth;226 osg::Vec4color;209 FontData(): 210 font("fonts/arial.ttf"), 211 layout(osgText::Text::LEFT_TO_RIGHT), 212 alignment(osgText::Text::LEFT_BASE_LINE), 213 axisAlignment(osgText::Text::XZ_PLANE), 214 characterSize(0.04f), 215 maximumHeight(1.0f), 216 maximumWidth(1.0f), 217 color(1.0f,1.0f,1.0f,1.0f) {} 218 219 std::string font; 220 osgText::Text::Layout layout; 221 osgText::Text::AlignmentType alignment; 222 osgText::Text::AxisAlignment axisAlignment; 223 float characterSize; 224 float maximumHeight; 225 float maximumWidth; 226 osg::Vec4 color; 227 227 }; 228 228 229 229 230 SlideShowConstructor( );230 SlideShowConstructor(const osgDB::ReaderWriter::Options* options); 231 231 232 232 void createPresentation(); … … 347 347 osg::Vec3 convertModelToSlide(const osg::Vec3& position) const; 348 348 349 osg::AnimationPath* readPivotPath(const std::string& filename) const;350 osg::AnimationPath* readRotationPath(const std::string& filename) const;351 352 349 osg::AnimationPathCallback* getAnimationPathCallback(const PositionData& positionData); 353 350 … … 361 358 return stateset; 362 359 } 360 361 osg::ref_ptr<const osgDB::ReaderWriter::Options> _options; 363 362 364 363 osg::Vec3 _slideOrigin; … … 412 411 std::string findFileAndRecordPath(const std::string& filename); 413 412 413 void recordOptionsFilePath(const osgDB::Options* options); 414 414 415 }; 415 416
