Cylinder3D.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 CYLINDER3D_H_
00037 #define CYLINDER3D_H_
00038 
00039 #include <Eigen/Dense>
00040 #include <structureColoring/RotationHelper.h>
00041 #include <boost/shared_ptr.hpp>
00042 
00043 class Cylinder3D {
00044 public:
00045         typedef Eigen::Vector3f Vec3;
00046         typedef Eigen::Matrix3f Mat3;
00047         typedef boost::shared_ptr<Cylinder3D> Cylinder3DPtr;
00048 
00049         Cylinder3D(): mPointOnAxis(0.f, 0.f, 0.f), mAxisDirection(0.f, 0.f, 0.f), mRadius(0){}
00050         Cylinder3D(Vec3 pointOnAxis, Vec3 axisDirection, float radius)
00051         : mPointOnAxis(pointOnAxis), mAxisDirection(axisDirection), mRadius(radius) {}
00052         Cylinder3D(Vec3 pointOnAxis, Vec3 axisDirection, float radius, const Vec3& rotationAxis, const float rotationAngle)
00053         : mPointOnAxis(pointOnAxis), mAxisDirection(axisDirection), mRadius(radius) {setTransformation(rotationAngle, rotationAxis);}
00054 
00055 //getter
00056         const Vec3& getPointOnAxis() const {return mPointOnAxis;}
00057         const Vec3& getAxisDirection() const {return mAxisDirection;}
00058         const float& getRadius() const {return mRadius;}
00059         const Vec3& getRotationAxis()const{return mRotAxis;}
00060         const float& getRotationAngle()const{return mRotAngle;}
00061         const Mat3& getTransformRot()const{return mTransformRot;}
00062         const Mat3& getReTransformRot()const{return mReTransformRot;}
00063 
00064 //calculations
00065         bool checkDistance(const Vec3& point, const float& maxDistance) const{
00066                 return fabsf(distanceToCylinderSurface(point)) < maxDistance;
00067         }
00068         bool checkNormal(const Vec3& normal, const Vec3& point, const float& mAngleEps) const{
00069                 Vec3 transformedPoint;
00070                 transformToCylinder(transformedPoint, point);
00071                 Eigen::Vector2f dirFromCenter(transformedPoint.x(), transformedPoint.y());
00072                 dirFromCenter.normalize();
00073 
00074                 Vec3 normalCylinder = mTransformRot * normal;
00075                 Eigen::Vector2f normal2 = normalCylinder.block<2,1>(0,0);
00076 
00077                 return fabsf(dirFromCenter.dot(normal2)) >= cosf(mAngleEps);
00078         }
00079         void projectPoint(Vec3& outPoint, const Vec3& point) const{
00080                 Vec3 transformedPoint;
00081                 transformToCylinder(transformedPoint, point);
00082                 Vec3 pOnAxisSameZ(0.f, 0.f, transformedPoint.z());
00083                 Vec3 connection = transformedPoint - pOnAxisSameZ;
00084                 float connectionLength = connection.norm();
00085                 outPoint = pOnAxisSameZ + connection * (mRadius / connectionLength);
00086         }
00087         void transformToCylinder(Vec3& outPoint, const Vec3& point) const { outPoint = mTransformRot * (point + mTransformTrans);}
00088         void transformToXYZCoords(Vec3& outPoint, const Vec3& point) const { outPoint = (mReTransformRot * point) - mTransformTrans;}
00089         float distanceToAxis(const Vec3& point) const {
00090                 Vec3 transformedPoint;
00091                 transformToCylinder(transformedPoint, point);
00092                 Eigen::Vector2f pointOnHeightZ(transformedPoint.x(), transformedPoint.y());
00093                 return pointOnHeightZ.norm();
00094         }
00095         float distanceToCylinderSurface(const Vec3& point) const{
00096                 return distanceToAxis(point) - mRadius;
00097         }
00098         void setTransformation(const float rotationAngle, const Vec3& rotationAxis){
00099                 mTransformRot = Eigen::AngleAxisf(rotationAngle, rotationAxis);
00100                 mReTransformRot = Eigen::AngleAxisf(-rotationAngle, rotationAxis);
00101                 mTransformTrans = -mPointOnAxis;
00102         }
00103 
00104 protected:
00108         void computeTransformation(){
00109                 Vec3 zAxis(0.f, 0.f, 1.f);
00110                 calculateRotation(mRotAxis, mRotAngle, mAxisDirection, zAxis);
00111                 mTransformRot = Eigen::AngleAxisf(mRotAngle, mRotAxis);
00112                 mTransformTrans= -mPointOnAxis;
00113                 mReTransformRot = Eigen::AngleAxisf(-mRotAngle, mRotAxis);
00114         }
00115 
00116         Vec3 mPointOnAxis;
00117         Vec3 mAxisDirection;
00118         float mRadius;
00119 
00120         Vec3 mRotAxis;
00121         float mRotAngle;
00122         Mat3 mTransformRot, mReTransformRot;
00123         Vec3 mTransformTrans;
00124 };
00125 
00126 #endif /* CYLINDER3D_H_ */


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