00001 //###################################################################### 00002 // 00003 // GraspIt! 00004 // Copyright (C) 2002-2009 Columbia University in the City of New York. 00005 // All rights reserved. 00006 // 00007 // GraspIt! is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // GraspIt! is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GraspIt!. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // Authors: Steffen Knoop 00021 // Andrew T. Miller 00022 // 00023 // $Id: grasp_presenter.cpp,v 1.3 2009/03/25 22:10:05 cmatei Exp $ 00024 // 00025 //###################################################################### 00026 00027 /***************************************************************************/ 00028 /* FILE: grasp_presenter.cc */ 00029 /* AUTHOR: Steffen Knoop */ 00030 /* DATE: 03-08-2002 */ 00031 /***************************************************************************/ 00032 00037 /* standard c,c++ includes */ 00038 #include <stdio.h> 00039 #include <iostream> 00040 00041 00042 #include <qstring.h> 00043 00044 /* inventor includes */ 00045 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h> 00046 #include <Inventor/actions/SoGetBoundingBoxAction.h> 00047 #include <Inventor/actions/SoSearchAction.h> 00048 #include <Inventor/nodes/SoCylinder.h> 00049 #include <Inventor/nodes/SoCone.h> 00050 #include <Inventor/nodes/SoCube.h> 00051 #include <Inventor/nodes/SoSphere.h> 00052 #include <Inventor/SoLists.h> 00053 #include "SoArrow.h" 00054 #include "SoTorquePointer.h" 00055 #include "SoComplexShape.h" 00056 #include <Inventor/fields/SoSFFloat.h> 00057 #include <Inventor/actions/SoGetMatrixAction.h> 00058 #include <Inventor/SbLinear.h> 00059 #include <Inventor/nodes/SoRotation.h> 00060 #include <Inventor/nodes/SoCamera.h> 00061 #include <Inventor/nodes/SoTransformSeparator.h> 00062 #include <Inventor/nodes/SoTransform.h> 00063 #include <Inventor/nodes/SoDirectionalLight.h> 00064 00065 #ifdef Q_WS_X11 00066 #include <unistd.h> 00067 #endif 00068 00069 /* graspit includes */ 00070 #include "graspitGUI.h" 00071 #include "contact.h" 00072 #include "ivmgr.h" 00073 #include "world.h" 00074 #include "body.h" 00075 #include "robot.h" 00076 #include "matvec3D.h" 00077 #include "grasp.h" 00078 00079 /* STL includes */ 00080 #include <list> 00081 00082 /* include grasp planner class */ 00083 #include "grasp_coordinates.h" 00084 #include "grasp_directions.h" 00085 #include "grasp_preshape.h" 00086 #include "grasp_visualization.h" 00087 #include "grasp_grasps.h" 00088 #include "grasp_planner.h" 00089 00090 00091 #include "grasp_presenter.h" 00092 00093 /* externs; defined in main.cc */ 00094 extern IVmgr *ivmgr; 00095 00099 grasp_presenter::grasp_presenter(){ 00100 processing = -1; 00101 my_hand = NULL; 00102 #ifdef GRASPITDBG 00103 std::cout << "PL_OUT: Presenter created." << std::endl; 00104 #endif 00105 } 00106 00110 grasp_presenter::~grasp_presenter(){ 00111 #ifdef GRASPITDBG 00112 std::cout << "PL_OUT: Presenter destroyed." << std::endl; 00113 #endif 00114 } 00115 00116 00120 void 00121 grasp_presenter::updateGlobals(){ 00122 ivmgr = graspItGUI->getIVmgr(); 00123 myViewer = ivmgr->getViewer(); 00124 my_world = ivmgr->getWorld(); 00125 my_hand = my_world->getCurrentHand(); 00126 } 00127 00131 void 00132 grasp_presenter::takeList(std::list<plannedGrasp*> graspList_in){ 00133 graspList = graspList_in; 00134 processing = -1; 00135 } 00136 00146 void 00147 grasp_presenter::showGrasp(int next, bool render){ 00148 00149 if (!graspList.empty()){ 00150 updateGlobals(); 00151 00152 /* Here, a separate window should be opened with copies of 00153 the hand, the robot, the object and all obstacles */ 00154 00155 00156 /* Show all grasps beginning with the best */ 00157 if (processing == -1){ 00158 it_gr = graspList.begin(); 00159 processing = 0; 00160 } 00161 00162 if (next >=0) { 00163 #ifdef GRASPITDBG 00164 std::cout << "PL_OUT: Showing next grasp." << std::endl; 00165 } 00166 else { 00167 std::cout<<"PL_OUT: Previous not implemented. Showing next instead." << std::endl; 00168 #endif 00169 } 00170 00171 if ((*it_gr)->get_quality() > 0.0){ 00172 putHand((*it_gr)->get_finalGraspPosition(), render); 00173 #ifdef GRASPITDBG 00174 std::cout << "PL_OUT: Grasp Nr " << processing << std::endl; 00175 std::cout << "PL_OUT: Quality: " << (*it_gr)->get_quality() << std::endl; 00176 #endif 00177 myViewer->render(); 00178 } 00179 it_gr++; 00180 processing++; 00181 if (it_gr == graspList.end()){ 00182 it_gr = graspList.begin(); 00183 processing = 0; 00184 } 00185 } 00186 #ifdef GRASPITDBG 00187 else std::cout << "PL_OUT: No grasps planned yet. There's nothin to show." << std::endl; 00188 #endif 00189 } 00190 00195 void 00196 grasp_presenter::chooseGrasp(){ 00197 #ifdef GRASPITDBG 00198 std::cout << "PL_OUT: YEAH, actual grasp chosen. Congratulations!" << std::endl; 00199 #endif 00200 } 00201 00206 void 00207 grasp_presenter::putHand(finalGraspPosition fgp, bool render){ 00208 00209 std::list<double> tmp = fgp.get_dof(); 00210 std::list<double>::iterator it = tmp.begin(); 00211 00212 my_hand->setTran(fgp.get_finalTran()); 00213 00214 for (int i=0; i<my_hand->getNumDOF(); i++){ 00215 my_hand->forceDOFVal(i,*it); 00216 if ((my_hand->getName() == "Barrett") && i>0) 00217 my_hand->forceDOFVal(i,my_hand->getDOF(i)->getMin()); 00218 if (it != tmp.end()) 00219 it++; 00220 } 00221 if (my_hand->getName() == "Barrett") { 00222 my_hand->autoGrasp(render,50); 00223 } 00224 00225 my_world->findAllContacts(); 00226 my_world->updateGrasps(); 00227 00228 } 00229 00230 00231 00232 00233 00234 00235 00236 00237