00001
00061 #include "../../dof/feature.h"
00062
00063
00064
00065 template<typename _DOF6>
00066 float Object<_DOF6>::getSimilarity(const Object &o) const
00067 {
00068 const float fw = data_.matchFormf(o.data_);
00069
00070 const float l1 = data_.getBB().extension();
00071 const float l2 = o.data_.getBB().extension();
00072
00073 return fw * std::min(l1,l2)/std::max(l1,l2);
00074 }
00075
00076
00077 template<typename _DOF6>
00078 const Slam_CurvedPolygon::ex_curved_polygon::BB &Object<_DOF6>::getBB() const
00079 {
00080 return data_.getBB();
00081 }
00082
00083 template<typename _DOF6>
00084 Slam_CurvedPolygon::ex_curved_polygon::BB Object<_DOF6>::getBB(const typename DOF6::TYPE &thr_rot, const typename DOF6::TYPE &thr_tr) const
00085 {
00086 return getBB().increaseIfNec(thr_rot, thr_tr);
00087 }
00088
00093 template<typename _DOF6>
00094 bool Object<_DOF6>::intersectsBB(const Object &o, const typename DOF6::TYPE &thr_rot, const typename DOF6::TYPE &thr_tr) const
00095 {
00096 return getBB()&o.getBB(thr_rot,thr_tr);
00097 }
00098
00103 template<typename _DOF6>
00104 bool Object<_DOF6>::intersectsBB(const Eigen::Vector3f &o, const Eigen::Matrix3f &rot, const Eigen::Vector3f &tr, const typename DOF6::TYPE &thr_rot, const typename DOF6::TYPE &thr_tr) const
00105 {
00106 return getBB().transform(rot,tr)&(DATA::BB(o).increaseIfNec(thr_rot, thr_tr));
00107 }
00108 template<typename _DOF6>
00109 bool Object<_DOF6>::intersectsBB(const Eigen::Vector3f &o, const typename DOF6::TYPE &thr_rot, const typename DOF6::TYPE &thr_tr) const
00110 {
00111 return getBB()&(DATA::BB(o).increaseIfNec(thr_rot, thr_tr));
00112 }
00113
00114 template<typename _DOF6>
00115 bool Object<_DOF6>::intersectsPts(const Object &o, const typename DOF6::TYPE &thr_rot, const typename DOF6::TYPE &thr_tr) const
00116 {
00117 for(size_t i=0; i<o.data_.getPoints3D().size(); i++)
00118 if(intersectsBB(o.data_.getPoints3D()[i], thr_rot, thr_tr))
00119 return true;
00120 return false;
00121 }
00122
00123
00124 template<typename _DOF6>
00125 void Object<_DOF6>::addTFList(const Object &o, const typename DOF6::TYPE &thr_rot, const typename DOF6::TYPE &thr_tr, const Eigen::Matrix3f &rot, const Eigen::Vector3f &tr, typename Object<_DOF6>::TFLIST &list) const
00126 {
00127
00128 typedef typename Object<_DOF6>::TF_CORS CORS;
00129
00130
00131
00132
00133
00134
00135
00136 const float fw = data_.matchFormf(o.data_);
00137
00138
00139
00140 ROS_ASSERT(used_<=creation_);
00141 float wX = fw*used_*sqrtf(std::min(data_.getWeight(),o.data_.getWeight())/100) / (1+data_.getNearestPoint().norm());
00142
00143 float wG=0.f;
00144 for(size_t i=0; i<o.data_.getOutline().size(); i++) {
00145 wG += (o.data_.getOutline()[(i+1)%o.data_.getOutline().size()].head(2)-o.data_.getOutline()[i].head(2)).norm();
00146 }
00147 wX /= 2*wG;
00148
00149
00150
00151
00152
00153 DATA::SURFACE surf = data_.getSurface();
00154 const DATA::SURFACE &surf1 = data_.getSurface();
00155 const DATA::SURFACE &surf2 = o.data_.getSurface();
00156 surf.transform(rot,tr);
00157
00158
00159 if(data_.getOutline().size()>100||o.data_.getOutline().size()>100) {
00160 ROS_ERROR("too big, skipping");
00161 return;
00162 }
00163
00164 for(size_t i=0; i<o.data_.getOutline().size(); i++) {
00165
00166 Eigen::Vector3f p2 = o.data_.getOutline()[i];
00167 Eigen::Vector3f v2 = surf2.project2world(p2.head<2>());
00168
00169 if(!intersectsBB(v2, rot,tr, thr_rot,thr_tr+0.025f)) {
00170 continue;
00171 }
00172
00173 const float w = wX * (
00174 (o.data_.getOutline()[(i+1)%o.data_.getOutline().size()].head(2)-p2.head<2>()).norm()
00175 + (o.data_.getOutline()[(i-1+o.data_.getOutline().size())%o.data_.getOutline().size()].head(2)-p2.head<2>()).norm()
00176 );
00177
00178 Eigen::Vector2f np = surf.nextPoint(v2);
00179
00180 Eigen::Vector3f np3;
00181 np3.head<2>() = np;
00182 np3(2) = std::max(p2(2), o.data_.getOutline()[(i+1)%o.data_.getOutline().size()](2));
00183 Eigen::Vector3f p1 = data_.getOutline().nextPoint(np3);
00184
00185 p1(2) = p2(2);
00186
00187 ::DOF6::S_FEATURE f1(surf.project2world(p1.head<2>()), surf.normalAt(p1.head<2>()), false);
00188 ::DOF6::S_FEATURE f2(surf2.project2world(p2.head<2>()), surf2.normalAt(p2.head<2>()), false);
00189
00190 if(!f1.isReachable(f2,thr_tr,thr_rot) ) {
00191
00192 continue;
00193 }
00194
00195 if(!pcl_isfinite(p1.sum())) {
00196 ROS_ERROR("invalid");
00197 continue;
00198 }
00199
00200
00201 ROS_ASSERT(pcl_isfinite(p1.sum()));
00202
00203 float w_pt = w * (0.15f+std::min(p2(2), p1(2)));
00204
00205
00206 f1.v_ = surf1.project2world(p1.head<2>());
00207 f1.n_ = surf1.normalAt(p1.head<2>());
00208
00209 if(pcl_isfinite(f1.v_.sum())&&pcl_isfinite(f2.v_.sum()))
00210 list.push_back( CORS(
00211 typename TFLINK::TFLinkObj(f1.v_, false,false, w_pt, w_pt),
00212 typename TFLINK::TFLinkObj(f2.v_,false,false, w_pt, w_pt)
00213 ) );
00214
00215
00216
00217
00218
00219
00220
00221 }
00222
00223 }