1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115 | //-------------------------------------------------------------------------
// Filename : FacetBody.cpp
//
// Purpose :
//
// Special Notes :
//
// Creator : David White
//
// Creation Date : 7/18/00
//
//-------------------------------------------------------------------------
// ********** BEGIN STANDARD INCLUDES **********
#include <assert.h>
// ********** END STANDARD INCLUDES **********
// ********** BEGIN CUBIT INCLUDES **********
#include "CubitDefines.h"
#include "CubitString.hpp"
#include "CubitPoint.hpp"
#include "CastTo.hpp"
#include "BodySM.hpp"
#include "Body.hpp"
#include "FacetBody.hpp"
#include "CubitSimpleAttrib.hpp"
#include "FacetQueryEngine.hpp"
#include "DLIList.hpp"
#include "FacetEvalTool.hpp"
#include "CurveFacetEvalTool.hpp"
#include "Surface.hpp"
#include "FacetSurface.hpp"
#include "CubitTransformMatrix.hpp"
#include "FacetPoint.hpp"
#include "FacetCurve.hpp"
#include "FacetCoEdge.hpp"
#include "FacetLoop.hpp"
#include "FacetShell.hpp"
#include "FacetLump.hpp"
#include "CubitFacetEdge.hpp"
#include "FacetModifyEngine.hpp"
#include "FacetAttrib.hpp"
#include "GfxDebug.hpp"
#include "CubitSimpleAttrib.hpp"
#include "CubitPointData.hpp"
//-------------------------------------------------------------------------
// Purpose : A constructor with a list of lumps that are attached.
//
// Special Notes :
//
//-------------------------------------------------------------------------
FacetBody::FacetBody(DLIList<Lump*>& my_lumps)
{
myLumps += my_lumps;
}
FacetBody::~FacetBody()
{
//Not sure what to do..
}
GeometryQueryEngine* FacetBody::get_geometry_query_engine() const
{
return FacetQueryEngine::instance();
}
void FacetBody::append_simple_attribute_virt(const CubitSimpleAttrib &csa)
{ attribSet.append_attribute(csa); }
void FacetBody::remove_simple_attribute_virt(const CubitSimpleAttrib &csa)
{ attribSet.remove_attribute(csa); }
void FacetBody::remove_all_simple_attribute_virt()
{ attribSet.remove_all_attributes(); }
CubitStatus FacetBody::get_simple_attribute(DLIList<CubitSimpleAttrib>& csa_list)
{ return attribSet.get_attributes(csa_list); }
CubitStatus FacetBody::get_simple_attribute( const CubitString& name,
DLIList<CubitSimpleAttrib>& csa_list )
{ return attribSet.get_attributes( name, csa_list ); }
CubitStatus FacetBody::save_attribs( FILE *file_ptr )
{ return attribSet.save_attributes( file_ptr); }
CubitStatus FacetBody::restore_attribs( FILE *file_ptr, unsigned int endian )
{ return attribSet.restore_attributes( file_ptr, endian ); }
//----------------------------------------------------------------
// Function: copy
// Description: create a new copy of the body.
// Author: sjowen
//----------------------------------------------------------------
BodySM* FacetBody::copy()
{
CubitStatus rv;
// ----------Copy the points on the body------------------------
std::map<TopologyBridge*, TopologyBridge*> old_to_new_map;
std::map<CubitPoint*, CubitPoint*> old_to_new_cubit_pts;
int ii;
DLIList<FacetPoint*> point_list;
get_points(point_list);
DLIList<TBPoint*> copy_points;
point_list.reset();
TBPoint *point_ptr;
TBPoint *point_copy;
for(ii=0; ii<point_list.size(); ii++)
{
point_ptr = point_list.get_and_step();
CubitVector temp_vector = point_ptr->coordinates();
CubitPoint *new_cubit_point = new CubitPointData( temp_vector );
rv = FacetModifyEngine::instance()->make_facet_point( new_cubit_point,
point_copy);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy points");
return (BodySM *)NULL;
}
copy_points.append( point_copy );
FacetPoint *old_fp = static_cast<FacetPoint*>(point_ptr);
old_to_new_cubit_pts.insert(
std::make_pair(old_fp->get_cubit_point(), new_cubit_point ) );
old_to_new_map.insert(
std::make_pair( point_ptr, point_copy ) );
}
// ------------------Copy the curves-------------------------
int jj;
std::map<FacetCurve*, FacetCurve*> hard_line_curve_map;
DLIList<FacetCurve*> curve_list;
get_curves( curve_list );
DLIList<Curve*> copy_curves;
curve_list.reset();
Curve *curve_ptr, *curve_copy;
FacetCurve *fcurve;
TBPoint *ptsm_ptr;
TBPoint *start_ptr, *end_ptr, *copy_start = NULL, *copy_end = NULL;<--- The scope of the variable 'start_ptr' can be reduced. [+]The scope of the variable 'start_ptr' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level. <--- The scope of the variable 'end_ptr' can be reduced. [+]The scope of the variable 'end_ptr' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (ii=0; ii<curve_list.size(); ii++)
{
curve_ptr = curve_list.get_and_step();
fcurve = CAST_TO( curve_ptr, FacetCurve );
start_ptr = fcurve->start_point();
end_ptr = fcurve->end_point();
int found0 = 0;
int found1 = 0;
// find the end points
point_list.reset();
copy_points.reset();
for (jj=0; jj<point_list.size() && (!found0 || !found1); jj++)
{
point_ptr = point_list.get_and_step();
ptsm_ptr = CAST_TO(point_ptr, TBPoint);
point_copy = copy_points.get_and_step();
if (ptsm_ptr == start_ptr)
{
copy_start = point_copy;
found0 = 1;
}
if (ptsm_ptr == end_ptr)
{
copy_end = point_copy;
found1 = 1;
}
}
// create the new curve and update the points
rv = FacetModifyEngine::instance()->make_facet_curve(copy_start,
copy_end,
curve_copy);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy curves");
return (BodySM *)NULL;
}
CurveFacetEvalTool *eval_tool = fcurve->get_eval_tool();
DLIList<CubitFacetEdge*> facet_edges;
eval_tool->get_facets( facet_edges );
CubitFacetEdge *tmp_facet_edge = facet_edges.get();
DLIList<CubitFacet*> adj_facets;
tmp_facet_edge->facets( adj_facets );
CubitFacet *tmp_facet = adj_facets.get_and_step();
tmp_facet->tool_id();
for( int k=adj_facets.size(); k--; )
{
if( tmp_facet_edge->num_adj_facets_on_surf( adj_facets.get_and_step()->tool_id() ) > 1 )
{
hard_line_curve_map.insert(
std::map<FacetCurve*, FacetCurve*>::value_type( static_cast<FacetCurve*>( CAST_TO( curve_copy, FacetCurve )),fcurve ));
break;
}
}
old_to_new_map.insert(
std::make_pair( curve_ptr, curve_copy ) );
copy_curves.append( curve_copy );
}
// ------------------copy coedges-----------------------
DLIList<FacetCoEdge*> coedge_list;
get_coedges( coedge_list );
DLIList<CoEdgeSM*> copy_coedges;
coedge_list.reset();
Curve *curvsm_ptr;
Curve *curvsm_copy = NULL;
CoEdgeSM *coedge_ptr, *coedge_copy;
FacetCoEdge *fcoedge;
for (ii=0; ii<coedge_list.size(); ii++)
{
coedge_ptr = coedge_list.get_and_step();
fcoedge = CAST_TO( coedge_ptr, FacetCoEdge );
Curve *curve_at_coedge = fcoedge->curve();
int found = 0;
// find the associated curve
curve_list.reset();
copy_curves.reset();
for (jj=0; jj<curve_list.size() && !found; jj++)
{
curve_ptr = curve_list.get_and_step();
curvsm_ptr = CAST_TO(curve_ptr, Curve);
curvsm_copy = copy_curves.get_and_step();
if (curve_at_coedge == curvsm_ptr)
{
found = 1;
}
}
// create the new coedge
CubitSense sense = fcoedge->sense();
rv = FacetModifyEngine::instance()->make_facet_coedge(curvsm_copy,
sense, coedge_copy);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy coedge");
return (BodySM *)NULL;
}
copy_coedges.append( coedge_copy );
}
// ----------------------copy loops--------------------------
int kk;
DLIList<FacetLoop*> loop_list;
get_loops( loop_list );
DLIList<LoopSM*> copy_loops;
loop_list.reset();
LoopSM *loop_ptr, *loop_copy;
FacetLoop *floop;<--- The scope of the variable 'floop' can be reduced. [+]The scope of the variable 'floop' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (ii=0; ii<loop_list.size(); ii++)
{
floop = loop_list.get_and_step();
DLIList<FacetCoEdge *>coedges_on_loop;
floop->get_coedges(coedges_on_loop);
DLIList<CoEdgeSM *>copy_coedges_on_loop;
// find all associated coedges on the loop
for(kk=0; kk<coedges_on_loop.size(); kk++)
{
int found = 0;
coedge_list.reset();
copy_coedges.reset();
CoEdgeSM *coedge_on_loop = coedges_on_loop.get_and_step();
for (jj=0; jj<coedge_list.size() && !found; jj++)
{
coedge_ptr = coedge_list.get_and_step();
coedge_copy = copy_coedges.get_and_step();
if (coedge_on_loop == coedge_ptr)
{
found = 1;
copy_coedges_on_loop.append(coedge_copy);
}
}
}
// create the new loop
rv = FacetModifyEngine::instance()->make_facet_loop(copy_coedges_on_loop,
loop_copy);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy loops");
return (BodySM *)NULL;
}
copy_loops.append( loop_copy );
}
// ----------------------copy surfaces--------------------------
DLIList<FacetSurface*> surface_list;
get_surfaces(surface_list);
DLIList<Surface*> copy_surfaces;
surface_list.reset();
Surface *surface_ptr, *surface_copy;
FacetSurface *fsurface;
for (ii=0; ii<surface_list.size(); ii++)
{
fsurface = surface_list.get_and_step();
DLIList<FacetLoop *>loops_on_surface;
fsurface->get_loops(loops_on_surface);
DLIList<LoopSM *>copy_loops_on_surface;
// find all associated loops on the surface
for(kk=0; kk<loops_on_surface.size(); kk++)
{
int found = 0;
loop_list.reset();
copy_loops.reset();
LoopSM *loop_on_surface = loops_on_surface.get_and_step();
for (jj=0; jj<loop_list.size() && !found; jj++)
{
loop_ptr = loop_list.get_and_step();
loop_copy = copy_loops.get_and_step();
if (loop_on_surface == loop_ptr)
{
found = 1;
copy_loops_on_surface.append(loop_copy);
}
}
}
// create the new surface
DLIList<CubitFacet*>facet_list;
DLIList<CubitPoint*>cpoint_list;
rv = fsurface->copy_facets( facet_list, cpoint_list, old_to_new_cubit_pts );
if (rv != CUBIT_SUCCESS)
{
return (BodySM *)NULL;
}
int interp_order = fsurface->interp_order();
double min_dot = fsurface->min_dot();
const CubitEvaluatorData *eval_data = fsurface->evaluator_data();
CubitBoolean use_point_addresses = CUBIT_FALSE;
rv = FacetModifyEngine::instance()->make_facet_surface(eval_data,
facet_list,
cpoint_list,
copy_loops_on_surface,
interp_order,
min_dot,
surface_copy,
use_point_addresses,
NULL,
&hard_line_curve_map);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy surfaces");
return (BodySM *)NULL;
}
old_to_new_map.insert(
std::make_pair( fsurface, surface_copy ) );
copy_surfaces.append( surface_copy );
}
// ----------------------copy shells--------------------------
DLIList<FacetShell*> shell_list;
get_shells(shell_list);
DLIList<ShellSM*> copy_shells;
shell_list.reset();
ShellSM *shell_ptr, *shell_copy;
FacetShell *fshell;<--- The scope of the variable 'fshell' can be reduced. [+]The scope of the variable 'fshell' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (ii=0; ii<shell_list.size(); ii++)
{
fshell = shell_list.get_and_step();
DLIList<FacetSurface *>surfaces_on_shell;
fshell->get_surfaces(surfaces_on_shell);
DLIList<Surface *>copy_surfaces_on_shell;
// find all associated loops on the surface
for(kk=0; kk<surfaces_on_shell.size(); kk++)
{
int found = 0;
surface_list.reset();
copy_surfaces.reset();
Surface *surface_on_shell = surfaces_on_shell.get_and_step();
for (jj=0; jj<surface_list.size() && !found; jj++)
{
surface_ptr = surface_list.get_and_step();
surface_copy = copy_surfaces.get_and_step();
if (surface_on_shell == surface_ptr)
{
found = 1;
copy_surfaces_on_shell.append(surface_copy);
}
}
}
// create the new shell
rv = FacetModifyEngine::instance()->make_facet_shell(copy_surfaces_on_shell,
shell_copy);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy shell");
return (BodySM *)NULL;
}
// set the sense of the surfaces on the shell - copy from the old shell
FacetShell *fshell_copy = CAST_TO(shell_copy, FacetShell);
surfaces_on_shell.reset();
copy_surfaces_on_shell.reset();
for (kk=0; kk<surfaces_on_shell.size(); kk++)
{
Surface *surface_on_shell = surfaces_on_shell.get_and_step();
Surface *copy_surface_on_shell = copy_surfaces_on_shell.get_and_step();
fsurface = CAST_TO( surface_on_shell, FacetSurface );
CubitSense sense = fsurface->get_shell_sense(fshell);
FacetSurface *copy_fsurface = CAST_TO( copy_surface_on_shell, FacetSurface );
copy_fsurface->set_shell_sense( fshell_copy, sense );
}
copy_shells.append( shell_copy );
}
// ----------------------copy lumps--------------------------
DLIList<FacetLump*> lump_list;
get_lumps(lump_list);
DLIList<Lump*> copy_lumps;
lump_list.reset();
Lump *lump_copy;
FacetLump *flump;<--- The scope of the variable 'flump' can be reduced. [+]The scope of the variable 'flump' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (ii=0; ii<lump_list.size(); ii++)
{
flump = lump_list.get_and_step();
DLIList<FacetShell *>shells_on_lump;
flump->get_shells(shells_on_lump);
DLIList<ShellSM *>copy_shells_on_lump;
// find all associated loops on the surface
for(kk=0; kk<shells_on_lump.size(); kk++)
{
int found = 0;
shell_list.reset();
copy_shells.reset();
ShellSM *shell_on_lump = shells_on_lump.get_and_step();
for (jj=0; jj<shell_list.size() && !found; jj++)
{
shell_ptr = shell_list.get_and_step();
shell_copy = copy_shells.get_and_step();
if (shell_on_lump == shell_ptr)
{
found = 1;
copy_shells_on_lump.append(shell_copy);
}
}
}
// create the new lump
rv = FacetModifyEngine::instance()->make_facet_lump(copy_shells_on_lump,
lump_copy);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy lump");
return (BodySM *)NULL;
}
old_to_new_map.insert(
std::make_pair( flump, lump_copy ) );
copy_lumps.append( lump_copy );
}
// ----------------------copy body--------------------------
BodySM *body_copy;
rv = FacetModifyEngine::instance()->make_facet_body(copy_lumps,
body_copy);
if(rv != CUBIT_SUCCESS)
{
PRINT_ERROR("Couldn't copy lump");
return (BodySM *)NULL;
}
//copy the attributes from old to new
std::map<TopologyBridge*, TopologyBridge*>::iterator iter;
for( iter= old_to_new_map.begin(); iter != old_to_new_map.end(); iter++ )<--- Prefer prefix ++/-- operators for non-primitive types. [+]Prefix ++/-- operators should be preferred for non-primitive types. Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code.
{
TopologyBridge *old_tb = iter->first;
TopologyBridge *new_tb = iter->second;
DLIList<CubitSimpleAttrib> old_attribs;
old_tb->get_simple_attribute( old_attribs );
for( int i=old_attribs.size(); i--; )
{
const CubitSimpleAttrib& copy = old_attribs.get_and_step();
new_tb->append_simple_attribute_virt( copy );
}
}
return (BodySM*)body_copy;
}
//----------------------------------------------------------------
// Function: can_be_deleted
// Description: determine if the body can be deleted
//
// Author: sjowen
//----------------------------------------------------------------
CubitBoolean FacetBody::can_be_deleted( DLIList <Body*> &body_list )
{
CubitBoolean delete_ok = CUBIT_TRUE;
DLIList<FacetSurface *>surf_list;
get_surfaces(surf_list);
int ii;
for (ii=0; ii<surf_list.size() && delete_ok; ii++)
{
FacetSurface *surf_ptr = surf_list.get_and_step();
DLIList<FacetBody*>my_body_list;
surf_ptr->get_bodies(my_body_list);
int jj; <--- The scope of the variable 'jj' can be reduced. [+]The scope of the variable 'jj' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
if (my_body_list.size() >= 2)
{
for (jj=0; jj<my_body_list.size() && delete_ok; jj++)
{
BodySM *my_body_ptr = my_body_list.get_and_step();
if (my_body_ptr != this)
{
int kk;
int found = 0;
for (kk=0; kk<body_list.size() && !found; kk++)
{
Body *body_ptr = body_list.get_and_step();
FacetBody* fbody_ptr = CAST_TO(body_ptr->get_body_sm_ptr(), FacetBody);
if (fbody_ptr)
{
if (my_body_ptr == fbody_ptr)
found = 1;
}
}
if (!found)
{
delete_ok = CUBIT_FALSE;
PRINT_ERROR("Body cannot be deleted because it is merged with adjacent Body\n");
PRINT_INFO(" Mesh Based Geometry entities cannot be unmerged.\n"
" Try using the no_merge option when importing the mesh\n");
}
}
}
}
}
return delete_ok;
}
//----------------------------------------------------------------
// Function: move
// Description: translate the body and its child entities
//
// Author: sjowen
//----------------------------------------------------------------
CubitStatus FacetBody::move(double dx, double dy, double dz)
{
CubitTransformMatrix tfmat;
tfmat.translate( dx, dy, dz );
CubitStatus stat = transform( tfmat, CUBIT_FALSE );
if (stat == CUBIT_SUCCESS)
myTransforms.translate( dx, dy, dz );
return stat;
}
//----------------------------------------------------------------
// Function: rotate
// Description: rotate the body and its child entities
//
// Author: sjowen
//----------------------------------------------------------------
CubitStatus FacetBody::rotate( double x, double y, double z,
double angle_in_degrees )
{
CubitTransformMatrix rotmat;
CubitVector axis( x, y, z );
rotmat.rotate( angle_in_degrees, axis );
CubitStatus stat = transform( rotmat, CUBIT_TRUE );
if (stat == CUBIT_SUCCESS)
myTransforms.rotate( angle_in_degrees, axis );
return stat;
}
//----------------------------------------------------------------
// Function: scale
// Description: scale the body and its child entities
// use a constant scale factor
//
// Author: sjowen
//----------------------------------------------------------------
CubitStatus FacetBody::scale(double scale_factor )
{
return scale(scale_factor,scale_factor,scale_factor);
}
//----------------------------------------------------------------
// Function: scale
// Description: scale the body and its child entities
//
// Author: sjowen
//----------------------------------------------------------------
CubitStatus FacetBody::scale(double scale_factor_x,
double scale_factor_y,
double scale_factor_z )
{
CubitTransformMatrix scalemat;
scalemat.scale_about_origin( scale_factor_x,
scale_factor_y,
scale_factor_z );
CubitStatus stat = transform( scalemat, CUBIT_FALSE );
if (stat == CUBIT_SUCCESS)
myTransforms.scale_about_origin( scale_factor_x,
scale_factor_y,
scale_factor_z );
// scale the facetcurve
DLIList<FacetCurve *> curve_list;
get_curves(curve_list);
Curve *curv_ptr;<--- The scope of the variable 'curv_ptr' can be reduced. [+]The scope of the variable 'curv_ptr' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (int ii=0; ii<curve_list.size(); ii++)
{
curv_ptr = curve_list.get_and_step();
FacetCurve *fcurve = CAST_TO( curv_ptr, FacetCurve );
if (fcurve)
{
fcurve->reset_length();
}
}
return stat;
}
//----------------------------------------------------------------
// Function: restore
// Description: restore the body and its child entities
// to its original coordinates using the inverse
// transformation matrix
//
// Author: sjowen
//----------------------------------------------------------------
CubitStatus FacetBody::restore()
{
// invert the transformation matrix and apply to entities
// (assumes an orthogonal matrix (ie. no shear or non-uniform scaling)
CubitTransformMatrix inverse_mat;
inverse_mat = myTransforms.inverse();
CubitStatus stat = transform( inverse_mat, CUBIT_TRUE );
if (stat == CUBIT_SUCCESS)
myTransforms.set_to_identity();
return stat;
}
//----------------------------------------------------------------
// Function: reflect
// Description: reflect the body about a exis
//
// Author: sjowen
//----------------------------------------------------------------
CubitStatus FacetBody::reflect( double reflect_axis_x,
double reflect_axis_y,
double reflect_axis_z )
{
CubitTransformMatrix reflectmat;
CubitVector reflect_vector( reflect_axis_x,
reflect_axis_y,
reflect_axis_z );
reflectmat.reflect( reflect_vector );
CubitStatus stat = transform( reflectmat, CUBIT_TRUE );
if (stat == CUBIT_SUCCESS)
myTransforms.reflect( reflect_vector );
return stat;
}
//----------------------------------------------------------------
// Function: transform
// Description: transform the body based on a transformation matrix
// main function for applying transformations to
// facet-based bodies
//
// Author: sjowen
//----------------------------------------------------------------
CubitStatus FacetBody::transform( CubitTransformMatrix &tfmat,
CubitBoolean is_rotation )
{
int ii;
// get the list of surfaces on the body
DLIList<FacetSurface *>surf_list;
get_surfaces( surf_list );
Surface *surf;
FacetSurface *fsurf;
FacetEvalTool *ftool;<--- The scope of the variable 'ftool' can be reduced. [+]The scope of the variable 'ftool' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
//CubitVector min, max;
// go through all the surfaces and collect the list of all points.
// (some may be listed on multiple surfaces)
DLIList<CubitPoint *>point_list;
for (ii=0; ii<surf_list.size(); ii++)
{
surf = surf_list.get_and_step();
fsurf = CAST_TO( surf, FacetSurface );
fsurf->get_my_points( point_list );
}
// unmark all the points so we can keep track of the ones that have
// already been transformed
CubitPoint *cp;
for (ii=0; ii<point_list.size(); ii++)
{
cp = point_list.get_and_step();
cp->marked( 0 );
}
// transform the points
//CubitVector norm, du, dv;
for (ii=0; ii<point_list.size(); ii++)
{
cp = point_list.get_and_step();
if (!cp->marked())
{
cp->transform( tfmat );
if (is_rotation)
cp->rotate_normal( tfmat );
cp->marked( 1 );
}
}
// check the vertices - make sure they are transformed
FacetPoint *fpt;
TBPoint *pt;<--- The scope of the variable 'pt' can be reduced. [+]The scope of the variable 'pt' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
DLIList<FacetPoint*>gpoint_list;
get_points(gpoint_list);
for (ii=0; ii<gpoint_list.size(); ii++)
{
pt = gpoint_list.get_and_step();
fpt = CAST_TO( pt, FacetPoint );
// only transform the point if it isn't already part of the facets
// (they could be points by themselves)
cp = fpt->get_cubit_point();
if (cp->num_adj_facets() == 0)
{
cp->transform( tfmat );
if (is_rotation)
cp->rotate_normal( tfmat );
}
}
// reset the bounding box and update the facet normal and plane
// init flags on edges to 0
DLIList<Surface*> tmp_surf_list( surf_list.size() );
CAST_LIST_TO_PARENT( surf_list, tmp_surf_list );
init_edge_flags( tmp_surf_list, 0 );
for (ii=0; ii<surf_list.size(); ii++)
{
surf = surf_list.get_and_step();
fsurf = CAST_TO( surf, FacetSurface );
// if we are using a bspline representation, then we also need to
// transform the control points on the edges and facets
ftool = fsurf->get_eval_tool();
if (ftool->interp_order() == 4)
{
ftool->transform_control_points( tfmat );
}
DLIList<CubitFacet *>flist;
DLIList<CubitPoint *>plist;
fsurf->get_my_facets( flist, plist);
int jj;
CubitFacet *facet_ptr;<--- The scope of the variable 'facet_ptr' can be reduced. [+]The scope of the variable 'facet_ptr' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (jj=0; jj<flist.size(); jj++)
{
facet_ptr = flist.get_and_step();
facet_ptr->update_plane();
facet_ptr->reset_bounding_box();
}
//must be done after facet's are reset...
ftool->reset_bounding_box();
// if this facet surface has a primitive evaluator, then we need
// to tell it about the transformation also.
fsurf->add_transformation( tfmat );
//re-calculate the area of the surface in case it changed
fsurf->update_measurement();
}
init_edge_flags( tmp_surf_list, 0 );
// Some transforms (those incorporating reflections)
// invert the geometry. Correct for it.
// -- jason k.
if ( tfmat.sub_matrix(3,3).determinant() < 0.0 )
{
// Flip CoFace senses
DLIList<FacetShell*> shells;
get_shells( shells );
//modified. mbrewer. doing both a reverse and a
//reverse_surfaces. the latter actually changes the
// underlying surfaces so that the normals can all
// still be outward pointing. It automatically changes
// the sense, therefore we also still need excplicity
// call reverse so that sense is corrected.
while (shells.size()){
shells.get()->reverse_surfaces();
shells.pop()->reverse();
}
}
return CUBIT_SUCCESS;
}
//----------------------------------------------------------------
// Function: init_edge_flags
// Description: set the flags on the facet edges
// Note: Only done for facet eval tool with order 4 interpolation
// Author: sjowen
//----------------------------------------------------------------
void FacetBody::init_edge_flags( DLIList<Surface *>&surf_list,
int )
{
int ii, jj;
Surface *surf;<--- The scope of the variable 'surf' can be reduced. [+]The scope of the variable 'surf' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
FacetSurface *fsurf;
FacetEvalTool *ftool;<--- The scope of the variable 'ftool' can be reduced. [+]The scope of the variable 'ftool' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
CubitFacetEdge *edge_ptr;
for (ii=0; ii<surf_list.size(); ii++)
{
DLIList<CubitFacetEdge*>edge_list;
surf = surf_list.get_and_step();
fsurf = CAST_TO( surf, FacetSurface );
ftool = fsurf->get_eval_tool();
if (ftool->interp_order() == 4)
{
ftool->get_edges( edge_list );
for (jj=0; jj<edge_list.size(); jj++)
{
edge_ptr = edge_list.get_and_step();
edge_ptr->set_flag( 0 );
}
}
}
}
CubitStatus FacetBody::get_transforms( CubitTransformMatrix &tfm )
{
tfm = myTransforms;
return CUBIT_SUCCESS;
}
CubitStatus FacetBody::set_transforms( CubitTransformMatrix tfm )
{
myTransforms = tfm;
return CUBIT_SUCCESS;
}
int FacetBody::validate(const CubitString &, DLIList <TopologyEntity*>&)
{
PRINT_ERROR("This option is not available for mesh defined geometry.\n");
return 0;
}
void FacetBody::get_parents_virt( DLIList<TopologyBridge*>& )
{}
void FacetBody::get_children_virt( DLIList<TopologyBridge*>& lumps )
{ CAST_LIST_TO_PARENT( myLumps, lumps ); }
void FacetBody::get_lumps( DLIList<FacetLump*>& result_list )
{
myLumps.reset();
for ( int i = 0; i < myLumps.size(); i++ )
if ( FacetLump* lump = dynamic_cast<FacetLump*>(myLumps.next(i)) )
result_list.append(lump);
}
void FacetBody::get_shells( DLIList<FacetShell*>& result_list )
{
DLIList<FacetLump*> lump_list;
get_lumps( lump_list );
lump_list.reset();
for ( int i = 0; i < lump_list.size(); i++ )
lump_list.next(i)->get_shells( result_list );
}
void FacetBody::get_surfaces( DLIList<FacetSurface*>& result_list )
{
DLIList<FacetShell*> shell_list;
DLIList<FacetSurface*> tmp_list;
get_shells(shell_list);
shell_list.reset();
for ( int i = 0; i < shell_list.size(); i++ )
{
tmp_list.clean_out();
shell_list.next(i)->get_surfaces( tmp_list );
result_list.merge_unique( tmp_list );
}
}
void FacetBody::get_loops( DLIList<FacetLoop*>& result_list )
{
DLIList<FacetSurface*> surface_list;
get_surfaces( surface_list );
surface_list.reset();
for ( int i = 0; i < surface_list.size(); i++ )
surface_list.next(i)->get_loops( result_list );
}
void FacetBody::get_coedges( DLIList<FacetCoEdge*>& result_list )
{
DLIList<FacetSurface*> surface_list;
get_surfaces( surface_list );
surface_list.reset();
for ( int i = 0; i < surface_list.size(); i++ )
surface_list.next(i)->get_coedges( result_list );
}
void FacetBody::get_curves( DLIList<FacetCurve*>& result_list )
{
DLIList<FacetCoEdge*> coedge_list;
get_coedges( coedge_list );
coedge_list.reset();
for ( int i = coedge_list.size(); i--; )
{
FacetCoEdge* coedge = coedge_list.get_and_step();
FacetCurve* curve = dynamic_cast<FacetCurve*>(coedge->curve());
if (curve)
result_list.append_unique(curve);
}
}
void FacetBody::get_points( DLIList<FacetPoint*>& result_list )
{
DLIList<FacetCurve*> curve_list;
get_curves( curve_list );
curve_list.reset();
for ( int i = curve_list.size(); i--; )
{
FacetCurve* curve = curve_list.get_and_step();
FacetPoint* point = dynamic_cast<FacetPoint*>(curve->start_point());
if (point)
result_list.append_unique(point);
point = dynamic_cast<FacetPoint*>(curve->end_point());
if (point)
result_list.append_unique(point);
}
}
void FacetBody::add_lump( FacetLump *lump_to_add )
{
Lump* lump = dynamic_cast<Lump*>(lump_to_add);
if (lump)
{
lump_to_add->add_body(this);
myLumps.append( lump );
}
}
void FacetBody::remove_lump( FacetLump *lump_to_remove )
{
FacetLump* lump = dynamic_cast<FacetLump*>(lump_to_remove);
if (lump)
{
assert(lump_to_remove->get_body() == this);
lump_to_remove->remove_body();
myLumps.remove( lump );
}
}
//-------------------------------------------------------------------------
// Purpose : Tear down topology
//
// Special Notes :
//
// Creator : Jason Kraftcheck
//
// Creation Date : 09/29/03
//-------------------------------------------------------------------------
void FacetBody::disconnect_all_lumps()
{
myLumps.reset();
for (int i = myLumps.size(); i--; )
{
Lump* sm_ptr = myLumps.get_and_step();
FacetLump* lump = dynamic_cast<FacetLump*>(sm_ptr);
if (lump)
{
assert(lump->get_body() == this);
lump->remove_body();
}
}
myLumps.clean_out();
}
//-------------------------------------------------------------------------
// Purpose : Find centroid
//
// Special Notes :
//
// Creator : Jason Kraftcheck
//
// Creation Date : 05/10/04
//-------------------------------------------------------------------------
CubitStatus FacetBody::mass_properties( CubitVector& centroid,
double& volume )
{
centroid.set( 0.0, 0.0, 0.0 );
volume = 0.0;
DLIList<FacetLump*> lumps (myLumps.size());
CAST_LIST( myLumps, lumps, FacetLump );
assert( myLumps.size() == lumps.size() );
for (int i = lumps.size(); i--; )
{
CubitVector cent;
double vol;
if (CUBIT_SUCCESS != lumps.get_and_step()->mass_properties(cent,vol))
return CUBIT_FAILURE;
centroid += vol*cent;
volume += vol;
}
if (volume > CUBIT_RESABS)
{
centroid /= volume;
}
else
{
centroid.set( 0.0, 0.0, 0.0 );
volume = 0.0;
}
return CUBIT_SUCCESS;
}
//-------------------------------------------------------------------------
// Purpose : Used to be FacetQueryEngine::is_point_in_body
//
// Special Notes :
//
// Creator : Jason Kraftcheck
//
// Creation Date : 05/10/04
//-------------------------------------------------------------------------
CubitPointContainment FacetBody::point_containment( const CubitVector &point, double tolerance )
{
CubitPointContainment pc_value;
FacetLump *facet_lump;
int i;
for(i=myLumps.size(); i--;)
{
facet_lump = dynamic_cast<FacetLump*>(myLumps.get_and_step());
pc_value = facet_lump->point_containment( point, tolerance );
if( pc_value == CUBIT_PNT_INSIDE )
return CUBIT_PNT_INSIDE;
else if( pc_value == CUBIT_PNT_BOUNDARY )
return CUBIT_PNT_BOUNDARY;
}
return CUBIT_PNT_OUTSIDE;
}
|