BV_fitter.h
Go to the documentation of this file.
00001 
00002 /*
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2011, Willow Garage, Inc.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of Willow Garage, Inc. nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00038 #ifndef FCL_BV_FITTER_H
00039 #define FCL_BV_FITTER_H
00040 
00041 #include "fcl/BVH/BVH_internal.h"
00042 #include "fcl/BV/kIOS.h"
00043 #include "fcl/BV/OBBRSS.h"
00044 #include <iostream>
00045 
00046 namespace fcl
00047 {
00048 
00050 template<typename BV>
00051 void fit(Vec3f* ps, int n, BV& bv)
00052 {
00053   for(int i = 0; i < n; ++i)
00054   {
00055     bv += ps[i];
00056   }
00057 }
00058 
00059 template<>
00060 void fit<OBB>(Vec3f* ps, int n, OBB& bv);
00061 
00062 template<>
00063 void fit<RSS>(Vec3f* ps, int n, RSS& bv);
00064 
00065 template<>
00066 void fit<kIOS>(Vec3f* ps, int n, kIOS& bv);
00067 
00068 template<>
00069 void fit<OBBRSS>(Vec3f* ps, int n, OBBRSS& bv);
00070 
00071 
00073 template<typename BV>
00074 class BVFitterBase
00075 {
00076 public:
00078   virtual void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_) = 0;
00079 
00081   virtual void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_) = 0;
00082 
00084   virtual BV fit(unsigned int* primitive_indices, int num_primitives) = 0;
00085 
00087   virtual void clear() = 0;
00088 };
00089 
00091 template<typename BV>
00092 class BVFitter : public BVFitterBase<BV>
00093 {
00094 public:
00096   virtual ~BVFitter() {}
00097 
00099   void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_)
00100   {
00101     vertices = vertices_;
00102     prev_vertices = NULL;
00103     tri_indices = tri_indices_;
00104     type = type_;
00105   }
00106 
00108   void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_)
00109   {
00110     vertices = vertices_;
00111     prev_vertices = prev_vertices_;
00112     tri_indices = tri_indices_;
00113     type = type_;
00114   }
00115 
00118   BV fit(unsigned int* primitive_indices, int num_primitives)
00119   {
00120     BV bv;
00121 
00122     if(type == BVH_MODEL_TRIANGLES)             
00123     {
00124       for(int i = 0; i < num_primitives; ++i)
00125       {
00126         Triangle t = tri_indices[primitive_indices[i]];
00127         bv += vertices[t[0]];
00128         bv += vertices[t[1]];
00129         bv += vertices[t[2]];
00130 
00131         if(prev_vertices)                      
00132         {
00133           bv += prev_vertices[t[0]];
00134           bv += prev_vertices[t[1]];
00135           bv += prev_vertices[t[2]];
00136         }
00137       }
00138     }
00139     else if(type == BVH_MODEL_POINTCLOUD)       
00140     {
00141       for(int i = 0; i < num_primitives; ++i)
00142       {
00143         bv += vertices[primitive_indices[i]];
00144 
00145         if(prev_vertices)                       
00146         {
00147           bv += prev_vertices[primitive_indices[i]];
00148         }
00149       }
00150     }
00151 
00152     return bv;
00153   }
00154 
00156   void clear()
00157   {
00158     vertices = NULL;
00159     prev_vertices = NULL;
00160     tri_indices = NULL;
00161     type = BVH_MODEL_UNKNOWN;
00162   }
00163 
00164 private:
00165 
00166   Vec3f* vertices;
00167   Vec3f* prev_vertices;
00168   Triangle* tri_indices;
00169   BVHModelType type;
00170 };
00171 
00172 
00174 template<>
00175 class BVFitter<OBB> : public BVFitterBase<OBB>
00176 {
00177 public:
00179   void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_)
00180   {
00181     vertices = vertices_;
00182     prev_vertices = NULL;
00183     tri_indices = tri_indices_;
00184     type = type_;
00185   }
00186 
00188   void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_)
00189   {
00190     vertices = vertices_;
00191     prev_vertices = prev_vertices_;
00192     tri_indices = tri_indices_;
00193     type = type_;
00194   }
00195 
00198   OBB fit(unsigned int* primitive_indices, int num_primitives);
00199 
00201   void clear()
00202   {
00203     vertices = NULL;
00204     prev_vertices = NULL;
00205     tri_indices = NULL;
00206     type = BVH_MODEL_UNKNOWN;
00207   }
00208 
00209 private:
00210 
00211   Vec3f* vertices;
00212   Vec3f* prev_vertices;
00213   Triangle* tri_indices;
00214   BVHModelType type;
00215 };
00216 
00217 
00219 template<>
00220 class BVFitter<RSS> : public BVFitterBase<RSS>
00221 {
00222 public:
00224   void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_)
00225   {
00226     vertices = vertices_;
00227     prev_vertices = NULL;
00228     tri_indices = tri_indices_;
00229     type = type_;
00230   }
00231 
00233   void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_)
00234   {
00235     vertices = vertices_;
00236     prev_vertices = prev_vertices_;
00237     tri_indices = tri_indices_;
00238     type = type_;
00239   }
00240 
00243   RSS fit(unsigned int* primitive_indices, int num_primitives);
00244 
00246   void clear()
00247   {
00248     vertices = NULL;
00249     prev_vertices = NULL;
00250     tri_indices = NULL;
00251     type = BVH_MODEL_UNKNOWN;
00252   }
00253 
00254 private:
00255 
00256   Vec3f* vertices;
00257   Vec3f* prev_vertices;
00258   Triangle* tri_indices;
00259   BVHModelType type;
00260 };
00261 
00262 
00264 template<>
00265 class BVFitter<kIOS> : public BVFitterBase<kIOS>
00266 {
00267 public:
00269   void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_)
00270   {
00271     vertices = vertices_;
00272     prev_vertices = NULL;
00273     tri_indices = tri_indices_;
00274     type = type_;
00275   }
00276 
00278   void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_)
00279   {
00280     vertices = vertices_;
00281     prev_vertices = prev_vertices_;
00282     tri_indices = tri_indices_;
00283     type = type_;
00284   }
00285 
00288   kIOS fit(unsigned int* primitive_indices, int num_primitives);
00289 
00291   void clear()
00292   {
00293     vertices = NULL;
00294     prev_vertices = NULL;
00295     tri_indices = NULL;
00296     type = BVH_MODEL_UNKNOWN;
00297   }
00298 
00299 private:
00300   Vec3f* vertices;
00301   Vec3f* prev_vertices;
00302   Triangle* tri_indices;
00303   BVHModelType type;
00304 };
00305 
00306 
00308 template<>
00309 class BVFitter<OBBRSS> : public BVFitterBase<OBBRSS>
00310 {
00311 public:
00313   void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_)
00314   {
00315     vertices = vertices_;
00316     prev_vertices = NULL;
00317     tri_indices = tri_indices_;
00318     type = type_;
00319   }
00320 
00322   void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_)
00323   {
00324     vertices = vertices_;
00325     prev_vertices = prev_vertices_;
00326     tri_indices = tri_indices_;
00327     type = type_;
00328   }
00329 
00332   OBBRSS fit(unsigned int* primitive_indices, int num_primitives);
00333 
00335   void clear()
00336   {
00337     vertices = NULL;
00338     prev_vertices = NULL;
00339     tri_indices = NULL;
00340     type = BVH_MODEL_UNKNOWN;
00341   }
00342 
00343 private:
00344 
00345   Vec3f* vertices;
00346   Vec3f* prev_vertices;
00347   Triangle* tri_indices;
00348   BVHModelType type;
00349 };
00350 
00351 }
00352 
00353 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


fcl
Author(s): Jia Pan
autogenerated on Tue Jan 15 2013 16:05:30