OSDN Git Service

Modified: lmrcImageTranspose
[eos/base.git] / src / Objects / DataManip / mrcImage / src / lmrcImageTranspose.c.org
1 /*
2 # %M% %Y% %I%
3 # The latest update : %G% at %U%
4 #
5 #%Z% mrcImageTranspose ver %I%
6 #%Z% Created by 
7 #%Z%
8 #%Z% Usage : mrcImageTranspose
9 #%Z% Attention
10 #%Z%
11 */
12 static char __sccs_id[] = "%Z%mrcImageTranspose ver%I%; Date:%D% %Z%";
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <math.h>                  
17 #define GLOBAL_DECLARATION
18 #include "../inc/config.h"
19
20 #define DEBUG
21 #include "genUtil.h"
22 #include "mrcImage.h"
23 #include "mrcRefUtil.h"
24
25
26 /* prototype */
27 void lmrcImageTranspose(mrcImage* out , mrcImage* in ,int mode ,int mode2);
28
29 void
30 main(int argc, char* argv[]) 
31 {
32         long status;
33         mrcImageTransposeInfo info;
34
35 /* variables */
36         mrcImage in;
37         mrcImage out;
38
39 /* input patameters ,file open */
40         init0(&info);
41         argCheck(&info, argc, argv);
42         init1(&info);
43
44 /* begin */
45         DEBUGPRINT("start ");
46         mrcFileRead(&in ,info.In ,"in main" ,0);
47         DEBUGPRINT("read ");
48         lmrcImageTranspose(&out ,&in ,info.mode ,info.Mode);
49         DEBUGPRINT("trans ");
50         mrcFileWrite(&out ,info.Out ,"in main" ,0);
51         DEBUGPRINT("write ");
52         exit(EXIT_SUCCESS);
53 }
54
55 void
56 additionalUsage()
57 {
58 fprintf(stdout ,"----- mode1 -----\n");
59 fprintf(stdout ,"0:+90degree in xy plane around z-axis: x->+y\n");
60 fprintf(stdout ,"1:-90degree in xy plane around z-axis: x->-y\n");
61 fprintf(stdout ,"2:+90degree in yz plane around x-axis: y->+z\n");
62 fprintf(stdout ,"3:-90degree in yz plane around x-axis: y->-z\n");
63 fprintf(stdout ,"4:+90degree in zx plane around y-axis: z->+x\n");
64 fprintf(stdout ,"5:-90degree in zx plane around y-axis: z->-x\n");
65 fprintf(stdout ,"----- mode2 -----\n");
66 fprintf(stdout ,"0: Image\n");
67 fprintf(stdout ,"1: Ref Image(mode1 =0 or 1)\n");
68 }
69
70 void lmrcImageTranspose(mrcImage* out , mrcImage* in ,int mode ,int mode2)
71 {
72   
73 /* variables */
74   int x,y,ox,oy,oz,flag,z;
75   double data;
76   mrcRefHeader header;
77
78 /* Initialization */
79   out->Header = in->Header;
80   switch (mode){
81   case 0:
82   case 1: {
83     out->HeaderN.x = in->HeaderN.y;
84     out->HeaderN.y = in->HeaderN.x;
85     break;
86   }
87   case 2:
88   case 3: {
89     out->HeaderN.y = in->HeaderN.z;
90     out->HeaderN.z = in->HeaderN.y;
91   }
92   case 4:
93   case 5: {
94     out->HeaderN.z = in->HeaderN.x;
95     out->HeaderN.x = in->HeaderN.z;
96   }
97   }
98   mrcInit(out,NULL);
99
100 /* begin */
101   flag = 0;
102   if (mode2){
103     flag = 1;
104     lmrcRefHeaderGet(&header ,in);
105     lmrcRefHeaderSet(out ,&header);
106   }
107   for (z=flag; z < in->HeaderN.z ;z++){
108   for (y=0;    y < in->HeaderN.y ;y++){
109   for (x=0;    x < in->HeaderN.x ;x++){
110         mrcPixelDataGet(in ,x ,y ,z ,&data ,mrcPixelRePart ,mrcPixelHowNearest);
111         switch (mode){
112         case 0:
113           ox = in->HeaderN.y - 1 - y;
114           oy = x;
115           oz = z;
116           break;
117         case 1:
118           ox = y;
119           oy = in->HeaderN.x - 1 - x;
120           oz = z;
121           break;
122         case 2:
123           ox = x;
124           oy = in->HeaderN.z - 1 - z;
125           oz = y;
126           break;
127         case 3:
128           ox = x;
129           oy = z;
130           oz = in->HeaderN.y - -1 - y;
131           break;
132         case 4:
133           ox = z;
134           oy = y;
135           oz = in->HeaderN.x - 1 - x;
136           break;
137         case 5:
138           ox = in->HeaderN.z - 1 - z;
139           oy = y;
140           oz = x;
141           break;
142         
143         }
144         mrcPixelDataSet(out, ox, oy, oz, data, mrcPixelRePart);
145   }
146   }
147   }
148   mrcStatDataSet(out,0);
149 }
150       
151         
152
153
154
155