diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-10-16 18:35:17 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-10-16 18:35:17 (GMT) |
commit | 60c543c1d8c6699cc96829f15b16ecc60ac0b410 (patch) | |
tree | f0087f620d45246acf0268da539cb815796d88c0 /src/uscxml/plugins/invoker/graphics/openscenegraph | |
parent | 4d186e24e44fe07f04708c2dc38387534c02c7fd (diff) | |
download | uscxml-60c543c1d8c6699cc96829f15b16ecc60ac0b410.zip uscxml-60c543c1d8c6699cc96829f15b16ecc60ac0b410.tar.gz uscxml-60c543c1d8c6699cc96829f15b16ecc60ac0b410.tar.bz2 |
Added license information and bug fixes
Diffstat (limited to 'src/uscxml/plugins/invoker/graphics/openscenegraph')
6 files changed, 180 insertions, 65 deletions
diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.cpp b/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.cpp index 6d2a8e2..bf4fac7 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.cpp +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.cpp @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #include "CompositeDisplay.h" #if 0 #ifdef MACOSX diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.h b/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.h index b524777..6c2adac 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.h +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/CompositeDisplay.h @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #ifndef COMPOSITEDISPLAY_H_W2MX9CXP #define COMPOSITEDISPLAY_H_W2MX9CXP diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp index d732e63..e4db10a 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #include "OSGInvoker.h" #include "uscxml/URL.h" #include "uscxml/UUID.h" @@ -37,7 +56,7 @@ namespace uscxml { #ifdef BUILD_AS_PLUGINS PLUMA_CONNECTOR -bool connect(pluma::Host& host) { +bool pluginConnect(pluma::Host& host) { host.add( new OSGInvokerProvider() ); return true; } @@ -47,8 +66,8 @@ bool connect(pluma::Host& host) { } else if (boost::iequals(LOCALNAME(childs.item(i)), tagName) && \ validChildren.find(tagName) != validChildren.end()) { \ procFunc(childs.item(i));\ + - OSGInvoker::OSGInvoker() { } @@ -68,7 +87,7 @@ Data OSGInvoker::getDataModelVariables() { void OSGInvoker::send(const SendRequest& req) { if (boost::iequals(req.name, "intersect")) { - + } } @@ -79,9 +98,9 @@ void OSGInvoker::invoke(const InvokeRequest& req) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); setupColors(); - + std::cout << req.dom; - + // register default event handlers Arabica::DOM::Events::EventTarget<std::string> evTarget = Arabica::DOM::Events::EventTarget<std::string>(req.dom); evTarget.addEventListener("DOMSubtreeModified", *this, false); @@ -91,7 +110,7 @@ void OSGInvoker::invoke(const InvokeRequest& req) { std::set<std::string> validChilds; validChilds.insert("display"); - + // this is somewhat unfortunate, if content contains a single child, we will get that, otherwise its parent (<content>) if (boost::iequals(LOCALNAME(req.dom), "display")) { processChildren(validChilds, req.dom.getParentNode()); @@ -121,7 +140,7 @@ void OSGInvoker::setupColors() { _colors["green"] = osg::Vec4(0.0, 0.5, 0.0, 1.0); _colors["olive"] = osg::Vec4(0.5, 0.5, 0.0, 1.0); } - + void OSGInvoker::runOnMainThread() { _displays_t::iterator dispIter = _displays.begin(); if (_mutex.try_lock()) { @@ -184,7 +203,7 @@ void OSGInvoker::processViewport(const Arabica::DOM::Node<std::string>& element) unsigned int actualY = 0; unsigned int actualWidth = 0; unsigned int actualHeight = 0; - + getViewport(element, actualX, actualY, actualWidth, actualHeight, compDisp); osg::Viewport* viewPort = new osg::Viewport(actualX, actualY, actualWidth, actualHeight); compDisp->addView(name, viewPort, sceneView); @@ -196,7 +215,7 @@ void OSGInvoker::processViewport(const Arabica::DOM::Node<std::string>& element) } else { sceneView->getCamera()->setClearColor(_colors["white"]); } - + std::set<std::string> validChilds; validChilds.insert("camera"); validChilds.insert("translation"); @@ -391,11 +410,11 @@ void OSGInvoker::processSphere(const Arabica::DOM::Node<std::string>& element) { float radius = 1; osg::Vec3 center(0,0,0); - + if (HAS_ATTR(element, "radius")) { radius = strTo<float>(ATTR(element, "radius")); } - + osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(center, radius); osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(sphere); osg::ref_ptr<osg::Geode> geode = new osg::Geode(); @@ -415,26 +434,26 @@ void OSGInvoker::updateSphere(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events void OSGInvoker::processBox(const Arabica::DOM::Node<std::string>& element) { assert(_nodes.find(element.getParentNode()) != _nodes.end()); osg::ref_ptr<osg::Node> parent = _nodes[element.getParentNode()]; - + float x = 1; float y = 1; float z = 1; osg::Vec3 center(0,0,0); - + if (HAS_ATTR(element, "x")) x = strTo<float>(ATTR(element, "x")); if (HAS_ATTR(element, "y")) y = strTo<float>(ATTR(element, "y")); if (HAS_ATTR(element, "z")) z = strTo<float>(ATTR(element, "z")); - + osg::ref_ptr<osg::Box> box = new osg::Box(center, x, y, z); osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(box); osg::ref_ptr<osg::Geode> geode = new osg::Geode(); geode->addDrawable(drawable); - + OSG_SET_COLOR; OSG_SET_MATERIAL; _nodes[element] = geode; - + parent->asGroup()->addChild(geode); } @@ -443,19 +462,19 @@ void OSGInvoker::updateBox(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::E void OSGInvoker::processCapsule(const Arabica::DOM::Node<std::string>& element) { assert(_nodes.find(element.getParentNode()) != _nodes.end()); osg::ref_ptr<osg::Node> parent = _nodes[element.getParentNode()]; - + float radius = 1; float height = 1; osg::Vec3 center(0,0,0); - + if (HAS_ATTR(element, "radius")) radius = strTo<float>(ATTR(element, "radius")); if (HAS_ATTR(element, "height")) height = strTo<float>(ATTR(element, "height")); - + osg::ref_ptr<osg::Capsule> capsule = new osg::Capsule(center, radius, height); osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(capsule); osg::ref_ptr<osg::Geode> geode = new osg::Geode(); geode->addDrawable(drawable); - + OSG_SET_COLOR; OSG_SET_MATERIAL; @@ -464,28 +483,28 @@ void OSGInvoker::processCapsule(const Arabica::DOM::Node<std::string>& element) } void OSGInvoker::updateCapsule(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event) { } - + void OSGInvoker::processCone(const Arabica::DOM::Node<std::string>& element) { assert(_nodes.find(element.getParentNode()) != _nodes.end()); osg::ref_ptr<osg::Node> parent = _nodes[element.getParentNode()]; - + float radius = 1; float height = 1; osg::Vec3 center(0,0,0); - + if (HAS_ATTR(element, "radius")) radius = strTo<float>(ATTR(element, "radius")); if (HAS_ATTR(element, "height")) height = strTo<float>(ATTR(element, "height")); - + osg::ref_ptr<osg::Cone> cone = new osg::Cone(center, radius, height); osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(cone); osg::ref_ptr<osg::Geode> geode = new osg::Geode(); geode->addDrawable(drawable); - + OSG_SET_COLOR; OSG_SET_MATERIAL; _nodes[element] = geode; - + parent->asGroup()->addChild(geode); } @@ -495,24 +514,24 @@ void OSGInvoker::updateCone(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events:: void OSGInvoker::processCylinder(const Arabica::DOM::Node<std::string>& element) { assert(_nodes.find(element.getParentNode()) != _nodes.end()); osg::ref_ptr<osg::Node> parent = _nodes[element.getParentNode()]; - + float radius = 1; float height = 1; osg::Vec3 center(0,0,0); - + if (HAS_ATTR(element, "radius")) radius = strTo<float>(ATTR(element, "radius")); if (HAS_ATTR(element, "height")) height = strTo<float>(ATTR(element, "height")); - + osg::ref_ptr<osg::Cylinder> cylinder = new osg::Cylinder(center, radius, height); osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(cylinder); osg::ref_ptr<osg::Geode> geode = new osg::Geode(); geode->addDrawable(drawable); - + OSG_SET_COLOR; OSG_SET_MATERIAL; _nodes[element] = geode; - + parent->asGroup()->addChild(geode); } @@ -528,14 +547,15 @@ osg::Vec4 OSGInvoker::getColor(const Arabica::DOM::Node<std::string>& element, c valid = true; return _colors[color]; } - + // otherwise try to parse as rgba values int i; osg::Vec4 colorVec = parseVec4(color, i); - + if (i == 1) { // only a single value was given, interpret as grey value - colorVec[1] = colorVec[2] = colorVec[0]; colorVec[3] = 1.0; + colorVec[1] = colorVec[2] = colorVec[0]; + colorVec[3] = 1.0; valid = true; return colorVec; } @@ -547,7 +567,7 @@ osg::Vec4 OSGInvoker::getColor(const Arabica::DOM::Node<std::string>& element, c return colorVec; } } - + // return empty reference valid = false; return osg::Vec4(); @@ -566,7 +586,7 @@ osg::ref_ptr<osg::Material> OSGInvoker::getMaterial(const Arabica::DOM::Node<std nodeMat->setDiffuse(osg::Material::FRONT, matColor); nodeMat->setDiffuse(osg::Material::BACK, matColor); } - + // translucency if (HAS_ATTR(element, "transparency")) { std::string transparency = ATTR(element, "transparency"); @@ -576,18 +596,18 @@ osg::ref_ptr<osg::Material> OSGInvoker::getMaterial(const Arabica::DOM::Node<std nodeMat->setTransparency(osg::Material::FRONT, trans); nodeMat->setTransparency(osg::Material::BACK, trans); } - + return nodeMat; } osg::Vec4 OSGInvoker::parseVec4(const std::string& coeffs, int& i) { - + // otherwise try to parse as rgba values std::string coeff; std::stringstream coeffSS(coeffs); - + osg::Vec4 vec; - + i = 0; while(std::getline(coeffSS, coeff, ',')) { boost::trim(coeff); @@ -595,13 +615,13 @@ osg::Vec4 OSGInvoker::parseVec4(const std::string& coeffs, int& i) { continue; if (!isNumeric(coeff.c_str(), 10)) continue; - + vec[i] = strTo<float>(coeff); i++; } return vec; } - + void OSGInvoker::processChildren(const std::set<std::string>& validChildren, const Arabica::DOM::Node<std::string>& element) { Arabica::DOM::NodeList<std::string> childs = element.getChildNodes(); for (int i = 0; i < childs.getLength(); ++i) { diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h index 512eecb..cda0ad3 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #ifndef OSGINVOKER_H_H6T4R8HU #define OSGINVOKER_H_H6T4R8HU @@ -115,7 +134,7 @@ protected: void setupColors(); std::map<std::string, osg::Vec4> _colors; typedef std::map<std::string, osg::Vec4> _colors_t; - + tthread::recursive_mutex _mutex; }; diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.cpp b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.cpp index a6f303a..3fbcc36 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.cpp +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.cpp @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #include "OSGConverter.h" #include <glog/logging.h> #include "uscxml/config.h" @@ -34,7 +53,7 @@ namespace uscxml { #ifdef BUILD_AS_PLUGINS PLUMA_CONNECTOR -bool connect(pluma::Host& host) { +bool pluginConnect(pluma::Host& host) { host.add( new OSGConverterProvider() ); return true; } @@ -145,7 +164,7 @@ void OSGConverter::cancel(const std::string sendId) { void OSGConverter::invoke(const InvokeRequest& req) { int nrThreads = 1; - + if (req.params.find("threads") != req.params.end() && isNumeric(req.params.find("threads")->second.atom.c_str(), 10)) { nrThreads = strTo<int>(req.params.find("threads")->second); } @@ -194,8 +213,8 @@ void OSGConverter::process(const SendRequest& req) { bool autoRotate = true; if (req.params.find("autorotate") != req.params.end()) { if (boost::iequals(req.params.find("autorotate")->second.atom, "off") || - boost::iequals(req.params.find("autorotate")->second.atom, "0") || - boost::iequals(req.params.find("autorotate")->second.atom, "false")) { + boost::iequals(req.params.find("autorotate")->second.atom, "0") || + boost::iequals(req.params.find("autorotate")->second.atom, "false")) { autoRotate = false; } } @@ -210,7 +229,7 @@ void OSGConverter::process(const SendRequest& req) { sceneGraph->addChild(model); osgDB::ReaderWriter::WriteResult result; - + osg::ref_ptr<osgDB::ReaderWriter> writer = osgDB::Registry::instance()->getReaderWriterForExtension(format); if(writer.valid()) { std::stringstream ss; @@ -225,7 +244,7 @@ void OSGConverter::process(const SendRequest& req) { return; } } - + /** * If we failed to interpret the extension as another 3D file, try to make a screenshot. */ @@ -273,7 +292,7 @@ void OSGConverter::process(const SendRequest& req) { LOG(ERROR) << "Traits returned with zero dimensions"; return; } - + GLenum pbuffer = gc->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT; viewer.setCameraManipulator(new osgGA::TrackballManipulator()); @@ -289,10 +308,10 @@ void OSGConverter::process(const SendRequest& req) { viewer.getCamera()->setClearColor(osg::Vec4f(1.0f,1.0f,1.0f,1.0f)); viewer.getCamera()->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); viewer.getCameraManipulator()->setByMatrix(osg::Matrix::lookAt(osg::Vec3d(0,0,bs.radius() * (-3.4 * zoom)), // eye - (osg::Vec3d)bs.center(), // center - osg::Vec3d(0,1,0))); // up + (osg::Vec3d)bs.center(), // center + osg::Vec3d(0,1,0))); // up - // viewer.home(); + // viewer.home(); // perform one viewer iteration viewer.realize(); @@ -310,9 +329,9 @@ void OSGConverter::reportSuccess(const SendRequest& req, const Data& content) { std::string format; Event::getParam(req.params, "format", format); - + event.data.compound["mimetype"] = Data(URL::getMimeType(format), Data::VERBATIM); - + if (event.name.length() == 0) event.name = "convert"; event.name += ".success"; @@ -530,11 +549,11 @@ void OSGConverter::dumpMatrix(const osg::Matrix& m) { } void OSGConverter::NameRespectingWriteToFile::operator()(const osg::Image& image, const unsigned int context_id) { - + // std::cout << "NameRespectingWriteToFile" << std::endl; // std::cout << image.s() << std::endl; // std::cout << image.t() << std::endl; - + // write to memory first std::string format; if (_req.params.find("format") != _req.params.end()) { @@ -552,21 +571,21 @@ void OSGConverter::NameRespectingWriteToFile::operator()(const osg::Image& image if (!osgDB::writeImageFile(image, tempFile, op)) { _converter->reportFailure(_req); } - + char* buffer = NULL; size_t length = 0; { std::ifstream file(tempFile.c_str()); - + file.seekg(0, std::ios::end); length = file.tellg(); file.seekg(0, std::ios::beg); buffer = (char*)malloc(length); file.read(buffer, length); } - - std::cout << tempFile << std::endl; - + + std::cout << tempFile << std::endl; + // remove(tempFile.c_str()); // osg::ref_ptr<osgDB::ReaderWriter> writerFormat = osgDB::Registry::instance()->getReaderWriterForExtension(format); // if(!writerFormat.valid()) @@ -577,7 +596,7 @@ void OSGConverter::NameRespectingWriteToFile::operator()(const osg::Image& image std::stringstream ssFormat; osgDB::ReaderWriter::WriteResult res = writerFormat->writeImage(image, ssFormat, op); - + if (_filename.length() > 0) { std::string tmpName = _filename; size_t pathSep = _filename.find_last_of(PATH_SEPERATOR); @@ -589,7 +608,7 @@ void OSGConverter::NameRespectingWriteToFile::operator()(const osg::Image& image std::ofstream outFile(tmpName.c_str()); outFile << ssFormat.str(); } - + if (pathSep != std::string::npos) { int err = rename(tmpName.c_str(), _filename.c_str()); if (err) { @@ -598,7 +617,7 @@ void OSGConverter::NameRespectingWriteToFile::operator()(const osg::Image& image } } #endif - + Data content; content.compound[format] = Data(buffer, length, false); diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.h b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.h index 2bc84a1..7164bb8 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.h +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.h @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #ifndef OSGCONVERTER_H_W09J90F0 #define OSGCONVERTER_H_W09J90F0 |