JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
Gdata.h
Go to the documentation of this file.
1#ifndef __JBXL_CPP_GRAPHIC_DATA_H_
2#define __JBXL_CPP_GRAPHIC_DATA_H_
3
10#include "ClassBox.h"
11#include "gheader.h"
12
13#include "Vector.h"
14
15
16//
17namespace jbxl {
18
19
20extern int ZeroBase;
21extern int TempBase;
22
23
25//
26//
27void free_CmnHead(CmnHead* hd); //< 共通ヘッダのメモリ領域を開放する
28void init_CmnHead(CmnHead* hd);
29
30#define freeCmnHead free_CmnHead
31#define initCmnHead init_CmnHead
32
34
36inline uByte& CmnHeadBytePoint(CmnHead hd, int i=0, int j=0, int k=0)
37{
38 return hd.grptr[(int)i + (int)j*hd.xsize + (int)k*hd.xsize*hd.ysize];
39}
40
41//template <typename T> MSGraph<T> copyCmnHead2MSGraph(CmnHead hd, unsigned int mode=CH2MG_NORMAL);
42//template <typename T> CmnHead copyMSGraph2CmnHead(MSGraph<T> mgr, unsigned int mode=MG2CH_NORMAL);
43//template <typename T> MSGraph<T> scalingMSGraph2D(MSGraph<T> vp, double scale)
44
45
47
62template <typename T> class MSGraph;
63template <typename T> class ExMSGraph;
64
65
75template <typename T=sWord> class MSGraph
76{
77public:
78 int xs;
79 int ys;
80 int zs;
81 T* gp;
82 T zero;
83 T base;
84
85// 以下は必要に応じて設定.
86public:
87 T max;
88 T min;
89 int color;
90 int state;
92 double RZxy;
93 double norm;
94
95public:
96 double wRateX;
97 double wRateY;
98 double wRateZ;
99 double wZeroX;
100 double wZeroY;
101 double wZeroZ;
102 double wNowX;
103 double wNowY;
104 double wNowZ;
105
106//
107public:
108 MSGraph(int x, int y=1, int z=1, T v=(T)0, T b=(T)0, double rz=1.0) { set(x, y, z, v, b, rz);}
109 MSGraph(RBound<int> rb, T v=(T)0, T b=(T)0, double rz=1.0) { set(rb, v, b, rz);}
110 MSGraph(void) { init();}
111
112 virtual ~MSGraph(void) {}
113
114 T& point(int x, int y=0, int z=0) { return gp[x+xs*y+xs*ys*z];}
115 T get_vPoint(double x, double y=0., double z=0., int mode=OFF);
116 void set_vPoint(double x, double y=0., double z=0., T cc=(T)0, int mode=OFF);
117 void put_vPoint(double x, double y=0., double z=0., T cc=(T)0, int mode=OFF);
118
119 void set(RBound<int> rb, T v=(T)0, T b=(T)0, double rz=1.0);
120 void set(int x, int y=1, int z=1, T v=(T)0, T b=(T)0, double rz=1.0);
121
122 void init(void);
123 bool isNull(void);
124 void fill(T v=(T)0);
125 void clear(T v);
126 void clear(void);
127 void getm(int x, int y, int z=1, T v=(T)0);
128 void getm(T v=(T)0);
129 void free(void);
130 void get_minmax(void);
131 void set_array(T* ary, int sz=0);
132 void contrast(T low, T high);
133
134 template <typename R> void mimicry(MSGraph<R> s) {
135 set(s.xs, s.ys, s.zs, (T)s.zero, (T)s.base, s.RZxy);
136 rbound = s.rbound;
137 color = s.color;
138 state = s.state;
139 max = s.zero;
140 min = s.zero;
141 norm = s.norm;
142 };
143
144 template <typename R> void dup(MSGraph<R> s) {
145 *this = s;
146 getm();
147 memcpy(gp, s.gp, xs*ys*zs*sizeof(T));
148 };
149
150 // for viewport
151 void setWindow(double x1, double y1, double x2, double y2);
152 void setWindow3D(double x1, double y1, double z1, double x2, double y2, double z2);
153
154 void wMove(double x, double y, double z=0.0) {wNowX=x; wNowY=y; wNowZ=z;}
155 void wMove_rel(double x, double y, double z=0.0) {wNowX+=x; wNowY+=y; wNowZ+=z;}
156
157
159};
160
161
167template <typename T> void MSGraph<T>::init(void)
168{
169 xs = ys = zs = 0;
170 gp = NULL;
171 RZxy = 1.0;
172 zero = (T)0;
173 base = (T)0;
174 min = (T)0;
175 max = (T)0;
176 norm = 1.0;
177 color = GRAPH_COLOR_UNKNOWN;
178 state = STATE_GRAPH_NOERR;
179 rbound.init();
180
181 wRateX = wRateY = 1.0;
182 wZeroX = wZeroY = 1.0;
183 wNowX = wNowY = 0.0;
184
185 return;
186}
187
188
194template <typename T> bool MSGraph<T>::isNull()
195{
196 if (gp==NULL) return true;
197
198#ifdef WIN32
199 if (gp==(T*)WIN_DD_NULL) return true;
200#endif
201
202 return false;
203}
204
205
206//
207template <typename T> void MSGraph<T>::set(RBound<int> rb, T v, T b, double rz)
208{
209 set(rb.xmax-rb.xmin+1, rb.ymax-rb.ymin+1, rb.zmax-rb.zmin+1, v, b, rz);
210 rbound = rb;
211 return;
212}
213
214
215//
216template <typename T> void MSGraph<T>::set(int x, int y, int z, T v, T b, double rz)
217{
218 if (z<=0) z = 1;
219
220 getm(x, y, z, v);
221 if (gp==NULL) return;
222
223 base = b;
224 if (rz<=0.0) RZxy = 1.0;
225 else RZxy = rz;
226 rbound.set(0, x-1, 0, y-1, 0, z-1);
227 //
228 color = GRAPH_COLOR_UNKNOWN;
229 if (z==1) color = GRAPH_COLOR_MONO;
230
231 norm = 1.0;
232 state = STATE_GRAPH_NOERR;
233 return;
234}
235
236
250template <typename T> void MSGraph<T>::getm(int x, int y, int z, T v)
251{
252 xs = x;
253 ys = y;
254 zs = z;
255 gp = NULL;
256 zero = max = min = v;
257
258 if (xs>0 && ys>0 && zs>0) {
259 gp = (T*)malloc(xs*ys*zs*sizeof(T));
260 if (gp==NULL) {
261 init();
263 return;
264 }
265 for (int i=0; i<xs*ys*zs; i++) gp[i] = (T)v;
266 }
267}
268
269
281template <typename T> void MSGraph<T>::getm(T v)
282{
283 gp = NULL;
284 zero = max = min = v;
285
286 if (xs>0 && ys>0 && zs>0) {
287 gp = (T*)malloc(xs*ys*zs*sizeof(T));
288 if (gp==NULL) {
289 init();
291 return;
292 }
293 for (int i=0; i<xs*ys*zs; i++) gp[i] = (T)v;
294 }
295}
296
297
298template <typename T> void MSGraph<T>::get_minmax(void)
299{
300 int i;
301
302 min = max = gp[0];
303
304 for (i=1; i<xs*ys; i++) {
305 min = Min(min, gp[i]);
306 max = Max(max, gp[i]);
307 }
308}
309
310
311template <typename T> void MSGraph<T>::set_array(T* ary, int sz)
312{
313 int size = xs*ys*zs;
314
315 if (sz>0) size = Min(size, sz);
316 for (int i=0; i<size; i++) gp[i] = ary[i];
317}
318
319
320template <typename T> void MSGraph<T>::contrast(T low, T high)
321{
322 if (max==min) return;
323
324 T dif = (high-low)/(max-min);
325
326 for (int i=0; i<xs*ys*zs; i++) {
327 gp[i] = (gp[i]-min)*dif + low;
328 }
329
330 return;
331}
332
333
339template <typename T> void MSGraph<T>::fill(T v)
340{
341 for (int i=0; i<xs*ys*zs; i++) gp[i] = v;
342 min = max = v;
343 return;
344}
345
346
352template <typename T> void MSGraph<T>::clear(T v)
353{
354 for (int i=0; i<xs*ys*zs; i++) gp[i] = v;
355 zero = min = max = v;
356 return;
357}
358
359
365template <typename T> void MSGraph<T>::clear(void)
366{
367 for (int i=0; i<xs*ys*zs; i++) gp[i] = zero;
368 min = max = zero;
369 return;
370}
371
372
378template <typename T> void MSGraph<T>::free(void)
379{
380 if (gp!=NULL) ::free(gp);
381 init();
382 return;
383}
384
385
397template <typename T> T MSGraph<T>::get_vPoint(double x, double y, double z, int mode)
398{
399 int ix, iy, iz;
400 int xx, yy, zz;
401 T ret;
402
403 ret = zero;
404
405 z = z*RZxy;
406 if (mode==OFF) {
407 ix = (int)(x+0.5) - rbound.xmin;
408 iy = (int)(y+0.5) - rbound.ymin;
409 iz = (int)(z+0.5) - rbound.zmin;
410 if (ix>=0 && ix<xs &&iy>=0 && iy<ys && iz>=0 && iz<zs){
411 ret = gp[iz*xs*ys + iy*xs + ix];
412 }
413 }
414 else {
415 int n = 0;
416 T cc = (T)0;
417
418 xx = (int)x - rbound.xmin;
419 yy = (int)y - rbound.ymin;
420 zz = (int)z - rbound.zmin;
421 for (ix=xx; ix<=xx+1; ix++)
422 for (iy=yy; iy<=yy+1; iy++)
423 for (iz=zz; iz<=zz+1; iz++) {
424 if (ix>=0 && ix<xs && iy>=0 && iy<ys && iz>=0 && iz<zs){
425 cc = cc + gp[iz*xs*ys + iy*xs + ix];
426 n++;
427 }
428 }
429 if (n!=0) ret = cc/n;
430 }
431
432 return ret;
433}
434
435
447template <typename T> void MSGraph<T>::set_vPoint(double x, double y, double z, T cc, int mode)
448{
449 int ix, iy, iz;
450 int xx, yy, zz;
451
452 z = z*RZxy;
453 if (mode==OFF) {
454 ix = (int)(x+0.5) - rbound.xmin;
455 iy = (int)(y+0.5) - rbound.ymin;
456 iz = (int)(z+0.5) - rbound.zmin;
457 if (ix>=0 && ix<xs && iy>=0 && iy<ys && iz>=0 && iz<zs){
458 gp[iz*xs*ys + iy*xs + ix] = cc;
459 }
460 }
461 else {
462 xx = (int)x - rbound.xmin;
463 yy = (int)y - rbound.ymin;
464 zz = (int)z - rbound.zmin;
465 for (ix=xx; ix<=xx+1; ix++)
466 for (iy=yy; iy<=yy+1; iy++)
467 for (iz=zz; iz<=zz+1; iz++) {
468 if (ix>=0 && ix<xs && iy>=0 && iy<ys && iz>=0 && iz<zs){
469 gp[iz*xs*ys + iy*xs + ix] = cc;
470 }
471 }
472 }
473 return;
474}
475
476
491template <typename T> void MSGraph<T>::put_vPoint(double x, double y, double z, T cc, int mode)
492{
493 int ix, iy, iz;
494 int xx, yy, zz;
495
496 z = z*RZxy;
497 if (mode==OFF) {
498 ix = (int)(x+0.5) - rbound.xmin;
499 iy = (int)(y+0.5) - rbound.ymin;
500 iz = (int)(z+0.5) - rbound.zmin;
501 if (ix>=0 && ix<xs && iy>=0 && iy<ys && iz>=0 && iz<zs){
502 if (gp[iz*xs*ys + iy*xs + ix]==zero) gp[iz*xs*ys + iy*xs + ix] = cc;
503 }
504 }
505 else {
506 xx = (int)x - rbound.xmin;
507 yy = (int)y - rbound.ymin;
508 zz = (int)z - rbound.zmin;
509 for (ix=xx; ix<=xx+1; ix++)
510 for (iy=yy; iy<=yy+1; iy++)
511 for (iz=zz; iz<=zz+1; iz++) {
512 if (ix>=0 && ix<xs && iy>=0 && iy<ys && iz>=0 && iz<zs){
513 if (gp[iz*xs*ys + iy*xs + ix]==zero) gp[iz*xs*ys + iy*xs + ix] = cc;
514 }
515 }
516 }
517
518 return;
519}
520
521
522template <typename T> void MSGraph<T>::setWindow(double x1, double y1, double x2, double y2)
523{
524 if (x1==x2 || y1==y2) return;
525
526 wRateX = (xs-1.0)/Xabs(x2-x1);
527 wRateY = (ys-1.0)/Xabs(y2-y1);
528 wZeroX = Min(x1, x2);
529 wZeroY = Max(y1, y2);
530}
531
532
555template <typename T> void MSGraph<T>::setWindow3D(double x1, double y1, double z1, double x2, double y2, double z2)
556{
557 if (x1==x2 || y1==y2 || z1==z2) return;
558
559 wRateX = (xs-1.0)/Xabs(x2-x1);
560 wRateY = (ys-1.0)/Xabs(y2-y1);
561 wRateZ = (zs-1.0)/Xabs(z2-z1);
562 wZeroX = Max(x1, x2);
563 wZeroY = Min(y1, y2);
564 wZeroZ = Max(z1, z2);
565}
566
567
568// オペレータ
569//
571{
572 xs = s.xs;
573 ys = s.ys;
574 zs = s.zs;
575 gp = s.gp;
576 zero = s.zero;
577 base = s.base;
578
579 max = s.max;
580 min = s.min;
581 color = s.color;
582 state = s.state;
583 rbound = s.rbound;
584 RZxy = s.RZxy;
585 norm = s.norm;
586
587 wRateX = s.wRateX;
588 wRateY = s.wRateY;
589 wRateZ = s.wRateZ;
590 wZeroX = s.wZeroX;
591 wZeroY = s.wZeroY;
592 wZeroZ = s.wZeroZ;
593 wNowX = s.wNowX;
594 wNowY = s.wNowY;
595 wNowZ = s.wNowZ;
596
597 return *this;
598}
599
600
601
603// 簡易表示インターフェイス
604//
605template <typename T=uWord> class MSGraphDisp : public CVDisplay
606{
607public:
608
609public:
611 virtual ~MSGraphDisp() {}
612
613 virtual void displayNew (MSGraph<T> vp) {}
614 virtual void displayNext(MSGraph<T> vp) {}
615};
616
617
618
620// データ変換
621//
622
623// ビット和を執れるように設定する.
624#define CH2MG_NORMAL 0 //< ノーマルコピー
625#define CH2MG_NOPARM 1
626
627#define MG2CH_NORMAL 0
628#define MG2CH_NOPARM 1
629#define MG2CH_CONTRAST 2
630#define MG2CH_OCTET 4
631
632//template <typename T> MSGraph<T> copyCmnHead2MSGraph(CmnHead hd, unsigned int mode=CH2MG_NORMAL);
633//template <typename T> CmnHead copyMSGraph2CmnHead(MSGraph<T> mgr, unsigned int mode=MG2CH_NORMAL);
634
651template <typename T> MSGraph<T> copyCmnHead2MSGraph(CmnHead hd, unsigned int mode=CH2MG_NORMAL, bool cnt=false)
652{
653 MSGraph<T> vp;
654 int kind = hd.kind & 0x00ff;
655
656 vp.init(); // vp.color = GRAPH_COLOR_UNKNOWN;
657
658 if (kind==UN_KNOWN_DATA || hd.kind==HEADER_NONE) {
660 return vp;
661 }
662
663 vp.set(hd.xsize, hd.ysize, hd.zsize);
664 if (vp.gp==NULL) { vp.state = JBXL_GRAPH_MEMORY_ERROR; return vp;}
665
666 // カラータイプ
667 if (kind==JPEG_RGB_DATA || kind==JPEG_MONO_DATA) {
668 //if (hd.zsize==3) vp.color = GRAPH_COLOR_PRGB;
669 if (hd.zsize==3) vp.color = GRAPH_COLOR_RGB;
670 }
671 else if (hd.depth==16) {
673 }
674
675 // カウンタ.ここでは,delete禁止
676 CVCounter* counter = NULL;
677 if (vp.zs>=10 && cnt) {
678 counter = GetUsableGlobalCounter();
679 if (counter!=NULL) counter->SetMax(vp.zs/10);
680 }
681
682 int ks, js, ln;
683 ln = vp.xs*vp.ys;
684
685 if (hd.depth==16){
686 sWord* bp = (sWord*)hd.grptr;
687 vp.max = vp.min = bp[0];
688 for (int k=0; k<vp.zs; k++) {
689 ks = k*ln;
690 for (int j=0; j<vp.xs*vp.ys; j++) {
691 js = j+ ks;
692 vp.gp[js] = bp[js];
693 vp.max = Max(vp.max, vp.gp[js]);
694 vp.min = Min(vp.min, vp.gp[js]);
695 }
696
697 if (counter!=NULL && k%10==0) {
698 counter->StepIt();
699 if (counter->isCanceled()) { // キャンセル
700 vp.free();
702 return vp;
703 }
704 }
705
706 }
707 }
708
709 else if (hd.depth<16){ // ==8
710 //int uint = (unsigned char)hd.grptr[0];
711 vp.max = vp.min = (T)((unsigned char)hd.grptr[0]);
712 for (int k=0; k<vp.zs; k++) {
713 ks = k*ln;
714 for (int j=0; j<vp.xs*vp.ys; j++) {
715 js = j + ks;
716 vp.gp[js] = (T)((unsigned char)hd.grptr[js]);
717 vp.max = Max(vp.max, vp.gp[js]);
718 vp.min = Min(vp.min, vp.gp[js]);
719 }
720
721 if (counter!=NULL && k%10==0) {
722 counter->StepIt();
723 if (counter->isCanceled()) { // キャンセル
724 vp.free();
726 return vp;
727 }
728 }
729 }
730 }
731
732 else {
733 vp.max = vp.min = (T)((uByte)hd.grptr[0]>>(hd.depth-15));
734 for (int k=0; k<vp.zs; k++) {
735 ks = k*ln;
736 for (int j=0; j<vp.xs*vp.ys; j++) {
737 js = j + ks;
738 vp.gp[js] = (T)((uByte)hd.grptr[js]>>(hd.depth-15));
739 vp.max = Max(vp.max, vp.gp[js]);
740 vp.min = Min(vp.min, vp.gp[js]);
741 }
742
743 if (counter!=NULL && k%10==0) {
744 counter->StepIt();
745 if (counter->isCanceled()) { // キャンセル
746 vp.free();
748 return vp;
749 }
750 }
751 }
752 }
753
754 // もし存在するなら,ヘッダ部分から Z方向の歪率, rboundを取り出す.
755 if (!checkBit(mode, CH2MG_NOPARM)) {
756 if (hd.bsize>0 && (kind==CT_DATA || kind==CT_3DM || kind==CT_3D_VOL)) {
757 sWord* rz = (sWord*)hd.buf;
758 if (rz[9]==RZXY_RATE || checkBit(hd.kind, HAS_RZXY)) {
759 double rzm = rz[8]/(double)rz[9];
760 if (rzm<5.0 && rzm>0.) vp.RZxy = rzm;
761 }
762
763 if (rz[10]!=0 && checkBit(hd.kind, HAS_BASE)) {
764 vp.base = (T)rz[10];
765 }
766
767 if (checkBit(hd.kind, HAS_RBOUND)) {
768 vp.rbound.xmin = rz[6];
769 vp.rbound.xmax = rz[7];
770 vp.rbound.ymin = rz[4];
771 vp.rbound.ymax = rz[5];
772 vp.rbound.zmin = rz[2];
773 vp.rbound.zmax = rz[3];
774 }
775 }
776 }
777
778 if (counter!=NULL) counter->PutFill();
779
780 return vp;
781}
782
783
805template <typename T> CmnHead copyMSGraph2CmnHead(MSGraph<T>& vp, unsigned int mode=MG2CH_NORMAL, bool cnt=false)
806{
807 CmnHead hd;
808 CTHead ct;
809
810 memset(&ct, 0, sizeof(CTHead));
811 memset(&hd, 0, sizeof(CmnHead));
812
813 if (vp.gp==NULL) {
815 hd.kind = HEADER_NONE;
816 return hd;
817 }
818
819 //
820 hd.kind = 0; // MSGraphからのコピー時には,ヘッダ情報は既に消失している.
821 hd.xsize = ct.xsize = ct.cutright= vp.xs;
822 hd.ysize = ct.ysize = ct.cutdown = vp.ys;
823 hd.zsize = vp.zs;
824
825 if (checkBit(mode, MG2CH_OCTET)) hd.depth = 8;
826 else hd.depth = sizeof(T)*8;
827 hd.lsize = hd.xsize*hd.ysize*hd.zsize*(hd.depth/8);
828 hd.bsize = sizeof(CTHead);
829
830 hd.grptr = (uByte*)malloc(hd.lsize*sizeof(uByte));
831 if (hd.grptr==NULL) {
833 hd.kind = HEADER_NONE;
834 return hd;
835 }
836 memset(hd.grptr, 0, hd.lsize*sizeof(uByte));
837
838 hd.buf = (uByte*)malloc(hd.bsize*sizeof(uByte));
839 if (hd.buf==NULL) {
840 free_CmnHead(&hd);
842 return hd;
843 }
844 memset(hd.buf, 0, hd.bsize*sizeof(uByte));
845
846 // カウンタ.ここでは,delete禁止
847 CVCounter* counter = NULL;
848
849 if (hd.zsize>=5 && cnt) {
850 counter = GetUsableGlobalCounter();
851 if (counter!=NULL) counter->SetMax(hd.zsize*2/10);
852 }
853
854 // 最大値,最小値を求める
855 int j, k, ks, js, ln;
856 T max, min;
857 max = min = vp.gp[0];
858
859 ln = vp.xs*vp.ys;
860 for (k=0; k<vp.zs; k++) {
861 ks = k*ln;
862 for (j=0; j<vp.ys*vp.xs; j++) {
863 js = j + ks;
864 min = Min(vp.gp[js], min);
865 max = Max(vp.gp[js], max);
866 }
867
868 // カウンタ
869 if (counter!=NULL && k%10==0) {
870 counter->StepIt();
871 if (counter->isCanceled()) { // キャンセル
872 free_CmnHead(&hd);
874 return hd;
875 }
876 }
877 }
878 vp.max = max;
879 vp.min = min;
880
881 // ノーマルコピー
882 if (mode==MG2CH_NORMAL) {
883 memcpy(hd.grptr, vp.gp, hd.lsize);
884 }
885
886 // 8bitへ変換
887 else if (checkBit(mode, MG2CH_OCTET)) {
888 // 255以下はコントラスト調整しない
889 if (!checkBit(mode, MG2CH_CONTRAST) && vp.max<=255 && vp.min>=0) {
890 max = 255;
891 min = 0;
892 }
893
894 for (k=0; k<hd.zsize; k++) {
895 ks = k*ln;
896 for (j=0; j<hd.xsize*hd.ysize; j++) {
897 js = j + ks;
898 hd.grptr[js] = (uByte)(((vp.gp[js]-min)/(double)(max-min))*255.);
899 }
900
901 // カウンタ
902 if (counter!=NULL && k%10==0) {
903 counter->StepIt();
904 if (counter->isCanceled()) { // キャンセル
905 free_CmnHead(&hd);
907 return hd;
908 }
909 }
910 }
911 }
912 if (counter!=NULL) counter->PutFill();
913
914 memcpy(hd.buf, &ct, hd.bsize);
915
916 // Z方向の歪率, rboundの設定.
917 if (!checkBit(mode, MG2CH_NOPARM)) {
918 sWord* rz = (sWord*)hd.buf;
919 if (vp.RZxy!=1.0) {
920 hd.kind = hd.kind | HAS_RZXY;
921 rz[9] = (sWord)RZXY_RATE;
922 rz[8] = (sWord)(vp.RZxy*RZXY_RATE);
923 }
924 if (vp.base!=0) {
925 rz[10] = (sWord)vp.base;
926 hd.kind |= HAS_BASE;
927 }
928 rz[2] = (sWord)vp.rbound.zmin;
929 rz[3] = (sWord)vp.rbound.zmax;
930 rz[4] = (sWord)vp.rbound.ymin;
931 rz[5] = (sWord)vp.rbound.ymax;
932 rz[6] = (sWord)vp.rbound.xmin;
933 rz[7] = (sWord)vp.rbound.xmax;
934 hd.kind |= HAS_RBOUND;
935 }
936
937 return hd;
938}
939
940
941// 2D画像の拡大・縮小
942//
943template <typename T> MSGraph<T> scalingMSGraph2D(MSGraph<T> vp, double scale)
944{
945 MSGraph<T> xp;
946
947 if (scale==0.0) return xp;
948
949 int xs = (int)(vp.xs*scale);
950 int ys = (int)(vp.ys*scale);
951 int zs = vp.zs;
952 int ps = xs*ys;
953 if (vp.xs*scale-xs>0.0) xs++;
954 if (vp.ys*scale-ys>0.0) ys++;
955
956 xp.set(xs, ys, zs);
957 xp.getm();
958 xp.color = vp.color;
959
960 for (int kk=0; kk<zs; kk++) {
961 int posk = kk*ps;
962 //
963 for (int jj=0; jj<ys; jj++) {
964 int posj = jj*xs + posk;
965 double y = jj/scale;
966 int j = (int)y;
967 int n = j + 1;
968 if (j>vp.ys-1) j = vp.ys-1;
969 if (n>vp.ys-1) n = vp.ys-1;
970 double bt = y - j;
971 //
972 for (int ii=0; ii<xs; ii++) {
973 double x = ii/scale;
974 int i = (int)x;
975 int m = i + 1;
976 if (j>vp.xs-1) j = vp.xs-1;
977 if (n>vp.xs-1) n = vp.xs-1;
978 double al = x - i;
979
980 T a = vp.point(i, j, kk);
981 T b = vp.point(m, j, kk);
982 T c = vp.point(i, n, kk);
983 T d = vp.point(m, n, kk);
984 T p = (T)(a*(1.0-al)*(1.0-bt) + b*al*(1.0-bt) + c*(1.0-al)*bt + d*al*bt);
985
986 xp.gp[ii+posj] = p;
987 }
988 }
989 }
990
991 return xp;
992}
993
994
995
997// Tools
998//
999
1000inline unsigned int ARGB2Int(unsigned int a, unsigned int r, unsigned int g, unsigned int b)
1001{
1002 if (isBigEndian) { // A-R-G-B
1003 a = (unsigned int)((a&0x000000ff)<<24);
1004 r = (unsigned int)((r&0x000000ff)<<16);
1005 g = (unsigned int)((g&0x000000ff)<<8);
1006 b = (unsigned int) (b&0x000000ff);
1007 }
1008 else { // B-G-R-A
1009 b = (unsigned int)((b&0x000000ff)<<24);
1010 g = (unsigned int)((g&0x000000ff)<<16);
1011 r = (unsigned int)((r&0x000000ff)<<8);
1012 a = (unsigned int) (a&0x000000ff);
1013 }
1014
1015 unsigned int c = (unsigned int)(a + r + g + b);
1016 return c;
1017}
1018
1019
1020#define RGBA2Int(r, g, b, a) ARGB2Int((r), (g), (b), (a))
1021#define ABGR2Int(a, b, g, r) ARGB2Int((a), (b), (g), (r))
1022#define BGRA2Int(b, g, r, a) ARGB2Int((b), (g), (r), (a))
1023
1024
1026{
1027 if (isBigEndian) { // A-R-G-B
1028 a = (int)(((a&0x00ff)>>4)<<12);
1029 r = (int)(((r&0x00ff)>>4)<<8);
1030 g = (int)(((g&0x00ff)>>4)<<4);
1031 b = (int) ((b&0x00ff)>>4);
1032 }
1033 else { // G-B A-R
1034 g = (int)(((g&0x00ff)>>4)<<12);
1035 b = (int)(((b&0x00ff)>>4)<<8);
1036 a = (int)(((a&0x00ff)>>4)<<4);
1037 r = (int) ((r&0x00ff)>>4);
1038 }
1039
1040 uWord c = (uWord)(a + r + g + b);
1041 return c;
1042}
1043
1044
1045#define RGBA2Word(r, g, b, a) ARGB2Word((r), (g), (b), (a))
1046#define ABGR2Word(a, b, g, r) ARGB2Word((a), (b), (g), (r))
1047#define BGRA2Word(b, g, r, a) ARGB2Word((b), (g), (r), (a))
1048
1049
1051{
1052 r = (int)(((r&0x00ff)>>3)<<11);
1053 g = (int)(((g&0x00ff)>>2)<<5);
1054 b = (int) ((b&0x00ff)>>3);
1055 uWord c = (uWord)(r + g + b);
1056
1057 if (isLittleEndian) swap_byte(&c, 2, 2);
1058 return c;
1059}
1060
1061
1074} // namespace
1075
1076
1077#endif
1078
C++ ToolBox of Class.
#define MG2CH_CONTRAST
コントラスト調整を行う
Definition Gdata.h:629
#define MG2CH_NORMAL
ノーマルコピー
Definition Gdata.h:627
#define CH2MG_NORMAL
Definition Gdata.h:624
#define MG2CH_NOPARM
パラメータ処理(Z軸の歪, rboundの処理)をしない.
Definition Gdata.h:628
#define CH2MG_NOPARM
パラメータ処理(Z軸の歪, rboundの処理)をしない.
Definition Gdata.h:625
#define MG2CH_OCTET
8bitへ変換
Definition Gdata.h:630
ベクトルライブラリ for C++
virtual void StepIt(int n=1)
カウンタのメモリを増やす
Definition ClassBox.h:171
virtual void SetMax(int m)
カウンタの最大値(最終目標)を設定
Definition ClassBox.h:161
virtual void PutFill()
取り敢えずの目標(最短目標)までカウンタを進める.
Definition ClassBox.h:164
virtual bool isCanceled()
カウンタがオペレータにより,キャンセルされたか
Definition ClassBox.h:173
virtual void displayNext(MSGraph< T > vp)
Definition Gdata.h:614
virtual ~MSGraphDisp()
Definition Gdata.h:611
virtual void displayNew(MSGraph< T > vp)
Definition Gdata.h:613
T get_vPoint(double x, double y=0., double z=0., int mode=OFF)
Definition Gdata.h:397
void clear(T v)
全空間を画素値 v にする
Definition Gdata.h:352
T * gp
グラフィックデータへのポインタ.
Definition Gdata.h:81
double wNowZ
ペンの現地点の z成分(ワールド座標系)
Definition Gdata.h:104
double wZeroX
スクリーン座標系の原点に対するワールド座標系の x成分.
Definition Gdata.h:99
int color
データのカラータイプ
Definition Gdata.h:89
T base
画措置の底上げの値.
Definition Gdata.h:83
double wZeroY
スクリーン座標系の原点に対するワールド座標系の y成分.
Definition Gdata.h:100
T & point(int x, int y=0, int z=0)
座標(x,y,z)の画素値の参照
Definition Gdata.h:114
void init(void)
グラフィックデータは解放しない
Definition Gdata.h:167
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition Gdata.h:80
void set_array(T *ary, int sz=0)
ary の内容を gpにコピー.
Definition Gdata.h:311
MSGraph< T > operator=(ExMSGraph< T > &s)
Definition Gdata.h:570
void setWindow3D(double x1, double y1, double z1, double x2, double y2, double z2)
Definition Gdata.h:555
void get_minmax(void)
min, max を獲得
Definition Gdata.h:298
MSGraph(void)
Definition Gdata.h:110
double wRateY
ワールド座標系の y成分1ドットに対するスクリーン座標系のドット数.
Definition Gdata.h:97
void contrast(T low, T high)
コントラストの調整
Definition Gdata.h:320
MSGraph(int x, int y=1, int z=1, T v=(T) 0, T b=(T) 0, double rz=1.0)
Definition Gdata.h:108
void dup(MSGraph< R > s)
Definition Gdata.h:144
void put_vPoint(double x, double y=0., double z=0., T cc=(T) 0, int mode=OFF)
Definition Gdata.h:491
T max
画素値の最大値
Definition Gdata.h:87
double wZeroZ
スクリーン座標系の原点に対するワールド座標系の z成分.
Definition Gdata.h:101
T min
画素値の最小値
Definition Gdata.h:88
double wRateZ
ワールド座標系の z成分1ドットに対するスクリーン座標系のドット数.
Definition Gdata.h:98
double wNowX
ペンの現地点の x成分(ワールド座標系)
Definition Gdata.h:102
double norm
規格化定数.フィルタのときに使用.
Definition Gdata.h:93
int xs
xサイズ. 4Byte.
Definition Gdata.h:78
int state
エラー制御
Definition Gdata.h:90
MSGraph(RBound< int > rb, T v=(T) 0, T b=(T) 0, double rz=1.0)
Definition Gdata.h:109
virtual ~MSGraph(void)
Definition Gdata.h:112
void getm(T v=(T) 0)
グラフィックメモリを獲得する
Definition Gdata.h:281
void fill(T v=(T) 0)
全空間を画素値 v にする
Definition Gdata.h:339
void set(int x, int y=1, int z=1, T v=(T) 0, T b=(T) 0, double rz=1.0)
Definition Gdata.h:216
double RZxy
Z軸の歪.Z軸の間隔を 1とした XY軸の間隔.(X or Y)/Z.
Definition Gdata.h:92
T zero
画素値のゼロ位.
Definition Gdata.h:82
void free(void)
グラフィックデータを開放する
Definition Gdata.h:378
void set(RBound< int > rb, T v=(T) 0, T b=(T) 0, double rz=1.0)
Definition Gdata.h:207
void setWindow(double x1, double y1, double x2, double y2)
Definition Gdata.h:522
bool isNull(void)
グラフィックデータを持っていないか?
Definition Gdata.h:194
void set_vPoint(double x, double y=0., double z=0., T cc=(T) 0, int mode=OFF)
Definition Gdata.h:447
void mimicry(MSGraph< R > s)
Definition Gdata.h:134
RBound< int > rbound
画像の境界情報
Definition Gdata.h:91
void clear(void)
全空間を画素値 zero にする
Definition Gdata.h:365
int ys
yサイズ. 4Byte.
Definition Gdata.h:79
double wNowY
ペンの現地点の y成分(ワールド座標系)
Definition Gdata.h:103
void wMove(double x, double y, double z=0.0)
Definition Gdata.h:154
void getm(int x, int y, int z=1, T v=(T) 0)
グラフィックメモリを獲得する
Definition Gdata.h:250
void wMove_rel(double x, double y, double z=0.0)
Definition Gdata.h:155
double wRateX
ワールド座標系の x成分1ドットに対するスクリーン座標系のドット数.
Definition Gdata.h:96
void init()
Definition Vector.h:455
T xmax
x軸境界の最大値.
Definition Vector.h:427
T ymin
y軸境界の最小値.
Definition Vector.h:428
void set(T XMin=(T) 0, T XMax=(T) 0, T YMin=(T) 0, T YMax=(T) 0, T ZMin=(T) 0, T ZMax=(T) 0, T TMin=(T) 0, T TMax=(T) 0)
Definition Vector.h:444
T zmax
z軸境界の最大値.
Definition Vector.h:431
T xmin
x軸境界の最小値.
Definition Vector.h:426
T ymax
y軸境界の最大値.
Definition Vector.h:429
T zmin
z軸境界の最小値.
Definition Vector.h:430
#define Min(x, y)
Definition common.h:250
#define OFF
Definition common.h:231
unsigned short uWord
2Byte
Definition common.h:334
#define Max(x, y)
Definition common.h:247
#define Xabs(x)
Definition common.h:257
short sWord
2Byte
Definition common.h:335
unsigned char uByte
1Byte
Definition common.h:332
#define WIN_DD_NULL
Definition common.h:96
#define checkBit(dat, bit)
Definition common.h:260
グラフィックデータヘッダ定義
#define HEADER_NONE
0x8000 // ヘッダ種別の指定なし
Definition gheader.h:212
#define GRAPH_COLOR_UNKNOWN
0x0070
Definition gheader.h:302
#define CT_3DM
0x0012 // 3D CT DATA(マルチスライス)
Definition gheader.h:178
#define GRAPH_COLOR_RGB
Definition gheader.h:270
#define HAS_BASE
0x0400 // 基底(底上げ)値を持つ
Definition gheader.h:206
#define GRAPH_COLOR_MONO
0x0000
Definition gheader.h:242
#define RZXY_RATE
RZxy をファイルのヘッダに埋め込む際の比率(倍率).
Definition gheader.h:215
#define JPEG_RGB_DATA
0x0020 // JPEG RGB
Definition gheader.h:184
#define CT_DATA
0x0010 // CT DATA (Moon形式)
Definition gheader.h:177
#define GRAPH_COLOR_MONO16
0x0010
Definition gheader.h:247
#define HAS_RBOUND
0x2000 // with RBound data
Definition gheader.h:209
#define UN_KNOWN_DATA
0x0000 // 知らないデータ形式(システムにお任せ)
Definition gheader.h:169
#define JPEG_MONO_DATA
0x0021 // JPEG MONO
Definition gheader.h:185
#define HAS_RZXY
0x1000 // with RZxy data
Definition gheader.h:208
#define CT_3D_VOL
0x0013 // CT ボリュームデータ
Definition gheader.h:179
#define STATE_GRAPH_NOERR
Definition gheader.h:234
#define JBXL_GRAPH_CANCEL
処理がキャンセルされた
Definition jbxl_state.h:168
#define JBXL_GRAPH_HEADER_ERROR
画像ヘッダーのエラー
Definition jbxl_state.h:169
#define JBXL_GRAPH_MEMORY_ERROR
メモリエラー
Definition jbxl_state.h:170
Definition Brep.h:29
unsigned int ARGB2Int(unsigned int a, unsigned int r, unsigned int g, unsigned int b)
Definition Gdata.h:1000
CVCounter * GetUsableGlobalCounter()
現在有効なグローバルカウンタを得る.(子カウンタを得るかもしれない)
Definition ClassBox.h:185
uWord RGB2Word(uWord r, uWord g, uWord b)
Definition Gdata.h:1050
MSGraph< T > scalingMSGraph2D(MSGraph< T > vp, double scale)
Definition Gdata.h:943
MSGraph< T > copyCmnHead2MSGraph(CmnHead hd, unsigned int mode=CH2MG_NORMAL, bool cnt=false)
Definition Gdata.h:651
uByte & CmnHeadBytePoint(CmnHead hd, int i=0, int j=0, int k=0)
共通ヘッダCmnHeadから座標を指定して,画像データを取り出す
Definition Gdata.h:36
int TempBase
Definition Gdata.cpp:14
void init_CmnHead(CmnHead *hd)
Definition Gdata.cpp:42
uWord ARGB2Word(uWord a, uWord r, uWord g, uWord b)
Definition Gdata.h:1025
void free_CmnHead(CmnHead *hd)
Definition Gdata.cpp:25
CmnHead getinfo_CmnHead(CmnHead hd)
ヘッダ情報のみをコピーする
Definition Gdata.cpp:58
CmnHead copyMSGraph2CmnHead(MSGraph< T > &vp, unsigned int mode=MG2CH_NORMAL, bool cnt=false)
Definition Gdata.h:805
int ZeroBase
Definition Gdata.cpp:13
sWord xsize
Definition gheader.h:65
sWord cutdown
Definition gheader.h:70
sWord ysize
Definition gheader.h:66
sWord cutright
Definition gheader.h:72
unsigned int lsize
Size of Graphics Data (byte unit)
Definition gheader.h:133
uByte * buf
Ture Header buffer
Definition gheader.h:137
int zsize
For 3D Data (or Color)
Definition gheader.h:130
int kind
Kind of Graphics Format.
Definition gheader.h:127
unsigned int bsize
Fllowing buf size or Any Data (byte unit)
Definition gheader.h:132
uByte * grptr
Pointer to Data.
Definition gheader.h:138
int ysize
Height of Graphics.
Definition gheader.h:129
int depth
Color Depth of Graphics (bit unit)
Definition gheader.h:131
int xsize
Width of Graphics.
Definition gheader.h:128
void swap_byte(void *p, int s, int c)
sの長さのpのバイト順序をbバイト毎に逆順にする.
Definition tools.cpp:1854
#define isLittleEndian
Definition tools.h:423
#define isBigEndian
Definition tools.h:422