g4tools  5.4.0
hatcher
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_hatcher
5 #define tools_hatcher
6 
49 #include "lina/vec3f"
50 #include "lina/vec2f"
51 #include "mathf"
52 #include <cfloat> // for FLT_MAX
53 
54 namespace tools {
55 
56 class hatcher {
57 public:
59  :fShift(.1f)
60  ,fDirAngle(fpi()/4)
61  ,fOffsetValue(.0f)
62  ,fOffset(vec3f(FLT_MAX,FLT_MAX,FLT_MAX))
63  ,fPrecisionFactor (.0001f) // good value to get rid of some errors
64  ,fStripWidth(0.0)
65  ,fFirstNumHatch(0)
67  ,fFirstPolyline(true)
69  {}
70  virtual ~hatcher() {}
71 protected:
72  hatcher(const hatcher& a_from)
73  :fNormal(a_from.fNormal)
74  ,fShift(a_from.fShift)
75  ,fDirAngle(a_from.fDirAngle)
76  ,fOffsetValue(a_from.fOffsetValue)
77  ,fOffset(a_from.fOffset)
78  ,fShiftVec(a_from.fShiftVec)
80  ,fDirVec(a_from.fDirVec)
81  ,fStripWidth(a_from.fStripWidth)
82  ,fPoints(a_from.fPoints)
83  ,fVertices(a_from.fVertices)
90  {}
91  hatcher& operator=(const hatcher& a_from){
92  fNormal = a_from.fNormal;
93  fShift = a_from.fShift;
94  fDirAngle = a_from.fDirAngle;
95  fOffsetValue = a_from.fOffsetValue;
96  fOffset = a_from.fOffset;
97  fShiftVec = a_from.fShiftVec;
99  fDirVec = a_from.fDirVec;
100  fStripWidth = a_from.fStripWidth;
101  fPoints = a_from.fPoints;
102  fVertices = a_from.fVertices;
109  return *this;
110  }
111 public:
122  bool compute_polyline (vec3f* listPoints,unsigned int number);
123 
124 
134  bool check_polyline(vec3f* listPoints,unsigned int number);
135 
136  void set_spacing(float a) {fShift = a;} //set the spacing for this hatch.
137  void set_angle(float a) {fDirAngle = a;} //set the Direction angle for the hatch in radians.
138  void set_offset(float a) {fOffsetValue = a;} //set the offset value for this hatch.
139  void set_offset_point(vec3f a) {fOffset = a;} //set the offset Point for this hatch.
140  void set_precision_factor(float a) {fPrecisionFactor = a;} //set the precision factor for computing (0.0001 is default).
141 
142  bool set_strip_width(float a) {
143  // set the strip width value(0 is default and means no strip).
144  if (a<0 || a>1) {
145  fStripWidth = 0;
146  return false;
147  }
148  fStripWidth = a;
149  return true;
150  }
151 
152  float get_spacing()const {return fShift;}
153  float get_angle()const {return fDirAngle;}
154  float get_offset()const {return fOffsetValue;}
155  const vec3f& get_offset_point() {return fOffset;}
156  float get_precision_factor()const {return fPrecisionFactor;}
157  float get_strip_width()const {return fStripWidth;}
158  const vec3f& get_normal() {return fNormal;}
159 
160  //size_t number_of_points() const {return fPoints.size();} //get the number of points compute for this hatch.
166  const std::vector<vec3f>& points() {return fPoints;}
167 
168  //size_t number_of_vertices() const {return fVertices.size();} //get the number of vertices compute for this hatch.
170  const std::vector<unsigned int>& vertices() {return fVertices;}
171 
172 protected:
173 
180  bool compute_single_polyline (vec3f* listPoints,unsigned int number);
181 
182 
193  vec2f resolve_system(const vec3f& A,const vec3f& B,const vec3f& C);
194 
195 
196 protected:
199 
201  float fShift; // Absloute distance between two hatch in the polyline plan */
202 
210  float fDirAngle;
211 
218 
223 
226 
229 
232 
237  float fStripWidth;
238 
240  std::vector<vec3f> fPoints;
241 
243  std::vector<unsigned int> fVertices;
244 
246  std::vector< std::vector<int> > fConflictNumHatchLineTab;
247 
249  std::vector<float> fHatchShiftToMatchPointVec;
250 
253 
255  unsigned int fNumberHatchToDraw;
256 
264  };
266 };
267 
268 }
269 
270 #include "hatcher.icc"
271 
272 #endif
tools::hatcher::fOffset
vec3f fOffset
first point of the hatch.
Definition: hatcher:222
tools::vec2f
Definition: vec2f:13
tools::hatcher::RESOLVE_UNDEFINED
@ RESOLVE_UNDEFINED
Definition: hatcher:263
tools::hatcher::compute_single_polyline
bool compute_single_polyline(vec3f *listPoints, unsigned int number)
draw the hatch into the polyline bounding box given in argument
tools::hatcher::fShift
float fShift
Spacing vector between two hatch.
Definition: hatcher:201
tools::hatcher::check_polyline
bool check_polyline(vec3f *listPoints, unsigned int number)
test if the polygone given is correct for hatching
tools::hatcher::fShiftVec
vec3f fShiftVec
Orientation vector for the hatch
Definition: hatcher:225
tools::hatcher::fNormal
vec3f fNormal
normal vector for the current polyline
Definition: hatcher:198
tools::hatcher::hatcher
hatcher()
Definition: hatcher:58
tools::hatcher::resolve_system
vec2f resolve_system(const vec3f &A, const vec3f &B, const vec3f &C)
Compute a vector system equation aA+bB=C return SbVec2f(0,0) if there is an error set the resolveResu...
tools::hatcher::get_strip_width
float get_strip_width() const
Definition: hatcher:157
tools::hatcher::get_normal
const vec3f & get_normal()
Definition: hatcher:158
tools::hatcher::fHatchShiftToMatchPointVec
std::vector< float > fHatchShiftToMatchPointVec
hatchShiftToMatchPointVec tab
Definition: hatcher:249
tools::hatcher::get_spacing
float get_spacing() const
Definition: hatcher:152
tools::hatcher::fPoints
std::vector< vec3f > fPoints
vector list of points
Definition: hatcher:240
tools::hatcher::fConflictNumHatchLineTab
std::vector< std::vector< int > > fConflictNumHatchLineTab
conflict line table
Definition: hatcher:246
tools::hatcher::RESOLVE_PRECISION_ERROR
@ RESOLVE_PRECISION_ERROR
Definition: hatcher:262
tools::hatcher::get_angle
float get_angle() const
Definition: hatcher:153
vec3f
tools::fpi
float fpi()
Definition: mathf:11
hatcher.icc
tools::hatcher::fResolveResult
ResolveErrors fResolveResult
Definition: hatcher:265
tools::hatcher::ResolveErrors
ResolveErrors
Definition: hatcher:258
tools::hatcher::compute_polyline
bool compute_polyline(vec3f *listPoints, unsigned int number)
draw the hatch into the polyline bounding box given in argument You have to get all compute points by...
tools::hatcher::vertices
const std::vector< unsigned int > & vertices()
vector of numbers of vertices
Definition: hatcher:170
tools::hatcher
Definition: hatcher:56
tools::hatcher::RESOLVE_OK
@ RESOLVE_OK
Definition: hatcher:259
tools::hatcher::set_spacing
void set_spacing(float a)
Definition: hatcher:136
tools::hatcher::fFirstPolyline
bool fFirstPolyline
Definition: hatcher:257
tools::hatcher::set_precision_factor
void set_precision_factor(float a)
Definition: hatcher:140
tools::hatcher::fStripWidth
float fStripWidth
strip with size : set to 0 by default between 0 and 1.0 means no strip, 0.5 means strip size is half ...
Definition: hatcher:237
tools::hatcher::~hatcher
virtual ~hatcher()
Definition: hatcher:70
tools::vec3f
Definition: vec3f:13
tools::hatcher::set_offset
void set_offset(float a)
Definition: hatcher:138
tools::hatcher::fOffsetValue
float fOffsetValue
between 0-1.
Definition: hatcher:217
tools::hatcher::set_angle
void set_angle(float a)
Definition: hatcher:137
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::hatcher::get_offset_point
const vec3f & get_offset_point()
Definition: hatcher:155
tools::hatcher::RESOLVE_COLINEAR
@ RESOLVE_COLINEAR
Definition: hatcher:260
tools::hatcher::points
const std::vector< vec3f > & points()
vector of compute points Be careful with this function because it can return a set of non convex pol...
Definition: hatcher:166
tools::hatcher::get_offset
float get_offset() const
Definition: hatcher:154
tools::hatcher::hatcher
hatcher(const hatcher &a_from)
Definition: hatcher:72
vec2f
mathf
tools::hatcher::get_precision_factor
float get_precision_factor() const
Definition: hatcher:156
tools::hatcher::RESOLVE_Z_ERROR
@ RESOLVE_Z_ERROR
Definition: hatcher:261
tools::hatcher::operator=
hatcher & operator=(const hatcher &a_from)
Definition: hatcher:91
tools::hatcher::fNumberHatchToDraw
unsigned int fNumberHatchToDraw
number of hatch to draw
Definition: hatcher:255
tools::hatcher::set_strip_width
bool set_strip_width(float a)
Definition: hatcher:142
tools::hatcher::fFirstNumHatch
int fFirstNumHatch
first hatch number to draw
Definition: hatcher:252
tools::hatcher::set_offset_point
void set_offset_point(vec3f a)
Definition: hatcher:139
tools::hatcher::fDirAngle
float fDirAngle
The angle (given in radians) is the one between the first line (point 1-point0) and the hatch lines,...
Definition: hatcher:210
tools::hatcher::fVertices
std::vector< unsigned int > fVertices
vector vertices number
Definition: hatcher:243
tools::hatcher::fPrecisionFactor
float fPrecisionFactor
factor for compute error between two points
Definition: hatcher:228
tools::hatcher::fDirVec
vec3f fDirVec
hatch direction Vector
Definition: hatcher:231