OglTetrahedralModel.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 OGLTETRAHEDRALMODEL_INL_
00026 #define OGLTETRAHEDRALMODEL_INL_
00027 
00028 #include "OglTetrahedralModel.h"
00029 
00030 #include <sofa/helper/gl/GLSLShader.h>
00031 
00032 namespace sofa
00033 {
00034 namespace component
00035 {
00036 namespace visualmodel
00037 {
00038 
00039 using namespace sofa::defaulttype;
00040 
00041 template<class DataTypes>
00042 OglTetrahedralModel<DataTypes>::OglTetrahedralModel()
00043 :depthTest(initData(&depthTest, (bool) true, "depthTest", "Set Depth Test")),
00044 blending(initData(&blending, (bool) true, "blending", "Set Blending"))
00045 {
00046 }
00047 
00048 template<class DataTypes>
00049 OglTetrahedralModel<DataTypes>::~OglTetrahedralModel()
00050 {
00051 }
00052 
00053 template<class DataTypes>
00054 void OglTetrahedralModel<DataTypes>::init()
00055 {
00056     sofa::core::objectmodel::BaseContext* context = this->getContext();
00057     context->get(topo);
00058     context->get(nodes);
00059 
00060 
00061     if (!nodes)
00062     {
00063         std::cerr << "OglTetrahedralModel : Error : no MechanicalState found." << std::endl;
00064         return;
00065     }
00066 
00067     if (!topo)
00068     {
00069         std::cerr << "OglTetrahedralModel : Error : no BaseMeshTopology found." << std::endl;
00070         return;
00071     }
00072 }
00073 
00074 template<class DataTypes>
00075 void OglTetrahedralModel<DataTypes>::drawTransparent()
00076 {
00077     if (!getContext()->getShowVisualModels()) return;
00078 
00079     if(blending.getValue())
00080         glEnable(GL_BLEND);
00081     if(depthTest.getValue())
00082         glDepthMask(GL_FALSE);
00083 
00084     glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
00085     core::componentmodel::topology::BaseMeshTopology::SeqTetras::const_iterator it;
00086 
00087 #ifdef GL_LINES_ADJACENCY_EXT
00088     const core::componentmodel::topology::BaseMeshTopology::SeqTetras& vec = topo->getTetras();
00089     VecCoord& x = *nodes->getX();
00090     Coord v;
00091 
00092     glBegin(GL_LINES_ADJACENCY_EXT);
00093     for(it = vec.begin() ; it != vec.end() ; it++)
00094     {
00095 
00096             for (unsigned int i=0 ; i< 4 ; i++){
00097                 v = x[(*it)[i]];
00098                 glVertex3f((GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]);
00099             }
00100     }
00101     glEnd();
00102 #endif
00103     glDisable(GL_BLEND);
00104     glDepthMask(GL_TRUE);
00105 }
00106 
00107 template<class DataTypes>
00108 bool OglTetrahedralModel<DataTypes>::addBBox(double* minBBox, double* maxBBox)
00109 {
00110     const core::componentmodel::topology::BaseMeshTopology::SeqTetras& vec = topo->getTetras();
00111     core::componentmodel::topology::BaseMeshTopology::SeqTetras::const_iterator it;
00112     VecCoord& x = *nodes->getX();
00113     Coord v;
00114 
00115     for(it = vec.begin() ; it != vec.end() ; it++)
00116     {
00117             for (unsigned int i=0 ; i< 4 ; i++){
00118                 v = x[(*it)[i]];
00119 
00120                 if (minBBox[0] > v[0]) minBBox[0] = v[0];
00121                 if (minBBox[1] > v[1]) minBBox[1] = v[1];
00122                 if (minBBox[2] > v[2]) minBBox[2] = v[2];
00123                 if (maxBBox[0] < v[0]) maxBBox[0] = v[0];
00124                 if (maxBBox[1] < v[1]) maxBBox[1] = v[1];
00125                 if (maxBBox[2] < v[2]) maxBBox[2] = v[2];
00126             }
00127     }
00128     return true;
00129 }
00130 
00131 }
00132 }
00133 }
00134 
00135 #endif //OGLTETRAHEDRALMODEL_H_

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