hey guys. I need some help here!
I have a 2D vector named grid.
what i need to do is magnify any data in it. it's of a bool type so something like this.

1100
0110
0011

in the 2D vector would become (after magnification)

11110000
11110000
00111100
00111100
00001111
00001111

so basically it doubles horizontally and vertically. but i cant seem to get the logic into code..

this is what ive got so far. it just increases the size of the vector and will iterate through the elements. but i have no idea where to go from here. im stumped. a mental block. and it's been like this for two days....any help would be appreciated!

numrows *=2;
    numcols *=2;

    //resize
    grid.resize(numrows);
    for (int i = 0; i < numrows ; i++ )
        grid.at(i).resize(numcols);


    vector< vector<bool> >::iterator row_it = grid.begin();
    vector< vector<bool> >::iterator row_end = grid.end();
    
    
    for ( ; row_it != row_end; ++row_it )
    {
        vector<bool>::iterator col_it = row_it->begin();
        vector<bool>::iterator col_end = row_it->end();

        for ( ; col_it != col_end; ++col_it )
        {



        }
    }
#include <vector>

template< typename T > 
void magnify( std::vector< std::vector<T> >& vec, size_t BY = 2 )
{
  std::vector< std::vector<T> > temp(vec) ;
  vec.clear() ;

  for( size_t i=0 ; i<temp.size() ; ++i )
  {
    std::vector<T> row ;
    for( size_t j=0 ; j<temp[i].size() ; ++j )
      row.resize( row.size()+BY, temp[i][j] ) ;
    vec.resize( vec.size()+BY, row ) ;
  }
  // TODO: inefficient; too many temporary vectors.
  // TODO: rewrite to get an efficient version.
}

thanks for the reply! :-) that really helped me get my head around it lol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.