void Vwr::CameraManipulator::initAutomaticMovement(osgViewer::Viewer* viewer) { t1 = t2 = 0; osg::Vec3d eye; osg::Vec3d center; osg::Vec3d up; viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up); this->lastPosition = originalEyePosition = eye; this->lastTargetPoint = center; float scale = appConf->getValue("Viewer.Display.NodeDistanceScale").toFloat(); weightPoint = (eye + cameraInterestPoint + cameraTargetPoint)/3; targetDistance = alterCameraTargetPoint(viewer); cameraPositions = new QVector<osg::Vec3d>(); cameraPositions->push_back(originalEyePosition); cameraPositions->push_back(cameraInterestPoint); cameraPositions->push_back(cameraTargetPoint); // vahy kontrolnych bodov pre trajektoriu kamery w1[0] = 1; w1[1] = -0.1; w1[2] = 1; targetPositions = new QVector<osg::Vec3d>(); targetPositions->push_back(center); targetPositions->push_back(cameraInterestPoint); targetPositions->push_back(weightPoint); // vahy kontrolnych bodov pre trajektriu pohladu w2[0] = 1; w2[1] = 0.5f; w2[2] = 1; // uprava vah aby boli viditelne vsetky body zaujmu alterWeights(viewer, selectedCluster); // zobrazenie kontornych bodov if (appConf->getValue("Viewer.Display.CameraPositions").toInt() == 1) { Data::Graph * g = Manager::GraphManager::getInstance()->getActiveGraph(); g->addNode("centerNode", g->getNodeMetaType(), center)->setColor(osg::Vec4(0, 0.5, 1, 0.5)); g->addNode("startNode", g->getNodeMetaType(), originalEyePosition / scale); g->addNode("interestPoint", g->getNodeMetaType(), cameraInterestPoint / scale)->setColor(osg::Vec4(0, 1, 1, 1)); g->addNode("weigthPoint", g->getNodeMetaType(), weightPoint)->setColor(osg::Vec4(0, 0.5, 1, 1)); } automaticMovementInitialized = true; }
bool CoreWindow::add_NodeClick() { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Data::Type *edgeType = NULL; Data::Type *nodeType = NULL; if (currentGraph != NULL) { osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true); osg::ref_ptr<Data::Node> node1 = currentGraph->addNode("newNode", currentGraph->getNodeMetaType(), position); if (isPlaying) layout->play(); } else { currentGraph= Manager::GraphManager::getInstance()->createNewGraph("NewGraph"); osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true); Data::MetaType* type = currentGraph->addMetaType(Data::GraphLayout::META_NODE_TYPE); osg::ref_ptr<Data::Node> node1 = currentGraph->addNode("newNode", type); if (isPlaying) layout->play(); } return true; }
void AddMetaNodeExecutor::execute_client() { int count, metaNodeId, id_edge, id_node; QString name, edgeName; float x, y, z; *stream >> metaNodeId >> name; Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes(); *stream >> x >> y >> z; osg::ref_ptr<Data::Node> metaNode = currentGraph->addNode(metaNodeId, name, currentGraph->getNodeMetaType(), osg::Vec3(x,y,z)); *stream >> edgeName; *stream >> count; for (int i = 0; i < count; i++) { *stream >> id_edge >> id_node; if (nodes->contains(id_node)) { currentGraph->addEdge(id_edge, edgeName, *nodes->find(id_node), metaNode, currentGraph->getEdgeMetaType(), true); } } }
void AddMetaNodeExecutor::execute_server() { int count, id; QString name, edgeName; float x, y, z; *stream >> name; Data::Graph* currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes(); *stream >> x >> y >> z; osg::ref_ptr<Data::Node> metaNode = currentGraph->addNode( name, currentGraph->getNodeMetaType(), osg::Vec3( x,y,z ) ); *stream >> edgeName; *stream >> count; QLinkedList<osg::ref_ptr<Data::Node> >* selectedNodes = new QLinkedList<osg::ref_ptr<Data::Node> >(); for ( int i = 0; i < count; i++ ) { *stream >> id; if ( nodes->contains( id ) ) { currentGraph->addEdge( edgeName, *nodes->find( id ), metaNode, currentGraph->getEdgeMetaType(), true ); selectedNodes->append( *nodes->find( id ) ); } } Server* server = Server::getInstance(); server->sendAddMetaNode( metaNode,selectedNodes,edgeName,osg::Vec3( x,y,z ) ); if ( ( ( QOSG::CoreWindow* )server->getCoreWindowReference() )->playing() ) { server->getLayoutThread()->play(); } }
void CoreWindow::addMetaNode() { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); if (currentGraph != NULL) { osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true); osg::ref_ptr<Data::Node> metaNode = currentGraph->addNode("metaNode", currentGraph->getNodeMetaType(), position); QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes(); QLinkedList<osg::ref_ptr<Data::Node> >::const_iterator i = selectedNodes->constBegin(); while (i != selectedNodes->constEnd()) { Data::Edge * e = currentGraph->addEdge("metaEdge", (*i), metaNode, currentGraph->getEdgeMetaType(), true); e->setCamera(viewerWidget->getCamera()); ++i; } if (isPlaying) layout->play(); } }
/*! * \param ea * Adapter udalosti. * * * Funkcia vypocita poziciu kamery a zmensi rychlost pohybu. * */ void Vwr::CameraManipulator::frame( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa ) { osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>( &aa ); // ak sme v rezime automatickeho pohybu if(movingAutomatically) { // inicializujeme premenne if (!automaticMovementInitialized) initAutomaticMovement(viewer); // dokym pohlad a pozicia neopisu celu trajektoriu if (t1 <= 1 || t2 <= 1) { // ziskanie novych pozicii na krivke if (t1 <= 1) { cameraPosition = CameraMath::getPointOnNextBezierCurve(t1, cameraPositions, w1); t1 += EYE_MOVEMENT_SPEED; } if (t2 <= 1) { targetPoint = CameraMath::getPointOnNextBezierCurve(t2, targetPositions, w2 ); t2 += TARGET_MOVEMENT_SPEED; } // aktualne pozicie kamery osg::Vec3d eye; osg::Vec3d center; osg::Vec3d up; viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up); // prepocitanie koordinatov kamerery s novymi hodnotami computePosition(cameraPosition, targetPoint, up); // zobrazenie trajektorie kamery if (appConf->getValue("Viewer.Display.CameraPath").toInt() == 1) { QLinkedList<osg::ref_ptr<osg::Node> > * list = coreGraph->getCustomNodeList(); osg::ref_ptr<osg::Group> group = new osg::Group; osg::ref_ptr<osg::Geode> g1 = new osg::Geode; g1->addDrawable(CameraMath::createAxis(eye, lastPosition)); g1->addDrawable(CameraMath::createAxis(targetPoint, lastTargetPoint, osg::Vec4d(1,0,0,1))); group->addChild(g1); lastPosition = eye; lastTargetPoint = targetPoint; list->push_back(group); } // vypis metriky do konzoly if (appConf->getValue("Graph.Metrics.ViewMetrics").toInt() == 1) { computeViewMetrics(viewer, selectedCluster); } } // ukoncenie pohybu else { movingAutomatically = false; if (appConf->getValue("Viewer.Display.CameraPositions").toInt() == 1) { osg::Vec3d eye; osg::Vec3d center; osg::Vec3d up; viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up); Data::Graph * g = Manager::GraphManager::getInstance()->getActiveGraph(); g->addNode("EndNode", g->getNodeMetaType(), eye); } // osg::Vec3d eye; // osg::Vec3d center; // osg::Vec3d up; // viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up); // cout << eye.x() << " " << eye.y() << " " << eye.z() << "\n"; } } // standardny frame else { computeStandardFrame(ea, aa); } }