Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
VertexSequence.hpp
Go to the documentation of this file.
1 #ifndef VERTEX_SEQUENCE_HPP
2 #define VERTEX_SEQUENCE_HPP
3 
4 #include "EntitySequence.hpp"
5 #include "SequenceData.hpp"
6 
7 namespace moab
8 {
9 
11 {
12  public:
13  VertexSequence( EntityHandle start, EntityID count, SequenceData* dat ) : EntitySequence( start, count, dat ) {}
14 
15  VertexSequence( EntityHandle start, EntityID count, EntityID data_size )
16  : EntitySequence( start, count, new SequenceData( 3, start, start + data_size - 1 ) )
17  {
18  data()->create_sequence_data( X, sizeof( double ) );
19  data()->create_sequence_data( Y, sizeof( double ) );
20  data()->create_sequence_data( Z, sizeof( double ) );
21  }
22 
23  virtual ~VertexSequence();
24 
25  inline ErrorCode get_coordinates( EntityHandle handle, double& x, double& y, double& z ) const;
26 
27  inline ErrorCode get_coordinates( EntityHandle handle, double coords[3] ) const;
28 
30  const double*& x,
31  const double*& y,
32  const double*& z ) const;
33 
34  inline ErrorCode set_coordinates( EntityHandle entity, double x, double y, double z );
35 
36  inline ErrorCode set_coordinates( EntityHandle entity, const double xyz[3] );
37 
38  inline ErrorCode get_coordinate_arrays( double*& x, double*& y, double*& z );
39 
40  inline ErrorCode get_coordinate_arrays( const double*& x, const double*& y, const double*& z ) const;
41 
43 
45 
46  ErrorCode push_front( EntityID count );
47  ErrorCode push_back( EntityID count );
48 
49  void get_const_memory_use( unsigned long& bytes_per_entity, unsigned long& size_of_sequence ) const;
50 
51  private:
52  enum Coord
53  {
54  X = 0,
55  Y = 1,
56  Z = 2
57  };
58 
59  inline double* array( Coord coord )
60  {
61  return reinterpret_cast< double* >( data()->get_sequence_data( coord ) );
62  }
63 
64  inline const double* array( Coord coord ) const
65  {
66  return reinterpret_cast< const double* >( data()->get_sequence_data( coord ) );
67  }
68 
69  inline double* x_array()
70  {
71  return array( X );
72  }
73  inline double* y_array()
74  {
75  return array( Y );
76  }
77  inline double* z_array()
78  {
79  return array( Z );
80  }
81 
82  inline const double* x_array() const
83  {
84  return array( X );
85  }
86  inline const double* y_array() const
87  {
88  return array( Y );
89  }
90  inline const double* z_array() const
91  {
92  return array( Z );
93  }
94 
95  VertexSequence( VertexSequence& split_from, EntityHandle here ) : EntitySequence( split_from, here ) {}
96 };
97 
98 ErrorCode VertexSequence::get_coordinates( EntityHandle handle, double& x, double& y, double& z ) const
99 {
100  EntityID offset = handle - data()->start_handle();
101  x = x_array()[offset];
102  y = y_array()[offset];
103  z = z_array()[offset];
104  return MB_SUCCESS;
105 }
106 
107 ErrorCode VertexSequence::get_coordinates( EntityHandle handle, double coords[3] ) const
108 {
109  EntityID offset = handle - data()->start_handle();
110  coords[X] = x_array()[offset];
111  coords[Y] = y_array()[offset];
112  coords[Z] = z_array()[offset];
113  return MB_SUCCESS;
114 }
115 
117  const double*& x,
118  const double*& y,
119  const double*& z ) const
120 {
121  EntityID offset = handle - data()->start_handle();
122  x = x_array() + offset;
123  y = y_array() + offset;
124  z = z_array() + offset;
125  return MB_SUCCESS;
126 }
127 
128 ErrorCode VertexSequence::set_coordinates( EntityHandle entity, double x, double y, double z )
129 {
130  EntityID offset = entity - data()->start_handle();
131  x_array()[offset] = x;
132  y_array()[offset] = y;
133  z_array()[offset] = z;
134  return MB_SUCCESS;
135 }
136 
137 ErrorCode VertexSequence::set_coordinates( EntityHandle entity, const double* xyz )
138 {
139  EntityID offset = entity - data()->start_handle();
140  x_array()[offset] = xyz[0];
141  y_array()[offset] = xyz[1];
142  z_array()[offset] = xyz[2];
143  return MB_SUCCESS;
144 }
145 
146 ErrorCode VertexSequence::get_coordinate_arrays( double*& x, double*& y, double*& z )
147 {
148  EntityID offset = start_handle() - data()->start_handle();
149  x = x_array() + offset;
150  y = y_array() + offset;
151  z = z_array() + offset;
152  return MB_SUCCESS;
153 }
154 
155 ErrorCode VertexSequence::get_coordinate_arrays( const double*& x, const double*& y, const double*& z ) const
156 {
157  return get_coordinates_ref( start_handle(), x, y, z );
158 }
159 
160 } // namespace moab
161 
162 #endif