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