JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
Morph.h
Go to the documentation of this file.
1#ifndef __JBXL_CPP_MORPHOLOGY_H_
2#define __JBXL_CPP_MORPHOLOGY_H_
3
14#include "Gdata.h"
15
16//
17namespace jbxl {
18
19
20#define OPENING 0
21#define CLOSING 1
22#define DILATION 2
23
24#define SPHERE_ELEMENT 1
25
26
27/*
28template <typename T> MSGraph<T> Morphology(MSGraph<T> vp, MSGraph<T> xp, int cc, int mode);
29template <typename T> MSGraph<T> opening_morph(MSGraph<T> vp, MSGraph<T> xp, int cc);
30template <typename T> bool point_open_morph(MSGraph<T> vp, int x, int y, int z, MSGraph<T> xp, int cc);
31template <typename T> void copy_morph_element(MSGraph<T> vp, int x, int y, int z, MSGraph<T> xp);
32template <typename T> MSGraph<T> fat_object_morph(MSGraph<T> vp, MSGraph<T> xp, int cc);
33template <typename T> bool point_fat_object_morph(MSGraph<T> vp, int x, int y, int z, MSGraph<T> xp, int cc);
34template <typename T> MSGraph<T> make_element_morph(Parameter x);
35*/
36
37
51template <typename T> MSGraph<T> Morphology(MSGraph<T> vp, MSGraph<T> xp, int cc, int mode)
52{
53 MSGraph<T> wp;
54
55 if (mode==OPENING) wp = opening_morph(vp, xp, cc);
56 else {
57 DEBUG_MODE PRINT_MESG("MORPHOLOGY: サポートしていない演算です = %d\n", mode);
58 }
59 return wp;
60}
61
62
75template <typename T> MSGraph<T> opening_morph(MSGraph<T> vp, MSGraph<T> xp, int cc)
76{
77 int i, j, k, ks, cz, cy, cx, ps;
78 bool err;
79 MSGraph<T> wp(vp.xs, vp.ys, vp.zs);
80 if (wp.isNull()) return wp;
81
82 ps = vp.xs*vp.ys;
83 for (k=0; k<vp.zs; k++) {
84 cz = k*ps;
85 for (j=0; j<vp.ys; j++) {
86 cy = cz + j*vp.xs;
87 for (i=0; i<vp.xs; i++) {
88 cx = cy + i;
89 if (vp.gp[cx]>=cc) {
90 err = point_open_morph(vp, i, j, k, xp, cc);
91 if (err) copy_morph_element(wp, i, j, k, xp);
92 }
93 }
94 }
95 }
96 return wp;
97}
98
99
105template <typename T> bool point_open_morph(MSGraph<T> vp, int x, int y, int z, MSGraph<T> xp, int cc)
106{
107 int i, j, k, cx, cy, cz;
108 int xx, yy, zz, ax, ay, az;
109
110 for (k=0; k<xp.zs; k++) {
111 zz = z + k - xp.zs/2;
112 if (zz<0) zz = 0;
113 if (zz>vp.zs-1) zz = vp.zs-1;
114 az = vp.xs*vp.ys*zz;
115 cz = xp.xs*xp.ys*k;
116 for (j=0; j<xp.ys; j++) {
117 yy = y + j - xp.ys/2;
118 ay = az + vp.xs*yy;
119 cy = cz + xp.xs*j;
120 for (i=0; i<xp.xs; i++) {
121 xx = x + i - xp.xs/2;
122 ax = ay + xx;
123 cx = cy + i;
124 if (xp.gp[cx]>0) {
125 if (!(xx>=0&&xx<vp.xs&&yy>=0&&yy<vp.ys)) return false;
126 if (vp.gp[ax]<cc) return false;
127 }
128 }
129 }
130 }
131 return true;
132}
133
134
140template <typename T> void copy_morph_element(MSGraph<T> vp, int x, int y, int z, MSGraph<T> xp)
141{
142 int i, j, k, cx, cy, cz;
143 int xx, yy, zz, ax, ay, az;
144
145 for (k=0; k<xp.zs; k++) {
146 zz = z + k - xp.zs/2;
147 az = vp.xs*vp.ys*zz;
148 cz = xp.xs*xp.ys*k;
149 for (j=0; j<xp.ys; j++) {
150 yy = y + j - xp.ys/2;
151 ay = az + vp.xs*yy;
152 cy = cz + xp.xs*j;
153 for (i=0; i<xp.xs; i++) {
154 xx = x + i - xp.xs/2;
155 ax = ay + xx;
156 cx = cy + i;
157 if (xx>=0&&xx<vp.xs&&yy>=0&&yy<vp.ys&&zz>=0&&zz<vp.zs){
158 if (xp.gp[cx]>0) vp.gp[ax] = xp.gp[cx];
159 }
160 }
161 }
162 }
163}
164
165
171template <typename T> MSGraph<T> fat_object_morph(MSGraph<T> vp, MSGraph<T> xp, int cc)
172{
173 int i, j, k, ps, cz, cy, cx;
174 bool err;
175 MSGraph<T> wp(vp.xs, vp.ys, vp.zs);
176 if (wp.isNull()) return wp;
177
178 ps = vp.xs*vp.ys;
179 for (k=0; k<vp.zs; k++) {
180 cz = k*ps;
181 for (j=0; j<vp.ys; j++) {
182 cy = cz + j*vp.xs;
183 for (i=0; i<vp.xs; i++) {
184 cx = cy + i;
185 if (vp.gp[cx]>=cc) {
186 err = point_fat_object_morph(vp, i, j, k, xp, cc);
187 if (err) copy_morph_element(wp, i, j, k, xp);
188 }
189 }
190 }
191 }
192 return wp;
193}
194
195
199template <typename T> bool point_fat_object_morph(MSGraph<T> vp, int x, int y, int z, MSGraph<T> xp, int cc)
200{
201 int i, j, k, cx, cy, cz;
202 int xx, yy, zz, ax, ay, az;
203
204 for (k=0; k<xp.zs; k++) {
205 zz = z + k - xp.zs/2;
206 if (zz<0) zz = 0;
207 if (zz>vp.zs-1) zz = vp.zs-1;
208 az = vp.xs*vp.ys*zz;
209 cz = xp.xs*xp.ys*k;
210 for (j=0; j<xp.ys; j++) {
211 yy = y + j - xp.ys/2;
212 ay = az + vp.xs*yy;
213 cy = cz + xp.xs*j;
214 for (i=0; i<xp.xs; i++) {
215 xx = x + i - xp.xs/2;
216 ax = ay + xx;
217 cx = cy + i;
218 if (xp.gp[cx]>0) {
219 if (xx>=0&&xx<vp.xs&&yy>=0&&yy<vp.ys) {
220 if (vp.gp[ax]>=cc) return true;
221 }
222 }
223 }
224 }
225 }
226 return false;
227}
228
229
236{
237 int *p, n, m, r, c, i, j, k, z;
238 int nn, xs, ir;
239 double s, sn, cs, dr, dt, df, th, fi, rx, zz;
240 MSGraph<T> vp, xp;
241
242 p = (int*)x.pm;
243 m = p[0]; // mode
244 r = p[1]; // hankei
245 c = p[2]; // color
246 s = p[3]/p[4]; // RZxy;
247
248 if (m==SPHERE_ELEMENT) {
249 xs = 2*r + 1;
250 vp.getm(xs, xs, (int)(xs*s+0.5));
251 if (vp.isNull()) return vp;
252
253 xp.xs = xs;
254 xp.ys = xs;
255 xp.zs = 1;
256
257 for (z=0; z<vp.zs; z++) {
258 xp.gp = &vp.gp[z*vp.xs*vp.ys];
259 zz = Min(r, Xabs(((vp.zs-1.)/2.-z)/s));
260 ir = (int)(sqrt(Max(r*r-zz*zz, 0.0))+0.5);
261 circle(xp, r, r, ir, c, ON);
262 }
263 }
264 else {
265 DEBUG_MODE PRINT_MESG("MAKE_ELEMENT_MORPH: no support mode = %d\n",m);
266 exit(1);
267 }
268 return vp;
269}
270
271
272} // namespace
273
274
275#endif
276
グラフィックデータ定義用ヘッダ
#define SPHERE_ELEMENT
Definition Morph.h:24
#define OPENING
Definition Morph.h:20
T * gp
グラフィックデータへのポインタ.
Definition Gdata.h:81
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition Gdata.h:80
int xs
xサイズ. 4Byte.
Definition Gdata.h:78
bool isNull(void)
グラフィックデータを持っていないか?
Definition Gdata.h:194
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
#define Min(x, y)
Definition common.h:250
#define Max(x, y)
Definition common.h:247
#define Xabs(x)
Definition common.h:257
#define ON
Definition common.h:230
Definition Brep.h:29
MSGraph< T > fat_object_morph(MSGraph< T > vp, MSGraph< T > xp, int cc)
Definition Morph.h:171
MSGraph< T > Morphology(MSGraph< T > vp, MSGraph< T > xp, int cc, int mode)
Definition Morph.h:51
void copy_morph_element(MSGraph< T > vp, int x, int y, int z, MSGraph< T > xp)
Definition Morph.h:140
bool point_fat_object_morph(MSGraph< T > vp, int x, int y, int z, MSGraph< T > xp, int cc)
Definition Morph.h:199
MSGraph< T > make_element_morph(Parameter32 x)
Definition Morph.h:235
bool point_open_morph(MSGraph< T > vp, int x, int y, int z, MSGraph< T > xp, int cc)
Definition Morph.h:105
MSGraph< T > opening_morph(MSGraph< T > vp, MSGraph< T > xp, int cc)
Definition Morph.h:75
sByte pm[32]
Definition common.h:345
#define PRINT_MESG(...)
環境依存用の出力関数.MS Windows用は未実装
Definition tools.h:469
#define DEBUG_MODE
Definition tools.h:502