Import Geant4 10.6.0 source tree

This commit is contained in:
Gabriele Cosmo
2019-12-06 15:12:28 +01:00
parent b2a62ae692
commit 5baee230e9
2997 changed files with 141580 additions and 98673 deletions
+189 -63
View File
@@ -61,46 +61,66 @@ public:
sf<float> label_to_axis;
sf<float> label_height;
sf<bool> labels_no_overlap_automated;
sf<float> labels_gap; //in percent of width.
// time labels only in hplot modeling for the moment.
sf<bool> time_labels;
sf_string time_format;
sf<double> time_offset;
sf<bool> time_offset_is_GMT;
public:
virtual const std::vector<field_desc>& node_fields() const {
virtual const desc_fields& node_desc_fields() const {
TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::axis)
static std::vector<field_desc> s_v;
if(s_v.empty()) {
s_v = parent::node_fields();
TOOLS_ADD_FIELD_DESC(width)
TOOLS_ADD_FIELD_DESC(minimum_value)
TOOLS_ADD_FIELD_DESC(maximum_value)
TOOLS_ADD_FIELD_DESC(divisions)
TOOLS_ADD_FIELD_DESC(modeling)
TOOLS_ADD_FIELD_DESC(is_log)
TOOLS_ADD_FIELD_DESC(labels_enforced)
TOOLS_ADD_FIELD_DESC(tick_up)
TOOLS_ADD_FIELD_DESC(tick_length)
TOOLS_ADD_FIELD_DESC(tick_number)
TOOLS_ADD_FIELD_DESC(labels)
TOOLS_ADD_FIELD_DESC(values)
TOOLS_ADD_FIELD_DESC(coords)
TOOLS_ADD_FIELD_DESC(sub_coords)
TOOLS_ADD_FIELD_DESC(magnitude)
TOOLS_ADD_FIELD_DESC(title)
TOOLS_ADD_FIELD_DESC(title_to_axis)
TOOLS_ADD_FIELD_DESC(title_height)
TOOLS_ADD_FIELD_DESC(title_hjust)
TOOLS_ADD_FIELD_DESC(label_to_axis)
TOOLS_ADD_FIELD_DESC(label_height)
TOOLS_ADD_FIELD_DESC(time_labels)
TOOLS_ADD_FIELD_DESC(time_format)
TOOLS_ADD_FIELD_DESC(time_offset)
TOOLS_ADD_FIELD_DESC(time_offset_is_GMT)
}
static const desc_fields s_v(parent::node_desc_fields(),27, //WARNING : take care of count.
TOOLS_ARG_FIELD_DESC(width),
TOOLS_ARG_FIELD_DESC(minimum_value),
TOOLS_ARG_FIELD_DESC(maximum_value),
TOOLS_ARG_FIELD_DESC(divisions),
TOOLS_ARG_FIELD_DESC(modeling),
TOOLS_ARG_FIELD_DESC(is_log),
TOOLS_ARG_FIELD_DESC(labels_enforced),
TOOLS_ARG_FIELD_DESC(tick_up),
TOOLS_ARG_FIELD_DESC(tick_length),
TOOLS_ARG_FIELD_DESC(tick_number),
TOOLS_ARG_FIELD_DESC(labels),
TOOLS_ARG_FIELD_DESC(values),
TOOLS_ARG_FIELD_DESC(coords),
TOOLS_ARG_FIELD_DESC(sub_coords),
TOOLS_ARG_FIELD_DESC(magnitude),
TOOLS_ARG_FIELD_DESC(title),
TOOLS_ARG_FIELD_DESC(title_to_axis),
TOOLS_ARG_FIELD_DESC(title_height),
TOOLS_ARG_FIELD_DESC(title_hjust),
TOOLS_ARG_FIELD_DESC(label_to_axis),
TOOLS_ARG_FIELD_DESC(label_height),
TOOLS_ARG_FIELD_DESC(labels_no_overlap_automated),
TOOLS_ARG_FIELD_DESC(labels_gap),
TOOLS_ARG_FIELD_DESC(time_labels),
TOOLS_ARG_FIELD_DESC(time_format),
TOOLS_ARG_FIELD_DESC(time_offset),
TOOLS_ARG_FIELD_DESC(time_offset_is_GMT)
);
return s_v;
}
virtual bool touched() {
if(parent::touched()) return true;
if(line_style().touched()) return true;
if(ticks_style().touched()) return true;
if(labels_style().touched()) return true;
if(mag_style().touched()) return true;
if(title_style().touched()) return true;
return false;
}
virtual void reset_touched() {
parent::reset_touched();
line_style().reset_touched();
ticks_style().reset_touched();
labels_style().reset_touched();
mag_style().reset_touched();
title_style().reset_touched();
}
private:
void add_fields(){
// if adding a field, look for reset_style() and set_from_style()
@@ -125,6 +145,8 @@ private:
add_field(&title_hjust);
add_field(&label_to_axis);
add_field(&label_height);
add_field(&labels_no_overlap_automated);
add_field(&labels_gap);
add_field(&time_labels);
add_field(&time_format);
@@ -206,6 +228,9 @@ public:
,label_to_axis(0) //inited below
,label_height(0) //inited below
,labels_no_overlap_automated(true)
,labels_gap(0.02f)
,time_labels(false)
,time_format("%H:%M:%S")
,time_offset(0) //UTC_time_1970_01_01__00_00_00
@@ -244,6 +269,9 @@ public:
,label_to_axis(a_from.label_to_axis)
,label_height(a_from.label_height)
,labels_no_overlap_automated(a_from.labels_no_overlap_automated)
,labels_gap(a_from.labels_gap)
,time_labels(a_from.time_labels)
,time_format(a_from.time_format)
,time_offset(a_from.time_offset)
@@ -284,6 +312,9 @@ public:
label_to_axis = a_from.label_to_axis;
label_height = a_from.label_height;
labels_no_overlap_automated = a_from.labels_no_overlap_automated;
labels_gap = a_from.labels_gap;
time_labels = a_from.time_labels;
time_format = a_from.time_format;
time_offset = a_from.time_offset;
@@ -304,6 +335,14 @@ public:
text_style& title_style() {return m_title_style;}
text_style& mag_style() {return m_mag_style;}
void set_color(const colorf& a_color){
m_line_style.color = a_color;
m_ticks_style.color = a_color;
m_labels_style.color = a_color;
m_title_style.color = a_color;
m_mag_style.color = a_color;
}
public:
void update_sg(std::ostream& a_out) {
//a_out << "debug : tools::axis::update_sg :" << std::endl;
@@ -324,7 +363,7 @@ public:
m_line_sep.add(mat);
draw_style* ds = new draw_style;
ds->style = draw_style::lines;
ds->style = draw_lines;
ds->line_pattern = m_line_style.pattern;
ds->line_width = m_line_style.width;
m_line_sep.add(ds);
@@ -385,7 +424,7 @@ public:
m_ticks_sep.add(mat);
draw_style* ds = new draw_style;
ds->style = draw_style::lines;
ds->style = draw_lines;
ds->line_pattern = m_ticks_style.pattern;
ds->line_width = m_ticks_style.width;
m_ticks_sep.add(ds);
@@ -400,6 +439,10 @@ public:
// labels scene graph :
m_labels_sep.clear();
if(m_labels_style.visible && tick_number ) {
m_labels_seps.clear();
m_labels_xs.clear();
m_labels_mtxs.clear();
rgba* mat = new rgba();
mat->color = m_labels_style.color;
m_labels_sep.add(mat);
@@ -407,23 +450,9 @@ public:
float text_size = label_height*m_labels_style.scale;
std::string font = m_labels_style.font.value();
/*FIXME : adjust text_size to be sure that the labels do not overlap.
{int number = tick_number;
if(number>=2) {
float min_delta_tick = coords[number-1]-coords[0];
float xx_prev = coords[0];
for(unsigned int index=1;index<number;index++) {
float xx = coords[index];
min_delta_tick = SbMinimum(min_delta_tick,xx-xx_prev);
xx_prev = xx;
}
text_size = SbMinimum(text_size,min_delta_tick);
}}
*/
if(font==font_hershey()) {
draw_style* ds = new draw_style;
ds->style = draw_style::lines;
ds->style = draw_lines;
ds->line_pattern = m_labels_style.line_pattern;
ds->line_width = m_labels_style.line_width;
m_labels_sep.add(ds);
@@ -452,7 +481,6 @@ public:
if(bin_center) { //label at the center of the bin :
if(index==(number-1)) continue;
xx = 0.5f*(coords.values()[index]+coords.values()[index+1]);
} else { // label on tick :
xx = coords.values()[index];
}
@@ -463,17 +491,29 @@ public:
separator* sep = new separator;
m_labels_sep.add(sep);
add_string_opt(*sep,
font,
m_labels_style.encoding.value(),
m_labels_style.smoothing,
labels.values()[index],
vec[0],vec[1],vec[2],
scale_rot,
m_labels_style.hjust,
m_labels_style.vjust,
m_ttf);
matrix* _tsf =
add_string_opt(*sep,
font,
m_labels_style.font_modeling.value(),
m_labels_style.encoding.value(),
m_labels_style.smoothing,
labels.values()[index],
vec[0],vec[1],vec[2],
scale_rot,
m_labels_style.hjust,
m_labels_style.vjust,
m_ttf);
if(_tsf) {
m_labels_seps.push_back(sep);
m_labels_xs.push_back(xx);
m_labels_mtxs.push_back(_tsf);
}
}}
if(labels_no_overlap_automated.value()) avoid_labels_overlap(a_out);
m_labels_seps.clear();
m_labels_xs.clear();
m_labels_mtxs.clear();
}
m_mag_sep.clear();
@@ -496,7 +536,7 @@ public:
if(font==font_hershey()) {
draw_style* ds = new draw_style;
ds->style = draw_style::lines;
ds->style = draw_lines;
ds->line_pattern = m_mag_style.line_pattern;
ds->line_width = m_mag_style.line_width;
m_mag_sep.add(ds);
@@ -504,6 +544,7 @@ public:
add_string(m_mag_sep,
font,
m_mag_style.font_modeling.value(),
m_mag_style.encoding.value(),
m_mag_style.smoothing,
string,
@@ -528,7 +569,7 @@ public:
if(font==font_hershey()) {
draw_style* ds = new draw_style;
ds->style = draw_style::lines;
ds->style = draw_lines;
ds->line_pattern = m_title_style.line_pattern;
ds->line_width = m_title_style.line_width;
m_title_sep.add(ds);
@@ -552,6 +593,7 @@ public:
add_string(m_title_sep,
font,
m_title_style.font_modeling.value(),
m_title_style.encoding.value(),
m_title_style.smoothing,
title.value(),
@@ -595,6 +637,9 @@ public: //style
is_log = false;
title.value().clear();
labels_no_overlap_automated = true;
labels_gap = 0.02f;
if(a_geom) {
////////////////////////////////////////////
// Take PAW default :
@@ -715,7 +760,7 @@ public: //style
title_height = v;
} else if(key=="title_hjust") {
hjust v;
if(!style_parser::shjust(sv,v))
if(!shjust(sv,v))
{style_failed(a_out,key,sv);return false;}
title_hjust = v;
@@ -728,6 +773,15 @@ public: //style
if(!to(sv,v)) {style_failed(a_out,key,sv);return false;}
label_height = v;
} else if(key=="labels_no_overlap_automated") {
bool v;
if(!to(sv,v)) {style_failed(a_out,key,sv);return false;}
labels_no_overlap_automated = v;
} else if(key=="labels_gap") {
float v;
if(!to(sv,v)) {style_failed(a_out,key,sv);return false;}
labels_gap = v;
} else {
a_out << "axis::set_from_style :"
<< " unknown key " << key << "."
@@ -736,7 +790,75 @@ public: //style
}
return true;
}
void set_encoding(const std::string& a_value) {
labels_style().encoding = a_value;
mag_style().encoding = a_value;
title_style().encoding = a_value;
}
protected:
float get_overlap(std::ostream& a_out,bool& a_overlap) {
a_overlap = false;
std::vector<float> x_mins;
std::vector<float> x_maxs;
{size_t index = 0;
bbox_action _action(a_out);
tools_vforcit(separator*,m_labels_seps,it) {
_action.reset();
(*it)->bbox(_action);
if(_action.end()) {
float dx,dy,dz;
if(_action.box().get_size(dx,dy,dz)) {
if(dx>0) {
x_mins.push_back(m_labels_xs[index]-dx*0.5f);
x_maxs.push_back(m_labels_xs[index]+dx*0.5f);
}
}
}
index++;
}}
float dx_overlap = 0;
{size_t number = x_mins.size();
for(size_t index=1;index<number;index++) {
float dx = x_mins[index]-x_maxs[index-1];
if(dx<0) {
a_overlap = true;
dx_overlap = mx(dx_overlap,-dx);
}
}}
return dx_overlap;
}
void avoid_labels_overlap(std::ostream& a_out) {
bool overlap;
float first_scale = 1;
float first_overlap = get_overlap(a_out,overlap);
if(overlap) {
float second_scale = 1.1f; // greater than one to be sure to overlap again.
{tools_vforcit(matrix*,m_labels_mtxs,it) {
(*it)->mul_scale(second_scale,second_scale,1);
}}
float second_overlap = get_overlap(a_out,overlap);
if(overlap) {
// first_overlap = a*first_scale+b
// second_overlap = a*second_scale+b
float a = (second_overlap-first_overlap)/(second_scale-first_scale);
float b = first_overlap-a*first_scale;
//float wanted_scale = -b/a; //zero overlap.
float wanted_gap = width.value()*labels_gap.value();
float wanted_scale = (-wanted_gap-b)/a;
if(wanted_scale<=0) wanted_scale = 1; // this if() should not happen.
wanted_scale /= second_scale;
{tools_vforcit(matrix*,m_labels_mtxs,it) {
(*it)->mul_scale(wanted_scale,wanted_scale,1);
}}
} else { //it should not happen.
tools_vforcit(matrix*,m_labels_mtxs,it) {
(*it)->mul_scale(1.0f/second_scale,1.0f/second_scale,1);
}
}
}
}
static void style_failed(std::ostream& a_out,
const std::string& a_key,
const std::string& a_value) {
@@ -943,7 +1065,7 @@ protected:
float tickSize;
int tickIndex;
static float goodTicks[] = {10.0, 5.0, 4.0, 2.0, 1.0};
static const float goodTicks[] = {10.0, 5.0, 4.0, 2.0, 1.0};
for(tickIndex = 0;
aSize/(tickSize=goodTicks[tickIndex]*fpow(10.0,a_mag))<MIN_TICKS;
tickIndex++){}
@@ -1093,6 +1215,10 @@ protected:
text_style m_title_style;
std::vector<float> m_sub_ticks; //n*(2+2)
std::vector<separator*> m_labels_seps;
std::vector<float> m_labels_xs;
std::vector<matrix*> m_labels_mtxs;
};
}}