/* osgVisual test. distortionNG, experimental. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "DistortionManipulator.h" #include #include using namespace osg; using namespace osgViewer; DistortionManipulator::DistortionManipulator(DistortionSet* ds) : _highlightColor( osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f) ), _distortionSet( ds ) { activeSetupMode = DISABLED; activeDistortionMode = MESH; activeManualSetupMode = DISTORTION; activeVisualizationMode = NONE; _highlighter = NULL; createVertexHighlighter(); _camera = 0; //_distortionMesh(distortionMesh) } DistortionManipulator::~DistortionManipulator() { } void DistortionManipulator::getUsage(osg::ApplicationUsage& usage) const { usage.addKeyboardMouseBinding("Keypad 7","Show distortion mesh / intensity map / none."); usage.addKeyboardMouseBinding("Keypad 8","Save distortion set."); // via plugin usage.addKeyboardMouseBinding("Keypad 4","Toggles Setup Mode between DISABLED, MANUAL & DELEGATED."); usage.addKeyboardMouseBinding("Keypad 5","MANUAL Mode: Toggle between blending & distortion setup."); usage.addKeyboardMouseBinding("Keypad 6","MANUAL Mode: Toggle if distortion drags affect mesh or rtt texture coordinates."); // Defaults to Mesh usage.addKeyboardMouseBinding("Keypad 1","Reset distortion."); usage.addKeyboardMouseBinding("Keypad 2","Reset intensity blending."); } bool DistortionManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::MOVE): break; case(osgGA::GUIEventAdapter::DRAG): { if ( activeSetupMode == MANUAL) { osg::notify(osg::ALWAYS)<(&aa); if ( viewer ) { osg::notify(osg::ALWAYS)<getDistortionInternals()->setValue(1, true); // per definition #0 = mesh, #1 = highlighter break; } case MANUAL : { activeSetupMode = DELEGATED; _distortionSet->getDistortionInternals()->setValue(1, false); // per definition #0 = mesh, #1 = highlighter OSG_ALWAYS<<"SetupMode DELEGATED activated"<getDistortionInternals()->setValue(1, false); // per definition #0 = mesh, #1 = highlighter OSG_ALWAYS<<"SetupMode DISABLED activated"< defaults to Mesh { activeDistortionMode = (activeDistortionMode==MESH?TEXCOORDINATES:MESH); OSG_ALWAYS<<"KEY_KP_6 : activeDistortionMode is now "< image = _distortionSet->getIntensityMap(); OSG_ALWAYS<<"Reseting IntensityMap Blending."<isDataContiguous()) { OSG_WARN<<"Warning: DistortionManipulator does not support working with non contiguous imagery as blendmaps!"<data(); for(unsigned int i=0;igetTotalSizeInBytes();i++) { *dataPtr++ = 255; } image->dirty(); } void DistortionManipulator::resetDistortion() { if(!_distortionSet.valid()) return; OSG_ALWAYS<<"ToDo: resetDistortion()"<(_stateset->getAttribute(osg::StateAttribute::POLYGONMODE)); if (!polyModeObj) { polyModeObj = new osg::PolygonMode; _stateset->setAttribute(polyModeObj); } if(show) polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); else polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::FILL);*/ } void DistortionManipulator::showIntensityMap(bool show) { OSG_ALWAYS<<"ToDo: showIntensityMap(bool) is now "<setShowIntensityMapOnly(show); } void DistortionManipulator::createVertexHighlighter() { osg::ref_ptr colors = new osg::Vec4Array(1); (*colors)[0] = _highlightColor; _highlighter = new osg::Geometry; _highlighter->setDataVariance( osg::Object::DYNAMIC ); _highlighter->setUseDisplayList( false ); _highlighter->setUseVertexBufferObjects( true ); _highlighter->setVertexArray( new osg::Vec3Array(1) ); // The highlighter vertex is updated by computeSelectedVertex(..) _highlighter->setColorArray( colors.get() ); _highlighter->setColorBinding( osg::Geometry::BIND_OVERALL ); _highlighter->addPrimitiveSet( new osg::DrawArrays(GL_POINTS, 0, 1) ); osg::ref_ptr geode = new osg::Geode; geode->addDrawable( _highlighter.get() ); geode->getOrCreateStateSet()->setAttributeAndModes( new osg::Point(8.0f) ); geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); geode->setCullingActive(false); // disable the culling for the selector, otherwise the selector is culled away on the edge. _distortionSet->getDistortionInternals()->addChild(geode, false); } void DistortionManipulator::computeSelectedVertex( osgUtil::LineSegmentIntersector::Intersection& result ) { osg::Geometry* geom = dynamic_cast( result.drawable.get() ); if ( !geom || geom==_highlighter ) return; osg::Vec3Array* vertices = dynamic_cast( geom->getVertexArray() ); osg::Vec3Array* selVertices = dynamic_cast( _highlighter->getVertexArray() ); if ( !vertices || !selVertices ) return; OSG_NOTIFY(osg::ALWAYS)<<"size of vertices="<size()<