Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
VertexSequence.hpp
Go to the documentation of this file.
00001 #ifndef VERTEX_SEQUENCE_HPP
00002 #define VERTEX_SEQUENCE_HPP
00003 
00004 #include "EntitySequence.hpp"
00005 #include "SequenceData.hpp"
00006 
00007 namespace moab
00008 {
00009 
00010 class VertexSequence : public EntitySequence
00011 {
00012   public:
00013     VertexSequence( EntityHandle start, EntityID count, SequenceData* dat ) : EntitySequence( start, count, dat ) {}
00014 
00015     VertexSequence( EntityHandle start, EntityID count, EntityID data_size )
00016         : EntitySequence( start, count, new SequenceData( 3, start, start + data_size - 1 ) )
00017     {
00018         data()->create_sequence_data( X, sizeof( double ) );
00019         data()->create_sequence_data( Y, sizeof( double ) );
00020         data()->create_sequence_data( Z, sizeof( double ) );
00021     }
00022 
00023     virtual ~VertexSequence();
00024 
00025     inline ErrorCode get_coordinates( EntityHandle handle, double& x, double& y, double& z ) const;
00026 
00027     inline ErrorCode get_coordinates( EntityHandle handle, double coords[3] ) const;
00028 
00029     inline ErrorCode get_coordinates_ref( EntityHandle handle,
00030                                           const double*& x,
00031                                           const double*& y,
00032                                           const double*& z ) const;
00033 
00034     inline ErrorCode set_coordinates( EntityHandle entity, double x, double y, double z );
00035 
00036     inline ErrorCode set_coordinates( EntityHandle entity, const double xyz[3] );
00037 
00038     inline ErrorCode get_coordinate_arrays( double*& x, double*& y, double*& z );
00039 
00040     inline ErrorCode get_coordinate_arrays( const double*& x, const double*& y, const double*& z ) const;
00041 
00042     EntitySequence* split( EntityHandle here );
00043 
00044     SequenceData* create_data_subset( EntityHandle start, EntityHandle end ) const;
00045 
00046     ErrorCode push_front( EntityID count );
00047     ErrorCode push_back( EntityID count );
00048 
00049     void get_const_memory_use( unsigned long& bytes_per_entity, unsigned long& size_of_sequence ) const;
00050 
00051   private:
00052     enum Coord
00053     {
00054         X = 0,
00055         Y = 1,
00056         Z = 2
00057     };
00058 
00059     inline double* array( Coord coord )
00060     {
00061         return reinterpret_cast< double* >( data()->get_sequence_data( coord ) );
00062     }
00063 
00064     inline const double* array( Coord coord ) const
00065     {
00066         return reinterpret_cast< const double* >( data()->get_sequence_data( coord ) );
00067     }
00068 
00069     inline double* x_array()
00070     {
00071         return array( X );
00072     }
00073     inline double* y_array()
00074     {
00075         return array( Y );
00076     }
00077     inline double* z_array()
00078     {
00079         return array( Z );
00080     }
00081 
00082     inline const double* x_array() const
00083     {
00084         return array( X );
00085     }
00086     inline const double* y_array() const
00087     {
00088         return array( Y );
00089     }
00090     inline const double* z_array() const
00091     {
00092         return array( Z );
00093     }
00094 
00095     VertexSequence( VertexSequence& split_from, EntityHandle here ) : EntitySequence( split_from, here ) {}
00096 };
00097 
00098 ErrorCode VertexSequence::get_coordinates( EntityHandle handle, double& x, double& y, double& z ) const
00099 {
00100     EntityID offset = handle - data()->start_handle();
00101     x               = x_array()[offset];
00102     y               = y_array()[offset];
00103     z               = z_array()[offset];
00104     return MB_SUCCESS;
00105 }
00106 
00107 ErrorCode VertexSequence::get_coordinates( EntityHandle handle, double coords[3] ) const
00108 {
00109     EntityID offset = handle - data()->start_handle();
00110     coords[X]       = x_array()[offset];
00111     coords[Y]       = y_array()[offset];
00112     coords[Z]       = z_array()[offset];
00113     return MB_SUCCESS;
00114 }
00115 
00116 ErrorCode VertexSequence::get_coordinates_ref( EntityHandle handle,
00117                                                const double*& x,
00118                                                const double*& y,
00119                                                const double*& z ) const
00120 {
00121     EntityID offset = handle - data()->start_handle();
00122     x               = x_array() + offset;
00123     y               = y_array() + offset;
00124     z               = z_array() + offset;
00125     return MB_SUCCESS;
00126 }
00127 
00128 ErrorCode VertexSequence::set_coordinates( EntityHandle entity, double x, double y, double z )
00129 {
00130     EntityID offset   = entity - data()->start_handle();
00131     x_array()[offset] = x;
00132     y_array()[offset] = y;
00133     z_array()[offset] = z;
00134     return MB_SUCCESS;
00135 }
00136 
00137 ErrorCode VertexSequence::set_coordinates( EntityHandle entity, const double* xyz )
00138 {
00139     EntityID offset   = entity - data()->start_handle();
00140     x_array()[offset] = xyz[0];
00141     y_array()[offset] = xyz[1];
00142     z_array()[offset] = xyz[2];
00143     return MB_SUCCESS;
00144 }
00145 
00146 ErrorCode VertexSequence::get_coordinate_arrays( double*& x, double*& y, double*& z )
00147 {
00148     EntityID offset = start_handle() - data()->start_handle();
00149     x               = x_array() + offset;
00150     y               = y_array() + offset;
00151     z               = z_array() + offset;
00152     return MB_SUCCESS;
00153 }
00154 
00155 ErrorCode VertexSequence::get_coordinate_arrays( const double*& x, const double*& y, const double*& z ) const
00156 {
00157     return get_coordinates_ref( start_handle(), x, y, z );
00158 }
00159 
00160 }  // namespace moab
00161 
00162 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines