MOAB: Mesh Oriented datABase  (version 5.2.1)
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, const double*& x, const double*& y,
00030                                           const double*& z ) const;
00031 
00032     inline ErrorCode set_coordinates( EntityHandle entity, double x, double y, double z );
00033 
00034     inline ErrorCode set_coordinates( EntityHandle entity, const double xyz[3] );
00035 
00036     inline ErrorCode get_coordinate_arrays( double*& x, double*& y, double*& z );
00037 
00038     inline ErrorCode get_coordinate_arrays( const double*& x, const double*& y, const double*& z ) const;
00039 
00040     EntitySequence* split( EntityHandle here );
00041 
00042     SequenceData* create_data_subset( EntityHandle start, EntityHandle end ) const;
00043 
00044     ErrorCode push_front( EntityID count );
00045     ErrorCode push_back( EntityID count );
00046 
00047     void get_const_memory_use( unsigned long& bytes_per_entity, unsigned long& size_of_sequence ) const;
00048 
00049   private:
00050     enum Coord
00051     {
00052         X = 0,
00053         Y = 1,
00054         Z = 2
00055     };
00056 
00057     inline double* array( Coord coord )
00058     {
00059         return reinterpret_cast< double* >( data()->get_sequence_data( coord ) );
00060     }
00061 
00062     inline const double* array( Coord coord ) const
00063     {
00064         return reinterpret_cast< const double* >( data()->get_sequence_data( coord ) );
00065     }
00066 
00067     inline double* x_array()
00068     {
00069         return array( X );
00070     }
00071     inline double* y_array()
00072     {
00073         return array( Y );
00074     }
00075     inline double* z_array()
00076     {
00077         return array( Z );
00078     }
00079 
00080     inline const double* x_array() const
00081     {
00082         return array( X );
00083     }
00084     inline const double* y_array() const
00085     {
00086         return array( Y );
00087     }
00088     inline const double* z_array() const
00089     {
00090         return array( Z );
00091     }
00092 
00093     VertexSequence( VertexSequence& split_from, EntityHandle here ) : EntitySequence( split_from, here ) {}
00094 };
00095 
00096 ErrorCode VertexSequence::get_coordinates( EntityHandle handle, double& x, double& y, double& z ) const
00097 {
00098     EntityID offset = handle - data()->start_handle();
00099     x               = x_array()[offset];
00100     y               = y_array()[offset];
00101     z               = z_array()[offset];
00102     return MB_SUCCESS;
00103 }
00104 
00105 ErrorCode VertexSequence::get_coordinates( EntityHandle handle, double coords[3] ) const
00106 {
00107     EntityID offset = handle - data()->start_handle();
00108     coords[X]       = x_array()[offset];
00109     coords[Y]       = y_array()[offset];
00110     coords[Z]       = z_array()[offset];
00111     return MB_SUCCESS;
00112 }
00113 
00114 ErrorCode VertexSequence::get_coordinates_ref( EntityHandle handle, const double*& x, const double*& y,
00115                                                const double*& z ) const
00116 {
00117     EntityID offset = handle - data()->start_handle();
00118     x               = x_array() + offset;
00119     y               = y_array() + offset;
00120     z               = z_array() + offset;
00121     return MB_SUCCESS;
00122 }
00123 
00124 ErrorCode VertexSequence::set_coordinates( EntityHandle entity, double x, double y, double z )
00125 {
00126     EntityID offset   = entity - data()->start_handle();
00127     x_array()[offset] = x;
00128     y_array()[offset] = y;
00129     z_array()[offset] = z;
00130     return MB_SUCCESS;
00131 }
00132 
00133 ErrorCode VertexSequence::set_coordinates( EntityHandle entity, const double* xyz )
00134 {
00135     EntityID offset   = entity - data()->start_handle();
00136     x_array()[offset] = xyz[0];
00137     y_array()[offset] = xyz[1];
00138     z_array()[offset] = xyz[2];
00139     return MB_SUCCESS;
00140 }
00141 
00142 ErrorCode VertexSequence::get_coordinate_arrays( double*& x, double*& y, double*& z )
00143 {
00144     EntityID offset = start_handle() - data()->start_handle();
00145     x               = x_array() + offset;
00146     y               = y_array() + offset;
00147     z               = z_array() + offset;
00148     return MB_SUCCESS;
00149 }
00150 
00151 ErrorCode VertexSequence::get_coordinate_arrays( const double*& x, const double*& y, const double*& z ) const
00152 {
00153     return get_coordinates_ref( start_handle(), x, y, z );
00154 }
00155 
00156 }  // namespace moab
00157 
00158 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines