EMAN2
Public Member Functions | Private Attributes | List of all members
EMAN::CustomVector< type > Class Template Reference

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

#include <marchingcubes.h>

Public Member Functions

 CustomVector (unsigned int starting_size=1024)
 Constructor. More...
 
 ~CustomVector ()
 
void clear (unsigned int starting_size=1024)
 Clear clears all data and resizes. More...
 
void resize (const unsigned int n)
 Resize Resize the data pointer using realloc In general you want to resize to a larger size... More...
 
void push_back (const type &t)
 Push back a value Potentially resizes. More...
 
void push_back_3 (const type *const p)
 Push back 3 values Potentially resizes. More...
 
void mult3 (const type &v1, const type &v2, const type &v3)
 Multiply contiguous groups of 3 by different values. More...
 
unsigned int elem ()
 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'. More...
 
type & operator[] (const unsigned int idx)
 Operator[] - provide convenient set functionality (note NOT get) More...
 
type * get_data ()
 get the underlying data as a pointer objects More...
 

Private Attributes

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

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 74 of file marchingcubes.h.

Constructor & Destructor Documentation

◆ CustomVector()

template<typename type >
EMAN::CustomVector< type >::CustomVector ( unsigned int  starting_size = 1024)
inlineexplicit

Constructor.

Parameters
starting_sizethe starting size of the underlying data

Definition at line 80 of file marchingcubes.h.

80 : data(0), size(0), elements(0)
81 {
82 resize(starting_size);
83 }
void resize(const unsigned int n)
Resize Resize the data pointer using realloc In general you want to resize to a larger size....
unsigned int elements
The number of stored elements.
type * data
The data pointer.
unsigned int size
The size of the associated memory block.

References EMAN::CustomVector< type >::resize().

◆ ~CustomVector()

template<typename type >
EMAN::CustomVector< type >::~CustomVector ( )
inline

Definition at line 85 of file marchingcubes.h.

86 {
87 if(data) {free(data); data=0;}
88 }

References EMAN::CustomVector< type >::data.

Member Function Documentation

◆ clear()

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

Clear clears all data and resizes.

Parameters
starting_sizethe starting size of the underlying data

Definition at line 94 of file marchingcubes.h.

95 {
96 if (data) {free(data); data = 0;}
97 size = 0;
98 elements = 0;
99 resize(starting_size);
100 }

References EMAN::CustomVector< type >::data, EMAN::CustomVector< type >::elements, EMAN::CustomVector< type >::resize(), and EMAN::CustomVector< type >::size.

◆ elem()

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 155 of file marchingcubes.h.

155{ return elements; }

References EMAN::CustomVector< type >::elements.

◆ get_data()

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 174 of file marchingcubes.h.

174{ return data; }

References EMAN::CustomVector< type >::data.

◆ mult3()

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 140 of file marchingcubes.h.

141 {
142 for(unsigned int i = 0; (i + 2) < elements; i += 3 ){
143 data[i] *= v1;
144 data[i+1] *= v2;
145 data[i+2] *= v3;
146 }
147 }

References EMAN::CustomVector< type >::data, and EMAN::CustomVector< type >::elements.

◆ operator[]()

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

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

Parameters
idxthe index to access for setting purposes potentially resizes

Definition at line 161 of file marchingcubes.h.

162 {
163 unsigned int csize = size;
164 while (idx >= csize ) {
165 csize *= 2;
166 }
167 if ( csize != size ) resize(csize);
168 return data[idx];
169 }

References EMAN::CustomVector< type >::data, EMAN::CustomVector< type >::resize(), and EMAN::CustomVector< type >::size.

◆ push_back()

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

Push back a value Potentially resizes.

Parameters
tthe value to push back

Definition at line 120 of file marchingcubes.h.

121 {
122 if ( elements == size ) resize(2*size);
123 data[elements] = t;
124 ++elements;
125 }

References EMAN::CustomVector< type >::data, EMAN::CustomVector< type >::elements, EMAN::CustomVector< type >::resize(), and EMAN::CustomVector< type >::size.

◆ push_back_3()

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

Push back 3 values Potentially resizes.

Parameters
pa pointer to 3 contiguous values

Definition at line 131 of file marchingcubes.h.

132 {
133 if ( elements+2 >= size ) resize(2*size);
134 memcpy( &data[elements], p, 3*sizeof(type));
135 elements = elements + 3;
136 }

References EMAN::CustomVector< type >::data, EMAN::CustomVector< type >::elements, EMAN::CustomVector< type >::resize(), and EMAN::CustomVector< type >::size.

◆ resize()

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
nthe new size of the underlying data

Definition at line 108 of file marchingcubes.h.

109 {
110 data = (type*)realloc(data, n*sizeof(type));
111
112 for(unsigned int i = size; i < n; ++i) data[i] = 0;
113 size = n;
114 }

References EMAN::CustomVector< type >::data, and EMAN::CustomVector< type >::size.

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

Member Data Documentation

◆ data

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

◆ elements

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

◆ size

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

The documentation for this class was generated from the following file: