Rev 209 | Rev 248 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 209 | Rev 221 | ||
---|---|---|---|
1 | #ifdef _CVI_ |
1 | #ifdef _CVI_ |
2 | # include <ansi_c.h> |
2 | # include <ansi_c.h> |
3 | # else _CVI_ |
3 | # else _CVI_ |
4 | # include <stdlib.h> |
4 | # include <stdlib.h> |
5 | # include <stdio.h> |
5 | # include <stdio.h> |
6 | # include <string.h> |
6 | # include <string.h> |
7 | #endif _CVI_ |
7 | #endif _CVI_ |
8 | 8 | ||
9 | #include "H3D.h" |
9 | #include "H3D.h" |
10 | #include "H2D.h" |
10 | #include "H2D.h" |
11 | #include "H1D.h" |
11 | #include "H1D.h" |
12 | 12 | ||
13 | #define H3DMAX 500 |
13 | #define H3DMAX 500 |
14 | H3D *h3[H3DMAX]; |
14 | H3D *h3[H3DMAX]; |
15 | //int Printf(char *format, ...); |
15 | //int Printf(char *format, ...); |
16 | 16 | ||
17 | int _VI_FUNC H3D_Clear(int h3d) { |
17 | int _VI_FUNC H3D_Clear(int h3d) { |
18 | if (!h3[h3d]) return -1; |
18 | if (!h3[h3d]) return -1; |
19 | memset(h3[h3d]->data, 0,h3[h3d]->size ); |
19 | memset(h3[h3d]->data, 0,h3[h3d]->size ); |
20 | h3[h3d]->min=0; |
20 | h3[h3d]->min=0; |
21 | h3[h3d]->max=0; |
21 | h3[h3d]->max=0; |
22 | h3[h3d]->nentries=0; |
22 | h3[h3d]->nentries=0; |
23 | return 0; |
23 | return 0; |
24 | 24 | ||
25 | } |
25 | } |
26 | 26 | ||
27 | int _VI_FUNC H3D_Print(int h3d) { |
27 | int _VI_FUNC H3D_Print(int h3d) { |
28 | if (!h3[h3d]) return -1; |
28 | if (!h3[h3d]) return -1; |
29 | //Printf("PrintH3D nx=%d minx=%f stepx=%f ny=%d miny=%f stepy=%f size=%d\n", h3[h3d]->nx, h3[h3d]->minx, h3[h3d]->stepx, h3[h3d]->ny, h3[h3d]->miny, h3[h3d]->stepy, h3[h3d]->size ) ; |
29 | //Printf("PrintH3D nx=%d minx=%f stepx=%f ny=%d miny=%f stepy=%f size=%d\n", h3[h3d]->nx, h3[h3d]->minx, h3[h3d]->stepx, h3[h3d]->ny, h3[h3d]->miny, h3[h3d]->stepy, h3[h3d]->size ) ; |
30 | return 0; |
30 | return 0; |
31 | 31 | ||
32 | } |
32 | } |
33 | 33 | ||
34 | int _VI_FUNC H3D_Exist(int h) { |
34 | int _VI_FUNC H3D_Exist(int h) { |
35 | if (h3[h]) return 1; |
35 | if (h3[h]) return 1; |
36 | else return 0; |
36 | else return 0; |
37 | } |
37 | } |
38 | 38 | ||
39 | 39 | ||
40 | int _VI_FUNC H3D_CalculateBin(int h, int axis, double value) { |
40 | int _VI_FUNC H3D_CalculateBin(int h, int axis, double value) { |
41 | int nx=1,xmin=0,dx=0; |
41 | int nx=1,xmin=0,dx=0; |
42 | int bin; |
42 | int bin; |
43 | switch (axis) { |
43 | switch (axis) { |
44 | case 0: |
44 | case 0: |
45 | nx = H3D_GetNbinsX(h); |
45 | nx = H3D_GetNbinsX(h); |
46 | xmin= H3D_GetMinX(h); |
46 | xmin= H3D_GetMinX(h); |
47 | dx = H3D_GetStepX(h); |
47 | dx = H3D_GetStepX(h); |
48 | break; |
48 | break; |
49 | case 1: |
49 | case 1: |
50 | nx = H3D_GetNbinsY(h); |
50 | nx = H3D_GetNbinsY(h); |
51 | xmin= H3D_GetMinY(h); |
51 | xmin= H3D_GetMinY(h); |
52 | dx = H3D_GetStepY(h); |
52 | dx = H3D_GetStepY(h); |
53 | break; |
53 | break; |
54 | case 2: |
54 | case 2: |
55 | nx = H3D_GetNbinsZ(h); |
55 | nx = H3D_GetNbinsZ(h); |
56 | xmin= H3D_GetMinZ(h); |
56 | xmin= H3D_GetMinZ(h); |
57 | dx = H3D_GetStepZ(h); |
57 | dx = H3D_GetStepZ(h); |
58 | break; |
58 | break; |
59 | 59 | ||
60 | } |
60 | } |
61 | if (dx==0) return -1; |
61 | if (dx==0) return -1; |
62 | if (value<xmin) return -1; |
62 | if (value<xmin) return -1; |
63 | bin = (int)((value-xmin)/dx); |
63 | bin = (int)((value-xmin)/dx); |
64 | if (bin>=nx) return -1; |
64 | if (bin>=nx) return -1; |
65 | else return bin; |
65 | else return bin; |
66 | } |
66 | } |
67 | 67 | ||
68 | int _VI_FUNC H3D_Fill(int h3d,double x, double y, double z, double val) { |
68 | int _VI_FUNC H3D_Fill(int h3d,double x, double y, double z, double val) { |
69 | 69 | ||
70 | int ix,iy, iz; |
70 | int ix,iy, iz; |
71 | if (!h3[h3d]) return -1; |
71 | if (!h3[h3d]) return -1; |
72 | 72 | ||
73 | ix = H3D_CalculateBin(h3d,0,x); |
73 | ix = H3D_CalculateBin(h3d,0,x); |
74 | if (ix<0) return ix; |
74 | if (ix<0) return ix; |
75 | 75 | ||
76 | iy = H3D_CalculateBin(h3d,1,y); |
76 | iy = H3D_CalculateBin(h3d,1,y); |
77 | if (iy<0) return iy; |
77 | if (iy<0) return iy; |
78 | 78 | ||
79 | iz = H3D_CalculateBin(h3d,2,z); |
79 | iz = H3D_CalculateBin(h3d,2,z); |
80 | if (iz<0) return iz; |
80 | if (iz<0) return iz; |
81 | 81 | ||
82 | 82 | ||
83 | H3D_FillBin(h3d, ix, iy, iz, val); |
83 | H3D_FillBin(h3d, ix, iy, iz, val); |
84 | return 0; |
84 | return 0; |
85 | } |
85 | } |
86 | 86 | ||
87 | int _VI_FUNC H3D_GetBin(int h3d,int x, int y, int z) { |
87 | int _VI_FUNC H3D_GetBin(int h3d,int x, int y, int z) { |
88 | return x+h3[h3d]->nx *(y+z*h3[h3d]->ny); |
88 | return x+h3[h3d]->nx *(y+z*h3[h3d]->ny); |
89 | } |
89 | } |
90 | 90 | ||
91 | int _VI_FUNC H3D_FillBin(int h3d,int x, int y, int z, double val) { |
91 | int _VI_FUNC H3D_FillBin(int h3d,int x, int y, int z, double val) { |
92 | 92 | ||
93 | int idx; |
93 | int idx; |
94 | if (!h3[h3d]) { |
94 | if (!h3[h3d]) { |
95 | //Printf("FillH3D error h3d is not initialized\n"); |
95 | //Printf("FillH3D error h3d is not initialized\n"); |
96 | return -1; |
96 | return -1; |
97 | } |
97 | } |
98 | 98 | ||
99 | idx = H3D_GetBin(h3d,x,y,z); |
99 | idx = H3D_GetBin(h3d,x,y,z); |
100 | h3[h3d]->data[idx]+=val; |
100 | h3[h3d]->data[idx]+=val; |
101 | //Printf("%d %d data %f %f\n",x,y,val, h3[h3d]->data[idx]); |
101 | //Printf("%d %d data %f %f\n",x,y,val, h3[h3d]->data[idx]); |
102 | if (h3[h3d]->data[idx]>h3[h3d]->max) h3[h3d]->max= h3[h3d]->data[idx]; |
102 | if (h3[h3d]->data[idx]>h3[h3d]->max) h3[h3d]->max= h3[h3d]->data[idx]; |
103 | if (h3[h3d]->data[idx]<h3[h3d]->min) h3[h3d]->min= h3[h3d]->data[idx]; |
103 | if (h3[h3d]->data[idx]<h3[h3d]->min) h3[h3d]->min= h3[h3d]->data[idx]; |
104 | h3[h3d]->nentries++; |
104 | h3[h3d]->nentries++; |
105 | return 0; |
105 | return 0; |
106 | } |
106 | } |
107 | 107 | ||
108 | double _VI_FUNC H3D_GetBinContent(int h3d,int atx, int aty, int atz) { |
108 | double _VI_FUNC H3D_GetBinContent(int h3d,int atx, int aty, int atz) { |
109 | 109 | ||
110 | int idx; |
110 | int idx; |
111 | if (!h3[h3d]) return 0; |
111 | if (!h3[h3d]) return 0; |
112 | if (h3[h3d]->nx <= atx) return 0; |
112 | if (h3[h3d]->nx <= atx) return 0; |
113 | if (h3[h3d]->ny <= aty) return 0; |
113 | if (h3[h3d]->ny <= aty) return 0; |
114 | if (h3[h3d]->nz <= atz) return 0; |
114 | if (h3[h3d]->nz <= atz) return 0; |
115 | idx = H3D_GetBin(h3d,atx,aty,atz); |
115 | idx = H3D_GetBin(h3d,atx,aty,atz); |
116 | if (idx*sizeof(double) < h3[h3d]->size ) return h3[h3d]->data[idx]; |
116 | if (idx*sizeof(double) < h3[h3d]->size ) return h3[h3d]->data[idx]; |
117 | 117 | ||
118 | 118 | ||
119 | return 0; |
119 | return 0; |
120 | } |
120 | } |
121 | 121 | ||
122 | 122 | ||
123 | int _VI_FUNC H3D_Init(int h3d,char *name, char *title, |
123 | int _VI_FUNC H3D_Init(int h3d,char *name, char *title, |
124 | int nx, double minx, double maxx, |
124 | int nx, double minx, double maxx, |
125 | int ny, double miny, double maxy, |
125 | int ny, double miny, double maxy, |
126 | int nz, double minz, double maxz) { |
126 | int nz, double minz, double maxz) { |
127 | 127 | ||
128 | if (h3[h3d]) { |
128 | if (h3[h3d]) { |
129 | 129 | ||
130 | free(h3[h3d]->data); |
130 | free(h3[h3d]->data); |
131 | free(h3[h3d]); |
131 | free(h3[h3d]); |
132 | h3[h3d] = NULL; |
132 | h3[h3d] = NULL; |
133 | } |
133 | } |
134 | //printf("InitH3D hID=%d\n",h3d); |
134 | //printf("InitH3D hID=%d\n",h3d); |
135 | h3[h3d] = (H3D *) malloc(sizeof(H3D)); |
135 | h3[h3d] = (H3D *) malloc(sizeof(H3D)); |
136 | //h2 =h3d; |
136 | //h2 =h3d; |
137 | 137 | ||
138 | H3D_SetTitle(h3d,title); |
138 | H3D_SetTitle(h3d,title); |
139 | H3D_SetName(h3d,name); |
139 | H3D_SetName(h3d,name); |
140 | h3[h3d]->id=H3D_ID; |
140 | h3[h3d]->id=H3D_ID; |
141 | h3[h3d]->nx = nx; |
141 | h3[h3d]->nx = nx; |
142 | h3[h3d]->ny = ny; |
142 | h3[h3d]->ny = ny; |
143 | h3[h3d]->nz = nz; |
143 | h3[h3d]->nz = nz; |
144 | 144 | ||
145 | h3[h3d]->minx = minx; |
145 | h3[h3d]->minx = minx; |
146 | h3[h3d]->miny = miny; |
146 | h3[h3d]->miny = miny; |
147 | h3[h3d]->minz = minz; |
147 | h3[h3d]->minz = minz; |
148 | 148 | ||
149 | h3[h3d]->stepx = (nx>1)?(maxx-minx)/(nx |
149 | h3[h3d]->stepx = (nx>1)?(maxx-minx)/(nx):0; |
150 | h3[h3d]->stepy = (nx>1)?(maxy-miny)/(ny |
150 | h3[h3d]->stepy = (nx>1)?(maxy-miny)/(ny):0; |
151 | h3[h3d]->stepz = (nx>1)?(maxz-minz)/(nz |
151 | h3[h3d]->stepz = (nx>1)?(maxz-minz)/(nz):0; |
152 | 152 | ||
153 | h3[h3d]->size = h3[h3d]->nx*h3[h3d]->ny*h3[h3d]->nz*sizeof(double); |
153 | h3[h3d]->size = h3[h3d]->nx*h3[h3d]->ny*h3[h3d]->nz*sizeof(double); |
154 | h3[h3d]->data = (double *) malloc(h3[h3d]->size); |
154 | h3[h3d]->data = (double *) malloc(h3[h3d]->size); |
155 | h3[h3d]->len=sizeof(H3D)-sizeof(double *)+h3[h3d]->size; |
155 | h3[h3d]->len=sizeof(H3D)-sizeof(double *)+h3[h3d]->size; |
156 | H3D_Clear(h3d); |
156 | H3D_Clear(h3d); |
157 | H3D_Print(h3d); |
157 | H3D_Print(h3d); |
158 | //Printf("InitH3D 0x%x\n", h3d ); |
158 | //Printf("InitH3D 0x%x\n", h3d ); |
159 | return 0; |
159 | return 0; |
160 | 160 | ||
161 | } |
161 | } |
162 | 162 | ||
163 | 163 | ||
164 | int _VI_FUNC H3D_SliXY(int histogram,int slice, int direction) { |
164 | int _VI_FUNC H3D_SliXY(int histogram,int slice, int direction) { |
165 | 165 | ||
166 | if (!H3D_Exist(histogram)) { |
166 | if (!H3D_Exist(histogram)) { |
167 | printf("3D Histogram %d does not exist!\n",histogram); |
167 | printf("3D Histogram %d does not exist!\n",histogram); |
168 | return -1; |
168 | return -1; |
169 | } |
169 | } |
170 | 170 | ||
171 | int hid=499; |
171 | int hid=499; |
172 | switch (direction){ |
172 | switch (direction){ |
173 | case 0:// xy |
173 | case 0:// xy |
174 | H2D_Init(hid,"projectionXY","projectionXY", |
174 | H2D_Init(hid,"projectionXY","projectionXY", |
175 | H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram), |
175 | H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram), |
176 | H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram) |
176 | H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram) |
177 | ); |
177 | ); |
178 | for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) |
178 | for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) |
179 | for (int j=0; j < H3D_GetNbinsY(histogram); j++ ) |
179 | for (int j=0; j < H3D_GetNbinsY(histogram); j++ ) |
180 | H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,j,slice)); |
180 | H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,j,slice)); |
181 | break; |
181 | break; |
182 | case 1:// xz |
182 | case 1:// xz |
183 | H2D_Init(hid,"projectionXZ","projectionXZ", |
183 | H2D_Init(hid,"projectionXZ","projectionXZ", |
184 | H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram), |
184 | H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram), |
185 | H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram) |
185 | H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram) |
186 | ); |
186 | ); |
187 | for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) |
187 | for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) |
188 | for (int j=0; j < H3D_GetNbinsZ(histogram); j++ ) |
188 | for (int j=0; j < H3D_GetNbinsZ(histogram); j++ ) |
189 | H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,slice,j)); |
189 | H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,slice,j)); |
190 | break; |
190 | break; |
191 | case 2:// yz |
191 | case 2:// yz |
192 | default: |
192 | default: |
193 | H2D_Init(hid,"projectionYZ","projectionYZ", |
193 | H2D_Init(hid,"projectionYZ","projectionYZ", |
194 | H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram), |
194 | H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram), |
195 | H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram) |
195 | H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram) |
196 | ); |
196 | ); |
197 | for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) |
197 | for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) |
198 | for (int j=0; j < H3D_GetNbinsZ(histogram); j++ ) |
198 | for (int j=0; j < H3D_GetNbinsZ(histogram); j++ ) |
199 | H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,slice,i,j)); |
199 | H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,slice,i,j)); |
200 | 200 | ||
201 | break; |
201 | break; |
202 | } |
202 | } |
203 | return hid; |
203 | return hid; |
204 | } |
204 | } |
205 | 205 | ||
206 | double _VI_FUNC H3D_GetMaxX(int h){ |
206 | double _VI_FUNC H3D_GetMaxX(int h){ |
207 | return h3[h]->minx+(h3[h]->nx |
207 | return h3[h]->minx+(h3[h]->nx)*h3[h]->stepx; |
208 | } |
208 | } |
209 | 209 | ||
210 | double _VI_FUNC H3D_GetMaxY(int h){ |
210 | double _VI_FUNC H3D_GetMaxY(int h){ |
211 | return h3[h]->miny+(h3[h]->ny |
211 | return h3[h]->miny+(h3[h]->ny)*h3[h]->stepy; |
212 | } |
212 | } |
213 | 213 | ||
214 | double _VI_FUNC H3D_GetMaxZ(int h){ |
214 | double _VI_FUNC H3D_GetMaxZ(int h){ |
215 | return h3[h]->minz+(h3[h]->nz |
215 | return h3[h]->minz+(h3[h]->nz)*h3[h]->stepz; |
216 | } |
216 | } |
217 | 217 | ||
218 | double _VI_FUNC H3D_GetXBinCenter(int h3d,int xbin) { |
218 | double _VI_FUNC H3D_GetXBinCenter(int h3d,int xbin) { |
219 | return h3[h3d]->minx+xbin*h3[h3d]->stepx; |
219 | return h3[h3d]->minx+(xbin+0.5)*h3[h3d]->stepx; |
220 | } |
220 | } |
221 | 221 | ||
222 | double _VI_FUNC H3D_GetYBinCenter(int h3d,int ybin) { |
222 | double _VI_FUNC H3D_GetYBinCenter(int h3d,int ybin) { |
223 | return h3[h3d]->miny+ybin*h3[h3d]->stepy; |
223 | return h3[h3d]->miny+(ybin+0.5)*h3[h3d]->stepy; |
224 | } |
224 | } |
225 | 225 | ||
226 | double _VI_FUNC H3D_GetZBinCenter(int h3d,int zbin) { |
226 | double _VI_FUNC H3D_GetZBinCenter(int h3d,int zbin) { |
227 | return h3[h3d]->minz+zbin*h3[h3d]->stepz; |
227 | return h3[h3d]->minz+(zbin+0.5)*h3[h3d]->stepz; |
228 | } |
228 | } |
229 | 229 | ||
230 | 230 | ||
231 | int _VI_FUNC H3D_Write2File(int h3d,FILE *fp) { |
231 | int _VI_FUNC H3D_Write2File(int h3d,FILE *fp) { |
232 | 232 | ||
233 | if (!fp) return -1; |
233 | if (!fp) return -1; |
234 | //printf("H3D sizeof(H3D)=%lu len-datasize=%d len=%lu datasize=%d\t",sizeof(H3D)-sizeof(double *),h3[h3d]->len-h3[h3d]->size,h3[h3d]->len,h3[h3d]->size); |
234 | //printf("H3D sizeof(H3D)=%lu len-datasize=%d len=%lu datasize=%d\t",sizeof(H3D)-sizeof(double *),h3[h3d]->len-h3[h3d]->size,h3[h3d]->len,h3[h3d]->size); |
235 | //printf("H3D sz=%d %d\n",sizeof(double),sizeof(double *)); |
235 | //printf("H3D sz=%d %d\n",sizeof(double),sizeof(double *)); |
236 | fwrite (h3[h3d], 1, sizeof(H3D)-sizeof(double *), fp); |
236 | fwrite (h3[h3d], 1, sizeof(H3D)-sizeof(double *), fp); |
237 | fwrite (h3[h3d]->data, 1, h3[h3d]->size, fp); |
237 | fwrite (h3[h3d]->data, 1, h3[h3d]->size, fp); |
238 | return 0; |
238 | return 0; |
239 | } |
239 | } |
240 | 240 | ||
241 | int _VI_FUNC H3D_Write(int h3d,const char *fname,const char *opt) { |
241 | int _VI_FUNC H3D_Write(int h3d,const char *fname,const char *opt) { |
242 | FILE *fp=fopen(fname,opt); |
242 | FILE *fp=fopen(fname,opt); |
243 | H3D_Write2File(h3d,fp); |
243 | H3D_Write2File(h3d,fp); |
244 | fclose(fp); |
244 | fclose(fp); |
245 | return 0; |
245 | return 0; |
246 | } |
246 | } |
247 | 247 | ||
248 | 248 | ||
249 | 249 | ||
250 | 250 | ||
251 | int _VI_FUNC H3D_SetTitle(int h3d,char *title) { |
251 | int _VI_FUNC H3D_SetTitle(int h3d,char *title) { |
252 | sprintf(h3[h3d]->title,"%s",title); |
252 | sprintf(h3[h3d]->title,"%s",title); |
253 | return 0; |
253 | return 0; |
254 | } |
254 | } |
255 | 255 | ||
256 | 256 | ||
257 | int _VI_FUNC H3D_SetTitleX(int h3d,char *title) { |
257 | int _VI_FUNC H3D_SetTitleX(int h3d,char *title) { |
258 | sprintf(h3[h3d]->titlex,"%s",title); |
258 | sprintf(h3[h3d]->titlex,"%s",title); |
259 | return 0; |
259 | return 0; |
260 | } |
260 | } |
261 | 261 | ||
262 | 262 | ||
263 | int _VI_FUNC H3D_SetTitleY(int h3d,char *title) { |
263 | int _VI_FUNC H3D_SetTitleY(int h3d,char *title) { |
264 | sprintf(h3[h3d]->titley,"%s",title); |
264 | sprintf(h3[h3d]->titley,"%s",title); |
265 | return 0; |
265 | return 0; |
266 | } |
266 | } |
267 | 267 | ||
268 | int _VI_FUNC H3D_SetTitleZ(int h3d,char *title) { |
268 | int _VI_FUNC H3D_SetTitleZ(int h3d,char *title) { |
269 | sprintf(h3[h3d]->titlez,"%s",title); |
269 | sprintf(h3[h3d]->titlez,"%s",title); |
270 | return 0; |
270 | return 0; |
271 | } |
271 | } |
272 | 272 | ||
273 | 273 | ||
274 | int _VI_FUNC H3D_SetName(int h3d,char *title) { |
274 | int _VI_FUNC H3D_SetName(int h3d,char *title) { |
275 | sprintf(h3[h3d]->name,"%s",title); |
275 | sprintf(h3[h3d]->name,"%s",title); |
276 | return 0; |
276 | return 0; |
277 | } |
277 | } |
278 | 278 | ||
279 | int _VI_FUNC H3D_GetNbinsY(int h) { |
279 | int _VI_FUNC H3D_GetNbinsY(int h) { |
280 | if (h3[h]) return h3[h]->ny; |
280 | if (h3[h]) return h3[h]->ny; |
281 | else return 0; |
281 | else return 0; |
282 | } |
282 | } |
283 | 283 | ||
284 | int _VI_FUNC H3D_GetNbinsX(int h) { |
284 | int _VI_FUNC H3D_GetNbinsX(int h) { |
285 | if (h3[h]) return h3[h]->nx; |
285 | if (h3[h]) return h3[h]->nx; |
286 | else return 0; |
286 | else return 0; |
287 | } |
287 | } |
288 | 288 | ||
289 | int _VI_FUNC H3D_GetNbinsZ(int h) { |
289 | int _VI_FUNC H3D_GetNbinsZ(int h) { |
290 | if (h3[h]) return h3[h]->nz; |
290 | if (h3[h]) return h3[h]->nz; |
291 | else return 0; |
291 | else return 0; |
292 | } |
292 | } |
293 | 293 | ||
294 | 294 | ||
295 | 295 | ||
296 | double _VI_FUNC H3D_GetMinX(int h) { |
296 | double _VI_FUNC H3D_GetMinX(int h) { |
297 | if (h3[h]) return h3[h]->minx; |
297 | if (h3[h]) return h3[h]->minx; |
298 | else return 0; |
298 | else return 0; |
299 | } |
299 | } |
300 | 300 | ||
301 | double _VI_FUNC H3D_GetMinY(int h) { |
301 | double _VI_FUNC H3D_GetMinY(int h) { |
302 | if (h3[h]) return h3[h]->miny; |
302 | if (h3[h]) return h3[h]->miny; |
303 | else return 0; |
303 | else return 0; |
304 | } |
304 | } |
305 | 305 | ||
306 | double _VI_FUNC H3D_GetMinZ(int h) { |
306 | double _VI_FUNC H3D_GetMinZ(int h) { |
307 | if (h3[h]) return h3[h]->minz; |
307 | if (h3[h]) return h3[h]->minz; |
308 | else return 0; |
308 | else return 0; |
309 | } |
309 | } |
310 | 310 | ||
311 | 311 | ||
312 | 312 | ||
313 | 313 | ||
314 | double _VI_FUNC H3D_GetStepX(int h) { |
314 | double _VI_FUNC H3D_GetStepX(int h) { |
315 | if (h3[h]) return h3[h]->stepx; |
315 | if (h3[h]) return h3[h]->stepx; |
316 | else return 0; |
316 | else return 0; |
317 | } |
317 | } |
318 | 318 | ||
319 | double _VI_FUNC H3D_GetStepY(int h) { |
319 | double _VI_FUNC H3D_GetStepY(int h) { |
320 | if (h3[h]) return h3[h]->stepy; |
320 | if (h3[h]) return h3[h]->stepy; |
321 | else return 0; |
321 | else return 0; |
322 | } |
322 | } |
323 | 323 | ||
324 | double _VI_FUNC H3D_GetStepZ(int h) { |
324 | double _VI_FUNC H3D_GetStepZ(int h) { |
325 | if (h3[h]) return h3[h]->stepz; |
325 | if (h3[h]) return h3[h]->stepz; |
326 | else return 0; |
326 | else return 0; |
327 | } |
327 | } |
328 | 328 | ||
329 | 329 | ||
330 | 330 | ||
331 | 331 | ||
332 | double _VI_FUNC H3D_GetMin(int h) { |
332 | double _VI_FUNC H3D_GetMin(int h) { |
333 | if (h3[h]) return h3[h]->min; |
333 | if (h3[h]) return h3[h]->min; |
334 | else return 0; |
334 | else return 0; |
335 | } |
335 | } |
336 | 336 | ||
337 | double _VI_FUNC H3D_GetMax(int h) { |
337 | double _VI_FUNC H3D_GetMax(int h) { |
338 | if (h3[h]) return h3[h]->max; |
338 | if (h3[h]) return h3[h]->max; |
339 | else return 0; |
339 | else return 0; |
340 | } |
340 | } |
341 | 341 | ||
342 | double * _VI_FUNC H3D_GetSliceXYData(int h, int slice) { |
342 | double * _VI_FUNC H3D_GetSliceXYData(int h, int slice) { |
343 | if (h3[h]) return (h3[h]->data+slice*h3[h]->nx*h3[h]->ny); |
343 | if (h3[h]) return (h3[h]->data+slice*h3[h]->nx*h3[h]->ny); |
344 | else return NULL; |
344 | else return NULL; |
345 | } |
345 | } |
346 | 346 | ||
347 | double * _VI_FUNC H3D_GetData(int h) { |
347 | double * _VI_FUNC H3D_GetData(int h) { |
348 | if (h3[h]) return h3[h]->data; |
348 | if (h3[h]) return h3[h]->data; |
349 | else return NULL; |
349 | else return NULL; |
350 | } |
350 | } |
351 | 351 | ||
352 | 352 | ||
353 | #ifdef _CVI_ |
353 | #ifdef _CVI_ |
354 | // defined only in CVI |
354 | // defined only in CVI |
355 | static HColorMap *colormap = NULL; |
355 | static HColorMap *colormap = NULL; |
356 | 356 | ||
357 | 357 | ||
358 | HColorMap * _VI_FUNC H3D_GetColorMap(void) { |
358 | HColorMap * _VI_FUNC H3D_GetColorMap(void) { |
359 | return colormap; |
359 | return colormap; |
360 | } |
360 | } |
361 | 361 | ||
362 | 362 | ||
363 | int _VI_FUNC H3D_SetRangeColors( double min, double max) { |
363 | int _VI_FUNC H3D_SetRangeColors( double min, double max) { |
364 | int i; |
364 | int i; |
365 | 365 | ||
366 | 366 | ||
367 | if (colormap == NULL) { |
367 | if (colormap == NULL) { |
368 | colormap = malloc(sizeof(HColorMap)); |
368 | colormap = malloc(sizeof(HColorMap)); |
369 | 369 | ||
370 | colormap->numberofColors = 5; |
370 | colormap->numberofColors = 5; |
371 | colormap->array = malloc(colormap->numberofColors*sizeof(ColorMapEntry)); |
371 | colormap->array = malloc(colormap->numberofColors*sizeof(ColorMapEntry)); |
372 | 372 | ||
373 | colormap->array[0].color = 0x0000ff; //BLUE |
373 | colormap->array[0].color = 0x0000ff; //BLUE |
374 | colormap->array[1].color = 0x00ff00; //GREEN |
374 | colormap->array[1].color = 0x00ff00; //GREEN |
375 | colormap->array[2].color = 0xffff00; //YELLOW |
375 | colormap->array[2].color = 0xffff00; //YELLOW |
376 | colormap->array[3].color = 0xff8000; //ORANGE |
376 | colormap->array[3].color = 0xff8000; //ORANGE |
377 | colormap->array[4].color = 0xff0000; //RED |
377 | colormap->array[4].color = 0xff0000; //RED |
378 | 378 | ||
379 | colormap->HiColor =colormap->array[colormap->numberofColors-1].color ; |
379 | colormap->HiColor =colormap->array[colormap->numberofColors-1].color ; |
380 | } |
380 | } |
381 | if (colormap->numberofColors<2) return -1; |
381 | if (colormap->numberofColors<2) return -1; |
382 | double fx = (max-min)/(colormap->numberofColors-1); |
382 | double fx = (max-min)/(colormap->numberofColors-1); |
383 | for (i=0; i<colormap->numberofColors; i++) { |
383 | for (i=0; i<colormap->numberofColors; i++) { |
384 | colormap->array[i].dataValue.valDouble=i*fx+min; |
384 | colormap->array[i].dataValue.valDouble=i*fx+min; |
385 | } |
385 | } |
386 | return 0; |
386 | return 0; |
387 | } |
387 | } |
388 | 388 | ||
389 | int _VI_FUNC H3D_DrawSliceXY(int histogram,int slice,int direction, int panel, int control, int *plothandle) { |
389 | int _VI_FUNC H3D_DrawSliceXY(int histogram,int slice,int direction, int panel, int control, int *plothandle) { |
390 | 390 | ||
391 | 391 | ||
392 | 392 | ||
393 | if (H3D_GetNbinsY(histogram)==1|| H3D_GetNbinsX(histogram)==1) { |
393 | if (H3D_GetNbinsY(histogram)==1|| H3D_GetNbinsX(histogram)==1) { |
394 | if (H3D_GetNbinsY(histogram)==1) { |
394 | if (H3D_GetNbinsY(histogram)==1) { |
395 | H1D_Init(499,"projection","projection", H3D_GetNbinsX(histogram), H3D_GetMinX(histogram), |
395 | H1D_Init(499,"projection","projection", H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram)); |
396 | for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,i,0,slice)); |
396 | for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,i,0,slice)); |
397 | } else { |
397 | } else { |
398 | H1D_Init(499,"projection","projection", H3D_GetNbinsY(histogram), H3D_GetMinY(histogram), |
398 | H1D_Init(499,"projection","projection", H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram)); |
399 | for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,0,i,slice)); |
399 | for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,0,i,slice)); |
400 | } |
400 | } |
401 | H1D_Draw(499, panel, control, plothandle); |
401 | H1D_Draw(499, panel, control, plothandle); |
402 | } else { |
402 | } else { |
403 | 403 | ||
404 | if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW); |
404 | if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW); |
405 | H3D_SetRangeColors(H3D_GetMin(histogram),H3D_GetMax(histogram)); |
405 | H3D_SetRangeColors(H3D_GetMin(histogram),H3D_GetMax(histogram)); |
406 | *plothandle = PlotScaledIntensity (panel, control, |
406 | *plothandle = PlotScaledIntensity (panel, control, |
407 | H3D_GetSliceXYData(histogram, slice), |
407 | H3D_GetSliceXYData(histogram, slice), |
408 | H3D_GetNbinsX(histogram), |
408 | H3D_GetNbinsX(histogram), |
409 | H3D_GetNbinsY(histogram), |
409 | H3D_GetNbinsY(histogram), |
410 | VAL_DOUBLE, |
410 | VAL_DOUBLE, |
411 | H3D_GetStepY(histogram), |
411 | H3D_GetStepY(histogram), |
412 |
|
412 | H3D_GetYBinCenter(histogram,0), |
413 | H3D_GetStepX(histogram), |
413 | H3D_GetStepX(histogram), |
414 |
|
414 | H3D_GetXBinCenter(histogram,0), |
415 | colormap->array, |
415 | colormap->array, |
416 | colormap->HiColor, |
416 | colormap->HiColor, |
417 | colormap->numberofColors, 1, 0); |
417 | colormap->numberofColors, 1, 0); |
418 | } |
418 | } |
419 | ProcessSystemEvents (); |
419 | ProcessSystemEvents (); |
420 | return *plothandle; |
420 | return *plothandle; |
421 | 421 | ||
422 | } |
422 | } |
423 | #endif |
423 | #endif |
424 | 424 |