CubeTopology.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_CUBETOPOLOGY_H
00026 #define SOFA_COMPONENT_TOPOLOGY_CUBETOPOLOGY_H
00027 
00028 #include <sofa/component/topology/MeshTopology.h>
00029 #include <sofa/defaulttype/Vec.h>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace topology
00038 {
00039 
00040 using namespace sofa::defaulttype;
00041 
00042 class CubeTopology : public MeshTopology
00043 {
00044 public:
00045 
00046     CubeTopology(int nx, int ny, int nz);
00047     CubeTopology();
00048 
00049     void setSize(int nx, int ny, int nz);
00050 
00051     void parse(core::objectmodel::BaseObjectDescription* arg);
00052 
00053     int getNx() const { return nx.getValue(); }
00054     int getNy() const { return ny.getValue(); }
00055     int getNz() const { return nz.getValue(); }
00056 
00057     void setNx(int n) { nx.setValue(n); setSize(); }
00058     void setNy(int n) { ny.setValue(n); setSize(); }
00059     void setNz(int n) { nz.setValue(n); setSize(); }
00060 
00061     virtual void init();
00062     virtual void reinit();
00063 
00064     //int getNbQuads();
00065     //Quad getQuad(int i);
00066     //Quad getQuad(int x, int y, int z);
00067 
00068     enum Plane { PLANE_UNKNOWN=0,
00069          PLANE_X0,
00070          PLANE_X1,
00071          PLANE_Y0,
00072          PLANE_Y1,
00073          PLANE_Z0,
00074          PLANE_Z1 };
00075 
00076     int point(int x, int y, int z, Plane p = PLANE_UNKNOWN) const; // { return x+nx.getValue()*(y+ny.getValue()*z); }
00077 
00078     void setP0(const Vector3& val) { p0 = val; }
00079     void setDx(const Vector3& val) { dx = val; inv_dx2 = 1/(dx*dx); }
00080     void setDy(const Vector3& val) { dy = val; inv_dy2 = 1/(dy*dy); }
00081     void setDz(const Vector3& val) { dz = val; inv_dz2 = 1/(dz*dz); }
00082 
00083     void setPos(SReal xmin, SReal xmax, SReal ymin, SReal ymax, SReal zmin, SReal zmax);
00084 
00085     const Vector3& getP0() const { return p0; }
00086     const Vector3& getDx() const { return dx; }
00087     const Vector3& getDy() const { return dy; }
00088     const Vector3& getDz() const { return dz; }
00089 
00090     Vector3   getMin() const { return min.getValue();}
00091     Vector3   getMax() const { return max.getValue();}
00092 
00093     Vector3 getPoint(int i) const;
00094     Vector3 getPoint(int x, int y, int z) const;
00095     bool hasPos()  const{ return true; }
00096     double getPX(int i)  const { return getPoint(i)[0]; }
00097     double getPY(int i) const { return getPoint(i)[1]; }
00098     double getPZ(int i) const { return getPoint(i)[2]; }
00099 
00100     void setSplitNormals(bool b){splitNormals.setValue(b);}
00101     
00102 protected:
00103     Data<int> nx;
00104     Data<int> ny;
00105     Data<int> nz;
00106     Data<bool> internalPoints;
00107     Data<bool> splitNormals;
00108 
00109     Data< Vector3 > min, max;
00111     Vector3 p0;
00113     Vector3 dx,dy,dz;
00114     SReal inv_dx2, inv_dy2, inv_dz2;
00115 
00116     virtual void setSize();
00117     void updateEdges();
00118     void updateQuads();
00119     //void updateHexas();
00120 };
00121 
00122 } // namespace topology
00123 
00124 } // namespace component
00125 
00126 } // namespace sofa
00127 
00128 #endif

Generated on Sun Nov 23 03:42:46 2008 for Sofa by  doxygen 1.5.7.1