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_directions.cpp,v 1.2 2009/03/25 22:10:05 cmatei Exp $ 00024 // 00025 //###################################################################### 00026 00027 /***************************************************************************/ 00028 /* FILE: grasp_directions.cc */ 00029 /* AUTHOR: Steffen Knoop */ 00030 /* DATE: 03-27-2002 */ 00031 /***************************************************************************/ 00032 00038 #include <math.h> 00039 #include "matvec3D.h" 00040 00041 /* STL */ 00042 #include "list" 00043 00044 #include "grasp_coordinates.h" 00045 #include "grasp_directions.h" 00046 00050 GraspDirection::GraspDirection() 00051 { 00052 // point = new coordinates; 00053 // dir = new coordinates; 00054 empty = false; 00055 } 00056 00060 GraspDirection::~GraspDirection() 00061 { 00062 // delete point; 00063 // delete dir; 00064 } 00065 00069 coordinates 00070 GraspDirection::get_point() const 00071 { 00072 return *point; 00073 } 00074 00078 coordinates 00079 GraspDirection::get_dir() const 00080 { 00081 return *dir; 00082 } 00083 00087 void 00088 GraspDirection::set_empty(bool in) 00089 { 00090 empty = in; 00091 } 00092 00096 bool 00097 GraspDirection::get_empty() const 00098 { 00099 return empty; 00100 } 00101 00105 void 00106 GraspDirection::set_gdType(graspDirectionType in) 00107 { 00108 gdType = in; 00109 } 00110 00114 graspDirectionType 00115 GraspDirection::get_gdType() const 00116 { 00117 return gdType; 00118 } 00119 00124 bool 00125 GraspDirection::operator==(const GraspDirection& p) 00126 { 00127 00128 //ATM: Hmmmm why is steffen comparing pointer values? 00129 if (p.get_point() == get_point() && 00130 p.get_dir() == get_dir() && 00131 p.get_empty() == get_empty()) 00132 return true; 00133 return false; 00134 } 00135 00136 00137 00138 /*************** 00139 CARTESIAN GraspDirection 00140 ***************/ 00141 00146 cartesianGraspDirection::cartesianGraspDirection() 00147 { 00148 point = new cartesian_coordinates(); 00149 dir = new cartesian_coordinates(); 00150 empty = false; 00151 } 00152 00157 cartesianGraspDirection::cartesianGraspDirection(GraspDirection* p) 00158 { 00159 point = new cartesian_coordinates(p->get_point()); 00160 dir = new cartesian_coordinates(p->get_dir()); 00161 empty = p->get_empty(); 00162 set_gdType(p->get_gdType()); 00163 } 00164 00169 cartesianGraspDirection::cartesianGraspDirection(cartesianGraspDirection* p) 00170 { 00171 point = new cartesian_coordinates(p->get_point()); 00172 dir = new cartesian_coordinates(p->get_dir()); 00173 empty = p->get_empty(); 00174 set_gdType(p->get_gdType()); 00175 } 00176 00181 cartesianGraspDirection::cartesianGraspDirection(const cartesianGraspDirection& p) : GraspDirection() 00182 { 00183 point = new cartesian_coordinates(p.get_point()); 00184 dir = new cartesian_coordinates(p.get_dir()); 00185 empty = p.get_empty(); 00186 set_gdType(p.get_gdType()); 00187 } 00188 00192 cartesianGraspDirection::~cartesianGraspDirection() 00193 { 00194 delete point; 00195 delete dir; 00196 } 00197 00201 void 00202 cartesianGraspDirection::set_point(coordinates in) 00203 { 00204 *point = in; 00205 } 00206 00210 void 00211 cartesianGraspDirection::set_dir(coordinates in) 00212 { 00213 *dir = in; 00214 } 00215 00220 double 00221 cartesianGraspDirection::distanceTo(cartesianGraspDirection to) const 00222 { 00223 double dist = point->distanceTo(to.get_point()); 00224 dist += dir->distanceTo(to.get_dir()); 00225 /* max is 2.0, every dist normed to 1 */ 00226 return dist / 2.0; 00227 } 00228 00229 /*************** 00230 CYLINDRICAL GraspDirection 00231 ***************/ 00236 cylindricalGraspDirection::cylindricalGraspDirection() : GraspDirection() 00237 { 00238 point = new cylindrical_coordinates(); 00239 dir = new cylindrical_coordinates(); 00240 empty = false; 00241 } 00242 00247 cylindricalGraspDirection::cylindricalGraspDirection(GraspDirection* p) : GraspDirection() 00248 { 00249 point = new cylindrical_coordinates(); 00250 set_point(p->get_point()); 00251 dir = new cylindrical_coordinates(); 00252 set_dir(p->get_dir()); 00253 empty = p->get_empty(); 00254 set_gdType(p->get_gdType()); 00255 } 00256 00261 cylindricalGraspDirection::cylindricalGraspDirection(cylindricalGraspDirection* p) : GraspDirection() 00262 { 00263 point = new cylindrical_coordinates(p->get_point()); 00264 dir = new cylindrical_coordinates(p->get_dir()); 00265 empty = p->get_empty(); 00266 set_gdType(p->get_gdType()); 00267 } 00268 00273 cylindricalGraspDirection::cylindricalGraspDirection(const cylindricalGraspDirection& p) : GraspDirection() 00274 { 00275 point = new cylindrical_coordinates(p.get_point()); 00276 dir = new cylindrical_coordinates(p.get_dir()); 00277 empty = p.get_empty(); 00278 set_gdType(p.get_gdType()); 00279 } 00280 00284 cylindricalGraspDirection::~cylindricalGraspDirection() 00285 { 00286 delete point; 00287 delete dir; 00288 } 00289 00293 void 00294 cylindricalGraspDirection::set_point(coordinates in) 00295 { 00296 (*point)[0] = in[0]; 00297 00298 while (in[1] > (2*M_PI)) 00299 in[1]-=(2*M_PI); 00300 while (in[1] < (2*M_PI)) 00301 in[1]+=(2*M_PI); 00302 (*point)[1] = in[1]; 00303 00304 (*point)[2] = in[2]; 00305 } 00306 00310 void 00311 cylindricalGraspDirection::set_dir(coordinates in) 00312 { 00313 (*dir)[0] = in[0]; 00314 (*dir)[1] = (in[1] > (2 * M_PI)) ? (2*M_PI) : in[1]; 00315 (*dir)[2] = in[2]; 00316 } 00317 00318 00319 /*************** 00320 SPHERICAL PART 00321 ***************/ 00322 00327 sphericalGraspDirection::sphericalGraspDirection() : GraspDirection() 00328 { 00329 point = new spherical_coordinates(); 00330 dir = new spherical_coordinates(); 00331 } 00332 00337 sphericalGraspDirection::sphericalGraspDirection(GraspDirection* p) : GraspDirection() 00338 { 00339 point = new spherical_coordinates(); 00340 set_point(p->get_point()); 00341 dir = new spherical_coordinates(); 00342 set_dir(p->get_dir()); 00343 empty = p->get_empty(); 00344 set_gdType(p->get_gdType()); 00345 } 00346 00351 sphericalGraspDirection::sphericalGraspDirection(sphericalGraspDirection* p) : GraspDirection() 00352 { 00353 point = new spherical_coordinates(p->get_point()); 00354 dir = new spherical_coordinates(p->get_dir()); 00355 empty = p->get_empty(); 00356 set_gdType(p->get_gdType()); 00357 } 00358 00363 sphericalGraspDirection::sphericalGraspDirection(const sphericalGraspDirection& p) : GraspDirection() 00364 { 00365 point = new spherical_coordinates(p.get_point()); 00366 dir = new spherical_coordinates(p.get_dir()); 00367 empty = p.get_empty(); 00368 set_gdType(p.get_gdType()); 00369 } 00370 00374 sphericalGraspDirection::~sphericalGraspDirection() 00375 { 00376 delete point; 00377 delete dir; 00378 } 00379 00383 void 00384 sphericalGraspDirection::set_point(coordinates in) 00385 { 00386 (*point)[0] = in[0]; 00387 00388 while (in[1] > M_PI) 00389 in[1]-=M_PI; 00390 while (in[1] < M_PI) 00391 in[1]+=M_PI; 00392 (*point)[1] = in[1]; 00393 00394 while (in[2] > (2*M_PI)) 00395 in[2]-=(2*M_PI); 00396 while (in[2] < (2*M_PI)) 00397 in[2]+=(2*M_PI); 00398 (*point)[2] = in[2]; 00399 } 00400 00404 void 00405 sphericalGraspDirection::set_dir(coordinates in) 00406 { 00407 (*dir)[0] = in[0]; 00408 (*dir)[1] = (in[1] > M_PI) ? M_PI : in[1]; 00409 (*dir)[2] = (in[1] > (2 * M_PI)) ? (2*M_PI) : in[1]; 00410 00411 } 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432