TAPs 0.7.7.3
TAPsInteractionPointGroup.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsInteractionPointGroup.cpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (07/23/2010)
00009 UPDATE          (09/21/2010)
00010 ******************************************************************************/
00011 #include "TAPsInteractionPointGroup.hpp"
00012 // Using Inclusion Model (i.e. definitions are included in declarations)
00013 //                       (this name.cpp is included in name.hpp)
00014 // Each friend is defined directly inside its declaration.
00015 
00016 BEGIN_NAMESPACE_TAPs
00017 //=============================================================================
00018 // Constructors
00019 //-----------------------------------------------------------------------------
00020 template <typename T>
00021 InteractionPointGroup<T>::InteractionPointGroup ()
00022 {}
00023 //-----------------------------------------------------------------------------
00024 template <typename T>
00025 InteractionPointGroup<T>::InteractionPointGroup ( InteractionPointGroup<T> const &orig )
00026     : m_IPGroup( orig.m_IPGroup )
00027     , m_CDPointForces( orig.m_CDPointForces )
00028 {}
00029 //-----------------------------------------------------------------------------
00030 template <typename T>
00031 InteractionPointGroup<T>::~InteractionPointGroup ()
00032 {}
00033 //-----------------------------------------------------------------------------
00034 template <typename T>
00035 std::string InteractionPointGroup<T>::StrInfo () const
00036 {
00037     std::ostringstream ss;
00038     ss << "InteractionPointGroup<" << typeid(T).name() << ">";
00039     ss << " contains " << m_IPGroup.size() << " interaction points";
00040     ss << "\n";
00041     return ss.str();
00042 }
00043 //-----------------------------------------------------------------------------
00044 //=============================================================================
00045 // Assignment Operator
00046 //-----------------------------------------------------------------------------
00047 template <typename T>
00048 InteractionPointGroup<T> & InteractionPointGroup<T>::operator= ( InteractionPointGroup<T> const &orig )
00049 {
00050     m_IPGroup = orig.m_IPGroup;
00051     m_CDPointForces = orig.m_CDPointForces;
00052     return *this;
00053 }
00054 //-----------------------------------------------------------------------------
00055 //=============================================================================
00056 // Operations
00057 //-----------------------------------------------------------------------------
00058 template <typename T>
00059 InteractionPoint<T> const & InteractionPointGroup<T>::GetInteractionPointAtIndex ( unsigned int i ) const
00060 {
00061     assert( i < m_IPGroup.size() );
00062     return m_IPGroup[i];
00063 }
00064 //-----------------------------------------------------------------------------
00065 template <typename T>
00066 InteractionPoint<T> & InteractionPointGroup<T>::GetInteractionPointAtIndex ( unsigned int i )
00067 {
00068     assert( i < m_IPGroup.size() );
00069     return m_IPGroup[i];
00070 }
00071 //-----------------------------------------------------------------------------
00072 template <typename T>
00073 std::vector< InteractionPoint<T> > const & InteractionPointGroup<T>::GetTheSetOfInteractionPoints () const
00074 {
00075     return m_IPGroup;
00076 }
00077 //-----------------------------------------------------------------------------
00078 template <typename T>
00079 unsigned int InteractionPointGroup<T>::GetNumOfInteractionPoints () const
00080 {
00081     return m_IPGroup.size();
00082 }
00083 //-----------------------------------------------------------------------------
00084 template <typename T>
00085 std::vector< InteractionPoint<T> > & InteractionPointGroup<T>::GetTheSetOfInteractionPoints ()
00086 {
00087     return m_IPGroup;
00088 }
00089 //-----------------------------------------------------------------------------
00090 template <typename T>
00091 void InteractionPointGroup<T>::AddInteractionPoint (
00092     Vector3<T> const & position,    
00093     typename PointMass<T>::Type typeOfPointMass 
00094 )
00095 {
00096     m_IPGroup.push_back( InteractionPoint<T>( position, typeOfPointMass, m_IPGroup.size() ) );
00097 }
00098 //-----------------------------------------------------------------------------
00099 template <typename T>
00100 void InteractionPointGroup<T>::SortInteractionPointsBasedOnDistanceFromTheOriginPos_LessThan ()
00101 {
00102     sort( m_IPGroup.begin(), m_IPGroup.end(), InteractionPoint<T>::CompareDistanceFromOriginPos_LessThan );
00103     int id = 0;
00104     for ( std::vector< InteractionPoint<T> >::iterator it = m_IPGroup.begin();
00105         it != m_IPGroup.end(); ++it )
00106     {
00107         it->SetID( id++ );
00108     }
00109 }
00110 //-----------------------------------------------------------------------------
00111 template <typename T>
00112 void InteractionPointGroup<T>::SortInteractionPointsBasedOnDistanceFromTheOriginPos_GreaterThan ()
00113 {
00114     sort( m_IPGroup.begin(), m_IPGroup.end(), InteractionPoint<T>::CompareDistanceFromOriginPos_GreaterThan );
00115     int id = 0;
00116     for ( std::vector< InteractionPoint<T> >::iterator it = m_IPGroup.begin();
00117         it != m_IPGroup.end(); ++it )
00118     {
00119         it->SetID( id++ );
00120     }
00121 }
00122 //-----------------------------------------------------------------------------
00123 template <typename T>
00124 bool InteractionPointGroup<T>::CalVolumeAndCentroid ( T & volume, Vector3<T> & centroid )
00125 {
00126     unsigned int size = m_IPGroup.size();
00127     if ( size == 0 )    return false;
00128 
00129     volume = 0;
00130     Vector3<T> sumOfIPCentroidMultWithIPMass;
00131     for ( unsigned int i = 0; i < size; ++i ) {
00132         sumOfIPCentroidMultWithIPMass += m_IPGroup[i].GetPosition() * m_IPGroup[i].GetMass();
00133         volume += m_IPGroup[i].GetMass();
00134     }
00135     centroid = sumOfIPCentroidMultWithIPMass / volume;
00136 
00137     return true;
00138 }
00139 //-----------------------------------------------------------------------------
00140 template <typename T>
00141 void InteractionPointGroup<T>::TransformedBy ( Matrix4x4<T> const & Trx )
00142 {
00143     std::vector< InteractionPoint<T> >::iterator it = m_IPGroup.begin();
00144     while ( it != m_IPGroup.end() ) {
00145         it->SetPosition( Trx * it->GetPosition() );
00146         ++it;
00147     }
00148 }
00149 //-----------------------------------------------------------------------------
00150 //=============================================================================
00151 
00152 
00153 //=============================================================================
00154 // OpenGL
00155 #if defined(__gl_h_) || defined(__GL_H__)
00156 //-----------------------------------------------------------------------------
00157 template <typename T>
00158 void InteractionPointGroup<T>::Draw () const
00159 {
00160     std::vector< InteractionPoint<T> >::const_iterator it = m_IPGroup.begin();
00161     glPushAttrib( GL_ALL_ATTRIB_BITS );
00162     glDisable( GL_LIGHTING );
00163     glPointSize( 8 );
00164     glLineWidth( 2 );
00165     glColor3f( 0, 1, 0 );
00166     glBegin( GL_POINTS );
00167     while ( it != m_IPGroup.end() ) {
00168         glVertex3fv( it->GetPosition().GetDataFloat() );
00169         ++it;
00170     }
00171     glEnd();
00172     it = m_IPGroup.begin();
00173     glColor3f( 0, 1, 1 );
00174     glBegin( GL_LINE_STRIP );
00175     while ( it != m_IPGroup.end() ) {
00176         glVertex3fv( it->GetPosition().GetDataFloat() );
00177         ++it;
00178     }
00179     glEnd();
00180     glPopAttrib();
00181 }
00182 //-----------------------------------------------------------------------------
00183 #endif  // OpenGL
00184 //=============================================================================
00185 
00186 
00187 //=============================================================================
00188 END_NAMESPACE_TAPs
00189 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00190 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines