Ejemplo n.º 1
0
void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath)
{
    _clearNodePath();

    // OSG_NOTICE<<"ObserverNodePath["<<this<<"]::_setNodePath() nodePath.size()="<<nodePath.size()<<std::endl;

    _nodePath.resize(nodePath.size());
    for(unsigned int i=0; i<nodePath.size(); ++i)
    {
        _nodePath[i] = nodePath[i];
    }
}
Ejemplo n.º 2
0
bool PickHandler::doNodePick(osg::NodePath nodePath)
{
	Data::Node * n = dynamic_cast<Data::Node *>(nodePath[nodePath.size() - 1]);

	if (n != NULL)
	{
		if (isAltPressed && pickMode == PickMode::NONE && !isShiftPressed)
		{
			cameraManipulator->setCenter(n->targetPosition());
		}
		else if (isAltPressed && pickMode == PickMode::NONE && isShiftPressed)
		{
			if (appConf->getValue("Viewer.PickHandler.SelectInterestPoints").toInt() == 1)
			{
				Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
				Util::ElementSelector::weightedElementSelector(currentGraph->getNodes(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this);
			}

			bool wasEmpty = false;
			if (pickedNodes.isEmpty())
			{
				pickedNodes.append(n);
				wasEmpty = true;
			}

			if (appConf->getValue("Viewer.Display.CameraPositions").toInt() == 1)
			{
				n->setColor(osg::Vec4(0, 1, 0, 1));
			}

			cameraManipulator->setNewPosition(n->getCurrentPosition(), getSelectionCenter(false), getSelectedNodes()->toStdList(), getSelectedEdges()->toStdList());

			if (wasEmpty)
				pickedNodes.removeFirst();
		}
		else if (pickMode != PickMode::NONE)
		{
			if (!pickedNodes.contains(n))
			{
				pickedNodes.append(n);
				n->setSelected(true);
			}

			if (isCtrlPressed)
				unselectPickedNodes(n);

			return true;
		}
	}

	return false;
}
Ejemplo n.º 3
0
bool PickHandler::doEdgePick(osg::NodePath nodePath, unsigned int primitiveIndex)
{
	osg::Geode * geode = dynamic_cast<osg::Geode *>(nodePath[nodePath.size() - 1]);

	if (geode != 0)
	{
		osg::Drawable * d = geode->getDrawable(0);
		osg::Geometry * geometry = d->asGeometry();

		if (geometry != NULL)
		{
			// zmena (plesko): ak vyber zachytil avatara, nastal segmentation fault,
			// lebo sa vyberal neexistujuci primitiveSet
			Data::Edge * e;
			if (geometry->getNumPrimitiveSets() > primitiveIndex) {
				e = dynamic_cast<Data::Edge *>(geometry->getPrimitiveSet(primitiveIndex));
			} else {
				return false;
			}
			// koniec zmeny

			if (e != NULL)
			{
				if (isAltPressed && pickMode == PickMode::NONE && !isShiftPressed)
				{
					osg::ref_ptr<osg::Vec3Array> coords = e->getCooridnates();

					cameraManipulator->setCenter(DataHelper::getMassCenter(coords));
					cameraManipulator->setDistance(Util::ApplicationConfig::get()->getValue("Viewer.PickHandler.PickedEdgeDistance").toFloat());
				}
				else if (isAltPressed && pickMode == PickMode::NONE && isShiftPressed)
				{
					if (appConf->getValue("Viewer.PickHandler.SelectInterestPoints").toInt() == 1)
					{
						Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
						Util::ElementSelector::weightedElementSelector(currentGraph->getNodes(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this);
					}

					bool wasEmpty = false;
					if (pickedEdges.isEmpty())
					{
						pickedEdges.append(e);
						wasEmpty = true;
					}

					osg::Vec3f edgeCenter = (e->getSrcNode()->getCurrentPosition() + e->getDstNode()->getCurrentPosition()) / 2;

					cameraManipulator->setNewPosition(edgeCenter, getSelectionCenter(false), getSelectedNodes()->toStdList(), getSelectedEdges()->toStdList());

					if (wasEmpty)
						pickedEdges.removeFirst();
				}
				else if (pickMode != PickMode::NONE)
				{
					if (!pickedEdges.contains(e))
					{
						pickedEdges.append(e);
						e->setSelected(true);
					}

					if (isCtrlPressed)
						unselectPickedEdges(e);

					return true;
				}

				return true;
			}
		}
	}

	return false;
}
Ejemplo n.º 4
0
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */
bool ossimPlanetViewer::computeIntersections(float x,
                                                     float y, 
                                                     const osg::NodePath& nodePath, 
                                                     osgUtil::LineSegmentIntersector::Intersections& intersections,
                                                     osg::Node::NodeMask traversalMask)
{
   if (!_camera.valid() || nodePath.empty()) return false;
   
   float local_x, local_y = 0.0;    
   const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
   if (!camera)
   {
      if(theIntersectWithMasterIfNotWithinAnyViewFlag)
      {
         camera = forceAdjustToMasterCamera(x, y, local_x, local_y);
         if(!camera) return false;
      }
      else
      {
         return false;
      }
   }
   
   osg::Matrixd matrix;
   if (nodePath.size()>1)
   {
      osg::NodePath prunedNodePath(nodePath.begin(),nodePath.end()-1);
      matrix = osg::computeLocalToWorld(prunedNodePath);
   }
   
   matrix.postMult(camera->getViewMatrix());
   matrix.postMult(camera->getProjectionMatrix());
   
   double zNear = -1.0;
   double zFar = 1.0;
   if (camera->getViewport())
   {
      matrix.postMult(camera->getViewport()->computeWindowMatrix());
      zNear = 0.0;
      zFar = 1.0;
   }
   
   osg::Matrixd inverse;
   inverse.invert(matrix);
   
   osg::Vec3d startVertex = osg::Vec3d(local_x,local_y,zNear) * inverse;
   osg::Vec3d endVertex = osg::Vec3d(local_x,local_y,zFar) * inverse;
   
   osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::MODEL, startVertex, endVertex);
   
   osgUtil::IntersectionVisitor iv(picker.get());
   iv.setTraversalMask(traversalMask);
   nodePath.back()->accept(iv);
   
   if (picker->containsIntersections())
   {
      intersections = picker->getIntersections();
      return true;
   }
   else
   {
      intersections.clear();
      return false;
   }
}