SparseGridSpringForceField.inl

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #ifndef SOFA_COMPONENT_FORCEFIELD_SPARSEGRIDSPRINGFORCEFIELD_INL
00026 #define SOFA_COMPONENT_FORCEFIELD_SPARSEGRIDSPRINGFORCEFIELD_INL
00027 
00028 #include <sofa/component/forcefield/SparseGridSpringForceField.h>
00029 #include <sofa/component/forcefield/StiffSpringForceField.inl>
00030 #include <sofa/helper/gl/template.h>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace component
00036 {
00037 
00038 namespace forcefield
00039 {
00040 
00041 template<class DataTypes>
00042 void SparseGridSpringForceField<DataTypes>::parse(core::objectmodel::BaseObjectDescription* arg)
00043 {
00044     this->Inherit::parse(arg);
00045     if (arg->getAttribute("stiffness")) this->setStiffness((Real)atof(arg->getAttribute("stiffness")));
00046     if (arg->getAttribute("damping")) this->setDamping((Real)atof(arg->getAttribute("damping")));
00047 }
00048 
00049 using std::cout;
00050 using std::cerr;
00051 using std::endl;
00052 
00053 template <class DataTypes>
00054 void SparseGridSpringForceField<DataTypes>::addForce(VecDeriv& f1, VecDeriv& f2, const VecCoord& x1, const VecCoord& x2, const VecDeriv& v1, const VecDeriv& v2)
00055 {
00056     // Calc any custom springs
00057     this->StiffSpringForceField<DataTypes>::addForce(f1, f2, x1, x2, v1, v2);
00058     // Compute topological springs
00059     f1.resize(x1.size());
00060     f2.resize(p2.size());
00061     this->m_potentialEnergy = 0;
00062 
00063 
00064     if (this->object1==this->object2)
00065     {
00066         topology::MultiResSparseGridTopology* topology = dynamic_cast<topology::MultiResSparseGridTopology*>(this->object1->getContext()->getTopology());
00067         if (topology != NULL)
00068         {
00069             int index = this->springs.size();
00070             int size = index;
00071             size += topology->getNbVoxels()*24;
00072             this->dfdx.resize(size);
00073         
00074             int i,j,k;
00075 
00076             Voxels *voxels;
00077 
00078             voxels = &(topology->vectorSparseGrid[topology->resolution]);
00079 
00080         std::map<Voxels::Index3D,Voxels::Voxel>::iterator iter;
00081 
00082         for(iter = voxels->getVoxelsMapBegin(); iter != voxels->getVoxelsMapEnd(); iter++)
00083             {
00084 
00086                 i = (*iter).first.i;
00087                 j = (*iter).first.j;
00088                 k = (*iter).first.k;
00089 
00090                 if (this->linesStiffness.getValue() != 0.0 || this->linesDamping.getValue() != 0.0)
00091                 {
00092                     typename SparseGridSpringForceField<DataTypes>::Spring spring;
00093 
00095                     spring.initpos = topology->getDx().norm();
00096                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00097                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00098 
00100                     spring.m1 = topology->point(i,j,k);
00101                     spring.m2 = topology->point(i+1,j,k);
00102                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00103                     spring.m1 = topology->point(i,j+1,k);
00104                     spring.m2 = topology->point(i+1,j+1,k);
00105                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00106                     spring.m1 = topology->point(i,j,k+1);
00107                     spring.m2 = topology->point(i+1,j,k+1);
00108                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00109                     spring.m1 = topology->point(i,j+1,k+1);
00110                     spring.m2 = topology->point(i+1,j+1,k+1);
00111                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00112 
00114                     spring.initpos = topology->getDy().norm();
00115                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00116                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00117 
00119                     spring.m1 = topology->point(i,j,k);
00120                     spring.m2 = topology->point(i,j+1,k);
00121                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00122                     spring.m1 = topology->point(i+1,j,k);
00123                     spring.m2 = topology->point(i+1,j+1,k);
00124                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00125                     spring.m1 = topology->point(i,j,k+1);
00126                     spring.m2 = topology->point(i,j+1,k+1);
00127                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00128                     spring.m1 = topology->point(i+1,j,k+1);
00129                     spring.m2 = topology->point(i+1,j+1,k+1);
00130                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00131 
00133                     spring.initpos = topology->getDz().norm();
00134                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00135                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00136 
00138                     spring.m1 = topology->point(i,j,k);
00139                     spring.m2 = topology->point(i,j,k+1);
00140                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00141                     spring.m1 = topology->point(i+1,j,k);
00142                     spring.m2 = topology->point(i+1,j,k+1);
00143                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00144                     spring.m1 = topology->point(i,j+1,k);
00145                     spring.m2 = topology->point(i,j+1,k+1);
00146                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00147                     spring.m1 = topology->point(i+1,j+1,k);
00148                     spring.m2 = topology->point(i+1,j+1,k+1);
00149                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring);
00150                 }
00151 
00152                 if (this->quadsStiffness.getValue() != 0.0 || this->quadsDamping.getValue() != 0.0)
00153                 {
00154                     typename SparseGridSpringForceField<DataTypes>::Spring spring1;
00155                     typename SparseGridSpringForceField<DataTypes>::Spring spring2;
00156 
00158                     // lines (x,y,z) -> (x+1,y+1,z)
00159                     spring1.initpos = (topology->getDx()+topology->getDy()).norm();
00160                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00161                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00162                     // lines (x+1,y,z) -> (x,y+1,z)
00163                     spring2.initpos = (topology->getDx()-topology->getDy()).norm();
00164                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00165                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00166 
00168                     spring1.m1 = topology->point(i,j,k);
00169                     spring1.m2 = topology->point(i+1,j+1,k);
00170                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring1);
00171                     spring2.m1 = topology->point(i,j+1,k);
00172                     spring2.m2 = topology->point(i+1,j,k);
00173                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring2);
00174                     spring1.m1 = topology->point(i,j,k+1);
00175                     spring1.m2 = topology->point(i+1,j+1,k+1);
00176                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring1);
00177                     spring2.m1 = topology->point(i,j+1,k+1);
00178                     spring2.m2 = topology->point(i+1,j,k+1);
00179                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring2);
00180 
00182                     // lines (x,y,z) -> (x+1,y,z+1)
00183                     spring1.initpos = (topology->getDx()+topology->getDz()).norm();
00184                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00185                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00186                     // lines (x+1,y,z) -> (x,y,z+1)
00187                     spring2.initpos = (topology->getDx()-topology->getDz()).norm();
00188                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00189                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00190 
00192                     spring1.m1 = topology->point(i,j,k);
00193                     spring1.m2 = topology->point(i+1,j,k+1);
00194                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring1);
00195                     spring2.m1 = topology->point(i,j,k+1);
00196                     spring2.m2 = topology->point(i+1,j,k);
00197                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring2);
00198                     spring1.m1 = topology->point(i,j+1,k);
00199                     spring1.m2 = topology->point(i+1,j+1,k+1);
00200                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring1);
00201                     spring2.m1 = topology->point(i,j+1,k+1);
00202                     spring2.m2 = topology->point(i+1,j+1,k);
00203                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring2);
00204 
00206                     // lines (x,y,z) -> (x,y+1,z+1)
00207                     spring1.initpos = (topology->getDy()+topology->getDz()).norm();
00208                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00209                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00210                     // lines (x,y+1,z) -> (x,y,z+1)
00211                     spring2.initpos = (topology->getDy()-topology->getDz()).norm();
00212                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00213                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00214 
00216                     spring1.m1 = topology->point(i,j,k);
00217                     spring1.m2 = topology->point(i,j+1,k+1);
00218                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring1);
00219                     spring2.m1 = topology->point(i,j,k+1);
00220                     spring2.m2 = topology->point(i,j+1,k);
00221                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring2);
00222                     spring1.m1 = topology->point(i+1,j,k);
00223                     spring1.m2 = topology->point(i+1,j+1,k+1);
00224                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring1);
00225                     spring2.m1 = topology->point(i+1,j,k+1);
00226                     spring2.m2 = topology->point(i+1,j+1,k);
00227                     this->addSpringForce(this->m_potentialEnergy,f1,x1,v1,f2,p2,v2, index++, spring2);
00228                 }
00229             }
00230 
00231         }
00232     }
00233 }
00234 
00235 template<class DataTypes>
00236 void SparseGridSpringForceField<DataTypes>::addDForce(VecDeriv& df1, VecDeriv& df2, const VecDeriv& dx1, const VecDeriv& dx2, double kFactor, double bFactor)
00237 {
00238     // Calc any custom springs
00239     this->StiffSpringForceField<DataTypes>::addDForce(df1,df2,dx1,dx2, kFactor, bFactor);
00240     // Compute topological springs
00241     df1.resize(dx1.size());
00242     df2.resize(dx2.size());
00243     if (this->object1==this->object2)
00244     {
00245         topology::MultiResSparseGridTopology* topology = dynamic_cast<topology::MultiResSparseGridTopology*>(this->object1->getContext()->getTopology());
00246         if (topology != NULL)
00247         {
00248             int index = this->springs.size();
00249             int size = index;
00250             size += topology->getNbVoxels()*24;
00251             this->dfdx.resize(size);
00252 
00253             //variable permettant de calculer
00254             int i,j,k;
00255 
00256             Voxels *voxels;
00257 
00258             voxels = &(topology->vectorSparseGrid[topology->resolution]);
00259 
00260         std::map<Voxels::Index3D,Voxels::Voxel>::iterator iter;
00261 
00262         for(iter = voxels->getVoxelsMapBegin(); iter != voxels->getVoxelsMapEnd(); iter++)
00263             {
00264 
00265                 i = (*iter).first.i;
00266                 j = (*iter).first.j;
00267                 k = (*iter).first.k;
00268 
00269 
00270                 if (this->linesStiffness.getValue() != 0.0 || this->linesDamping.getValue() != 0.0)
00271                 {
00272                     typename SparseGridSpringForceField<DataTypes>::Spring spring;
00273 
00275                     spring.initpos = topology->getDx().norm();
00276                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00277                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00279                     spring.m1 = topology->point(i,j,k);
00280                     spring.m2 = topology->point(i+1,j,k);
00281                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00282                     spring.m1 = topology->point(i,j+1,k);
00283                     spring.m2 = topology->point(i+1,j+1,k);
00284                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00285                     spring.m1 = topology->point(i,j,k+1);
00286                     spring.m2 = topology->point(i+1,j,k+1);
00287                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00288                     spring.m1 = topology->point(i,j+1,k+1);
00289                     spring.m2 = topology->point(i+1,j+1,k+1);
00290                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00291 
00293                     spring.initpos = topology->getDy().norm();
00294                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00295                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00297                     spring.m1 = topology->point(i,j,k);
00298                     spring.m2 = topology->point(i,j+1,k);
00299                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00300                     spring.m1 = topology->point(i+1,j,k);
00301                     spring.m2 = topology->point(i+1,j+1,k);
00302                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00303                     spring.m1 = topology->point(i,j,k+1);
00304                     spring.m2 = topology->point(i,j+1,k+1);
00305                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00306                     spring.m1 = topology->point(i+1,j,k+1);
00307                     spring.m2 = topology->point(i+1,j+1,k+1);
00308                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00309 
00311                     spring.initpos = topology->getDz().norm();
00312                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00313                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00314 
00316                     spring.m1 = topology->point(i,j,k);
00317                     spring.m2 = topology->point(i,j,k+1);
00318                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00319                     spring.m1 = topology->point(i+1,j,k);
00320                     spring.m2 = topology->point(i+1,j,k+1);
00321                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00322                     spring.m1 = topology->point(i,j+1,k);
00323                     spring.m2 = topology->point(i,j+1,k+1);
00324                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00325                     spring.m1 = topology->point(i+1,j+1,k);
00326                     spring.m2 = topology->point(i+1,j+1,k+1);
00327                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring, kFactor, bFactor);
00328                 }
00329 
00330                 if (this->quadsStiffness.getValue() != 0.0 || this->quadsDamping.getValue() != 0.0)
00331                 {
00332                     typename SparseGridSpringForceField<DataTypes>::Spring spring1;
00333                     typename SparseGridSpringForceField<DataTypes>::Spring spring2;
00334 
00336                     // lines (x,y,z) -> (x+1,y+1,z)
00337                     spring1.initpos = (topology->getDx()+topology->getDy()).norm();
00338                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00339                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00340                     // lines (x+1,y,z) -> (x,y+1,z)
00341                     spring2.initpos = (topology->getDx()-topology->getDy()).norm();
00342                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00343                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00344 
00346                     spring1.m1 = topology->point(i,j,k);
00347                     spring1.m2 = topology->point(i+1,j+1,k);
00348                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring1);
00349                     spring2.m1 = topology->point(i,j+1,k);
00350                     spring2.m2 = topology->point(i+1,j,k);
00351                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring2);
00352                     spring1.m1 = topology->point(i,j,k+1);
00353                     spring1.m2 = topology->point(i+1,j+1,k+1);
00354                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring1);
00355                     spring2.m1 = topology->point(i,j+1,k+1);
00356                     spring2.m2 = topology->point(i+1,j,k+1);
00357                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring2);
00358 
00360                     // lines (x,y,z) -> (x+1,y,z+1)
00361                     spring1.initpos = (topology->getDx()+topology->getDz()).norm();
00362                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00363                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00364                     // lines (x+1,y,z) -> (x,y,z+1)
00365                     spring2.initpos = (topology->getDx()-topology->getDz()).norm();
00366                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00367                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00368 
00370                     spring1.m1 = topology->point(i,j,k);
00371                     spring1.m2 = topology->point(i+1,j,k+1);
00372                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring1);
00373                     spring2.m1 = topology->point(i,j,k+1);
00374                     spring2.m2 = topology->point(i+1,j,k);
00375                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring2);
00376                     spring1.m1 = topology->point(i,j+1,k);
00377                     spring1.m2 = topology->point(i+1,j+1,k+1);
00378                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring1);
00379                     spring2.m1 = topology->point(i,j+1,k+1);
00380                     spring2.m2 = topology->point(i+1,j+1,k);
00381                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring2);
00382 
00384                     // lines (x,y,z) -> (x,y+1,z+1)
00385                     spring1.initpos = (topology->getDy()+topology->getDz()).norm();
00386                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00387                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00388                     // lines (x,y+1,z) -> (x,y,z+1)
00389                     spring2.initpos = (topology->getDy()-topology->getDz()).norm();
00390                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00391                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00392 
00394                     spring1.m1 = topology->point(i,j,k);
00395                     spring1.m2 = topology->point(i,j+1,k+1);
00396                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring1);
00397                     spring2.m1 = topology->point(i,j,k+1);
00398                     spring2.m2 = topology->point(i,j+1,k);
00399                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring2);
00400                     spring1.m1 = topology->point(i+1,j,k);
00401                     spring1.m2 = topology->point(i+1,j+1,k+1);
00402                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring1);
00403                     spring2.m1 = topology->point(i+1,j,k+1);
00404                     spring2.m2 = topology->point(i+1,j+1,k);
00405                     this->addSpringDForce(df1,dx1,df2,dx2, index++, spring2);
00406                 }
00407             }
00408         }
00409     }
00410 }
00411 
00412 
00413 
00414 template<class DataTypes>
00415 void SparseGridSpringForceField<DataTypes>::draw()
00416 {
00417     if (!this->getContext()->getShowForceFields())
00418         return;
00419     assert(this->object1);
00420     assert(this->object2);
00421     // Draw any custom springs
00422     this->StiffSpringForceField<DataTypes>::draw();
00423     // Compute topological springs
00424     const VecCoord& p1 = *this->object1->getX();
00425     const VecCoord& p2 = *this->object2->getX();
00426 
00427     glDisable(GL_LIGHTING);
00428     glColor4f(0.0,0.5,0.0,1);
00429     glBegin(GL_LINES);
00430     if (this->object1==this->object2)
00431     {
00432         topology::MultiResSparseGridTopology* topology = dynamic_cast<topology::MultiResSparseGridTopology*>(this->object1->getContext()->getTopology());
00433         if (topology != NULL)
00434         {
00435 
00436             //const int nz = topology->getNz();
00437 
00438             //variable permettant de calculer
00439             int i,j,k;
00440 
00441             Voxels *voxels;
00442 
00443             voxels = &(topology->vectorSparseGrid[topology->resolution]);
00444 
00445         std::map<Voxels::Index3D,Voxels::Voxel>::iterator iter;
00446 
00447         for(iter = voxels->getVoxelsMapBegin(); iter != voxels->getVoxelsMapEnd(); iter++)
00448             {
00449                 i = (*iter).first.i;
00450                 j = (*iter).first.j;
00451                 k = (*iter).first.k;
00452 
00453                 if (this->linesStiffness.getValue() != 0.0 || this->linesDamping.getValue() != 0.0)
00454                 {
00455                     typename SparseGridSpringForceField<DataTypes>::Spring spring;
00456 
00458                     spring.initpos = topology->getDx().norm();
00459                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00460                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00462 
00463                     spring.m1 = topology->point(i,j,k);
00464                     spring.m2 = topology->point(i+1,j,k);
00465                     helper::gl::glVertexT(p1[spring.m1]);
00466                     helper::gl::glVertexT(p2[spring.m2]);
00467                     spring.m1 = topology->point(i,j+1,k);
00468                     spring.m2 = topology->point(i+1,j+1,k);
00469                     helper::gl::glVertexT(p1[spring.m1]);
00470                     helper::gl::glVertexT(p2[spring.m2]);
00471                     spring.m1 = topology->point(i,j,k+1);
00472                     spring.m2 = topology->point(i+1,j,k+1);
00473                     helper::gl::glVertexT(p1[spring.m1]);
00474                     helper::gl::glVertexT(p2[spring.m2]);
00475                     spring.m1 = topology->point(i,j+1,k+1);
00476                     spring.m2 = topology->point(i+1,j+1,k+1);
00477                     helper::gl::glVertexT(p1[spring.m1]);
00478                     helper::gl::glVertexT(p2[spring.m2]);
00479 
00481                     spring.initpos = topology->getDy().norm();
00482                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00483                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00485                     spring.m1 = topology->point(i,j,k);
00486                     spring.m2 = topology->point(i,j+1,k);
00487                     helper::gl::glVertexT(p1[spring.m1]);
00488                     helper::gl::glVertexT(p2[spring.m2]);
00489                     spring.m1 = topology->point(i+1,j,k);
00490                     spring.m2 = topology->point(i+1,j+1,k);
00491                     helper::gl::glVertexT(p1[spring.m1]);
00492                     helper::gl::glVertexT(p2[spring.m2]);
00493                     spring.m1 = topology->point(i,j,k+1);
00494                     spring.m2 = topology->point(i,j+1,k+1);
00495                     helper::gl::glVertexT(p1[spring.m1]);
00496                     helper::gl::glVertexT(p2[spring.m2]);
00497                     spring.m1 = topology->point(i+1,j,k+1);
00498                     spring.m2 = topology->point(i+1,j+1,k+1);
00499                     helper::gl::glVertexT(p1[spring.m1]);
00500                     helper::gl::glVertexT(p2[spring.m2]);
00501 
00503                     spring.initpos = topology->getDz().norm();
00504                     spring.ks = this->linesStiffness.getValue() / spring.initpos;
00505                     spring.kd = this->linesDamping.getValue() / spring.initpos;
00506 
00508                     spring.m1 = topology->point(i,j,k);
00509                     spring.m2 = topology->point(i,j,k+1);
00510                     helper::gl::glVertexT(p1[spring.m1]);
00511                     helper::gl::glVertexT(p2[spring.m2]);
00512                     spring.m1 = topology->point(i+1,j,k);
00513                     spring.m2 = topology->point(i+1,j,k+1);
00514                     helper::gl::glVertexT(p1[spring.m1]);
00515                     helper::gl::glVertexT(p2[spring.m2]);
00516                     spring.m1 = topology->point(i,j+1,k);
00517                     spring.m2 = topology->point(i,j+1,k+1);
00518                     helper::gl::glVertexT(p1[spring.m1]);
00519                     helper::gl::glVertexT(p2[spring.m2]);
00520                     spring.m1 = topology->point(i+1,j+1,k);
00521                     spring.m2 = topology->point(i+1,j+1,k+1);
00522                     helper::gl::glVertexT(p1[spring.m1]);
00523                     helper::gl::glVertexT(p2[spring.m2]);
00524 
00525 
00526 
00527                     typename SparseGridSpringForceField<DataTypes>::Spring spring1;
00528                     typename SparseGridSpringForceField<DataTypes>::Spring spring2;
00530                     // lines (x,y,z) -> (x+1,y+1,z)
00531                     spring1.initpos = (topology->getDx()+topology->getDy()).norm();
00532                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00533                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00534                     // lines (x+1,y,z) -> (x,y+1,z)
00535                     spring2.initpos = (topology->getDx()-topology->getDy()).norm();
00536                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00537                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00538 
00540                     spring1.m1 = topology->point(i,j,k);
00541                     spring1.m2 = topology->point(i+1,j+1,k);
00542                     helper::gl::glVertexT(p1[spring1.m1]);
00543                     helper::gl::glVertexT(p2[spring1.m2]);
00544                     spring2.m1 = topology->point(i,j+1,k);
00545                     spring2.m2 = topology->point(i+1,j,k);
00546                     helper::gl::glVertexT(p1[spring2.m1]);
00547                     helper::gl::glVertexT(p2[spring2.m2]);
00548                     spring1.m1 = topology->point(i,j,k+1);
00549                     spring1.m2 = topology->point(i+1,j+1,k+1);
00550                     helper::gl::glVertexT(p1[spring1.m1]);
00551                     helper::gl::glVertexT(p2[spring1.m2]);
00552                     spring2.m1 = topology->point(i,j+1,k+1);
00553                     spring2.m2 = topology->point(i+1,j,k+1);
00554                     helper::gl::glVertexT(p1[spring2.m1]);
00555                     helper::gl::glVertexT(p2[spring2.m2]);
00556 
00558                     // lines (x,y,z) -> (x+1,y,z+1)
00559                     spring1.initpos = (topology->getDx()+topology->getDz()).norm();
00560                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00561                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00562                     // lines (x+1,y,z) -> (x,y,z+1)
00563                     spring2.initpos = (topology->getDx()-topology->getDz()).norm();
00564                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00565                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00566 
00568                     spring1.m1 = topology->point(i,j,k);
00569                     spring1.m2 = topology->point(i+1,j,k+1);
00570                     helper::gl::glVertexT(p1[spring1.m1]);
00571                     helper::gl::glVertexT(p2[spring1.m2]);
00572                     spring2.m1 = topology->point(i,j,k+1);
00573                     spring2.m2 = topology->point(i+1,j,k);
00574                     helper::gl::glVertexT(p1[spring2.m1]);
00575                     helper::gl::glVertexT(p2[spring2.m2]);
00576                     spring1.m1 = topology->point(i,j+1,k);
00577                     spring1.m2 = topology->point(i+1,j+1,k+1);
00578                     helper::gl::glVertexT(p1[spring1.m1]);
00579                     helper::gl::glVertexT(p2[spring1.m2]);
00580                     spring2.m1 = topology->point(i,j+1,k+1);
00581                     spring2.m2 = topology->point(i+1,j+1,k);
00582                     helper::gl::glVertexT(p1[spring2.m1]);
00583                     helper::gl::glVertexT(p2[spring2.m2]);
00584 
00586                     // lines (x,y,z) -> (x,y+1,z+1)
00587                     spring1.initpos = (topology->getDy()+topology->getDz()).norm();
00588                     spring1.ks = this->linesStiffness.getValue() / spring1.initpos;
00589                     spring1.kd = this->linesDamping.getValue() / spring1.initpos;
00590                     // lines (x,y+1,z) -> (x,y,z+1)
00591                     spring2.initpos = (topology->getDy()-topology->getDz()).norm();
00592                     spring2.ks = this->linesStiffness.getValue() / spring2.initpos;
00593                     spring2.kd = this->linesDamping.getValue() / spring2.initpos;
00594 
00596                     spring1.m1 = topology->point(i,j,k);
00597                     spring1.m2 = topology->point(i,j+1,k+1);
00598                     helper::gl::glVertexT(p1[spring1.m1]);
00599                     helper::gl::glVertexT(p2[spring1.m2]);
00600                     spring2.m1 = topology->point(i,j,k+1);
00601                     spring2.m2 = topology->point(i,j+1,k);
00602                     helper::gl::glVertexT(p1[spring2.m1]);
00603                     helper::gl::glVertexT(p2[spring2.m2]);
00604                     spring1.m1 = topology->point(i+1,j,k);
00605                     spring1.m2 = topology->point(i+1,j+1,k+1);
00606                     helper::gl::glVertexT(p1[spring1.m1]);
00607                     helper::gl::glVertexT(p2[spring1.m2]);
00608                     spring2.m1 = topology->point(i+1,j,k+1);
00609                     spring2.m2 = topology->point(i+1,j+1,k);
00610                     helper::gl::glVertexT(p1[spring2.m1]);
00611                     helper::gl::glVertexT(p2[spring2.m2]);
00612                 }
00613             }
00614 
00615         }
00616     }
00617     glEnd();
00618 }
00619 
00620 } // namespace forcefield
00621 
00622 } // namespace component
00623 
00624 } // namespace sofa
00625 
00626 #endif

Generated on Sun Nov 23 03:05:06 2008 for Sofa by  doxygen 1.5.7.1