/cvi/instr/HISTO/H1D.c |
---|
0,0 → 1,282 |
#include <userint.h> |
#ifdef _CVI_ |
# include <ansi_c.h> |
# else _CVI_ |
# include <stdlib.h> |
# include <stdio.h> |
# include <string.h> |
#endif _CVI_ |
#include "H1D.h" |
#define H1DMAX 500 |
H1D *h1[H1DMAX]; |
//int Printf(char *format, ...); |
int _VI_FUNC H1D_Clear(int h1d) { |
if (!h1[h1d]) return -1; |
memset(h1[h1d]->data, 0,h1[h1d]->size ); |
h1[h1d]->min=0; |
h1[h1d]->max=0; |
h1[h1d]->nentries=0; |
return 0; |
} |
int _VI_FUNC H1D_Print(int h1d) { |
if (!h1[h1d]) return -1; |
//Printf("PrintH1D_ nx=%d minx=%f stepx=%f ny=%d miny=%f stepy=%f size=%d\n", h1[h1d]->nx, h1[h1d]->minx, h1[h1d]->stepx, h1[h1d]->ny, h1[h1d]->miny, h1[h1d]->stepy, h1[h1d]->size ) ; |
return 0; |
} |
int _VI_FUNC H1D_Exist(int h) { |
if (h1[h]) return 1; |
else return 0; |
} |
int _VI_FUNC H1D_GetBin(int h, double value) { |
int nx,xmin,dx; |
int bin; |
nx = H1D_GetNbinsX(h); |
xmin= H1D_GetMinX(h); |
dx = H1D_GetStepX(h); |
if (dx==0) return -1; |
if (value<xmin) return -1; |
bin = (int)((value-xmin)/dx); |
if (bin>=nx) return -1; |
else return bin; |
} |
int _VI_FUNC H1D_Fill(int h1d,double x, double val) { |
int ix; |
if (!h1[h1d]) return -1; |
ix = H1D_GetBin(h1d,x); |
if (ix<0) return ix; |
h1[h1d]->data[ix]+=val; |
//Printf("%d %d data %f %f\n",x,y,val, h1[h1d]->data[idx]); |
if (h1[h1d]->data[ix]>h1[h1d]->max) h1[h1d]->max= h1[h1d]->data[ix]; |
if (h1[h1d]->data[ix]<h1[h1d]->min) h1[h1d]->min= h1[h1d]->data[ix]; |
h1[h1d]->nentries++; |
return 0; |
} |
int _VI_FUNC H1D_FillBin(int h1d,int x, double val) { |
if (!h1[h1d]) { |
//Printf("FillH1D_ error h1d is not initialized\n"); |
return -1; |
} |
h1[h1d]->data[x]+=val; |
//Printf("%d %d data %f %f\n",x,y,val, h1[h1d]->data[idx]); |
if (h1[h1d]->data[x]>h1[h1d]->max) h1[h1d]->max= h1[h1d]->data[x]; |
if (h1[h1d]->data[x]<h1[h1d]->min) h1[h1d]->min= h1[h1d]->data[x]; |
h1[h1d]->nentries++; |
return 0; |
} |
int _VI_FUNC H1D_SetBinContent(int h1d,int x, double val) { |
if (!h1[h1d]) { |
//Printf("FillH1D_ error h1d is not initialized\n"); |
return -1; |
} |
h1[h1d]->data[x]=val; |
//Printf("%d %d data %f %f\n",x,y,val, h1[h1d]->data[idx]); |
if (h1[h1d]->data[x]>h1[h1d]->max) h1[h1d]->max= h1[h1d]->data[x]; |
if (h1[h1d]->data[x]<h1[h1d]->min) h1[h1d]->min= h1[h1d]->data[x]; |
h1[h1d]->nentries++; |
return 0; |
} |
double _VI_FUNC H1D_GetBinContent(int h1d,int atx) { |
int idx; |
if (!h1[h1d]) return 0; |
if (h1[h1d]->nx <= atx) return 0; |
if (atx<0) return 0; |
if (atx*sizeof(double) < h1[h1d]->size ) return h1[h1d]->data[atx]; |
return 0; |
} |
int _VI_FUNC H1D_Init(int h1d,char *name, char *title,int nx, double minx, double maxx) { |
if (h1[h1d]) { |
free(h1[h1d]->data); |
free(h1[h1d]); |
h1[h1d] = NULL; |
} |
// if (h1d!=H1D_MAX-1) printf("InitH1D_ hID=%d\n",h1d); |
h1[h1d] = (H1D *) malloc(sizeof(H1D)); |
//h2 =h1d; |
H1D_SetTitle(h1d,title); |
H1D_SetName(h1d,name); |
H1D_SetTitleX(h1d,"x"); |
; |
h1[h1d]->id=H1D_ID; |
h1[h1d]->nx = nx; |
h1[h1d]->minx = minx; |
h1[h1d]->stepx = (nx>1)?(maxx-minx)/(nx-1):0; |
h1[h1d]->size = h1[h1d]->nx*sizeof(double); |
h1[h1d]->data = (double *) malloc(h1[h1d]->size); |
h1[h1d]->len=sizeof(H1D)-sizeof(double *)+h1[h1d]->size; |
H1D_Clear(h1d); |
H1D_Print(h1d); |
//Printf("InitH1D 0x%x\n", h1d ); |
return 0; |
} |
double _VI_FUNC H1D_GetXBinCenter(int h1d,int xbin) { |
return h1[h1d]->minx+xbin*h1[h1d]->stepx; |
} |
int _VI_FUNC H1D_Write2File(int h1d,FILE *fp) { |
if (!fp) return -1; |
//printf("H1D sizeof(H1D)=%lu len-datasize=%d len=%lu datasize=%d\t",sizeof(H1D)-sizeof(double *),h1[h1d]->len-h1[h1d]->size,h1[h1d]->len,h1[h1d]->size); |
//printf("H1D sz=%d %d\n",sizeof(double),sizeof(double *)); |
if (!H1D_Exist(h1d)){ |
printf("Histogram H1D=%d is not initialized\n",h1d); |
return -1; |
} |
fwrite (h1[h1d], 1, sizeof(H1D)-sizeof(double *), fp); |
fwrite (h1[h1d]->data, 1, h1[h1d]->size, fp); |
return 0; |
} |
int _VI_FUNC H1D_Write(int h1d,const char *fname,const char *opt) { |
FILE *fp=fopen(fname,opt); |
H1D_Write2File(h1d,fp); |
fclose(fp); |
return 0; |
} |
int _VI_FUNC H1D_SetTitle(int h1d,char *title) { |
if (!h1[h1d]) { |
printf("h1d %d does not exist %s\n",h1d, title); |
return 0; |
} |
sprintf(h1[h1d]->title,"%s",title); |
return 0; |
} |
int _VI_FUNC H1D_SetTitleX(int h1d,char *title) { |
sprintf(h1[h1d]->titlex,"%s",title); |
return 0; |
} |
int _VI_FUNC H1D_SetTitleY(int h1d,char *title) { |
sprintf(h1[h1d]->titley,"%s",title); |
return 0; |
} |
char * _VI_FUNC H1D_GetTitleX(int h1d) { |
return h1[h1d]->titlex; |
} |
char * _VI_FUNC H1D_GetTitleY(int h1d) { |
return h1[h1d]->titley; |
} |
char * _VI_FUNC H1D_GetTitle(int h1d) { |
return h1[h1d]->title; |
} |
int _VI_FUNC H1D_SetName(int h1d,char *title) { |
sprintf(h1[h1d]->name,"%s",title); |
return 0; |
} |
int _VI_FUNC H1D_GetNbinsX(int h) { |
if (h1[h]) return h1[h]->nx; |
else return 0; |
} |
double _VI_FUNC H1D_GetMinX(int h) { |
if (h1[h]) return h1[h]->minx; |
else return 0; |
} |
double _VI_FUNC H1D_GetMaxX(int h){ |
return h1[h]->minx+(h1[h]->nx-1)*h1[h]->stepx; |
} |
double _VI_FUNC H1D_GetStepX(int h) { |
if (h1[h]) return h1[h]->stepx; |
else return 0; |
} |
double _VI_FUNC H1D_GetMin(int h) { |
if (h1[h]) return h1[h]->min; |
else return 0; |
} |
double _VI_FUNC H1D_GetMax(int h) { |
if (h1[h]) return h1[h]->max; |
else return 0; |
} |
double * _VI_FUNC H1D_GetData(int h) { |
if (h1[h]) return h1[h]->data; |
else return NULL; |
} |
int _VI_FUNC H1D_Draw(int histogram,int panel, int control, int *plothandle) { |
const unsigned int hcolors[8]= {VAL_RED, VAL_GREEN, VAL_BLUE, VAL_CYAN, VAL_MAGENTA, VAL_YELLOW, VAL_GRAY, VAL_BLACK}; |
if (!H1D_Exist(histogram)) { |
printf("1D Histogram %d does not exist!\n",histogram); |
return 0; |
} |
#ifdef _CVI_ |
if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW); |
*plothandle = PlotWaveform (panel, control, H1D_GetData(histogram), H1D_GetNbinsX(histogram), VAL_DOUBLE, 1, 0, |
H1D_GetMinX(histogram), H1D_GetStepX(histogram), VAL_FAT_LINE, VAL_SMALL_SOLID_SQUARE, VAL_SOLID, 1, |
hcolors[histogram%8]); |
RefreshGraph (panel, control); |
ProcessSystemEvents (); |
#endif |
return *plothandle; |
} |
/cvi/instr/HISTO/H1D.fp |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/cvi/instr/HISTO/H1D.h |
---|
0,0 → 1,78 |
#ifndef _H1D_H_ |
#define _H1D_H_ |
#ifdef _CVI_ |
#include <cvidef.h> |
#include <ivi.h> |
#include <userint.h> |
#else |
#define _VI_FUNC |
#endif |
#include <stdio.h> |
/* 2d histogramming */ |
#define H1D_ID 0x11 |
#pragma pack(4) |
typedef struct { |
unsigned int id,len; |
unsigned int nx; |
int nentries; |
unsigned int size; |
double min; |
double max; |
double minx; |
double stepx; |
char name[20]; |
char title[100]; |
char titlex[40]; |
char titley[40]; |
double *data; |
} H1D; |
#pragma pack() |
double _VI_FUNC H1D_GetYBinCenter(int h2d,int ybin); |
double _VI_FUNC H1D_GetYBinCenter(int h2d,int xbin); |
int _VI_FUNC H1D_Clear(int h2d); |
int _VI_FUNC H1D_Print(int h2d); |
int _VI_FUNC H1D_Exist(int h2d); |
int _VI_FUNC H1D_GetBin(int h2d, double value); |
int _VI_FUNC H1D_Fill(int h2d,double x, double val); |
int _VI_FUNC H1D_FillBin(int h2d,int x, double val); |
int _VI_FUNC H1D_SetBinContent(int h2d,int x, double val); |
double _VI_FUNC H1D_GetBinContent(int h2d,int atx); |
int _VI_FUNC H1D_Init(int h2d,char *name, char *title,int nx, double minx, double maxx); |
int _VI_FUNC H1D_Write(int h2d,const char *fname,const char*opt); |
int _VI_FUNC H1D_Write2File(int h2d,FILE *fp); |
int _VI_FUNC H1D_SetTitle(int h2d,char *title); |
int _VI_FUNC H1D_SetTitleX(int h2d,char *title); |
int _VI_FUNC H1D_SetTitleY(int h2d,char *title); |
int _VI_FUNC H1D_SetName(int h2d,char *title); |
char * _VI_FUNC H1D_GetTitleX(int h1d); |
char * _VI_FUNC H1D_GetTitleY(int h1d); |
char * _VI_FUNC H1D_GetTitle(int h1d); |
int _VI_FUNC H1D_GetNbinsX(int h); |
double _VI_FUNC H1D_GetMinX(int h); |
double _VI_FUNC H1D_GetMaxX(int h); |
double _VI_FUNC H1D_GetStepX(int h); |
double _VI_FUNC H1D_GetMin(int h); |
double _VI_FUNC H1D_GetMax(int h); |
double * _VI_FUNC H1D_GetData(int h); |
int _VI_FUNC H1D_Draw(int histogram,int panel, int control, int *plothandle) ; |
#endif /* _H1D_H_ */ |
/cvi/instr/HISTO/H2D.c |
---|
0,0 → 1,308 |
#ifdef _CVI_ |
# include <ansi_c.h> |
# else /* _CVI_ */ |
# include <stdlib.h> |
# include <stdio.h> |
# include <string.h> |
#endif /* _CVI_ */ |
#include "H2D.h" |
#define H2DMAX 500 |
H2D *h2[H2DMAX]; |
//int Printf(char *format, ...); |
int _VI_FUNC H2D_Clear(int h2d) { |
if (!h2[h2d]) return -1; |
memset(h2[h2d]->data, 0,h2[h2d]->size ); |
h2[h2d]->min=0; |
h2[h2d]->max=0; |
h2[h2d]->nentries=0; |
return 0; |
} |
int _VI_FUNC H2D_Print(int h2d) { |
if (!h2[h2d]) return -1; |
//Printf("PrintH2D nx=%d minx=%f stepx=%f ny=%d miny=%f stepy=%f size=%d\n", h2[h2d]->nx, h2[h2d]->minx, h2[h2d]->stepx, h2[h2d]->ny, h2[h2d]->miny, h2[h2d]->stepy, h2[h2d]->size ) ; |
return 0; |
} |
int _VI_FUNC H2D_Exist(int h) { |
if (h2[h]) return 1; |
else return 0; |
} |
int _VI_FUNC H2D_GetBin(int h2d,int x, int y) { |
return x+h2[h2d]->nx * y; |
} |
int _VI_FUNC H2D_CalculateBin(int h, int axis, double value) { |
int nx=0; |
double xmin=0,dx=0; |
int bin; |
switch (axis) { |
case 0: |
nx = H2D_GetNbinsX(h); |
xmin= H2D_GetMinX(h); |
dx = H2D_GetStepX(h); |
break; |
case 1: |
nx = H2D_GetNbinsY(h); |
xmin= H2D_GetMinY(h); |
dx = H2D_GetStepY(h); |
break; |
default: |
return -1; |
} |
if (dx<1e-10) return -1; |
if (value<xmin) return -1; |
bin = (int)((value-xmin)/dx); |
if (bin>=nx) return -1; |
else return bin; |
} |
int _VI_FUNC H2D_Fill(int h2d,double x, double y, double val) { |
int ix,iy; |
if (!h2[h2d]) return -1; |
ix = H2D_CalculateBin(h2d,0,x); |
if (ix<0) return ix; |
iy = H2D_CalculateBin(h2d,1,y); |
if (iy<0) return iy; |
return H2D_SetBinContent(h2d,ix, iy, val); |
} |
int _VI_FUNC H2D_SetBinContent(int h2d,int x, int y, double val) { |
int idx; |
if (!h2[h2d]) { |
//Printf("FillH2D_ error h2d is not initialized\n"); |
return -1; |
} |
idx = x+y*h2[h2d]->nx; |
h2[h2d]->data[idx]+=val; |
//Printf("%d %d data %f %f\n",x,y,val, h2[h2d]->data[idx]); |
if (h2[h2d]->data[idx]>h2[h2d]->max) h2[h2d]->max= h2[h2d]->data[idx]; |
if (h2[h2d]->data[idx]<h2[h2d]->min) h2[h2d]->min= h2[h2d]->data[idx]; |
h2[h2d]->nentries++; |
return 0; |
} |
double _VI_FUNC H2D_GetBinContent(int h2d,int atx,int aty) { |
int idx; |
if (!h2[h2d]) return 0; |
if (h2[h2d]->nx <= (unsigned int)atx) return 0; |
if (h2[h2d]->ny <= (unsigned int)aty) return 0; |
idx = atx+aty*h2[h2d]->nx; |
if (idx*sizeof(double) < h2[h2d]->size ) return h2[h2d]->data[idx]; |
return 0; |
} |
int _VI_FUNC H2D_Init(int h2d,const char *name,const char *title,int nx, double minx, double maxx, int ny, double miny, double maxy) { |
if (h2[h2d]) { |
free(h2[h2d]->data); |
free(h2[h2d]); |
h2[h2d] = NULL; |
} |
//printf("InitH2D_ hID=%d\n",h2d); |
h2[h2d] = (H2D *) malloc(sizeof(H2D)); |
//h2 =h2d; |
H2D_SetTitle(h2d,title); |
H2D_SetName(h2d,name); |
h2[h2d]->id=H2D_ID; |
h2[h2d]->nx = nx; |
h2[h2d]->ny = ny; |
h2[h2d]->minx = minx; |
h2[h2d]->miny = miny; |
h2[h2d]->stepx = (nx>1)?(maxx-minx)/(nx-1):0; |
h2[h2d]->stepy = (nx>1)?(maxy-miny)/(ny-1):0; |
h2[h2d]->size = h2[h2d]->nx*h2[h2d]->ny*sizeof(double); |
h2[h2d]->data = (double *) malloc(h2[h2d]->size); |
h2[h2d]->len=sizeof(H2D)-sizeof(double *)+h2[h2d]->size; |
H2D_Clear(h2d); |
H2D_Print(h2d); |
//Printf("InitH2D 0x%x\n", h2d ); |
return 0; |
} |
double _VI_FUNC H2D_GetXBinCenter(int h2d,int xbin) { |
return h2[h2d]->minx+xbin*h2[h2d]->stepx; |
} |
double _VI_FUNC H2D_GetYBinCenter(int h2d,int ybin) { |
return h2[h2d]->miny+ybin*h2[h2d]->stepy; |
} |
int _VI_FUNC H2D_Write2File(int h2d,FILE *fp) { |
if (!fp) return -1; |
//printf("H2D sizeof(H2D)=%lu len-datasize=%d len=%lu datasize=%d\t",sizeof(H2D)-sizeof(double *),h2[h2d]->len-h2[h2d]->size,h2[h2d]->len,h2[h2d]->size); |
//printf("H2D sz=%d %d\n",sizeof(double),sizeof(double *)); |
if (!H2D_Exist(h2d)){ |
printf("Histogram H2D=%d is not initialized\n",h2d); |
return -1; |
} |
fwrite (h2[h2d], 1, sizeof(H2D)-sizeof(double *), fp); |
fwrite (h2[h2d]->data, 1, h2[h2d]->size, fp); |
return 0; |
} |
int _VI_FUNC H2D_Write(int h2d,const char *fname,const char *opt) { |
FILE *fp=fopen(fname,opt); |
H2D_Write2File(h2d,fp); |
fclose(fp); |
return 0; |
} |
int _VI_FUNC H2D_SetTitle(int h2d,const char *title) { |
sprintf(h2[h2d]->title,"%s",title); |
return 0; |
} |
int _VI_FUNC H2D_SetTitleX(int h2d,const char *title) { |
sprintf(h2[h2d]->titlex,"%s",title); |
return 0; |
} |
int _VI_FUNC H2D_SetTitleY(int h2d,const char *title) { |
sprintf(h2[h2d]->titley,"%s",title); |
return 0; |
} |
int _VI_FUNC H2D_SetName(int h2d,const char *title) { |
sprintf(h2[h2d]->name,"%s",title); |
return 0; |
} |
int _VI_FUNC H2D_GetNbinsY(int h) { |
if (h2[h]) return h2[h]->ny; |
else return 0; |
} |
int _VI_FUNC H2D_GetNbinsX(int h) { |
if (h2[h]) return h2[h]->nx; |
else return 0; |
} |
double _VI_FUNC H2D_GetMinY(int h) { |
if (h2[h]) return h2[h]->miny; |
else return 0; |
} |
double _VI_FUNC H2D_GetMinX(int h) { |
if (h2[h]) return h2[h]->minx; |
else return 0; |
} |
double _VI_FUNC H2D_GetMaxX(int h){ |
return h2[h]->minx+(h2[h]->nx-1)*h2[h]->stepx; |
} |
double _VI_FUNC H2D_GetMaxY(int h){ |
return h2[h]->miny+(h2[h]->ny-1)*h2[h]->stepy; |
} |
double _VI_FUNC H2D_GetStepY(int h) { |
if (h2[h]) return h2[h]->stepy; |
else return 0; |
} |
double _VI_FUNC H2D_GetStepX(int h) { |
if (h2[h]) return h2[h]->stepx; |
else return 0; |
} |
double _VI_FUNC H2D_GetMin(int h) { |
if (h2[h]) return h2[h]->min; |
else return 0; |
} |
double _VI_FUNC H2D_GetMax(int h) { |
if (h2[h]) return h2[h]->max; |
else return 0; |
} |
double * _VI_FUNC H2D_GetData(int h) { |
if (h2[h]) return h2[h]->data; |
else return NULL; |
} |
#ifdef _CVI_ |
// defined only in CVI |
static HColorMap *colormap = NULL; |
HColorMap * _VI_FUNC H2D_GetColorMap(void) { |
return colormap; |
} |
int _VI_FUNC H2D_SetRangeColors( double min, double max) { |
int i; |
if (colormap == NULL) { |
colormap = malloc(sizeof(HColorMap)); |
colormap->numberofColors = 5; |
colormap->array = malloc(colormap->numberofColors*sizeof(ColorMapEntry)); |
colormap->array[0].color = 0x0000ff; //BLUE |
colormap->array[1].color = 0x00ff00; //GREEN |
colormap->array[2].color = 0xffff00; //YELLOW |
colormap->array[3].color = 0xff8000; //ORANGE |
colormap->array[4].color = 0xff0000; //RED |
colormap->HiColor =colormap->array[colormap->numberofColors-1].color ; |
} |
if (colormap->numberofColors<2) return -1; |
double fx = (max-min)/(colormap->numberofColors-1); |
for (i=0; i<colormap->numberofColors; i++) { |
colormap->array[i].dataValue.valDouble=i*fx+min; |
} |
return 0; |
} |
int _VI_FUNC H2D_Draw(int histogram,int panel, int control, int *plothandle) { |
if (!H2D_Exist(histogram)) { |
printf("2D Histogram %d does not exist!\n",histogram); |
return 0; |
} |
if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW); |
H2D_SetRangeColors(H2D_GetMin(histogram),H2D_GetMax(histogram)); |
*plothandle = PlotScaledIntensity (panel, control, |
H2D_GetData(histogram), |
H2D_GetNbinsX(histogram), |
H2D_GetNbinsY(histogram), |
VAL_DOUBLE, |
H2D_GetStepY(histogram), |
H2D_GetMinY(histogram), |
H2D_GetStepX(histogram), |
H2D_GetMinX(histogram), |
colormap->array, |
colormap->HiColor, |
colormap->numberofColors, 1, 0); |
RefreshGraph (panel, control); |
ProcessSystemEvents (); |
return *plothandle; |
} |
#endif |
/cvi/instr/HISTO/H2D.fp |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/cvi/instr/HISTO/H2D.h |
---|
0,0 → 1,97 |
#ifndef _H2D_H_ |
#define _H2D_H_ |
#ifdef _CVI_ |
#include <cvidef.h> |
#include <ivi.h> |
#include <userint.h> |
#include "toolbox.h" |
#ifndef _HCOLORMAP_ |
#define _HCOLORMAP_ |
typedef struct { |
ColorMapEntry *array; |
int numberofColors; |
int HiColor; |
} HColorMap; |
#endif |
HColorMap _VI_FUNC *H2D_GetColorMap(void); |
#else |
#define _VI_FUNC |
#endif |
#include <stdio.h> |
#ifdef __CINT__ |
#define HALIGN 41 |
#else |
#define HALIGN 40 |
#endif |
/* 2d histogramming */ |
#define H2D_ID 0x10 |
#pragma pack(4) |
typedef struct { |
unsigned int id,len; |
unsigned int nx; |
unsigned int ny; |
int nentries; |
unsigned int size; // 6*4 |
double min; |
double max; |
double minx; |
double miny; |
double stepx; |
double stepy; // 6*8 |
char name[20]; |
char title[100]; |
char titlex[40]; |
char titley[HALIGN]; // 196 |
double *data; |
} H2D; |
#pragma pack() |
double _VI_FUNC H2D_GetYBinCenter(int h2d,int ybin); |
double _VI_FUNC H2D_GetYBinCenter(int h2d,int xbin); |
int _VI_FUNC H2D_Clear(int h2d); |
int _VI_FUNC H2D_Print(int h2d); |
int _VI_FUNC H2D_Exist(int h2d); |
int _VI_FUNC H2D_CalculateBin(int h2d, int axis, double value); |
int _VI_FUNC H2D_GetBin(int h2d,int x, int y); |
int _VI_FUNC H2D_Fill(int h2d,double x, double y, double val); |
int _VI_FUNC H2D_SetBinContent(int h2d,int x, int y, double val); |
double _VI_FUNC H2D_GetBinContent(int h2d,int atx, int aty); |
int _VI_FUNC H2D_Init(int h2d,const char *name,const char *title,int nx, double minx, double maxx, int ny, double miny, double maxy); |
int _VI_FUNC H2D_Write(int h2d,const char *fname,const char*opt); |
int _VI_FUNC H2D_Write2File(int h2d,FILE *fp); |
int _VI_FUNC H2D_SetTitle(int h2d,const char *title); |
int _VI_FUNC H2D_SetTitleX(int h2d,const char *title); |
int _VI_FUNC H2D_SetTitleY(int h2d,const char *title); |
int _VI_FUNC H2D_SetName(int h2d,const char *title); |
int _VI_FUNC H2D_GetNbinsY(int h); |
int _VI_FUNC H2D_GetNbinsX(int h); |
double _VI_FUNC H2D_GetMinY(int h); |
double _VI_FUNC H2D_GetMinX(int h); |
double _VI_FUNC H2D_GetMaxX(int h); |
double _VI_FUNC H2D_GetMaxY(int h); |
double _VI_FUNC H2D_GetStepY(int h); |
double _VI_FUNC H2D_GetStepX(int h); |
double _VI_FUNC H2D_GetMin(int h); |
double _VI_FUNC H2D_GetMax(int h); |
double * _VI_FUNC H2D_GetData(int h); |
int _VI_FUNC H2D_SetRangeColors(double min, double max); |
int _VI_FUNC H2D_Draw(int histogram,int panel, int control, int *plothandle); |
#endif /* _H2D_H_ */ |
/cvi/instr/HISTO/H3D.c |
---|
0,0 → 1,423 |
#ifdef _CVI_ |
# include <ansi_c.h> |
# else _CVI_ |
# include <stdlib.h> |
# include <stdio.h> |
# include <string.h> |
#endif _CVI_ |
#include "H3D.h" |
#include "H2D.h" |
#include "H1D.h" |
#define H3DMAX 500 |
H3D *h3[H3DMAX]; |
//int Printf(char *format, ...); |
int _VI_FUNC H3D_Clear(int h3d) { |
if (!h3[h3d]) return -1; |
memset(h3[h3d]->data, 0,h3[h3d]->size ); |
h3[h3d]->min=0; |
h3[h3d]->max=0; |
h3[h3d]->nentries=0; |
return 0; |
} |
int _VI_FUNC H3D_Print(int h3d) { |
if (!h3[h3d]) return -1; |
//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 ) ; |
return 0; |
} |
int _VI_FUNC H3D_Exist(int h) { |
if (h3[h]) return 1; |
else return 0; |
} |
int _VI_FUNC H3D_CalculateBin(int h, int axis, double value) { |
int nx=1,xmin=0,dx=0; |
int bin; |
switch (axis) { |
case 0: |
nx = H3D_GetNbinsX(h); |
xmin= H3D_GetMinX(h); |
dx = H3D_GetStepX(h); |
break; |
case 1: |
nx = H3D_GetNbinsY(h); |
xmin= H3D_GetMinY(h); |
dx = H3D_GetStepY(h); |
break; |
case 2: |
nx = H3D_GetNbinsZ(h); |
xmin= H3D_GetMinZ(h); |
dx = H3D_GetStepZ(h); |
break; |
} |
if (dx==0) return -1; |
if (value<xmin) return -1; |
bin = (int)((value-xmin)/dx); |
if (bin>=nx) return -1; |
else return bin; |
} |
int _VI_FUNC H3D_Fill(int h3d,double x, double y, double z, double val) { |
int ix,iy, iz; |
if (!h3[h3d]) return -1; |
ix = H3D_CalculateBin(h3d,0,x); |
if (ix<0) return ix; |
iy = H3D_CalculateBin(h3d,1,y); |
if (iy<0) return iy; |
iz = H3D_CalculateBin(h3d,2,z); |
if (iz<0) return iz; |
H3D_FillBin(h3d, ix, iy, iz, val); |
return 0; |
} |
int _VI_FUNC H3D_GetBin(int h3d,int x, int y, int z) { |
return x+h3[h3d]->nx *(y+z*h3[h3d]->ny); |
} |
int _VI_FUNC H3D_FillBin(int h3d,int x, int y, int z, double val) { |
int idx; |
if (!h3[h3d]) { |
//Printf("FillH3D error h3d is not initialized\n"); |
return -1; |
} |
idx = H3D_GetBin(h3d,x,y,z); |
h3[h3d]->data[idx]+=val; |
//Printf("%d %d data %f %f\n",x,y,val, h3[h3d]->data[idx]); |
if (h3[h3d]->data[idx]>h3[h3d]->max) h3[h3d]->max= h3[h3d]->data[idx]; |
if (h3[h3d]->data[idx]<h3[h3d]->min) h3[h3d]->min= h3[h3d]->data[idx]; |
h3[h3d]->nentries++; |
return 0; |
} |
double _VI_FUNC H3D_GetBinContent(int h3d,int atx, int aty, int atz) { |
int idx; |
if (!h3[h3d]) return 0; |
if (h3[h3d]->nx <= atx) return 0; |
if (h3[h3d]->ny <= aty) return 0; |
if (h3[h3d]->nz <= atz) return 0; |
idx = H3D_GetBin(h3d,atx,aty,atz); |
if (idx*sizeof(double) < h3[h3d]->size ) return h3[h3d]->data[idx]; |
return 0; |
} |
int _VI_FUNC H3D_Init(int h3d,char *name, char *title, |
int nx, double minx, double maxx, |
int ny, double miny, double maxy, |
int nz, double minz, double maxz) { |
if (h3[h3d]) { |
free(h3[h3d]->data); |
free(h3[h3d]); |
h3[h3d] = NULL; |
} |
//printf("InitH3D hID=%d\n",h3d); |
h3[h3d] = (H3D *) malloc(sizeof(H3D)); |
//h2 =h3d; |
H3D_SetTitle(h3d,title); |
H3D_SetName(h3d,name); |
h3[h3d]->id=H3D_ID; |
h3[h3d]->nx = nx; |
h3[h3d]->ny = ny; |
h3[h3d]->nz = nz; |
h3[h3d]->minx = minx; |
h3[h3d]->miny = miny; |
h3[h3d]->minz = minz; |
h3[h3d]->stepx = (nx>1)?(maxx-minx)/(nx-1):0; |
h3[h3d]->stepy = (nx>1)?(maxy-miny)/(ny-1):0; |
h3[h3d]->stepz = (nx>1)?(maxz-minz)/(nz-1):0; |
h3[h3d]->size = h3[h3d]->nx*h3[h3d]->ny*h3[h3d]->nz*sizeof(double); |
h3[h3d]->data = (double *) malloc(h3[h3d]->size); |
h3[h3d]->len=sizeof(H3D)-sizeof(double *)+h3[h3d]->size; |
H3D_Clear(h3d); |
H3D_Print(h3d); |
//Printf("InitH3D 0x%x\n", h3d ); |
return 0; |
} |
int _VI_FUNC H3D_SliXY(int histogram,int slice, int direction) { |
if (!H3D_Exist(histogram)) { |
printf("3D Histogram %d does not exist!\n",histogram); |
return -1; |
} |
int hid=499; |
switch (direction){ |
case 0:// xy |
H2D_Init(hid,"projectionXY","projectionXY", |
H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram), |
H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram) |
); |
for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) |
for (int j=0; j < H3D_GetNbinsY(histogram); j++ ) |
H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,j,slice)); |
break; |
case 1:// xz |
H2D_Init(hid,"projectionXZ","projectionXZ", |
H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram), |
H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram) |
); |
for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) |
for (int j=0; j < H3D_GetNbinsZ(histogram); j++ ) |
H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,slice,j)); |
break; |
case 2:// yz |
default: |
H2D_Init(hid,"projectionYZ","projectionYZ", |
H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram), |
H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram) |
); |
for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) |
for (int j=0; j < H3D_GetNbinsZ(histogram); j++ ) |
H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,slice,i,j)); |
break; |
} |
return hid; |
} |
double _VI_FUNC H3D_GetMaxX(int h){ |
return h3[h]->minx+(h3[h]->nx-1)*h3[h]->stepx; |
} |
double _VI_FUNC H3D_GetMaxY(int h){ |
return h3[h]->miny+(h3[h]->ny-1)*h3[h]->stepy; |
} |
double _VI_FUNC H3D_GetMaxZ(int h){ |
return h3[h]->minz+(h3[h]->nz-1)*h3[h]->stepz; |
} |
double _VI_FUNC H3D_GetXBinCenter(int h3d,int xbin) { |
return h3[h3d]->minx+xbin*h3[h3d]->stepx; |
} |
double _VI_FUNC H3D_GetYBinCenter(int h3d,int ybin) { |
return h3[h3d]->miny+ybin*h3[h3d]->stepy; |
} |
double _VI_FUNC H3D_GetZBinCenter(int h3d,int zbin) { |
return h3[h3d]->minz+zbin*h3[h3d]->stepz; |
} |
int _VI_FUNC H3D_Write2File(int h3d,FILE *fp) { |
if (!fp) return -1; |
//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); |
//printf("H3D sz=%d %d\n",sizeof(double),sizeof(double *)); |
fwrite (h3[h3d], 1, sizeof(H3D)-sizeof(double *), fp); |
fwrite (h3[h3d]->data, 1, h3[h3d]->size, fp); |
return 0; |
} |
int _VI_FUNC H3D_Write(int h3d,const char *fname,const char *opt) { |
FILE *fp=fopen(fname,opt); |
H3D_Write2File(h3d,fp); |
fclose(fp); |
return 0; |
} |
int _VI_FUNC H3D_SetTitle(int h3d,char *title) { |
sprintf(h3[h3d]->title,"%s",title); |
return 0; |
} |
int _VI_FUNC H3D_SetTitleX(int h3d,char *title) { |
sprintf(h3[h3d]->titlex,"%s",title); |
return 0; |
} |
int _VI_FUNC H3D_SetTitleY(int h3d,char *title) { |
sprintf(h3[h3d]->titley,"%s",title); |
return 0; |
} |
int _VI_FUNC H3D_SetTitleZ(int h3d,char *title) { |
sprintf(h3[h3d]->titlez,"%s",title); |
return 0; |
} |
int _VI_FUNC H3D_SetName(int h3d,char *title) { |
sprintf(h3[h3d]->name,"%s",title); |
return 0; |
} |
int _VI_FUNC H3D_GetNbinsY(int h) { |
if (h3[h]) return h3[h]->ny; |
else return 0; |
} |
int _VI_FUNC H3D_GetNbinsX(int h) { |
if (h3[h]) return h3[h]->nx; |
else return 0; |
} |
int _VI_FUNC H3D_GetNbinsZ(int h) { |
if (h3[h]) return h3[h]->nz; |
else return 0; |
} |
double _VI_FUNC H3D_GetMinX(int h) { |
if (h3[h]) return h3[h]->minx; |
else return 0; |
} |
double _VI_FUNC H3D_GetMinY(int h) { |
if (h3[h]) return h3[h]->miny; |
else return 0; |
} |
double _VI_FUNC H3D_GetMinZ(int h) { |
if (h3[h]) return h3[h]->minz; |
else return 0; |
} |
double _VI_FUNC H3D_GetStepX(int h) { |
if (h3[h]) return h3[h]->stepx; |
else return 0; |
} |
double _VI_FUNC H3D_GetStepY(int h) { |
if (h3[h]) return h3[h]->stepy; |
else return 0; |
} |
double _VI_FUNC H3D_GetStepZ(int h) { |
if (h3[h]) return h3[h]->stepz; |
else return 0; |
} |
double _VI_FUNC H3D_GetMin(int h) { |
if (h3[h]) return h3[h]->min; |
else return 0; |
} |
double _VI_FUNC H3D_GetMax(int h) { |
if (h3[h]) return h3[h]->max; |
else return 0; |
} |
double * _VI_FUNC H3D_GetSliceXYData(int h, int slice) { |
if (h3[h]) return (h3[h]->data+slice*h3[h]->nx*h3[h]->ny); |
else return NULL; |
} |
double * _VI_FUNC H3D_GetData(int h) { |
if (h3[h]) return h3[h]->data; |
else return NULL; |
} |
#ifdef _CVI_ |
// defined only in CVI |
static HColorMap *colormap = NULL; |
HColorMap * _VI_FUNC H3D_GetColorMap(void) { |
return colormap; |
} |
int _VI_FUNC H3D_SetRangeColors( double min, double max) { |
int i; |
if (colormap == NULL) { |
colormap = malloc(sizeof(HColorMap)); |
colormap->numberofColors = 5; |
colormap->array = malloc(colormap->numberofColors*sizeof(ColorMapEntry)); |
colormap->array[0].color = 0x0000ff; //BLUE |
colormap->array[1].color = 0x00ff00; //GREEN |
colormap->array[2].color = 0xffff00; //YELLOW |
colormap->array[3].color = 0xff8000; //ORANGE |
colormap->array[4].color = 0xff0000; //RED |
colormap->HiColor =colormap->array[colormap->numberofColors-1].color ; |
} |
if (colormap->numberofColors<2) return -1; |
double fx = (max-min)/(colormap->numberofColors-1); |
for (i=0; i<colormap->numberofColors; i++) { |
colormap->array[i].dataValue.valDouble=i*fx+min; |
} |
return 0; |
} |
int _VI_FUNC H3D_DrawSliceXY(int histogram,int slice,int direction, int panel, int control, int *plothandle) { |
if (H3D_GetNbinsY(histogram)==1|| H3D_GetNbinsX(histogram)==1) { |
if (H3D_GetNbinsY(histogram)==1) { |
H1D_Init(499,"projection","projection", H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetStepX(histogram)); |
for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,i,0,slice)); |
} else { |
H1D_Init(499,"projection","projection", H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetStepY(histogram)); |
for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,0,i,slice)); |
} |
H1D_Draw(499, panel, control, plothandle); |
} else { |
if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW); |
H3D_SetRangeColors(H3D_GetMin(histogram),H3D_GetMax(histogram)); |
*plothandle = PlotScaledIntensity (panel, control, |
H3D_GetSliceXYData(histogram, slice), |
H3D_GetNbinsX(histogram), |
H3D_GetNbinsY(histogram), |
VAL_DOUBLE, |
H3D_GetStepY(histogram), |
H3D_GetMinY(histogram), |
H3D_GetStepX(histogram), |
H3D_GetMinX(histogram), |
colormap->array, |
colormap->HiColor, |
colormap->numberofColors, 1, 0); |
} |
ProcessSystemEvents (); |
return *plothandle; |
} |
#endif |
/cvi/instr/HISTO/H3D.fp |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/cvi/instr/HISTO/H3D.h |
---|
0,0 → 1,98 |
#ifndef _H3D_H_ |
#define _H3D_H_ |
#ifdef _CVI_ |
#include <cvidef.h> |
#include <ivi.h> |
#include "toolbox.h" |
#ifndef _HCOLORMAP_ |
#define _HCOLORMAP_ |
typedef struct { |
ColorMapEntry *array; |
int numberofColors; |
int HiColor; |
} HColorMap; |
#endif |
HColorMap * _VI_FUNC H3D_GetColorMap(void); |
#else |
#define _VI_FUNC |
#endif |
#include <stdio.h> |
/* 2d histogramming */ |
#define H3D_ID 0x12 |
#pragma pack(4) |
typedef struct |
{ |
unsigned int id,len; |
unsigned int nx; |
unsigned int ny; |
unsigned int nz; |
int nentries; |
unsigned int size; |
double min; |
double max; |
double minx; |
double miny; |
double minz; |
double stepx; |
double stepy; |
double stepz; |
char name[20]; |
char title[100]; |
char titlex[40]; |
char titley[40]; |
char titlez[40]; |
double *data; |
}H3D; |
#pragma pack() |
int _VI_FUNC H3D_SliXY(int histogram,int slice, int direction); |
double _VI_FUNC H3D_GetYBinCenter(int h3d,int ybin); |
double _VI_FUNC H3D_GetYBinCenter(int h3d,int xbin); |
int _VI_FUNC H3D_Clear(int h3d); |
int _VI_FUNC H3D_Print(int h3d); |
int _VI_FUNC H3D_Exist(int h3d); |
int _VI_FUNC H3D_CalculateBin(int h3d, int axis, double value); |
int _VI_FUNC H3D_GetBin(int h3d,int x, int y, int z); |
int _VI_FUNC H3D_Fill(int h3d,double x, double y, double z, double val); |
int _VI_FUNC H3D_FillBin(int h3d,int x, int y, int z, double val); |
double _VI_FUNC H3D_GetBinContent(int h3d,int atx, int aty, int atz); |
int _VI_FUNC H3D_Init(int h3d,char *name, char *title,int nx, double minx, double maxx, int ny, double miny, double maxy,int nz, double minz, double maxz); |
int _VI_FUNC H3D_Write(int h3d,const char *fname,const char*opt); |
int _VI_FUNC H3D_Write2File(int h3d,FILE *fp); |
int _VI_FUNC H3D_SetTitle(int h3d,char *title); |
int _VI_FUNC H3D_SetTitleX(int h3d,char *title); |
int _VI_FUNC H3D_SetTitleY(int h3d,char *title); |
int _VI_FUNC H3D_SetTitleZ(int h3d,char *title); |
int _VI_FUNC H3D_SetName(int h3d,char *title); |
int _VI_FUNC H3D_GetNbinsY(int h); |
int _VI_FUNC H3D_GetNbinsX(int h); |
int _VI_FUNC H3D_GetNbinsZ(int h); |
double _VI_FUNC H3D_GetMaxX(int h); |
double _VI_FUNC H3D_GetMaxY(int h); |
double _VI_FUNC H3D_GetMaxZ(int h); |
double _VI_FUNC H3D_GetMinX(int h); |
double _VI_FUNC H3D_GetMinY(int h); |
double _VI_FUNC H3D_GetMinZ(int h); |
double _VI_FUNC H3D_GetStepX(int h); |
double _VI_FUNC H3D_GetStepY(int h); |
double _VI_FUNC H3D_GetStepZ(int h); |
double _VI_FUNC H3D_GetMin(int h); |
double _VI_FUNC H3D_GetMax(int h); |
double * _VI_FUNC H3D_GetSliceXYData(int h, int slice); |
double * _VI_FUNC H3D_GetData(int h); |
#endif |