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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/hatcher (Version 11.3.0) and /externals/g4tools/include/tools/hatcher (Version 9.0.p2)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_hatcher                             
  5 #define tools_hatcher                             
  6                                                   
  7 /**                                               
  8  *                                                
  9  * hatcher is a class to draw Hatch in a 3D po    
 10  * A hatch is caracterise by a direction (dirA    
 11  * second hatch,                                  
 12  * an offset, and a stripWidth :                  
 13  * - offset value : between 0-1, This value se    
 14  *   the hatch.0 meen that the hatch  will tou    
 15  *   of the polyline, and 1 meen that first ha    
 16  *   at a 'spacing' distance to first point       
 17  * - offsetVec : the 3D point from where a hat    
 18  *   very usefull to have hach continuing in d    
 19  *                                                
 20  * The compute_polyline() method<br>              
 21  * By default:                                    
 22  * - spacing = .1;                                
 23  * - dirAngle = PI/4;                             
 24  * - offsetValue = 0;                             
 25  * - stripWidth=0.0;                              
 26  *                                                
 27  * A way to get all points and vertices and to    
 28  * <pre>                                          
 29  *  iindex =0;                                    
 30  *  icoord =0;                                    
 31  *  for (unsigned int a=0;a<sbHatch.number_of_    
 32  *    for (unsigned int b=0;b<sbHatch.number_o    
 33  *      coordinate3->point.set1Value(icoord,sb    
 34  *      indexedFaceSet->coordIndex.set1Value(i    
 35  *      iindex++;                                 
 36  *      icoord ++;                                
 37  *    }                                           
 38  *    indexedFaceSet->coordIndex.set1Value(iin    
 39  *    iindex++;                                   
 40  *  }                                             
 41  * </pre>                                         
 42  *                                                
 43  * @author Laurent Garnier                        
 44  * Creation : on Fri Jan 05 2004                  
 45  * Last update : 9 April 2004                     
 46  *                                                
 47  */                                               
 48                                                   
 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:                                           
 58   hatcher()                                       
 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     
 64   ,fStripWidth(0.0)                               
 65   ,fFirstNumHatch(0)                              
 66   ,fNumberHatchToDraw(0)                          
 67   ,fFirstPolyline(true)                           
 68   ,fResolveResult(RESOLVE_UNDEFINED)              
 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)                    
 79   ,fPrecisionFactor(a_from.fPrecisionFactor)      
 80   ,fDirVec(a_from.fDirVec)                        
 81   ,fStripWidth(a_from.fStripWidth)                
 82   ,fPoints(a_from.fPoints)                        
 83   ,fVertices(a_from.fVertices)                    
 84   ,fConflictNumHatchLineTab(a_from.fConflictNu    
 85   ,fHatchShiftToMatchPointVec(a_from.fHatchShi    
 86   ,fFirstNumHatch(a_from.fFirstNumHatch)          
 87   ,fNumberHatchToDraw(a_from.fNumberHatchToDra    
 88   ,fFirstPolyline(a_from.fFirstPolyline)          
 89   ,fResolveResult(a_from.fResolveResult)          
 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;                 
 98     fPrecisionFactor = a_from.fPrecisionFactor    
 99     fDirVec = a_from.fDirVec;                     
100     fStripWidth = a_from.fStripWidth;             
101     fPoints = a_from.fPoints;                     
102     fVertices = a_from.fVertices;                 
103     fConflictNumHatchLineTab = a_from.fConflic    
104     fHatchShiftToMatchPointVec = a_from.fHatch    
105     fFirstNumHatch = a_from.fFirstNumHatch;       
106     fNumberHatchToDraw = a_from.fNumberHatchTo    
107     fFirstPolyline = a_from.fFirstPolyline;       
108     fResolveResult = a_from.fResolveResult;       
109     return *this;                                 
110   }                                               
111 public:                                           
112   /**                                             
113   * draw the hatch into the polyline bounding     
114   * You have to get all compute points by the     
115   * Number of points can be get by number_of_p    
116   * The  number of vertices in the return poly    
117   * and vertice table by get_vertices             
118   * @return FALSE if :                            
119   *    - All points are not in the same plan      
120   *    - There is a precision error on one or     
121   */                                              
122   bool compute_polyline (vec3f* listPoints,uns    
123                                                   
124                                                   
125   /**                                             
126   * test if the polygone given is correct for     
127   * @return FALSE if :                            
128   *    - All points are not in the same plan      
129   *    - Number of points <3                      
130   *    - Offset point is not in the same plan     
131   *    - There is less than three different po    
132   *    - The vector from point[0],point[1] is     
133   */                                              
134   bool check_polyline(vec3f* listPoints,unsign    
135                                                   
136   void set_spacing(float a) {fShift = a;}         
137   void set_angle(float a) {fDirAngle = a;}        
138   void set_offset(float a) {fOffsetValue = a;}    
139   void set_offset_point(vec3f a) {fOffset = a;    
140   void set_precision_factor(float a) {fPrecisi    
141                                                   
142   bool set_strip_width(float a) {                 
143     // set the strip width value(0 is default     
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 fOff    
156   float get_precision_factor()const {return fP    
157   float get_strip_width()const {return fStripW    
158   const vec3f& get_normal() {return fNormal;}     
159                                                   
160   //size_t number_of_points() const {return fP    
161   /** vector of compute points<br>                
162    * Be careful with this function because it     
163    * polygone if you have a non convex polygon    
164    * to draw it, you have to use a tesselisati    
165    */                                             
166   const std::vector<vec3f>& points() {return f    
167                                                   
168   //size_t number_of_vertices() const {return     
169   /** vector of numbers of vertices */            
170   const std::vector<unsigned int>& vertices()     
171                                                   
172 protected:                                        
173                                                   
174   /**                                             
175   * draw the hatch into the polyline bounding     
176   * @return FALSE if :                            
177   *    - All points are not in the same plan      
178   *    - There is a precision error on one or     
179   */                                              
180   bool compute_single_polyline (vec3f* listPoi    
181                                                   
182                                                   
183   /**                                             
184   * Compute a vector system equation aA+bB=C      
185   * return SbVec2f(0,0) if there is an error      
186   * set the resolveResult variable to the erro    
187   * COLINEAR if A and B are                       
188   * PRECISION_ERROR if there is a lack of prec    
189   * Z_ERROR if there s no solution for Z          
190   * UNDEFINED never throw                         
191   * return a SbVec2f  for result. a is 'x' val    
192   */                                              
193   vec2f resolve_system(const vec3f& A,const ve    
194                                                   
195                                                   
196 protected:                                        
197   /** normal vector for the current polyline *    
198   vec3f fNormal;                                  
199                                                   
200   /** Spacing vector between two hatch */         
201   float fShift; // Absloute distance between t    
202                                                   
203   /** The angle (given in radians) is the one     
204    * line (point 1-point0) and the hatch lines    
205    * Given in the direct axis ((point1-point0)    
206    * normalPlanVec). The angle in compute only    
207    * Changes on angle value for others polylin    
208    * perform correct hatching between the poly    
209    */                                             
210   float fDirAngle;                                
211                                                   
212   /** between 0-1. This value set the offset o    
213   * that the hatch will touch the first point     
214   * and 1 meen that first hatch will be draw      
215   * at a 'spacing' distance to first point        
216   */                                              
217   float fOffsetValue;                             
218                                                   
219   /** first point of the hatch.                   
220    * offset = firstPolylinePoint+ShiftVec*offs    
221    */                                             
222   vec3f fOffset;                                  
223                                                   
224   /** Orientation vector for the hatch  */        
225   vec3f fShiftVec;                                
226                                                   
227   /** factor for compute error between two poi    
228   float fPrecisionFactor;                         
229                                                   
230   /** hatch direction Vector */                   
231   vec3f  fDirVec;                                 
232                                                   
233   /** strip with size : set to 0 by default       
234    * between 0 and 1.0 means no strip, 0.5 mea    
235    * half of distance between two hatches         
236    */                                             
237   float fStripWidth;                              
238                                                   
239   /** vector list of points */                    
240   std::vector<vec3f> fPoints;                     
241                                                   
242   /** vector vertices number */                   
243   std::vector<unsigned int> fVertices;            
244                                                   
245   /** conflict line table */                      
246   std::vector< std::vector<int> > fConflictNum    
247                                                   
248   /** hatchShiftToMatchPointVec tab*/             
249   std::vector<float> fHatchShiftToMatchPointVe    
250                                                   
251   /** first hatch number to draw */               
252   int fFirstNumHatch;                             
253                                                   
254   /**number of hatch to draw */                   
255   unsigned int fNumberHatchToDraw;                
256                                                   
257   bool fFirstPolyline;                            
258   enum ResolveErrors{                             
259     RESOLVE_OK = 0,                               
260     RESOLVE_COLINEAR,                             
261     RESOLVE_Z_ERROR,                              
262     RESOLVE_PRECISION_ERROR,                      
263     RESOLVE_UNDEFINED                             
264   };                                              
265   ResolveErrors fResolveResult;                   
266 };                                                
267                                                   
268 }                                                 
269                                                   
270 #include "hatcher.icc"                            
271                                                   
272 #endif