g4tools  5.4.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
tools::sg::ellipse Class Reference
Inheritance diagram for tools::sg::ellipse:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::ellipse:
Collaboration graph
[legend]

Public Member Functions

virtual void * cast (const std::string &a_class) const
 
virtual const desc_fieldsnode_desc_fields () const
 
virtual bool pos_tan_nor (float, vec3f &a_pos, vec3f &a_tan, vec3f &a_nor) const
 
virtual void copy (curve *&a_new) const
 
virtual void render (render_action &a_action)
 
virtual void pick (pick_action &a_action)
 
virtual void bbox (bbox_action &a_action)
 
 ellipse ()
 
virtual ~ellipse ()
 
 ellipse (const ellipse &a_from)
 
ellipseoperator= (const ellipse &a_from)
 
- Public Member Functions inherited from tools::sg::node
virtual const std::string & s_cls () const =0
 
virtual nodecopy () const =0
 
virtual unsigned int cls_version () const
 
virtual void search (search_action &a_action)
 
virtual void get_matrix (get_matrix_action &a_action)
 
virtual bool write (write_action &a_action)
 
virtual void event (event_action &)
 
virtual bool read (read_action &a_action)
 
virtual void is_visible (visible_action &)
 
virtual void protocol_one_fields (std::vector< field * > &a_fields) const
 
virtual bool draw_in_frame_buffer () const
 
virtual bool touched ()
 
virtual void reset_touched ()
 
 node ()
 
virtual ~node ()
 
void touch ()
 
fieldfield_from_desc (const field_desc &a_desc) const
 
void dump_field_descs (std::ostream &a_out) const
 
fieldfind_field_by_name (const std::string &a_name) const
 
- Public Member Functions inherited from tools::curve
 curve ()
 
virtual ~curve ()
 
 curve (const curve &a_from)
 
curveoperator= (const curve &a_from)
 
void set_model_matrix (const mat4f &a_m)
 

Public Attributes

sf< float > rx
 
sf< float > ry
 
sf< float > phi_min
 
sf< float > phi_max
 
sf< unsigned int > steps
 

Protected Member Functions

void update_sg ()
 
- Protected Member Functions inherited from tools::sg::node
 node (const node &)
 
nodeoperator= (const node &)
 
void add_field (field *a_field)
 
bool write_fields (write_action &a_action)
 
bool read_fields (read_action &a_action)
 
field_desc::offset_t field_offset (const field *a_field) const
 
fieldfind_field (const field_desc &a_rdesc) const
 
void check_fields (std::ostream &a_out) const
 

Protected Attributes

std::vector< float > m_xyzs
 
- Protected Attributes inherited from tools::curve
mat4f m_model
 

Detailed Description

Definition at line 21 of file ellipse.

Constructor & Destructor Documentation

◆ ellipse() [1/2]

tools::sg::ellipse::ellipse ( )
inline

Definition at line 125 of file ellipse.

126  :parent()
127  ,curve()
128  ,rx(1)
129  ,ry(1)
130  ,phi_min(0)
132  ,steps(40)
133  {
134  add_fields();
135  }

◆ ~ellipse()

virtual tools::sg::ellipse::~ellipse ( )
inlinevirtual

Definition at line 136 of file ellipse.

136 {}

◆ ellipse() [2/2]

tools::sg::ellipse::ellipse ( const ellipse a_from)
inline

Definition at line 138 of file ellipse.

139  :parent(a_from)
140  ,curve(a_from)
141  ,rx(a_from.rx)
142  ,ry(a_from.ry)
143  ,phi_min(a_from.phi_min)
144  ,phi_max(a_from.phi_max)
145  ,steps(a_from.steps)
146  {
147  add_fields();
148  }

Member Function Documentation

◆ bbox()

virtual void tools::sg::ellipse::bbox ( bbox_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 117 of file ellipse.

117  {
118  if(touched()) {
119  update_sg();
120  reset_touched();
121  }
122  a_action.add_line_strip(m_xyzs);
123  }

◆ cast()

virtual void* tools::sg::ellipse::cast ( const std::string &  a_class) const
inlinevirtual

Reimplemented from tools::curve.

Definition at line 24 of file ellipse.

24  {
25  if(void* p = cmp_cast<ellipse>(this,a_class)) return p;
26  if(void* p = cmp_cast<curve>(this,a_class)) return p;
27  return node::cast(a_class);
28  }

◆ copy()

virtual void tools::sg::ellipse::copy ( curve *&  a_new) const
inlinevirtual

Implements tools::curve.

Definition at line 84 of file ellipse.

84 {a_new = new ellipse(*this);}

◆ node_desc_fields()

virtual const desc_fields& tools::sg::ellipse::node_desc_fields ( ) const
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 36 of file ellipse.

36  {
38  static const desc_fields s_v(parent::node_desc_fields(),5, //WARNING : take care of count.
44  );
45  return s_v;
46  }

◆ operator=()

ellipse& tools::sg::ellipse::operator= ( const ellipse a_from)
inline

Definition at line 149 of file ellipse.

149  {
150  parent::operator=(a_from);
151  curve::operator=(a_from);
152  rx = a_from.rx;
153  ry = a_from.ry;
154  phi_min = a_from.phi_min;
155  phi_max = a_from.phi_max;
156  steps = a_from.steps;
157  return *this;
158  }

◆ pick()

virtual void tools::sg::ellipse::pick ( pick_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 98 of file ellipse.

98  {
99  if(touched()) {
100  update_sg();
101  reset_touched();
102  }
103  if(a_action.stop_at_first()){
104  a_action.add_line_strip(m_xyzs);
105  if(a_action.done()) a_action.set_node(this);
106  } else {
107  a_action.set_done(false);
108  a_action.zs().clear();
109  a_action.ws().clear();
110  a_action.add_line_strip(m_xyzs);
111  if(a_action.done()) {
112  a_action.add_pick(*this,a_action.zs(),a_action.ws(),a_action.state());
113  a_action.set_done(false);
114  }
115  }
116  }

◆ pos_tan_nor()

virtual bool tools::sg::ellipse::pos_tan_nor ( float  ,
vec3f a_pos,
vec3f a_tan,
vec3f a_nor 
) const
inlinevirtual

Implements tools::curve.

Definition at line 56 of file ellipse.

59  {
60 
61  //float r = radius.value();
62  //float cs = fcos(a_s);
63  //float sn = fsin(a_s);
64 
65  float x,y,z;
66 
67  {//x = r*cs;y = r*sn;z = 0;
68  x = 0;y = 0;z = 0;
69  m_model.mul_3f(x,y,z);
70  a_pos.set_value(x,y,z);}
71 
72  {//x = -sn;y = cs;z = 0;
73  x = 0;y = 1;z = 0;
74  m_model.mul_dir_3(x,y,z);
75  a_tan.set_value(x,y,z);}
76 
77  {x = 0;y = 0;z = 1;
78  m_model.mul_dir_3(x,y,z);
79  a_nor.set_value(x,y,z);}
80 
81  return true;
82  }

◆ render()

virtual void tools::sg::ellipse::render ( render_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 86 of file ellipse.

86  {
87  if(touched()) {
88  update_sg();
89  reset_touched();
90  }
91  //Same logic as Inventor SoLightModel.model = BASE_COLOR.
92  const state& state = a_action.state();
93  a_action.set_lighting(false);
94  a_action.add_line_strip(m_xyzs);
95  a_action.set_lighting(state.m_GL_LIGHTING);
96  }

◆ update_sg()

void tools::sg::ellipse::update_sg ( )
inlineprotected

Definition at line 160 of file ellipse.

160  {
161  m_xyzs.clear();
162  if(!steps.value()) return;
163 
164  unsigned int num = steps.value();
165 
166  //set number of points approximatively proportional to the ellipse circumference
167  //float circ = kPI*(r1+r2)*(phi2-phi1)/360;
168  //Int_t n = (Int_t)(np*circ/((gPad->GetX2()-gPad->GetX1())+(gPad->GetY2()-gPad->GetY1())));
169  //if (n < 8) n= 8;
170  //if (n > np) n = np;
171 
172  m_xyzs.resize((num+1)*3);
173 
174  float phimin = phi_min.value();
175  float phimax = phi_max.value();
176  float r1 = rx.value();
177  float r2 = ry.value();
178 
179  float phi1 = mn<float>(phimin,phimax);
180  float phi2 = mx<float>(phimin,phimax);
181 
182  float angle,dx,dy;
183  float dphi = (phi2-phi1)/float(num);
184  size_t pos = 0;
185  for(unsigned int i=0;i<=num;i++) {
186  angle = phi1 + float(i)*dphi;
187  dx = r1*fcos(angle);
188  dy = r2*fsin(angle);
189  m_xyzs[pos] = dx;pos++;
190  m_xyzs[pos] = dy;pos++;
191  m_xyzs[pos] = 0;pos++;
192  }
193  /*
194  TString opt = option;
195  opt.ToLower();
196  if (phi2-phi1 >= 360 ) {
197  if (GetFillStyle()) gPad->PaintFillArea(n,x,y);
198  if (GetLineStyle()) gPad->PaintPolyLine(n+1,x,y);
199  } else {
200  x[n+1] = gPad->XtoPad(x1);
201  y[n+1] = gPad->YtoPad(y1);
202  x[n+2] = x[0];
203  y[n+2] = y[0];
204  if (GetFillStyle()) gPad->PaintFillArea(n+2,x,y);
205  if (GetLineStyle()) {
206  if (TestBit(kNoEdges) || opt.Contains("only")) gPad->PaintPolyLine(n+1,x,y);
207  else gPad->PaintPolyLine(n+3,x,y);
208  }
209  }
210  */
211 
212  }

Member Data Documentation

◆ m_xyzs

std::vector<float> tools::sg::ellipse::m_xyzs
protected

Definition at line 215 of file ellipse.

◆ phi_max

sf<float> tools::sg::ellipse::phi_max

Definition at line 33 of file ellipse.

◆ phi_min

sf<float> tools::sg::ellipse::phi_min

Definition at line 32 of file ellipse.

◆ rx

sf<float> tools::sg::ellipse::rx

Definition at line 30 of file ellipse.

◆ ry

sf<float> tools::sg::ellipse::ry

Definition at line 31 of file ellipse.

◆ steps

sf<unsigned int> tools::sg::ellipse::steps

Definition at line 34 of file ellipse.


The documentation for this class was generated from the following file:
tools::curve::curve
curve()
Definition: curve:34
tools::mat4f::mul_3f
void mul_3f(float &a_x, float &a_y, float &a_z) const
Definition: mat4f:58
tools::sg::ellipse
Definition: ellipse:21
tools::sg::ellipse::phi_min
sf< float > phi_min
Definition: ellipse:32
tools::sg::ellipse::ry
sf< float > ry
Definition: ellipse:31
tools::fcos
float fcos(const float &x)
Definition: mathf:42
tools::sg::ellipse::phi_max
sf< float > phi_max
Definition: ellipse:33
tools::sg::ellipse::ellipse
ellipse()
Definition: ellipse:125
tools::sg::node::cast
virtual void * cast(const std::string &a_class) const
Definition: node:38
tools::sg::ellipse::rx
sf< float > rx
Definition: ellipse:30
tools::mat4::mul_dir_3
void mul_dir_3(T &a_x, T &a_y, T &a_z) const
Definition: mat4:211
tools::curve::m_model
mat4f m_model
Definition: curve:58
tools::curve::operator=
curve & operator=(const curve &a_from)
Definition: curve:51
tools::ftwo_pi
float ftwo_pi()
Definition: mathf:12
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::ellipse::update_sg
void update_sg()
Definition: ellipse:160
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::fsin
float fsin(const float &x)
Definition: mathf:43
tools::sg::node::touched
virtual bool touched()
Definition: node:96
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
tools::sg::ellipse::steps
sf< unsigned int > steps
Definition: ellipse:34
tools::sg::ellipse::m_xyzs
std::vector< float > m_xyzs
Definition: ellipse:215
tools::sg::node::reset_touched
virtual void reset_touched()
Definition: node:102