//---Author: Richard T. Jones 07/12/2007 //---Version: 1.0 /************************************************************************* * Copyright(c) 1998, University of Connecticut, All rights reserved. * * Author: Richard T. Jones, Asst. Prof. of Physics * * * * Permission to use, copy, modify and distribute this software and its * * documentation for non-commercial purposes is hereby granted without * * fee, provided that the above copyright notice appears in all copies * * and that both the copyright notice and this permission notice appear * * in the supporting documentation. The author makes no claims about the * * suitability of this software for any purpose. * * It is provided "as is" without express or implied warranty. * *************************************************************************/ ////////////////////////////////////////////////////////////////////////// // // // Michelson Interferometric Topography Analysis Package // // // // The present package implements tools for modeling the shape of a // // general 2D surface in terms of its Legendre expansion. // // // ////////////////////////////////////////////////////////////////////////// #include #include using namespace std; #include #include #include #include ClassImp(TBitmap) TBitmap::TBitmap(UInt_t width, UInt_t height) : fWidth(width), fHeight(height), fDeg(0) { fImage = new Double_t[width*height]; fTimage = 0; fHasModel = 0; } TBitmap::TBitmap(const TBitmap& map) : fWidth(map.fWidth), fHeight(map.fHeight), fDeg(0) { fImage = new Double_t[fWidth*fHeight]; for (UInt_t i=0; iGetDegree() != deg) { delete fHasModel; fHasModel = 0; } if (fHasModel) { ++fHasModelCtr; Double_t coeff[deg*deg]; UInt_t ci[deg*deg]; UInt_t cj[deg*deg]; UInt_t nchanged=0; for (UInt_t i=0; i 1000) { UInt_t k=0; for (UInt_t m=0; m 1e-10) { std::cerr << "Warning in TBitmap::ComputeFast - " << "algorithm finds " << fImage[k] << ", expected " << expected << ", difference = " << fImage[k]-expected << std::endl; } fImage[k] = expected; } } fHasModelCtr = 0; } if (fHasModel) delete fHasModel; fHasModel = new TModel(model); } void TBitmap::Compute(const TModel& model) { // Compute the value of the model at the lattice sites // of the bitmap and store the results in fImage. if (fDeg) { ComputeFast(model); return; } std::cout << "+c+" << std::endl; if (fTimage) { delete fTimage; fTimage = 0; } if (fHasModel) { delete fHasModel; fHasModel = 0; } UInt_t k=0; for (UInt_t m=0; mSetImage(fImage,fWidth,fHeight); } fTimage->Gray(); fTimage->Draw(option); } void TBitmap::ReadBMP(const char* filename) { #include struct bmp_header_ bmp_header; struct dib_header_ dib_header; std::ifstream infile(filename); if (! infile.is_open()) { std::cout << "ReadBMP error - file %s cannot be opened for reading.\n" << std::endl; return; } infile.read((char*)&bmp_header,sizeof(struct bmp_header_)); if (bmp_header.magic != 0x4d42) { std::cout << "ReadBMP error - file %s does not have a valid bmp file header.\n" << std::endl; return; } infile.read((char*)&dib_header,sizeof(struct dib_header_)); if (dib_header.hdrlen != 40) { std::cout << "ReadBMP error - file %s does not have a recognized bmp file header.\n" << std::endl; return; } unsigned int *values = new unsigned int[dib_header.width*dib_header.height]; infile.read((char*)values,dib_header.size); infile.close(); delete [] fImage; fWidth = dib_header.width; fHeight = dib_header.height; fImage = new Double_t[fWidth*fHeight]; for (UInt_t i=0; i struct bmp_header_ bmp_header; struct dib_header_ dib_header; std::ofstream outfile(filename); if (! outfile.is_open()) { std::cout << "WriteBMP error - file %s cannot be opened for writing.\n" << std::endl; return; } bmp_header.magic = 0x4d42; bmp_header.fsize = sizeof(struct bmp_header_) + sizeof(struct dib_header_) + fWidth * fHeight * 4; bmp_header.reserved[0] = 0; bmp_header.reserved[1] = 0; bmp_header.offset = 54; outfile.write((char*)&bmp_header,sizeof(struct bmp_header_)); dib_header.hdrlen = 40; dib_header.width = fWidth; dib_header.height = fHeight; dib_header.planes = 1; dib_header.depth = 32; dib_header.compression = 0; dib_header.size = fWidth * fHeight * 4; dib_header.hresol = 0; dib_header.vresol = 0; dib_header.ncolors = 0; dib_header.nimpcolors = 0; outfile.write((char*)&dib_header,sizeof(struct dib_header_)); unsigned int *values = new unsigned int[fWidth*fHeight]; double maxval=-1e30; double minval=1e30; for (unsigned int i=0; i maxval)? fImage[i] : maxval; minval = (fImage[i] < minval)? fImage[i] : minval; } double slope = 3*255/(maxval-minval+1e-30); for (unsigned int i=0; i> fWidth >> fHeight; buf.ReadStaticArray(fImage); } else { buf << fWidth << fHeight; buf.WriteArray(fImage, fWidth*fHeight); } }