BoxConstraint.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_CONSTRAINT_BOXCONSTRAINT_INL
00026 #define SOFA_COMPONENT_CONSTRAINT_BOXCONSTRAINT_INL
00027 
00028 #if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
00029 #pragma once
00030 #endif
00031 
00032 //#include <sofa/component/constraint/FixedConstraint.inl>
00033 #include <sofa/component/constraint/BoxConstraint.h>
00034 #include <sofa/helper/gl/template.h>
00035 
00036 
00037 namespace sofa
00038 {
00039 
00040 namespace component
00041 {
00042 
00043 namespace constraint
00044 {
00045 
00046 using std::cout;
00047 using std::cerr;
00048 using std::endl;
00049 
00050 using namespace sofa::helper;
00051 using namespace sofa::defaulttype;
00052 
00053 template <class DataTypes>
00054 BoxConstraint<DataTypes>::BoxConstraint()
00055 : boxes( initData( &boxes, "box", "DOFs in the box defined by xmin,ymin,zmin, xmax,ymax,zmax are fixed") )
00056 {
00057     boxes.beginEdit()->push_back(Vec6(0,0,0,1,1,1));
00058     boxes.endEdit();
00059 }
00060 
00061 template <class DataTypes>
00062 void BoxConstraint<DataTypes>::init()
00063 {
00064     Inherited::init();
00065     const helper::vector<Vec6>& vb=boxes.getValue();
00066     vector <unsigned> indices;
00067     this->clearConstraints();
00068     for (unsigned int bi=0;bi<vb.size();++bi)
00069     {
00070         const Vec6& b=vb[bi];
00071         indices.clear();
00072         this->mstate->getIndicesInSpace( indices, b[0],b[3],b[1],b[4],b[2],b[5] );
00073         for(unsigned int i = 0; i < indices.size(); i++)
00074         {
00075             this->addConstraint(indices[i]);
00076         }
00077     }
00078 }
00079 
00080 
00081 
00082 template <class DataTypes>
00083 BoxConstraint<DataTypes>::~BoxConstraint()
00084 {}
00085 
00086 
00087 template <class DataTypes>
00088 void BoxConstraint<DataTypes>::draw()
00089 {
00090     if (!this->getContext()->getShowBehaviorModels())
00091         return;
00092     const VecCoord& x = *this->mstate->getX();
00093     glDisable (GL_LIGHTING);
00094     glPointSize(10);
00095     glColor4f (1,0.5,0.5,1);
00096     glBegin (GL_POINTS);
00097     const SetIndex& indices = this->f_indices.getValue();
00098     for (typename SetIndex::const_iterator it = indices.begin();
00099         it != indices.end();
00100         ++it)
00101     {
00102         gl::glVertexT(x[*it]);
00103     }
00104     glEnd();
00105     
00107     glBegin(GL_LINES);
00108     const helper::vector<Vec6>& vb=boxes.getValue();
00109     for (unsigned int bi=0;bi<vb.size();++bi)
00110     {
00111         const Vec6& b=vb[bi];
00112         //const Vec6& b=box.getValue();
00113         const Real& Xmin=b[0];
00114         const Real& Xmax=b[3];
00115         const Real& Ymin=b[1];
00116         const Real& Ymax=b[4];
00117         const Real& Zmin=b[2];
00118         const Real& Zmax=b[5];
00119         glVertex3d(Xmin,Ymin,Zmin);
00120         glVertex3d(Xmin,Ymin,Zmax);
00121         glVertex3d(Xmin,Ymin,Zmin);
00122         glVertex3d(Xmax,Ymin,Zmin);
00123         glVertex3d(Xmin,Ymin,Zmin);
00124         glVertex3d(Xmin,Ymax,Zmin);
00125         glVertex3d(Xmin,Ymax,Zmin);
00126         glVertex3d(Xmax,Ymax,Zmin);
00127         glVertex3d(Xmin,Ymax,Zmin);
00128         glVertex3d(Xmin,Ymax,Zmax);
00129         glVertex3d(Xmin,Ymax,Zmax);
00130         glVertex3d(Xmin,Ymin,Zmax);
00131         glVertex3d(Xmin,Ymin,Zmax);
00132         glVertex3d(Xmax,Ymin,Zmax);
00133         glVertex3d(Xmax,Ymin,Zmax);
00134         glVertex3d(Xmax,Ymax,Zmax);
00135         glVertex3d(Xmax,Ymin,Zmax);
00136         glVertex3d(Xmax,Ymin,Zmin);
00137         glVertex3d(Xmin,Ymax,Zmax);
00138         glVertex3d(Xmax,Ymax,Zmax);
00139         glVertex3d(Xmax,Ymax,Zmin);
00140         glVertex3d(Xmax,Ymin,Zmin);
00141         glVertex3d(Xmax,Ymax,Zmin);
00142         glVertex3d(Xmax,Ymax,Zmax);
00143     }
00144     glEnd();
00145 }
00146 
00147 template <class DataTypes>
00148     bool BoxConstraint<DataTypes>::addBBox(double* minBBox, double* maxBBox)
00149 {
00150     const helper::vector<Vec6>& vb=boxes.getValue();
00151     for (unsigned int bi=0;bi<vb.size();++bi)
00152     {
00153         const Vec6& b=vb[bi];
00154         //const Vec6& b=box.getValue();
00155         if (b[0] < minBBox[0]) minBBox[0] = b[0];
00156         if (b[1] < minBBox[1]) minBBox[1] = b[1];
00157         if (b[2] < minBBox[2]) minBBox[2] = b[2];
00158         if (b[3] > maxBBox[0]) maxBBox[0] = b[3];
00159         if (b[4] > maxBBox[1]) maxBBox[1] = b[4];
00160         if (b[5] > maxBBox[2]) maxBBox[2] = b[5];
00161     }
00162     return true;
00163 }
00164 
00165 } // namespace constraint
00166 
00167 } // namespace component
00168 
00169 } // namespace sofa
00170 
00171 #endif

Generated on Sun Nov 23 02:39:03 2008 for Sofa by  doxygen 1.5.7.1