00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 */ 00030 00040 #ifndef LASER_SLAM_SCAN_INTERSECTION_H 00041 #define LASER_SLAM_SCAN_INTERSECTION_H 00042 00043 #include <vector> 00044 #include <LinearMath/btTransform.h> 00045 00046 namespace laser_slam 00047 { 00048 00051 class ScanIntersection 00052 { 00053 public: 00058 ScanIntersection (std::vector<btVector3> poly, 00059 unsigned grid_size=100); 00060 00061 ScanIntersection (const ScanIntersection& i); 00062 00066 double unseenProportion (const btTransform& scan, 00067 const std::vector<btTransform>& ref_scans) const; 00068 00070 inline 00071 bool contains (const btTransform& scan, const btVector3& pt) const 00072 { 00073 // Transform p into relative coordinates in frame of \a scan 00074 const btVector3 p = scan.inverse()*pt; 00075 00076 // Short-circuit test if point is too close or too far from center 00077 const double dist = p.distance2(center_); 00078 if (dist > circumradius2_) 00079 return false; 00080 else if (dist < inradius2_) 00081 return true; 00082 00083 // Point-in-polygon test 00084 int i, j = 0; 00085 bool c = false; 00086 for (i=0, j=poly_.size()-1; i<(int)poly_.size(); j = i++) { 00087 if ( ((poly_[i].y()>p.y()) != (poly_[j].y()>p.y())) && 00088 (p.x() < (poly_[j].x()-poly_[i].x()) * (p.y()-poly_[i].y()) / 00089 (poly_[j].y()-poly_[i].y()) + poly_[i].x()) ) 00090 c = !c; 00091 } 00092 return c; 00093 } 00094 00095 00096 private: 00097 00098 00099 std::vector<btVector3> poly_; 00100 std::vector<btVector3> grid_; 00101 btVector3 center_; 00102 float inradius2_, circumradius2_; 00103 }; 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 } // namespace 00114 00115 #endif // include guard