Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
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;
00058 }
00059
00060 bool checkAngles(const float& angleThreshold) const {
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
00111
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
00146
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