So basically, in the normal case, you want to add 26 positions to the vector, and those could be easily enumerated, except that you have to be carefull not to access voxels that are out-of bounds.
If you really, really, want to optimize this function to the max, the most optimal implementation would be a single switch, and unrolled loops.
For each of the 3 dimensions, there are only five possibilites:
case 1: {somePos[i] - resol}; // 1 value only
case 2: {somePos[i] - resol, somePos[i]} // 2 values
case 3: {somePos[i] - resol, somePos[i], somePos[i] + resol} // all 3
case 4: {somePos[i], somePos[i] + resol} // 2 values again
case 5: {somePos[i] + resol} // 1 value only
There's also a "case 0" where none of the values are in range. But if that's true for any of the dimensions, then you don't add any values at all.
Combining the 5 posssiblities for each of three dimensions, gives you 125 possible cases to implement. Given which of the 125 cases you've got, you can then just unroll the loops and ifs into a sequence of up to 26 push_back() calls.
Something like this:
enum eCase {
CASE_NONE = 0,
CASE_LOW1 = 1,
CASE_LOW2 = 2,
CASE_ALL3 = 3,
CASE_HIGH2 = 4,
CASE_HIGH1 = 5,
};
eCase Xcase = /* a function of somePos[0], m_MinPos[0], m_MaxPos[0], and resol */
eCase Ycase = ...
eCase Zcase = ...
#define MUNGE(_x,_y,_z) (((((_x)*6)+(_y))*6)+(_z))
switch (MUNGE(Xcase, Ycase, Zcase) {
default:
break; // all CASE_NONE's do nothing
case MUNGE (CASE_ALL3, CASE_ALL3, CASE_ALL3):
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] - resol, somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] - resol, somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] - resol, somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] , somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] , somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] , somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] + resol, somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] + resol, somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] - resol, somePos.m_pPos[1] + resol, somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] - resol, somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] - resol, somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] - resol, somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] , somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] , somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] + resol, somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] + resol, somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] , somePos.m_pPos[1] + resol, somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] - resol, somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] - resol, somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] - resol, somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] , somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] , somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] , somePos.m_pPos[2] + resol));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] + resol, somePos.m_pPos[2] - resol));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] + resol, somePos.m_pPos[2] ));
vect1.push_back( pos (somePos.m_pPos[0] + resol, somePos.m_pPos[1] + resol, somePos.m_pPos[2] + resol));
break;
... only 124 more cases to go!
DO NOT -- repeat DO NOT actually write all of this code by hand!!!
There is no way any human could do that without coding a hard-to-find bug.
Write another program to write source code instead. :-)