JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
Graph.h
Go to the documentation of this file.
1#ifndef __JBXL_CPP_MEMORY_SIMPLE_GRAPH_H_
2#define __JBXL_CPP_MEMORY_SIMPLE_GRAPH_H_
3
10#include "Gdata.h"
11
12
13//
14namespace jbxl {
15
16
17void rotate_point (int& x, int& y, double sxc, double syc, double dxc, double dyc, double cst, double snt);
18void rotate_point_angle(int& x, int& y, double sxc, double syc, double dxc, double dyc, double th);
19
20/*
21template <typename T> RBound<int> out_around_MSGraph(MSGraph<T> vp, int x, int y, int mode=8);
22template <typename T> Vector<double> dgree_circle_MSGraph(MSGraph<T> vp);
23template <typename T> double count_around_MSGraph(MSGraph<T> vp);
24template <typename T> int count_area_MSGraph(MSGraph<T> xp);
25template <typename T> int count_object_MSGraph(MSGraph<T> xp, int mn, int mx);
26template <typename T> RBound<int> get_boundary_MSGraph(MSGraph<T> vp, int mn, int mx);
27
28template <typename T, typename R> void cat_MSGraph (MSGraph<R> src, MSGraph<T>& dst);
29template <typename T, typename R> void cat_MSGraph (MSGraph<R>* src, MSGraph<T>* dst);
30template <typename T, typename R> void copy_MSGraph(MSGraph<R> src, MSGraph<T>& dst);
31template <typename T, typename R> void copy_MSGraph(MSGraph<R>* src, MSGraph<T>* dst);
32template <typename T> MSGraph<T> dup_MSGraph(MSGraph<T> src);
33template <typename T> MSGraph<T>* dup_MSGraph(MSGraph<T>* src);
34
35template <typename T> void ToPola(Vector<T> nv, double& cst, double& snt, double& csf, double& snf, double pcsf=0.0, double psnf=1.0)
36template <typename T, typename R> void Local2World(MSGraph<T> gd, MSGraph<T> vp, Vector<R> oq, Vector<R> op, Vector<R> ex);
37
38template <typename T> void MSGraph_chngColor(MSGraph<T> vp, int f, int t);
39template <typename T> int MSGraph_Paint (MSGraph<T> vp, int x, int y, int mn, int mx, int cc, int mode=8);
40template <typename T> int MSGraph_Paint3D (MSGraph<T> vp, int x, int y, int z, int mn, int mx, int cc, int mode=8);
41template <typename T> void MSGraph_Line (MSGraph<T> vp, int x1, int y1, int x2, int y2, int cc);
42template <typename T> void MSGraph_Line3D (MSGraph<T> vp, int x1, int y1, int z1, int x2, int y2, int z2, int cc);
43template <typename T> void MSGraph_Triangle (MSGraph<T> vp, int x1, int y1, int x2, int y2, int x3, int y3, int cc, int mode=OFF);
44template <typename T> void MSGraph_Box (MSGraph<T> vp, int x1, int y1, int x2, int y2, int cc, int mode=OFF);
45template <typename T> void MSGraph_Circle (MSGraph<T> vp, int x, int y, int r, int cc, int mode=OFF);
46template <typename T> void MSGraph_Circle3D (MSGraph<T> vp, Vector<> ox, Vector<> ex, int rr, int cc, int mode=OFF);
47template <typename T> void MSGraph_Pool (MSGraph<T> vp, Vector<> a, Vector<> b, int rr, int cc);
48template <typename T> void MSGraph_Torus (MSGraph<T> vp, Vector<> ox, Vector<> ex, int rr, int ra, int cc);
49template <typename T> void MSGraph_Sphere (MSGraph<T> vp, Vector<> a, int r, int cc, int mode=1);
50
51template <typename T> MSGraph<T> cut_object_MSGraph(MSGraph<T> vp, int mn, int mx, int blank=BOUNDARY_BLANK, bool ecnt=false);
52template <typename T> MSGraph<T> cut_object_MSGraph(MSGraph<T> vp, int mn, int mx, RBound<int> rbound, int blank=BOUNDARY_BLANK, bool ecnt=false);
53template <typename T> MSGraph<T> cut_object_MSGraph(MSGraph<T> vp, RBound<int> rbound, bool ecnt=false);
54
55template <typename T> MSGraph<T> zoom_MSGraph (MSGraph<T> vp, double zm, int mode=ON);
56template <typename T> MSGraph<T> reduce_MSGraph(MSGraph<T> vp, double rc, int mode=ON)
57template <typename T> MSGraph<T> rotate_MSGraph(MSGraph<T> vp, int xs, int ys, double cst, double snt, int mode=ON);
58template <typename T> MSGraph<T> rotate_MSGraph(MSGraph<T> vp, double th, int mode=ON);
59
60template <typename T> MSGraph<T> x_reverse_MSGraph(MSGraph<T> vp);
61template <typename T> MSGraph<T> grab_MSGraph(MSGraph<T> vp, int x1, int y1, int x2, int y2);
62template <typename T> MSGraph<T>* grab_MSGraph(MSGraph<T>* vp, int x1, int y1, int x2, int y2);
63template <typename T> void set_around_MSGraph(MSGraph<T> vp, int cc);
64
65template <typename T> int addPaint_MSGraph(MSGraph<T> xp, int x, int y, int mn, int mx, int add, int mode=8);
66template <typename T> MSGraph<T> Density_Filter(MSGraph<T> vp, int size, double rate, int mode=8, int work_color=0);
67template <typename T> MSGraph<T> Density_Mask(MSGraph<T> vp, double rate, int mode=8, int work_color=0);
68template <typename T> void delete_noise_MSGraph(MSGraph<T> vp, int size, int mode=8, int work_color=0)
69*/
70
71
87{
89 double fac = 1.113757;
90// double fac = 1.182;
91
92/*
93 MSGraph<T> pp;
94 pp.set(vp.xs+2, vp.ys+2, 1);
95 for (int j=0; j<vp.ys; j++) {
96 for (int i=0; i<vp.xs; i++) {
97 pp.gp[(j+1)*pp.xs+i+1] = vp.gp[j*vp.xs+i];
98 }
99 }
100*/
101 vt.z = -1.0;
102 vt.x = count_around_MSGraph(vp);
103 vt.y = count_area_MSGraph(vp);
104 if (vt.y!=0) vt.z = (vt.x*vt.x)/(4.*PI*vt.y)/fac;
105
106 //pp.free();
107
108 return vt;
109}
110
111
126template <typename T> Vector<double> object_feature_MSGraph(MSGraph<T> vp, int mn, int mx)
127{
128 int cnt = 0;
129 int nx, ny;
130 MSGraph<T> pp;
132
133 pp.mimicry(vp);
134 for (int i=0; i<pp.xs*pp.ys*pp.zs; i++) pp.gp[i] = vp.gp[i];
135
136 MSGraph_Paint(pp, 0, 0, pp.zero, pp.zero, mx+1, 4);
137
138 for (int j=0; j<pp.ys; j++) {
139 ny = pp.xs*j;
140 for (int i=0; i<pp.xs; i++) {
141 nx = ny + i;
142 if (pp.gp[nx]==pp.zero) {
143 MSGraph_Paint(pp, i, j, pp.zero, pp.zero, mx, 8);
144 }
145 }
146 }
147
148 MSGraph_Paint(pp, 0, 0, mx+1, mx+1, pp.zero, 4);
149
150 vt = dgree_circle_MSGraph<T>(pp);
151
152 for (int j=0; j<pp.ys; j++) {
153 ny = pp.xs*j;
154 for (int i=0; i<pp.xs; i++) {
155 nx = ny + i;
156 if (pp.gp[nx]>=mn && pp.gp[nx]<=mx) {
157 MSGraph_Paint(pp, i, j, mn, mx, pp.zero, 8);
158 cnt++;
159 }
160 }
161 }
162 pp.free();
163 vt.x = (double)cnt;
164
165 return vt;
166}
167
168
169/*
170template <typename T> double count_around_MSGraph(MSGraph<T> vp)
171
1722D画像において,vp.zero以外の輝度値のオブジェクトの周囲長を測る.@n
173穴空きのオブジェクトも計算可能.独自アルゴリズム(C) 2002
174
175面積が 4以下では不正確になる.@n
176縁にかかる画像に関しては正確に計算できない.=> 縁をvp.zeroで埋めること.
177
178@return 周囲長
179*/
180template <typename T> double count_around_MSGraph(MSGraph<T> vp)
181{
182 int i, j, m, n, cc;
183 bool sflg;
184 double cnt;
185 const double qs = 0.70710678118654752440084436210; // sqrt(2.)/2.
186 MSGraph<T> xp;
187
188 xp = zoom_MSGraph(vp, 2, OFF);
189 if (xp.isNull()) return -1.0;
190
191 cnt = 0.0;
192 for (j=1; j<xp.ys-1; j+=2) {
193 for (i=1; i<xp.xs-1; i+=2) {
194 cc = 0;
195 sflg = false;
196 for (n=0; n<2; n++) {
197 for (m=0; m<2; m++) {
198 if (xp.point(i+m, j+n)!=vp.zero) {
199 cc++;
200 if (n>0) if (xp.point(i+(1-m), j)!=vp.zero) sflg = true; // 対角チェック
201 }
202 }
203 }
204
205 if (cc==1 || cc==3) cnt += qs;
206 else if (cc==2) {
207 if (sflg==false) cnt += 1;
208 else cnt += 2;
209 }
210 }
211 }
212 xp.free();
213
214 return cnt;
215}
216
217
223template <typename T> int count_area_MSGraph(MSGraph<T> xp)
224{
225 int ss = 0;
226
227 for (int i=0; i<xp.xs*xp.ys*xp.zs; i++) {
228 if (xp.gp[i]!=xp.zero) ss++;
229 }
230 return ss;
231}
232
233
234template <typename T> int count_object_MSGraph(MSGraph<T> xp, int mn, int mx)
235{
236 int cnt = 0;
237 int nx, ny;
238 MSGraph<T> pp;
239
240 pp.mimicry(xp);
241 for (int i=0; i<pp.xs*pp.ys*pp.zs; i++) pp.gp[i] = xp.gp[i];
242
243 MSGraph_Paint(pp, 0, 0, pp.zero, pp.zero, mx+1, 4);
244
245 for (int j=0; j<pp.ys; j++) {
246 ny = pp.xs*j;
247 for (int i=0; i<pp.xs; i++) {
248 nx = ny + i;
249 if (pp.gp[nx]==pp.zero) {
250 MSGraph_Paint(pp, i, j, pp.zero, pp.zero, mx, 8);
251 }
252 }
253 }
254
255 MSGraph_Paint(pp, 0, 0, mx+1, mx+1, pp.zero, 4);
256
257 for (int j=0; j<pp.ys; j++) {
258 ny = pp.xs*j;
259 for (int i=0; i<pp.xs; i++) {
260 nx = ny + i;
261 if (pp.gp[nx]>=mn && pp.gp[nx]<=mx) {
262 MSGraph_Paint(pp, i, j, mn, mx, pp.zero, 8);
263 cnt++;
264 }
265 }
266 }
267 pp.free();
268
269 return cnt;
270}
271
272
295template <typename T> RBound<int> out_around_MSGraph(MSGraph<T> vp, int x, int y, int mode=8)
296{
297 int i, j, sp, cp, w, ll, ss;
298 int xx, yy, vx, vy, ix;
299 bool eflg=false;
300
301 int r8[8]={-1, 1, -1, -1, 1, -1, 1, 1};
302 int r4[8]={ 0, 1, -1, 0, 0, -1, 1, 0};
303 int* cc;
304
305 i = x;
306 // オブジェクトを探す
307 for (j=y; j<vp.ys-1; j++) {
308 for (i=x; i<vp.xs-1; i++) {
309 if (vp.gp[i+(j)*vp.xs]!=vp.zero) {
310 eflg = true;
311 break;
312 }
313 }
314 if (eflg) break;
315 }
316 x = i;
317 y = j;
318 eflg = false;
319
320 RBound<int> rb(x, x, y, y);
321 i = y*vp.xs + x;
322
323 sp = cp = i;
324 ss = ll = 0;
325 vx = 1;
326 vy = 0;
327
328 if (mode==4) {
329 ix = 4;
330 cc = r4;
331 }
332 else {
333 ix = 8;
334 cc = r8;
335 }
336
337 do {
338 w = abs(vx)+abs(vy);
339 xx = (vx*cc[0]+vy*cc[1])/w;
340 yy = (vx*cc[2]+vy*cc[3])/w;
341 for (j=1; j<=ix; j++) {
342 if (vp.gp[cp+yy*vp.xs+xx]!=vp.zero) {
343 vx = xx;
344 vy = yy;
345 cp = cp + yy*vp.xs + xx;
346 xx = cp%vp.xs;
347 yy = (cp-xx)/vp.xs;
348 rb.xmax = Max(rb.xmax, xx);
349 rb.ymax = Max(rb.ymax, yy);
350 rb.xmin = Min(rb.xmin, xx);
351 rb.ymin = Min(rb.ymin, yy);
352 break;
353 }
354 else {
355 if(sp==cp && xx==-1 && yy==vp.zero) {
356 eflg = true;
357 break;
358 }
359 w = abs(xx)+abs(yy);
360 vx = (xx*cc[4]+yy*cc[5])/w;
361 vy = (xx*cc[6]+yy*cc[7])/w;
362 xx = vx;
363 yy = vy;
364 }
365 }
366 ll++;
367 if (abs(vx)+abs(vy)==2) ss++;
368 } while(!eflg);
369
370 if (mode==4) ss = 0;
371 (rb.xmax)++;
372 (rb.ymax)++;
373 (rb.xmin)--;
374 (rb.ymin)--;
375 rb.zmax = ss;
376 rb.zmin = ll;
377 return rb;
378}
379
380
386template <typename T> RBound<int> get_boundary_MSGraph(MSGraph<T> vp, T mn, T mx)
387{
388 int nx, ny, nz, ps;
389 RBound<int> rb;
390
391 rb.set(vp.xs, 0, vp.ys, 0, vp.zs, 0);
392
393 ps = vp.xs*vp.ys;
394 for (int k=0; k<vp.zs; k++) {
395 nz = k*ps;
396 for (int j=0; j<vp.ys; j++) {
397 ny = j*vp.xs + nz;
398 for (int i=0; i<vp.xs; i++) {
399 nx = i + ny;
400 if (vp.gp[nx]>=mn && vp.gp[nx]<=mx) {
401 rb.fusion((T)i, (T)j, (T)k);
402 }
403 }
404 }
405 }
406 rb.cutdown(vp.rbound);
407
408 return rb;
409}
410
411
421template <typename T, typename R> void cat_MSGraph(MSGraph<R> src, MSGraph<T>& dst)
422{
423 if ((void*)src.gp==(void*)dst.gp) return;
424
425 int i, x, y, z;
426 MSGraph<T> vp;
427 RBound<int> rb;
428
429 rb.xmin = Min(src.rbound.xmin, dst.rbound.xmin);
430 rb.ymin = Min(src.rbound.ymin, dst.rbound.ymin);
431 rb.zmin = Min(src.rbound.zmin, dst.rbound.zmin);
432 rb.xmax = Max(src.rbound.xmax, dst.rbound.xmax);
433 rb.ymax = Max(src.rbound.ymax, dst.rbound.ymax);
434 rb.zmax = Max(src.rbound.zmax, dst.rbound.zmax);
435
436 vp.set(rb.xmax-rb.xmin+1, rb.ymax-rb.ymin+1, rb.zmax-rb.zmin+1, dst.zero, dst.base, dst.RZxy);
437 if (vp.gp==NULL) return;
438 vp.rbound = rb;
439 vp.max = Max((T)src.max, dst.max);
440 vp.min = Min((T)src.min, dst.min);
441
442 for (i=0; i<dst.xs*dst.ys*dst.zs; i++) {
443 if (dst.gp[i]!=dst.zero) {
444 x = i%dst.xs + dst.rbound.xmin - rb.xmin;
445 y = (i/dst.xs)%dst.ys + dst.rbound.ymin - rb.ymin;
446 z = i/(dst.xs*dst.ys) + dst.rbound.zmin - rb.zmin;
447 vp.gp[z*vp.xs*vp.ys + y*vp.xs + x] = dst.gp[i];
448 }
449 }
450
451 for (i=0; i<src.xs*src.ys*src.zs; i++) {
452 if (src.gp[i]!=src.zero) {
453 x = i%src.xs + src.rbound.xmin - rb.xmin;
454 y = (i/src.xs)%src.ys + src.rbound.ymin - rb.ymin;
455 z = i/(src.xs*src.ys) + src.rbound.zmin - rb.zmin;
456 vp.gp[z*vp.xs*vp.ys + y*vp.xs + x] = (T)src.gp[i];
457 }
458 }
459
460 dst.free();
461 dst = vp;
462 return;
463}
464
465
475template <typename T, typename R> void cat_MSGraph(MSGraph<R>* src, MSGraph<T>* dst)
476{
477 if (src==NULL || dst==NULL) return;
478 if ((void*)src->gp==(void*)dst->gp) return;
479
480 int i, x, y, z;
481 MSGraph<T> vp;
482 RBound<int> rb;
483
484 rb.xmin = Min(src->rbound.xmin, dst->rbound.xmin);
485 rb.ymin = Min(src->rbound.ymin, dst->rbound.ymin);
486 rb.zmin = Min(src->rbound.zmin, dst->rbound.zmin);
487 rb.xmax = Max(src->rbound.xmax, dst->rbound.xmax);
488 rb.ymax = Max(src->rbound.ymax, dst->rbound.ymax);
489 rb.zmax = Max(src->rbound.zmax, dst->rbound.zmax);
490
491 vp.set(rb.xmax-rb.xmin+1, rb.ymax-rb.ymin+1, rb.zmax-rb.zmin+1, dst->zero, dst->base, dst->RZxy);
492 if (vp.gp==NULL) return;
493 vp.rbound = rb;
494 vp.max = Max((T)src->max, dst->max);
495 vp.min = Min((T)src->min, dst->min);
496
497 for (i=0; i<dst->xs*dst->ys*dst->zs; i++) {
498 if (dst->gp[i]!=dst->zero) {
499 x = i%dst->xs + dst->rbound.xmin - rb.xmin;
500 y = (i/dst->xs)%dst->ys + dst->rbound.ymin - rb.ymin;
501 z = i/(dst->xs*dst->ys) + dst->rbound.zmin - rb.zmin;
502 vp.gp[z*vp.xs*vp.ys + y*vp.xs + x] = dst->gp[i];
503 }
504 }
505
506 for (i=0; i<src->xs*src->ys*src->zs; i++) {
507 if (src->gp[i]!=src->zero) {
508 x = i%src->xs + src->rbound.xmin - rb.xmin;
509 y = (i/src->xs)%src->ys + src->rbound.ymin - rb.ymin;
510 z = i/(src->xs*src->ys) + src->rbound.zmin - rb.zmin;
511 vp.gp[z*vp.xs*vp.ys + y*vp.xs + x] = (T)src->gp[i];
512 }
513 }
514
515 dst->free();
516 *dst = vp;
517 return;
518}
519
520
530template <typename R, typename T> void copy_MSGraph(MSGraph<R> src, MSGraph<T>& dst)
531{
532 if ((void*)src.gp==(void*)dst.gp) return;
533
534 MSGraph<T> vp;
535
536 vp.getm(src.xs, src.ys, src.zs, (T)src.zero);
537 if (vp.gp==NULL) {
538 dst.free();
539 dst.gp = NULL;
541 return;
542 }
543
544 vp.max = (T)src.max;
545 vp.min = (T)src.min;
546 vp.base = (T)src.base;
547 vp.color = src.color;
548 vp.state = src.state;
549 for (int i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = (T)src.gp[i];
550
551 dst.free();
552 dst = vp;
553 return;
554}
555
556
566template <typename R, typename T> void copy_MSGraph(MSGraph<R>* src, MSGraph<T>* dst)
567{
568 if (src==NULL || dst==NULL) return;
569 if ((void*)src->gp==(void*)dst->gp) return;
570
571 MSGraph<T> vp;
572
573 vp.getm(src->xs, src->ys, src->zs, (T)src->zero);
574 if (vp.gp==NULL) {
575 dst->free();
576 dst->gp = NULL;
578 return;
579 }
580
581 vp.max = (T)src->max;
582 vp.min = (T)src->min;
583 vp.base = (T)src->base;
584 vp.color = src->color;
585 vp.state = src->state;
586 for (int i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = (T)src->gp[i];
587
588 dst->free();
589 *dst = vp;
590 return;
591}
592
593
602template <typename T> MSGraph<T> dup_MSGraph(MSGraph<T> src)
603{
604 MSGraph<T> vp;
605
606 vp.init();
607 if (src.isNull()) {
609 return vp;
610 }
611
612 vp = src;
613 vp.getm(src.xs, src.ys, src.zs, src.zero);
614 if (vp.gp==NULL) {
615 vp.init();
617 return vp;
618 }
619
620 for (int i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = src.gp[i];
621
622 return vp;
623}
624
625
634template <typename T> MSGraph<T>* dup_MSGraph(MSGraph<T>* src)
635{
636 if (src==NULL) return NULL;
637 MSGraph<T>* vp = new MSGraph<T>();
638
639 vp->init();
640 if (src->isNull()) {
642 return vp;
643 }
644
645 *vp = *src;
646 vp->getm(src->xs, src->ys, src->zs, src->zero);
647 if (vp->gp==NULL) {
648 vp->init();
650 return vp;
651 }
652
653 for (int i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = src->gp[i];
654
655 return vp;
656}
657
658
674template <typename T> void ToPola(Vector<T> nv, double& cst, double& snt, double& csf, double& snf, double pcsf=0.0, double psnf=1.0)
675{
676 if (nv.n!=1.0) nv.normalize();
677 if (nv.z<-1.0) nv.z = -1.0;
678 if (nv.z> 1.0) nv.z = 1.0;
679 cst = nv.z;
680 snt = sqrt(1.0-nv.z*nv.z);
681
682 if (snt<Sin_Tolerance) {
683 cst = Sign(cst);
684 snt = 0.0;
685 csf = pcsf;
686 snf = psnf;
687 }
688 else {
689 csf = nv.x/snt;
690 snf = nv.y/snt;
691 }
692/*
693 if (*snt<Sin_Tolerance) {
694 *cst = Sign(*cst);
695 *snt = 0.0;
696 }
697
698 double rr = sqrt(nv.x*nv.x + nv.y*nv.y);
699 if (rr<=Zero_Eps) {
700 *csf = 0.0;
701 *snf = 1.0;
702 }
703 else {
704 *csf = nv.x/rr;
705 *snf = nv.y/rr;
706 }
707*/
708 return;
709}
710
711
729template <typename T, typename R>
730 void Local2World(MSGraph<T> gd, MSGraph<T> vp, Vector<R> oq, Vector<R> op, Vector<R> ex, double* pcsf=NULL, double* psnf=NULL)
731{
732 int x, y, z, cx, cy, cz;
733 double px, py, pz, xx, yy, zz;
734 double cst, snt, csf=0.0, snf=1.0;
735
736 if (pcsf!=NULL && psnf!=NULL) {
737 csf = *pcsf;
738 snf = *psnf;
739 }
740
741 ToPola(ex, cst, snt, csf, snf, csf, snf);
742
743 for (z=0; z<vp.zs; z++) {
744 cz = z*vp.xs*vp.ys;
745 for (y=0; y<vp.ys; y++) {
746 cy = cz + y*vp.xs;
747 for (x=0; x<vp.xs; x++) {
748 cx = cy + x;
749 if (vp.gp[cx]!=vp.zero) {
750 px = z - op.z; // ローカルな極座標系の原点へ
751 py = op.x - x;
752 pz = op.y - y;
753 xx = px*snt*csf - py*snf - pz*cst*csf + oq.x;
754 yy = px*snt*snf + py*csf - pz*cst*snf + oq.y;
755 zz = px*cst + pz*snt + oq.z;
756 gd.set_vPoint(xx, yy, zz, vp.gp[cx], ON);
757 }
758 }
759 }
760 }
761
762 if (pcsf!=NULL && psnf!=NULL) {
763 *pcsf = csf;
764 *psnf = snf;
765 }
766}
767
768
769template <typename T> void MSGraph_changeColor(MSGraph<T> vp, int f, int t)
770{
771 for (int i=0; i<vp.xs*vp.ys*vp.zs; i++) {
772 if (vp.gp[i]==(T)f) vp.gp[i] = (T)t;
773 }
774}
775
776
793template <typename T> int MSGraph_Paint(MSGraph<T> vp, int x, int y, int mn, int mx, int cc, int mode=8)
794{
795 int i, j, k, ss;
796
797 if (cc<=mx && cc>=mn) {
798 DEBUG_MODE PRINT_MESG("WARNING: MSGraph_Paint: c = %d. Not be %d< c <%d\n", cc, mn, mx);
799 return 0;
800 }
801
802 if (x<0 || x>=vp.xs || y<0 || y>=vp.ys) return 0;
803 if (vp.gp[y*vp.xs+x]>(T)mx || vp.gp[y*vp.xs+x]<(T)mn) return 0;
804
805 while(x>0) {
806 if (vp.gp[y*vp.xs+x-1]>(T)mx || vp.gp[y*vp.xs+x-1]<(T)mn) break;
807 x--;
808 }
809 k = x;
810
811 ss = 0;
812 while(k<vp.xs) {
813 if (vp.gp[y*vp.xs+k]>(T)mx || vp.gp[y*vp.xs+k]<(T)mn) break;
814 vp.gp[y*vp.xs+k] = (T)cc;
815 ss++;
816 k++;
817 }
818 k--;
819
820 for (i=x; i<=k; i++){
821 if (y-1>=0 && y-1<vp.ys){
822 j = (y-1)*vp.xs+i;
823 if (vp.gp[j]<=(T)mx && vp.gp[j]>=(T)mn) {
824 ss += MSGraph_Paint(vp, i, y-1, mn, mx, cc, mode);
825 }
826
827 if (Xabs(mode)==8) { // 8-neighborhood
828 if (i-1>=0) {
829 if (vp.gp[j-1]<=(T)mx && vp.gp[j-1]>=(T)mn) {
830 ss += MSGraph_Paint(vp, i-1, y-1, mn, mx, cc, mode);
831 }
832 }
833 if (i+1<vp.xs) {
834 if (vp.gp[j+1]<=(T)mx && vp.gp[j+1]>=(T)mn) {
835 ss += MSGraph_Paint(vp, i+1, y-1, mn, mx, cc, mode);
836 }
837 }
838 }
839 }
840
841 if (y+1>=0 && y+1<vp.ys){
842 j = (y+1)*vp.xs+i;
843 if (vp.gp[j]<=(T)mx && vp.gp[j]>=(T)mn) {
844 ss += MSGraph_Paint(vp, i, y+1, mn, mx, cc, mode);
845 }
846
847 if (Xabs(mode)==8) { // 8-neighborhood
848 if (i-1>=0) {
849 if (vp.gp[j-1]<=(T)mx && vp.gp[j-1]>=(T)mn) {
850 ss += MSGraph_Paint(vp, i-1, y+1, mn, mx, cc, mode);
851 }
852 }
853 if (i+1<vp.xs) {
854 if (vp.gp[j+1]<=(T)mx && vp.gp[j+1]>=(T)mn) {
855 ss += MSGraph_Paint(vp, i+1, y+1, mn, mx, cc, mode);
856 }
857 }
858 }
859 }
860 }
861 return ss;
862}
863
864
883template <typename T> int MSGraph_Paint3D(MSGraph<T> vp, int x, int y, int z, int mn, int mx, int cc, int mode=8)
884{
885 int i, j, ps, ss;
886 MSGraph<T> xp;
887
888 ss = 0;
889 ps = vp.xs*vp.ys;
890 xp = vp;
891 xp.zs = 1;
892 xp.gp = &(vp.gp[z*ps]);
893
894 if (xp.gp[y*xp.xs+x]>(T)mx || xp.gp[y*xp.xs+x]<(T)mn) return 0;
895 ss += MSGraph_Paint(xp, x, y, mn, mx, cc, mode);
896 if (mode<0) {
897 DEBUG_MODE PRINT_MESG("WARNING: MSGraph_Paint3D: zz = %d\n", z);
898 }
899
900 for (i=0; i<ps; i++) {
901 if (xp.gp[i]==(T)cc) {
902 x = i%vp.xs;
903 y = i/vp.xs;
904 if (z-1>=0) {
905 j = (z-1)*ps+y*vp.xs+x;
906 if (vp.gp[j]<=(T)mx && vp.gp[j]>=(T)mn) {
907 ss += MSGraph_Paint3D(vp, x, y, z-1, mn, mx, cc, mode);
908 }
909 }
910 if (z+1<vp.zs) {
911 j = (z+1)*ps+y*vp.xs+x;
912 if (vp.gp[j]<=(T)mx && vp.gp[j]>=(T)mn) {
913 ss += MSGraph_Paint3D(vp, x, y, z+1, mn, mx, cc, mode);
914 }
915 }
916 }
917 }
918
919 return ss;
920}
921
922
939template <typename T> void MSGraph_Line(MSGraph<T> vp, int x1, int y1, int x2, int y2, int cc)
940{
941 int thresh=0, index;
942 int xunit=1;
943 int yunit=1;
944 int xdiff=x2-x1;
945 int ydiff=y2-y1;
946
947 if (xdiff<0) {
948 xdiff = -xdiff;
949 xunit = -1;
950 }
951 if (ydiff<0) {
952 ydiff = -ydiff;
953 yunit = -1;
954 }
955
956 if (xdiff>ydiff) {
957 for (index=0; index<xdiff+1; index++) {
958 if (x1>=0 && x1<vp.xs && y1>=0 && y1<vp.ys) {
959 vp.point(x1, y1) = (T)cc;
960 }
961 x1 = x1 + xunit;
962 thresh = thresh + ydiff;
963 if (thresh>=xdiff) {
964 thresh = thresh - xdiff;
965 y1 = y1 + yunit;
966 }
967 }
968 }
969 else {
970 for (index=0; index<ydiff+1; index++) {
971 if (x1>=0 && x1<vp.xs && y1>=0 && y1<vp.ys) {
972 vp.point(x1, y1) = (T)cc;
973 }
974 y1 = y1 + yunit;
975 thresh = thresh + xdiff;
976 if (thresh>=ydiff) {
977 thresh = thresh - ydiff;
978 x1 = x1 + xunit;
979 }
980 }
981 }
982}
983
984
1007template <typename T> void MSGraph_Triangle(MSGraph<T> vp, int x1, int y1, int x2, int y2, int x3, int y3, int cc, int mode=OFF)
1008{
1009 MSGraph_Line(vp, x1, y1, x2, y2, cc);
1010 MSGraph_Line(vp, x2, y2, x3, y3, cc);
1011 MSGraph_Line(vp, x3, y3, x1, y1, cc);
1012
1013 if (mode==ON) {
1014 MSGraph_Paint(vp, (x1+x2+x3)/3, (y1+y2+y3)/3, (int)vp.zero, cc-1, cc, 4);
1015 }
1016 return;
1017}
1018
1019
1036template <typename T> void MSGraph_Box(MSGraph<T> vp, int x1, int y1, int x2, int y2, int cc, int mode=OFF)
1037{
1038 MSGraph_Line(vp, x1, y1, x2, y1, cc);
1039 MSGraph_Line(vp, x2, y1, x2, y2, cc);
1040 MSGraph_Line(vp, x2, y2, x1, y2, cc);
1041 MSGraph_Line(vp, x1, y2, x1, y1, cc);
1042
1043 if (mode==ON) {
1044 MSGraph_Paint(vp, (x1+x2)/2, (y1+y2)/2, (int)vp.zero, cc-1, cc, 4);
1045 }
1046 return;
1047}
1048
1049
1061template <typename T> void MSGraph_Line3D(MSGraph<T> vp, int x1, int y1, int z1, int x2, int y2, int z2, int cc)
1062{
1063 int i;
1064 int xx, yy, zz, dx, dy, dz;
1065 int ux=1, uy=1, uz=1;
1066 int sx=0, sy=0, sz=0;
1067
1068 dx = x2 - x1;
1069 dy = y2 - y1;
1070 dz = z2 - z1;
1071
1072 if (dx<0) {
1073 dx = -dx;
1074 ux = -1;
1075 }
1076 if (dy<0) {
1077 dy = -dy;
1078 uy = -1;
1079 }
1080 if (dz<0) {
1081 dz = -dz;
1082 uz = -1;
1083 }
1084
1085 xx = x1;
1086 yy = y1;
1087 zz = z1;
1088
1089 if (xx>=0 && xx<vp.xs && yy>=0 && yy<vp.ys && zz>=0 && zz<vp.zs) {
1090 vp.point(xx, yy, zz) = (T)cc;
1091 }
1092 if (dx>=dy && dx>=dz) {
1093 for (i=1; i<=dx; i++) {
1094 xx = xx + ux;
1095 sy = sy + dy;
1096 sz = sz + dz;
1097 if (sy>dx) {
1098 sy = sy - dx;
1099 yy = yy + uy;
1100 }
1101 if (sz>dx) {
1102 sz = sz - dx;
1103 zz = zz + uz;
1104 }
1105 if (xx>=0 && xx<vp.xs && yy>=0 && yy<vp.ys && zz>=0 && zz<vp.zs) {
1106 vp.point(xx, yy, zz) = (T)cc;
1107 }
1108 }
1109 }
1110 else if (dy>dx && dy>=dz) {
1111 for (i=1; i<=dy; i++) {
1112 yy = yy + uy;
1113 sx = sx + dx;
1114 sz = sz + dz;
1115 if (sx>dy) {
1116 sx = sx - dy;
1117 xx = xx + ux;
1118 }
1119 if (sz>dy) {
1120 sz = sz - dy;
1121 zz = zz + uz;
1122 }
1123 if (xx>=0 && xx<vp.xs && yy>=0 && yy<vp.ys && zz>=0 && zz<vp.zs) {
1124 vp.point(xx, yy, zz) = (T)cc;
1125 }
1126 }
1127 }
1128 else {
1129 for (i=1; i<=dz; i++) {
1130 zz = zz + uz;
1131 sx = sx + dx;
1132 sy = sy + dy;
1133 if (sx>dz) {
1134 sx = sx - dz;
1135 xx = xx + ux;
1136 }
1137 if (sy>dz) {
1138 sy = sy - dz;
1139 yy = yy + uy;
1140 }
1141 if (xx>=0 && xx<vp.xs && yy>=0 && yy<vp.ys && zz>=0 && zz<vp.zs) {
1142 vp.point(xx, yy, zz) = (T)cc;
1143 }
1144 }
1145 }
1146}
1147
1148
1160template <typename T> void MSGraph_Circle(MSGraph<T> vp, int x, int y, int r, int cc, int mode=OFF)
1161{
1162 double yy, dy, dt;
1163 int i, nn, cx;
1164 int ix, iy, ux=1;
1165 int *px, *py;
1166
1167 if (r<=0) return;
1168
1169 px = (int*)malloc(sizeof(int)*(r+1));
1170 py = (int*)malloc(sizeof(int)*(r+1));
1171 if (px==NULL || py==NULL) {
1172 if (px!=NULL) free(px);
1173 if (py!=NULL) free(py);
1174 return;
1175 }
1176 memset(px, 0, sizeof(int)*(r+1));
1177 memset(py, 0, sizeof(int)*(r+1));
1178
1179 ix = 0;
1180 iy = r;
1181 yy = (double)r;
1182 nn = 0;
1183 px[0] = ix;
1184 py[0] = iy;
1185
1186 cx = (y+iy)*vp.xs + (x+ix);
1187 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.gp[cx] = (T)cc;
1188 while(iy>=ix) {
1189 ix = ix + ux;
1190 dt = -ux/yy;
1191 dy = ix*dt;
1192 yy = yy + dy;
1193 iy = (int)yy;
1194
1195 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1196 nn++;
1197 px[nn] = ix;
1198 py[nn] = iy;
1199 }
1200
1201 for (i=0; i<=nn; i++) {
1202 ix = py[nn-i];
1203 iy = px[nn-i];
1204 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1205 }
1206
1207 for (i=0; i<=nn; i++) {
1208 ix = py[i];
1209 iy = -px[i];
1210 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1211 }
1212
1213 for (i=0; i<=nn; i++) {
1214 ix = px[nn-i];
1215 iy = -py[nn-i];
1216 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1217 }
1218
1219 for (i=0; i<=nn; i++) {
1220 ix = -px[i];
1221 iy = -py[i];
1222 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1223 }
1224
1225 for (i=0; i<=nn; i++) {
1226 ix = -py[nn-i];
1227 iy = -px[nn-i];
1228 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1229 }
1230
1231 for (i=0; i<=nn; i++) {
1232 ix = -py[i];
1233 iy = px[i];
1234 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1235 }
1236
1237 for (i=0; i<=nn; i++) {
1238 ix = -px[nn-i];
1239 iy = py[nn-i];
1240 if (x+ix>=0 && x+ix<vp.xs && y+iy>=0 && y+iy<vp.ys) vp.point(x+ix, y+iy) = (T)cc;
1241 }
1242
1243 if (mode==ON) MSGraph_Paint(vp, x, y, (int)vp.zero, cc-1, cc, 4);
1244
1245 free(px);
1246 free(py);
1247}
1248
1249
1263template <typename T> void MSGraph_Circle3D(MSGraph<T> vp, Vector<> ox, Vector<> ex, int rr, int cc, int mode=OFF)
1264{
1265 MSGraph<T> xp(2*rr+3, 2*rr+3);
1266 if (xp.gp==NULL) return;
1267
1268 Vector<> oz((xp.xs-1)/2., (xp.ys-1)/2., 0.0);
1269
1270 MSGraph_Circle(xp, rr+1, rr+1, rr, cc, mode);
1271 Local2World(vp, xp, ox, oz, ex);
1272 xp.free();
1273}
1274
1275
1276
1288template <typename T> void MSGraph_Pool(MSGraph<T> vp, Vector<> a, Vector<> b, int rr, int cc)
1289{
1290 int i, cz;
1291 Vector<> ox, oz;
1292 MSGraph<T> xp, pp;
1293
1294 ox = a - b;
1295 ox.norm();
1296 xp.set(2*rr+3, 2*rr+3, (int)(ox.n + 0.5));
1297 if (xp.gp==NULL) return;
1298
1299 pp = xp;
1300 for (i=0; i<xp.zs; i++) {
1301 cz = i*xp.xs*xp.ys;
1302 pp.gp = &(xp.gp[cz]);
1303 MSGraph_Circle(pp, rr+1, rr+1, rr, cc, ON);
1304 }
1305
1306 oz.set((xp.xs-1)/2.0, (xp.ys-1)/2.0, (xp.zs-1)/2.0);
1307 Local2World(vp, xp, (a+b)/2.0, oz, ox);
1308 xp.free();
1309 return;
1310}
1311
1312
1326template <typename T>
1327 void MSGraph_Torus(MSGraph<T> vp, Vector<> ox, Vector<> ex, int rr, int ra, int cc)
1328{
1329 int i, nn;
1330 double dt, th, xx, yy, zz, sn, cs;
1331 MSGraph<T> xp;
1332 Vector<> ve, vo, vz;
1333
1334 xp.set(2*(rr+ra)+3, 2*(rr+ra)+3, 2*ra+3);
1335 if (xp.gp==NULL) return;
1336 nn = (int)(2.0*PI*(rr+ra)*2 + 0.5);
1337 dt = 2.0*PI/nn;
1338
1339 zz = (xp.zs-1)/2.0;
1340 for (i=0; i<nn; i++) {
1341 th = dt*i;
1342 sn = sin(th);
1343 cs = cos(th);
1344 xx = (xp.xs-1)/2.0 + rr*cs;
1345 yy = (xp.ys-1)/2.0 - rr*sn;
1346 vo.set(xx, yy, zz);
1347 ve.set(sn, cs, 0.0);
1348 MSGraph_Circle3D(xp, vo, ve, ra, cc, ON);
1349 }
1350 vz.set((xp.xs-1)/2., (xp.ys-1)/2., (xp.zs-1)/2.);
1351
1352 Local2World(vp, xp, ox, vz, ex);
1353 xp.free();
1354
1355 return;
1356}
1357
1358
1373template <typename T> void MSGraph_Sphere(MSGraph<T> vp, Vector<> a, int r, int cc, int mode=1)
1374{
1375 int i, j, k, rx, nn, s=1; // s: 壁を作る場合の境界からの距離
1376 double th, fi, cs, sn, cf, sf, dt;
1377 double xx, yy, zz;
1378 MSGraph<T> xp;
1379
1380 if (mode==1) {
1381 xp = vp;
1382 for (k=(int)(a.z-r+0.5); k<=(int)(a.z+r+0.5); k++) {
1383 if (k>=0 && k<vp.zs) {
1384 xp.gp = &vp.gp[k*vp.xs*vp.ys];
1385 rx = (int)(sqrt(r*r-(a.z-k)*(a.z-k))+0.5);
1386 MSGraph_Circle(xp, (int)(a.x+0.5), (int)(a.y+0.5), rx, cc, ON);
1387 }
1388 }
1389 }
1390 else {
1391 nn = (int)(2*PI*r + 0.5)*2;
1392 dt = PI/nn;
1393 for (i=0; i<=nn; i++) {
1394 th = dt*i;
1395 sn = sin(th);
1396 cs = cos(th);
1397 zz = r*cs + a.z;
1398 if (mode==-1) {
1399 if (zz<s) zz = s;
1400 if (zz>vp.zs-s-1) zz = vp.zs - s - 1;
1401 }
1402 for (j=0; j<=2*nn; j++) {
1403 fi = dt*j;
1404 cf = cos(fi);
1405 sf = sin(fi);
1406 xx = r*sn*cf + a.x;
1407 yy = r*sn*sf + a.y;
1408 if (mode==-1) {
1409 if (xx<s) xx = s;
1410 if (yy<s) yy = s;
1411 if (xx>vp.xs-s-1) xx = vp.xs - s - 1;
1412 if (yy>vp.ys-s-1) yy = vp.ys - s - 1;
1413 }
1414 vp.set_vPoint(xx, yy, zz, (T)cc, ON);
1415 }
1416 }
1417 }
1418 return;
1419}
1420
1421
1435template <typename T> MSGraph<T> cut_object_MSGraph(MSGraph<T> vp, int mn, int mx, int blank=BOUNDARY_BLANK, bool ecnt=false)
1436{
1437 int i, j, k, n;
1438 int cx, cy, cz, cp;
1439 int ax, ay, az, ap;
1440 MSGraph<T> xp; // = new MSGraph<T>();
1441
1442 xp.init();
1443 RBound<int> rb(vp.xs-1, 0, vp.ys-1, 0, vp.zs-1, 0);
1444 RBound<int> rx(0, vp.xs-1, 0, vp.ys-1, 0, vp.zs-1);
1445 CVCounter* counter = NULL;
1446
1447 if (ecnt) counter = GetUsableGlobalCounter();
1448 if (counter!=NULL) {
1449 if (counter->isCanceled()) {
1451 return xp;
1452 }
1453 counter->SetMax(vp.zs*2);
1454 }
1455
1456 ap = vp.xs*vp.ys;
1457 n = 0;
1458 for (k=0; k<vp.zs; k++) {
1459 az = ap*k;
1460 for (j=0; j<vp.ys; j++) {
1461 ay = az + vp.xs*j;
1462 for (i=0; i<vp.xs; i++) {
1463 ax = ay + i;
1464 if (vp.gp[ax]>=(T)mn && vp.gp[ax]<=(T)mx) {
1465 n++;
1466 rb.fusion(i, j, k);
1467 }
1468 }
1469 }
1470
1471 // Counter
1472 if (counter!=NULL) {
1473 counter->StepIt();
1474 if (counter->isCanceled()) {
1476 return xp;
1477 }
1478 }
1479 }
1480
1481 if (n==0) {
1483 return xp;
1484 }
1485
1486 if (blank>0) rb.enlarge(blank);
1487 rb.commonarea(rx);
1488
1489 xp.set(rb.xmax-rb.xmin+1, rb.ymax-rb.ymin+1, rb.zmax-rb.zmin+1, vp.zero, vp.base, vp.RZxy);
1490 if (xp.isNull()) {
1492 return xp;
1493 }
1494 xp.rbound = rb;
1495 xp.min = (T)mx;
1496 xp.max = (T)mn;
1497 xp.color = vp.color;
1498
1499 cp = xp.xs*xp.ys;
1500 for (k=0; k<xp.zs; k++) {
1501 cz = cp*k;
1502 az = ap*(k+rb.zmin);
1503 for (j=0; j<xp.ys; j++) {
1504 cy = cz + xp.xs*j;
1505 ay = az + vp.xs*(j+rb.ymin);
1506 for (i=0; i<xp.xs; i++) {
1507 cx = cy + i;
1508 ax = ay + (i+rb.xmin);
1509 if (vp.gp[ax]>=(T)mn && vp.gp[ax]<=(T)mx) {
1510 xp.gp[cx] = vp.gp[ax];
1511 xp.max = Max(xp.max, xp.gp[cx]);
1512 xp.min = Min(xp.min, xp.gp[cx]);
1513 }
1514 }
1515 }
1516
1517 // Counter
1518 if (counter!=NULL) {
1519 counter->StepIt();
1520 if (counter->isCanceled()) {
1522 return xp;
1523 }
1524 }
1525 }
1526
1527 xp.rbound.cutdown(vp.rbound);
1528
1529 return xp;
1530}
1531
1532
1547template <typename T> MSGraph<T> cut_object_MSGraph(MSGraph<T> vp, int mn, int mx, RBound<int> rbound, int blank=BOUNDARY_BLANK, bool ecnt=false)
1548{
1549 int i, j, k, n;
1550 int cx, cy, cz, cp;
1551 int ax, ay, az, ap;
1552 MSGraph<T> xp; // = new MSGraph<T>();
1553
1554 xp.init();
1555 RBound<int> rb(vp.xs-1, 0, vp.ys-1, 0, vp.zs-1, 0);
1556 RBound<int> rx(0, vp.xs-1, 0, vp.ys-1, 0, vp.zs-1);
1557 CVCounter* counter = NULL;
1558
1559 if (ecnt) counter = GetUsableGlobalCounter();
1560 if (counter!=NULL) {
1561 if (counter->isCanceled()) {
1563 return xp;
1564 }
1565 counter->SetMax(vp.zs*2);
1566 }
1567
1568 rbound.commonarea(rx);
1569 ap = vp.xs*vp.ys;
1570 n = 0;
1571 for (k=rbound.zmin; k<=rbound.zmax; k++) {
1572 az = ap*k;
1573 for (j=rbound.ymin; j<=rbound.ymax; j++) {
1574 ay = az + vp.xs*j;
1575 for (i=rbound.xmin; i<=rbound.xmax; i++) {
1576 ax = ay + i;
1577 if (vp.gp[ax]>=(T)mn && vp.gp[ax]<=(T)mx) {
1578 n++;
1579 rb.fusion(i, j, k);
1580 }
1581 }
1582 }
1583
1584 // Counter
1585 if (counter!=NULL) {
1586 counter->StepIt();
1587 if (counter->isCanceled()) {
1589 return xp;
1590 }
1591 }
1592 }
1593
1594 if (n==0) {
1596 return xp;
1597 }
1598
1599 if (blank>0) rb.enlarge(blank);
1600 rb.commonarea(rbound);
1601
1602 xp.set(rb.xmax-rb.xmin+1, rb.ymax-rb.ymin+1, rb.zmax-rb.zmin+1, vp.zero, vp.base, vp.RZxy);
1603 if (xp.isNull()) {
1605 return xp;
1606 }
1607 xp.rbound = rb;
1608 xp.min = (T)mx;
1609 xp.max = (T)mn;
1610 xp.color = vp.color;
1611
1612 cp = xp.xs*xp.ys;
1613 for (k=0; k<xp.zs; k++) {
1614 cz = cp*k;
1615 az = ap*(k+rb.zmin);
1616 for (j=0; j<xp.ys; j++) {
1617 cy = cz + xp.xs*j;
1618 ay = az + vp.xs*(j+rb.ymin);
1619 for (i=0; i<xp.xs; i++) {
1620 cx = cy + i;
1621 ax = ay + i + rb.xmin;
1622 if (vp.gp[ax]>=(T)mn && vp.gp[ax]<=(T)mx) {
1623 xp.gp[cx] = vp.gp[ax];
1624 xp.max = Max(xp.max, xp.gp[cx]);
1625 xp.min = Min(xp.min, xp.gp[cx]);
1626 }
1627 }
1628 }
1629
1630 // Counter
1631 if (counter!=NULL) {
1632 counter->StepIt();
1633 if (counter->isCanceled()) {
1635 return xp;
1636 }
1637 }
1638 }
1639 xp.rbound.cutdown(vp.rbound);
1640
1641 return xp;
1642}
1643
1644
1656template <typename T> MSGraph<T> cut_object_MSGraph(MSGraph<T> vp, RBound<int> rb, bool ecnt=false)
1657{
1658 int i, j, k;
1659 int cx, cy, cz, cp;
1660 int ax, ay, az, ap;
1661 MSGraph<T> xp; // = new MSGraph<T>();
1662
1663 xp.init();
1664 RBound<int> rx(0, vp.xs-1, 0, vp.ys-1, 0, vp.zs-1);
1665 CVCounter* counter = NULL;
1666
1667 if (ecnt) counter = GetUsableGlobalCounter();
1668 if (counter!=NULL) {
1669 if (counter->isCanceled()) {
1671 return xp;
1672 }
1673 counter->SetMax(vp.zs*2);
1674 }
1675
1676 rb.commonarea(rx);
1677 xp.set(rb.xmax-rb.xmin+1, rb.ymax-rb.ymin+1, rb.zmax-rb.zmin+1, vp.zero, vp.base, vp.RZxy);
1678 if (xp.isNull()) {
1680 return xp;
1681 }
1682 xp.rbound = rb;
1683 xp.color = vp.color;
1684
1685 ap = vp.xs*vp.ys;
1686 cp = xp.xs*xp.ys;
1687
1688 for (k=0; k<xp.zs; k++) {
1689 cz = cp*k;
1690 az = ap*(k+rb.zmin);
1691 for (j=0; j<xp.ys; j++) {
1692 cy = cz + xp.xs*j;
1693 ay = az + vp.xs*(j+rb.ymin);
1694 for (i=0; i<xp.xs; i++) {
1695 cx = cy + i;
1696 ax = ay + i + rb.xmin;
1697 xp.gp[cx] = vp.gp[ax];
1698
1699 if (cx==0) xp.max = xp.min = xp.gp[cx];
1700 else {
1701 xp.max = Max(xp.max, xp.gp[cx]);
1702 xp.min = Min(xp.min, xp.gp[cx]);
1703 }
1704 }
1705 }
1706
1707 // Counter
1708 if (counter!=NULL) {
1709 counter->StepIt();
1710 if (counter->isCanceled()) {
1712 return xp;
1713 }
1714 }
1715 }
1716 xp.rbound.cutdown(vp.rbound);
1717
1718 return xp;
1719}
1720
1721
1733template <typename T> MSGraph<T> zoom_MSGraph(MSGraph<T> vp, double zm, int mode=ON)
1734{
1735 int xss, yss, ps, pz, py;
1736 MSGraph<T> vx;
1737
1738 vx.init();
1739
1740 if (vp.gp==NULL) {
1742 return vx;
1743 }
1744 if (zm==0.0) {
1746 return vx;
1747 }
1748 else if (zm<0.0) zm = -zm;
1749
1750 xss = (int)(vp.xs*zm) + 1;
1751 yss = (int)(vp.ys*zm) + 1;
1752
1753 vx.set(xss, yss, vp.zs);
1754 if (vx.isNull()) return vx;
1755 vx.color = vp.color;
1756
1757 ps = xss*yss;
1758
1759 if (mode==ON) {
1760 int ii, jj, kk, ll;
1761 double xx, yy, al, bt;
1762
1763 for(int k=0; k<vx.zs; k++) {
1764 pz = k*ps;
1765 for(int j=0; j<yss; j++) {
1766 py = pz + j*xss;
1767 for(int i=0; i<xss; i++) {
1768 xx = i/zm;
1769 yy = j/zm;
1770 ii = (int)xx;
1771 jj = (int)yy;
1772 if (ii>=vp.xs) ii = vp.xs - 1;
1773 if (jj>=vp.ys) jj = vp.ys - 1;
1774
1775 kk = ii + 1;
1776 ll = jj + 1;
1777 if (kk>=vp.xs) kk = vp.xs - 1;
1778 if (ll>=vp.ys) ll = vp.ys - 1;
1779
1780 if (xx>=0.) al = xx - ii;
1781 else al = 0.;
1782 if (yy>=0.) bt = yy - jj;
1783 else bt = 0.;
1784
1785 vx.gp[py+i] = (T)((1.-al)*(1.-bt)*vp.point(ii, jj, k) + al*(1.-bt)*vp.point(kk, jj, k)
1786 + (1.-al)*bt*vp.point(ii, ll, k) + al*bt*vp.point(kk, ll, k) + 0.5);
1787 }
1788 }
1789 }
1790 }
1791
1792 else {
1793 int ii, jj;
1794
1795 for(int k=0; k<vx.zs; k++) {
1796 pz = k*ps;
1797 for(int j=0; j<yss; j++) {
1798 py = pz + j*xss;
1799 for(int i=0; i<xss; i++) {
1800 ii = (int)(i/zm);
1801 jj = (int)(j/zm);
1802 vx.gp[py+i] = vp.point(ii, jj, k);
1803 }
1804 }
1805 }
1806 }
1807
1808 return vx;
1809}
1810
1811
1814template <typename T> MSGraph<T> reduce_MSGraph(MSGraph<T> vp, double rc, int mode=ON)
1815{
1816 int xss, yss, ps, pz, py;
1817 MSGraph<T> vx;
1818
1819 vx.init();
1820
1821 if (vp.gp==NULL) {
1823 return vx;
1824 }
1825 if (rc==0.0) {
1827 return vx;
1828 }
1829 else if (rc<0.0) rc = -rc;
1830
1831 xss = (int)(vp.xs/rc);
1832 yss = (int)(vp.ys/rc);
1833
1834 vx.set(xss, yss, vp.zs);
1835 if (vx.isNull()) return vx;
1836 vx.color = vp.color;
1837
1838 ps = xss*yss;
1839
1840 if (mode==ON) {
1841 int ii, jj, kk, ll, ss, nn;
1842
1843 for(int z=0; z<vx.zs; z++) {
1844 pz = z*ps;
1845 for(int j=0; j<yss; j++) {
1846 py = pz + j*xss;
1847 for(int i=0; i<xss; i++) {
1848 ii = (int)(i*rc);
1849 jj = (int)(j*rc);
1850 if (ii>=vp.xs) ii = vp.xs - 1;
1851 if (jj>=vp.ys) jj = vp.ys - 1;
1852
1853 ss = nn = 0;
1854 for(int l=jj; l<jj+(int)rc; l++) {
1855 ll = l;
1856 if (ll>=vp.ys) ll = vp.ys - 1;
1857 for(int k=ii; k<ii+(int)rc; k++) {
1858 kk = k;
1859 if (kk>=vp.xs) kk = vp.xs - 1;
1860 ss += vp.point(kk, ll, z);
1861 nn++;
1862 }
1863 }
1864 vx.gp[py+i] = ss/nn;
1865 }
1866 }
1867 }
1868 }
1869
1870 else {
1871 int ii, jj;
1872
1873 for(int k=0; k<vx.zs; k++) {
1874 pz = k*ps;
1875 for(int j=0; j<yss; j++) {
1876 py = pz + j*xss;
1877 for(int i=0; i<xss; i++) {
1878 ii = (int)(i*rc);
1879 jj = (int)(j*rc);
1880 if (ii>=vp.xs) ii = vp.xs - 1;
1881 if (jj>=vp.ys) jj = vp.ys - 1;
1882 vx.gp[py+i] = vp.point(ii, jj, k);
1883 }
1884 }
1885 }
1886 }
1887
1888 return vx;
1889}
1890
1891
1897template <typename T> MSGraph<T> rotate_MSGraph(MSGraph<T> vp, int xs, int ys, double cst, double snt, int mode=ON)
1898{
1899 MSGraph<T> vs;
1900 T pt;
1901 int i, j, m, n;
1902 int ps, px, pz;
1903 double u, t, x, y, a, b;
1904
1905 vs.set(xs, ys, vp.zs, vp.zero, vp.base);
1906 if (vs.isNull()) return vs;
1907 vs.color = vp.color;
1908
1909 ps = vs.xs*vs.ys;
1910
1911 for (int k=0; k<vs.zs; k++) {
1912 pz = k*ps;
1913 for (int jj=0; jj<vs.ys; jj++) {
1914 px = pz + jj*vs.xs;
1915 for (int ii=0; ii<vs.xs; ii++) {
1916 u = ii - (vs.xs-1)/2.;
1917 t = (vs.ys-1)/2. - jj;
1918 x = u*cst + t*snt;
1919 y = - u*snt + t*cst;
1920 a = x + (vp.xs-1)/2.;
1921 b = (vp.ys-1)/2. - y;
1922 i = (int)a;
1923 j = (int)b;
1924
1925 if (i<0 || i>=vp.xs || j<0 || j>=vp.ys) {
1926 pt = vs.zero;
1927 }
1928 else {
1929 if (mode==ON) {
1930 if (a>=0.) a = a - i;
1931 else a = 0.;
1932 if (b>=0.) b = b - j;
1933 else b = 0.;
1934
1935 m = i + 1;
1936 n = j + 1;
1937 if (m>=vp.xs) m = vp.xs - 1;
1938 if (n>=vp.ys) n = vp.ys - 1;
1939 pt = (T)((1.-a)*(1.-b)*vp.point(i, j, k) + (1.-a)*b*vp.point(i, n, k)
1940 + a*(1.-b)*vp.point(m, j, k) + a*b*vp.point(m, n, k) + 0.5);
1941 }
1942 else {
1943 pt = vp.point(i, j, k);
1944 }
1945 }
1946 vs.gp[px+ii] = pt;
1947 }
1948 }
1949 }
1950 return vs;
1951}
1952
1953
1956template <typename T> MSGraph<T> rotate_MSGraph(MSGraph<T> vp, double th, int mode=ON)
1957{
1958 MSGraph<T> vs;
1959 double cst = cos(th);
1960 double snt = cos(th);
1961 int xys = (int)sqrt(vp.xs*vp.xs+vp.ys*vp.ys) + 1;
1962
1963 vs = rotate_MSGraph<T>(vp, xys, xys, cst, snt, mode);
1964 return vs;
1965}
1966
1967
1978template <typename T> MSGraph<T> x_reverse_MSGraph(MSGraph<T> vp, bool ecnt=false)
1979{
1980 int i, j, k, cy, cz;
1981 MSGraph<T> wp;
1982 CVCounter* counter = NULL;
1983
1984 wp.init();
1985
1986 if (ecnt) counter = GetUsableGlobalCounter();
1987 if (counter!=NULL) {
1988 if (counter->isCanceled()) {
1990 return wp;
1991 }
1992 counter->SetMax(vp.zs);
1993 }
1994
1995 wp.set(vp.xs, vp.ys, vp.zs, vp.zero, vp.base, vp.RZxy);
1996 if (wp.isNull()) return wp;
1997 wp.color = vp.color;
1998
1999 for (k=0; k<vp.zs; k++) {
2000 cz = k*vp.xs*vp.ys;
2001 for (j=0; j<vp.ys; j++) {
2002 cy = cz + j*vp.xs;
2003 for (i=0; i<vp.xs; i++) {
2004 wp.gp[cy + i] = vp.gp[cy + vp.xs - 1 - i];
2005 }
2006 }
2007
2008 // Counter
2009 if (counter!=NULL) {
2010 counter->StepIt();
2011 if (counter->isCanceled()) {
2013 return wp;
2014 }
2015 }
2016 }
2017 return wp;
2018}
2019
2020
2030template <typename T> void set_around_MSGraph(MSGraph<T> vp, int cc=0, int size=1)
2031{
2032 int i, j, px1, px2;
2033/*
2034 for (i=0; i<vp.xs; i++){
2035 px1 = i;
2036 px2 = (vp.ys-1)*vp.xs + i;
2037 vp.gp[px1] = (T)cc;
2038 vp.gp[px2] = (T)cc;
2039 }
2040
2041 for (j=1; j<vp.ys-1; j++){
2042 px1 = j*vp.xs;
2043 px2 = (j+1)*vp.xs - 1;
2044 vp.gp[px1] = (T)cc;
2045 vp.gp[px2] = (T)cc;
2046 }
2047*/
2048 for(j=0; j<vp.ys; j++) {
2049 px1 = j*vp.xs;
2050 px2 = (j+1)*vp.xs-size;
2051 for(i=0; i<size; i++) {
2052 vp.gp[i+px1] = (T)cc;
2053 vp.gp[i+px2] = (T)cc;
2054 }
2055 }
2056
2057 for(j=0; j<size; j++) {
2058 px1 = j*vp.xs;
2059 px2 = (j+vp.ys-size)*vp.xs;
2060 for(i=0; i<vp.xs; i++) vp.gp[i+px1] = (T)cc;
2061 for(i=0; i<vp.xs; i++) vp.gp[i+px2] = (T)cc;
2062 }
2063
2064}
2065
2066
2079template <typename T> MSGraph<T> grab_MSGraph(MSGraph<T> vp, int x1, int y1, int x2, int y2, int zs=0, int ze=0)
2080{
2081 int i, j, k;
2082 int xs, xe, ys, ye;
2083 int xsize, ysize, zsize;
2084 MSGraph<T> xp;
2085
2086 xp.init();
2087 xs = Min(x1, x2);
2088 xe = Max(x1, x2);
2089 xs = Max(xs, 0);
2090 xe = Min(xe, vp.xs-1);
2091 ys = Min(y1, y2);
2092 ye = Max(y1, y2);
2093 ys = Max(ys, 0);
2094 ye = Min(ye, vp.ys-1);
2095 zs = Max(zs, 0);
2096 ze = Min(ze, vp.zs-1);
2097
2098 xsize = xe - xs + 1;
2099 ysize = ye - ys + 1;
2100 zsize = ze - zs + 1;
2101
2102 xp.set(xsize, ysize, zsize, vp.zero, vp.base);
2103 if (xp.isNull()) return xp;
2104 xp.color = vp.color;
2105
2106 xp.max = vp.point(xs, ys, zs);
2107 xp.min = xp.max;
2108
2109 for (k=0; k<zsize; k++) {
2110 for (j=0; j<ysize; j++) {
2111 for (i=0; i<xsize; i++) {
2112 T point = vp.point(xs+i, ys+j, zs+k);
2113 xp.point(i, j, k) = point;
2114 if (point>xp.max) xp.max = point;
2115 else if (point<xp.min) xp.min = point;
2116 }
2117 }
2118 }
2119
2120 xp.rbound.xmin = vp.rbound.xmin + xs;
2121 xp.rbound.xmax = vp.rbound.xmin + xe;
2122 xp.rbound.ymin = vp.rbound.ymin + ys;
2123 xp.rbound.ymax = vp.rbound.ymin + ye;
2124 xp.rbound.zmin = vp.rbound.zmin + zs;
2125 xp.rbound.zmax = vp.rbound.zmin + ze;
2126 return xp;
2127}
2128
2129
2143template <typename T> MSGraph<T>* grab_MSGraph(MSGraph<T>* vp, int x1, int y1, int x2, int y2, int zs=0, int ze=0)
2144{
2145 int i, j, k;
2146 int xs, xe, ys, ye;
2147 int xsize, ysize, zsize;
2148 MSGraph<T>* xp = new MSGraph<T>();
2149
2150 xp->init();
2151 xs = Min(x1, x2);
2152 xe = Max(x1, x2);
2153 xs = Max(xs, 0);
2154 xe = Min(xe, vp->xs-1);
2155 ys = Min(y1, y2);
2156 ye = Max(y1, y2);
2157 ys = Max(ys, 0);
2158 ye = Min(ye, vp->ys-1);
2159 zs = Max(zs, 0);
2160 ze = Min(ze, vp->zs-1);
2161
2162 xsize = xe - xs + 1;
2163 ysize = ye - ys + 1;
2164 zsize = ze - zs + 1;
2165
2166 xp->set(xsize, ysize, zsize, vp->zero, vp->base);
2167 xp->color = vp->color;
2168
2169 xp->max = vp->point(xs, ys, zs);
2170 xp->min = xp->max;
2171
2172 for (k=0; k<zsize; k++) {
2173 for (j=0; j<ysize; j++) {
2174 for (i=0; i<xsize; i++) {
2175 T point = vp->point(xs+i, ys+j, zs+k);
2176 xp->point(i, j, k) = point;
2177 if (point>xp->max) xp->max = point;
2178 else if (point<xp->min) xp->min = point;
2179 }
2180 }
2181 }
2182
2183 xp->rbound.xmin = vp->rbound.xmin + xs;
2184 xp->rbound.xmax = vp->rbound.xmin + xe;
2185 xp->rbound.ymin = vp->rbound.ymin + ys;
2186 xp->rbound.ymax = vp->rbound.ymin + ye;
2187 xp->rbound.zmin = vp->rbound.zmin + zs;
2188 xp->rbound.zmax = vp->rbound.zmin + ze;
2189 return xp;
2190}
2191
2192
2212template <typename T> int addPaint_MSGraph(MSGraph<T> xp, int x, int y, int mn, int mx, int add, int mode=8)
2213{
2214 int i, k, cc, cx, st, ed, num=0;
2215
2216 if (x<0 || x>=xp.xs || y<0 || y>=xp.ys) return 0;
2217
2218 // 左端へ
2219 cc = (int)xp.point(x, y);
2220 while(x>0) {
2221 cx = (int)xp.point(x-1, y);
2222 if (cx>mx || cx<mn) break;
2223 cc = cx;
2224 x--;
2225 }
2226 st = k = x;
2227
2228 // 右方向へ塗りつぶし
2229 while(k<xp.xs) {
2230 cx = (int)xp.point(k, y);
2231 if (cx>mx || cx<mn) break;
2232 xp.point(k, y) += add;
2233 cc = cx;
2234 num++;
2235 k++;
2236 }
2237 ed = k - 1;
2238
2239 // 上下ライン
2240 for (i=st; i<=ed; i++){
2241 cc = (int)xp.point(i, y) - add;
2242
2243 // 1ライン上へ
2244 if (y-1>=0 && y-1<xp.ys){
2245 cx = (int)xp.point(i, y-1);
2246 if (cx<=mx && cx>=mn) {
2247 num += addPaint_MSGraph(xp, i, y-1, mn, mx, add, mode);
2248 }
2249 if (mode>=8) {
2250 if (i-1>=0) {
2251 cx = (int)xp.point(i-1, y-1);
2252 if (cx<=mx && cx>=mn) {
2253 num += addPaint_MSGraph(xp, i-1, y-1, mn, mx, add, mode);
2254 }
2255 }
2256 if (i+1<xp.xs) {
2257 cx = (int)xp.point(i+1, y-1);
2258 if (cx<=mx && cx>=mn) {
2259 num += addPaint_MSGraph(xp, i+1, y-1, mn, mx, add, mode);
2260 }
2261 }
2262 }
2263 }
2264
2265 // 1ライン下へ
2266 if (y+1>=0 && y+1<xp.ys){
2267 cx = (int)xp.point(i, y+1);
2268 if (cx<=mx && cx>=mn) {
2269 num += addPaint_MSGraph(xp, i, y+1, mn, mx, add, mode);
2270 }
2271 if (mode>=8) {
2272 if (i-1>=0) {
2273 cx = (int)xp.point(i-1, y+1);
2274 if (cx<=mx && cx>=mn) {
2275 num += addPaint_MSGraph(xp, i-1, y+1, mn, mx, add, mode);
2276 }
2277 }
2278 if (i+1<xp.xs) {
2279 cx = (int)xp.point(i+1, y+1);
2280 if (cx<=mx && cx>=mn) {
2281 num += addPaint_MSGraph(xp, i+1, y+1, mn, mx, add, mode);
2282 }
2283 }
2284 }
2285 }
2286 }
2287 return num;
2288}
2289
2290
2307template <typename T> MSGraph<T> Density_Mask(MSGraph<T> vp, double rate, int mode=8, int work_color=0)
2308{
2309 MSGraph<T> pp;
2310 int ps = vp.xs*vp.ys;
2311
2312 if (work_color==0) {
2313 if (vp.max==0 || vp.max==vp.zero) vp.get_minmax();
2314 work_color = vp.max + 1;
2315 }
2316 pp.mimicry(vp);
2317
2318 if ((int)(ps*rate+0.5)==ps) {
2319 int eflg = OFF;
2320 for (int i=0; i<ps; i++) {
2321 if (vp.gp[i]==vp.zero) {
2322 pp.state = 0;
2323 eflg = ON;
2324 break;
2325 }
2326 }
2327 if (eflg==OFF) {
2328 for (int i=0; i<ps; i++) pp.gp[i] = vp.gp[i];
2329 pp.state = ps;
2330 }
2331 return pp;
2332 }
2333
2334 MSGraph<T> xp;
2335 xp.set(vp.xs+2, vp.ys+2, 1, vp.zero, vp.base, vp.RZxy);
2336 xp.color = vp.color;
2337
2338 for (int j=0; j<vp.ys; j++) {
2339 for (int i=0; i<vp.xs; i++) {
2340 xp.gp[(j+1)*xp.xs+i+1] = vp.gp[j*vp.xs+i];
2341 }
2342 }
2343 set_around_MSGraph(xp, xp.zero+1);
2344 MSGraph_Paint(xp, 0, 0, xp.zero+1, work_color-1, work_color, mode);
2345
2346 int nn = 0;
2347 for (int j=0; j<vp.ys; j++) {
2348 for (int i=0; i<vp.xs; i++) {
2349 if (xp.gp[(j+1)*xp.xs+i+1]==work_color) {
2350 pp.gp[j*pp.xs+i] = vp.gp[j*vp.xs+i];
2351 nn++;
2352 }
2353 }
2354 }
2355 pp.state = nn;
2356
2357 if ((int)(ps*rate+0.5)>nn) {
2358 pp.state = 0;
2359 pp.clear();
2360 }
2361
2362 xp.free();
2363 return pp;
2364}
2365
2366
2381template <typename T> MSGraph<T> Density_Filter(MSGraph<T> vp, int size, double rate, int mode=8, int work_color=0)
2382{
2383 MSGraph<T> pp, xp, wp;
2384 int hsize = size/2;
2385
2386 if (work_color==0) {
2387 if (vp.max==0 || vp.max==vp.zero) vp.get_minmax();
2388 work_color = vp.max + 1;
2389 }
2390
2391 if (hsize==0) hsize = 1;
2392 size = hsize*2 + 1;
2393 pp.set(size, size, 1, vp.zero, vp.base);
2394 wp.mimicry(vp);
2395
2396 for (int j=hsize; j<vp.ys-hsize; j++) {
2397 for (int i=hsize; i<vp.xs-hsize; i++) {
2398
2399 for (int m=-hsize; m<=hsize; m++) {
2400 int vx = (m+j)*vp.xs + i;
2401 int px = (m+hsize)*pp.xs + hsize;
2402
2403 for (int n=-hsize; n<=hsize; n++) {
2404 pp.gp[px+n] = vp.gp[vx+n];
2405 }
2406 }
2407
2408 xp = Density_Mask<T>(pp, rate, mode, work_color);
2409
2410 if (xp.state!=0) {
2411 for (int m=-hsize; m<=hsize; m++) {
2412 int wx = (m+j)*wp.xs + i;
2413 int xx = (m+hsize)*xp.xs + hsize;
2414
2415 for (int n=-hsize; n<=hsize; n++) {
2416 if (xp.gp[xx+n]!=vp.zero) {
2417 wp.gp[wx+n] = xp.gp[xx+n];
2418 }
2419 }
2420 }
2421 }
2422 xp.free();
2423 }
2424 }
2425
2426 pp.free();
2427 return wp;
2428}
2429
2430
2437template <typename T> void delete_noise_MSGraph(MSGraph<T> vp, int size, int mode=8, int work_color=0)
2438{
2439 int i, j, k;
2440 int num, ps ,pp;
2441
2442 ps = vp.xs*vp.ys;
2443 if (work_color==0) {
2444 if (vp.max==0 || vp.max==vp.zero) vp.get_minmax();
2445 work_color = vp.max + 1;
2446 }
2447
2448 for(j=0; j<vp.ys; j++) {
2449 pp = j*vp.xs;
2450 for(i=0; i<vp.xs; i++) {
2451 if (vp.gp[i+pp]>vp.zero && vp.gp[i+pp]<work_color) {
2452 num = addPaint_MSGraph(vp, i, j, 1, work_color-1, work_color, mode);
2453 if (num<=size) {
2454 int n = 0;
2455 for (k=i+pp; k<ps; k++) {
2456 if (vp.gp[k]>=work_color) {
2457 vp.gp[k] = vp.zero;
2458 n++;
2459 if (n>=num) break;
2460 }
2461 }
2462 }
2463 else {
2464 int n = 0;
2465 for (k=i+pp; k<ps; k++) {
2466 if (vp.gp[k]>=work_color) {
2467 vp.gp[k] = -vp.gp[k];
2468 n++;
2469 if (n>=num) break;
2470 }
2471 }
2472 }
2473 }
2474 }
2475 }
2476
2477 for (i=0; i<ps; i++) {
2478 if (vp.gp[i]<vp.zero) vp.gp[i] = - vp.gp[i] - work_color;
2479 }
2480}
2481
2482
2483} // namespace
2484
2485
2486#endif
グラフィックデータ定義用ヘッダ
#define BOUNDARY_BLANK
境界 RBound<T> の余白
Definition Vector.h:42
virtual void StepIt(int n=1)
カウンタのメモリを増やす
Definition ClassBox.h:171
virtual void SetMax(int m)
カウンタの最大値(最終目標)を設定
Definition ClassBox.h:161
virtual bool isCanceled()
カウンタがオペレータにより,キャンセルされたか
Definition ClassBox.h:173
void clear(T v)
全空間を画素値 v にする
Definition Gdata.h:352
T * gp
グラフィックデータへのポインタ.
Definition Gdata.h:81
int color
データのカラータイプ
Definition Gdata.h:89
T base
画措置の底上げの値.
Definition Gdata.h:83
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 get_minmax(void)
min, max を獲得
Definition Gdata.h:298
T max
画素値の最大値
Definition Gdata.h:87
T min
画素値の最小値
Definition Gdata.h:88
int xs
xサイズ. 4Byte.
Definition Gdata.h:78
int state
エラー制御
Definition Gdata.h:90
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
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
int ys
yサイズ. 4Byte.
Definition Gdata.h:79
void getm(int x, int y, int z=1, T v=(T) 0)
グラフィックメモリを獲得する
Definition Gdata.h:250
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
void enlarge(T f)
境界構造体 bound を広げる
Definition Vector.h:461
void fusion(RBound< T > bound)
境界構造体 bound と融合させる
Definition Vector.h:483
T ymax
y軸境界の最大値.
Definition Vector.h:429
void cutdown(RBound< T > bound)
切り出した場合の境界
Definition Vector.h:527
T zmin
z軸境界の最小値.
Definition Vector.h:430
void commonarea(RBound< T > bound)
境界構造体 bound との共通領域 共通領域がない場合は,min>max になる
Definition Vector.h:516
Vector< T > normalize(void)
Definition Vector.h:87
double norm(void)
Definition Vector.h:71
void set(T X, T Y=0, T Z=0, double N=0.0, double C=1.0, int D=0)
Definition Vector.h:110
double n
ノルム
Definition Vector.h:62
#define Min(x, y)
Definition common.h:250
#define Sign(x)
Definition common.h:253
#define OFF
Definition common.h:231
#define Max(x, y)
Definition common.h:247
#define PI
Definition common.h:182
#define Xabs(x)
Definition common.h:257
#define ON
Definition common.h:230
#define JBXL_GRAPH_IVDARG_ERROR
無効な引数
Definition jbxl_state.h:178
#define JBXL_GRAPH_NODATA_ERROR
データが無い
Definition jbxl_state.h:171
#define JBXL_GRAPH_CANCEL
処理がキャンセルされた
Definition jbxl_state.h:168
#define JBXL_GRAPH_MEMORY_ERROR
メモリエラー
Definition jbxl_state.h:170
Definition Brep.h:29
void MSGraph_Sphere(MSGraph< T > vp, Vector<> a, int r, int cc, int mode=1)
Definition Graph.h:1373
int MSGraph_Paint(MSGraph< T > vp, int x, int y, int mn, int mx, int cc, int mode=8)
Definition Graph.h:793
void set_around_MSGraph(MSGraph< T > vp, int cc=0, int size=1)
Definition Graph.h:2030
void rotate_point_angle(int &x, int &y, double sxc, double syc, double dxc, double dyc, double th)
Definition Graph.cpp:52
CVCounter * GetUsableGlobalCounter()
現在有効なグローバルカウンタを得る.(子カウンタを得るかもしれない)
Definition ClassBox.h:185
void MSGraph_Box(MSGraph< T > vp, int x1, int y1, int x2, int y2, int cc, int mode=OFF)
Definition Graph.h:1036
void Local2World(MSGraph< T > gd, MSGraph< T > vp, Vector< R > oq, Vector< R > op, Vector< R > ex, double *pcsf=NULL, double *psnf=NULL)
Definition Graph.h:730
void ToPola(Vector< T > nv, double &cst, double &snt, double &csf, double &snf, double pcsf=0.0, double psnf=1.0)
Definition Graph.h:674
void copy_MSGraph(MSGraph< R > src, MSGraph< T > &dst)
Definition Graph.h:530
int addPaint_MSGraph(MSGraph< T > xp, int x, int y, int mn, int mx, int add, int mode=8)
Definition Graph.h:2212
void delete_noise_MSGraph(MSGraph< T > vp, int size, int mode=8, int work_color=0)
Definition Graph.h:2437
void MSGraph_Line3D(MSGraph< T > vp, int x1, int y1, int z1, int x2, int y2, int z2, int cc)
Definition Graph.h:1061
double Sin_Tolerance
sinθ==0
Definition Tolerance.cpp:23
MSGraph< T > cut_object_MSGraph(MSGraph< T > vp, int mn, int mx, int blank=BOUNDARY_BLANK, bool ecnt=false)
Definition Graph.h:1435
MSGraph< T > Density_Mask(MSGraph< T > vp, double rate, int mode=8, int work_color=0)
Definition Graph.h:2307
int count_object_MSGraph(MSGraph< T > xp, int mn, int mx)
Definition Graph.h:234
RBound< int > out_around_MSGraph(MSGraph< T > vp, int x, int y, int mode=8)
Definition Graph.h:295
MSGraph< T > Density_Filter(MSGraph< T > vp, int size, double rate, int mode=8, int work_color=0)
Definition Graph.h:2381
void MSGraph_changeColor(MSGraph< T > vp, int f, int t)
Definition Graph.h:769
MSGraph< T > grab_MSGraph(MSGraph< T > vp, int x1, int y1, int x2, int y2, int zs=0, int ze=0)
Definition Graph.h:2079
Vector< double > dgree_circle_MSGraph(MSGraph< T > vp)
Definition Graph.h:86
int MSGraph_Paint3D(MSGraph< T > vp, int x, int y, int z, int mn, int mx, int cc, int mode=8)
Definition Graph.h:883
void MSGraph_Torus(MSGraph< T > vp, Vector<> ox, Vector<> ex, int rr, int ra, int cc)
Definition Graph.h:1327
MSGraph< T > x_reverse_MSGraph(MSGraph< T > vp, bool ecnt=false)
Definition Graph.h:1978
MSGraph< T > rotate_MSGraph(MSGraph< T > vp, int xs, int ys, double cst, double snt, int mode=ON)
Definition Graph.h:1897
void rotate_point(int &x, int &y, double sxc, double syc, double dxc, double dyc, double cst, double snt)
Definition Graph.cpp:26
void MSGraph_Pool(MSGraph< T > vp, Vector<> a, Vector<> b, int rr, int cc)
Definition Graph.h:1288
MSGraph< T > dup_MSGraph(MSGraph< T > src)
Definition Graph.h:602
Vector< double > object_feature_MSGraph(MSGraph< T > vp, int mn, int mx)
Definition Graph.h:126
void cat_MSGraph(MSGraph< R > src, MSGraph< T > &dst)
Definition Graph.h:421
MSGraph< T > reduce_MSGraph(MSGraph< T > vp, double rc, int mode=ON)
Definition Graph.h:1814
void MSGraph_Line(MSGraph< T > vp, int x1, int y1, int x2, int y2, int cc)
Definition Graph.h:939
RBound< int > get_boundary_MSGraph(MSGraph< T > vp, T mn, T mx)
Definition Graph.h:386
MSGraph< T > zoom_MSGraph(MSGraph< T > vp, double zm, int mode=ON)
Definition Graph.h:1733
double count_around_MSGraph(MSGraph< T > vp)
Definition Graph.h:180
void MSGraph_Circle(MSGraph< T > vp, int x, int y, int r, int cc, int mode=OFF)
Definition Graph.h:1160
void MSGraph_Circle3D(MSGraph< T > vp, Vector<> ox, Vector<> ex, int rr, int cc, int mode=OFF)
Definition Graph.h:1263
int count_area_MSGraph(MSGraph< T > xp)
Definition Graph.h:223
void MSGraph_Triangle(MSGraph< T > vp, int x1, int y1, int x2, int y2, int x3, int y3, int cc, int mode=OFF)
Definition Graph.h:1007
#define PRINT_MESG(...)
環境依存用の出力関数.MS Windows用は未実装
Definition tools.h:469
#define DEBUG_MODE
Definition tools.h:502