void binary_save(const blitz::Array<T,n> & M,std::string filename) { T z;assert(M.isStorageContiguous()); std::stringstream f;M.dumpStructureInformation(f); std::ofstream out(filename.c_str(),std::ios::binary); std::string s = f.str();int i=int(s.length())+1;char c='1'; out.write( (char*) &i,sizeof(i)); out.write( (s.c_str()) ,i*sizeof(c)); out.write( (char*)M.dataFirst(),M.numElements()*sizeof(z)); }
void binary_load(blitz::Array<T,n> & M,std::string filename) { assert(M.isStorageContiguous());T z; std::ifstream out(filename.c_str(),std::ios::binary); int i;char c='1'; out.read( (char*) &i,sizeof(i)); char *st = new char[i+1]; out.read( st ,i*sizeof(c)); std::string s(st); std::stringstream f; M.dumpStructureInformation(f); if (f.str() != s) FATAL("Can not load binary : array do not conform. Structure (file vs array)"<<s<<"----"<<f.str()); out.read( (char*)M.dataFirst(),M.numElements()*sizeof(z)); }
void display( void) { glClear( GL_COLOR_BUFFER_BIT); glRasterPos2i( 0, 0); switch( disp) { case display_a: glDrawPixels( image.cols(), image.rows(), GL_LUMINANCE, GL_FLOAT, alpha.dataFirst()); break; case display_bg: glDrawPixels( image.cols(), image.rows(), GL_RGB, GL_FLOAT, bg.dataFirst()); break; case display_fg: glDrawPixels( image.cols(), image.rows(), GL_RGB, GL_FLOAT, fg.dataFirst()); break; case display_comp: glDrawPixels( image.cols(), image.rows(), GL_RGB, GL_FLOAT, comp.dataFirst()); break; case display_img: glDrawPixels( image.cols(), image.rows(), GL_RGB, GL_FLOAT, image.dataFirst()); break; case display_tri: glDrawPixels( image.cols(), image.rows(), GL_LUMINANCE, GL_UNSIGNED_BYTE, trimap.dataFirst()); break; } glutSwapBuffers(); }
void convert2rgb( blitz::Array<Imath::Color3f,2>& img) { vigra::BasicImageView<vigra::TinyVector<float,3> > img_view( (vigra::TinyVector<float,3> *) img.dataFirst(), img.cols(), img.rows()); for( int j=0;j<img.rows();++j) for( int i=0;i<img.cols();++i) img( j, i) *= lab_scale; vigra::transformImage( vigra::srcImageRange( img_view), vigra::destImage( img_view), vigra::Lab2RGBFunctor<float>( 1.0f)); }