TriangleSetGeometryAlgorithms.h

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_TOPOLOGY_TRIANGLESETGEOMETRYALGORITHMS_H
00026 #define SOFA_COMPONENT_TOPOLOGY_TRIANGLESETGEOMETRYALGORITHMS_H
00027 
00028 #include <sofa/component/topology/EdgeSetGeometryAlgorithms.h>  
00029 
00030 namespace sofa
00031 {
00032 
00033 namespace component
00034 {
00035 
00036 namespace topology
00037 {
00038     using core::componentmodel::topology::BaseMeshTopology;
00039     typedef BaseMeshTopology::TriangleID TriangleID;
00040     typedef BaseMeshTopology::Triangle Triangle;
00041     typedef BaseMeshTopology::SeqTriangles SeqTriangles;
00042     typedef BaseMeshTopology::VertexTriangles VertexTriangles;
00043     typedef BaseMeshTopology::EdgeTriangles EdgeTriangles;
00044     typedef BaseMeshTopology::TriangleEdges TriangleEdges;
00045         
00049     template < class DataTypes >
00050     class TriangleSetGeometryAlgorithms : public EdgeSetGeometryAlgorithms<DataTypes>  
00051     {
00052     public:
00053         typedef typename DataTypes::VecCoord VecCoord;
00054         typedef typename DataTypes::Real Real;
00055         typedef typename DataTypes::Coord Coord;
00056 
00057         TriangleSetGeometryAlgorithms() 
00058         : EdgeSetGeometryAlgorithms<DataTypes>()
00059         {}
00060 
00061         virtual ~TriangleSetGeometryAlgorithms() {}
00062 
00066         const Coord& getPositionPoint(unsigned int i);
00067         
00071         Real computeTriangleArea(const unsigned int i) const;
00072 
00076         void computeTriangleArea( BasicArrayInterface<Real> &ai) const;
00077 
00081         Real computeRestTriangleArea(const unsigned int i) const;
00082 
00086         sofa::helper::vector< double > computeTriangleBarycoefs( const sofa::defaulttype::Vec<3,double> &p, unsigned int ind_t);
00087 
00091         sofa::helper::vector< double > compute3PointsBarycoefs( const sofa::defaulttype::Vec<3,double> &p, 
00092                                                                 unsigned int ind_p1, 
00093                                                                 unsigned int ind_p2, 
00094                                                                 unsigned int ind_p3);
00095 
00099         void closestIndexPair(unsigned int ind_ta, unsigned int ind_tb, unsigned int &ind1, unsigned int &ind2);
00100 
00104         bool is_PointinTriangle(bool is_tested, const sofa::defaulttype::Vec<3,Real>& p, unsigned int ind_t, unsigned int &ind_t_test);
00105 
00109         sofa::defaulttype::Vec<3,double> computeBaryEdgePoint(sofa::helper::vector< unsigned int>& indices, const double &coord_p);
00110 
00114         sofa::defaulttype::Vec<3,double> computeTriangleNormal(const unsigned int ind_t);
00115 
00119         bool isQuadDeulaunayOriented(const sofa::defaulttype::Vec<3,double>& p_q1, 
00120                                     const sofa::defaulttype::Vec<3,double>& p_q2, 
00121                                     unsigned int ind_q3, unsigned int ind_q4);
00122         
00126         sofa::defaulttype::Vec<3,double> getOppositePoint(unsigned int ind_p, sofa::helper::vector< unsigned int>& indices, const double &coord_p);
00127 
00131         bool is_triangle_in_plane(const unsigned int ind_t, const unsigned int ind_p, 
00132                                 const sofa::defaulttype::Vec<3,Real>& plane_vect);
00133 
00137         void Prepare_VertexDuplication(const unsigned int ind_p, 
00138                                     const unsigned int ind_t_from, const unsigned int ind_t_to, 
00139                                     const sofa::helper::vector< unsigned int>& indices_from, const double &coord_from, 
00140                                     const sofa::helper::vector< unsigned int>& indices_to, const double &coord_to, 
00141                                     sofa::helper::vector< unsigned int > &triangles_list_1, 
00142                                     sofa::helper::vector< unsigned int > &triangles_list_2);
00143                             
00147         bool computeSegmentTriangleIntersection(bool is_entered, 
00148                                                 const sofa::defaulttype::Vec<3,double>& a, 
00149                                                 const sofa::defaulttype::Vec<3,double>& b, 
00150                                                 const unsigned int ind_t,
00151                                                 sofa::helper::vector<unsigned int> &indices,
00152                                                 double &baryCoef, double& coord_kmin);
00153 
00157         bool computeIntersectedPointsList(const sofa::defaulttype::Vec<3,double>& a, 
00158                                         const sofa::defaulttype::Vec<3,double>& b, 
00159                                         const unsigned int ind_ta, unsigned int& ind_tb,
00160                                         sofa::helper::vector< unsigned int > &triangles_list, 
00161                                         sofa::helper::vector< sofa::helper::vector< unsigned int> > &indices_list, 
00162                                         sofa::helper::vector< double >& coords_list, 
00163                                         bool& is_on_boundary);
00164 
00167         void writeMSHfile(const char *filename);
00168     };
00169 
00170 
00171     template< class Real>
00172     bool is_point_in_triangle(const sofa::defaulttype::Vec<3,Real>& p, 
00173                             const sofa::defaulttype::Vec<3,Real>& a, 
00174                             const sofa::defaulttype::Vec<3,Real>& b, 
00175                             const sofa::defaulttype::Vec<3,Real>& c);
00176 
00177     template< class Real>      
00178     bool is_point_in_halfplane(const sofa::defaulttype::Vec<3,Real>& p, 
00179                                 unsigned int e0, unsigned int e1, 
00180                                 const sofa::defaulttype::Vec<3,Real>& a, 
00181                                 const sofa::defaulttype::Vec<3,Real>& b, 
00182                                 const sofa::defaulttype::Vec<3,Real>& c, 
00183                                 unsigned int ind_p0, unsigned int ind_p1, unsigned int ind_p2);
00184 
00185     void snapping_test_triangle(double epsilon, 
00186                                 double alpha0, double alpha1, double alpha2, 
00187                                 bool& is_snap_0, bool& is_snap_1, bool& is_snap_2);
00188 
00189     void snapping_test_edge(double epsilon, 
00190                             double alpha0, double alpha1, 
00191                             bool& is_snap_0, bool& is_snap_1);
00192     
00193     template< class Real>
00194     inline Real areaProduct(const sofa::defaulttype::Vec<3,Real>& a, const sofa::defaulttype::Vec<3,Real>& b);
00195     
00196     template< class Real>
00197     inline Real areaProduct(const defaulttype::Vec<2,Real>& a, const defaulttype::Vec<2,Real>& b );
00198     
00199     template< class Real>
00200     inline Real areaProduct(const defaulttype::Vec<1,Real>& , const defaulttype::Vec<1,Real>&  );
00201 
00202 } // namespace topology
00203 
00204 } // namespace component
00205 
00206 } // namespace sofa
00207 
00208 #endif

Generated on Sun Nov 23 03:47:09 2008 for Sofa by  doxygen 1.5.7.1