OpenWalnut  1.5.0dev
WFiber.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <algorithm>
26 #include <cmath>
27 #include <utility>
28 #include <vector>
29 
30 #include "../WLimits.h"
31 #include "WFiber.h"
32 
33 namespace
34 {
35  std::pair< double, double > dXt_optimized( double thresholdSquare, const WFiber &q, const WFiber &r )
36  {
37  const size_t qsize = q.size();
38  const size_t rsize = r.size();
39  double qr = 0.0;
40  double rq = 0.0;
41 
42  // will contain every point-to-point square-distances
43  std::vector< std::vector< double > > m( qsize, std::vector< double >( rsize, 0.0 ) );
44 
45  // double **m = new double*[qsize];
46 
47  for( size_t i = 0; i < qsize; ++i )
48  {
49  // m[i] = new double[rsize];
50  for( size_t j = 0; j < rsize; ++j )
51  {
52  m[i][j] = length2( q[i] - r[j] );
53  }
54  }
55  // compute dt(q,r)
56  double minSoFar;
57  for( size_t i = 0; i < qsize; ++i )
58  {
59  minSoFar = *( std::min_element( m[i].begin(), m[i].end() ) );
60  // minSoFar = *( std::min_element( &m[i][0], &m[i][rsize] ) );
61  if( minSoFar > thresholdSquare )
62  {
63  qr += std::sqrt( minSoFar );
64  }
65  }
66  qr = qr / qsize;
67  // compute dt(r,q)
68  for( size_t j = 0; j < rsize; ++j )
69  {
70  minSoFar = wlimits::MAX_DOUBLE;
71  for( size_t i = 0; i < qsize; ++i )
72  {
73  if( m[i][j] < minSoFar )
74  {
75  minSoFar = m[i][j];
76  }
77  }
78  if( minSoFar > thresholdSquare )
79  {
80  rq += std::sqrt( minSoFar );
81  }
82  }
83  rq = rq / rsize;
84  return std::make_pair( qr, rq );
85  }
86 }
87 
88 WFiber::WFiber( const std::vector< WPosition > &points )
89  : WLine( points )
90 {
91 }
92 
94  : WLine()
95 {
96 }
97 
98 double WFiber::distDST( double thresholdSquare, const WFiber &q, const WFiber &r )
99 {
100  std::pair< double, double > result = ::dXt_optimized( thresholdSquare, q, r );
101  return std::min( result.first, result.second );
102 }
103 
104 double WFiber::distDLT( double thresholdSquare, const WFiber &q, const WFiber &r )
105 {
106  std::pair< double, double > result = ::dXt_optimized( thresholdSquare, q, r );
107  return std::max( result.first, result.second );
108 }
Represents a neural pathway.
Definition: WFiber.h:40
WFiber()
Creates an empty fiber.
Definition: WFiber.cpp:93
static double distDLT(double thresholdSquare, const WFiber &q, const WFiber &r)
This is the Larger thresholded distance as described by Zhang: http://dx.doi.org/10....
Definition: WFiber.cpp:104
static double distDST(double thresholdSquare, const WFiber &q, const WFiber &r)
This is the Smaller thresholded distance as described by Zhang: http://dx.doi.org/10....
Definition: WFiber.cpp:98
A line is an ordered sequence of WPositions.
Definition: WLine.h:42
size_type size() const
Wrapper around std::vector member function.
Definition: WMixinVector.h:267
const double MAX_DOUBLE
Maximum double value.
Definition: WLimits.cpp:31