g4tools  5.4.0
sf_polyhedron
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_hep_sf_polyhedron
5 #define tools_hep_sf_polyhedron
6 
7 #include "../sg/bsf"
8 #include "polyhedron"
9 #include "../typedefs"
10 #include "../io/iwbuf"
11 #include "../io/irbuf"
12 #include "../HEADER"
13 
14 namespace tools {
15 namespace hep {
16 
17 class sf_polyhedron : public sg::bsf<polyhedron> {
19 public:
20  virtual bool write(io::iwbuf& a_buffer) {
21  //FIXME : write fNumberOfSteps ?
22 
23  int nvert = m_value.GetNoVertices();
24  int nface = m_value.GetNoFacets();
25  double* ds = new double[1+3*nvert+1+8*nface];
26  uint32 di=0;
27 
28  {ds[di] = nvert;di++;
29  HVPoint3D* pV = m_value.GetPV();
30  for(int index=1;index<=nvert;index++) { //CERN still in FORTRAN...
31  HVPoint3D& p = pV[index];
32  ds[di] = p[0];di++;
33  ds[di] = p[1];di++;
34  ds[di] = p[2];di++;
35  }}
36 
37  {ds[di] = nface;di++;
38  SbFacet* pF = m_value.GetPF();
39  int v,f;
40  for(int index=1;index<=nface;index++) {
41  SbFacet& fc = pF[index]; //yes, yes +1
42  for(int i=0;i<4;i++) {
43  fc.GetEdge(i,v,f);
44  ds[di] = v;di++;
45  ds[di] = f;di++;
46  }
47  }}
48 
49  bool status = a_buffer.write_vec(di,ds);
50 
51  delete [] ds;
52 
53  return status;
54  }
55 
56  virtual bool read(io::irbuf& a_buffer) {
57  double* ds;
58  uint32 sz;
59  if(!a_buffer.read_vec(sz,ds)) return false;
60  uint32 di=0;
61  //FIXME : check di vs sz.
62 
63  int nvert = (int)ds[di];di++;
64  HVPoint3D* pV = new HVPoint3D[nvert+1];
65  for(int index=1;index<=nvert;index++) {
66  HVPoint3D& p = pV[index];
67  p[0] = ds[di];di++;
68  p[1] = ds[di];di++;
69  p[2] = ds[di];di++;
70  }
71 
72  int nface = (int)ds[di];di++;
73  SbFacet* pF = new SbFacet[nface+1];
74  int v[8];
75  for(int index=1;index<=nface;index++) {
76  SbFacet& fc = pF[index];
77  for(int i=0;i<8;i++) {
78  v[i] = (int)ds[di];di++;
79  }
80  fc.Set(v);
81  }
82 
83  m_value.Set(nvert,pV,nface,pF); //it takes ownership of pV,pF.
84 
85  delete [] ds;
86 #ifdef TOOLS_MEM
87  mem::decrement(s_new().c_str());
88 #endif
89 
90  return true;
91  }
92  virtual bool dump(std::ostream&) {
93  return true;
94  }
95  virtual bool s_value(std::string& a_s) const {a_s.clear();return false;}
96  virtual bool s2value(const std::string&) {return false;}
97 public:
99  sf_polyhedron(const polyhedron& a_value):parent(a_value){}
100  virtual ~sf_polyhedron(){}
101 public:
102  sf_polyhedron(const sf_polyhedron& a_from):parent(a_from){}
104  parent::operator=(a_from);
105  return *this;
106  }
107 public:
109  parent::operator=(a_value);
110  return *this;
111  }
112 };
113 
114 }}
115 
116 #endif
tools::hep::SbFacet
Definition: polyhedron:45
tools::hep::SbFacet::GetEdge
void GetEdge(int i, int &v, int &f) const
Definition: polyhedron:119
tools::sg::bsf
Definition: bsf:19
tools::vec3d
Definition: vec3d:13
tools::sg::bsf< polyhedron >::m_value
polyhedron m_value
Definition: bsf:120
tools::io::irbuf::read_vec
virtual bool read_vec(uint32 &, uchar *&)=0
tools::hep::sf_polyhedron::~sf_polyhedron
virtual ~sf_polyhedron()
Definition: sf_polyhedron:100
tools::sg::field
Definition: field:25
tools::hep::polyhedron
Definition: polyhedron:142
tools::hep::SbFacet::Set
void Set(int v[8])
Definition: polyhedron:131
tools::hep::sf_polyhedron::operator=
sf_polyhedron & operator=(const polyhedron &a_value)
Definition: sf_polyhedron:108
tools::hep::sf_polyhedron::read
virtual bool read(io::irbuf &a_buffer)
Definition: sf_polyhedron:56
tools::sg::field::operator=
field & operator=(const field &)
Definition: field:57
tools::io::iwbuf::write_vec
virtual bool write_vec(uint32, const uchar *)=0
TOOLS_HEADER
#define TOOLS_HEADER(a__class, a__sclass, a__parent)
Definition: HEADER:10
tools::hep::sf_polyhedron::s2value
virtual bool s2value(const std::string &)
Definition: sf_polyhedron:96
tools::hep::sf_polyhedron::sf_polyhedron
sf_polyhedron()
Definition: sf_polyhedron:98
tools::hep::sf_polyhedron::dump
virtual bool dump(std::ostream &)
Definition: sf_polyhedron:92
tools::hep::sf_polyhedron::sf_polyhedron
sf_polyhedron(const sf_polyhedron &a_from)
Definition: sf_polyhedron:102
tools::hep::sf_polyhedron::sf_polyhedron
sf_polyhedron(const polyhedron &a_value)
Definition: sf_polyhedron:99
tools::hep::sf_polyhedron::s_value
virtual bool s_value(std::string &a_s) const
Definition: sf_polyhedron:95
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::io::irbuf
Definition: irbuf:19
tools::hep::sf_polyhedron::write
virtual bool write(io::iwbuf &a_buffer)
Definition: sf_polyhedron:20
tools::io::iwbuf
Definition: iwbuf:15
tools::hep::sf_polyhedron::operator=
sf_polyhedron & operator=(const sf_polyhedron &a_from)
Definition: sf_polyhedron:103
polyhedron
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::hep::sf_polyhedron
Definition: sf_polyhedron:17