JG ROOT Tools libraries  version 5.0 - august 2014
RHoughTransform3D.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file RHoughTransform3D.hh
3  *
4  * Include file for the class RHoughTransform3D
5  */
6 //======================================================================
7 
8 #ifndef R_HOUGH_TRANSFORM_3D_HH
9 #define R_HOUGH_TRANSFORM_3D_HH
10 
11 //======================================================================
12 
13 // GRootTools includes
14 #include "RBaseFunctions.hh"
15 #include "RSphereTesselation.hh"
16 
17 // ROOT includes
18 #include "TH2.h"
19 #include "TH3.h"
20 #include "TPoint.h"
21 #include "TMath.h"
22 #include "TLine.h"
23 
24 ///! Identifier suffix for transform histogram
25 #define R_H3D_MAIN_XY "MainXY"
26 
27 ///! Identifier suffix for transform histogram
28 #define R_H3D_LOCAL_XY "ImprXY"
29 
30 ///! Identifier suffix for transform histogram
31 #define R_H3D_LOCAL_ANG "ImprAng"
32 
33 //======================================================================
34 /*! \class RHoughTransform3D
35  *
36  * This class is a 3D adaptation of the Hough transform analysis, in
37  * order to search for lines in a 3D histogram.
38  *
39  * The discretization of 3D directions is based on the tesselation of
40  * a sphere starting from an icosahedron (see class RSphereTesselation).
41  * The analysis is limited to the directions on the unit sphere defining
42  * unique directions, then only half of the tesselation points are
43  * considered.
44  *
45  * <B>Line detection main procedure</B>
46  *
47  * The line searching principle is the following:
48  * - each point of the sphere defines a (theta,phi) direction, with
49  * direction vector Uz;
50  * - for each direction, a perpendicular plane (Ux,Uy) is defined,
51  * and a corresponding 2D histogram is created (the histogram is
52  * created only once, and reused for each direction);
53  * - for each bin of the source 3D histogram, the (ux,uy,uz) coordinates
54  * are computed to score the (Ux,Uy) histogram;
55  * - the maximum value (score) for the (Ux,Uy) histogram defines the
56  * score for the direction (theta,phi);
57  * - the direction with the maximum score is considered for a line
58  * detection:
59  * - if the score is higher than the detection threshold, the detection
60  * is valid
61  *
62  * Main procedure parameters:
63  * - directions discretization level (sphere tesselation)
64  * - 3D source (signal) histogram center, as origin point for the projections
65  * - 2D score histogram: size and binning along Ux and Uy directions (the
66  * histogram dimensions must be large enough to cover the projections of
67  * the source histogram)
68  *
69  * <B>Line detection improvement</B>
70  *
71  * The main detection procedure precision is limited to the sphere
72  * tessalation.
73  * Once a line is detected, a local analysis allows to refine the line
74  * parameters around the result of the main procedure.
75  *
76  *
77  * <B>Multiple lines search: detected line suppression</B>
78  *
79  *
80  * \par Configuration functions
81  *
82  * Configuration at construction time:
83  *
84  \code
85 
86  TH3 * hsrc = ... // define the source histogram
87 
88  RHoughTransform3D h3d ( hsrc, u_short div = 2,
89  u_int nxy = 100, double xymax = 100.,
90  double thr = 0. );
91 
92  \endcode
93  *
94  * Configuration functions:
95  *
96  * \code
97 
98  TH3 * hsrc = ... // define the source histogram
99 
100  RHoughTransform3D h3d; // empty analysis
101 
102  double thr = 0.2; // threshold for source histogram
103  h3d.SetSourceHisto ( hsrc, thr );
104 
105  u_short div = 2; // number of division for sphere tesselation (3D directions discretization)
106  h3d.SetTesselation ( 2 );
107 
108  u_int nxy = 100; // number of bins for (Ux,Uy) score histogram
109  double xymax = 100.; // (Ux,Uy) score histogram axis limits: [-xymax;+xymax]
110  h3d.SetTransformMain ( nxy, xymax, "UxUy_Score" );
111 
112  \endcode
113  *
114  *
115  *
116  *
117  * \par Line search functions
118  *
119  * The main function to perform the line analysis search is
120  * RHoughTransform3D::AnalyseTransformMain().
121  *
122  * This function computes the score histogram (Ux,Uy) for each direction
123  * of the 3D directions discretization.
124  * The direction with maximum score is memorized as the result of the
125  * analysis.
126  *
127  * The score histogram for 1 direction is filled with the
128  * RHoughTransform3D::ComputeTransformXY() function.
129  *
130  */
132 {
133  //------------------------------------------------------------
134  /*! \object_doc{RHoughTransform3D} */
136  //------------------------------------------------------------
137 
138  /*! Weight limit for ignoring point*/
139  static double epsilon;
140 
141  /*! Option for threshold on histogram amplitude for contributing to the analysis*/
142  static const u_int optThreshold = 0x00000002;
143 
144  /*! Option for amplitude as weight of histogram point*/
145  static const u_int optAmplitude = 0x00000004;
146 
147  /*! Option for smoothing the Hough transform histogram*/
148  static const u_int optSmooth = 0x00000008;
149 
150  /*! Option for angles in degrees*/
151  static const u_int optdegree = 0x00000010;
152 
153  /*! Mode for line suppression: sharp cut*/
154  static const u_short modeCut = 0x0000;
155 
156  /*! Mode for line suppression: gauss shape reduction*/
157  static const u_short modeGaus = 0x0001;
158 
159 
160  /*! Conversion factor from radians to degrees*/
161  static const double rad2deg;
162 
163  /*! Conversion factor from degrees to radians*/
164  static const double deg2rad;
165 
166 
167  protected:
168  RSphereTesselation sphere; ///< Discretized representation of directions on a sphere
169  int * sph_pts; ///< Array of selected points for unique representation of 3D directions
170  int * sph_seg; ///< Array of segments connecting the selected points
171  TVector3 * sph_ux; ///< Unit X vector for discretization directions
172  TVector3 * sph_uy; ///< Unit X vector for discretization directions
173  double * sph_score; ///< Score for discretization directions
174  u_int npts; ///< Number of selected points
175  u_int nseg; ///< Number of selected segments
176 
177  TH3 * src_histo; ///< Pointer to the histogram to analyse
178  TVector3 src_center; ///< Image histogram center
179  double threshold; ///< Threshold value
180 
181  u_int src_data_dim; ///< Reduced source data dimension
182  u_int src_data_num; ///< Number of source data points
183  TVector3 * src_data_pos; ///< Array of source data point positions
184  double * src_data_weight; ///< Array of source data point weight
185 
186  // maximum search data
187  TH2 * h_anal_xy; ///< Pointer to the Ux-Uy weight histogram for the analysed direction
188  string hxy_id; ///< Identifier for created histogram name
189 
190  double hxy_max; ///< Maximum value for current Ux-Uy weight histogram
191  double hxy_max_x; ///< X value for analysis maximum
192  double hxy_max_y; ///< Y value for analysis maximum
193  double hxy_max_theta; ///< Theta value for analysis maximum
194  double hxy_max_phi; ///< Phi value for analysis maximum
195  bool analysis_done; ///< Whether the analysis has been performed
196 
197  double hxy_last_score; ///< Maximum score for current direction
198  double hxy_last_x; ///< X value for current direction maximum
199  double hxy_last_y; ///< Y value for current direction maximum
200  double hxy_last_theta; ///< Theta value for current direction maximum
201  double hxy_last_phi; ///< Phi value for current direction maximum
202 
203  // main / improved (local) analysis
204  TH2 * h_main_xy; ///< Pointer to the Ux-Uy score histogram for the main analysis (all directions)
205  TH2 * h_local_xy; ///< Pointer to the Ux-Uy score histogram for the improved local analysis
206  TH2 * h_local_ang; ///< Pointer to the Theta-Phi score histogram for the improved local analysis
207  TVector3 * pt_local; ///< Array of vectors from local analysis
208  bool local_analysis; ///< Whether the ongoing analysis is local
209 
210  TAttLine line_att; ///< Lines draw attributes (ROOT)
211 
212  u_int options; ///< Transform options
213 
214  public:
215 
216  //------------------------------------------------------------
217  /** @name Constructors, affectation, destructor */
218  //@{
219  RHoughTransform3D ( TH3 * hptr = NULL,
220  u_short div = 2, u_int nxy = 0, double xymax = 0.,
221  double thr = 0., const string & id = "" );
222  virtual ~RHoughTransform3D ( );
223  //@}
224 
225  //------------------------------------------------------------
226  /** @name Transform analysis options */
227  //@{
228  u_int GetOptions ( ) const; // inline
229  bool GetOptionThreshold ( ) const; // inline
230  bool GetOptionAmplWeight ( ) const; // inline
231  bool GetOptionThresholdAmplWeight ( ) const; // inline
232  bool GetOptionSmooth ( ) const; // inline
233 
234  virtual void SetOptionAmplWeight ( bool thr = false );
235  virtual void SetOptionUnitWeight ( );
236 
237  virtual void SetOptionSmooth ( ); // inline
238  virtual void SetOptionNoSmooth ( ); // inline
239 
240  virtual void SetOptionDegree ( ); // inline
241  virtual void SetOptionRadian ( ); // inline
242  virtual bool IsOptionDegree ( ) const; // inline
243  virtual bool IsOptionRadian ( ) const; // inline
244  //@}
245 
246  //------------------------------------------------------------
247  /** @name Transform analysis parameters */
248  //@{
249  TH3 * GetSourceHisto ( ) const; // inline
250  TH3 * GetWeightHisto ( const string & hname = "" ) const;
251  virtual double GetWeight ( double pval ) const;
252 
253  const TVector3 & GetSourceCenter ( ) const; // inline
254  TVector3 & GetSourceCenter ( ); // inline
255  virtual void SetSourceCenter ( const TVector3 & ctr );
256 
257  virtual int SetSourceHisto ( TH3 * hptr, double thr = 0. );
258  virtual void SetThreshold ( double thr ); // inline
259 
260  virtual void ResetSourceData ( );
261  virtual void InitSourceData ( );
262  virtual void UpdateSourceData ( );
263 
264  virtual void ResetTesselation ( );
265  virtual const RSphereTesselation & SetTesselation ( u_short div );
266 
267  int GetNpoints ( ) const; // inline
268  int GetNsegments ( ) const; // inline
269  const RSphereTesselation & GetSphereTesselation ( ) const; // inline
270 
271  const RTesselationPoint & GetPoint ( int ip ) const; // inline
272  const RTesselationSegment & GetSegment ( int is ) const; // inline
273 
274  virtual void SetTransformId ( const string & id ); // inline
275  virtual void ResetTransform ( );
276  virtual void ResetTransformMain ( );
277  virtual void ResetTransformLocal ( );
278 
279  virtual TH2 * SetTransformMain ( u_int nxy, double xymax );
280  virtual TH2 * SetTransformLocal ( u_int nxy, double dxy, u_int na, double da );
281 
282  //@}
283 
284  //------------------------------------------------------------
285  /** @name Transform analysis functions */
286  //@{
287 
288  virtual int SetAnalysisMain ( );
289  virtual int SetAnalysisLocal ( );
290  virtual int ComputeTransformXY ( u_int ip );
291  virtual int ComputeTransformXY ( double theta, double phi, bool deg = false );
292  virtual int ComputeTransformXY ( TVector3 ux, TVector3 uy );
293 
294  TH2 * GetLocalHistoAngle ( ); // inline
295  TH2 * GetLocalHistoUxUy ( ); // inline
296 
297  // maximum search analysis
298  virtual void ResetAnalysis ( );
299  virtual int AnalyseTransformMain ( );
300  virtual int AnalyseTransformLocal ( );
301 
302  double GetMaxScore ( ) const;
303  double GetMaxScore ( double & theta, double & phi, double & ux, double & uy ) const;
304 
305 
306  // previously found lines suppression
307 
308  virtual void SuppressSourceLine ( double theta, double phi,
309  double ux, double uy, double width,
310  u_short mode = modeCut, u_short sdiv = 1 );
311 
312  virtual void SuppressSourceLine ( TVector3 Pt, TVector3 dir,
313  double width,
314  u_short mode = modeCut, u_short sdiv = 1 );
315 
316  virtual u_int SearchLineSuppress ( double hthr, u_int nlmax = 1,
317  double * thtab = NULL, double * rtab = NULL, double * htab = NULL,
318  u_short sdiv = 1 );
319  //@}
320 
321  //------------------------------------------------------------
322  /** @name ROOT related functions */
323  //@{
324  virtual void SetLineColor ( Color_t c ); // inline
325  virtual void SetLineWidth ( Width_t w ); // inline
326  virtual void SetLineStyle ( Style_t s ); // inline
327  virtual void SetLineAtt ( TAttLine & att ); // inline
328 
329  const TAttLine & GetLineAtt ( ) const; // inline
330  TAttLine & GetLineAtt ( ); // inline
331 
332  TPolyMarker3D * CreatePoints3D ( ) const;
333  TPolyLine3D * CreateSegment3D ( int is ) const;
334  TList * CreateLines3D ( const TAttLine latt = TAttLine(kRed+1,2,1 ) ) const;
335 
336  TList * CreateScorePoints3D ( Color_t col = kAzure+1, Style_t sty = 20, double siz = 1.0 ) const;
337  TList * CreateLocalPoints3D ( Color_t col = kRed+1, Style_t sty = 20, double siz = 1.0 ) const;
338 
339  TPolyLine3D * CreateLine3D ( ) const;
340  TPolyLine3D * CreateLine3D ( double theta, double phi, double ux, double uy ) const;
341 
342  /*! For ROOT dictionary.*/
344  //@}
345 };
346 
347 //----------------------------------------------------------------------
348 // Inline functions
349 #include "icc/RHoughTransform3D.icc"
350 
351 
352 //======================================================================
353 
354 #endif
double hxy_max_x
X value for analysis maximum.
Definition: RHoughTransform3D.hh:191
TList * CreateLocalPoints3D(Color_t col=kRed+1, Style_t sty=20, double siz=1.0) const
Definition: RHoughTransform3D.cpp:1469
TVector3 * pt_local
Array of vectors from local analysis.
Definition: RHoughTransform3D.hh:207
TPolyMarker3D * CreatePoints3D() const
Definition: RHoughTransform3D.cpp:1344
virtual void ResetSourceData()
Definition: RHoughTransform3D.cpp:235
virtual void SetTransformId(const string &id)
Definition: RHoughTransform3D.icc:120
virtual void ResetAnalysis()
Definition: RHoughTransform3D.cpp:852
double * sph_score
Score for discretization directions.
Definition: RHoughTransform3D.hh:173
TVector3 src_center
Image histogram center.
Definition: RHoughTransform3D.hh:178
TVector3 * sph_ux
Unit X vector for discretization directions.
Definition: RHoughTransform3D.hh:171
virtual void SetLineColor(Color_t c)
Definition: RHoughTransform3D.icc:139
GObject(RHoughTransform3D)
TH3 * src_histo
Pointer to the histogram to analyse.
Definition: RHoughTransform3D.hh:177
const RTesselationPoint & GetPoint(int ip) const
Definition: RHoughTransform3D.icc:100
virtual void SetOptionAmplWeight(bool thr=false)
Definition: RHoughTransform3D.cpp:105
RHoughTransform3D(TH3 *hptr=NULL, u_short div=2, u_int nxy=0, double xymax=0., double thr=0., const string &id="")
Definition: RHoughTransform3D.cpp:33
virtual TH2 * SetTransformMain(u_int nxy, double xymax)
Definition: RHoughTransform3D.cpp:522
TH2 * GetLocalHistoAngle()
Definition: RHoughTransform3D.icc:126
static double epsilon
Definition: RHoughTransform3D.hh:139
Definition: RHoughTransform3D.hh:131
int GetNpoints() const
Definition: RHoughTransform3D.icc:82
const TVector3 & GetSourceCenter() const
Definition: RHoughTransform3D.icc:63
static const u_short modeGaus
Definition: RHoughTransform3D.hh:157
virtual void SetLineWidth(Width_t w)
Definition: RHoughTransform3D.icc:145
double hxy_max
Maximum value for current Ux-Uy weight histogram.
Definition: RHoughTransform3D.hh:190
virtual int SetSourceHisto(TH3 *hptr, double thr=0.)
Definition: RHoughTransform3D.cpp:191
bool GetOptionSmooth() const
Definition: RHoughTransform3D.icc:28
virtual void SetOptionRadian()
Definition: RHoughTransform3D.icc:45
TH2 * GetLocalHistoUxUy()
Definition: RHoughTransform3D.icc:130
static const u_int optSmooth
Definition: RHoughTransform3D.hh:148
virtual int AnalyseTransformMain()
Definition: RHoughTransform3D.cpp:871
TList * CreateLines3D(const TAttLine latt=TAttLine(kRed+1, 2, 1)) const
Definition: RHoughTransform3D.cpp:1384
const RSphereTesselation & GetSphereTesselation() const
Definition: RHoughTransform3D.icc:94
double hxy_max_theta
Theta value for analysis maximum.
Definition: RHoughTransform3D.hh:193
virtual int SetAnalysisLocal()
Definition: RHoughTransform3D.cpp:678
double hxy_last_x
X value for current direction maximum.
Definition: RHoughTransform3D.hh:198
double hxy_last_theta
Theta value for current direction maximum.
Definition: RHoughTransform3D.hh:200
TVector3 * src_data_pos
Array of source data point positions.
Definition: RHoughTransform3D.hh:183
bool local_analysis
Whether the ongoing analysis is local.
Definition: RHoughTransform3D.hh:208
TH2 * h_main_xy
Pointer to the Ux-Uy score histogram for the main analysis (all directions)
Definition: RHoughTransform3D.hh:204
TH2 * h_anal_xy
Pointer to the Ux-Uy weight histogram for the analysed direction.
Definition: RHoughTransform3D.hh:187
TPolyLine3D * CreateSegment3D(int is) const
Definition: RHoughTransform3D.cpp:1364
u_int npts
Number of selected points.
Definition: RHoughTransform3D.hh:174
ClassDef(RHoughTransform3D, 0)
virtual double GetWeight(double pval) const
Definition: RHoughTransform3D.cpp:165
TVector3 * sph_uy
Unit X vector for discretization directions.
Definition: RHoughTransform3D.hh:172
virtual void UpdateSourceData()
Definition: RHoughTransform3D.cpp:272
virtual void ResetTransform()
Definition: RHoughTransform3D.cpp:483
virtual const RSphereTesselation & SetTesselation(u_short div)
Definition: RHoughTransform3D.cpp:362
virtual void SetOptionUnitWeight()
Definition: RHoughTransform3D.cpp:118
double hxy_last_y
Y value for current direction maximum.
Definition: RHoughTransform3D.hh:199
double hxy_last_phi
Phi value for current direction maximum.
Definition: RHoughTransform3D.hh:201
u_int src_data_num
Number of source data points.
Definition: RHoughTransform3D.hh:182
static const u_int optdegree
Definition: RHoughTransform3D.hh:151
u_int GetOptions() const
Definition: RHoughTransform3D.icc:11
static const u_short modeCut
Definition: RHoughTransform3D.hh:154
int * sph_seg
Array of segments connecting the selected points.
Definition: RHoughTransform3D.hh:170
virtual TH2 * SetTransformLocal(u_int nxy, double dxy, u_int na, double da)
Definition: RHoughTransform3D.cpp:586
RSphereTesselation sphere
Discretized representation of directions on a sphere.
Definition: RHoughTransform3D.hh:168
virtual void ResetTransformLocal()
Definition: RHoughTransform3D.cpp:497
TList * CreateScorePoints3D(Color_t col=kAzure+1, Style_t sty=20, double siz=1.0) const
Definition: RHoughTransform3D.cpp:1417
virtual void SuppressSourceLine(double theta, double phi, double ux, double uy, double width, u_short mode=modeCut, u_short sdiv=1)
Definition: RHoughTransform3D.cpp:1100
int GetNsegments() const
Definition: RHoughTransform3D.icc:88
virtual int ComputeTransformXY(u_int ip)
Definition: RHoughTransform3D.cpp:705
static const u_int optAmplitude
Definition: RHoughTransform3D.hh:145
virtual void SetLineAtt(TAttLine &att)
Definition: RHoughTransform3D.icc:157
bool GetOptionThresholdAmplWeight() const
Definition: RHoughTransform3D.icc:24
TH3 * GetWeightHisto(const string &hname="") const
Definition: RHoughTransform3D.cpp:127
virtual void SetLineStyle(Style_t s)
Definition: RHoughTransform3D.icc:151
bool GetOptionThreshold() const
Definition: RHoughTransform3D.icc:15
double GetMaxScore() const
Definition: RHoughTransform3D.cpp:1051
double threshold
Threshold value.
Definition: RHoughTransform3D.hh:179
virtual void ResetTransformMain()
Definition: RHoughTransform3D.cpp:490
virtual void SetOptionSmooth()
Definition: RHoughTransform3D.icc:33
bool GetOptionAmplWeight() const
Definition: RHoughTransform3D.icc:19
virtual void ResetTesselation()
Definition: RHoughTransform3D.cpp:337
int * sph_pts
Array of selected points for unique representation of 3D directions.
Definition: RHoughTransform3D.hh:169
TAttLine line_att
Lines draw attributes (ROOT)
Definition: RHoughTransform3D.hh:210
Definition: RSphereTesselation.hh:31
u_int src_data_dim
Reduced source data dimension.
Definition: RHoughTransform3D.hh:181
double hxy_max_phi
Phi value for analysis maximum.
Definition: RHoughTransform3D.hh:194
virtual bool IsOptionDegree() const
Definition: RHoughTransform3D.icc:49
virtual void SetOptionDegree()
Definition: RHoughTransform3D.icc:41
double * src_data_weight
Array of source data point weight.
Definition: RHoughTransform3D.hh:184
TH2 * h_local_xy
Pointer to the Ux-Uy score histogram for the improved local analysis.
Definition: RHoughTransform3D.hh:205
double hxy_max_y
Y value for analysis maximum.
Definition: RHoughTransform3D.hh:192
virtual void SetThreshold(double thr)
Definition: RHoughTransform3D.icc:75
Definition: RSolidTesselation.hh:109
Definition: RSolidTesselation.hh:36
string hxy_id
Identifier for created histogram name.
Definition: RHoughTransform3D.hh:188
virtual int SetAnalysisMain()
Definition: RHoughTransform3D.cpp:658
static const double rad2deg
Definition: RHoughTransform3D.hh:161
virtual ~RHoughTransform3D()
Definition: RHoughTransform3D.cpp:89
TH3 * GetSourceHisto() const
Definition: RHoughTransform3D.icc:59
static const double deg2rad
Definition: RHoughTransform3D.hh:164
virtual void InitSourceData()
Definition: RHoughTransform3D.cpp:246
const TAttLine & GetLineAtt() const
Definition: RHoughTransform3D.icc:161
virtual void SetOptionNoSmooth()
Definition: RHoughTransform3D.icc:37
u_int options
Transform options.
Definition: RHoughTransform3D.hh:212
virtual u_int SearchLineSuppress(double hthr, u_int nlmax=1, double *thtab=NULL, double *rtab=NULL, double *htab=NULL, u_short sdiv=1)
Definition: RHoughTransform3D.cpp:1288
u_int nseg
Number of selected segments.
Definition: RHoughTransform3D.hh:175
virtual int AnalyseTransformLocal()
Definition: RHoughTransform3D.cpp:918
const RTesselationSegment & GetSegment(int is) const
Definition: RHoughTransform3D.icc:106
virtual void SetSourceCenter(const TVector3 &ctr)
Definition: RHoughTransform3D.cpp:223
TH2 * h_local_ang
Pointer to the Theta-Phi score histogram for the improved local analysis.
Definition: RHoughTransform3D.hh:206
virtual bool IsOptionRadian() const
Definition: RHoughTransform3D.icc:53
bool analysis_done
Whether the analysis has been performed.
Definition: RHoughTransform3D.hh:195
double hxy_last_score
Maximum score for current direction.
Definition: RHoughTransform3D.hh:197
TPolyLine3D * CreateLine3D() const
Definition: RHoughTransform3D.cpp:1514
static const u_int optThreshold
Definition: RHoughTransform3D.hh:142