示例#1
0
文件: paker.cpp 项目: foliveira/paker
int main(int argc, char *argv[]) 
{
	if(argc > 1)
	{
		if(!strcmp(argv[1], "-h"))
		{
			cout << "Paker - Compressão de ficheiros" << endl;
			cout << endl << "Para empacotar use:" << endl;
			cout << endl << argv[0] << " rle|lzss|mix repetition_bits|[position_bits coincidence_bits] <filename>" << endl;
			cout << endl << "ou para desempacotar:" << endl;
			cout << endl << argv[0] << " -u <filename>" << endl;
			cout << endl << "Para comprimir escolher um dos seguintes modos:" << endl;
			cout << endl << "\trle - Utilizar a te'cnica RLE sobre o ficheiro, ";
			cout << "e' necessa'rio fornecer o valore de repetition_bits (valores 4 por defeito)." << endl;
			cout << endl << "\tlzss - Utilizar a te'cnica LZSS sobre o ficheiro, ";
			cout << "e' necessa'rio fornecer os valores de position_bits e coincidence_bits (valores 10 e 4 por defeito)." << endl;
			cout << endl << "\tmix - Utilizar a te'cnica LZSS em conjunto com RLE sobre o ficheiro, ";
			cout << "e' necessa'rio fornecer os valores de repetition_bits, position_bits e coincidence_bits (valores 4, 10 e 4 por defeito)." << endl;
			cout << endl << endl << "ISEL 2008 - Fa'bio Oliveira [30979] e Renato Verissi'mo [30796]" << endl;

			return 0;
		}
		else if(!strcmp(argv[1], "-u"))
		{
			if (argc < 3) 
			{ 
				cout << "Use " << argv[0] << " -h para obter ajuda" << endl; 
				return 1; 
			}

			UnPk upk(argv[argc - 1]);
			int error = upk.init();
			
			if(error) 
				return error;
		    
			upk.go();
		}
		else 
		{
			if (argc < 4) 
			{ 
				cout << "Use " << argv[0] << " -h para obter ajuda" << endl; 
				return 1;
			}

			FileName iname = argv[argc - 1];
			FileName oname = iname.getBaseName();

			oname.addExtension(pk_ext);

			Pk pk(iname, oname);
			int error = pk.init();
			
			if(error) 
				return error;

			pk.go(argc - 2, argv + 1, iname.getExtension());
		}
	}
	else
	{
		cout << "Use " << argv[0] << " -h para obter ajuda" << endl; 	
		return 1;
	}
}
示例#2
0
/* Produce all images ------------------------------------------------------ */
void Micrograph::produce_all_images(int label, double minCost,
                                    const FileName &fn_rootIn, const FileName &fn_image, double ang,
                                    double tilt, double psi, bool rmStack)
{
    MetaData SF;
    Image<double> I;
    Micrograph *M;

    // Set Source image
    if (fn_image == "")
        M = this;
    else
    {
        M = new Micrograph;
        M->open_micrograph(fn_image/*, swapbyte*/);
        M->set_window_size(X_window_size, Y_window_size);
        M->set_transmitance_flag(compute_transmitance);
        M->set_inverse_flag(compute_inverse);
    }

    // Set scale for particles
    int MXdim, MYdim, thisXdim, thisYdim;
    M->size(MXdim, MYdim);
    this->size(thisXdim, thisYdim);
    double scaleX = (double) MXdim / thisXdim;
    double scaleY = (double) MYdim / thisYdim;

    // Compute max and minimum if compute_transmitance
    // or compute_inverse flags are ON
    double Dmax=0., Dmin=0.;
    if (compute_transmitance || compute_inverse)
    {
        (*this).computeDoubleMinMax(Dmin, Dmax);

        if (compute_transmitance)
        {
            if (Dmin > 1)
                Dmin = log10(Dmin);
            if (Dmax > 1)
                Dmax = log10(Dmax);
        }
    }
    // Scissor all particles
    if (ang != 0)
        std::cout << "Angle from Y axis to tilt axis " << ang << std::endl
        << "   applying appropriate rotation\n";
    int nmax = ParticleNo();
    FileName fn_aux;
    FileName _ext = fn_rootIn.getFileFormat();
    FileName fn_out;
    FileName fn_root = fn_rootIn.removeFileFormat().removeLastExtension();
    if (fn_rootIn.hasStackExtension())
        fn_out=fn_root.addExtension(_ext);
    else
    	fn_out=fn_rootIn.addExtension("stk");

    if (rmStack)
        fn_out.deleteFile();
    size_t ii = 0;
    size_t id;
    for (int n = 0; n < nmax; n++)
        if (coords[n].valid && coords[n].cost > minCost && coords[n].label == label)
        {
            fn_aux.compose(++ii, fn_out);
            id = SF.addObject();
            // If the ctfRow was set, copy the info to images metadata
            if (ctfRow.containsLabel(MDL_CTF_DEFOCUSU))
                SF.setRow(ctfRow, id);
            SF.setValue(MDL_IMAGE, fn_aux, id);
            SF.setValue(MDL_MICROGRAPH, M->fn_micrograph, id);
            SF.setValue(MDL_XCOOR, coords[n].X, id);
            SF.setValue(MDL_YCOOR, coords[n].Y, id);
            bool t = M->scissor(coords[n], I(), Dmin, Dmax, scaleX, scaleY);
            if (!t)
            {
                std::cout << "Particle " << fn_aux
                << " is very near the border, "
                << "corresponding image is set to blank\n";
                SF.setValue(MDL_ENABLED, -1, id);
            }
            else
                SF.setValue(MDL_ENABLED, 1, id);
            //  if (ang!=0) I().rotate(-ang);
            I.write(fn_out, ii, true, WRITE_APPEND);
        }
    SF.write(fn_out.withoutExtension() + ".xmd");


    // Free source image??
    if (fn_image != "")
    {
        M->close_micrograph();
        delete M;
    }
}