Introduction of small tools

From EosPedia
Jump to: navigation, search

First, show how to write basic main function.

Tool.c

#include "../inc/Tool.h"
#include "genUtil.h"
#include "mrcImage.h"

int
main(int argc, char* argv[])
{
    ToolInfo info;    // struct that stores information from argument
    lToolInfo linfo;  // struct that stores information for API
    mrcImage in;      // [[mrcImage]] as input
    mrcImage out;     // [[mrcImage]] as output

    // 3 function set that are provided as prototype.
    init0(&info);            // Initial Setting
    argCheck(&info, argc, argv);    // Pass the value from argument.
    init1(&info);            // Work depending on argument information: e.g. file open or close

    mrcFileRead(&in, info.In, "in main", 0);   // File read

  lTool(&out, &in, &linfo, info.mode);       // Process "in", and Create "out".
                        // Generally, function whose first letter is "l" is image process library.

    mrcFileWrite(&out, info.Out, "in main", 0); // File write
   
}


Next, show how to write basic image process library. Here, show how to write the program that performs projection along z axis.

lTool.c

#include "./lTool.h"
#include "genUtil.h"
#include "mrcImage.h"

void
lTool(mrcImage* out, mrcImage* in, lToolInfo* linfo, int status)
{
    mrcImageParaTypeReal x, y, z;    // Variable that expresses pixel coordinates
    double src, dst;                     // Store the value of pixel

    out->Header = in->Header;        // Make same format of output image as input image.
  out->HeaderN.z = 1;              // For Example, deal as 1 pixel data about along z axis.
    mrcInit(&out, NULL);             // Secure the memory region for output image.

    for(z=0; z<in->HeaderN.z; z++){
    for(y=0; y<in->HeaderN.y; y++){
    for(x=0; x<in->HeaderN.x; x++){
        // Get the value of pixel.
        mrcPixelDataGet(in,  x, y, z, &src, mrcPixelRePart, mrcPixelHowNearest);
        mrcPixelDataGet(out, x, y, 0, &dst, mrcPixelRePart, mrcPixelHowNearest);

        // Add the value of pixel.
        dst += src;

        // Set a new value of pixel.
        mrcPixelDataSet(out, x, y, 0,  dst, mrcPixelRePart);
   } 
    }
    }
}