TubularMapping.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_MAPPING_TUBULARMAPPING_INL
00026 #define SOFA_COMPONENT_MAPPING_TUBULARMAPPING_INL
00027
00028 #include <sofa/component/mapping/TubularMapping.h>
00029 #include <sofa/defaulttype/VecTypes.h>
00030 #include <sofa/defaulttype/RigidTypes.h>
00031 #include <sofa/core/componentmodel/behavior/MechanicalMapping.inl>
00032 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00033
00034
00035 namespace sofa
00036 {
00037
00038 namespace component
00039 {
00040
00041 namespace mapping
00042 {
00043
00044 template <class BasicMapping>
00045 void TubularMapping<BasicMapping>::init()
00046 {
00047 this->BasicMapping::init();
00048
00049 }
00050
00051
00052
00053 template <class BasicMapping>
00054 void TubularMapping<BasicMapping>::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in )
00055 {
00056
00057
00058
00059
00060 if(out.size() != rotatedPoints.size()){
00061 rotatedPoints.resize(out.size());
00062 }
00063
00064 unsigned int N = m_nbPointsOnEachCircle.getValue();
00065 double rho = m_radius.getValue();
00066
00067 out.resize(in.size() * N);
00068 rotatedPoints.resize(in.size() * N);
00069
00070 Vec Y0;
00071 Vec Z0;
00072 Y0[0] = (Real) (0.0); Y0[1] = (Real) (1.0); Y0[2] = (Real) (0.0);
00073 Z0[0] = (Real) (0.0); Z0[1] = (Real) (0.0); Z0[2] = (Real) (1.0);
00074
00075 for (unsigned int i=0; i<in.size(); i++)
00076 {
00077 Vec curPos = in[i].getCenter();
00078
00079 Mat rotation;
00080 in[i].writeRotationMatrix(rotation);
00081
00082 Vec Y;
00083 Vec Z;
00084
00085 Y = rotation * Y0;
00086 Z = rotation * Z0;
00087
00088 for(unsigned int j=0; j<N; ++j){
00089
00090 rotatedPoints[i*N+j] = (Y*cos((Real) (2.0*j*M_PI/N)) + Z*sin((Real) (2.0*j*M_PI/N)))*((Real) rho);
00091 Vec x = curPos + rotatedPoints[i*N+j];
00092
00093
00094 out[i*N+j] = x;
00095 }
00096 }
00097 }
00098
00099
00100
00101 template <class BasicMapping>
00102 void TubularMapping<BasicMapping>::applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in )
00103 {
00104
00105
00106
00107 if(out.size() != rotatedPoints.size()){
00108 rotatedPoints.resize(out.size());
00109 }
00110
00111 unsigned int N = m_nbPointsOnEachCircle.getValue();
00112
00113 out.resize(in.size() * N);
00114 Deriv v,omega;
00115
00116 for (unsigned int i=0; i<in.size(); i++)
00117 {
00118 v = in[i].getVCenter();
00119 omega = in[i].getVOrientation();
00120
00121 for(unsigned int j=0; j<N; ++j){
00122
00123 out[i*N+j] = v - cross(rotatedPoints[i*N+j],omega);
00124
00125 }
00126 }
00127 }
00128
00129
00130 template <class BasicMapping>
00131 void TubularMapping<BasicMapping>::applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in )
00132 {
00133
00134
00135
00136
00137 if(in.size() != rotatedPoints.size()){
00138 rotatedPoints.resize(in.size());
00139 }
00140
00141 unsigned int N = m_nbPointsOnEachCircle.getValue();
00142
00143 Deriv v,omega;
00144
00145 for (unsigned int i=0; i<out.size(); i++)
00146 {
00147 for(unsigned int j=0; j<N; j++){
00148
00149 Deriv f = in[i*N+j];
00150 v += f;
00151 omega += cross(rotatedPoints[i*N+j],f);
00152 }
00153
00154 out[i].getVCenter() += v;
00155 out[i].getVOrientation() += omega;
00156
00157 }
00158
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 }
00180
00181 }
00182
00183 }
00184
00185 #endif // SOFA_COMPONENT_MAPPING_TUBULARMAPPING_INL