void BodyMotionGenerationBar::onGenerationButtonClicked() { set<BodyMotionItem*> motionItems; // for avoiding overlap ItemList<Item> selectedItems = ItemTreeView::mainInstance()->selectedItems<Item>(); for(size_t i=0; i < selectedItems.size(); ++i){ PoseSeqItem* poseSeqItem = dynamic_cast<PoseSeqItem*>(selectedItems[i]); if(poseSeqItem){ motionItems.insert(poseSeqItem->bodyMotionItem()); } else { BodyMotionItem* motionItem = dynamic_cast<BodyMotionItem*>(selectedItems[i]); if(motionItem){ motionItems.insert(motionItem); } } } for(set<BodyMotionItem*>::iterator p = motionItems.begin(); p != motionItems.end(); ++p){ BodyMotionItem* motionItem = *p; BodyItem* bodyItem = motionItem->findOwnerItem<BodyItem>(true); if(bodyItem){ PoseProvider* provider = 0; PoseSeqItem* poseSeqItem = dynamic_cast<PoseSeqItem*>(motionItem->parentItem()); if(poseSeqItem){ provider = poseSeqItem->interpolator().get(); } else { bodyMotionPoseProvider->initialize(bodyItem->body(), motionItem->motion()); provider = bodyMotionPoseProvider; if(setup->newBodyItemCheck.isChecked()){ BodyMotionItem* newMotionItem = new BodyMotionItem(); newMotionItem->setName(motionItem->name() + "'"); motionItem->parentItem()->insertChildItem(newMotionItem, motionItem->nextItem()); motionItem = newMotionItem; } } shapeBodyMotion(bodyItem->body(), provider, motionItem, true); } } }
void HrpsysSequenceFileExportPlugin::HrpsysSequenceFileExport() { cout << "\x1b[31m" << "Start HrpsysSequenceFileExport" << "\x1b[m" << endl; // BodyItem,BodyPtr ItemList<BodyItem> bodyItems = ItemTreeView::mainInstance()->checkedItems<BodyItem>(); BodyPtr body = bodyItems[0]->body();// ロボットモデルは1個のみチェック LeggedBodyHelperPtr lgh = getLeggedBodyHelper(body); PoseSeqItem* poseSeqItem = ItemTreeView::mainInstance()->selectedItems<PoseSeqItem>()[0]; PoseSeqPtr poseSeq = poseSeqItem->poseSeq(); BodyMotionItem* bodyMotionItem = poseSeqItem->bodyMotionItem(); BodyMotionPtr motion = bodyMotionItem->motion(); string poseSeqPathString = poseSeqItem->filePath(); boost::filesystem::path poseSeqPath(poseSeqPathString); cout << " parent_path:" << poseSeqPath.parent_path().string() << " basename:" << getBasename(poseSeqPath) << endl; double dt = ((double) 1)/motion->frameRate(); int numFrames = motion->numFrames(); std::vector<string> extentionVec{"wrenches","optionaldata"}; for(auto ext : extentionVec){ MultiValueSeqItemPtr seqItem = bodyMotionItem->findSubItem<MultiValueSeqItem>(ext); if(!seqItem){ cout << ext << " is not found in PoseSeq: " << poseSeqItem->name() << endl; continue; } stringstream fnamess; fnamess << poseSeqItem->name() << "." << ext; ofstream ofs; ofs.open(((filesystem::path) poseSeqPath.parent_path() / fnamess.str()).string().c_str(), ios::out); MultiValueSeqPtr multiValueSeqPtr = seqItem->seq(); for(int i=0; i<numFrames; ++i){ ofs << i*dt; MultiValueSeq::Frame frame = multiValueSeqPtr->frame(i); for(int j=0; j<frame.size(); ++j){ ofs << " " << frame[j]; } ofs << endl; } ofs.close(); } cout << "\x1b[31m" << "Finished HrpsysSequenceFileExport" << "\x1b[m" << endl << endl; }