NodePair.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 NODEPAIR_H_
00037 #define NODEPAIR_H_
00038 
00039 #include <structureColoring/OcTree.h>
00040 #include <structureColoring/RotationHelper.h>
00041 
00045 class NodePair {
00046 public:
00047         typedef Eigen::Vector3f Vec3;
00048         typedef OcTree::NodePtr NodePtr;
00049 
00050         NodePair(const NodePtr& nodeOne, const NodePtr& nodeTwo, const float& angleThreshold) :
00051                 mOne(nodeOne), mTwo(nodeTwo), mStable(false){
00052                 //mCross = mOne->value.normal.cross(mTwo->value.normal);
00053                 float rotAngle;
00054                 calculateRotation(mCross, rotAngle, mOne->value_.normal, mTwo->value_.normal);
00055                 mNumPoints = mOne->value_.numPoints + mTwo->value_.numPoints;
00056                 mCrossCurv = std::max(mOne->value_.curv, mTwo->value_.curv);
00057                 mStable = true;//checkAngles(angleThreshold);
00058         }
00059 
00060         bool checkAngles(const float& angleThreshold) const {//TODO change to 2D ..
00061                 Vec3 connectionOneTwo(mTwo->value_.meanPos - mOne->value_.meanPos);
00062                 connectionOneTwo -= connectionOneTwo.dot( mCross ) * mCross;
00063                 connectionOneTwo.normalize();
00064                 return fabsf(mOne->value_.normal.dot(connectionOneTwo) - mTwo->value_.normal.dot(-connectionOneTwo)) > cos(angleThreshold);
00065         }
00066 
00067         bool stable() const {return mStable;}
00068         const NodePtr& getFirst() const {return mOne;}
00069         const NodePtr& getSecond() const {return mTwo;}
00070         const Vec3& getCross() const {return mCross;}
00071         float getCrossCurv() const {return mCrossCurv;}
00072         const unsigned int& getNumPoints() const {return mNumPoints;}
00073 private:
00074         NodePtr mOne;
00075         NodePtr mTwo;
00076         Vec3 mCross;
00077         float mCrossCurv;
00078         unsigned int mNumPoints;
00079         bool mStable;
00080 };
00081 typedef std::vector<NodePair> NodePairs;
00082 
00086 class NodePair2D {
00087 public:
00088         typedef Eigen::Vector3f Vec3;
00089         typedef Eigen::Matrix3f Mat3;
00090         typedef Eigen::Vector2f Vec2;
00091 
00092         static void get2DTransformation(Mat3& trans, float& angle, Vec3& axis, const Vec3& cylinderDirectionHypothesis){
00093                 const Vec3 zAxis(0.f, 0.f, 1.f);
00094                 calculateRotation(axis, angle, zAxis, cylinderDirectionHypothesis);
00095                 angle *= -1.f;
00096                 trans = Eigen::AngleAxisf(angle, axis);
00097         }
00098 
00099         NodePair2D(const NodePair& nodePair, const Mat3& transformation, const float& dist): mDist(dist) {
00100                 Vec3 posOne3 = transformation * nodePair.getFirst()->value_.meanPos;
00101                 mPosOne = Vec2(posOne3.x(), posOne3.y());
00102                 Vec3 normalOne3 = transformation * nodePair.getFirst()->value_.normal;
00103                 mNormalOne = Vec2(normalOne3.x(), normalOne3.y());
00104                 mNormalOne.normalize();
00105                 Vec3 posTwo3 = transformation * nodePair.getSecond()->value_.meanPos;
00106                 mPosTwo = Vec2(posTwo3.x(), posTwo3.y());
00107                 Vec3 normalTwo3 = transformation * nodePair.getSecond()->value_.normal;
00108                 mNormalTwo = Vec2(normalTwo3.x(), normalTwo3.y());
00109                 mNormalTwo.normalize();
00110 //              std::cout << "position1:" << std::endl << mPosOne << "normal1:" << std::endl << mNormalOne << std::endl;
00111 //              std::cout << "position2:" << std::endl << mPosTwo << "normal2:" << std::endl << mNormalTwo << std::endl;
00112                 initialize();
00113         }
00114 
00122         NodePair2D(const Vec2& nodeOnePosition, const Vec2& nodeOneNormal,
00123                         const Vec2& nodeTwoPosition, const Vec2& nodeTwoNormal, const float& dist) :
00124                                 mPosOne(nodeOnePosition), mNormalOne(nodeOneNormal), mPosTwo(
00125                                 nodeTwoPosition), mNormalTwo(nodeTwoNormal), mDist(dist) {
00126                 initialize();
00127         }
00128 
00132         bool stable(){return mStable;}
00133 
00137         const Vec2& getCircleMidPoint() const {return mCircleMidPoint;}
00138 
00142         const float& getRadius() const {return mRadius;}
00143 private:
00144         void initialize(){
00145                 // set mOnePos + s1 * mOneNormal = mTwoPos + s2 * mTwoNormal
00146                 // calculate s1, s2 -> get x, y
00147                 float numerator = mNormalOne.y() * (mPosOne.x() - mPosTwo.x()) + mNormalOne.x() * (mPosTwo.y() - mPosOne.y());
00148                 float denominator = mNormalTwo.x() * mNormalOne.y() - mNormalOne.x() * mNormalTwo.y();
00149                 float s2 = numerator / denominator;
00150                 mCircleMidPoint.x() = mPosTwo.x() +  s2 * mNormalTwo.x();
00151                 mCircleMidPoint.y() = mPosTwo.y() + s2 * mNormalTwo.y();
00152                 mRadius = (distToMidPoint(mPosOne) + distToMidPoint(mPosTwo)) * 0.5f;
00153                 mStable = checkRadius();
00154         }
00155 
00156         bool checkRadius(){
00157                 return fabsf(distToMidPoint(mPosOne) - mRadius) < mDist && std::isfinite(mCircleMidPoint.y()) && std::isfinite(mCircleMidPoint.x());
00158         }
00159 
00164         float distToMidPoint(const Vec2& vec) const {
00165                 Vec2 connectingVec(mCircleMidPoint - vec);
00166                 return connectingVec.norm();
00167         }
00168 
00169         Vec2 mPosOne;
00170         Vec2 mNormalOne;
00171 
00172         Vec2 mPosTwo;
00173         Vec2 mNormalTwo;
00174 
00175         float mDist;
00176 
00177         float mRadius;
00178         Vec2 mCircleMidPoint;
00179         bool mStable;
00180 };
00181 typedef std::vector<NodePair2D> NodePairs2D;
00182 
00183 
00184 #endif /* NODEPAIR_H_ */


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