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
+104 -13
View File
@@ -5,6 +5,8 @@
#define tools_sg_vertices
#include "node"
#include "gstos"
#include "sf"
#include "mf"
#include "render_action"
@@ -12,23 +14,24 @@
#include "bbox_action"
#include "visible_action"
#include "../vmanip"
namespace tools {
namespace sg {
class vertices : public node {
class vertices : public node, public gstos {
TOOLS_NODE(vertices,tools::sg::vertices,node)
typedef gstos parent_gstos;
public:
sf<gl::mode_t> mode;
mf<float> xyzs;
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::vertices)
static std::vector<field_desc> s_v;
if(s_v.empty()) {
s_v = parent::node_fields();
TOOLS_ADD_FIELD_DESC(mode)
TOOLS_ADD_FIELD_DESC(xyzs)
}
static const desc_fields s_v(parent::node_desc_fields(),2, //WARNING : take care of count.
TOOLS_ARG_FIELD_DESC(mode),
TOOLS_ARG_FIELD_DESC(xyzs)
);
return s_v;
}
private:
@@ -36,17 +39,66 @@ private:
add_field(&mode);
add_field(&xyzs);
}
protected: //gstos
virtual unsigned int create_gsto(std::ostream&,sg::render_manager& a_mgr) {
//unsigned int npt = xyzs.values().size()/3;
//::printf("debug : vertices : %lu : create_gsto : %u\n",this,npt);
return a_mgr.create_gsto_from_data(xyzs.values());
}
public:
virtual void render(render_action& a_action) {
if(xyzs.empty()) return;
const state& state = a_action.state();
if(state.m_use_gsto) {
unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
if(_id) {
#ifdef __APPLE__
bool restore_blend = check_set_blend(a_action);
#endif
a_action.begin_gsto(_id);
size_t npt = xyzs.values().size()/3;
bufpos pos = 0;
if(gl::is_line(mode.value())) {
//Same logic as Inventor SoLightModel.model = BASE_COLOR.
a_action.set_lighting(false);
a_action.draw_gsto_v(mode.value(),npt,pos);
a_action.set_lighting(state.m_GL_LIGHTING);
} else {
a_action.draw_gsto_v(mode.value(),npt,pos);
}
a_action.end_gsto();
#ifdef __APPLE__
if(restore_blend) a_action.set_blend(true);
#endif
return;
} else { //!_id
// use immediate rendering.
}
} else {
clean_gstos(&a_action.render_manager());
}
#ifdef __APPLE__
bool restore_blend = check_set_blend(a_action);
#endif
// immediate rendering :
if(gl::is_line(mode.value())) {
//Same logic as Inventor SoLightModel.model = BASE_COLOR.
const state& state = a_action.state();
a_action.set_lighting(false);
a_action.draw_vertex_array(mode.value(),xyzs.values());
a_action.set_lighting(state.m_GL_LIGHTING);
} else {
a_action.draw_vertex_array(mode.value(),xyzs.values());
}
#ifdef __APPLE__
if(restore_blend) a_action.set_blend(true);
#endif
}
virtual void pick(pick_action& a_action) {
a_action.add__primitive(*this,mode.value(),xyzs.values(),true);
@@ -76,6 +128,7 @@ public:
public:
vertices(const vertices& a_from)
:parent(a_from)
,parent_gstos(a_from)
,mode(a_from.mode)
,xyzs(a_from.xyzs)
{
@@ -86,6 +139,7 @@ public:
}
vertices& operator=(const vertices& a_from){
parent::operator=(a_from);
parent_gstos::operator=(a_from);
mode = a_from.mode;
xyzs = a_from.xyzs;
@@ -111,10 +165,9 @@ public:
v[a_pos] = a_z;a_pos++;
xyzs.touch();
}
/*
bool add(const std::vector<float>& a_v) {
std::vector<float>::size_type number = a_v.size()/3;
if(3*number!=a_v.size()) return false;
std::vector<float>::size_type _number = a_v.size()/3;
if(3*_number!=a_v.size()) return false;
std::vector<float>::const_iterator it;
for(it=a_v.begin();it!=a_v.end();it+=3) {
xyzs.add(*(it+0));
@@ -123,7 +176,7 @@ public:
}
return true;
}
*/
size_t number() const {return xyzs.size()/3;}
void clear() {xyzs.clear();}
@@ -156,6 +209,29 @@ public:
}
return true;
}
bool center() {
std::vector<float>& v = xyzs.values();
std::vector<float>::size_type _number = v.size()/3;
if(!_number) return true;
if(3*_number!=v.size()) return false;
float x_mean = 0;
float y_mean = 0;
float z_mean = 0;
{for(std::vector<float>::const_iterator it=v.begin();it!=v.end();it+=3) {
x_mean += *(it+0);
y_mean += *(it+1);
z_mean += *(it+2);
}}
x_mean /= float(_number);
y_mean /= float(_number);
z_mean /= float(_number);
{for(std::vector<float>::iterator it=v.begin();it!=v.end();it+=3) {
*(it+0) -= x_mean;
*(it+1) -= y_mean;
*(it+2) -= z_mean;
}}
return true;
}
protected:
bool _is_visible(const matrix_action& a_action) {
if(xyzs.empty()) return false;
@@ -171,6 +247,21 @@ protected:
if(!action.node()) return false;
return true;
}
#ifdef __APPLE__
protected:
// macOS/Mojave : on this version, points are blended even if alpha is one !
bool check_set_blend(render_action& a_action) {
bool restore_blend = false;
const state& state = a_action.state();
if(state.m_GL_BLEND) {
if(state.m_color.a()==1) {
a_action.set_blend(false);
restore_blend = true;
}
}
return restore_blend;
}
#endif //__APPLE__
};
}}