PointSetTopologyContainer.cpp

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 #include <sofa/component/topology/PointSetTopologyContainer.h>
00026 
00027 #include <sofa/simulation/tree/GNode.h>
00028 #include <sofa/component/MeshLoader.h>
00029 
00030 #include <sofa/core/ObjectFactory.h>
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace topology
00038 {
00039 
00040 using namespace sofa::defaulttype;
00041 
00042 SOFA_DECL_CLASS(PointSetTopologyContainer)
00043 int PointSetTopologyContainerClass = core::RegisterObject("Point set topology container")
00044 .add< PointSetTopologyContainer >()
00045 ;
00046 
00047 PointSetTopologyContainer::PointSetTopologyContainer(int npoints)
00048 : nbPoints(npoints)
00049 {
00050 }
00051 
00052 void PointSetTopologyContainer::setNbPoints(int n)
00053 {
00054     nbPoints = n;
00055 }
00056 
00057 bool PointSetTopologyContainer::checkTopology() const
00058 {
00059     return true;
00060 }
00061 
00062 void PointSetTopologyContainer::clear()
00063 {
00064   nbPoints = 0;
00065   initPoints.clear();
00066 }
00067 
00068 void PointSetTopologyContainer::addPoint(double px, double py, double pz)
00069 {
00070   initPoints.push_back(InitTypes::Coord((SReal)px, (SReal)py, (SReal)pz));
00071   if (initPoints.size() > (unsigned)nbPoints)
00072     nbPoints = initPoints.size();
00073 }
00074 
00075 bool PointSetTopologyContainer::hasPos() const
00076 {
00077   return !initPoints.empty();
00078 }
00079 
00080 double PointSetTopologyContainer::getPX(int i) const
00081 {
00082     if ((unsigned)i < initPoints.size())
00083         return initPoints[i][0];
00084     else
00085         return 0.0;
00086 }
00087 
00088 double PointSetTopologyContainer::getPY(int i) const
00089 {
00090     if ((unsigned)i < initPoints.size())
00091         return initPoints[i][1];
00092     else
00093         return 0.0;
00094 }
00095 
00096 double PointSetTopologyContainer::getPZ(int i) const
00097 {
00098     if ((unsigned)i < initPoints.size())
00099         return initPoints[i][2];
00100     else
00101         return 0.0;
00102 }
00103 
00104 void PointSetTopologyContainer::init()
00105 {
00106     sofa::component::MeshLoader* loader;
00107     this->getContext()->get(loader);
00108     
00109     if(loader)
00110     {
00111         loadFromMeshLoader(loader);
00112     }
00113 }
00114 
00115 void PointSetTopologyContainer::loadFromMeshLoader(sofa::component::MeshLoader* loader)
00116 {
00117     nbPoints = loader->getNbPoints();
00118 }
00119 
00120 void PointSetTopologyContainer::addPoints(const unsigned int nPoints)
00121 {
00122     nbPoints += nPoints;
00123 }
00124 
00125 void PointSetTopologyContainer::removePoints(const unsigned int nPoints)
00126 {
00127     nbPoints -= nPoints;
00128 }
00129 
00130 void PointSetTopologyContainer::addPoint()
00131 {
00132     ++nbPoints;
00133 }
00134 
00135 void PointSetTopologyContainer::removePoint()
00136 {
00137     --nbPoints;
00138 }
00139 
00140 } // namespace topology
00141 
00142 } // namespace component
00143 
00144 } // namespace sofa
00145 

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