Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
ScdVertexData.hpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 #ifndef SCD_VERTEX_DATA_HPP
17 #define SCD_VERTEX_DATA_HPP
18 
19 //
20 // Class: ScdVertexData
21 //
22 // Purpose: represent a rectangular vertex block of mesh
23 //
24 // A ScdVertex represents a rectangular vertex block of mesh, including both vertices and
25 // the parametric space used to address those vertices.
26 
27 #include "SequenceData.hpp"
28 #include "moab/HomXform.hpp"
29 
30 namespace moab
31 {
32 
34 {
35 
36  private:
37  //! parameter min/max, in homogeneous coords ijkh (extra row for stride eventually)
39 
40  //! difference between max and min params plus one (i.e. # VERTICES in
41  //! each parametric direction)
42  int dIJK[3];
43 
44  //! difference between max and min params (i.e. # VERTEXS in
45  //! each parametric direction)
46  int dIJKm1[3];
47 
48  public:
49  //! constructor
50  ScdVertexData( const EntityHandle start_vertex,
51  const int imin,
52  const int jmin,
53  const int kmin,
54  const int imax,
55  const int jmax,
56  const int kmax );
57 
58  virtual ~ScdVertexData() {}
59 
60  //! get handle of vertex at i, j, k
61  EntityHandle get_vertex( const int i, const int j, const int k ) const;
62 
63  //! get handle of vertex at homogeneous coordinates
64  EntityHandle get_vertex( const HomCoord& coords ) const;
65 
66  //! get the parameters of a given handle; return MB_FAILURE if vhandle not in this
67  //! sequence
68  ErrorCode get_params( const EntityHandle vhandle, int& i, int& j, int& k ) const;
69 
70  //! get min params for this vertex
71  void min_params( int& i, int& j, int& k ) const;
72 
73  //! get max params for this vertex
74  void max_params( int& i, int& j, int& k ) const;
75 
76  //! get the min params
77  const HomCoord& min_params() const;
78 
79  //! get the max params
80  const HomCoord& max_params() const;
81 
82  //! get the number of vertices in each direction, inclusive
83  void param_extents( int& di, int& dj, int& dk ) const;
84 
85  //! convenience functions for parameter extents
86  int i_min() const
87  {
88  return vertexParams[0].hom_coord()[0];
89  }
90  int j_min() const
91  {
92  return vertexParams[0].hom_coord()[1];
93  }
94  int k_min() const
95  {
96  return vertexParams[0].hom_coord()[2];
97  }
98  int i_max() const
99  {
100  return vertexParams[1].hom_coord()[0];
101  }
102  int j_max() const
103  {
104  return vertexParams[1].hom_coord()[1];
105  }
106  int k_max() const
107  {
108  return vertexParams[1].hom_coord()[2];
109  }
110 
111  //! return whether this vseq's parameter space contains these parameters
112  bool contains( const HomCoord& coords ) const;
113  bool contains( const int i, const int j, const int k ) const;
114 
116  EntityHandle end,
117  const int* sequence_data_sizes,
118  const int* tag_data_sizes ) const;
119 };
120 
121 inline EntityHandle ScdVertexData::get_vertex( const int i, const int j, const int k ) const
122 {
123  return start_handle() + ( i - i_min() ) + ( j - j_min() ) * dIJK[0] + ( k - k_min() ) * dIJK[0] * dIJK[1];
124 }
125 
126 inline EntityHandle ScdVertexData::get_vertex( const HomCoord& coords ) const
127 {
128  return get_vertex( coords.hom_coord()[0], coords.hom_coord()[1], coords.hom_coord()[2] );
129 }
130 
131 inline ErrorCode ScdVertexData::get_params( const EntityHandle vhandle, int& i, int& j, int& k ) const
132 {
133  if( TYPE_FROM_HANDLE( vhandle ) != MBVERTEX ) return MB_FAILURE;
134 
135  int hdiff = vhandle - start_handle();
136 
137  k = hdiff / ( dIJK[0] * dIJK[1] );
138  j = ( hdiff - ( k * dIJK[0] * dIJK[1] ) ) / dIJK[0];
139  i = hdiff % dIJK[0];
140 
141  k += vertexParams[0].k();
142  j += vertexParams[0].j();
143  i += vertexParams[0].i();
144 
145  return ( vhandle >= start_handle() && i >= i_min() && i <= i_max() && j >= j_min() && j <= j_max() &&
146  k >= k_min() && k <= k_max() )
147  ? MB_SUCCESS
148  : MB_FAILURE;
149 }
150 
151 //! get min params for this vertex
152 inline void ScdVertexData::min_params( int& i, int& j, int& k ) const
153 {
154  i = i_min();
155  j = j_min();
156  k = k_min();
157 }
158 
159 //! get max params for this vertex
160 inline void ScdVertexData::max_params( int& i, int& j, int& k ) const
161 {
162  i = i_max();
163  j = j_max();
164  k = k_max();
165 }
166 
167 inline const HomCoord& ScdVertexData::min_params() const
168 {
169  return vertexParams[0];
170 }
171 
172 inline const HomCoord& ScdVertexData::max_params() const
173 {
174  return vertexParams[1];
175 }
176 
177 //! get the number of vertices in each direction, inclusive
178 inline void ScdVertexData::param_extents( int& di, int& dj, int& dk ) const
179 {
180  di = dIJK[0];
181  dj = dIJK[1];
182  dk = dIJK[2];
183 }
184 
185 inline bool ScdVertexData::contains( const HomCoord& coords ) const
186 {
187  return ( coords >= vertexParams[0] && coords <= vertexParams[1] ) ? true : false;
188 }
189 
190 inline bool ScdVertexData::contains( const int i, const int j, const int k ) const
191 {
192  return contains( HomCoord( i, j, k ) );
193 }
194 
195 } // namespace moab
196 
197 #endif