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_grasps.cpp,v 1.2 2009/03/25 22:10:05 cmatei Exp $ 00024 // 00025 //###################################################################### 00026 00027 /***************************************************************************/ 00028 /* FILE: grasp_grasps.cc */ 00029 /* AUTHOR: Steffen Knoop */ 00030 /* DATE: 03-08-2002 */ 00031 /***************************************************************************/ 00032 00037 /* inventor includes */ 00038 #include <Inventor/actions/SoGetBoundingBoxAction.h> 00039 #include <Inventor/actions/SoSearchAction.h> 00040 #include <Inventor/nodes/SoCylinder.h> 00041 #include <Inventor/nodes/SoCone.h> 00042 #include <Inventor/nodes/SoCube.h> 00043 #include <Inventor/nodes/SoSphere.h> 00044 #include <Inventor/SoLists.h> 00045 #include "SoArrow.h" 00046 #include "SoTorquePointer.h" 00047 #include "SoComplexShape.h" 00048 #include <Inventor/fields/SoSFFloat.h> 00049 #include <Inventor/actions/SoGetMatrixAction.h> 00050 #include <Inventor/SbLinear.h> 00051 #include <Inventor/nodes/SoRotation.h> 00052 #include <Inventor/nodes/SoCamera.h> 00053 #include <Inventor/nodes/SoTransformSeparator.h> 00054 #include <Inventor/nodes/SoDirectionalLight.h> 00055 #include <Inventor/sensors/SoIdleSensor.h> 00056 #include <Inventor/nodes/SoMaterial.h> 00057 #include <Inventor/SbColor.h> 00058 #include <Inventor/nodes/SoTransform.h> 00059 00060 00061 #include "body.h" 00062 #include "matvec3D.h" 00063 #include "grasp_coordinates.h" 00064 #include "grasp_directions.h" 00065 #include "grasp_preshape.h" 00066 #include "grasp_visualization.h" 00067 #include "grasp_grasps.h" 00068 00069 00070 00074 plannedGrasp::plannedGrasp(){ 00075 myGraspDir = cartesianGraspDirection(); 00076 myPreshape = PR_None; 00077 finalGPos = finalGraspPosition(); 00078 myQuality = -1.; 00079 myCP = NULL; 00080 } 00081 00085 plannedGrasp::plannedGrasp(const plannedGrasp& in){ 00086 set_graspDirection(in.get_graspDirection()); 00087 set_fixedFingerDirection(in.get_fixedFingerDirection()); 00088 myQuality = in.get_quality(); 00089 myPreshape = in.get_preshape(); 00090 myGraspableBody = in.get_graspableBody(); 00091 finalGPos = in.get_finalGraspPosition(); 00092 myCP = in.get_graspRepresentation(); 00093 } 00094 00098 plannedGrasp::plannedGrasp(cartesianGraspDirection in){ 00099 set_graspDirection(in); 00100 myPreshape = PR_None; 00101 myQuality = -1.; 00102 myCP = NULL; 00103 } 00104 00108 plannedGrasp::~plannedGrasp(){ 00109 if (myCP != NULL) 00110 delete myCP; 00111 } 00112 00117 double 00118 plannedGrasp::distanceTo(plannedGrasp to) const { 00119 return (DIST_DIR_WEIGHT * myGraspDir.distanceTo(to.get_graspDirection()) + 00120 DIST_FFD_WEIGHT * fixedFingerDirection.distanceTo(to.get_fixedFingerDirection()) + 00121 DIST_PRESH_WEIGHT * myPreshape.distanceTo(to.get_preshape())) / 00122 (DIST_DIR_WEIGHT + DIST_FFD_WEIGHT + DIST_PRESH_WEIGHT); 00123 } 00124 00125 00129 cartesianGraspDirection 00130 plannedGrasp::get_graspDirection()const{ 00131 return myGraspDir; 00132 } 00133 00137 void 00138 plannedGrasp::set_graspDirection(cartesianGraspDirection in){ 00139 myGraspDir.set_point(in.get_point()); 00140 myGraspDir.set_dir(in.get_dir()); 00141 myGraspDir.set_empty(in.get_empty()); 00142 myGraspDir.set_gdType(in.get_gdType()); 00143 return; 00144 } 00145 00149 cartesian_coordinates 00150 plannedGrasp::get_fixedFingerDirection()const{ 00151 return fixedFingerDirection; 00152 } 00153 00157 void 00158 plannedGrasp::set_fixedFingerDirection(cartesian_coordinates in){ 00159 fixedFingerDirection = in; 00160 return; 00161 } 00162 00166 finalGraspPosition 00167 plannedGrasp::get_finalGraspPosition()const{ 00168 return finalGPos; 00169 } 00170 00174 void 00175 plannedGrasp::set_finalGraspPosition(finalGraspPosition in){ 00176 finalGPos = in; 00177 return; 00178 } 00179 00180 // bool 00181 // plannedGrasp::get_isReachable()const{ 00182 // return isReachable; 00183 // } 00184 00185 // void 00186 // plannedGrasp::set_isReachable(bool in){ 00187 // isReachable = in; 00188 // return; 00189 // } 00190 00194 double 00195 plannedGrasp::get_quality()const{ 00196 return myQuality; 00197 } 00198 00202 void 00203 plannedGrasp::set_quality(double in){ 00204 myQuality = in; 00205 return; 00206 } 00207 00211 preshape 00212 plannedGrasp::get_preshape()const{ 00213 return myPreshape; 00214 } 00215 00219 void 00220 plannedGrasp::set_preshape(preshape in){ 00221 myPreshape = in; 00222 } 00223 00227 GraspableBody* 00228 plannedGrasp::get_graspableBody()const{ 00229 return myGraspableBody; 00230 } 00231 00235 void 00236 plannedGrasp::set_graspableBody(GraspableBody* gb){ 00237 myGraspableBody = gb; 00238 return; 00239 } 00240 00244 grasp_representation* 00245 plannedGrasp::get_graspRepresentation()const{ 00246 return myCP; 00247 } 00248 00252 void 00253 plannedGrasp::set_graspRepresentation(grasp_representation* gr){ 00254 myCP = gr; 00255 return; 00256 } 00257 00261 void 00262 plannedGrasp::remove_graspRepresentation(){ 00263 delete myCP; 00264 myCP = NULL; 00265 return; 00266 } 00267 00273 #ifdef WIN32 00274 bool 00275 compareGraspQM::operator()(plannedGrasp* &first, plannedGrasp* &second) const 00276 { 00277 if (first->get_quality() > second->get_quality()) 00278 return true; 00279 return false; 00280 } 00281 #else 00282 bool 00283 compareGraspQM::operator()(plannedGrasp* &first, plannedGrasp* &second) const 00284 { 00285 if (first->get_quality() < second->get_quality()) 00286 return true; 00287 return false; 00288 } 00289 #endif 00290 00291 /*****************/ 00292 00296 finalGraspPosition::finalGraspPosition(){ 00297 } 00298 00302 finalGraspPosition::finalGraspPosition(const finalGraspPosition& in){ 00303 finalTran = in.get_finalTran(); 00304 dof = in.get_dof(); 00305 } 00306 00310 finalGraspPosition::~finalGraspPosition(){ 00311 dof.clear(); 00312 } 00313 00317 transf 00318 finalGraspPosition::get_finalTran()const{ 00319 return finalTran; 00320 } 00321 00325 void 00326 finalGraspPosition::set_finalTran(transf in){ 00327 finalTran = in; 00328 return; 00329 } 00330 00334 std::list<double> 00335 finalGraspPosition::get_dof() const{ 00336 return dof; 00337 } 00338 00342 void 00343 finalGraspPosition::add_dof(double in){ 00344 dof.push_back(in); 00345 } 00346 00350 bool 00351 finalGraspPosition::change_dof(unsigned int nr, double in){ 00352 if (nr<dof.size()){ 00353 std::list<double>::iterator it = dof.begin(); 00354 for (unsigned int i=0; i<nr; i++) 00355 it++; 00356 (*it) = in; 00357 return true; 00358 } 00359 else return false; 00360 } 00361 00362 00363 /****************** 00364 Local Variables: 00365 mode:c++ 00366 End: 00367 ******************/ 00368 00369 00370 00371 00372 00373 00374