void run() { foldnodeplot.reset(new PlotPoints()); env->add(foldnodeplot); folddirplot.reset(new PlotLines(3)); env->add(folddirplot); pickplot.reset(new PlotSpheres()); env->add(pickplot); tofoldplot.reset(new PlotPoints()); env->add(tofoldplot); destplot.reset(new PlotPoints()); env->add(destplot); pickedNode = pickedNode2 = NULL; setupScene(); initStandardCloth(); facepicker.reset(new SoftBodyFacePicker(*this, viewer.getCamera(), cloth->softBody.get())); facepicker->setPickCallback(boost::bind(&CustomScene::pickCallback, this, _1)); addVoidKeyCallback('f', boost::bind(&CustomScene::doFold, this)); addVoidKeyCallback('g', boost::bind(&CustomScene::doRandomFolds, this, 3)); addVoidKeyCallback('h', boost::bind(&CustomScene::pickUpAndDrop, this)); addVoidKeyCallback('s', boost::bind(&CustomScene::saveCloth, this)); addVoidKeyCallback('l', boost::bind(&CustomScene::loadCloth, this)); addPreDrawCallback(boost::bind(&CustomScene::markFolds, this)); addPreDrawCallback(boost::bind(&CustomScene::drawPick, this)); addPreDrawCallback(boost::bind(&CustomScene::markNodesToFold, this)); startViewer(); setSyncTime(false); startFixedTimestepLoop(BulletConfig::dt); }
void ScreenSharingViewer::onDataReceived(const QString &inData) { std::string data = inData.toStdString(); LOG4CPLUS_INFO(msLogger, "ENTER: ScreenSharingViewer::dataReceived(), data : " + data); if (!data.compare(0, 1, getMessageTypeStr(iviLink::SCR_SHARING_START) ) ) { LOG4CPLUS_INFO(msLogger, "case : data starts with iviLink::SCR_SHARING_START"); } else if (!data.compare(0, 1, getMessageTypeStr(iviLink::SCR_SHARING_SERVER_ADDRESS) ) ) { LOG4CPLUS_INFO(msLogger, "case : data starts with iviLink::SCR_SHARING_SERVER_ADDRESS"); mServerAddress = data.substr(1); LOG4CPLUS_INFO(msLogger, "mServerAddress : " + mServerAddress); if (!startedByUser) { if (QMessageBox::Ok == QMessageBox::question(this, "Incoming Screen Sharing Request" ,"Do you want to start Screen Sharing Session?", QMessageBox::Cancel, QMessageBox::Ok) ) { sendData(getMessageTypeStr(iviLink::SCR_SHARING_START_ACK) ); LOG4CPLUS_INFO(msLogger, "dialog : OK : start viewer"); sleep(4); hide(); startViewer(); } else sendData(getMessageTypeStr(iviLink::SCR_SHARING_EXIT) ); LOG4CPLUS_INFO(msLogger, "dialog : Cancel : quit"); qApp->quit(); } } else if (!data.compare(0, 1, getMessageTypeStr(iviLink::SCR_SHARING_START_ACK) ) ) { LOG4CPLUS_INFO(msLogger, "case : iviLink::SCR_SHARING_START_ACK : start viewer"); isConnectedWithServer = true; hide(); startViewer(); } else if (!data.compare(0, 1, getMessageTypeStr(iviLink::SCR_SHARING_EXIT) ) ) { LOG4CPLUS_INFO(msLogger, "case : iviLink::SCR_SHARING_EXIT : quit"); system(viewerKiller.c_str() ); qApp->quit(); } }
void CustomScene::run() { viewer.addEventHandler(new CustomKeyHandler(*this)); const float dt = BulletConfig::dt; const float table_height = .5; const float table_thickness = .05; table.reset(new BoxObject(0, GeneralConfig::scale * btVector3(.75,.75,table_thickness/2), btTransform(btQuaternion(0, 0, 0, 1), GeneralConfig::scale * btVector3(1.25, 0, table_height-table_thickness/2)))); env->add(table); cloth = createCloth(GeneralConfig::scale * 0.25, GeneralConfig::scale * btVector3(1, 0, 1), 31); env->add(cloth); const float radius = 0.1; sphere.reset(new SphereObject(1, GeneralConfig::scale * radius, btTransform(btQuaternion(0, 0, 0, 1), GeneralConfig::scale * btVector3(1.1, 0, table_height + radius)))); env->add(sphere); startViewer(); stepFor(dt, 0.5); BulletInstance::Ptr bullet2(new BulletInstance); OSGInstance::Ptr osg2(new OSGInstance); osg->root->addChild(osg2->root.get()); Fork::Ptr fork(new Fork(env, bullet2, osg2)); registerFork(fork); cout << "environment copied" << endl; SphereObject::Ptr sphere2 = boost::static_pointer_cast<SphereObject> (fork->forkOf(sphere)); // apply force in second world on sphere for 0.5 secs for (int i = 0; i < 0.5/dt; ++i) { sphere2->rigidBody->applyCentralForce(GeneralConfig::scale * btVector3(-30, -30, 0)); fork->env->step(dt, BulletConfig::maxSubSteps, BulletConfig::internalTimeStep); step(dt); idleFor(dt); } startFixedTimestepLoop(dt); }
void run() { foldnodeplot.reset(new PlotPoints()); env->add(foldnodeplot); folddirplot.reset(new PlotLines(3)); env->add(folddirplot); pickplot.reset(new PlotSpheres()); env->add(pickplot); pickedNode = NULL; leftManipAxes.reset(new PlotAxes); env->add(leftManipAxes); rightManipAxes.reset(new PlotAxes); env->add(rightManipAxes); // load the robot pr2m.reset(new PR2Manager(*this)); if (FlatteningConfig::useFakeGripper) { TelekineticGripper::Ptr fakeLeft(new TelekineticGripper(pr2m->pr2Left)); fakeLeft->setTransform(pr2m->pr2Left->getTransform()); env->add(fakeLeft); gleft.reset(new GenManip(fakeLeft)); TelekineticGripper::Ptr fakeRight(new TelekineticGripper(pr2m->pr2Right)); fakeRight->setTransform(pr2m->pr2Right->getTransform()); gright.reset(new GenManip(fakeRight)); env->add(fakeRight); pr2m->pr2->setTransform(btTransform(btQuaternion::getIdentity(), btVector3(0, 0, -100))); // out of view } else { gleft.reset(new GenManip(pr2m->pr2Left)); gright.reset(new GenManip(pr2m->pr2Right)); } // create the table const float table_height = .5; const float table_thickness = .05; tableExtents = GeneralConfig::scale * btVector3(.75,.75,table_thickness/2); tableTrans = btTransform(btQuaternion(0, 0, 0, 1), GeneralConfig::scale * btVector3(0.8, 0, table_height-table_thickness/2)); BoxObject::Ptr table(new BoxObject(0, tableExtents, tableTrans)); table->rigidBody->setFriction(0.1); env->add(table); cout << "table margin: " << table->rigidBody->getCollisionShape()->getMargin() << endl; // put the table in openrave /* OpenRAVE::KinBodyPtr raveTable = OpenRAVE::RaveCreateKinBody(rave->env); raveTable->SetName("table"); vector<OpenRAVE::AABB> v; v.push_back(OpenRAVE::AABB(util::toRaveTransform(table_trans, 1./pr2m->pr2->scale).trans, 1./pr2m->pr2->scale * util::toRaveVector(table_extents))); raveTable->InitFromBoxes(v, true); rave->env->AddKinBody(raveTable); */ #if 0 OpenRAVE::ViewerBasePtr raveViewer = OpenRAVE::RaveCreateViewer(rave->env, "qtcoin"); rave->env->AddViewer(raveViewer); raveViewer->main(true); #endif const int resx = 45, resy = 31; // const btScalar lenx = GeneralConfig::scale * 0.7, leny = GeneralConfig::scale * 0.5; const btScalar lenx = GeneralConfig::scale * 0.7/2, leny = GeneralConfig::scale * 0.5/2; // const btVector3 clothcenter = GeneralConfig::scale * btVector3(0.5, 0, table_height+0.01); const btVector3 clothcenter = GeneralConfig::scale * btVector3(0.3, 0.1, table_height+0.01); // cloth = makeSelfCollidingTowel(clothcenter, lenx, leny, resx, resy, env->bullet->softBodyWorldInfo); cloth.reset(new Cloth(resx, resy, lenx, leny, clothcenter, env->bullet->softBodyWorldInfo)); env->add(cloth); facepicker.reset(new SoftBodyFacePicker(*this, viewer.getCamera(), cloth->softBody.get())); facepicker->setPickCallback(boost::bind(&CustomScene::pickCallback, this, _1)); sbgripperleft.reset(new GenPR2SoftGripper(pr2m->pr2, gleft, true)); sbgripperleft->setGrabOnlyOnContact(true); sbgripperleft->setTarget(cloth); GenPR2SoftGripperAction leftAction(pr2m->pr2, gleft->baseManip()->manip, sbgripperleft); leftAction.setTarget(cloth); leftAction.setExecTime(1.); addVoidKeyCallback('a', boost::bind(&CustomScene::runGripperAction, this, leftAction)); addVoidKeyCallback('c', boost::bind(&CustomScene::graspPickedNode, this)); addVoidKeyCallback('f', boost::bind(&CustomScene::greedyFlattenSingle, this)); addVoidKeyCallback('F', boost::bind(&CustomScene::deepFlattenSingle, this)); addVoidKeyCallback('g', boost::bind(&CustomScene::liftCloth, this)); addPreDrawCallback(boost::bind(&CustomScene::markFolds, this)); addPreDrawCallback(boost::bind(&CustomScene::drawPick, this)); addPreDrawCallback(boost::bind(&CustomScene::drawManipAxes, this)); addPreDrawCallback(boost::bind(&GenPR2SoftGripper::dbgDraw, sbgripperleft.get(), this)); startViewer(); startFixedTimestepLoop(BulletConfig::dt); }