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 class ScdVertexData : public SequenceData
33 {
34
35 private:
36
37 //! parameter min/max, in homogeneous coords ijkh (extra row for stride eventually)
38 HomCoord vertexParams[3];
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
50 //! constructor
51 ScdVertexData(const EntityHandle start_vertex,
52 const int imin, const int jmin, const int kmin,
53 const int imax, const int jmax, const int kmax) ;
54
~ScdVertexData()55 virtual ~ScdVertexData() {}
56
57 //! get handle of vertex at i, j, k
58 EntityHandle get_vertex(const int i, const int j, const int k) const;
59
60 //! get handle of vertex at homogeneous coordinates
61 EntityHandle get_vertex(const HomCoord &coords) const;
62
63 //! get the parameters of a given handle; return MB_FAILURE if vhandle not in this
64 //! sequence
65 ErrorCode get_params(const EntityHandle vhandle,
66 int &i, int &j, int &k) const;
67
68 //! get min params for this vertex
69 void min_params(int &i, int &j, int &k) const;
70
71 //! get max params for this vertex
72 void max_params(int &i, int &j, int &k) const;
73
74 //! get the min params
75 const HomCoord &min_params() const;
76
77 //! get the max params
78 const HomCoord &max_params() const;
79
80 //! get the number of vertices in each direction, inclusive
81 void param_extents(int &di, int &dj, int &dk) const;
82
83 //! convenience functions for parameter extents
i_min() const84 int i_min() const {return vertexParams[0].hom_coord()[0];}
j_min() const85 int j_min() const {return vertexParams[0].hom_coord()[1];}
k_min() const86 int k_min() const {return vertexParams[0].hom_coord()[2];}
i_max() const87 int i_max() const {return vertexParams[1].hom_coord()[0];}
j_max() const88 int j_max() const {return vertexParams[1].hom_coord()[1];}
k_max() const89 int k_max() const {return vertexParams[1].hom_coord()[2];}
90
91 //! return whether this vseq's parameter space contains these parameters
92 bool contains(const HomCoord &coords) const;
93 bool contains(const int i, const int j, const int k) const;
94
95 SequenceData* subset( EntityHandle start,
96 EntityHandle end,
97 const int* sequence_data_sizes,
98 const int* tag_data_sizes ) const;
99 };
100
get_vertex(const int i,const int j,const int k) const101 inline EntityHandle ScdVertexData::get_vertex(const int i, const int j,
102 const int k) const
103 {
104 return start_handle() + (i-i_min()) + (j-j_min())*dIJK[0] +
105 (k-k_min())*dIJK[0]*dIJK[1];
106 }
107
get_vertex(const HomCoord & coords) const108 inline EntityHandle ScdVertexData::get_vertex(const HomCoord &coords) const
109 {
110 return get_vertex(coords.hom_coord()[0], coords.hom_coord()[1], coords.hom_coord()[2]);
111 }
112
get_params(const EntityHandle vhandle,int & i,int & j,int & k) const113 inline ErrorCode ScdVertexData::get_params(const EntityHandle vhandle,
114 int &i, int &j, int &k) const
115 {
116 if (TYPE_FROM_HANDLE(vhandle) != MBVERTEX) return MB_FAILURE;
117
118 int hdiff = vhandle - start_handle();
119
120 k = hdiff / (dIJK[0]*dIJK[1]);
121 j = (hdiff - (k*dIJK[0]*dIJK[1])) / dIJK[0];
122 i = hdiff % dIJK[0];
123
124 k += vertexParams[0].k();
125 j += vertexParams[0].j();
126 i += vertexParams[0].i();
127
128 return (vhandle >= start_handle() &&
129 i >= i_min() && i <= i_max() &&
130 j >= j_min() && j <= j_max() &&
131 k >= k_min() && k <= k_max()) ? MB_SUCCESS : MB_FAILURE;
132 }
133
134 //! get min params for this vertex
min_params(int & i,int & j,int & k) const135 inline void ScdVertexData::min_params(int &i, int &j, int &k) const
136 {
137 i = i_min();
138 j = j_min();
139 k = k_min();
140 }
141
142 //! get max params for this vertex
max_params(int & i,int & j,int & k) const143 inline void ScdVertexData::max_params(int &i, int &j, int &k) const
144 {
145 i = i_max();
146 j = j_max();
147 k = k_max();
148 }
149
min_params() const150 inline const HomCoord &ScdVertexData::min_params() const
151 {
152 return vertexParams[0];
153 }
154
max_params() const155 inline const HomCoord &ScdVertexData::max_params() const
156 {
157 return vertexParams[1];
158 }
159
160 //! get the number of vertices in each direction, inclusive
param_extents(int & di,int & dj,int & dk) const161 inline void ScdVertexData::param_extents(int &di, int &dj, int &dk) const
162 {
163 di = dIJK[0];
164 dj = dIJK[1];
165 dk = dIJK[2];
166 }
167
contains(const HomCoord & coords) const168 inline bool ScdVertexData::contains(const HomCoord &coords) const
169 {
170 return (coords >= vertexParams[0] && coords <= vertexParams[1]) ? true : false;
171 }
172
contains(const int i,const int j,const int k) const173 inline bool ScdVertexData::contains(const int i, const int j, const int k) const
174 {
175 return contains(HomCoord(i, j, k));
176 }
177
178 } // namespace moab
179
180 #endif
181