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

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