File: Envelope_overlay_2.h

package info (click to toggle)
cgal 4.0-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 65,068 kB
  • sloc: cpp: 500,870; ansic: 102,544; sh: 321; python: 92; makefile: 75; xml: 2
file content (253 lines) | stat: -rw-r--r-- 7,631 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Copyright (c) 2005  Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/next/Envelope_3/include/CGAL/Envelope_3/Envelope_overlay_2.h $
// $Id: Envelope_overlay_2.h 67117 2012-01-13 18:14:48Z lrineau $
// 
//
// Author(s)     : Michal Meyerovitch     <gorgymic@post.tau.ac.il>
//                 Baruch Zukerman        <baruchzu@post.tau.ac.il>

#ifndef CGAL_ENVELOPE_OVERLAY_2_H
#define CGAL_ENVELOPE_OVERLAY_2_H

#include <CGAL/Arr_overlay_2.h>
#include <CGAL/Envelope_3/Envelope_overlay_functor.h>

#include <iostream>

namespace CGAL {

template <class MinimizationDiagram_2, 
          class OverlayFunctor = Envelope_overlay_functor<MinimizationDiagram_2> >
class Envelope_overlay_2
{
public:
  typedef MinimizationDiagram_2                                  Minimization_diagram_2;
  
  typedef typename Minimization_diagram_2::Face_handle           Face_handle;
  typedef typename Minimization_diagram_2::Face_iterator         Face_iterator;

  typedef typename Minimization_diagram_2::Vertex_handle         Vertex_handle;
  typedef typename Minimization_diagram_2::Vertex_iterator       Vertex_iterator;

  typedef typename Minimization_diagram_2::Halfedge_handle       Halfedge_handle;
  typedef typename Minimization_diagram_2::Halfedge_iterator     Halfedge_iterator;

  typedef OverlayFunctor                                         Overlay_functor;
protected:
  typedef typename Minimization_diagram_2::Geometry_traits_2     Traits;
  typedef typename Traits::Xy_monotone_surface_3                 Xy_monotone_surface_3;

public:
  
  void operator()(Minimization_diagram_2& md1,
                  Minimization_diagram_2& md2,
                  Minimization_diagram_2& result)
  {
    CGAL_assertion(md1.is_valid());
    CGAL_assertion(md2.is_valid());

    Overlay_functor overlay_func(md1, md2, result);
    overlay(md1, md2, result, overlay_func);
        
    CGAL_assertion_code(post_test_assertions(result));
  }


public:
  
  /*
  void print_face(Face_handle fh)
  {
    std::cout << (fh->is_unbounded() ? "unbounded" : "bounded");
    
    if (fh->get_is_set())
    {
      std::cout << " #data= " << fh->number_of_data_objects();
      if (fh->number_of_data_objects() > 0)
        std::cout << " data= " << fh->get_data();
    }

    if (fh->get_aux_is_set(0))
    {
      std::cout << " #data1= " << get_number_of_aux_data_objects(fh, 0);
      if (get_number_of_aux_data_objects(fh, 0)>0)
        std::cout << " data#1= " << get_aux_data(fh, 0);
    }
    if (fh->get_aux_is_set(1))
    {
      std::cout << " #data2= " << get_number_of_aux_data_objects(fh, 1);
      if (get_number_of_aux_data_objects(fh, 1)>0)
        std::cout << " data#2= " << get_aux_data(fh, 1);
    }
    std::cout << std::endl;
  }

  // print the aux data in the faces of md
  void print_faces(Minimization_diagram_2& md)
  {
    Face_iterator fit = md.faces_begin();
    for(; fit != md.faces_end(); ++fit)
    {
      Face_handle fh = fit;
      print_face(fh);
    }
    std::cout << std::endl;
  }

  void print_vertices(Minimization_diagram_2& md)
  {
    Vertex_iterator vit = md.vertices_begin();
    for(; vit != md.vertices_end(); ++vit)
    {
      Vertex_handle vh = vit;
      std::cout << vh->point();

      if (vh->get_is_set())
      {
        std::cout << " #data= " << vh->number_of_data_objects();
        if (vh->number_of_data_objects() > 0)
          std::cout << " data= " << vh->get_data();
      }

      if (vh->get_aux_is_set(0))
      {
        std::cout << " #data1= " << get_number_of_aux_data_objects(vh, 0);
        if (get_number_of_aux_data_objects(vh, 0)>0)
          std::cout << " data#1= " << get_aux_data(vh, 0);
      }
      if (vh->get_aux_is_set(1))
      {
        std::cout << " #data2= " << get_number_of_aux_data_objects(vh, 1);
        if (get_number_of_aux_data_objects(vh, 1)>0)
          std::cout << " data#2= " << get_aux_data(vh, 1);
      }
      std::cout << std::endl;
    }
    std::cout << std::endl;  
  }

  void print_edges(Minimization_diagram_2& md)
  {
    Halfedge_iterator hit = md.halfedges_begin();
    for(; hit != md.halfedges_end(); ++hit, ++hit)
    {
      Halfedge_handle hh = hit;
      std::cout << hh->curve();

      if (hh->get_is_set())
      {
        std::cout << " #data= " << hh->number_of_data_objects();
        if (hh->number_of_data_objects() > 0)
          std::cout << " data= " << hh->get_data();
      }


      if (hh->get_aux_is_set(0))
      {
        std::cout << " #data1= " << get_number_of_aux_data_objects(hh, 0);
        if (get_number_of_aux_data_objects(hh, 0)>0)
          std::cout << " data#1= " << get_aux_data(hh, 0);
      }
      if (hh->get_aux_is_set(1))
      {
        std::cout << " #data2= " << get_number_of_aux_data_objects(hh, 1);

        if (get_number_of_aux_data_objects(hh, 1)>0)
          std::cout << " data#2= " << get_aux_data(hh, 1);
      }
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }
  */

  void post_test_assertions(Minimization_diagram_2& md)
  {
    // check that all data is filled in result
    Face_iterator fi = md.faces_begin();
    for(; fi != md.faces_end(); ++fi)
    {
      Face_handle fh = fi;
      CGAL_assertion_msg(fh->get_aux_is_set(0), "data from md1 on face is not set");
      CGAL_assertion_msg(fh->get_aux_is_set(1), "data from md2 on face is not set");
    }

    Halfedge_iterator hi = md.halfedges_begin();
    for(; hi != md.halfedges_end(); ++hi)
    {
      Halfedge_handle hh = hi;
      CGAL_assertion_msg(hh->get_aux_is_set(0), "data from md1 on halfedge is not set");
      CGAL_assertion_msg(hh->get_aux_is_set(1), "data from md2 on halfedge is not set");
    }

    Vertex_iterator vi = md.vertices_begin();
    for(; vi != md.vertices_end(); ++vi)
    {
      Vertex_handle vh = vi;
      CGAL_assertion_msg(vh->get_aux_is_set(0), "data from md1 on vertex is not set");
      CGAL_assertion_msg(vh->get_aux_is_set(1), "data from md2 on vertex is not set");
    }
  }
protected:
  // helper methods
  template <class FeatureHandle>
  Xy_monotone_surface_3 get_aux_data(FeatureHandle fh, unsigned int id)
  {
    const Object& o = fh->get_aux_source(id);
    Xy_monotone_surface_3 data;

    Halfedge_handle h;
    Vertex_handle v;
  	Face_handle f;
  	if (assign(v, o))
  	  data = v->get_data();
  	else if (assign(h, o))
  	  data = h->get_data();
  	else
  	{
  	  CGAL_assertion(assign(f, o));
      assign(f, o);
  	  data = f->get_data();
  	}
    return data;
  }
  template <class FeatureHandle>
  int get_number_of_aux_data_objects(FeatureHandle fh, unsigned int id)
  {
	  const Object& o = fh->get_aux_source(id);
    int data;

    Halfedge_handle h;
    Vertex_handle v;
  	Face_handle f;
  	if (assign(v, o))
  	  data = v->number_of_data_objects();
  	else if (assign(h, o))
  	  data = h->number_of_data_objects();
  	else
  	{
  	  CGAL_assertion(assign(f, o));
      assign(f, o);
  	  data = f->number_of_data_objects();
  	}
    return data;
  }

};

} //namespace CGAL

#endif