00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_CONSTRAINTS_PSYS_BOX_H 00002 #define OPENTISSUE_DYNAMICS_PSYS_CONSTRAINTS_PSYS_BOX_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/dynamics/psys/psys_constraint.h> 00013 #include <cassert> 00014 00015 namespace OpenTissue 00016 { 00017 namespace psys 00018 { 00019 00020 template<typename types> 00021 class Box 00022 : public Constraint< types > 00023 { 00024 public: 00025 00026 typedef typename types::math_types math_types; 00027 typedef typename math_types::vector3_type vector3_type; 00028 typedef typename types::particle_type particle_type; 00029 typedef typename types::system_type system_type; 00030 typedef typename types::aabb_type aabb_type; 00031 00032 protected: 00033 00034 aabb_type m_aabb; 00035 00036 public: 00037 00038 aabb_type & aabb() { return m_aabb; } 00039 aabb_type const & aabb() const { return m_aabb; } 00040 00041 public: 00042 00043 Box() 00044 : m_aabb(0,0,0,1000,1000,1000) 00045 {} 00046 00047 virtual ~Box(){} 00048 00049 public: 00050 00051 void satisfy() 00052 { 00053 typedef typename system_type::particle_iterator particle_iterator; 00054 using std::min; 00055 using std::max; 00056 00057 vector3_type r; 00058 vector3_type m = m_aabb.min(); 00059 vector3_type M = m_aabb.max(); 00060 00061 particle_iterator p = this->owner()->particle_begin(); 00062 particle_iterator end = this->owner()->particle_end(); 00063 for(;p!=end;++p) 00064 p->position() = min( M, max(m, p->position()) ); 00065 } 00066 00067 }; 00068 } // namespace psys 00069 00070 } // namespace OpenTissue 00071 00072 // OPENTISSUE_DYNAMICS_PSYS_CONSTRAINTS_PSYS_BOX_H 00073 #endif