예제 #1
0
void RigGeometry::updateGeomToSkelMatrix(const osg::NodePath& nodePath)
{
    bool foundSkel = false;
    osg::ref_ptr<osg::RefMatrix> geomToSkelMatrix;
    for (osg::NodePath::const_iterator it = nodePath.begin(); it != nodePath.end(); ++it)
    {
        osg::Node* node = *it;
        if (!foundSkel)
        {
            if (node == mSkeleton)
                foundSkel = true;
        }
        else
        {
            if (osg::Transform* trans = node->asTransform())
            {
                if (!geomToSkelMatrix)
                    geomToSkelMatrix = new osg::RefMatrix;
                trans->computeWorldToLocalMatrix(*geomToSkelMatrix, nullptr);
            }
        }
    }
    if (geomToSkelMatrix && !geomToSkelMatrix->isIdentity())
        mGeomToSkelMatrix = geomToSkelMatrix;
}
예제 #2
0
void AddQueries::addDataToNodePath( osg::NodePath& np, unsigned int numVertices, const osg::BoundingBox& bb )
{
    // For every Node in the NodePath that has a QueryCullCallback and a 
    // QueryComputation object, add the number of vertices and the transformed
    // bounding box to that Node's QueryComputation.

    osg::NodePath localNP;
    osg::NodePath::reverse_iterator rit;
    for( rit=np.rbegin(); rit!=np.rend(); rit++ )
    {
        QueryCullCallback* qcc = dynamic_cast< QueryCullCallback* >(
            (*rit)->getCullCallback() );

        osgwQuery::QueryComputation* nd( NULL );
        if( qcc != NULL )
            nd = qcc->getQueryComputation();
        if( nd != NULL )
        {
            nd->setNumVertices( nd->getNumVertices() + numVertices );

            osg::BoundingBox xformBB = osgwTools::transform( osg::computeLocalToWorld( localNP ), bb );
            osg::BoundingBox ndBB = nd->getBoundingBox();
            ndBB.expandBy( xformBB );
            nd->setBoundingBox( ndBB );
        }

        // Yuck. std::vector doesn't support push_back().
        //localNP.push_front( *rit );
        localNP.resize( localNP.size() + 1 );
        unsigned int idx;
        for( idx=localNP.size()-1; idx>0; idx-- )
            localNP[ idx ] = localNP[ idx-1 ];
        localNP[ 0 ] = *rit;
    }
}
예제 #3
0
파일: Selection.cpp 프로젝트: joevandyk/osg
void osgManipulator::computeNodePathToRoot(osg::Node& node, osg::NodePath& np)
{
    np.clear();
    osg::ref_ptr<FindNodePathToRootVisitor> visitor = new FindNodePathToRootVisitor(np);
    node.accept(*visitor);
    np.pop_back();
    std::reverse(np.begin(), np.end());
}
예제 #4
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];
    }
}
예제 #5
0
ImageOverlayEditor::EditPoint
ImageOverlayEditor::getEditPoint(const osg::NodePath &nodePath)
{
    for (osg::NodePath::const_iterator itr = nodePath.begin(); itr != nodePath.end(); ++itr)
    {
        if ((*itr)->getName() == "LOWER_LEFT") return EDITPOINT_LOWER_LEFT;
        if ((*itr)->getName() == "LOWER_RIGHT") return EDITPOINT_LOWER_RIGHT;
        if ((*itr)->getName() == "UPPER_LEFT") return EDITPOINT_UPPER_LEFT;
        if ((*itr)->getName() == "UPPER_RIGHT") return EDITPOINT_UPPER_RIGHT;
        if ((*itr)->getName() == "CENTER") return EDITPOINT_CENTER;
    }
    return EDITPOINT_NONE;
}
예제 #6
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;
}
예제 #7
0
파일: Dragger.cpp 프로젝트: 4ker/osg
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// computeNodePathToRoot
//
void osgManipulator::computeNodePathToRoot(osg::Node& node, osg::NodePath& np)
{
    np.clear();

    osg::NodePathList nodePaths = node.getParentalNodePaths();

    if (!nodePaths.empty())
    {
        np = nodePaths.front();
        if (nodePaths.size()>1)
        {
            OSG_NOTICE<<"osgManipulator::computeNodePathToRoot(,) taking first parent path, ignoring others."<<std::endl;
        }
    }
}
예제 #8
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;
}
예제 #9
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;
   }
}