void init(osg::Geometry* geom) {
   _geom = geom;
   _array = static_cast<osg::Vec3Array*>(geom->getVertexArray());
   if (!_geom->getNumPrimitiveSets()) {
     _dw = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,0);
     geom->addPrimitiveSet(_dw.get());
   } else {
     _dw = dynamic_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(_geom->getNumPrimitiveSets()-1));
   }
 }
  void GridVisualizationBase::loadImageAsRectangle(osg::ref_ptr<osg::Geode> geode,
						   osg::ref_ptr<osg::Image> image,
						   float pos_x1,float pos_y1,float pos_x2,float pos_y2)const
  {
    if(! (image.valid()))
    {
      std::cout << "Error Loading Texture: Image is not valid " << std::endl;
      exit(0);
    }
    // Create a Geometry object.
    osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
    
    //full color display
    osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
    geom->setColorArray( c.get() );
    geom->setColorBinding( osg::Geometry::BIND_OVERALL );
    c->push_back( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
    
    //set texture coordinates
    osg::ref_ptr<osg::Vec2dArray>  texture_coordinates = new osg::Vec2dArray;
    texture_coordinates->push_back(osg::Vec2d(0,0));
    texture_coordinates->push_back(osg::Vec2d(1,0));
    texture_coordinates->push_back(osg::Vec2d(1,1));
    texture_coordinates->push_back(osg::Vec2d(0,1));
    geom->setTexCoordArray(0, texture_coordinates.get());
    
    // Specify the vertices:
    osg::ref_ptr<osg::Vec3Array>  vertice_array = new osg::Vec3Array;
    vertice_array->push_back(osg::Vec3(pos_x1,pos_y1,0));
    vertice_array->push_back(osg::Vec3(pos_x2,pos_y1,0));
    vertice_array->push_back(osg::Vec3(pos_x2,pos_y2,0));
    vertice_array->push_back(osg::Vec3(pos_x1,pos_y2,0));
    // Associate this set of vertices with the geometry associated with the geode 
    geom->setVertexArray(vertice_array);
   
     // Create a QUAD primitive by specifying the 
     // vertices from our vertex list that make up this QUAD:

    // Add primitive to the geometry
    geom->addPrimitiveSet(new osg::DrawArrays( osg::PrimitiveSet::POLYGON, 0, vertice_array->size() ) );
    
    // Attach the image in a Texture2D object
    osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
    texture->setImage( image.get() );

    osg::StateSet *state = geom->getOrCreateStateSet();
    
    //apply texture to geom
    state->setTextureAttributeAndModes(0, texture.get());
    
    //remove old drawables
    while(geode->removeDrawables(0));
    //add a mew one
    geode->addDrawable(geom.get());  
  }
PropertyReflection* RefosgPolygonOffset::getProperty(const std::string &name) {
	if (name == "_userData") {
		// Getter overloaded, must specify one type
		typedef Referenced * (osg::Object::*getUserDataFN)() ;
		return new GetterSetterProperty<Referenced*, osg::Object>("_userData", _object.get(), (getUserDataFN)&osg::PolygonOffset::getUserData, &osg::PolygonOffset::setUserData);
	}
	if (name == "_units") {
		// Getter overloaded, must specify one type
		typedef float (osg::PolygonOffset::*getUnitsFN)() const;
		// Setter overloaded, must specify one type
		typedef void (osg::PolygonOffset::*setUnitsFN)(float) ;
		return new GetterSetterProperty<float, osg::PolygonOffset>("_units", _object.get(), (getUnitsFN)&osg::PolygonOffset::getUnits, (setUnitsFN)&osg::PolygonOffset::setUnits);
	}
	if (name == "_factor") {
		// Getter overloaded, must specify one type
		typedef float (osg::PolygonOffset::*getFactorFN)() const;
		// Setter overloaded, must specify one type
		typedef void (osg::PolygonOffset::*setFactorFN)(float) ;
		return new GetterSetterProperty<float, osg::PolygonOffset>("_factor", _object.get(), (getFactorFN)&osg::PolygonOffset::getFactor, (setFactorFN)&osg::PolygonOffset::setFactor);
	}
	if (name == "_name") {
		// Getter overloaded, must specify one type
		typedef const std::string & (osg::Object::*getNameFN)() const;
		// Setter overloaded, must specify one type
		typedef void (osg::Object::*setNameFN)(const std::string &) ;
		return new GetterSetterProperty<std::string, osg::Object>("_name", _object.get(), (getNameFN)&osg::PolygonOffset::getName, (setNameFN)&osg::PolygonOffset::setName);
	}
	if (name == "_updateCallback") {
		// Getter overloaded, must specify one type
		typedef osg::StateAttribute::Callback * (osg::StateAttribute::*getUpdateCallbackFN)() ;
		return new GetterSetterProperty<osg::StateAttribute::Callback*, osg::StateAttribute>("_updateCallback", _object.get(), (getUpdateCallbackFN)&osg::PolygonOffset::getUpdateCallback, &osg::PolygonOffset::setUpdateCallback);
	}
	if (name == "_dataVariance") {
		return new GetterSetterEnumProperty<osg::Object::DataVariance, osg::Object>("_dataVariance", _object.get(), &osg::PolygonOffset::getDataVariance, &osg::PolygonOffset::setDataVariance, osg_object_datavariance);
	}
	if (name == "_eventCallback") {
		// Getter overloaded, must specify one type
		typedef osg::StateAttribute::Callback * (osg::StateAttribute::*getEventCallbackFN)() ;
		return new GetterSetterProperty<osg::StateAttribute::Callback*, osg::StateAttribute>("_eventCallback", _object.get(), (getEventCallbackFN)&osg::PolygonOffset::getEventCallback, &osg::PolygonOffset::setEventCallback);
	}
	throw PropertyNotFoundException(name);
}
void ossimPlanetClientThread::removeConnection(osg::ref_ptr<ossimPlanetClientConnection> connection)
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theConnectionListMutex);
   ossimPlanetClientThreadConnectionList::iterator iter = std::find(theClientConnectionList.begin(),
                                                                    theClientConnectionList.end(),
                                                                    connection.get());
   if(iter != theClientConnectionList.end())
   {
      theClientConnectionList.erase(iter);
   }
}
Esempio n. 5
0
bool ossimPlanetViewer::addAnnotation(osg::ref_ptr<ossimPlanetAnnotationLayerNode> annotation)
{
   bool result = false;
   
   if(theAnnotationLayer.valid())
   {
      result = theAnnotationLayer->addChild(annotation.get());
   }
   
   return result;
}
Esempio n. 6
0
void World::setUpViewer() {
    _viewer.setUpViewInWindow( 150.0f, 150.0f, 1024.0f, 768.0f );
    _viewer.setSceneData( _root_node.get() );
    
    _camera = _viewer.getCamera();
//    _camera->setProjectionMatrixAsPerspective( 70.0f, 1024.0f/768.0f, 1.0f, 10000.0f );
//    _camera->setViewMatrixAsLookAt(vec3( 1000.0f, 0.0f, -1000.0f ), vec3( 0.0f, 0.0f, 0.0f ), vec3( 0.0f, 0.0f, -1.0f ) );
    
    _viewer.setCameraManipulator(new osgGA::TrackballManipulator);
    
    _viewer.realize();
}
bool ShaderContainer::addShaderNode( const std::string& name, osg::ref_ptr< osg::Group > node, osg::Group* p_parent )
{
    if ( _shaderNodes.find( name ) != _shaderNodes.end() )
        return false;

    _shaderNodes[ name ] = node;

    if ( p_parent )
        p_parent->addChild( node.get() );

    return true;
}
Esempio n. 8
0
osg::StateSet* getSingletonLightPointSystemSet()
{
    static osg::ref_ptr<osg::StateSet> s_stateset = 0;
    if (!s_stateset)
    {
        s_stateset = new osg::StateSet;
        // force light point nodes to be drawn after everything else by picking a rendering bin number after
        // the transparent bin.
        s_stateset->setRenderBinDetails(20,"DepthSortedBin");
    }
    return s_stateset.get();
}
Esempio n. 9
0
void GL_Window::getTexture(osg::ref_ptr<osg::Image> image){

    if(image != '\0'){
        texture->setImage(image.get());
        stateset->setTextureAttributeAndModes (0, texture.get(), osg::StateAttribute::ON);
    }
    else
    {
        stateset->setTextureAttributeAndModes (0, texture.get(), osg::StateAttribute::OFF);
    }
    redraw();
}
    void onClick( Control* control, int mouseButtonMask ) {
        
        //Remove the add point handler if it's valid
        if (s_addPointHandler.valid())
        {            
            osgEarth::removeEventHandler( s_viewer, s_addPointHandler.get() );
            s_addPointHandler = NULL;
        }        

        if (!s_editor.valid() && s_activeFeature.valid())
        {
            Style* style = _featureGraph->getStyles()->getDefaultStyle();
            if ( style )
            {
                style->get<LineSymbol>()->stroke()->stipple() = 0x00FF;
                _featureGraph->dirty();
            }
            s_editor = new FeatureEditor(s_activeFeature.get(), s_source.get(), s_mapNode.get());
            s_root->addChild( s_editor.get() );
        }
    }
Esempio n. 11
0
 Camera::Camera(osg::ref_ptr<GLContextManager> pContext, osg::ref_ptr<osg::Texture2D> ptex)
     : pContext(pContext),
     ptex(ptex)
 {
     minimalz = 1.0;
     pContext->makeCurrent();
     CHECK_GL();
     fbo = new FBO(GL_TEXTURE_2D, pContext->getTextureID(ptex.get()), ptex->getTextureWidth(), ptex->getTextureHeight());
     fov = 30.0;
     aspectRatio = 4.0 / 3.0;
     bDoublePrecisionMode = false;
 }
Esempio n. 12
0
bool
ShaderGenerator::processText(const osg::StateSet* ss, osg::ref_ptr<osg::StateSet>& replacement)
{
    // do nothing if there's no GLSL support
    if ( !_active )
        return false;

    // Capture the active current state:
    osg::ref_ptr<osg::StateSet> current = static_cast<StateEx*>(_state.get())->capture();

    // check for a real osg::Program. If it exists, bail out so that OSG
    // can use the program already in the graph
    osg::StateAttribute* program = current->getAttribute(osg::StateAttribute::PROGRAM);
    if ( dynamic_cast<osg::Program*>(program) != 0L )
        return false;

    // New state set. We never modify existing statesets.
    replacement = ss ? osg::clone(ss, osg::CopyOp::SHALLOW_COPY) : new osg::StateSet();

    // new VP:
    osg::ref_ptr<VirtualProgram> vp = VirtualProgram::cloneOrCreate(replacement.get());
    
    // give the VP a name if it needs one.
    if ( vp->getName().empty() )
    {
        vp->setName( _name );
    }

    std::string vertSrc =
        "#version " GLSL_VERSION_STR "\n" GLSL_PRECISION "\n"
        "varying " MEDIUMP "vec4 " TEX_COORD_TEXT ";\n"
        "void " VERTEX_FUNCTION "(inout vec4 vertexVIEW)\n"
        "{ \n"
        INDENT TEX_COORD_TEXT " = gl_MultiTexCoord0;\n"
        "} \n";

    std::string fragSrc =
        "#version " GLSL_VERSION_STR "\n" GLSL_PRECISION "\n"
        "uniform sampler2D " SAMPLER_TEXT ";\n"
        "varying " MEDIUMP "vec4 " TEX_COORD_TEXT ";\n"
        "void " FRAGMENT_FUNCTION "(inout vec4 color)\n"
        "{ \n"
        INDENT MEDIUMP "vec4 texel = texture2D(" SAMPLER_TEXT ", " TEX_COORD_TEXT ".xy);\n"
        //INDENT MEDIUMP "vec4 texel = texture2DLod(" SAMPLER_TEXT ", " TEX_COORD_TEXT ".xy, 0.0);\n"
        INDENT "color.a *= texel.a; \n"
        "}\n";

    vp->setFunction( VERTEX_FUNCTION,   vertSrc, ShaderComp::LOCATION_VERTEX_MODEL, 0.5f );
    vp->setFunction( FRAGMENT_FUNCTION, fragSrc, ShaderComp::LOCATION_FRAGMENT_COLORING, 0.5f );
    replacement->getOrCreateUniform( SAMPLER_TEXT, osg::Uniform::SAMPLER_2D )->set( 0 );

    return replacement.valid();
}
Esempio n. 13
0
    osg::ref_ptr<osg::GraphicsContext> QtOsgMixGraphicsWidget::createWidgetContext(
                                                                                   void* parent,
                                                                                   osg::ref_ptr<osg::GraphicsContext::Traits> traits) {
      traits->windowDecoration = false;

#if defined(__APPLE__)
#if defined(USE_COCOA)
      wdata =  new WindowData(WindowData::CreateOnlyView);
      traits->inheritedWindowData = wdata;
      haveNSView = false;
#else
      traits->inheritedWindowData = new WindowData(HIViewGetWindow((HIViewRef)winId()));
#endif
#elif defined(WIN32) && !defined(__CYGWIN__)
      traits->inheritedWindowData = new WindowData((HWND)winId());
#else // all others
      traits->inheritedWindowData = new WindowData(winId());
#endif // __APPLE__

      osg::DisplaySettings* ds = osg::DisplaySettings::instance();
      if (ds->getStereo()) {
        switch(ds->getStereoMode()) {
        case(osg::DisplaySettings::QUAD_BUFFER):
          traits->quadBufferStereo = true;
          break;
        case(osg::DisplaySettings::VERTICAL_INTERLACE):
        case(osg::DisplaySettings::CHECKERBOARD):
        case(osg::DisplaySettings::HORIZONTAL_INTERLACE):
          traits->stencil = 8;
          break;
        default: break;
        }
      }

      osg::ref_ptr<osg::GraphicsContext> gc =
        osg::GraphicsContext::createGraphicsContext(traits.get());

      if (parent) {
        traits->x = ((QWidget*)parent)->x();
        traits->y = ((QWidget*)parent)->y();
        traits->width = ((QWidget*)parent)->width();
        traits->height = ((QWidget*)parent)->height();
      }
      else {
        traits->x = x();
        traits->y = y();
        traits->width = width();
        traits->height = height();
      }

      return gc;
    }
Esempio n. 14
0
void CSVRender::InstanceMode::secondarySelectPressed (osg::ref_ptr<TagBase> tag)
{
    if (tag)
    {
        if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
        {
            // hit an Object, toggle its selection state
            CSVRender::Object* object = objectTag->mObject;
            object->setSelected (!object->getSelected());
            return;
        }
    }
}
Esempio n. 15
0
Registry* 
Registry::instance(bool erase)
{
    static osg::ref_ptr<Registry> s_registry = new Registry;

    if (erase) 
    {   
        s_registry->destruct();
        s_registry = 0;
    }

    return s_registry.get(); // will return NULL on erase
}
    void onClick( Control* control, int mouseButtonMask ) {

        //remove the editor if it's valid
        if (s_editor.valid())
        {
            s_root->removeChild( s_editor.get() );
            s_editor = NULL;

            // Unset the stipple on the line
            Style style = s_featureNode->getStyle();
            style.get<LineSymbol>()->stroke()->stipple().unset();
            s_featureNode->setStyle( style );            
        }

        //Add the new add point handler
        if (!s_addPointHandler.valid())
        {            
            s_addPointHandler = new AddPointHandler( s_featureNode.get() );
            s_addPointHandler->setIntersectionMask( 0x1 );
            s_viewer->addEventHandler( s_addPointHandler.get() );
        }        
    }
Esempio n. 17
0
void ImagePager::requestImageFile(const std::string& fileName, osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* /*framestamp*/, osg::ref_ptr<osg::Referenced>& imageRequest, const osg::Referenced* options)
{

    osgDB::Options* readOptions = dynamic_cast<osgDB::Options*>(const_cast<osg::Referenced*>(options));
    if (!readOptions)
    {
       readOptions = Registry::instance()->getOptions();
    }

    bool alreadyAssigned = dynamic_cast<ImageRequest*>(imageRequest.get()) && (imageRequest->referenceCount()>1);
    if (alreadyAssigned)
    {
        // OSG_NOTICE<<"ImagePager::requestImageFile("<<fileName<<") alreadyAssigned"<<std::endl;
        return;
    }

    osg::ref_ptr<ImageRequest> request = new ImageRequest;
    request->_timeToMergeBy = timeToMergeBy;
    request->_fileName = fileName;
    request->_attachmentPoint = attachmentPoint;
    request->_attachmentIndex = attachmentIndex;
    request->_requestQueue = _readQueue.get();
    request->_readOptions = readOptions;

    imageRequest = request;

    // OSG_NOTICE<<"ImagePager::requestImageFile("<<fileName<<") new request."<<std::endl;

    _readQueue->add(request.get());

    if (!_startThreadCalled)
    {
		#ifndef EMSCRIPTEN
        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_run_mutex);

        if (!_startThreadCalled)
        {
            _startThreadCalled = true;
            _done = false;

            for(ImageThreads::iterator itr = _imageThreads.begin();
                itr != _imageThreads.end();
                ++itr)
            {
                (*itr)->startThread();
            }

        }
		#endif //EMSCRIPTEN
    }
}
Esempio n. 18
0
void MinimalDrawBoundsShadowMap::ViewData::performBoundAnalysis( const osg::Camera& camera )
{
    if( !_projection.valid() )
        return;

    osg::Camera::BufferAttachmentMap & bam 
        = const_cast<osg::Camera&>( camera ).getBufferAttachmentMap();
#if ANALYSIS_DEPTH
    osg::Camera::Attachment & attachment = bam[ osg::Camera::DEPTH_BUFFER ];
#else
    osg::Camera::Attachment & attachment = bam[ osg::Camera::COLOR_BUFFER ];
#endif

    const osg::ref_ptr< osg::Image > image = attachment._image.get();
    if( !image.valid() ) 
        return;

    osg::Matrix m;
    m.invert( *_modellingSpaceToWorldPtr * 
              camera.getViewMatrix() * 
              camera.getProjectionMatrix() );

    m.preMult( osg::Matrix::scale( osg::Vec3( 2.f, 2.f, 2.f ) ) *
               osg::Matrix::translate( osg::Vec3( -1.f, -1.f, -1.f ) ) );

    osg::BoundingBox bb = scanImage( image.get(), m );

    if( getDebugDraw() ) { 
        ConvexPolyhedron p;
        p.setToBoundingBox( bb );
        p.transform( *_modellingSpaceToWorldPtr, 
                 osg::Matrix::inverse( *_modellingSpaceToWorldPtr ) );

        setDebugPolytope( "scan", p,
                      osg::Vec4( 0,0,0,1 ), osg::Vec4( 0,0,0,0.1 ) );
    }

    cutScenePolytope( *_modellingSpaceToWorldPtr, 
                     osg::Matrix::inverse( *_modellingSpaceToWorldPtr ), bb );

    frameShadowCastingCamera( _mainCamera.get(), _camera.get() );

    _projection->set( _camera->getProjectionMatrix( ) );

    BaseClass::ViewData::_texgen->setPlanesFromMatrix(
            _camera->getProjectionMatrix() *
            osg::Matrix::translate(1.0,1.0,1.0) *
            osg::Matrix::scale(0.5,0.5,0.5) );

    updateDebugGeometry( _mainCamera.get(),  _camera.get() );
}
PropertyReflection* RefosgParticleRadialShooter::getProperty(const std::string &name) {
	if (name == "_rot_speed_range") {
		// Setter overloaded, must specify one type
		typedef void (osgParticle::RadialShooter::*setInitialRotationalSpeedRangeFN)(const rangev3 &) ;
		return new GetterSetterProperty<rangev3, osgParticle::RadialShooter>("_rot_speed_range", _object.get(), &osgParticle::RadialShooter::getInitialRotationalSpeedRange, (setInitialRotationalSpeedRangeFN)&osgParticle::RadialShooter::setInitialRotationalSpeedRange);
	}
	if (name == "_userData") {
		// Getter overloaded, must specify one type
		typedef Referenced * (osg::Object::*getUserDataFN)() ;
		return new GetterSetterProperty<Referenced*, osg::Object>("_userData", _object.get(), (getUserDataFN)&osgParticle::RadialShooter::getUserData, &osgParticle::RadialShooter::setUserData);
	}
	if (name == "_phi_range") {
		// Setter overloaded, must specify one type
		typedef void (osgParticle::RadialShooter::*setPhiRangeFN)(const rangef &) ;
		return new GetterSetterProperty<rangef, osgParticle::RadialShooter>("_phi_range", _object.get(), &osgParticle::RadialShooter::getPhiRange, (setPhiRangeFN)&osgParticle::RadialShooter::setPhiRange);
	}
	if (name == "_name") {
		// Getter overloaded, must specify one type
		typedef const std::string & (osg::Object::*getNameFN)() const;
		// Setter overloaded, must specify one type
		typedef void (osg::Object::*setNameFN)(const std::string &) ;
		return new GetterSetterProperty<std::string, osg::Object>("_name", _object.get(), (getNameFN)&osgParticle::RadialShooter::getName, (setNameFN)&osgParticle::RadialShooter::setName);
	}
	if (name == "_theta_range") {
		// Setter overloaded, must specify one type
		typedef void (osgParticle::RadialShooter::*setThetaRangeFN)(const rangef &) ;
		return new GetterSetterProperty<rangef, osgParticle::RadialShooter>("_theta_range", _object.get(), &osgParticle::RadialShooter::getThetaRange, (setThetaRangeFN)&osgParticle::RadialShooter::setThetaRange);
	}
	if (name == "_speed_range") {
		// Setter overloaded, must specify one type
		typedef void (osgParticle::RadialShooter::*setInitialSpeedRangeFN)(const rangef &) ;
		return new GetterSetterProperty<rangef, osgParticle::RadialShooter>("_speed_range", _object.get(), &osgParticle::RadialShooter::getInitialSpeedRange, (setInitialSpeedRangeFN)&osgParticle::RadialShooter::setInitialSpeedRange);
	}
	if (name == "_dataVariance") {
		return new GetterSetterEnumProperty<osg::Object::DataVariance, osg::Object>("_dataVariance", _object.get(), &osgParticle::RadialShooter::getDataVariance, &osgParticle::RadialShooter::setDataVariance, osg_object_datavariance);
	}
	throw PropertyNotFoundException(name);
}
Esempio n. 20
0
Particle_Viewer::Particle_Viewer(int Id, spacePointType_e type, osg::Vec3 initialPosition, osg::ref_ptr<osg::ShapeDrawable> shape)
{
    osg::Vec3 fixPosition = this->fixPosition(initialPosition);

    this->id = Id;
    this->type = type;

    this->particleNode = new osg::Geode;
    particleNode->addDrawable(shape.get());

    this->setPosition(fixPosition);
    this->initialPosition = fixPosition;
    this->addChild(particleNode.get());
}
Esempio n. 21
0
void processLoadedModel(osg::ref_ptr<osg::Node>& loadedModel, int optimizer_options, const std::string& cursorFileName)
{
    if (!loadedModel) return;
    
#if !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)

    // add back in enabling of the GL_ALPHA_TEST to get around the core OSG no longer setting it by default for opaque bins.
    // the alpha test is required for the volume rendering alpha clipping to work.
    loadedModel->getOrCreateStateSet()->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
#endif

    // optimize the scene graph, remove rendundent nodes and state etc.
    osgUtil::Optimizer optimizer;
    optimizer.optimize(loadedModel.get(), optimizer_options);

    if (!cursorFileName.empty())
    {
        osg::ref_ptr<osg::Group> group = new osg::Group;
        group->addChild(loadedModel.get());
        group->addChild(createCursorSubgraph(cursorFileName, 0.05f));
        loadedModel = group;
    }
}
ossim_int32 ossimPlanetTextureLayerGroup::findLayerIndexNoMutex(osg::ref_ptr<ossimPlanetTextureLayer> layer)const
{
   ossim_uint32 idx = 0;
   for(idx = 0; idx < theChildrenList.size(); ++idx)
   {
      if(theChildrenList[idx].get() == layer.get())
      {
         return (ossim_int32)idx;
      }
   }
   
   return -1;
   
}
Esempio n. 23
0
PropertyReflection* RefosgTransform::getProperty(const std::string &name) {
	if (name == "_initialBound") {
		return new GetterSetterProperty<BoundingSphere, osg::Node>("_initialBound", _object.get(), &osg::Transform::getInitialBound, &osg::Transform::setInitialBound);
	}
	if (name == "_userData") {
		// Getter overloaded, must specify one type
		typedef Referenced * (osg::Object::*getUserDataFN)() ;
		return new GetterSetterProperty<Referenced*, osg::Object>("_userData", _object.get(), (getUserDataFN)&osg::Transform::getUserData, &osg::Transform::setUserData);
	}
	if (name == "_nodeMask") {
		return new GetterSetterProperty<osg::Node::NodeMask, osg::Node>("_nodeMask", _object.get(), &osg::Transform::getNodeMask, &osg::Transform::setNodeMask);
	}
	if (name == "_referenceFrame") {
		return new GetterSetterEnumProperty<osg::Transform::ReferenceFrame, osg::Transform>("_referenceFrame", _object.get(), &osg::Transform::getReferenceFrame, &osg::Transform::setReferenceFrame, osg_transform_referenceframe);
	}
	if (name == "_name") {
		// Getter overloaded, must specify one type
		typedef const std::string & (osg::Object::*getNameFN)() const;
		// Setter overloaded, must specify one type
		typedef void (osg::Object::*setNameFN)(const std::string &) ;
		return new GetterSetterProperty<std::string, osg::Object>("_name", _object.get(), (getNameFN)&osg::Transform::getName, (setNameFN)&osg::Transform::setName);
	}
	if (name == "_cullingActive") {
		return new GetterSetterProperty<bool, osg::Node>("_cullingActive", _object.get(), &osg::Transform::getCullingActive, &osg::Transform::setCullingActive);
	}
	if (name == "_dataVariance") {
		return new GetterSetterEnumProperty<osg::Object::DataVariance, osg::Object>("_dataVariance", _object.get(), &osg::Transform::getDataVariance, &osg::Transform::setDataVariance, osg_object_datavariance);
	}
	if (name == "_descriptions") {
		// Getter overloaded, must specify one type
		typedef osg::Node::DescriptionList & (osg::Node::*getDescriptionsFN)() ;
		// Setter overloaded, must specify one type
		typedef void (osg::Node::*setDescriptionsFN)(const osg::Node::DescriptionList &) ;
		return new GetterSetterProperty<osg::Node::DescriptionList, osg::Node>("_descriptions", _object.get(), (getDescriptionsFN)&osg::Transform::getDescriptions, (setDescriptionsFN)&osg::Transform::setDescriptions);
	}
	throw PropertyNotFoundException(name);
}
Esempio n. 24
0
BboxDrawable::BboxDrawable( const osg::BoundingBox& box, const BBoxSymbol &bboxSymbol ) :
osg::Geometry()
{
    setUseVertexBufferObjects(true);

    float margin = bboxSymbol.margin().isSet() ? bboxSymbol.margin().value() : 2.f;
    osg::Vec3Array* v = new osg::Vec3Array();
    if ( bboxSymbol.geom().isSet() && bboxSymbol.geom().value() == BBoxSymbol::GEOM_BOX_ORIENTED )
    {
        float h = box.yMax() - box.yMin() + 2.f * margin;
        v->push_back( osg::Vec3(box.xMax()+margin+h/2.f, box.yMax()+margin-h/2.f, 0) );
    }
    v->push_back( osg::Vec3(box.xMax()+margin, box.yMax()+margin, 0) );
    v->push_back( osg::Vec3(box.xMin()-margin, box.yMax()+margin, 0) );
    v->push_back( osg::Vec3(box.xMin()-margin, box.yMin()-margin, 0) );
    v->push_back( osg::Vec3(box.xMax()+margin, box.yMin()-margin, 0) );
    setVertexArray(v);
    if ( v->getVertexBufferObject() )
        v->getVertexBufferObject()->setUsage(GL_STATIC_DRAW_ARB);

    osg::Vec4Array* c = new osg::Vec4Array();
    if ( bboxSymbol.fill().isSet() )
    {
        c->push_back( bboxSymbol.fill()->color() );
        addPrimitiveSet( new osg::DrawArrays(GL_POLYGON, 0, v->getNumElements()) );
    }

    if ( bboxSymbol.border().isSet() )
    {
        c->push_back( bboxSymbol.border()->color() );
        if ( bboxSymbol.border()->width().isSet() )
            getOrCreateStateSet()->setAttribute( new osg::LineWidth( bboxSymbol.border()->width().value() ));
        addPrimitiveSet( new osg::DrawArrays(GL_LINE_LOOP, 0, v->getNumElements()) );
    }

    setColorArray( c );
    setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE_SET );

    // add the static "isText=true" uniform; this is a hint for the annotation shaders
    // if they get installed.
    static osg::ref_ptr<osg::Uniform> s_isTextUniform = new osg::Uniform(osg::Uniform::BOOL, AnnotationUtils::UNIFORM_IS_TEXT());
    s_isTextUniform->set( false );
    getOrCreateStateSet()->addUniform( s_isTextUniform.get() );

    // Disable culling since this bounding box will eventually be drawn in screen space.
#if OSG_MIN_VERSION_REQUIRED(3,4,0)
    setCullingActive(false);
#endif
}
Esempio n. 25
0
File: main.cpp Progetto: Risca/sgct
void myInitOGLFun()
{
	initOSG();

	osg::ref_ptr<osg::Node>            mModel;
	osg::ref_ptr<osg::MatrixTransform> mModelTrans;

	mSceneTrans		= new osg::MatrixTransform();
	mModelTrans		= new osg::MatrixTransform();

	//rotate osg coordinate system to match sgct
	mModelTrans->preMult(osg::Matrix::rotate(glm::radians(-90.0f),
                                            1.0f, 0.0f, 0.0f));

	mRootNode->addChild( mSceneTrans.get() );
	mSceneTrans->addChild( mModelTrans.get() );

	sgct::MessageHandler::instance()->print("Loading model '../SharedResources/airplane.ive'...\n");
	mModel = osgDB::readNodeFile("../SharedResources/airplane.ive");

	if ( mModel.valid() )
	{
		sgct::MessageHandler::instance()->print("Model loaded successfully!\n");
		mModelTrans->addChild(mModel.get());

		//get the bounding box
		osg::ComputeBoundsVisitor cbv;
		osg::BoundingBox &bb(cbv.getBoundingBox());
		mModel->accept( cbv );

		osg::Vec3f tmpVec;
		tmpVec = bb.center();

		//scale to fit model and translate model center to origin
		mModelTrans->postMult(osg::Matrix::translate( -tmpVec ) );
		mModelTrans->postMult(osg::Matrix::scale( 1.0f/bb.radius(), 1.0f/bb.radius(), 1.0f/bb.radius() ));

		sgct::MessageHandler::instance()->print("Model bounding sphere center:\tx=%f\ty=%f\tz=%f\n", tmpVec[0], tmpVec[1], tmpVec[2] );
		sgct::MessageHandler::instance()->print("Model bounding sphere radius:\t%f\n", bb.radius() );

		//disable face culling
		mModel->getOrCreateStateSet()->setMode( GL_CULL_FACE,
			osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
	}
	else
		sgct::MessageHandler::instance()->print("Failed to read model!\n");

	setupLightSource();
}
PropertyReflection* RefosgShadowShadowMap::getProperty(const std::string &name) {
	if (name == "_ambientBias") {
		return new GetterSetterProperty<osg::Vec2, osgShadow::ShadowMap>("_ambientBias", _object.get(), &osgShadow::ShadowMap::getAmbientBias, &osgShadow::ShadowMap::setAmbientBias);
	}
	if (name == "_dataVariance") {
		return new GetterSetterEnumProperty<osg::Object::DataVariance, osg::Object>("_dataVariance", _object.get(), &osgShadow::ShadowMap::getDataVariance, &osgShadow::ShadowMap::setDataVariance, osg_object_datavariance);
	}
	if (name == "_textureSize") {
		return new GetterSetterProperty<osg::Vec2s, osgShadow::ShadowMap>("_textureSize", _object.get(), &osgShadow::ShadowMap::getTextureSize, &osgShadow::ShadowMap::setTextureSize);
	}
	if (name == "_name") {
		// Getter overloaded, must specify one type
		typedef const std::string & (osg::Object::*getNameFN)() const;
		// Setter overloaded, must specify one type
		typedef void (osg::Object::*setNameFN)(const std::string &) ;
		return new GetterSetterProperty<std::string, osg::Object>("_name", _object.get(), (getNameFN)&osgShadow::ShadowMap::getName, (setNameFN)&osgShadow::ShadowMap::setName);
	}
	if (name == "_userData") {
		// Getter overloaded, must specify one type
		typedef Referenced * (osg::Object::*getUserDataFN)() ;
		return new GetterSetterProperty<Referenced*, osg::Object>("_userData", _object.get(), (getUserDataFN)&osgShadow::ShadowMap::getUserData, &osgShadow::ShadowMap::setUserData);
	}
	throw PropertyNotFoundException(name);
}
PropertyReflection* RefosgShadowShadowVolume::getProperty(const std::string &name) {
	if (name == "_name") {
		// Getter overloaded, must specify one type
		typedef const std::string & (osg::Object::*getNameFN)() const;
		// Setter overloaded, must specify one type
		typedef void (osg::Object::*setNameFN)(const std::string &) ;
		return new GetterSetterProperty<std::string, osg::Object>("_name", _object.get(), (getNameFN)&osgShadow::ShadowVolume::getName, (setNameFN)&osgShadow::ShadowVolume::setName);
	}
	if (name == "_dataVariance") {
		return new GetterSetterEnumProperty<osg::Object::DataVariance, osg::Object>("_dataVariance", _object.get(), &osgShadow::ShadowVolume::getDataVariance, &osgShadow::ShadowVolume::setDataVariance, osg_object_datavariance);
	}
	if (name == "_drawMode") {
		return new GetterSetterProperty<osgShadow::ShadowVolumeGeometry::DrawMode, osgShadow::ShadowVolume>("_drawMode", _object.get(), &osgShadow::ShadowVolume::getDrawMode, &osgShadow::ShadowVolume::setDrawMode);
	}
	if (name == "_dynamicShadowVolumes") {
		return new GetterSetterProperty<bool, osgShadow::ShadowVolume>("_dynamicShadowVolumes", _object.get(), &osgShadow::ShadowVolume::getDynamicShadowVolumes, &osgShadow::ShadowVolume::setDynamicShadowVolumes);
	}
	if (name == "_userData") {
		// Getter overloaded, must specify one type
		typedef Referenced * (osg::Object::*getUserDataFN)() ;
		return new GetterSetterProperty<Referenced*, osg::Object>("_userData", _object.get(), (getUserDataFN)&osgShadow::ShadowVolume::getUserData, &osgShadow::ShadowVolume::setUserData);
	}
	throw PropertyNotFoundException(name);
}
Esempio n. 28
0
bool GestionEvenements::handle( const osgGA::GUIEventAdapter& ea,
 osgGA::GUIActionAdapter& aa)
{
	switch(ea.getEventType()){
		case osgGA::GUIEventAdapter::KEYDOWN :
		
			switch(ea.getKey()){
				
				case 'a':
					viewer.setCameraManipulator(trackCone.get());
					break;
				case 'z':
					viewer.setCameraManipulator(trackBoite.get());
					break;
				case 'e':
					viewer.setCameraManipulator(trackSphere.get());
					break;
			}
			break;
		
		case osgGA::GUIEventAdapter::PUSH :{
			int x = ea.getX();
			int y = ea.getY();
			if( ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
				std::cout << "bouton gauche" << std::endl;
			if (ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
				std::cout << "bouton milieu" << std::endl;
			if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
				std::cout << "bouton droit" << std::endl;
			break;
 }
		case osgGA::GUIEventAdapter::DOUBLECLICK :
			break;
			}
 return false; // pour que l'événement soit traité par d'autres gestionnaires
}
Esempio n. 29
0
bool
StateSetCache::share(osg::ref_ptr<osg::StateAttribute>& input,
                     osg::ref_ptr<osg::StateAttribute>& output,
                     bool                               checkEligible)
{
    _attrShareAttempts++;

    if ( !checkEligible || eligible(input.get()) )
    {
        Threading::ScopedMutexLock lock( _mutex );

        pruneIfNecessary();

        std::pair<StateAttributeSet::iterator,bool> result = _stateAttributeCache.insert( input );
        if ( result.second )
        {
            // first use
            output = input.get();
            _attrShareMisses++;
            return false;
        }
        else
        {
            // found a share!
            output = result.first->get();
            _attrShareHits++;
            return true;
        }
    }
    else
    {
        _attrsIneligible++;
        output = input.get();
        return false;
    }
}
    void onClick( Control* control, int mouseButtonMask ) {

        //remove the editor if it's valid
        if (s_editor.valid())
        {
            s_root->removeChild( s_editor.get() );
            s_editor = NULL;

            Style* style = _featureGraph->getStyles()->getDefaultStyle();
            if ( style )
            {            
                style->get<LineSymbol>()->stroke()->stipple().unset();
                _featureGraph->dirty();
            }
        }

        //Add the new add point handler
        if (!s_addPointHandler.valid() && s_activeFeature.valid())
        {
            s_addPointHandler = new AddPointHandler(s_activeFeature.get(), s_source.get(), s_mapNode->getMap()->getProfile()->getSRS());
            s_addPointHandler->setIntersectionMask( 0x1 );
            s_viewer->addEventHandler( s_addPointHandler.get() );
        }        
    }