Plane3D.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Fraunhofer FKIE
00003  *
00004  * Authors: Bastian Gaspers
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * * Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * * Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * * Neither the name of the Fraunhofer FKIE nor the names of its
00015  *   contributors may be used to endorse or promote products derived from
00016  *   this software without specific prior written permission.
00017  *
00018  * This file is part of the StructureColoring ROS package.
00019  *
00020  * The StructureColoring ROS package is free software:
00021  * you can redistribute it and/or modify it under the terms of the
00022  * GNU Lesser General Public License as published by the Free
00023  * Software Foundation, either version 3 of the License, or
00024  * (at your option) any later version.
00025  *
00026  * The StructureColoring ROS package is distributed in the hope that it will be useful,
00027  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00028  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029  * GNU Lesser General Public License for more details.
00030  *
00031  * You should have received a copy of the GNU Lesser General Public License
00032  * along with The StructureColoring ROS package.
00033  * If not, see <http://www.gnu.org/licenses/>.
00034  */
00035 
00036 #ifndef PLANE_H_
00037 #define PLANE_H_
00038 
00039 #include <structureColoring/RotationHelper.h>
00040 #include <boost/shared_ptr.hpp>
00041 #include <Eigen/Dense>
00042 
00043 class Plane3D{
00044 public:
00045         typedef Eigen::Vector3f Vec3;
00046         typedef boost::shared_ptr<Plane3D> Plane3DPtr;
00047 
00048         Plane3D() : mNormal(0.f,0.f,0.f), mDistanceToOrigin(0) {}
00049         Plane3D(const Vec3& normal, const float distanceToOrigin) : mNormal(normal), mDistanceToOrigin(distanceToOrigin) {
00050                 initializeTransformation();
00051         }
00052 
00053 //getter
00054         const Vec3& getPlaneNormal() const {
00055                 return mNormal;
00056         }
00057         const float& getPlaneDistanceToOrigin() const {
00058                 return mDistanceToOrigin;
00059         }
00060 
00061 //setter
00062         void setPlaneNormal(const Vec3& normal){
00063                 mNormal = normal;
00064         }
00065         void setPlaneDistanceToOrigin(const float& dist){
00066                 mDistanceToOrigin = dist;
00067         }
00068 
00069 //calculations
00070         bool checkDistance(const Vec3& p, const float& maxDistance) const {
00071                 return (distance(p) <= maxDistance);
00072         }
00073         bool checkNormal(const Vec3& n, const float& maxAngle) const {
00074                 return fabsf(mNormal.dot(n)) > cos(maxAngle);
00075         }
00076         float distance(const Vec3& p) const {
00077                 return fabsf(signedDistance(p));
00078         }
00079         float signedDistance(const Vec3& p) const {
00080                 return mNormal.dot(p) - mDistanceToOrigin;
00081         }
00082         Vec3 getOrthogonalProjectionOntoPlane(const Vec3& p) const {
00083                 return p - mNormal * signedDistance(p);
00084         }
00085         Vec3 transformToXYPlane(const Vec3& p) const {
00086                 return (mPcs * (p - mNormal * mDistanceToOrigin));
00087         }
00088         Vec3 transformToXYZCoords(const Vec3& p) const {
00089                 return (mPcst * p) + mNormal * mDistanceToOrigin;
00090         }
00091 
00092 protected:
00093         void initializeTransformation(){
00094                 Vec3 coordAxis = Vec3(0, 0, 1);
00095                 Vec3 rotAxis;
00096                 float rotAngle;
00097                 calculateRotation(rotAxis, rotAngle, coordAxis, mNormal);
00098                 mPcs = Eigen::AngleAxisf(-rotAngle, rotAxis);
00099                 mPcst = mPcs.transpose();
00100         }
00101 
00102         Vec3 mNormal;
00103         float mDistanceToOrigin;
00104 
00105 //Transformation
00106         Eigen::Matrix3f mPcs, mPcst;
00107 };
00108 
00109 #endif /* PLANE_H_ */


structure_coloring_fkie
Author(s): Bastian Gaspers
autogenerated on Sun Jan 5 2014 11:38:09