OpendTect-6_4  6.4
rcollinebuilder.h
Go to the documentation of this file.
1 #ifndef rcollinebuilder_h
2 #define rcollinebuilder_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kris (separated by Bert)
9  Date: Apr 2010
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 
14 */
15 
16 #include "math2.h"
17 
18 
19 template <class T>
20 bool makeLine(const T& start,const T& stop, TypeSet<T>& output,const T& step);
21 
22 
27 template <class T>
29 {
30 public:
31  RColLineBuilder(const T& start,const T& dir,
32  const T& step,TypeSet<T>& line);
33  int nextExtension();
37 protected:
38 
39  const T& start_;
40  const T& dir_;
41  const T& step_;
42  const float dirlen_;
44 
45  float distToLine(const T&) const;
46 
47 };
48 
49 
50 template <class T> inline
52  const T& dir, const T& step, TypeSet<T>& line )
53  : start_( start )
54  , dir_(dir)
55  , step_(step)
56  , line_(line)
57  , dirlen_(Math::Sqrt(float(dir_[0]*dir_[0]+dir_[1]*dir_[1])))
58 { }
59 
60 
61 template <class T> inline
63 {
64  if ( !dir_[0] && !dir_[1] )
65  return -1;
66 
67  T bestrc;
68  if ( line_.size() )
69  {
70  const T& lastpos = line_[line_.size()-1];
71 
72  float disttoline = mUdf(float);
73 
74  if ( dir_[0] )
75  {
76  const T candidate =
77  lastpos + T(dir_[0]>0?step_[0]:-step_[0], 0 );
78  const float dist = distToLine(candidate);
79  if ( dist<disttoline )
80  { bestrc = candidate; disttoline=dist; }
81  }
82 
83  if ( dir_[1] )
84  {
85  const T candidate =
86  lastpos + T(0,dir_[1]>0?step_[1]:-step_[1] );
87  const float dist = distToLine(candidate);
88  if ( dist<disttoline )
89  { bestrc = candidate; disttoline=dist; }
90  }
91 
92  if ( dir_[0] && dir_[1] )
93  {
94  const T candidate =
95  lastpos + T( dir_[0]>0?step_[0]:-step_[0],
96  dir_[1]>0?step_[1]:-step_[1] );
97  const float dist = distToLine(candidate);
98  if ( dist<disttoline )
99  { bestrc = candidate; disttoline=dist; }
100  }
101  }
102  else
103  bestrc = start_;
104 
105  line_ += bestrc;
106  return 1;
107 }
108 
109 
110 template <class T> inline
111 float RColLineBuilder<T>::distToLine( const T& rc ) const
112 {
113  return fabs((dir_[0]*(rc[1]-start_[1])-dir_[1]*(rc[0]-start_[0]))/dirlen_);
114 }
115 
116 
117 template <class T> inline
118 bool makeLine( const T& start, const T& stop, const T& step, TypeSet<T>& output)
119 {
120  if ( start[0]%step[0] != stop[0]%step[0]
121  || start[1]%step[1] != stop[1]%step[1] )
122  return false;
123 
124  output.erase();
125  if ( start == stop )
126  { output += T(start); return true; }
127 
128  T dir = stop;
129  dir -= start;
130 
131  RColLineBuilder<T> builder( start, dir, step, output );
132 
133  while ( builder.nextExtension()>0 && output[output.size()-1]!=stop )
134  ;
135 
136  return true;
137 }
138 
139 
140 #endif
RColLineBuilder(const T &start, const T &dir, const T &step, TypeSet< T > &line)
Definition: rcollinebuilder.h:51
const T & dir_
Definition: rcollinebuilder.h:40
RowCol step_
Definition: horizontracker.h:141
Set of (small) copyable elements.
Definition: commontypes.h:30
const T & start_
Definition: rcollinebuilder.h:39
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
const T & step_
Definition: rcollinebuilder.h:41
size_type size() const
int nextExtension()
Definition: rcollinebuilder.h:62
bool makeLine(const T &start, const T &stop, TypeSet< T > &output, const T &step)
const float dirlen_
Definition: rcollinebuilder.h:42
virtual void erase()
Definition: math2.h:29
float distToLine(const T &) const
Definition: rcollinebuilder.h:111
Creates a line in RowCol space.
Definition: rcollinebuilder.h:28
#define mClass(module)
Definition: commondefs.h:164
float Sqrt(float)
TypeSet< T > & line_
Definition: rcollinebuilder.h:43

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019