MOAB: Mesh Oriented datABase  (version 5.4.0)
SweptVertexData.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifndef SWEPT_VERTEX_DATA_HPP
00017 #define SWEPT_VERTEX_DATA_HPP
00018 
00019 //
00020 // Class: SweptVertexData
00021 //
00022 // Purpose: represent a rectangular vertex block of mesh
00023 //
00024 // A SweptVertex represents a rectangular vertex block of mesh, including both vertices and
00025 // the parametric space used to address those vertices.
00026 
00027 #include "SequenceData.hpp"
00028 #include "moab/HomXform.hpp"
00029 
00030 namespace moab
00031 {
00032 
00033 class SweptVertexData : public SequenceData
00034 {
00035 
00036   private:
00037     //! parameter min/max, in homogeneous coords ijkh (extra row for stride eventually)
00038     HomCoord vertexParams[3];
00039 
00040     //! difference between max and min params plus one (i.e. # VERTICES in
00041     //! each parametric direction)
00042     int dIJK[3];
00043 
00044     //! difference between max and min params (i.e. # VERTEXS in
00045     //! each parametric direction)
00046     int dIJKm1[3];
00047 
00048   public:
00049     //! constructor
00050     SweptVertexData( const EntityHandle start_vertex,
00051                      const int imin,
00052                      const int jmin,
00053                      const int kmin,
00054                      const int imax,
00055                      const int jmax,
00056                      const int kmax );
00057 
00058     virtual ~SweptVertexData() {}
00059 
00060     //! get handle of vertex at i, j, k
00061     EntityHandle get_vertex( const int i, const int j, const int k ) const;
00062 
00063     //! get handle of vertex at homogeneous coordinates
00064     EntityHandle get_vertex( const HomCoord& coords ) const;
00065 
00066     //! get the parameters of a given handle; return MB_FAILURE if vhandle not in this
00067     //! sequence
00068     ErrorCode get_params( const EntityHandle vhandle, int& i, int& j, int& k ) const;
00069 
00070     //! get min params for this vertex
00071     void min_params( int& i, int& j, int& k ) const;
00072 
00073     //! get max params for this vertex
00074     void max_params( int& i, int& j, int& k ) const;
00075 
00076     //! get the min params
00077     const HomCoord& min_params() const;
00078 
00079     //! get the max params
00080     const HomCoord& max_params() const;
00081 
00082     //! get the number of vertices in each direction, inclusive
00083     void param_extents( int& di, int& dj, int& dk ) const;
00084 
00085     //! convenience functions for parameter extents
00086     int i_min() const
00087     {
00088         return vertexParams[0].hom_coord()[0];
00089     }
00090     int j_min() const
00091     {
00092         return vertexParams[0].hom_coord()[1];
00093     }
00094     int k_min() const
00095     {
00096         return vertexParams[0].hom_coord()[2];
00097     }
00098     int i_max() const
00099     {
00100         return vertexParams[1].hom_coord()[0];
00101     }
00102     int j_max() const
00103     {
00104         return vertexParams[1].hom_coord()[1];
00105     }
00106     int k_max() const
00107     {
00108         return vertexParams[1].hom_coord()[2];
00109     }
00110 
00111     //! return whether this vseq's parameter space contains these parameters
00112     bool contains( const HomCoord& coords ) const;
00113     bool contains( const int i, const int j, const int k ) const;
00114 
00115     SequenceData* subset( EntityHandle start,
00116                           EntityHandle end,
00117                           const int* sequence_data_sizes,
00118                           const int* tag_data_sizes ) const;
00119 };
00120 
00121 inline EntityHandle SweptVertexData::get_vertex( const int i, const int j, const int k ) const
00122 {
00123     return start_handle() + ( i - i_min() ) + ( j - j_min() ) * dIJK[0] + ( k - k_min() ) * dIJK[0] * dIJK[1];
00124 }
00125 
00126 inline EntityHandle SweptVertexData::get_vertex( const HomCoord& coords ) const
00127 {
00128     return get_vertex( coords.hom_coord()[0], coords.hom_coord()[1], coords.hom_coord()[2] );
00129 }
00130 
00131 inline ErrorCode SweptVertexData::get_params( const EntityHandle vhandle, int& i, int& j, int& k ) const
00132 {
00133     if( TYPE_FROM_HANDLE( vhandle ) != MBVERTEX ) return MB_FAILURE;
00134 
00135     int hdiff = vhandle - start_handle();
00136 
00137     k = hdiff / ( dIJK[0] * dIJK[1] );
00138     j = ( hdiff - ( k * dIJK[0] * dIJK[1] ) ) / dIJK[0];
00139     i = hdiff % dIJK[0];
00140 
00141     k += vertexParams[0].k();
00142     j += vertexParams[0].j();
00143     i += vertexParams[0].i();
00144 
00145     return ( vhandle >= start_handle() && i >= i_min() && i <= i_max() && j >= j_min() && j <= j_max() &&
00146              k >= k_min() && k <= k_max() )
00147                ? MB_SUCCESS
00148                : MB_FAILURE;
00149 }
00150 
00151 //! get min params for this vertex
00152 inline void SweptVertexData::min_params( int& i, int& j, int& k ) const
00153 {
00154     i = i_min();
00155     j = j_min();
00156     k = k_min();
00157 }
00158 
00159 //! get max params for this vertex
00160 inline void SweptVertexData::max_params( int& i, int& j, int& k ) const
00161 {
00162     i = i_max();
00163     j = j_max();
00164     k = k_max();
00165 }
00166 
00167 inline const HomCoord& SweptVertexData::min_params() const
00168 {
00169     return vertexParams[0];
00170 }
00171 
00172 inline const HomCoord& SweptVertexData::max_params() const
00173 {
00174     return vertexParams[1];
00175 }
00176 
00177 //! get the number of vertices in each direction, inclusive
00178 inline void SweptVertexData::param_extents( int& di, int& dj, int& dk ) const
00179 {
00180     di = dIJK[0];
00181     dj = dIJK[1];
00182     dk = dIJK[2];
00183 }
00184 
00185 inline bool SweptVertexData::contains( const HomCoord& coords ) const
00186 {
00187     return ( coords >= vertexParams[0] && coords <= vertexParams[1] ) ? true : false;
00188 }
00189 
00190 inline bool SweptVertexData::contains( const int i, const int j, const int k ) const
00191 {
00192     return contains( HomCoord( i, j, k ) );
00193 }
00194 
00195 }  // namespace moab
00196 
00197 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines