~ubuntu-branches/debian/stretch/cgal/stretch

« back to all changes in this revision

Viewing changes to include/CGAL/Linear_cell_complex_operations.h

  • Committer: Package Import Robot
  • Author(s): Joachim Reichel
  • Date: 2014-04-05 10:56:43 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140405105643-jgnrpu2thtx23zfs
Tags: 4.4-1
* New upstream release.
* Remove patches do-not-link-example-with-qt4-support-library.patch and
  fix_jet_fitting_3.patch (applied upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
   */
39
39
  template <class LCC>
40
40
  typename LCC::Vector compute_normal_of_cell_2
41
 
  (const LCC& /*amap*/, typename LCC::Dart_const_handle adart)
 
41
  (const LCC& amap, typename LCC::Dart_const_handle adart)
42
42
  {
43
43
    // TODO Better approximation by using Newell's method
44
44
    // Nx += (Vy - V'y) * (Vz + V'z);
45
45
    // Ny += (Vz - V'z) * (Vx + V'x);
46
46
    // Nz += (Vx - V'x) * (Vy + V'y);
47
47
    // But problem with functor since this is not the sum of normal vectors.
48
 
  
 
48
 
49
49
    typedef typename LCC::Point Point;
50
50
    typedef typename LCC::Vector Vector;
51
51
    typename LCC::Dart_const_handle start=adart;
52
52
    Vector normal(CGAL::NULL_VECTOR);
53
53
 
54
 
    while ( !start->is_free(0) && start->beta(0)!=adart )
55
 
      start = start->beta(0);
 
54
    while ( !amap.template is_free<0>(start) &&
 
55
            amap.template beta<0>(start)!=adart )
 
56
      start = amap.template beta<0>(start);
56
57
 
57
 
    if ( start->is_free(1) || start->beta(1)->other_extremity()==NULL )
 
58
    if ( amap.template is_free<1>(start) ||
 
59
         amap.other_extremity(amap.template beta<1>(start))==LCC::null_handle )
58
60
      return normal;
59
61
 
60
62
    unsigned int nb = 0;
61
 
    adart = start->beta(1);
62
 
  
63
 
    const Point* prev = &LCC::point(start);
64
 
    const Point* curr = &LCC::point(adart);
65
 
    for ( ; adart!=start && adart->other_extremity()!=NULL;
66
 
          adart=adart->beta(1) )
 
63
    adart = amap.template beta<1>(start);
 
64
 
 
65
    const Point* prev = &amap.point(start);
 
66
    const Point* curr = &amap.point(adart);
 
67
    for ( ; adart!=start && amap.other_extremity(adart)!=LCC::null_handle;
 
68
          adart=amap.template beta<1>(adart) )
67
69
    {
68
 
      const Point* next = &LCC::point(adart->other_extremity());
 
70
      const Point* next = &amap.point( amap.other_extremity(adart));
69
71
      if ( !typename LCC::Traits::Collinear_3()(*prev, *curr, *next) )
70
72
      {
71
73
        normal = typename LCC::Traits::Construct_sum_of_vectors()
76
78
      }
77
79
      curr = next;
78
80
    }
79
 
  
80
 
    if ( nb<2 ) return normal;       
81
 
    return (typename LCC::Traits::Construct_scaled_vector()(normal, 1.0/nb));  
 
81
 
 
82
    if ( nb<2 ) return normal;
 
83
    return (typename LCC::Traits::Construct_scaled_vector()(normal, 1.0/nb));
82
84
    //  return normal / std::sqrt(normal * normal);
83
85
  }
84
86
 
94
96
    typedef typename LCC::Vector Vector;
95
97
    Vector normal(CGAL::NULL_VECTOR);
96
98
    unsigned int nb = 0;
97
 
  
 
99
 
98
100
    for ( CMap_one_dart_per_incident_cell_const_iterator<LCC,2,0>
99
101
            it(amap, adart); it.cont(); ++it )
100
102
    {
102
104
        (normal, CGAL::compute_normal_of_cell_2(amap,it));
103
105
      ++nb;
104
106
    }
105
 
  
106
 
    if ( nb<2 ) return normal;       
 
107
 
 
108
    if ( nb<2 ) return normal;
107
109
    return (typename LCC::Traits::Construct_scaled_vector()(normal, 1.0/nb));
108
110
  }
 
111
  // Compute the barycenter of a given i-cell
 
112
  // General case, 1<i<=dimension
 
113
  template<class LCC, unsigned int i, unsigned int dim=LCC::dimension>
 
114
  struct Barycenter_functor
 
115
  {
 
116
    static typename LCC::Point run(const LCC& amap,
 
117
                                   typename LCC::Dart_const_handle adart)
 
118
    {
 
119
      CGAL_static_assertion(0<i && i<=LCC::dimension);
 
120
      CGAL_assertion(adart != LCC::null_handle);
 
121
 
 
122
      typename LCC::Vector vec
 
123
        (typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
 
124
                                                  amap.point(adart)));
 
125
      unsigned int nb = 1;
 
126
 
 
127
      CGAL::CMap_one_dart_per_incident_cell_const_iterator<LCC,0,i,i>
 
128
          it(amap, adart);
 
129
      for ( ++it; it.cont(); ++it)
 
130
      {
 
131
        vec = typename LCC::Traits::Construct_sum_of_vectors()
 
132
          (vec, typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
 
133
                                                    amap.point(it) ));
 
134
        ++nb;
 
135
      }
 
136
 
 
137
      return typename LCC::Traits::Construct_translated_point()
 
138
        (CGAL::ORIGIN, typename LCC::Traits::Construct_scaled_vector()
 
139
         (vec, 1.0/nb));
 
140
    }
 
141
  };
 
142
 
 
143
  // Compute the barycenter of a given 1-cell
 
144
  template<class LCC, unsigned int dim>
 
145
  struct Barycenter_functor<LCC, 1, dim>
 
146
  {
 
147
    static typename LCC::Point run(const LCC& amap,
 
148
                                   typename LCC::Dart_const_handle adart)
 
149
    {
 
150
      CGAL_static_assertion(1<=LCC::dimension);
 
151
      CGAL_assertion(adart != LCC::null_handle);
 
152
      typename LCC::Dart_const_handle d2=amap.other_extremity(adart);
 
153
      if (d2==amap.null_handle) return amap.point(adart);
 
154
      return typename LCC::Traits::Construct_midpoint()
 
155
        (amap.point(adart),
 
156
         amap.point(d2));
 
157
    }
 
158
  };
 
159
 
 
160
  // Compute the barycenter of a given 2-cell
 
161
  template<class LCC, unsigned int dim>
 
162
  struct Barycenter_functor<LCC, 2, dim>
 
163
  {
 
164
    static typename LCC::Point run(const LCC& amap,
 
165
                                   typename LCC::Dart_const_handle adart)
 
166
    {
 
167
      CGAL_static_assertion(2<=LCC::dimension);
 
168
      CGAL_assertion(adart != LCC::null_handle);
 
169
 
 
170
      typename LCC::Vector vec
 
171
        (typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
 
172
                                                  amap.point(adart)));
 
173
      unsigned int nb = 1;
 
174
 
 
175
        typename LCC::template Dart_of_cell_range<2,2>::const_iterator
 
176
          vhit  = amap.template darts_of_cell<2,2>(adart).begin(),
 
177
          vhend = amap.template darts_of_cell<2,2>(adart).end();
 
178
      for( ++vhit; vhit!=vhend; ++vhit )
 
179
      {
 
180
        vec = typename LCC::Traits::Construct_sum_of_vectors()
 
181
          (vec, typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
 
182
                                                         amap.point(vhit) ));
 
183
        ++nb;
 
184
      }
 
185
      return typename LCC::Traits::Construct_translated_point()
 
186
        (CGAL::ORIGIN, typename LCC::Traits::Construct_scaled_vector()
 
187
         (vec, 1.0/nb));
 
188
    }
 
189
  };
109
190
 
110
191
} // namespace CGAL
111
192