g4tools  5.4.0
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
tools::clip< VEC3 > Class Template Reference

Public Member Functions

 clip ()
 
virtual ~clip ()
 
void reset ()
 
void add (const VEC3 &a_point)
 
void execute (const plane< VEC3 > &plane)
 
const std::vector< VEC3 > & result () const
 

Protected Types

typedef VEC3::elem_t T
 

Protected Member Functions

void out_point (const VEC3 &a_p)
 

Protected Attributes

std::vector< VEC3 > m_data [2]
 
unsigned int m_cur
 

Detailed Description

template<class VEC3>
class tools::clip< VEC3 >

Definition at line 120 of file geom3.

Member Typedef Documentation

◆ T

template<class VEC3 >
typedef VEC3::elem_t tools::clip< VEC3 >::T
protected

Definition at line 122 of file geom3.

Constructor & Destructor Documentation

◆ clip()

template<class VEC3 >
tools::clip< VEC3 >::clip ( )
inline

Definition at line 124 of file geom3.

124 :m_cur(0){}

◆ ~clip()

template<class VEC3 >
virtual tools::clip< VEC3 >::~clip ( )
inlinevirtual

Definition at line 125 of file geom3.

125 {}

Member Function Documentation

◆ add()

template<class VEC3 >
void tools::clip< VEC3 >::add ( const VEC3 &  a_point)
inline

Definition at line 136 of file geom3.

136 {m_data[m_cur].push_back(a_point);}

◆ execute()

template<class VEC3 >
void tools::clip< VEC3 >::execute ( const plane< VEC3 > &  plane)
inline

Definition at line 138 of file geom3.

138  {
139  //Clip polygon against plane. This might change the number of
140  //vertices in the polygon.
141 
142  size_t n = m_data[m_cur].size();
143  if(!n) return;
144 
145  // create a loop :
146  VEC3 dummy = m_data[m_cur][0];
147  m_data[m_cur].push_back(dummy);
148 
149  const VEC3& planeN = plane.normal();
150 
151  for(size_t i = 0; i < n; i++) {
152  VEC3 v0 = m_data[m_cur][i];
153  VEC3 v1 = m_data[m_cur][i+1];
154 
155  T d0 = plane.distance(v0);
156  T d1 = plane.distance(v1);
157 
158  if (d0 >= 0.0f && d1 < 0.0f) { // exit plane
159  VEC3 dir = v1-v0;
160  // we know that v0 != v1 since we got here
161  dir.normalize();
162  T dot = dir.dot(planeN);
163  VEC3 newvertex = v0 - dir * (d0/dot);
164  out_point(newvertex);
165  } else if (d0 < 0.0f && d1 >= 0.0f) { // enter plane
166  VEC3 dir = v1-v0;
167  // we know that v0 != v1 since we got here
168  dir.normalize();
169  T dot = dir.dot(planeN);
170  VEC3 newvertex = v0 - dir * (d0/dot);
171  out_point(newvertex);
172  out_point(v1);
173  } else if (d0 >= 0.0f && d1 >= 0.0f) { // in plane
174  out_point(v1);
175  }
176  }
177  m_data[m_cur].clear();
178  m_cur ^= 1;
179  }

◆ out_point()

template<class VEC3 >
void tools::clip< VEC3 >::out_point ( const VEC3 &  a_p)
inlineprotected

Definition at line 184 of file geom3.

184 {m_data[m_cur ^ 1].push_back(a_p);}

◆ reset()

template<class VEC3 >
void tools::clip< VEC3 >::reset ( )
inline

Definition at line 130 of file geom3.

130  {
131  m_data[0].clear();
132  m_data[1].clear();
133  m_cur = 0;
134  }

◆ result()

template<class VEC3 >
const std::vector<VEC3>& tools::clip< VEC3 >::result ( ) const
inline

Definition at line 181 of file geom3.

181 {return m_data[m_cur];}

Member Data Documentation

◆ m_cur

template<class VEC3 >
unsigned int tools::clip< VEC3 >::m_cur
protected

Definition at line 188 of file geom3.

◆ m_data

template<class VEC3 >
std::vector<VEC3> tools::clip< VEC3 >::m_data[2]
protected

Definition at line 187 of file geom3.


The documentation for this class was generated from the following file:
tools::clip::m_cur
unsigned int m_cur
Definition: geom3:188
tools::clip::T
VEC3::elem_t T
Definition: geom3:122
tools::clip::out_point
void out_point(const VEC3 &a_p)
Definition: geom3:184
tools::clip::m_data
std::vector< VEC3 > m_data[2]
Definition: geom3:187