Show
Ignore:
Timestamp:
09/19/14 12:35:23 (12 days ago)
Author:
robert
Message:

Moved widgets from VolumeEditorWidget? to TransferFunctionWidget?, and widget utilities into WidgetUtils?.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgViewer/View.cpp

    r13202 r13376  
    10631063        camera->setReadBuffer(buffer); 
    10641064        camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); 
    1065         camera->setAllowEventFocus(false); 
     1065        camera->setAllowEventFocus(true); 
    10661066        camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); 
    10671067        //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); 
     
    19571957{ 
    19581958    OSG_INFO<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl; 
    1959  
     1959     
    19601960    float local_x, local_y; 
    19611961    const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); 
     
    19921992} 
    19931993 
     1994 
    19941995const osg::Camera* View::getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const 
    19951996{ 
    19961997    const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); 
    19971998    const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(eventState->getGraphicsContext()); 
    1998  
    19991999    bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS; 
     2000     
     2001    // OSG_NOTICE<<"getCameraContainingPosition("<<x<<", "<<y<<") view_invert_y = "<<view_invert_y<<", Xmin() = "<<eventState->getXmin()<<", Xmax() = "<<eventState->getXmax()<<", Ymin() = "<<eventState->getYmin()<<", Ymax() = "<<eventState->getYmax()<<std::endl; 
    20002002 
    20012003    double epsilon = 0.5; 
    2002  
    2003     if (_camera->getGraphicsContext() && 
    2004         (!gw || _camera->getGraphicsContext()==gw) && 
    2005         _camera->getViewport()) 
    2006     { 
     2004     
     2005        
     2006    // if master camera has graphics context and eventState context matches then assume coordinates refer 
     2007    // to master camera 
     2008    bool masterActive = (_camera->getGraphicsContext()!=0 && _camera->getViewport()); 
     2009    bool eventStateMatchesMaster = (gw!=0) ? _camera->getGraphicsContext()==gw : false;  
     2010     
     2011    if (masterActive && eventStateMatchesMaster) 
     2012    { 
     2013        // OSG_NOTICE<<"Event state matches master"<<std::endl; 
    20072014        const osg::Viewport* viewport = _camera->getViewport(); 
    2008  
    2009         double new_x = x; 
    2010         double new_y = y; 
    2011  
    2012         if (!gw) 
    2013         { 
    2014             new_x = static_cast<double>(_camera->getGraphicsContext()->getTraits()->width) * (x - eventState->getXmin())/(eventState->getXmax()-eventState->getXmin()); 
    2015             new_y = view_invert_y ? 
    2016                        static_cast<double>(_camera->getGraphicsContext()->getTraits()->height) * (1.0 - (y- eventState->getYmin())/(eventState->getYmax()-eventState->getYmin())) : 
    2017                        static_cast<double>(_camera->getGraphicsContext()->getTraits()->height) * (y - eventState->getYmin())/(eventState->getYmax()-eventState->getYmin()); 
    2018         } 
    2019  
    2020         if (viewport && 
    2021             new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) && 
     2015         
     2016        // rescale mouse x,y first to 0 to 1 range 
     2017        double new_x = (x-eventState->getXmin())/(eventState->getXmax()-eventState->getXmin()); 
     2018        double new_y = (y-eventState->getYmin())/(eventState->getYmax()-eventState->getYmin()); 
     2019         
     2020        // flip y if required 
     2021        if (view_invert_y) new_y = 1.0f-new_y; 
     2022         
     2023        // rescale mouse x, y to window dimensions so we can check against master Camera's viewport 
     2024        new_x *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->width); 
     2025        new_y *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->height); 
     2026         
     2027        if (new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) && 
    20222028            new_x < (viewport->x()+viewport->width()-1.0+epsilon) && new_y <= (viewport->y()+viewport->height()-1.0+epsilon) ) 
    20232029        { 
     
    20252031            local_y = new_y; 
    20262032 
    2027             OSG_INFO<<"Returning master camera"<<std::endl; 
     2033            //OSG_NOTICE<<"Returning master camera"<<std::endl; 
    20282034 
    20292035            return _camera.get(); 
    20302036        } 
    2031     } 
    2032  
     2037        else 
     2038        { 
     2039            // OSG_NOTICE<<"master camera viewport not matched."<<std::endl; 
     2040        } 
     2041    } 
     2042     
    20332043    osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix(); 
    20342044 
     
    20892099bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections, osg::Node::NodeMask traversalMask) 
    20902100{ 
    2091     if (!_camera.valid()) return false; 
    2092  
    2093     float local_x, local_y = 0.0; 
     2101    float local_x, local_y; 
    20942102    const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); 
    2095     if (!camera) camera = _camera.get(); 
    2096  
    2097  
    2098     osgUtil::LineSegmentIntersector::CoordinateFrame cf = camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION; 
    2099     osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(cf, local_x, local_y); 
    2100  
    2101 #if 0 
    2102     OSG_NOTICE<<"View::computeIntersections(x="<<x<<", y="<<y<<", local_x="<<local_x<<", local_y="<<local_y<<") "<<cf<<std::endl; 
    2103     OSG_NOTICE<<"  viewport ("<<camera->getViewport()->x()<<","<<camera->getViewport()->y()<<","<<camera->getViewport()->width()<<","<<camera->getViewport()->height()<<")"<<std::endl; 
    2104  
    2105     const osg::GraphicsContext::Traits* traits = camera->getGraphicsContext() ? camera->getGraphicsContext()->getTraits() : 0; 
    2106     if (traits) 
    2107     { 
    2108         OSG_NOTICE<<"  window ("<<traits->x<<","<<traits->y<<","<<traits->width<<","<<traits->height<<")"<<std::endl; 
     2103     
     2104    OSG_NOTICE<<"computeIntersections("<<x<<", "<<y<<") local_x="<<local_x<<", local_y="<<local_y<<std::endl; 
     2105     
     2106    if (camera) return computeIntersections(camera, (camera->getViewport()==0)?osgUtil::Intersector::PROJECTION : osgUtil::Intersector::WINDOW, local_x, local_y, intersections, traversalMask); 
     2107    else return false; 
     2108} 
     2109 
     2110bool View::computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections, osg::Node::NodeMask traversalMask) 
     2111{ 
     2112    float local_x, local_y; 
     2113    const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); 
     2114     
     2115    OSG_NOTICE<<"computeIntersections("<<x<<", "<<y<<") local_x="<<local_x<<", local_y="<<local_y<<std::endl; 
     2116 
     2117    if (camera) return computeIntersections(camera, (camera->getViewport()==0)?osgUtil::Intersector::PROJECTION : osgUtil::Intersector::WINDOW, local_x, local_y, nodePath, intersections, traversalMask); 
     2118    else return false; 
     2119} 
     2120 
     2121bool View::computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) 
     2122{ 
     2123#if 1 
     2124    if (ea.getNumPointerData()>=1) 
     2125    { 
     2126        const osgGA::PointerData* pd = ea.getPointerData(ea.getNumPointerData()-1); 
     2127        const osg::Camera* camera = dynamic_cast<const osg::Camera*>(pd->object.get()); 
     2128        if (camera)  
     2129        { 
     2130            return computeIntersections(camera, osgUtil::Intersector::PROJECTION, pd->getXnormalized(), pd->getYnormalized(), intersections, traversalMask); 
     2131        } 
    21092132    } 
    21102133#endif 
    2111  
     2134    return computeIntersections(ea.getX(), ea.getY(), intersections, traversalMask); 
     2135} 
     2136 
     2137bool View::computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) 
     2138{ 
     2139#if 1 
     2140    if (ea.getNumPointerData()>=1) 
     2141    { 
     2142        const osgGA::PointerData* pd = ea.getPointerData(ea.getNumPointerData()-1); 
     2143        const osg::Camera* camera = dynamic_cast<const osg::Camera*>(pd->object.get()); 
     2144        if (camera)  
     2145        { 
     2146            return computeIntersections(camera, osgUtil::Intersector::PROJECTION, pd->getXnormalized(), pd->getYnormalized(), nodePath, intersections, traversalMask); 
     2147        } 
     2148    } 
     2149#endif 
     2150    return computeIntersections(ea.getX(), ea.getY(), nodePath, intersections, traversalMask); 
     2151} 
     2152 
     2153bool View::computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections, osg::Node::NodeMask traversalMask) 
     2154{ 
     2155    if (!camera) return false; 
     2156 
     2157    osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(cf, x, y); 
    21122158    osgUtil::IntersectionVisitor iv(picker.get()); 
    21132159    iv.setTraversalMask(traversalMask); 
    21142160 
    2115  
    2116 #if 1 
    21172161    const_cast<osg::Camera*>(camera)->accept(iv); 
    2118 #else 
    2119  
    2120     // timing test code paths for comparing KdTree based intersections vs conventional intersections 
    2121  
    2122     iv.setUseKdTreeWhenAvailable(true); 
    2123     iv.setDoDummyTraversal(true); 
    2124  
    2125     const_cast<osg::Camera*>(camera)->accept(iv); 
    2126  
    2127  
    2128     osg::Timer_t before = osg::Timer::instance()->tick(); 
    2129     const_cast<osg::Camera*>(camera)->accept(iv); 
    2130  
    2131     osg::Timer_t after_dummy = osg::Timer::instance()->tick(); 
    2132  
    2133     int intersectsBeforeKdTree = picker->getIntersections().size(); 
    2134  
    2135     iv.setDoDummyTraversal(false); 
    2136     const_cast<osg::Camera*>(camera)->accept(iv); 
    2137     osg::Timer_t after_kdTree_2 = osg::Timer::instance()->tick(); 
    2138  
    2139     int intersectsBeforeConventional = picker->getIntersections().size(); 
    2140  
    2141     iv.setUseKdTreeWhenAvailable(false); 
    2142     const_cast<osg::Camera*>(camera)->accept(iv); 
    2143     osg::Timer_t after = osg::Timer::instance()->tick(); 
    2144  
    2145     int intersectsAfterConventional = picker->getIntersections().size(); 
    2146  
    2147     double timeDummy = osg::Timer::instance()->delta_m(before, after_dummy); 
    2148     double timeKdTree = osg::Timer::instance()->delta_m(after_dummy, after_kdTree_2); 
    2149     double timeConventional = osg::Timer::instance()->delta_m(after_kdTree_2, after); 
    2150  
    2151     OSG_NOTICE<<"Using Dummy                    "<<timeDummy<<std::endl; 
    2152     OSG_NOTICE<<"      KdTrees                  "<<timeKdTree 
    2153                             <<"\tNum intersects = "<<intersectsBeforeConventional-intersectsBeforeKdTree<<std::endl; 
    2154     OSG_NOTICE<<"      KdTrees - Traversal      "<<timeKdTree-timeDummy<<std::endl; 
    2155     OSG_NOTICE<<"      Conventional             "<<timeConventional 
    2156                             <<"\tNum intersects = "<<intersectsAfterConventional-intersectsBeforeConventional<<std::endl; 
    2157     OSG_NOTICE<<"      Conventional - Traversal "<<timeConventional-timeDummy<<std::endl; 
    2158     OSG_NOTICE<<"      Delta                    "<<timeConventional/timeKdTree<<std::endl; 
    2159     OSG_NOTICE<<"      Delta sans Traversal     "<<(timeConventional-timeDummy)/(timeKdTree-timeDummy)<<std::endl; 
    2160     OSG_NOTICE<<std::endl; 
    2161 #endif 
    21622162 
    21632163    if (picker->containsIntersections()) 
     
    21732173} 
    21742174 
    2175 bool View::computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) 
    2176 { 
    2177     if (!_camera.valid() || nodePath.empty()) return false; 
    2178  
    2179     float local_x, local_y = 0.0; 
    2180     const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); 
    2181     if (!camera) camera = _camera.get(); 
     2175bool View::computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) 
     2176{ 
     2177    if (!camera || nodePath.empty()) return false; 
    21822178 
    21832179    osg::Matrixd matrix; 
     
    21932189    double zNear = -1.0; 
    21942190    double zFar = 1.0; 
    2195     if (camera->getViewport()) 
     2191    if (cf==osgUtil::Intersector::WINDOW && camera->getViewport()) 
    21962192    { 
    21972193        matrix.postMult(camera->getViewport()->computeWindowMatrix()); 
     
    22032199    inverse.invert(matrix); 
    22042200 
    2205     osg::Vec3d startVertex = osg::Vec3d(local_x,local_y,zNear) * inverse; 
    2206     osg::Vec3d endVertex = osg::Vec3d(local_x,local_y,zFar) * inverse; 
     2201    osg::Vec3d startVertex = osg::Vec3d(x,y,zNear) * inverse; 
     2202    osg::Vec3d endVertex = osg::Vec3d(x,y,zFar) * inverse; 
    22072203 
    22082204    osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::MODEL, startVertex, endVertex); 
     
    22242220} 
    22252221 
    2226  
    22272222void View::addDevice(osgGA::Device* eventSource) 
    22282223{