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

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