質問編集履歴

1

質問の修正

2016/10/26 03:48

投稿

DOLL1515
DOLL1515

スコア8

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ```###前提・実現したいこと
12
12
 
13
- CAD(Designer K-Ver14.0)で図のような立体画像を作成し、この画像の赤い部分のような、輪郭画像を抽出するプログラムを作成しました。このプログラムを使用し現在カメラのレンズ部分とフラッシュ部分の二つの穴の輪郭を抽出するプログラムを作っているところですが、難しいです。誰かわかる方いませんか?プログラムは長いので改造する部分のみここに記述します。
13
+ CADで図のような立体画像を作成し、この画像の赤い部分のような、輪郭画像を抽出するプログラムを作成しました。このプログラムを使用し現在カメラのレンズ部分とフラッシュ部分の二つの穴の輪郭を抽出するプログラムを作っているところですが、難しいです。誰かわかる方いませんか?プログラムは長いので改造する部分のみここに記述します。
14
14
 
15
15
 
16
16
 
@@ -22,740 +22,6 @@
22
22
 
23
23
 
24
24
 
25
- // 平面作成
26
-
27
- int MeshTool::process_event4(mouse_event_type evnt_type, const pick_event& pe)
28
-
29
-
30
-
31
- if (evnt_type == MOUSE_BUTTON_DOWN && pe.left_button()) { //左クリック
32
-
33
- ENTITY* ent = NULL;
34
-
35
- if (m_numberOfPositions == 0) {
36
-
37
- if (PickEntity(pe, ent, FALSE)) {
38
-
39
- m_entity1 = ent;
40
-
41
- if (m_entity1 != NULL) {
42
-
43
- m_numberOfPositions = 1;
44
-
45
- ShowPrompt();
46
-
47
- }
48
-
49
- }
50
-
51
- }
52
-
53
- }
54
-
55
-
56
-
57
- if (m_numberOfPositions == 1) {
58
-
59
- if (pSelection == NULL) {
60
-
61
- CAcisDoc* pDoc = PickEventToAcisDoc(pe);
62
-
63
- if (pDoc) pSelection = pDoc->GetSelection();
64
-
65
- if (pSelection && pSelection->IsEmpty()) {
66
-
67
- PushTool(new SelectTool(is_VERTEX), ID_EDIT_SELECT);
68
-
69
- }
70
-
71
- return 0;
72
-
73
- }
74
-
75
-
76
-
77
- if (pSelection && !pSelection->IsEmpty()) {
78
-
79
- ShowPrompt();
80
-
81
- double val;
82
-
83
- int cnt = 0, m_pos_sum = 0;
84
-
85
- ENTITY *ent1 = NULL, *face = m_entity1;
86
-
87
- ENTITY_LIST* entities = pSelection->GetEntityList();
88
-
89
- ENTITY_LIST face_list = NULL, point_list = NULL;
90
-
91
- face_list.add(face);
92
-
93
-
94
-
95
- entities->init();
96
-
97
-
98
-
99
- while (ent1 = entities->next()) {
100
-
101
- m_pos_sum += ent_pos_get(ent1, NULL);
102
-
103
- }
104
-
105
-
106
-
107
- m_pos_list = new SPAposition[m_pos_sum];
108
-
109
-
110
-
111
- entities->init();
112
-
113
- while (ent1 = entities->next()) {
114
-
115
- cnt = ent_pos_get(ent1, m_pos_list, cnt);
116
-
117
- }
118
-
119
-
120
-
121
- double distance = 0.0;
122
-
123
- SPAposition pos(0, 0, 0);
124
-
125
- SPAunit_vector face_uv;
126
-
127
-
128
-
129
- api_entity_point_distance(face, m_pos_list[0], pos, distance);
130
-
131
- val = distance + 0.1;
132
-
133
-
134
-
135
- int dia = 0;
136
-
137
- dia = RealDialog("面・点間の距離の許容値", "数値入力", val);
138
-
139
-
140
-
141
- pSelection->SetHighlight(FALSE);
142
-
143
-
144
-
145
-
146
-
147
- if (dia) {
148
-
149
- pSelection->Clear();
150
-
151
- pSelection = NULL;
152
-
153
- m_numberOfPositions = 0;
154
-
155
- ShowPrompt();
156
-
157
- return 0;
158
-
159
- }
160
-
161
-
162
-
163
-
164
-
165
- entities->init();
166
-
167
-
168
-
169
- API_NOP_BEGIN;
170
-
171
- for (int i = 0; i < m_pos_sum; i++) {
172
-
173
-
174
-
175
- api_entity_point_distance(face, m_pos_list[i], pos, distance);
176
-
177
-
178
-
179
-
180
-
181
- kfunc_PickFacePosUV_sub((FACE*&)face, pos, face_uv);
182
-
183
-
184
-
185
-
186
-
187
- distance = dist_pt_to_plane(m_pos_list[i], pos, face_uv);
188
-
189
- ent1 = entities->next();
190
-
191
-
192
-
193
-
194
-
195
- if (distance <= val) {
196
-
197
- point_list.add(ent1);
198
-
199
- }
200
-
201
- }
202
-
203
- API_NOP_END;
204
-
205
- delete[] m_pos_list;
206
-
207
- m_pos_list = NULL;
208
-
209
-
210
-
211
-
212
-
213
- entities->clear();
214
-
215
- entities->add(point_list);
216
-
217
- pSelection->SetHighlight(TRUE);
218
-
219
-
220
-
221
- int pcnt = point_list.count();
222
-
223
- if (pcnt) {
224
-
225
-
226
-
227
- int list_count = 0;
228
-
229
- double val2 = 0.0;
230
-
231
- ENTITY *ent2 = NULL;
232
-
233
- SPAposition *input_list = new SPAposition[pcnt];
234
-
235
-
236
-
237
- point_list.init();
238
-
239
- while (ent2 = point_list.next()) {
240
-
241
- list_count = ent_pos_get(ent2, input_list, list_count);
242
-
243
- }
244
-
245
-
246
-
247
- // 重複点消去
248
-
249
- pcnt = DEL_dup_PosListForStl(input_list, pcnt);
250
-
251
-
252
-
253
- // 平面に投影した点を取得
254
-
255
- for (int i = 0; i < pcnt; i++) {
256
-
257
- input_list[i] = proj_pt_to_plane(input_list[i], pos, face_uv);
258
-
259
- }
260
-
261
- // 重複点消去
262
-
263
- pcnt = DEL_dup_PosListForStl(input_list, pcnt);
264
-
265
-
266
-
267
- // 面上の点のみを取得する
268
-
269
- int tmp_cnt = 0, inp_num;
270
-
271
- vector<SPAposition> tmp_list;
272
-
273
- API_NOP_BEGIN;
274
-
275
- for (int i = 0; i < pcnt; i++) {
276
-
277
- api_entity_point_distance(face, input_list[i], pos, distance);
278
-
279
- if (fabs(distance) < 1e-5) {
280
-
281
- tmp_list.push_back(input_list[i]);
282
-
283
- tmp_cnt++;
284
-
285
- }
286
-
287
- inp_num = tmp_cnt;
288
-
289
- }
290
-
291
- API_NOP_END;
292
-
293
-
294
-
295
- delete[]input_list;
296
-
297
- input_list = new SPAposition[inp_num];
298
-
299
-
300
-
301
- for (int i = 0; i < inp_num; i++) {
302
-
303
- input_list[i] = tmp_list[i];
304
-
305
- }
306
-
307
-
308
-
309
- SPAunit_vector xaxis, yaxis;
310
-
311
- compute_axes_from_z(face_uv, xaxis, yaxis);
312
-
313
- SPAtransf trans = coordinate_transf(input_list[0], xaxis, yaxis);
314
-
315
- SPAtransf rev_trans = trans.inverse();
316
-
317
- //SPAtransf trans = coordinate_transf(input_list[0], SPAunit_vector(0, 1, 0), SPAunit_vector(0, 0, 1));
318
-
319
-
320
-
321
- // トランスで変換後、輪郭図形を求める処理を行う
322
-
323
- for (int i = 0; i < inp_num; i++) {
324
-
325
- input_list[i] *= rev_trans;
326
-
327
- }
328
-
329
-
330
-
331
- double x_max;
332
-
333
- SPAposition start_pos, now_pos, next_pos, past_pos(0, 0, 0);
334
-
335
- vector<SPAposition> next_pos_list;
336
-
337
- vector<SPAposition> fig_list;
338
-
339
-
340
-
341
-
342
-
343
- // 開始点を求める
344
-
345
- for (int i = 0; i < inp_num; i++) {//面上の点より小さい間ループ
346
-
347
- if (i == 0) x_max = input_list[0].x();
348
-
349
- if (input_list[i].x() >= x_max) {
350
-
351
-
352
-
353
- x_max = input_list[i].x();
354
-
355
- start_pos = input_list[i];
356
-
357
- }
358
-
359
- }
360
-
361
-
362
-
363
- // 許容値処理
364
-
365
- val2 = 0.01;
366
-
367
- while (1) {// fil_pos許容値内の点をリストに格納して返す
368
-
369
- next_pos_list = fil_pos(inp_num, start_pos, input_list, val2);
370
-
371
- if (size(next_pos_list) > 2) break;
372
-
373
- val2 = val2 + 0.01;
374
-
375
- if (val2 > 10.0) break;
376
-
377
- }
378
-
379
-
380
-
381
-
382
-
383
- if (RealDialog("点間の許容値", "数値入力", val2)) return 0;
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
- // 点群からエッジを作る点を求める
392
-
393
- int i_cnt = 0;
394
-
395
- fig_list.push_back(start_pos); next_pos = past_pos = now_pos = start_pos;
396
-
397
-
398
-
399
- for (int i = 0; i < inp_num; i++) {
400
-
401
- past_pos = now_pos;
402
-
403
- now_pos = next_pos;
404
-
405
- if (!size(next_pos_list)) break;
406
-
407
- next_pos_list = fil_pos(inp_num, now_pos, input_list, val2);
408
-
409
- next_pos = get_next_pos(now_pos, next_pos_list, past_pos, fig_list, i ? 1 : 0);
410
-
411
-
412
-
413
- fig_list.push_back(next_pos);
414
-
415
- i_cnt++;
416
-
417
- if (i && next_pos == start_pos) break;
418
-
419
- }
420
-
421
-
422
-
423
- delete[]input_list;
424
-
425
- input_list = NULL;
426
-
427
-
428
-
429
- int num = size(fig_list);
430
-
431
- if (num) {
432
-
433
-
434
-
435
-
436
-
437
- for (int i = 0; i < num; i++) {
438
-
439
- fig_list[i] *= trans;
440
-
441
-
442
-
443
- }
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
- StartEntityCreation();
452
-
453
- API_BEGIN;
454
-
455
- EDGE* edge;
456
-
457
- ENTITY_LIST edge_list;
458
-
459
-
460
-
461
- for (int i = 0; i < num - 1; i++) {
462
-
463
- api_curve_line(fig_list[i], fig_list[i+1], edge);
464
-
465
- api_get_edges((ENTITY*)edge, edge_list);
466
-
467
- }
468
-
469
-
470
-
471
- BODY *wire = NULL;
472
-
473
- make_wire_from_edgelist(edge_list, wire);
474
-
475
- kapi_set_attr_color(wire, rgb_color(0,0,1));
476
-
477
- RecordEntity(wire);
478
-
479
-
480
-
481
-
482
-
483
- if (next_pos == start_pos) {
484
-
485
- BODY *sheet = NULL; ENTITY_LIST dummy_list;
486
-
487
-
488
-
489
- check_outcome(result = kapi_make_surface_advanced_cover((ENTITY*)wire, dummy_list, sheet));
490
-
491
- RecordEntity2((ENTITY*)sheet);
492
-
493
- }
494
-
495
- //DelEntities(point_list);
496
-
497
- API_END;
498
-
499
- EndEntityCreation2(NULL, result, TRUE);
500
-
501
- CheckOutcome(result);
502
-
503
-
504
-
505
-
506
-
507
- }// if(num)
508
-
509
-
510
-
511
- m_numberOfPositions = 0;
512
-
513
- ShowPrompt();
514
-
515
-
516
-
517
-
518
-
519
- }// if (pcnt)
520
-
521
- api_kkk_highlight_ents_with_del_ds(*entities, FALSE);
522
-
523
-
524
-
525
-
526
-
527
- }// if (pSelection && !pSelection->IsEmpty())
528
-
529
- pSelection->SetHighlight(FALSE);
530
-
531
- pSelection->Clear();
532
-
533
- pSelection = NULL;
534
-
535
- }
536
-
537
- return 0;
538
-
539
- }
540
-
541
-
542
-
543
-
544
-
545
-
546
-
547
- int MeshTool::kdisp_pos_get(ENTITY *ent, SPAposition *pos_list, int list_cnt)
548
-
549
- {
550
-
551
- KDISP *kdisp_p = (KDISP *)ent;
552
-
553
- int cnt = 0;
554
-
555
-
556
-
557
- FILE *fp = kdisp_p->open_stl();
558
-
559
- SPAtransf trans = kdisp_p->get_transf();
560
-
561
- API_SYS_BEGIN
562
-
563
- while (fp) {
564
-
565
- double data[12];
566
-
567
- if (kdisp_p->read_stl(data, fp) == FALSE)
568
-
569
- break;
570
-
571
- if (pos_list) {
572
-
573
- for (int j = 0; j < 3; j++) {
574
-
575
- pos_list[list_cnt + cnt++] = SPAposition(data[3 * j], data[3 * j + 1], data[3 * j + 2]) * trans;
576
-
577
- }
578
-
579
- }else {
580
-
581
- cnt += 3;
582
-
583
- }
584
-
585
- }
586
-
587
- API_SYS_END
588
-
589
- if(pos_list) return list_cnt + cnt;
590
-
591
- return cnt;
592
-
593
- }
594
-
595
-
596
-
597
-
598
-
599
- int MeshTool::ent_pos_get(ENTITY *ent,SPAposition *pos_list, int list_cnt)
600
-
601
- {
602
-
603
- m_pos_cnt = 0;
604
-
605
- int i = 0, cnt = 0, num = 0;
606
-
607
-
608
-
609
- vertices_list = NULL;
610
-
611
- api_get_vertices(ent, vertices_list);
612
-
613
- cnt = vertices_list.iteration_count();
614
-
615
-
616
-
617
- ENTITY *ent_temp, *owner = NULL;
618
-
619
- SPAtransf trans;
620
-
621
- api_get_owner(ent, owner);
622
-
623
- if (is_BODY(owner)) {
624
-
625
- TRANSFORM *TRANS = ((BODY *)owner)->transform();
626
-
627
- if (TRANS) trans = TRANS->transform();
628
-
629
- }
630
-
631
-
632
-
633
- if (pos_list) {
634
-
635
- for (i = 0; i < cnt; i++) {
636
-
637
- ent_temp = vertices_list[i];
638
-
639
- pos_list[list_cnt + i] = ((VERTEX*)ent_temp)->geometry()->coords()* trans;
640
-
641
- }
642
-
643
- return list_cnt + cnt;
644
-
645
- }
646
-
647
- return cnt;
648
-
649
- }
650
-
651
-
652
-
653
-
654
-
655
- vector<SPAposition> MeshTool::fil_pos(int pcnt, SPAposition pos ,SPAposition *pos_list, double val)
656
-
657
- {
658
-
659
- double dis = 0.0;
660
-
661
- vector<SPAposition> new_pos_list;
662
-
663
-
664
-
665
- for (int i = 0; i < pcnt; i++) {
666
-
667
- double temp = pos_list[i].x() - pos.x();
668
-
669
- if( temp < -val) continue;
670
-
671
- if( temp > val) continue;
672
-
673
-
674
-
675
- dis = distance_to_point(pos, pos_list[i]);
676
-
677
- if (dis > val || dis == 0.0) continue;
678
-
679
- new_pos_list.push_back(pos_list[i]);
680
-
681
- }
682
-
683
- return new_pos_list;
684
-
685
- }
686
-
687
-
688
-
689
-
690
-
691
-
692
-
693
- SPAposition MeshTool::get_next_pos(SPAposition now_pos, vector<SPAposition> next_pos_list, SPAposition past_pos, vector<SPAposition> fig_list, int mode)
694
-
695
- {
696
-
697
- SPAposition next_position;
698
-
699
-
700
-
701
- int cnum = size(next_pos_list);
702
-
703
- int fig_cnt = size(fig_list);
704
-
705
- double min_angle, temp_angle;
706
-
707
- SPAvector pv_1(0, -1, 0), pv_2;
708
-
709
- SPAunit_vector z(0, 0, 1);
710
-
711
-
712
-
713
-
714
-
715
- min_angle = 100.0;
716
-
717
- if( mode )
718
-
719
- pv_1 = now_pos - past_pos;
720
-
721
- for (int i = 0; i < cnum; i++) {
722
-
723
- for (int j = 0; j < fig_cnt - 1; j++) {
724
-
725
- if (next_pos_list[i] == fig_list[j+1]) continue;
726
-
727
- }
728
-
729
- pv_2 = next_pos_list[i] - now_pos;
730
-
731
- temp_angle = angle_between( pv_1, pv_2, z);
732
-
733
- if( temp_angle > M_PI)
734
-
735
- temp_angle = temp_angle - 2.0*M_PI;
736
-
737
-
738
-
739
- if (temp_angle < min_angle) {
740
-
741
- min_angle = temp_angle;
742
-
743
- next_position = next_pos_list[i];
744
-
745
-
746
-
747
- }
748
-
749
- }
750
-
751
- return next_position;
752
-
753
- }
754
-
755
-
756
-
757
-
758
-
759
25
 
760
26
 
761
27
  }![イメージ説明](9b3bc1d93208e455183939cf7f97ab56.jpeg)