GCC Code Coverage Report


Directory: ./
File: Tools/sciplot_utilities.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 0 4 0.0%
Branches: 0 8 0.0%

Line Branch Exec Source
1 // ______ ______ _ _ _____ ______
2 // | ____| ____| | (_)/ ____| | ____|
3 // | |__ | |__ | | _| (___ ___| |__
4 // | __| | __| | | | |\___ \ / __| __|
5 // | | | |____| |____| |____) | (__| |____
6 // |_| |______|______|_|_____/ \___|______|
7 // Finite Elements for Life Sciences and Engineering
8 //
9 // License: LGL2.1 License
10 // FELiScE default license: LICENSE in root folder
11 //
12 // Main authors: Vicente Mataix Ferrandiz
13 //
14
15 // System includes
16
17 // External includes
18 #ifdef FELISCE_WITH_SCIPLOT
19 #ifndef FELISCE_COMPILED_IN_MAC_OS // Does not work in Mac OS
20 #include "Core/NoThirdPartyWarning/Sciplot/sciplot.hpp"
21 #endif
22 #endif
23
24 // Project includes
25 #include "Tools/sciplot_utilities.hpp"
26
27 namespace felisce
28 {
29
30 namespace SciplotUtilities
31 {
32
33 void Generate2DPlot(
34 const felisce::TableInterpolation& rTable,
35 const std::string FileType,
36 const bool ShowPlot
37 )
38 {
39 const std::vector<felisce::TableInterpolation> aux_tables = {rTable};
40 Generate2DPlot(aux_tables, FileType, ShowPlot);
41 }
42
43 /***********************************************************************************/
44 /***********************************************************************************/
45
46 void Generate2DPlot(
47 const std::vector<felisce::TableInterpolation>& rTables,
48 const std::string FileType,
49 const bool ShowPlot
50 )
51 {
52 // ignore unused argument
53 #ifndef FELISCE_WITH_SCIPLOT
54 static_cast<void>(rTables);
55 static_cast<void>(FileType);
56 static_cast<void>(ShowPlot);
57 #endif
58
59 #ifdef FELISCE_WITH_SCIPLOT
60 #ifdef FELISCE_COMPILED_IN_MAC_OS // Does not work in Mac OS
61 static_cast<void>(rTables);
62 static_cast<void>(FileType);
63 static_cast<void>(ShowPlot);
64 #endif
65 #endif
66 //end ignore unused argument
67
68 #ifdef FELISCE_WITH_SCIPLOT
69 #ifndef FELISCE_COMPILED_IN_MAC_OS // Does not work in Mac OS
70 // Create a Plot object
71 sciplot::Plot plot;
72
73 // Set the width and height of the plot in points (72 points = 1 inch)
74 plot.size(360, 360);
75
76 // Set the font name and size
77 plot.fontName("Helvetica");
78 plot.fontSize(12);
79
80 // Set the x and y labels
81 auto& r_var_names = rTables[0].GetVariablesNames(); // Get the names of the variables, assuming always same name
82 plot.xlabel(r_var_names[0]);
83 plot.ylabel(r_var_names[1]);
84
85 // Set some options for the legend
86 plot.legend()
87 .atTop()
88 .fontSize(10)
89 .displayHorizontal()
90 .displayExpandWidthBy(2);
91
92 // Plotting all tables
93 for (auto& r_table : rTables) {
94 auto& r_names = r_table.GetVariablesNames();
95 const auto vectors = r_table.GetTableAsVectors();
96
97 // The x vector
98 const sciplot::Vec x(vectors[0].data(), vectors[0].size());
99
100 // The y vector
101 const sciplot::Vec y(vectors[1].data(), vectors[1].size());
102
103 // Plot the function
104 plot.drawCurveWithPoints(x, y).label(r_names[1]);
105 }
106
107 // Show the plot in a pop-up window
108 if (ShowPlot) {
109 plot.show();
110 }
111
112 // Save the plot to a PDF file
113 plot.save(rTables[0].GetTableName() + "." + FileType);
114 #endif
115 #endif
116 }
117
118 } // namespace SciplotUtilities
119 } // namespace felisce
120