Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::CustomVector< type > Class Template Reference

CustomVector has some trivial optimizations of the STL vector. More...

#include <marchingcubes.h>

Inheritance diagram for EMAN::CustomVector< type >:

Inheritance graph
[legend]
Collaboration diagram for EMAN::CustomVector< type >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CustomVector (unsigned int starting_size=1024)
 Constructor.
void clear (unsigned int starting_size=1024)
 Clear clears all data and resizes.
void resize (const unsigned int n)
 Resize Resize the data pointer using realloc In general you want to resize to a larger size.
void push_back (const type &t)
 Push back a value Potentially resizes.
void push_back_3 (const type *const p)
 Push back 3 values Potentially resizes.
void mult3 (const type &v1, const type &v2, const type &v3)
 Multiply contiguous groups of 3 by different values.
unsigned int elem ()
 The number of elements, is the same as STL::vector size() Should be called size() but oh well.
type & operator[] (const unsigned int idx)
 Operator[] - provide convenient set functionality (note NOT get).
type * get_data ()
 get the underlying data as a pointer objects

Private Attributes

type * data
 The data pointer.
unsigned int size
 The size of the associated memory block.
unsigned int elements
 The number of stored elements.

Detailed Description

template<typename type>
class EMAN::CustomVector< type >

CustomVector has some trivial optimizations of the STL vector.

It has get_data() functionality, which gives direct access to the underlying data, which is necessary for handing OpenGL vertex and normal arrays - the native STL vector does not give straightforward access to the data pointers. This class also has a push_back_3 function which does a memcpy of 3 elements - this can be used instead of 3 push_back function calls. Although it wasn't rigorously tested it should save some time by virtue of less function calls. Although the savings may be trivial, I just haven't tested it.

This class was not written for general use because- it is designed specifically for use in conjunction with the MarchingCubes class only.

Author:
David Woolford

Definition at line 70 of file marchingcubes.h.


Constructor & Destructor Documentation

template<typename type>
EMAN::CustomVector< type >::CustomVector unsigned int  starting_size = 1024  )  [inline, explicit]
 

Constructor.

Parameters:
starting_size the starting size of the underlying data

Definition at line 76 of file marchingcubes.h.

00076                                                                                : data(0), size(0), elements(0)
00077                         {
00078                                 resize(starting_size);
00079                         }


Member Function Documentation

template<typename type>
void EMAN::CustomVector< type >::clear unsigned int  starting_size = 1024  )  [inline]
 

Clear clears all data and resizes.

Parameters:
starting_size the starting size of the underlying data

Definition at line 85 of file marchingcubes.h.

Referenced by EMAN::MarchingCubes::calculate_surface().

00086                         {
00087                                 if ( data != 0 )
00088                                 {
00089                                         delete [] data;
00090                                         data = 0;
00091                                 }
00092                                 size = 0;
00093                                 elements = 0;
00094                                 resize(starting_size);
00095                         }

template<typename type>
unsigned int EMAN::CustomVector< type >::elem  )  [inline]
 

The number of elements, is the same as STL::vector size() Should be called size() but oh well.

.. This is the actual number of stored floating point numbers not the number of 'groups of 3'

Returns:
the number of elements stored by this object

Definition at line 150 of file marchingcubes.h.

Referenced by EMAN::MarchingCubes::get_isosurface(), EMAN::MarchingCubes::marching_cube(), EMAN::MarchingCubes::surface_face_z(), and EMAN::U3DWriter::write_clod_mesh_generator_node().

00150 { return elements; }

template<typename type>
type* EMAN::CustomVector< type >::get_data  )  [inline]
 

get the underlying data as a pointer objects

Returns:
the data pointer

Definition at line 169 of file marchingcubes.h.

Referenced by EMAN::MarchingCubes::get_isosurface(), EMAN::MarchingCubes::surface_face_z(), and EMAN::U3DWriter::write_clod_mesh_generator_node().

00169 { return data; }

template<typename type>
void EMAN::CustomVector< type >::mult3 const type &  v1,
const type &  v2,
const type &  v3
[inline]
 

Multiply contiguous groups of 3 by different values.

Definition at line 135 of file marchingcubes.h.

00136                         {
00137                                 for(unsigned int i = 0; (i + 2) < elements; i += 3 ){
00138                                         data[i] *= v1;
00139                                         data[i+1] *= v2;
00140                                         data[i+2] *= v3;
00141                                 }
00142                         }

template<typename type>
type& EMAN::CustomVector< type >::operator[] const unsigned int  idx  )  [inline]
 

Operator[] - provide convenient set functionality (note NOT get).

Parameters:
idx the index to access for setting purposes potentially resizes

Definition at line 156 of file marchingcubes.h.

00157                         {
00158                                 unsigned int csize = size;
00159                                 while (idx >= csize ) {
00160                                         csize *= 2;
00161                                 }
00162                                 if ( csize != size ) resize(csize);
00163                                 return data[idx];
00164                         }

template<typename type>
void EMAN::CustomVector< type >::push_back const type &  t  )  [inline]
 

Push back a value Potentially resizes.

Parameters:
t the value to push back

Definition at line 115 of file marchingcubes.h.

Referenced by EMAN::MarchingCubes::marching_cube().

00116                         {
00117                                 if ( elements == size ) resize(2*size);
00118                                 data[elements] = t;
00119                                 ++elements;
00120                         }

template<typename type>
void EMAN::CustomVector< type >::push_back_3 const type *const   p  )  [inline]
 

Push back 3 values Potentially resizes.

Parameters:
p a pointer to 3 contiguous values

Definition at line 126 of file marchingcubes.h.

Referenced by EMAN::MarchingCubes::marching_cube().

00127                         {
00128                                 if ( elements+2 >= size ) resize(2*size);
00129                                 memcpy( &data[elements], p, 3*sizeof(type));
00130                                 elements = elements + 3;
00131                         }

template<typename type>
void EMAN::CustomVector< type >::resize const unsigned int  n  )  [inline]
 

Resize Resize the data pointer using realloc In general you want to resize to a larger size.

..

Parameters:
n the new size of the underlying data

Definition at line 103 of file marchingcubes.h.

Referenced by EMAN::CustomVector< F32 >::clear(), EMAN::CustomVector< F32 >::CustomVector(), EMAN::CustomVector< F32 >::operator[](), EMAN::CustomVector< F32 >::push_back(), and EMAN::CustomVector< F32 >::push_back_3().

00104                         {
00105                                 data = (type*)realloc(data, n*sizeof(type));
00106 
00107                                 for(unsigned int i = size; i < n; ++i) data[i] = 0;
00108                                 size = n;
00109                         }


Member Data Documentation

template<typename type>
type* EMAN::CustomVector< type >::data [private]
 

The data pointer.

Definition at line 173 of file marchingcubes.h.

Referenced by EMAN::CustomVector< F32 >::clear(), EMAN::CustomVector< F32 >::get_data(), EMAN::CustomVector< F32 >::mult3(), EMAN::CustomVector< F32 >::operator[](), EMAN::CustomVector< F32 >::push_back(), EMAN::CustomVector< F32 >::push_back_3(), and EMAN::CustomVector< F32 >::resize().

template<typename type>
unsigned int EMAN::CustomVector< type >::elements [private]
 

The number of stored elements.

Definition at line 177 of file marchingcubes.h.

Referenced by EMAN::CustomVector< F32 >::clear(), EMAN::CustomVector< F32 >::elem(), EMAN::CustomVector< F32 >::mult3(), EMAN::CustomVector< F32 >::push_back(), and EMAN::CustomVector< F32 >::push_back_3().

template<typename type>
unsigned int EMAN::CustomVector< type >::size [private]
 

The size of the associated memory block.

Definition at line 175 of file marchingcubes.h.

Referenced by EMAN::CustomVector< F32 >::clear(), EMAN::CustomVector< F32 >::operator[](), EMAN::CustomVector< F32 >::push_back(), EMAN::CustomVector< F32 >::push_back_3(), and EMAN::CustomVector< F32 >::resize().


The documentation for this class was generated from the following file:
Generated on Mon Jul 19 13:06:12 2010 for EMAN2 by  doxygen 1.4.4