FF3DGuidanceAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #include "stdafx.h"
00024 #include "FF3DGuidanceAgent.h"
00025 #include "define.h"
00026 
00027 
00028 #include "FF3DSphericalForceModel.h"
00029 #include "FF3DAttractivePointForceModel.h"
00030 #include "FF3DDiscForceModel.h"
00031 #include "FF3DLinearForceModel.h"
00032 #include "FF3DPlanarForceModel.h"
00033 #include "FF3DPicobHGForceModel.h"
00034 #include "FF3DPicobGForceModel.h"
00035 
00036 /*#include <Shape.h>
00037 #include <Sphere.h>
00038 #include <Cone.h>
00039 #include <Appearance.h>
00040 #include <FrictionalSurface.h>*/
00041 
00042 
00043 FF3DGuidanceAgent::FF3DGuidanceAgent()
00044 : Child( new FF3DGuidanceAgentCollider ), MicoleAgent("FF3DGuidanceAgent","Output"), _fm(NULL), _transform(new Transform())
00045 {
00046         ((FF3DGuidanceAgentCollider *)this->collider.get())->_parent = this;
00047 
00048         //add FF3DGuidanceAgent in scene
00049         Display * dis = ReachinMicoleApplication::getInstance()->getDisplay();
00050         
00051         _transform->children->add(this);
00052         dis->children->add( _transform );  
00053 
00055         /*
00056 #ifdef _DEBUG
00057         Shape * sh = new Shape;
00058         Cone * sph = new Cone;
00059 
00060         //FrictionalSurface * surf = new FrictionalSurface;
00061         sph->height->set(0.05);
00062         sph->bottom_radius->set(0.01);
00063 
00064         //surf->stiffness->set( 500 );
00065 
00066         Material * mat = new Material;
00067         mat->diffuse_color->set( RGB(0,1,0));
00068 
00069         Appearance * app = new Appearance;
00070         app->material->set(mat);
00071         //app->surface->set( surf );
00072 
00073         sh->appearance->set(app);
00074         sh->geometry->set(sph);
00075 
00076         _transform->children->add(sh);
00077 #endif
00078         */
00079         //en test
00080 
00081         sendMessage("Set stiffness = 1.5;");
00082         sendMessage("Set d = 0.02;");
00083 
00084 
00085         bindMessage( "^OUT FF3D GUIDE : point=\\((.*), (.*), (.*)\\);$", 
00086                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePointForceModel ));
00087         bindMessage( "^OUT FF3D GUIDE : sphere=\\((.*), (.*), (.*), (.*)\\);$", 
00088                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleSphericalForceModel ));
00089         bindMessage( "^OUT FF3D GUIDE : line=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$", 
00090                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleLinearForceModel ));
00091         bindMessage( "^OUT FF3D GUIDE : plan=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$", 
00092                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePlanarForceModel ));
00093         bindMessage( "^OUT FF3D GUIDE : disc=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\),(.*)\\);$", 
00094                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleDiscForceModel ));
00095         bindMessage( "^OUT FF3D GUIDE : none;$", 
00096                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleNoForceModel ));
00097         bindMessage( "^OUT FF3D GUIDE : picobhg=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$", 
00098                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePicobHgForceModel ));
00099         bindMessage( "^OUT FF3D GUIDE : picobg=\\((.*), (.*), (.*)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$", 
00100                 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePicobGForceModel ));
00101 }
00102 
00103 FF3DGuidanceAgent::~FF3DGuidanceAgent()
00104 {
00105         delete _fm;
00106 //      delete _transform;
00107 }
00108 
00109 void FF3DGuidanceAgent::handlePointForceModel ( MicoleBus *app, int argc, const char **argv )
00110 {
00111         if (argc < 3)
00112                 return;
00113         Vec3f position;
00114         try
00115         {
00116                 position.x = atof(argv[0]);
00117                 position.y = atof(argv[1]);
00118                 position.z = atof(argv[2]);
00119         }
00120         catch (...) //can append for truncated packet or bad transmission
00121         {
00122                 return;
00123         }
00124 
00125         _transform->translation->set(Vec3f(0,0,0));
00126         _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00127 
00128         setForceModel(new FF3DAttractivePointForceModel(position));
00129 }
00130 
00131 void FF3DGuidanceAgent::handleLinearForceModel ( MicoleBus *app, int argc, const char **argv )
00132 {
00133                 if (argc < 6)
00134                 return;
00135         Vec3f pt1;
00136         Vec3f pt2;
00137         try
00138         {
00139                 pt1.x = atof(argv[0]);
00140                 pt1.y = atof(argv[1]);
00141                 pt1.z = atof(argv[2]);
00142 
00143                 //_transform->translation->set(pt1);
00144                 pt2.x = atof(argv[3]);
00145                 pt2.y = atof(argv[4]);
00146                 pt2.z = atof(argv[5]);
00147         }
00148         catch (...) //can append for truncated packet or bad transmission
00149         {
00150                 return;
00151         }
00152 
00153         setForceModel(new FF3DLinearForceModel(pt1,pt2));
00154 
00155         //we compute the euclidian norma
00156         Vec3f vec_line = pt1 - pt2;
00157         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00158         _transform->translation->set( (pt1+pt2)/2 ); 
00159 }
00160 
00161 void FF3DGuidanceAgent::handlePlanarForceModel ( MicoleBus *app, int argc, const char **argv ) 
00162 {
00163         if (argc < 6)
00164                 return;
00165 
00166         Vec3f pt1;
00167         Vec3f pt2;
00168         Vec3f pt3;
00169         try
00170         {
00171                 pt1.x = atof(argv[0]);
00172                 pt1.y = atof(argv[1]);
00173                 pt1.z = atof(argv[2]);
00174                 _transform->translation->set(pt1);
00175 
00176                 pt2.x = atof(argv[3]);
00177                 pt2.y = atof(argv[4]);
00178                 pt2.z = atof(argv[5]);
00179         }
00180         catch (...) //can append for truncated packet or bad transmission
00181         { 
00182                 return;
00183         }
00184 
00185         /*pt3.x = atof(argv[6]);
00186         pt3.y = atof(argv[7]);
00187         pt3.z = atof(argv[8]);*/
00188 
00189         Vec3f vec_line = pt1 - pt2;
00190         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00191         _transform->translation->set( pt1 ); 
00192 
00193         setForceModel(new FF3DPlanarForceModel(pt1,pt2));
00194 }
00195 
00196 void FF3DGuidanceAgent::handleSphericalForceModel ( MicoleBus *app, int argc, const char **argv )
00197 {
00198         if (argc < 4)
00199                 return;
00200 
00201         Vec3f position;
00202         mgFloat range;
00203         try
00204         {
00205                 position.x = atof(argv[0]);
00206                 position.y = atof(argv[1]);
00207                 position.z = atof(argv[2]);
00208                 range = atof(argv[3]);
00209         }
00210         catch (...) //can append for truncated packet or bad transmission
00211         {
00212                 return;
00213         }
00214 
00215         _transform->translation->set(position);
00216         _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00217 
00218         //setForceModel(new FF3DPointForceModel(position));
00219         setForceModel( new FF3DSphericalForceModel(Vec3f(0,0,0),range) );
00220 }
00221 
00222 void FF3DGuidanceAgent::handleDiscForceModel ( MicoleBus *app, int argc, const char **argv ) 
00223 {
00224         if (argc < 7)
00225                 return;
00226 
00227         Vec3f pt1;
00228         Vec3f pt2;
00229         Vec3f pt3;
00230         try
00231         {
00232                 pt1.x = atof(argv[0]);
00233                 pt1.y = atof(argv[1]);
00234                 pt1.z = atof(argv[2]);
00235                 _transform->translation->set(pt1);
00236 
00237                 pt2.x = atof(argv[3]);
00238                 pt2.y = atof(argv[4]);
00239                 pt2.z = atof(argv[5]);
00240         }
00241         catch (...) //can append for truncated packet or bad transmission
00242         {
00243                 return;
00244         }
00245 
00246         mgFloat range = atof(argv[6]);
00247         
00248         Vec3f vec_line = pt1 - pt2;
00249         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00250         _transform->translation->set( pt1 ); 
00251 
00252         setForceModel(new FF3DDiscForceModel(pt1,pt2,range));
00253 }
00254 
00255 void FF3DGuidanceAgent::handleNoForceModel ( MicoleBus *app, int argc, const char **argv ) 
00256 {
00257         setForceModel(NULL);
00258 }
00259 
00260 void FF3DGuidanceAgent::handlePicobHgForceModel ( MicoleBus *app, int argc, const char **argv )
00261 {
00262         if (argc < 9)
00263                 return;
00264 
00265         Vec3f pt1;
00266         Vec3f pt2;
00267         try
00268         {
00269                 pt1.x = atof(argv[0]);
00270                 pt1.y = atof(argv[1]);
00271                 pt1.z = atof(argv[2]);
00272 
00273                 //_transform->translation->set(pt1);
00274                 pt2.x = atof(argv[3]);
00275                 pt2.y = atof(argv[4]);
00276                 pt2.z = atof(argv[5]);
00277         }
00278         catch (...)
00279         { //can append for truncated packet or bad transmission
00280         }
00281 
00282         //we compute the euclidian norma
00283         Vec3f vec_line = pt1 - pt2;
00284         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00285         _transform->translation->set( (pt1+pt2)/2 ); 
00286         
00287         vector<Vec3f> bumpList;
00288         Picob::readPicobList(argv[6], bumpList);
00289         setForceModel(new FF3DPicobHGForceModel(pt1, pt2, bumpList, atof(argv[7]), atof(argv[8])));
00290 }
00291 
00292 void FF3DGuidanceAgent::handlePicobGForceModel ( MicoleBus *app, int argc, const char **argv )
00293 {
00294         if (argc < 6)
00295                 return;
00296 
00297         Vec3f pt;
00298         try {
00299                 pt.x = atof(argv[0]);
00300                 pt.y = atof(argv[1]);
00301                 pt.z = atof(argv[2]);
00302         }
00303         catch (...)
00304         { //can append for truncated packet or bad transmission
00305         }
00306 
00307 
00308         vector<Vec3f> bumpList;
00309         Picob::readPicobList(argv[3], bumpList);
00310         setForceModel(new FF3DPicobGForceModel(pt, bumpList, atof(argv[4]), atof(argv[5])));
00311 
00312         _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00313         _transform->translation->set(Vec3f(0,0,0));
00314 }

Generated on Tue Oct 16 17:10:42 2007 for Micole by  doxygen 1.4.7