forked from nasa/puma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.cpp
1261 lines (853 loc) · 52.5 KB
/
examples.cpp
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
#include <iostream>
#include "puma.h"
using namespace std;
//_____________________________________________________________________________
// main function for Examples
int main (int argc, char **argv)
//-----------------------------------------------------------------------------
{
// To run input one command line argument from the list of codes below
// e.g. you can enter individual examples by entering "prim1" or the whole category as "prim"
if (argc <= 1){
cout << endl << "Enter one of the following codes to run examples:" << endl;
cout << "Name of Examples Code and # of examples to input in command line argument" << endl;
cout << "all examples all" << endl;
cout << "primitives prim1-5" << endl;
cout << "export export1-5" << endl;
cout << "import import1-2" << endl;
cout << "volumefraction volfrac" << endl;
cout << "isosurface isosurf" << endl;
cout << "surfacearea surfarea" << endl;
cout << "medianfilter3d filter1-3" << endl;
cout << "generaterandomfibers genfibers1-6" << endl;
cout << "generaterandomspheres genspheres1-2" << endl;
cout << "generatetpms gentpms" << endl;
cout << "porespace pore1-2" << endl;
cout << "meaninterceptlength mil" << endl;
cout << "orientation orient1-6" << endl;
cout << "conductivity cond1-11" << endl;
cout << "tortuosity tort1-4" << endl;
} else {
//// primitives ////
// primitives: Matrix
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"prim1")) || (!strcmp(argv[1],"prim"))){
cout << endl << "Creating a matrix with user input size and printing a slice of it:"<< endl;
puma::Matrix<double> mat(10,10,10, 3.5); // sets all the elements to 3.5
// N.B. note that if a value is not specified, matrix just allocates the memory, does not set the matrix to zeros
mat.set(0,-1, 4,4, 4,4, 1); // creating a central solid fiber
// N.B. -1 specifies until the end of domain mat.X()-1
mat.printRange(0,-1, 0,-1, 4,5);
}
// primitives: Workspace
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"prim2")) || (!strcmp(argv[1],"prim"))){
cout << endl << "Creating a grayscale workspace:"<< endl;
puma::Workspace grayWS(10,10,10,1e-6, false); // automatically initializes it to zeros
// false prevents it from writing the log, unnecessary for these tutorials
grayWS.matrix.set(0,-1, 4,4, 4,4, 255); // creating a central solid fiber
grayWS.matrix.printRange(0,-1, 0,-1, 4,5);
cout << endl << "Segmenting it into a segmented workspace:"<< endl;
puma::Cutoff cutoff(0,89); // calling puma::Cutoff is equivalent to calling pair<int,int>
grayWS.setMaterialID(cutoff,0); // mask the segmented ws with the grayscale one, thresholding by assigning 0 to the range 0-89
grayWS.setMaterialID(puma::Cutoff(90,255),1); // assigning 1 to the range 90-255, with the direct cutoff pair
grayWS.matrix.printRange(0,-1, 0,-1, 4,5);
}
// primitives: Vec3
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"prim3")) || (!strcmp(argv[1],"prim"))){
cout << endl << "Creating a vector with three components:"<< endl;
puma::Vec3<double> vector(60,5,1);
vector.x = 1; // reassign one of the components
cout << "Computing magnitude of original vector: " << vector.magnitude() << endl; // compute the magnitude
cout << "Computing magnitude of normalized vector: " << (vector.norm()).magnitude() << endl; // compute the magnitude
puma::Vec3<double> vector2(50,0,0);
vector.dot(vector2); // dot product
vector.cross(vector2); // cross product
}
// primitives: Vec4
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"prim4")) || (!strcmp(argv[1],"prim"))){
cout << endl << "Creating a vector with three components and a time value" << endl;
puma::Vec4<float> vec1(1.2, -3.4, 5.6);
puma::Vec4<float> vec2(1.2, -3.4, 5.6, 1);
}
// primitives: MatVec3
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"prim5"))){
cout << endl << "Creating a direction matrix for a single fiber running along x:" << endl;
puma::MatVec3<double> directions(10,10,10); // initializes it to Vec3(0,0,0)
directions.set(0,-1, 4,4, 4,4, puma::Vec3<double>(1,0,0));
directions.printRange(0,-1, 0,-1, 4,5);
}
//// export3dtiff ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"export1")) || (!strcmp(argv[1],"export"))){
cout << endl << "Exporting a puma matrix to a tiff file:"<< endl;
puma::Matrix<int> mat(10,10,10, 0);
mat.set(0,-1, 4,4, 4,4, 150); // -1 specifies until the end of domain
puma::export_3DTiff(&mat, "cpp/examples/exampledata/matrix_example_notnorm", false); // not normalized
puma::export_3DTiff(&mat, "cpp/examples/exampledata/matrix_example_norm", true); // normalized --> 150 becomes 255 since highest value
cout<< endl << "Exporting a workspace to a tiff file:"<< endl;
puma::Workspace grayWS(10,10,10,1e-6, false);
grayWS.matrix.set(0,-1, 4,4, 4,4, 255);
puma::export_3DTiff(&grayWS, "cpp/examples/exampledata/workspace_example_notnorm", false);
}
//// exportbin ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"export2")) || (!strcmp(argv[1],"export"))){
cout << endl << "Exporting a puma matrix to a binary file:"<< endl;
puma::Matrix<int> mat(10,10,10, 0);
mat.set(0,-1, 4,4, 4,4, 150); // -1 specifies until the end of domain
puma::export_bin(&mat, "cpp/examples/exampledata/mat_example"); // to specify numThreads, add one more int to the inputs at the end
cout<< endl << "Exporting a workspace to a binary file:"<< endl;
puma::Workspace grayWS(10,10,10,1e-6, false);
grayWS.matrix.set(0,-1, 4,4, 4,4, 255);
puma::export_bin(&grayWS, "cpp/examples/exampledata/workspace_example");
}
//// exportvtk ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"export3")) || (!strcmp(argv[1],"export"))){
cout << endl << "Exporting a puma matrix to a vtk file:"<< endl;
puma::Matrix<int> mat(10,10,10, 0);
mat.set(0,-1, 4,4, 4,4, 150); // -1 specifies until the end of domain
puma::export_vtk(&mat, "cpp/examples/exampledata/mat_example"); // to specify numThreads, add one more int to the inputs at the end
puma::export_vtk(&mat, "cpp/examples/exampledata/mat_example_ASCII", 'a'); // export vtk it in ASCII instead of BINARY
puma::export_vtk(&mat, "cpp/examples/exampledata/mat_example_ASCII_unstructured", 'a', true); // export vtk to an unstructured grid (for import in code Aster)
cout<< endl << "Exporting a workspace to a vtk file:"<< endl;
puma::Workspace grayWS(10,10,10,1e-6, false);
grayWS.matrix.set(0,-1, 4,4, 4,4, 255);
puma::export_vtk(&grayWS, "cpp/examples/exampledata/workspace_example");
}
//// exportstl ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"export4")) || (!strcmp(argv[1],"export"))){
cout << endl << "Running the Marching Cubes as the previous example and exporting the triangles created to an stl file:"<< endl;
puma::Workspace grayWS(1e-6, false);
puma::import_3DTiff(&grayWS,"cpp/test/tiff/grayWS/200_FiberForm.tif",0);
// 1. Exporting the STL Directly
puma::export_STL(&grayWS, puma::Cutoff(90,255), false,"cpp/examples/exampledata/triangles1");
// 2. Computing the Triangles separately via the marching cubes algorithm, then exporting the STL
vector< puma::Triangle<float> > tris;
puma::isosurface_MarchingCubes(&tris, &grayWS, puma::Cutoff(90,255), true,1,false,0);
cout << endl << "Number of triangles generated: " << tris.size()<< endl;
puma::export_STL(&tris,false,"cpp/examples/exampledata/triangles2");
// 3. Segmenting the Workspace, then computing the Triangles separately via the marching cubes algorithm, then exporting the STL
grayWS.setMaterialID(puma::Cutoff(0,89),0);
grayWS.setMaterialID(puma::Cutoff(90,255),1);
puma::isosurface_MarchingCubes(&tris, &grayWS, puma::Cutoff(1,1), true,1,false,0);
cout << endl << "Number of triangles generated: " << tris.size()<< endl;
puma::export_STL(&tris,false,"cpp/examples/exampledata/triangles3");
}
//// exporttextfile ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"export5")) || (!strcmp(argv[1],"export"))){
cout << endl << "Exporting a puma matrix to a text file:"<< endl;
puma::Matrix<int> mat(10,10,10, 0);
mat.set(0,-1, 4,4, 4,4, 150); // -1 specifies until the end of domain
puma::export_Textfile(&mat, "cpp/examples/exampledata/mat_example"); // to specify numThreads, add one more int to the inputs at the end
cout<< endl << "Exporting a workspace to a text file:"<< endl;
puma::Workspace grayWS(10,10,10,1e-6, false);
grayWS.matrix.set(0,-1, 4,4, 4,4, 255);
puma::export_Textfile(&grayWS, "cpp/examples/exampledata/workspace_example");
}
//// import3dtiff ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"import1")) || (!strcmp(argv[1],"import"))){
cout << endl << "Importing a grayscale workspace of FiberForm and printing a subset of it:" << endl;
puma::Workspace grayWS(1e-6, false); // no need to specify the size since the import function takes care of it
puma::import_3DTiff(&grayWS, "cpp/test/tiff/grayWS/200_FiberForm.tif",0); // note that .tif is required
grayWS.matrix.printRange(150,(int)grayWS.X()-1, 150, (int)grayWS.Y()-1, 100,101);
cout << "Importing the same segmented workspace and printing the same subset of it:" << endl;
puma::Workspace segWS(1e-6, false); // no need to specify the size since the import function takes care of it
puma::import_3DTiff(&segWS, "cpp/test/tiff/segWS/200_FiberForm.tif",0);
segWS.matrix.printRange(150,(int)segWS.X()-1, 150, (int)segWS.Y()-1, 100,101);
}
//// importbin ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"import2")) || (!strcmp(argv[1],"import"))){
cout << endl << "Importing a puma matrix to a binary file:"<< endl;
// *** Note: Run first ExportBin_Example to generate the data imported in this example ***
puma::Matrix<int> mat(10,10,10, 0);
mat.set(0,-1, 4,4, 4,4, 150); // -1 specifies until the end of domain
puma::import_bin(&mat, "cpp/examples/exampledata/mat_example.puma"); // note that .puma is required
// to specify the number of processors used to read file (i.e. numThreads), add one more int to the inputs at the end
mat.printRange(0,-1, 0,-1, 4,5);
cout<< endl << "Importing a workspace to a binary file:"<< endl;
puma::Workspace grayWS(10,10,10,1e-6, false);
grayWS.matrix.set(0,-1, 4,4, 4,4, 255);
puma::import_bin(&grayWS, "cpp/examples/exampledata/workspace_example.puma");
grayWS.matrix.printRange(0,-1, 0,-1, 4,5);
}
//// volumefraction ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"volfrac"))){
cout << endl << "Computing Porosity and Volume Fraction of a segmented Fiberform sample:"<< endl;
puma::Workspace workspace(1.3, false);
puma::import_3DTiff(&workspace, "cpp/test/tiff/segWS/200_FiberForm.tif",0);
cout << endl << "Porosity: " << puma::compute_VolumeFraction(&workspace,0,0) << endl;
cout << "Fiber Volume Fraction: " << puma::compute_VolumeFraction(&workspace,1,0) << endl;
}
//// isosurface ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"isosurf"))){
cout << endl << "Running the Marching Cubes on a grayscale FiberForm sample, with closed edges and factor of 2:"<< endl;
puma::Workspace grayWS(1e-6, false);
puma::import_3DTiff(&grayWS,"cpp/test/tiff/grayWS/200_FiberForm.tif",0);
// 1. Computing the Triangles via the Marching Cubes Algorithm. Faster, but there can be small holes in the mesh. Good for visualizations, bad for simulations
vector< puma::Triangle<float> > tris;
puma::isosurface_MarchingCubes(&tris, &grayWS,puma::Cutoff(90,255), true,1,false,0);
cout << endl << "Number of triangles generated - Maching Cubes Regular: " << tris.size()<< endl;
// 2. Computing the Triangles via the Lewiner Marching Cubes Algorithm. Slower, more triangles, but gaurantees topologically correct surface
puma::isosurface_LewinerMarchingCubes(&tris, &grayWS,puma::Cutoff(90,255), true,1,false,0);
cout << endl << "Number of triangles generated - Maching Cubes Lewiner: " << tris.size()<< endl;
// 3. Segmenting the Workspace, then computing the Triangles separately via the marching cubes algorithm, then exporting the STL
grayWS.setMaterialID(puma::Cutoff(0,89),0);
grayWS.setMaterialID(puma::Cutoff(90,255),1);
puma::isosurface_MarchingCubes(&tris,&grayWS,puma::Cutoff(90,255),true,1,false,0);
cout << endl << "Number of triangles generated - Segmented: " << tris.size()<< endl;
}
//// surfacearea ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"surfarea"))){
cout << endl << "Computing the surface area of a sample of FiberForm:"<< endl;
puma::Workspace grayWS(1e-6, false);
puma::import_3DTiff(&grayWS,"cpp/test/tiff/grayWS/200_FiberForm.tif",0);
pair<double, double> sa = compute_SurfaceAreaMarchingCubes(&grayWS, puma::Cutoff(128, 255), true, 0);
cout << endl << "Raw Surface Area: " << sa.first << " m^2" << endl;
cout << "Specific Surface Area: " << sa.first << " 1/m" << endl;
}
//// medianfilter3d ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"filter1")) || (!strcmp(argv[1],"filter"))){
cout << endl << "Applying a Median filter to a FiberForm sample and printing a slice of it:"<< endl;
puma::Workspace grayWS(1e-6, false);
puma::import_3DTiff(&grayWS, "cpp/test/tiff/grayWS/100_FiberForm.tif",0);
cout << "Before Median filter:"<< endl;
grayWS.matrix.printRange(50,-1, 50, -1, 50,51);
//in this case, the return should be true since all values are valid
puma::filter_Median3D(&grayWS,3);
cout << endl << "After Median filter:"<< endl;
grayWS.matrix.printRange(50,-1, 50, -1, 50,51);
}
//// meanfilter3d ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"filter2")) || (!strcmp(argv[1],"filter"))){
cout << endl << "Applying a Mean filter to a FiberForm sample and printing a slice of it:"<< endl;
puma::Workspace grayWS(1e-6, false);
puma::import_3DTiff(&grayWS, "cpp/test/tiff/grayWS/100_FiberForm.tif",0);
cout << "Before Mean filter:"<< endl;
grayWS.matrix.printRange(50,-1, 50, -1, 50,51);
//in this case, the return should be true since all values are valid
puma::filter_Mean3D(&grayWS,3);
cout << endl << "After Mean filter:"<< endl;
grayWS.matrix.printRange(50,-1, 50, -1, 50,51);
}
//// bilateralfilter ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"filter3")) || (!strcmp(argv[1],"filter"))){
cout << endl << "Applying a Bilateral filter to a FiberForm sample and printing a slice of it:"<< endl;
puma::Workspace grayWS(1e-6, false);
puma::import_3DTiff(&grayWS, "cpp/test/tiff/grayWS/100_FiberForm.tif",0);
cout << "Before Bilateral filter:"<< endl;
grayWS.matrix.printRange(50,-1, 50, -1, 50,51);
//in this case, the return should be true since all values are valid
puma::filter_Bilateral(&grayWS,4,4,50);
cout << endl << "After Bilateral filter:"<< endl;
grayWS.matrix.printRange(50,-1, 50, -1, 50,51);
}
//// generaterandomfibers ////
// generaterandomfibers: straightCircle
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genfibers1")) || (!strcmp(argv[1],"genfibers"))){
cout << endl << "Creating a 200^3 domain with non-intersecting random fibers having a circular cross section, slight preference for angle in XY:"<< endl;
// Creates an empty workspace
puma::Workspace grayWS(1e-6, false);
// Preparing inputs for fibers generation
RandomFibersInput input;
input.straightCircle(200,200,200,5,0,200,0,90,90,15,false,0.9,100);
input.print = true; // printing option can be turned off like this, ON as a default
// Generating fibers
puma::generateRandomFibers(&grayWS, input);
// Export to 3D tiff
puma::export_3DTiff(&grayWS,"cpp/examples/exampledata/RandomFibers_straightCircle_example.tiff",false);
}
// generaterandomfibers: curvedCircle
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genfibers2")) || (!strcmp(argv[1],"genfibers"))){
puma::Workspace grayWS(1e-6, false);
RandomFibersInput input;
input.curvedCircle(100,100,100,5,0,50,0,90,90,15,false,0.95,100,150,0,1e-3);
puma::generateRandomFibers(&grayWS, input);
puma::Workspace grayWS2(1e-6, false);
RandomFibersInput input2;
input2.curvedCircle(100,100,100,5,0,50,0,90,90,15,true,0.9,100,150,0,1e-3);
puma::generateRandomFibers(&grayWS2, input2);
}
// generaterandomfibers: straightFlower
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genfibers3")) || (!strcmp(argv[1],"genfibers"))){
puma::Workspace grayWS(1e-6, false);
RandomFibersInput input;
input.straightFlower(200,200,200,5,0,200,0,90,90,15,false,0.90,100,4,1,5,2,0);
puma::generateRandomFibers(&grayWS, input);
puma::Workspace grayWS2(1e-6, false);
RandomFibersInput input2;
input2.straightFlower(200,200,200,5,0,200,0,90,90,15,true,0.90,100,4,1,5,2,0);
puma::generateRandomFibers(&grayWS2, input2);
}
// generaterandomfibers: straightFlower_Hollow
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genfibers4")) || (!strcmp(argv[1],"genfibers"))){
puma::Workspace grayWS(1e-6, false);
RandomFibersInput input;
input.straightFlower_Hollow(200,200,200,5,0,200,0,90,90,15,false,0.90,100,4,1,5,2,0,1,2.5,0);
puma::generateRandomFibers(&grayWS, input);
puma::Workspace grayWS2(1e-6, false);
RandomFibersInput input2;
input2.straightFlower_Hollow(200,200,200,5,0,200,0,90,90,15,true,0.90,100,4,1,5,2,0,1,2.5,0);
puma::generateRandomFibers(&grayWS2, input2);
}
// generaterandomfibers: curvedFlower
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genfibers5")) || (!strcmp(argv[1],"genfibers"))){
puma::Workspace grayWS(1e-6, false);
RandomFibersInput input;
input.curvedFlower(100,100,100,5,0,100,0,90,90,15,false,0.95,100,120,0,1e-2,4,1,5,2,0);
puma::generateRandomFibers(&grayWS, input);
puma::Workspace grayWS2(1e-6, false);
RandomFibersInput input2;
input2.curvedFlower(100,100,100,5,0,100,0,90,90,15,true,0.95,100,120,0,1e-2,4,1,5,2,0);
puma::generateRandomFibers(&grayWS2, input2);
}
// generaterandomfibers: curvedFlower_Hollow
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genfibers6")) || (!strcmp(argv[1],"genfibers"))){
puma::Workspace grayWS(1e-6, false);
RandomFibersInput input;
input.curvedFlower_Hollow(100,100,100,5,0,100,0,90,90,15,false,0.95,100,120,0,1e-2,4,1,5,2,0,1,2.5,0);
puma::generateRandomFibers(&grayWS, input);
puma::Workspace grayWS2(1e-6, false);
RandomFibersInput input2;
input2.curvedFlower_Hollow(100,100,100,5,0,100,0,90,90,15,true,0.95,100,120,0,1e-2,4,1,5,2,0,1,2.5,0);
puma::generateRandomFibers(&grayWS2, input2);
}
//// generaterandomspheres ////
// generaterandomspheres: non-intersecting large spheres
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genspheres1")) || (!strcmp(argv[1],"genspheres"))){
cout << endl << "Creating a 200^3 domain with non-intersecting spheres:"<< endl;
puma::Timer t;
// Creates an empty workspace
puma::Workspace sphereWS(1e-6, false);
// Preparing inputs for spheres generation
RandomSpheresInput input(200,200,200,80.0,3.0,false,0.99,100);
// Generating spheres
puma::generateRandomSpheres(&sphereWS, input);
// Printing the elapsed time
cout << "Time: " << t.elapsed() << endl;
// Export to 3D tiff
puma::export_3DTiff(&sphereWS,"cpp/examples/exampledata/Generate_RandomSpheres_nonintersecting",false);
// Creating triangulated isosurface
vector<puma::Triangle<float> > Triangles;
puma::isosurface_MarchingCubes(&Triangles,&sphereWS,puma::Cutoff(128,255),true,1,false,40);
// Exporting to stl file
Export_STL test(&Triangles,false,"cpp/examples/exampledata/Generate_RandomSpheres_nonintersecting");
}
// generaterandomspheres: intersecting large spheres
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"genspheres2")) || (!strcmp(argv[1],"genspheres"))){
cout << endl << "Creating a 200^3 domain with intersecting spheres:"<< endl;
puma::Workspace sphereWS(1e-6, false);
RandomSpheresInput input(200,200,200,10.0,3.0,true,0.99,100);
puma::generateRandomSpheres(&sphereWS, input);
puma::export_3DTiff(&sphereWS,"cpp/examples/exampledata/Generate_RandomSpheres_intersecting.tif",false);
vector<puma::Triangle<float> > Triangles;
puma::isosurface_MarchingCubes(&Triangles,&sphereWS,puma::Cutoff(128,255),true,1,false);
Export_STL test(&Triangles,false,"cpp/examples/exampledata/Generate_RandomSpheres_intersecting.stl");
}
//// generatetpms ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"gentpms"))){
double diameter = 20; // in mm
double height = 38.1; // in mm
double p = 4.72;
double q = 0.5045;
bool circle = true;
bool exportSTL = false;
bool binaryTiff = true;
bool continuousTiff = true;
int equationNumber = 0; // equation 0, 1 or 2
std::string outputFolder = "cpp/test/out/stl/";
std::string outputLabel = "equation1";
int scale = 10; // keep between 5-20
int voxelsX = diameter * scale;
int voxelsY = diameter * scale;
int voxelsZ = height * scale;
double radius = diameter * scale / 2.0;
double p_scaled = p / scale;
puma::Workspace ws(1e-6,false);
// triply periodic minimal surface (TPMS)
TPMSInput input(voxelsX,voxelsY,voxelsZ,p_scaled,p_scaled,q,q, equationNumber);
bool success = puma::generateTPMS(&ws, input);
/// Comment out this section to keep rectangular
if(circle){
for(int i=0;i<ws.X();i++){
for(int j=0;j<ws.Y();j++){
for(int k=0;k<ws.Z();k++){
if(std::sqrt((i-ws.X()/2.0)*(i-ws.X()/2.0) + (j-ws.Y()/2.0)*(j-ws.Y()/2.0)) > radius ){
ws.matrix(i,j,k) = 0;
}
}
}
}
}
if (success) {
if(exportSTL){
puma::export_STL(&ws, puma::Cutoff(128, 255), false, outputFolder + outputLabel +"_tpms_test.stl");
}
if(continuousTiff) {
puma::export_3DTiff(&ws, outputFolder + outputLabel + "_tpms_test.tif", false);
}
if(binaryTiff) {
ws.setMaterialID(puma::Cutoff(0,127),0);
ws.setMaterialID(puma::Cutoff(128,255),255);
puma::export_3DTiff(&ws, outputFolder + outputLabel + "_tpms_test_binary.tif", false);
}
}
}
//// porespace ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"pore1")) || (!strcmp(argv[1],"pore"))){
puma::Workspace grayWS;
RandomFibersInput input;
input.straightFlower_Hollow(200,200,1, 30, 0, 1, 0, 0, 0, 90, true, 0.6, 2, 1, 0, 0, 0, 0, 1, 20, 0);
generateRandomFibers(&grayWS,input);
puma::Matrix<long> poreMatrix;
puma::identifyPoreSpace(&grayWS,&poreMatrix,puma::Cutoff(0,127));
double average = poreMatrix.average();
cout << "Average porespace: " << average << endl;
}
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"pore2")) || (!strcmp(argv[1],"pore"))) {
puma::Workspace grayWS;
RandomFibersInput input;
input.straightFlower_Hollow(200, 200, 1, 30, 0, 1, 0, 0, 0, 90, true, 0.6, 2, 1, 0, 0, 0, 0, 1, 20, 0);
generateRandomFibers(&grayWS, input);
puma::fillClosedPores(&grayWS, puma::Cutoff(0, 127), 255);
grayWS.setMaterialID(puma::Cutoff(0, 127), 0);
grayWS.setMaterialID(puma::Cutoff(128, 256), 1);
double average = grayWS.matrix.average();
cout << "Average porespace: " << average << endl;
}
//// meaninterceptlength ////
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"mil"))){
cout << endl << "Finding the mean intercept length of a FiberForm 200^3 sample:"<< endl;
// Creating empty workspace
puma::Workspace segWS(1e-6, false);
// Importing FiberForm 200^3 tiff, selecting only subsection of it
puma::import_3DTiff(&segWS,"cpp/test/tiff/segWS/200_FiberForm.tif");
// Computing the Mean Intercept Length
puma::Vec3<double> mil = puma::compute_MeanInterceptLength(&segWS,puma::Cutoff(0,0));
cout << "Mean Intercept Length: " << mil.x << ' ' << mil.y << ' ' << mil.z << endl;
}
//// orientation ////
// orientation: Ray Casting on Generated Random Fibers
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"orient1")) || (!strcmp(argv[1],"orient"))){
cout << endl << "Creating a random fiber domain and computing the Orientation via the ray casting method:"<< endl;
// Generating random fiber sample (see generateRandomFibers example for step-by-step description)
int scale = 50;
puma::Workspace grayWS(1e-5, false);
puma::MatVec3<double> tangents;
RandomFibersInput input;
input.straightCircle(scale,scale,scale,2,0,scale,0,90,90,90,false,0.9,1);
input.print = false; puma::generateRandomFibers(&grayWS,&tangents,input);
// Segmenting sample
puma::Workspace segWS(grayWS.shape(), false);
segWS.setMaterialID(&grayWS, puma::Cutoff(0,127),0);
segWS.setMaterialID(&grayWS, puma::Cutoff(128,255),1);
// Initializing orientation matrix
puma::MatVec3<double> dirs;
// Computing orientation using Cay Casting (RC)
puma::compute_orientationRC(&segWS, puma::Cutoff(1, 1), 15,5, &dirs, false);
// Initializing orientation error matrix
puma::Matrix<double> error;
// Computing orientation error between the estimated orientation (dirs) and the true orientation (tangents)
pair <double, double> MeanSD = puma::compute_orientationComparison(&segWS, &dirs, &tangents, &error, puma::Cutoff(1,1));
cout << "Mean: " << MeanSD.first << endl;
cout << "Standard Deviation: " << MeanSD.second << endl;
}
// orientation: Artificial Flux on Generated Random Fibers
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"orient3")) || (!strcmp(argv[1],"orient"))){
cout << endl << "Creating a random fiber domain and computing the Orientation via the artificial flux method:"<< endl;
// Generating random fiber sample (see generateRandomFibers example for step-by-step description)
int scale = 50;
puma::Workspace grayWS(1e-5, false);
puma::MatVec3<double> tangents;
RandomFibersInput input;
input.straightCircle(scale,scale,scale,2,0,scale,0,90,90,90,false,0.9,1);
input.print = false; puma::generateRandomFibers(&grayWS,&tangents,input);
puma::Workspace segWS(grayWS.shape(), false);
segWS.setMaterialID(&grayWS,puma::Cutoff(0,127),0);
segWS.setMaterialID(&grayWS,puma::Cutoff(128,255),1);
puma::MatVec3<double> dirs;
// Computing orientation using Artificial Flux (AF)
puma::compute_orientationAF(&segWS, &dirs, puma::Cutoff(1, 1), 1e-5, 10000,false);
puma::Matrix<double> error;
pair <double, double> MeanSD = puma::compute_orientationComparison(&segWS, &dirs, &tangents, &error, puma::Cutoff(1,1));
cout << "Mean: " << MeanSD.first << endl;
cout << "Standard Deviation: " << MeanSD.second << endl;
}
// orientation: Structure Tensor on Generated Random Fibers
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"orient5")) || (!strcmp(argv[1],"orient"))){
cout << endl << "Creating a random fiber domain and computing the Orientation via the structure tensor method:"<< endl;
// Generating random fiber sample (see generateRandomFibers example for step-by-step description)
int scale = 50;
puma::Workspace grayWS(1e-5, false);
puma::MatVec3<double> tangents;
RandomFibersInput input;
input.straightCircle(scale,scale,scale,2,0,scale,0,90,90,90,false,0.9,1);
input.print = false; puma::generateRandomFibers(&grayWS,&tangents,input);
puma::Workspace segWS(grayWS.shape(), false);
segWS.setMaterialID(&grayWS, puma::Cutoff(0,127),0);
segWS.setMaterialID(&grayWS, puma::Cutoff(128,255),1);
puma::MatVec3<double> dirs;
// Computing orientation using Structure Tensor (ST)
puma::compute_orientationST(&segWS, 0.7, 1.1, puma::Cutoff(1, 1), &dirs,false);
puma::Matrix<double> error;
pair <double, double> MeanSD = puma::compute_orientationComparison(&segWS, &dirs, &tangents, &error, puma::Cutoff(1,1));
cout << "Mean: " << MeanSD.first << endl;
cout << "Standard Deviation: " << MeanSD.second << endl;
}
//// conductivity ////
// fvthermalconductivity: Multiple materials in series
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"cond1")) || (!strcmp(argv[1],"cond"))){
cout << endl << "Computing the thermal conductivity using finite volume considering a locally isotropic sample having several materials in series:"<< endl;
// Initializing Workspace
puma::Workspace segWS(100,57,62,0,1e-6, false);
// Setting the workspace values of the materials in series
segWS.matrix.set(10,19,0,56,0,61,1);
segWS.matrix.set(20,29,0,56,0,61,2);
segWS.matrix.set(30,39,0,56,0,61,3);
segWS.matrix.set(40,49,0,56,0,61,4);
segWS.matrix.set(50,59,0,56,0,61,5);
segWS.matrix.set(60,69,0,56,0,61,6);
segWS.matrix.set(70,79,0,56,0,61,7);
segWS.matrix.set(80,89,0,56,0,61,8);
segWS.matrix.set(90,99,0,56,0,61,9);
// Initializing Temperature field
puma::Matrix<double> T;
// Initializing material conductivity
map<int, double> matCond;
matCond[0] = 1;
matCond[1] = 2;
matCond[2] = 3;
matCond[3] = 4;
matCond[4] = 5;
matCond[5] = 6;
matCond[6] = 7;
matCond[7] = 8;
matCond[8] = 9;
matCond[9] = 10;
// Running simulation
puma::Vec3<double> k = puma::compute_FVThermalConductivity(&segWS, &T, matCond,"periodic","bicgstab",'z',1e-3,10000,true);
cout << endl << "Conductivity: " << endl;
cout << "kxx " << k.x << " kxy " << k.y << " kxz " << k.z << endl;
}
// fvthermalconductivity: FiberForm 100^3
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"cond2")) || (!strcmp(argv[1],"cond"))){
cout << endl << "Computing the thermal conductivity using finite volume considering a locally isotropic FiberForm 100^3 sample:"<< endl;
// Initializing Workspace
puma::Workspace ws(1e-6, false);
// Importing 3D tiff
puma::import_3DTiff(&ws,"cpp/test/tiff/grayWS/100_FiberForm.tif");
// Segmenting workspace by thresholding
ws.setMaterialID(&ws,puma::Cutoff(0,89),0);
ws.setMaterialID(&ws,puma::Cutoff(90,255),1);
// Initializing Temperature field and material conductivity
puma::Matrix<double> T;
map<int, double> matCond;
matCond[0] = 0.0257; // air conductivity
matCond[1] = 12; // approximation to fiber conductivity
// Running simulation in three directions
puma::Vec3<double> kx = puma::compute_FVThermalConductivity(&ws, &T, matCond,"symmetric","cg",'x',1e-3,10000,true);
puma::Vec3<double> ky = puma::compute_FVThermalConductivity(&ws, &T, matCond,"symmetric","cg",'y',1e-3,10000,true);
puma::Vec3<double> kz = puma::compute_FVThermalConductivity(&ws, &T, matCond,"symmetric","cg",'z',1e-3,10000,true);
cout << endl << "Conductivity: " << endl;
cout << "kxx " << kx.x << " kxy " << kx.y << " kxz " << kx.z << endl;
cout << "kyx " << ky.x << " kyy " << ky.y << " kyz " << ky.z << endl;
cout << "kzx " << kz.x << " kzy " << kz.y << " kzz " << kz.z << endl;
}
// ejthermalconductivity: Multiple materials in series
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"cond3")) || (!strcmp(argv[1],"cond"))){
cout << endl << "Computing the thermal conductivity using explicit jump considering a locally isotropic sample having several materials in series:"<< endl;
// Initializing Workspace
puma::Workspace segWS(100,57,62,0,1e-6, false);
// Setting the workspace values of the materials in series
segWS.matrix.set(10,19,0,56,0,61,1);
segWS.matrix.set(20,29,0,56,0,61,2);
segWS.matrix.set(30,39,0,56,0,61,3);
segWS.matrix.set(40,49,0,56,0,61,4);
segWS.matrix.set(50,59,0,56,0,61,5);
segWS.matrix.set(60,69,0,56,0,61,6);
segWS.matrix.set(70,79,0,56,0,61,7);
segWS.matrix.set(80,89,0,56,0,61,8);
segWS.matrix.set(90,99,0,56,0,61,9);
// Initializing Temperature field
puma::Matrix<double> T;
// Initializing material conductivity
map<int, double> matCond;
matCond[0] = 1;
matCond[1] = 2;
matCond[2] = 3;
matCond[3] = 4;
matCond[4] = 5;
matCond[5] = 6;
matCond[6] = 7;
matCond[7] = 8;
matCond[8] = 9;
matCond[9] = 10;
// Running simulation
puma::Vec3<double> k = compute_EJThermalConductivity(&segWS, &T, matCond,'x',1e-3,10000,true);
cout << endl << "Conductivity: " << endl;
cout << "kxx " << k.x << " kxy " << k.y << " kxz " << k.z << endl;
}
// ejthermalconductivity: FiberForm 100^3
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"cond4")) || (!strcmp(argv[1],"cond"))){
cout << endl << "Computing the thermal conductivity using explicit jump considering a locally isotropic FiberForm 100^3 sample:"<< endl;
// Initializing Workspace
puma::Workspace ws(1e-6, false);
// Importing 3D tiff
puma::import_3DTiff(&ws,"cpp/test/tiff/grayWS/100_FiberForm.tif");
// Segmenting workspace by thresholding
ws.setMaterialID(&ws,puma::Cutoff(0,89),0);
ws.setMaterialID(&ws,puma::Cutoff(90,255),1);
// Initializing Temperature field and material conductivity
puma::Matrix<double> T;
map<int, double> matCond;
matCond[0] = 0.0257; // air conductivity
matCond[1] = 12; // approximation to fiber conductivity
// Running simulation in three directions
puma::Vec3<double> kx = compute_EJThermalConductivity(&ws, &T, matCond,'x',1e-3,10000,true);
puma::Vec3<double> ky = compute_EJThermalConductivity(&ws, &T, matCond,'x',1e-3,10000,true);
puma::Vec3<double> kz = compute_EJThermalConductivity(&ws, &T, matCond,'x',1e-3,10000,true);
cout << endl << "Conductivity: " << endl;
cout << "kxx " << kx.x << " kxy " << kx.y << " kxz " << kx.z << endl;
cout << "kyx " << ky.x << " kyy " << ky.y << " kyz " << ky.z << endl;
cout << "kzx " << kz.x << " kzy " << kz.y << " kzz " << kz.z << endl;
}
// fvanisotropicthermalconductivity: Multiple materials in series
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"cond5")) || (!strcmp(argv[1],"cond"))){
cout << endl << "Computing the thermal conductivity using finite volume considering a locally anisotropic sample having several materials in series:"<< endl;
// Initializing Workspace
puma::Workspace segWS(100,57,62,0,1e-6, false);
// Setting the workspace values of the materials in series
segWS.matrix.set(10,19,0,56,0,61,1);
segWS.matrix.set(20,29,0,56,0,61,2);
segWS.matrix.set(30,39,0,56,0,61,3);
segWS.matrix.set(40,49,0,56,0,61,4);
segWS.matrix.set(50,59,0,56,0,61,5);
segWS.matrix.set(60,69,0,56,0,61,6);
segWS.matrix.set(70,79,0,56,0,61,7);
segWS.matrix.set(80,89,0,56,0,61,8);
segWS.matrix.set(90,99,0,56,0,61,9);
// Initializing Temperature and Flux field
puma::Matrix<double> T;
puma::MatVec3<double> q;
// Initializing material conductivity
map<int, vector<double>> matCond;
matCond[0] = {1,1,1,0,0,0};
matCond[1] = {2,2,2,0,0,0};
matCond[2] = {3,3,3,0,0,0};
matCond[3] = {4,4,4,0,0,0};
matCond[4] = {5,5,5,0,0,0};
matCond[5] = {6,6,6,0,0,0};
matCond[6] = {7,7,7,0,0,0};
matCond[7] = {8,8,8,0,0,0};
matCond[8] = {9,9,9,0,0,0};
matCond[9] = {10,10,10,0,0,0};
// Running simulation
puma::Vec3<double> k = puma::compute_FVanisotropicThermalConductivity(&segWS, &T, &q, matCond, "mpfa", "symmetric","bicgstab",'x',1e-2,10000,true);
cout << endl << "Conductivity: " << endl;
cout << "kxx " << k.x << " kxy " << k.y << " kxz " << k.z << endl;
}
// fvanisotropicthermalconductivity: FiberForm 100^3
if((!strcmp(argv[1],"all")) || (!strcmp(argv[1],"cond6")) || (!strcmp(argv[1],"cond"))){
cout << endl << "Computing the thermal conductivity using finite volume considering a locally anisotropic FiberForm 100^3 sample:"<< endl;
// Initializing Workspace
puma::Workspace ws(1e-6, false);
// Importing 3D tiff
puma::import_3DTiff(&ws,"cpp/test/tiff/grayWS/100_FiberForm.tif");
// Computing orientations using Structure Tensor (ST) method
puma::MatVec3< double> tangents;
puma::compute_orientationST(&ws, 0.7, 0.7, puma::Cutoff(89,255), &tangents);
// Initializing Temperature, flux field and material conductivity
puma::Matrix<double> T;
puma::MatVec3<double> q;
map<int, vector<double>> matCond;
matCond[89] = {0.0257}; // air conductivity
matCond[255] = {15, 8}; // approximation to fiber conductivity, here considered isotropic as an example