ExternalFace.cpp
Go to the documentation of this file.
00001 /*
00002  * ExternalFace.cpp
00003  *
00004  *  Created on: Dec 14, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <obs_providers/ExternalFace.hpp>
00009 
00010 // Declare
00011 PLUGINLIB_DECLARE_CLASS(tk_obstacle, ExternalFace, telekyb_obs::ExternalFace, TELEKYB_NAMESPACE::ObstacleProvider);
00012 
00013 namespace telekyb_obs {
00014 
00015 ExternalFaceOptions::ExternalFaceOptions()
00016         : OptionContainer("ExternalFace")
00017 {
00018         tInputFaces = addOption< std::vector<Eigen::Vector3d> >("tInputFaces",
00019                         "Input Faces here",
00020                         std::vector<Eigen::Vector3d>(),false,false);
00021 }
00022 
00023 ExternalFace::ExternalFace()
00024         : ObstacleProvider("tk_obstacle/ExternalFace")
00025 {
00026         std::vector<Eigen::Vector3d> optionInput = options.tInputFaces->getValue();
00027         // fill faces
00028         for (unsigned int i = 0; i < optionInput.size() / 3; i++) {
00029                 Face f;
00030                 f.origin = optionInput[i*3 + 0];
00031                 f.dir1 = optionInput[i*3 + 1];
00032                 f.dir2 = optionInput[i*3 + 2];
00033                 faces.push_back(f);
00034         }
00035 }
00036 
00037 ExternalFace::~ExternalFace()
00038 {
00039 
00040 }
00041 
00042 // called directly after Creation
00043 void ExternalFace::initialize()
00044 {
00045 
00046 }
00047 
00048 // called right before destruction
00049 void ExternalFace::destroy()
00050 {
00051 
00052 }
00053 
00054 
00055 void ExternalFace::getObstaclePoints(const TKState& lastState, std::vector<Position3D>& obstaclePoints) const
00056 {
00057 
00058         if (faces.empty()) {
00059                 ROS_ERROR("Warning, no faces defined!");
00060                 return;
00061         }
00062 
00063         Eigen::Vector3d point = lastState.position;
00064 
00065         for (unsigned int i = 0; i < faces.size(); ++i) {
00066 
00067                 // Work with face f.
00068                 Eigen::Vector3d faceNormal = faces[i].dir1.cross(faces[i].dir2);
00069                 faceNormal.normalize();
00070 
00071                 //ROS_INFO("Distance to plane: %f", (point - faces[i].origin).dot(faceNormal) );
00072 
00073                 Eigen::Vector3d projectedPoint = point - ((point - faces[i].origin).dot(faceNormal) * faceNormal );
00074 
00075 
00076                 // Calculation
00077                 double relativePosDir1 = (faces[i].dir1.dot(projectedPoint - faces[i].origin)) / faces[i].dir1.squaredNorm();
00078                 double relativePosDir2 = (faces[i].dir2.dot(projectedPoint - faces[i].origin)) / faces[i].dir2.squaredNorm();
00079 
00080                 //ROS_WARN("Direction Norms: Dir1: %f, Dir2: %f", relativePosDir1, relativePosDir2);
00081 
00082                 // Conditional check to project point to edges or vertices
00083                 if (relativePosDir1 < 0) {
00084                         projectedPoint -= relativePosDir1 * faces[i].dir1;
00085 
00086                 } else if (relativePosDir1 > 1.0) {
00087                         projectedPoint -= (relativePosDir1 - 1.0) * faces[i].dir1;
00088                 }
00089 
00090                 // 2nd Projection
00091                 if (relativePosDir2 < 0) {
00092                         projectedPoint -= relativePosDir2 * faces[i].dir2;
00093 
00094                 } else if (relativePosDir2 > 1.0) {
00095                         projectedPoint -= (relativePosDir2 - 1.0) * faces[i].dir2;
00096                 }
00097 
00098                 //ROS_WARN_STREAM("Projected Point:" << std::endl << projectedPoint);
00099 
00100                 // condition checking
00101                 obstaclePoints.push_back(projectedPoint);
00102         }
00103 
00104         // copy because of efficiency;
00105 //      Position3D minSurrObsBox = options.tMinSurrObsBox->getValue();
00106 //      Position3D maxSurrObsBox = options.tMaxSurrObsBox->getValue();
00107 //
00108 //      Position3D currentPos = lastState.position;
00109 //
00110 //      if(     currentPos(0) > maxSurrObsBox(0) ||
00111 //                      currentPos(1) > maxSurrObsBox(1) ||
00112 //                      currentPos(2) > maxSurrObsBox(2) ||
00113 //                      currentPos(0) < minSurrObsBox(0) ||
00114 //                      currentPos(1) < minSurrObsBox(1) ||
00115 //                      currentPos(2) < minSurrObsBox(2)){
00116 //              ROS_WARN("Current Position outside the obstacle box.");
00117 //      }else{
00118 //              obstaclePoints.push_back(Position3D(minSurrObsBox(0),currentPos(1),currentPos(2)));
00119 //              obstaclePoints.push_back(Position3D(maxSurrObsBox(0),currentPos(1),currentPos(2)));
00120 //              obstaclePoints.push_back(Position3D(currentPos(0),minSurrObsBox(1),currentPos(2)));
00121 //              obstaclePoints.push_back(Position3D(currentPos(0),maxSurrObsBox(1),currentPos(2)));
00122 //              obstaclePoints.push_back(Position3D(currentPos(0),currentPos(1),minSurrObsBox(2)));
00123 //              obstaclePoints.push_back(Position3D(currentPos(0),currentPos(1),maxSurrObsBox(2)));
00124 //      }
00125 }
00126 
00127 } /* namespace telekyb_obs */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


tk_obstacle
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:22