JunkBox_Lib  1.10.2
gdata.c
Go to the documentation of this file.
1 
10 #include "gdata.h"
11 #include "jbxl_state.h"
12 
13 
14 int ZeroBase = 0;
15 double RZxy = 1.0; // 3D 画像での x,y 対 z方向比 (z方向のピクセル間隔)/(x,y方向のピクセル間隔)
16 int ChkRZxy = OFF; // RZxy が設定されているなら ON, 設定されていないなら OFF
17 
18 
28 {
29  if (hd!=NULL) {
30  if (hd->buf!=NULL) free(hd->buf);
31  if (hd->grptr!=NULL) free(hd->grptr);
32  init_CmnHead(hd);
33  }
34 }
35 
36 
45 {
46  if (hd!=NULL) {
47  memset(hd, 0, sizeof(CmnHead));
48  hd->kind = HEADER_NONE;
49  }
50 }
51 
52 
66 BSGraph make_BSGraph(int xs, int ys, int zs)
67 {
68  int i;
69  BSGraph vp;
70 
71  memset(&vp, 0, sizeof(BSGraph));
72  if (xs==0 || ys==0) {
74  return vp;
75  }
76 
77  vp.xs = xs;
78  vp.ys = ys;
79  if (zs>0) vp.zs = zs;
80  else vp.zs = 1;
81  vp.state = JBXL_NORMAL;
82 
83  vp.gp = (uByte*)malloc(vp.xs*vp.ys*vp.zs*sizeof(uByte));
84  if (vp.gp==NULL) {
85  memset(&vp, 0, sizeof(BSGraph));
87  return vp;
88  }
89  for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0;
90 
91  return vp;
92 }
93 
94 
108 WSGraph make_WSGraph(int xs, int ys, int zs)
109 {
110  int i;
111  WSGraph vp;
112 
113  memset(&vp, 0, sizeof(WSGraph));
114  if (xs==0 || ys==0) {
116  return vp;
117  }
118 
119  vp.xs = xs;
120  vp.ys = ys;
121  if (zs>0) vp.zs = zs;
122  else vp.zs = 1;
123  vp.state = JBXL_NORMAL;
124 
125  vp.gp = (sWord*)malloc(vp.xs*vp.ys*vp.zs*sizeof(sWord));
126  if (vp.gp==NULL) {
127  memset(&vp, 0, sizeof(WSGraph));
129  return vp;
130  }
131  for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0;
132 
133  return vp;
134 }
135 
136 
150 FSGraph make_FSGraph(int xs, int ys, int zs)
151 {
152  int i;
153  FSGraph vp;
154 
155  memset(&vp, 0, sizeof(FSGraph));
156  if (xs==0 || ys==0) {
158  return vp;
159  }
160 
161  vp.xs = xs;
162  vp.ys = ys;
163  if (zs>0) vp.zs = zs;
164  else vp.zs = 1;
165  vp.state = JBXL_NORMAL;
166 
167  vp.gp = (double*)malloc(vp.xs*vp.ys*vp.zs*sizeof(double));
168  if (vp.gp==NULL) {
169  memset(&vp, 0, sizeof(FSGraph));
171  return vp;
172  }
173  for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0.0;
174 
175  return vp;
176 }
177 
178 
192 ISGraph make_ISGraph(int xs, int ys, int zs)
193 {
194  int i;
195  ISGraph vp;
196 
197  memset(&vp, 0, sizeof(ISGraph));
198  if (xs==0 || ys==0) {
200  return vp;
201  }
202 
203  vp.xs = xs;
204  vp.ys = ys;
205  if (zs>0) vp.zs = zs;
206  else vp.zs = 1;
207  vp.state = JBXL_NORMAL;
208 
209  vp.gp = (int*)malloc(vp.xs*vp.ys*vp.zs*sizeof(int));
210  if (vp.gp==NULL) {
211  memset(&vp, 0, sizeof(ISGraph));
213  return vp;
214  }
215  for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0;
216 
217  return vp;
218 }
219 
220 
234 VSGraph make_VSGraph(int xs, int ys, int zs)
235 {
236  int i;
237  VSGraph vp;
238 
239  memset(&vp, 0, sizeof(VSGraph));
240  if (xs==0 || ys==0) {
242  return vp;
243  }
244 
245  vp.xs = xs;
246  vp.ys = ys;
247  if (zs>0) vp.zs = zs;
248  else vp.zs = 1;
249  vp.state = JBXL_NORMAL;
250 
251  vp.gp = (vector*)malloc(xs*ys*zs*sizeof(vector));
252  if (vp.gp==NULL) {
253  memset(&vp, 0, sizeof(VSGraph));
255  return vp;
256  }
257  for (i=0; i<xs*ys*zs; i++) vp.gp[i] = set_vector(0.0, 0.0, 0.0);
258 
259  return vp;
260 }
261 
262 
277 MSGraph make_MSGraph(int xs, int ys, int zs, int depth)
278 {
279  MSGraph vp;
280 
281  memset(&vp, 0, sizeof(MSGraph));
282  if (xs==0 || ys==0) {
284  return vp;
285  }
286 
287  vp.xs = xs;
288  vp.ys = ys;
289  if (zs>0) vp.zs = zs;
290  else vp.zs = 1;
291  if (depth>0) vp.depth = depth;
292  else vp.depth = 1;
293  vp.state = JBXL_NORMAL;
294 
295  vp.gp = (unsigned char*)malloc(xs*ys*zs*((depth+7)/8));
296  if (vp.gp==NULL) {
297  memset(&vp, 0, sizeof(MSGraph));
299  return vp;
300  }
301  memset(vp.gp, 0, xs*ys*zs*((depth+7)/8));
302  return vp;
303 }
304 
305 
319 BSGraph* new_BSGraph(int xs, int ys, int zs)
320 {
321  int i;
322  BSGraph* vp;
323 
324  vp = (BSGraph*)malloc(sizeof(BSGraph));
325  if (vp==NULL) return NULL;
326  memset(vp, 0, sizeof(BSGraph));
327 
328  if (xs==0 || ys==0) {
330  return vp;
331  }
332 
333  vp->xs = xs;
334  vp->ys = ys;
335  if (zs>0) vp->zs = zs;
336  else vp->zs = 1;
337  vp->state = JBXL_NORMAL;
338 
339  vp->gp = (uByte*)malloc(vp->xs*vp->ys*vp->zs*sizeof(uByte));
340  if (vp->gp==NULL) {
341  memset(vp, 0, sizeof(BSGraph));
343  return vp;
344  }
345  for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0;
346 
347  return vp;
348 }
349 
350 
364 WSGraph* new_WSGraph(int xs, int ys, int zs)
365 {
366  int i;
367  WSGraph* vp;
368 
369  vp = (WSGraph*)malloc(sizeof(WSGraph));
370  if (vp==NULL) return NULL;
371  memset(vp, 0, sizeof(WSGraph));
372 
373  if (xs==0 || ys==0) {
375  return vp;
376  }
377 
378  vp->xs = xs;
379  vp->ys = ys;
380  if (zs>0) vp->zs = zs;
381  else vp->zs = 1;
382  vp->state = JBXL_NORMAL;
383 
384  vp->gp = (sWord*)malloc(vp->xs*vp->ys*vp->zs*sizeof(sWord));
385  if (vp->gp==NULL) {
386  memset(vp, 0, sizeof(WSGraph));
388  return vp;
389  }
390  for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0;
391 
392  return vp;
393 }
394 
395 
409 FSGraph* new_FSGraph(int xs, int ys, int zs)
410 {
411  int i;
412  FSGraph* vp;
413 
414  vp = (FSGraph*)malloc(sizeof(FSGraph));
415  if (vp==NULL) return NULL;
416  memset(vp, 0, sizeof(FSGraph));
417 
418  if (xs==0 || ys==0) {
420  return vp;
421  }
422 
423  vp->xs = xs;
424  vp->ys = ys;
425  if (zs>0) vp->zs = zs;
426  else vp->zs = 1;
427  vp->state = JBXL_NORMAL;
428 
429  vp->gp = (double*)malloc(vp->xs*vp->ys*vp->zs*sizeof(double));
430  if (vp->gp==NULL) {
431  memset(vp, 0, sizeof(FSGraph));
433  return vp;
434  }
435  for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0.0;
436 
437  return vp;
438 }
439 
440 
454 ISGraph* new_ISGraph(int xs, int ys, int zs)
455 {
456  int i;
457  ISGraph* vp;
458 
459  vp = (ISGraph*)malloc(sizeof(ISGraph));
460  if (vp==NULL) return NULL;
461  memset(vp, 0, sizeof(ISGraph));
462 
463  if (xs==0 || ys==0) {
465  return vp;
466  }
467 
468  vp->xs = xs;
469  vp->ys = ys;
470  if (zs>0) vp->zs = zs;
471  else vp->zs = 1;
472  vp->state = JBXL_NORMAL;
473 
474  vp->gp = (int*)malloc(vp->xs*vp->ys*vp->zs*sizeof(int));
475  if (vp->gp==NULL) {
476  memset(vp, 0, sizeof(ISGraph));
478  return vp;
479  }
480  for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0;
481 
482  return vp;
483 }
484 
485 
499 VSGraph* new_VSGraph(int xs, int ys, int zs)
500 {
501  int i;
502  VSGraph* vp;
503 
504  vp = (VSGraph*)malloc(sizeof(VSGraph));
505  if (vp==NULL) return NULL;
506  memset(vp, 0, sizeof(VSGraph));
507 
508  if (xs==0 || ys==0) {
510  return vp;
511  }
512 
513  vp->xs = xs;
514  vp->ys = ys;
515  if (zs>0) vp->zs = zs;
516  else vp->zs = 1;
517  vp->state = JBXL_NORMAL;
518 
519  vp->gp = (vector*)malloc(vp->xs*vp->ys*vp->zs*sizeof(vector));
520  if (vp->gp==NULL) {
521  memset(vp, 0, sizeof(VSGraph));
523  return vp;
524  }
525  for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = set_vector(0.0, 0.0, 0.0);
526 
527  return vp;
528 }
529 
530 
545 MSGraph* new_MSGraph(int xs, int ys, int zs, int depth)
546 {
547  MSGraph* vp;
548 
549  vp = (MSGraph*)malloc(sizeof(MSGraph));
550  if (vp==NULL) return NULL;
551  memset(vp, 0, sizeof(MSGraph));
552 
553  if (xs==0 || ys==0) {
555  return vp;
556  }
557 
558  vp->xs = xs;
559  vp->ys = ys;
560  if (zs>0) vp->zs = zs;
561  else vp->zs = 1;
562  if (depth>0) vp->depth = depth;
563  else vp->depth = 1;
564  vp->state = JBXL_NORMAL;
565 
566  vp->gp = (unsigned char*)malloc(vp->xs*vp->ys*vp->zs*((depth+7)/8));
567  if (vp->gp==NULL) {
568  memset(vp, 0, sizeof(MSGraph));
570  return vp;
571  }
572  memset(vp->gp, 0, vp->xs*vp->ys*vp->zs*((depth+7)/8));
573 
574  return vp;
575 }
576 
577 
588 {
589  int i;
590  ISGraph ix;
591 
592  ix.xs = vp.xs;
593  ix.ys = vp.ys;
594  ix.zs = vp.zs;
595  ix.state = vp.state;
596 
597  ix.gp = (int*)malloc(ix.xs*ix.ys*ix.zs*sizeof(int));
598  if (ix.gp==NULL) {
599  memset(&ix, 0, sizeof(ISGraph));
601  return ix;
602  }
603  for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (int)vp.gp[i];
604 
605  return ix;
606 }
607 
608 
619 {
620  int i;
621  FSGraph ix;
622 
623  ix.xs = vp.xs;
624  ix.ys = vp.ys;
625  ix.zs = vp.zs;
626  ix.state = vp.state;
627 
628  ix.gp = (double*)malloc(ix.xs*ix.ys*ix.zs*sizeof(double));
629  if (ix.gp==NULL) {
630  memset(&ix, 0, sizeof(FSGraph));
632  return ix;
633  }
634  for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i]=(double)vp.gp[i];
635 
636  return ix;
637 }
638 
639 
650 {
651  int i;
652  WSGraph ix;
653 
654  ix.xs = vp.xs;
655  ix.ys = vp.ys;
656  ix.zs = vp.zs;
657  ix.state = vp.state;
658 
659  ix.gp = (sWord*)malloc(ix.xs*ix.ys*ix.zs*sizeof(sWord));
660  if (ix.gp==NULL) {
661  memset(&ix, 0, sizeof(WSGraph));
663  return ix;
664  }
665  for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i];
666 
667  return ix;
668 }
669 
670 
681 {
682  int i;
683  WSGraph ix;
684 
685  ix.xs = vp.xs;
686  ix.ys = vp.ys;
687  ix.zs = vp.zs;
688  ix.state = vp.state;
689 
690  ix.gp = (sWord*)malloc(ix.xs*ix.ys*ix.zs*sizeof(sWord));
691  if (ix.gp==NULL) {
692  memset(&ix, 0, sizeof(WSGraph));
694  return ix;
695  }
696  for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i];
697 
698  return ix;
699 }
700 
701 
712 {
713  int i;
714  WSGraph ix;
715 
716  ix.xs = vp.xs;
717  ix.ys = vp.ys;
718  ix.zs = vp.zs;
719  ix.state = vp.state;
720 
721  ix.gp = (sWord*)malloc(ix.xs*ix.ys*ix.zs*sizeof(sWord));
722  if (ix.gp==NULL) {
723  memset(&ix, 0, sizeof(WSGraph));
725  return ix;
726  }
727  for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i];
728 
729  return ix;
730 }
731 
732 
743 {
744  int i;
745  FSGraph ix;
746 
747  ix = make_FSGraph(vp.xs, vp.ys, vp.zs);
748  if (ix.gp==NULL) return ix;
749 
750  for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = vp.gp[i].n;
751  ix.state = vp.state;
752 
753  return ix;
754 }
755 
756 
766 {
767  int i;
768  WSGraph ix;
769 
770  ix = make_WSGraph(vp.xs, vp.ys, vp.zs);
771  if (ix.gp==NULL) return ix;
772 
773  for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i].n;
774  ix.state = vp.state;
775 
776  return ix;
777 }
778 
779 
788 {
789  rb->xmax = rb->ymax = rb->zmax = 0;
790  rb->xmin = rb->ymin = rb->zmin = SINTMAX;
791  rb->misc = OFF;
792 }
793 
794 
803 {
804  rb->xmax = rb->ymax = rb->zmax = 0.0;
805  rb->xmin = rb->ymin = rb->zmin = DBL_MAX;
806  rb->misc = OFF;
807 }
808 
809 
818 void set_RZxy(double rzm)
819 {
820  ChkRZxy = ON;
821  RZxy = rzm;
822  //fprintf(stderr,"set_RZxy: set RZxy to %f\n", rzm);
823 }
824 
825 
832 int chk_RZxy(void)
833 {
834  if (ChkRZxy==OFF) {
835  DEBUG_MODE PRINT_MESG("CHK_RZXY: WARNING: undefined RZxy!!!\n");
836  //exit(1);
837  return FALSE;
838  }
839  return TRUE;
840 }
841 
#define OFF
Definition: common.h:231
short sWord
2Byte
Definition: common.h:335
#define SINTMAX
Definition: common.h:204
#define TRUE
Definition: common.h:226
#define FALSE
Definition: common.h:223
unsigned char uByte
1Byte
Definition: common.h:332
#define ON
Definition: common.h:230
FSGraph V2FSGraph(VSGraph vp)
Definition: gdata.c:742
BSGraph make_BSGraph(int xs, int ys, int zs)
Definition: gdata.c:66
FSGraph * new_FSGraph(int xs, int ys, int zs)
Definition: gdata.c:409
WSGraph I2WSGraph(ISGraph vp)
Definition: gdata.c:680
MSGraph make_MSGraph(int xs, int ys, int zs, int depth)
Definition: gdata.c:277
WSGraph make_WSGraph(int xs, int ys, int zs)
Definition: gdata.c:108
FSGraph W2FSGraph(WSGraph vp)
Definition: gdata.c:618
ISGraph * new_ISGraph(int xs, int ys, int zs)
Definition: gdata.c:454
int ChkRZxy
Definition: gdata.c:16
void set_RZxy(double rzm)
Definition: gdata.c:818
VSGraph * new_VSGraph(int xs, int ys, int zs)
Definition: gdata.c:499
MSGraph * new_MSGraph(int xs, int ys, int zs, int depth)
Definition: gdata.c:545
void init_CmnHead(CmnHead *hd)
Definition: gdata.c:44
void free_CmnHead(CmnHead *hd)
Definition: gdata.c:27
VSGraph make_VSGraph(int xs, int ys, int zs)
Definition: gdata.c:234
BSGraph * new_BSGraph(int xs, int ys, int zs)
Definition: gdata.c:319
FSGraph make_FSGraph(int xs, int ys, int zs)
Definition: gdata.c:150
ISGraph make_ISGraph(int xs, int ys, int zs)
Definition: gdata.c:192
WSGraph * new_WSGraph(int xs, int ys, int zs)
Definition: gdata.c:364
double RZxy
Definition: gdata.c:15
void init_DRBound(DRBound *rb)
Definition: gdata.c:802
int chk_RZxy(void)
Definition: gdata.c:832
WSGraph F2WSGraph(FSGraph vp)
Definition: gdata.c:711
WSGraph V2WSGraph(VSGraph vp)
Definition: gdata.c:765
ISGraph W2ISGraph(WSGraph vp)
Definition: gdata.c:587
WSGraph B2WSGraph(BSGraph vp)
Definition: gdata.c:649
void init_IRBound(IRBound *rb)
Definition: gdata.c:787
int ZeroBase
Definition: gdata.c:14
グラフィックデータ定義用ヘッダ
#define HEADER_NONE
0x8000 // ヘッダ種別の指定なし
Definition: gheader.h:212
JunkBox_Lib 状態ヘッダ
#define JBXL_GRAPH_IVDARG_ERROR
無効な引数
Definition: jbxl_state.h:178
#define JBXL_NORMAL
正常
Definition: jbxl_state.h:32
#define JBXL_GRAPH_MEMORY_ERROR
メモリエラー
Definition: jbxl_state.h:170
vector set_vector(double x, double y, double z)
Definition: matrix.c:82
Definition: gdata.h:27
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition: gdata.h:30
int xs
xサイズ. 4Byte.
Definition: gdata.h:28
int state
状態
Definition: gdata.h:31
uByte * gp
グラフィックデータへのポインタ. xs*ys*zs*1Byte.
Definition: gdata.h:32
int ys
yサイズ. 4Byte.
Definition: gdata.h:29
uByte * buf
Ture Header buffer
Definition: gheader.h:137
int kind
Kind of Graphics Format.
Definition: gheader.h:127
uByte * grptr
Pointer to Data.
Definition: gheader.h:138
Definition: gdata.h:124
double xmax
Definition: gdata.h:126
int misc
Definition: gdata.h:131
double ymin
Definition: gdata.h:127
double zmin
Definition: gdata.h:129
double xmin
Definition: gdata.h:125
double zmax
Definition: gdata.h:130
double ymax
Definition: gdata.h:128
Definition: gdata.h:70
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition: gdata.h:73
int xs
xサイズ. 4Byte.
Definition: gdata.h:71
int state
状態
Definition: gdata.h:74
double * gp
グラフィックデータへのポインタ. xs*ys*zs*sizeof(double)
Definition: gdata.h:75
int ys
yサイズ. 4Byte.
Definition: gdata.h:72
Definition: gdata.h:113
int xmax
x軸境界の最大値.
Definition: gdata.h:115
int misc
多目的用.
Definition: gdata.h:120
int ymax
y軸境界の最大値.
Definition: gdata.h:117
int xmin
x軸境界の最小値.
Definition: gdata.h:114
int ymin
y軸境界の最小値.
Definition: gdata.h:116
int zmax
z軸境界の最大値.
Definition: gdata.h:119
int zmin
z軸境界の最小値.
Definition: gdata.h:118
Definition: gdata.h:56
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition: gdata.h:59
int xs
xサイズ. 4Byte.
Definition: gdata.h:57
int state
状態
Definition: gdata.h:60
int ys
yサイズ. 4Byte.
Definition: gdata.h:58
int * gp
グラフィックデータへのポインタ. xs*ys*zs*4Byte
Definition: gdata.h:61
Definition: gdata.h:98
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition: gdata.h:101
int xs
xサイズ. 4Byte.
Definition: gdata.h:99
int state
状態
Definition: gdata.h:103
unsigned char * gp
グラフィックデータへのポインタ. xs*ys*zs*depth.
Definition: gdata.h:104
int depth
Color Depth.
Definition: gdata.h:102
int ys
yサイズ. 4Byte.
Definition: gdata.h:100
Definition: gdata.h:84
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition: gdata.h:87
int xs
xサイズ. 4Byte.
Definition: gdata.h:85
int state
状態
Definition: gdata.h:88
vector * gp
グラフィックデータへのポインタ. xs*ys*zs*sizeof(vector).
Definition: gdata.h:89
int ys
yサイズ. 4Byte.
Definition: gdata.h:86
Definition: gdata.h:42
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition: gdata.h:45
int xs
xサイズ. 4Byte.
Definition: gdata.h:43
int state
状態
Definition: gdata.h:46
sWord * gp
グラフィックデータへのポインタ. xs*ys*zs*2Byte.
Definition: gdata.h:47
int ys
yサイズ. 4Byte.
Definition: gdata.h:44
Definition: matrix.h:29
double n
ベクトルの大きさ
Definition: matrix.h:33
#define PRINT_MESG
環境依存用の出力関数.print_message()
Definition: tools.h:475
#define DEBUG_MODE
Definition: tools.h:502