ModelLayer nodes are not conserving their nodeMask

classic Classic list List threaded Threaded
4 messages Options
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

ModelLayer nodes are not conserving their nodeMask

Hello,
I have noticed that every time I add a new modelLayer, the old modelLayer nodes lose their nodeMasks.

In more details:
I need to set a mask for some modelLayers to avoid their selection in the IntersectionPicker;
so every time I add my Layer, I set its masks:
mapNode->getModelLayerGroup()->getChild(mapNode->getModelLayerGroup()->getNumChildren() - 1)->setNodeMask(4);

but with the new modification in the MapNode, I lose these information because in the MapNode.cpp, all the nodes are deleted without saving their masks in the  rebuildLayerNodes function.

So, I did a temporary modification to solve that, but I think it should be taken in consideration to maintain all nodes information.

Modification:

void rebuildLayerNodes(const Map* map, osg::Group* layerNodes)
    {
        std::vector<int> masks;
        for (unsigned int i = 0; i < layerNodes->getNumChildren(); i++)
        {
                if(layerNodes->getChild(i))
                        masks.push_back(layerNodes->getChild(i)->getNodeMask());
        }


        layerNodes->removeChildren(0, layerNodes->getNumChildren());

        LayerVector layers;
        map->getLayers(layers);
        int id = 0;
        for (LayerVector::iterator i = layers.begin(); i != layers.end(); ++i)
        {
            Layer* layer = i->get();
            osg::Node* node = layer->getOrCreateNode();
            if (node)
            {
                osg::Group* container = new osg::Group();
                container->setName(layer->getName());
                container->addChild(node);
                container->setStateSet(layer->getStateSet());
                if(id<masks.size())
                        container->setNodeMask(masks.at(id));

                layerNodes->addChild(container);
                id++;
            }
        }
    }
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: ModelLayer nodes are not conserving their nodeMask

MCA,

Can you instead just call layer->getOrCreateNode()->setNodeMask?
Glenn Waldron / Pelican Mapping
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Re: ModelLayer nodes are not conserving their nodeMask

Thanks,
I added layer->getOrCreateNode()->setNodeMask   after adding the layer to the map, but it did not work because in the rebuildLayerNodes function you are not adding the layer node directly, but you are adding it as a child of a new group.

So you can instead use "layer->getOrCreateNode()->setNodeMask", but also in rebuildLayerNodes  function you need to add: "container->setNodeMask(node->getNodeMask());".

this will affect only the old nodes, not the last inserted one, so you need to call :
mapNode->getModelLayerGroup()->getChild(i)->setNodeMask(4); // for the last layer
and
layer->getOrCreateNode()->setNodeMask (4); // will be used at rebuild time

it will work using the first modification in the first post, or with this one ( a little bit illogical: 2 differents call of setNodemask)
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Re: ModelLayer nodes are not conserving their nodeMask

In reply to this post by gwaldron
Sorry for the previous replay, I made a mistake in my test.

your suggestion " layer->getOrCreateNode()->setNodeMask" is working, even if the ModelLayer node does not save its mask, but affecting the node layer directly did the trick, because the modelLayer group contain only the layer node with the correct mask.

So, this is working with the IntersectionPicker.

Thank you.