Code modifications to follow doc

This commit is contained in:
Guillaume Damiand 2011-10-23 11:42:53 +00:00
parent 9b4924df84
commit 31440599ae
4 changed files with 345 additions and 464 deletions

View File

@ -20,6 +20,7 @@
#define CGAL_LINEAR_CELL_COMPLEX_H 1
#include <CGAL/Combinatorial_map.h>
#include <CGAL/Combinatorial_map_operations.h>
#include <CGAL/Linear_cell_complex_min_items.h>
#include <CGAL/Linear_cell_complex_traits.h>
#include <CGAL/predicates_d.h>
@ -68,7 +69,8 @@ namespace CGAL {
typedef Alloc_ Alloc;
static const unsigned int ambient_dimension = ambient_dim;
static const unsigned int dimension = Base::dimension;
typedef typename Base::Dart_handle Dart_handle;
typedef typename Base::Dart_const_handle Dart_const_handle;
typedef typename Base::Helper Helper;
@ -533,8 +535,19 @@ namespace CGAL {
template<unsigned int i>
Point barycenter(Dart_const_handle adart) const
{
CGAL_static_assertion(0<i && i<=dimension);
CGAL_assertion(adart != NULL);
// Special case for edge.
if (i==1)
{
Dart_const_handle d2=adart->other_extremity();
if (d2==NULL) return point(adart);
return typename Traits::Construct_midpoint() (point(adart),
point(d2));
}
// General case, 1<i<=dimension
Vector vec(typename Traits::Construct_vector()(CGAL::ORIGIN,
point(adart)));
unsigned int nb = 1;
@ -552,7 +565,74 @@ namespace CGAL {
(CGAL::ORIGIN, typename Traits::Construct_scaled_vector()(vec, 1.0/nb));
}
};
/** Insert a point in a given 1-cell.
* @param dh a dart handle to the 1-cell
* @param p the point to insert
* @return a dart handle to the new vertex containing p.
*/
Dart_handle insert_point_in_cell_1(Dart_handle dh, const Point& p)
{
Vertex_attribute_handle v=create_vertex_attribute(p);
Dart_handle res = CGAL::insert_cell_0_in_cell_1(*this, dh);
set_vertex_attribute(res, v);
return res;
}
/** Insert a point in a given 2-cell.
* @param dh a dart handle to the 2-cell
* @param p the point to insert
* @return a dart handle to the new vertex containing p.
*/
Dart_handle insert_point_in_cell_2(Dart_handle dh, const Point& p)
{
Vertex_attribute_handle v = create_vertex_attribute(p);
Dart_handle first = CGAL::insert_cell_0_in_cell_2(*this, dh);
if (first != NULL) // If the triangulated facet was not made of one dart
set_vertex_attribute(first, v);
else
erase_vertex_attribute(v);
return first;
}
/** Insert a point in a given i-cell.
* @param dh a dart handle to the i-cell
* @param p the point to insert
* @return a dart handle to the new vertex containing p.
*/
template <unsigned int i>
Dart_handle insert_point_in_cell(Dart_handle dh, const Point& p)
{
CGAL_static_assertion(1<=i && i<=2);
if (i==1) return insert_point_in_cell_1(dh, p);
return insert_point_in_cell_2(dh, p);
}
/** Insert a dangling edge in a given facet.
* @param dh a dart of the facet (!=NULL).
* @param p the coordinates of the new vertex.
* @return a dart of the new edge, incident to the new vertex.
*/
Dart_handle insert_dangling_cell_1_in_cell_2(Dart_handle dh, const Point& p)
{
Vertex_attribute_handle v = create_vertex_attribute(p);
Dart_handle res = CGAL::insert_dangling_cell_1_in_cell_2(*this, dh);
set_vertex_attribute(res, v);
return res;
}
/** Insert a point in a given i-cell.
* @param dh a dart handle to the i-cell
* @param p the point to insert
* @return a dart handle to the new vertex containing p.
*/
template <unsigned int i>
Dart_handle insert_barycenter_in_cell(Dart_handle dh)
{ return insert_point_in_cell<i>(dh, barycenter<i>(dh)); }
};
} // namespace CGAL

View File

@ -33,192 +33,142 @@
namespace CGAL {
/** @file Combinatorial_map_with_embedding_constructors.h
* Basic construction operations for an embedded combinatorial map.
* create edge, triangle, quadrilateral, tetrahedron,hexahedron, plus
* contruction from other CGAL data structures.
/** @file Linear_cell_complex_constructors.h
* Some construction operations for a linear cell complex from other
* CGAL data structures.
*/
/** Create an iso cuboid given an Iso_cuboid_3.
* @param amap the used combinatorial map.
* @param c the iso cuboid.
* @return the dart of the new cuboid incident to the first vertex of c.
*/
/*template <class CMap>
typename CMap::Dart_handle make_iso_cuboid
(CMap& amap, const typename CMap::Iso_cuboid& r)
{
return make_hexahedron<CMap>(amap, r[0], r[1], r[2], r[3],
r[4], r[5], r[6], r[7]);
}*/
/** Create an iso cuboid given its two extreme points.
* @param amap the used combinatorial map.
* @param ap1 the first point.
* @param ap2 the second.
* @return the dart of the new iso cuboid incident to ap1.
*/
/*template <class CMap>
typename CMap::Dart_handle make_iso_cuboid(CMap& amap,
const typename CMap::Point& ap1,
const typename CMap::Point& ap2)
{
return make_iso_cuboid<CMap>
(amap, //typename CMap::Construct_iso_cuboid()(ap1, ap2));
typename CMap::Iso_cuboid(ap1, ap2));
}*/
/** Create a cube given one point and one length.
* @param amap the used combinatorial map.
* @param ap1 the first point.
* @param al the length.
* @return the dart of the new cube incident to ap1.
*/
/*template < class Map >
typename Map::Dart_handle make_cube(Map& amap,
const typename Map::Point& ap1,
typename Map::FT al)
{ return make_cuboid(amap, ap1, al, al, al); }*/
/** Convert an embedded plane graph read into a flux into combinatorial map.
* @param amap the combinatorial map where the graph will be converted.
/** Import an embedded plane graph read into a flux into a linear cell complex.
* @param alcc the linear cell complex where the graph will be imported.
* @param ais the istream where read the graph.
* @return A dart created during the convertion.
*/
template< class Map >
typename Map::Dart_handle import_from_plane_graph(Map& amap,
std::istream& ais)
template< class LCC >
typename LCC::Dart_handle import_from_plane_graph(LCC& alcc,
std::istream& ais)
{
typedef typename Map::Dart_handle Dart_handle;
typedef typename Map::Traits::Direction_2 Direction;
typedef typename std::list<Dart_handle>::iterator List_iterator;
typedef typename std::map<Direction, Dart_handle>::iterator Map_iterator;
CGAL_static_assertion( LCC::ambient_dimension==2 );
typedef typename LCC::Dart_handle Dart_handle;
typedef typename LCC::Traits::Direction_2 Direction;
typedef typename std::list<Dart_handle>::iterator List_iterator;
typedef typename std::map<Direction, Dart_handle>::iterator LCC_iterator;
// Arrays of vertices
std::vector< typename LCC::Vertex_attribute_handle > initVertices;
std::vector< std::list<Dart_handle> > testVertices;
// Arrays of vertices
std::vector< typename Map::Vertex_attribute_handle > initVertices;
std::vector< std::list<Dart_handle> > testVertices;
std::string txt;
typename Map::FT x, y;
Dart_handle d1 = NULL, d2 = NULL;
unsigned int v1, v2;
ais >> txt;
if (txt != "OFF2D")
{
std::cout << "Problem: file is not 2D OFF." << std::endl;
std::string txt;
typename LCC::FT x, y;
Dart_handle d1 = NULL, d2 = NULL;
unsigned int v1, v2;
unsigned int nbSommets = 0;
unsigned int nbAretes = 0;
ais >> nbSommets >> nbAretes;
while (nbSommets > 0)
{
if (!ais.good())
{
std::cout << "Problem: file does not contain enough vertices."
<< std::endl;
return NULL;
}
}
unsigned int nbSommets = 0;
unsigned int nbAretes = 0;
ais >> x >> y;
initVertices.push_back(alcc.create_vertex_attribute(typename LCC::Point(x, y)));
testVertices.push_back(std::list<Dart_handle>());
--nbSommets;
}
ais >> nbSommets >> nbAretes;
while (nbSommets > 0)
{
if (!ais.good())
while (nbAretes > 0)
{
if (!ais.good())
{
std::cout << "Problem: file does not contain enough vertices."
<< std::endl;
return NULL;
std::cout << "Problem: file does not contain enough edges."
<< std::endl;
return NULL;
}
ais >> x >> y;
initVertices.push_back(amap.create_vertex_attribute(typename Map::Point(x, y)));
testVertices.push_back(std::list<Dart_handle>());
--nbSommets;
}
// We read an egde (given by the number of its two vertices).
ais >> v1 >> v2;
--nbAretes;
while (nbAretes > 0)
{
if (!ais.good())
CGAL_assertion(v1 < initVertices.size());
CGAL_assertion(v2 < initVertices.size());
d1 = alcc.create_dart(initVertices[v1]);
d2 = alcc.create_dart(initVertices[v2]);
alcc.link_beta(d1, d2, 2);
testVertices[v1].push_back(d1);
testVertices[v2].push_back(d2);
}
// LCC associating directions and darts.
std::map<Direction, Dart_handle> tabDart;
List_iterator it;
LCC_iterator it2;
Dart_handle first = NULL;
Dart_handle prec = NULL;
typename LCC::Point sommet1, sommet2;
for (unsigned int i = 0; i < initVertices.size(); ++i)
{
it = testVertices[i].begin();
if (it != testVertices[i].end()) // Si la liste n'est pas vide.
{
// 1. We insert all the darts and sort them depending on the direction
tabDart.clear();
sommet1 = LCC::point(*it);
sommet2 = LCC::point((*it)->beta(2));
tabDart.insert(std::pair<Direction, Dart_handle>
(typename LCC::Construct_direction_2()
(typename LCC::Construct_vector()
(sommet1,sommet2)), *it));
++it;
while (it != testVertices[i].end())
{
std::cout << "Problem: file does not contain enough edges."
<< std::endl;
return NULL;
sommet2 = LCC::point((*it)->beta(2));
tabDart.insert(std::pair<Direction, Dart_handle>
(typename LCC::Construct_direction_2()
(typename LCC::Construct_vector()
(sommet1,sommet2)), *it));
++it;
}
// 2. We run through the array of darts and 1 links darts.
it2 = tabDart.begin();
first = it2->second;
prec = first;
++it2;
// We read an egde (given by the number of its two vertices).
ais >> v1 >> v2; ais.ignore(256, '\n');
--nbAretes;
CGAL_assertion(v1 < initVertices.size());
CGAL_assertion(v2 < initVertices.size());
d1 = amap.create_dart(initVertices[v1]);
d2 = amap.create_dart(initVertices[v2]);
amap.link_beta(d1, d2, 2);
testVertices[v1].push_back(d1);
testVertices[v2].push_back(d2);
}
// Map associating directions and darts.
std::map<Direction, Dart_handle> tabDart;
List_iterator it;
Map_iterator it2;
Dart_handle first = NULL;
Dart_handle prec = NULL;
typename Map::Point sommet1, sommet2;
for (unsigned int i = 0; i < initVertices.size(); ++i)
{
it = testVertices[i].begin();
if (it != testVertices[i].end()) // Si la liste n'est pas vide.
while (it2 != tabDart.end())
{
// 1. We insert all the darts and sort them depending on the direction
tabDart.clear();
sommet1 = Map::point(*it);
sommet2 = Map::point((*it)->beta(2));
tabDart.insert(std::pair<Direction, Dart_handle>
(typename Map::Construct_direction()
(typename Map::Construct_vector()
(sommet1,sommet2)), *it));
++it;
while (it != testVertices[i].end())
{
sommet2 = Map::point((*it)->beta(2));
tabDart.insert(std::pair<Direction, Dart_handle>
(typename Map::Construct_direction()
(typename Map::Construct_vector()
(sommet1,sommet2)), *it));
++it;
}
// 2. We run through the array of darts and 1 links darts.
it2 = tabDart.begin();
first = it2->second;
prec = first;
++it2;
while (it2 != tabDart.end())
{
amap.template link_beta<0>(prec, it2->second->beta(2));
prec = it2->second;
++it2;
}
amap.template link_beta<0>(prec, first->beta(2));
alcc.template link_beta<0>(prec, it2->second->beta(2));
prec = it2->second;
++it2;
}
}
// We return a dart from the imported object.
return first;
alcc.template link_beta<0>(prec, first->beta(2));
}
}
// We return a dart from the imported object.
return first;
}
/** Convert a given Triangulation_3 into the 3D combinatorial map.
* @param amap the used combinatorial map.
/** Convert a given Triangulation_3 into a 3D linear cell complex.
* @param alcc the used linear cell complex.
* @param atr the Triangulation_3.
* @return A dart incident to the infinite vertex.
*/
template < class Map, class Triangulation >
typename Map::Dart_handle import_from_triangulation_3(Map& amap,
template < class LCC, class Triangulation >
typename LCC::Dart_handle import_from_triangulation_3(LCC& alcc,
const Triangulation &atr)
{
// Case of empty triangulations.
@ -232,17 +182,17 @@ typename Map::Dart_handle import_from_triangulation_3(Map& amap,
typedef typename Triangulation::Vertex_iterator TVertex_iterator;
typedef typename Triangulation::Cell_iterator TCell_iterator;
typedef typename
std::map< TCell_iterator, typename Map::Dart_handle >::iterator itmap_tcell;
std::map< TCell_iterator, typename LCC::Dart_handle >::iterator itmap_tcell;
// Create vertices in the map and associate in a map
// TVertex_handle and vertices in the map.
std::map< TVertex_handle, typename Map::Vertex_attribute_handle > TV;
std::map< TVertex_handle, typename LCC::Vertex_attribute_handle > TV;
for (TVertex_iterator it = atr.vertices_begin();
it != atr.vertices_end(); ++it)
{
// if (it != atr.infinite_vertex())
{
TV[it] = amap.create_vertex_attribute(it->point());
TV[it] = alcc.create_vertex_attribute(it->point());
}
}
@ -250,11 +200,11 @@ typename Map::Dart_handle import_from_triangulation_3(Map& amap,
// and tetrahedron.
TCell_iterator it;
std::map< TCell_iterator, typename Map::Dart_handle > TC;
std::map< TCell_iterator, typename LCC::Dart_handle > TC;
itmap_tcell maptcell_it;
typename Map::Dart_handle res=NULL, dart=NULL;
typename Map::Dart_handle init=NULL, cur=NULL, neighbor=NULL;
typename LCC::Dart_handle res=NULL, dart=NULL;
typename LCC::Dart_handle init=NULL, cur=NULL, neighbor=NULL;
for (it = atr.cells_begin(); it != atr.cells_end(); ++it)
{
@ -264,7 +214,7 @@ typename Map::Dart_handle import_from_triangulation_3(Map& amap,
it->vertex(3) != atr.infinite_vertex())
*/
{
res = amap.make_tetrahedron(TV[it->vertex(0)],
res = alcc.make_tetrahedron(TV[it->vertex(0)],
TV[it->vertex(1)],
TV[it->vertex(2)],
TV[it->vertex(3)]);
@ -297,10 +247,10 @@ typename Map::Dart_handle import_from_triangulation_3(Map& amap,
maptcell_it->second->beta(2); break;
case 3: neighbor = maptcell_it->second; break;
}
while (Map::vertex_attribute(neighbor) !=
Map::vertex_attribute(cur->other_extremity()) )
while (LCC::vertex_attribute(neighbor) !=
LCC::vertex_attribute(cur->other_extremity()) )
neighbor = neighbor->beta(1);
amap.template topo_sew<3>(cur, neighbor);
alcc.template topo_sew<3>(cur, neighbor);
if (!neighbor->beta(2)->is_free(3) &&
!neighbor->beta(0)->beta(2)->is_free(3) &&
!neighbor->beta(1)->beta(2)->is_free(3))
@ -332,86 +282,84 @@ struct Hedge_cmp
};
}
/** Convert a given Polyhedron_3 into 3D combinatorial map.
* @param amap the combinatorial map where Polyhedron_3 will be converted.
/** Import a given Polyhedron_3 into a Linear_cell_complex.
* @param alcc the combinatorial map where Polyhedron_3 will be converted.
* @param apoly the Polyhedron.
* @return A dart created during the convertion.
*/
template< class Map, class Polyhedron >
typename Map::Dart_handle import_from_polyhedron(Map& amap,
const Polyhedron &apoly)
template< class LCC, class Polyhedron >
typename LCC::Dart_handle import_from_polyhedron(LCC& alcc,
const Polyhedron &apoly)
{
typedef typename Polyhedron::Halfedge_const_handle Halfedge_handle;
typedef typename Polyhedron::Facet_const_iterator Facet_iterator;
typedef typename Polyhedron::Halfedge_around_facet_const_circulator
HF_circulator;
typedef typename Polyhedron::Halfedge_const_handle Halfedge_handle;
typedef typename Polyhedron::Facet_const_iterator Facet_iterator;
typedef typename Polyhedron::Halfedge_around_facet_const_circulator
HF_circulator;
typedef std::map < Halfedge_handle, typename Map::Dart_handle>
Halfedge_handle_map;
typedef typename Halfedge_handle_map::iterator itmap_hds;
Halfedge_handle_map TC;
typedef std::map < Halfedge_handle, typename LCC::Dart_handle>
Halfedge_handle_map;
typedef typename Halfedge_handle_map::iterator itmap_hds;
Halfedge_handle_map TC;
itmap_hds it;
typename Map::Dart_handle d = NULL, prev = NULL,
firstFacet = NULL, firstAll = NULL;
itmap_hds it;
typename LCC::Dart_handle d = NULL, prev = NULL;
typename LCC::Dart_handle firstFacet = NULL, firstAll = NULL;
// First traversal to build the darts and link them.
for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i)
{
HF_circulator j = i->facet_begin();
prev = NULL;
do
{
d = amap.create_dart();
TC[j] = d;
if (prev != NULL) amap.template link_beta<1>(prev, d);
else firstFacet = d;
it = TC.find(j->opposite());
if (it != TC.end())
amap.link_beta(d, it->second, 2);
prev = d;
// First traversal to build the darts and link them.
for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i)
{
HF_circulator j = i->facet_begin();
prev = NULL;
do
{
d = alcc.create_dart();
TC[j] = d;
if (prev != NULL) alcc.template link_beta<1>(prev, d);
else firstFacet = d;
it = TC.find(j->opposite());
if (it != TC.end())
alcc.link_beta(d, it->second, 2);
prev = d;
}
while (++j != i->facet_begin());
alcc.template link_beta<1>(prev, firstFacet);
if (firstAll == NULL) firstAll = firstFacet;
}
// Second traversal to update the geometry.
// We run one again through the facets of the HDS.
for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i)
{
HF_circulator j = i->facet_begin();
do
{
d = TC[j]; // Get the dart associated to the Halfedge
if (LCC::vertex_attribute(d) == NULL)
{
alcc.set_vertex_attribute
(d, alcc.create_vertex_attribute(j->opposite()->vertex()->point()));
}
while (++j != i->facet_begin());
amap.template link_beta<1>(prev, firstFacet);
if (firstAll == NULL) firstAll = firstFacet;
}
// Second traversal to update the geometry.
// We run one again through the facets of the HDS.
for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i)
{
HF_circulator j = i->facet_begin();
do
{
d = TC[j]; // Get the dart associated to the Halfedge
if (Map::vertex_attribute(d) == NULL)
{
amap.set_vertex_attribute(d,
amap.create_vertex_attribute(j->opposite()->vertex()->point()));
}
}
while (++j != i->facet_begin());
}
return firstAll;
}
while (++j != i->facet_begin());
}
return firstAll;
}
template < class Map >
// class Polyhedron=CGAL::Polyhedron_3<typename Map::Kernel> >
void
load_off(Map& amap, std::istream& in)
template < class LCC >
void load_off(LCC& alcc, std::istream& in)
{
File_header_OFF m_file_header;
File_scanner_OFF scanner( in, m_file_header.verbose());
if ( ! in) return;
m_file_header = scanner; // Remember file header after return.
Linear_cell_complex_incremental_builder_3<Map> B( amap);
Linear_cell_complex_incremental_builder_3<LCC> B( alcc);
B.begin_surface( scanner.size_of_vertices(),
scanner.size_of_facets(),
scanner.size_of_halfedges());
typedef typename Map::Point Point;
typedef typename LCC::Point Point;
// read in all vertices
std::size_t i;
@ -479,24 +427,23 @@ if ( ! in || B.error()) {
}
/** Convert a Polyhedron_3 read into a flux into 3D combinatorial map.
* @param amap the combinatorial map where Polyhedron_3 will be converted.
* @param alcc the combinatorial map where Polyhedron_3 will be converted.
* @param ais the istream where read the Polyhedron_3.
* @return A dart created during the convertion.
*/
template < class Map >
// class Polyhedron=CGAL::Polyhedron_3<typename Map::Kernel> >
typename Map::Dart_handle
import_from_polyhedron_flux(Map& amap, std::istream& ais)
template < class LCC >
typename LCC::Dart_handle
import_from_polyhedron_flux(LCC& alcc, std::istream& ais)
{
if (!ais.good())
{
std::cout << "Error reading flux." << std::endl;
return NULL;
}
CGAL::Polyhedron_3<typename Map::Traits> P;
ais >> P;
return import_from_polyhedron<Map,
CGAL::Polyhedron_3<typename Map::Traits> > (amap, P);
if (!ais.good())
{
std::cout << "Error reading flux." << std::endl;
return NULL;
}
CGAL::Polyhedron_3<typename LCC::Traits> P;
ais >> P;
return import_from_polyhedron<LCC, CGAL::Polyhedron_3<typename LCC::Traits> >
(alcc, P);
}
} // namespace CGAL

View File

@ -16,8 +16,8 @@
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
//
#ifndef CGAL_COMBINATORIAL_MAP_WITH_POINTS_OPERATIONS_H
#define CGAL_COMBINATORIAL_MAP_WITH_POINTS_OPERATIONS_H 1
#ifndef CGAL_LINEAR_CELL_COMPLEX_OPERATIONS_H
#define CGAL_LINEAR_CELL_COMPLEX_OPERATIONS_H 1
#include <CGAL/Cell_iterators.h>
#include <CGAL/Combinatorial_map_operations.h>
@ -37,9 +37,9 @@ namespace CGAL {
* @param adart a dart incident to the facet.
* @return the normal of the facet.
*/
template <class CMap>
typename CMap::Vector compute_normal_of_cell_2
(const CMap& amap, typename CMap::Dart_const_handle adart)
template <class LCC>
typename LCC::Vector compute_normal_of_cell_2
(const LCC& amap, typename LCC::Dart_const_handle adart)
{
// TODO Better approximation by using Newell's method
// Nx += (Vy - V'y) * (Vz + V'z);
@ -47,9 +47,9 @@ typename CMap::Vector compute_normal_of_cell_2
// Nz += (Vx - V'x) * (Vy + V'y);
// But problem with functor since this is not the sum of normal vectors.
typedef typename CMap::Point Point;
typedef typename CMap::Vector Vector;
typename CMap::Dart_const_handle start=adart;
typedef typename LCC::Point Point;
typedef typename LCC::Vector Vector;
typename LCC::Dart_const_handle start=adart;
Vector normal(CGAL::NULL_VECTOR);
while ( !start->is_free(0) && start->beta(0)!=adart )
@ -61,24 +61,23 @@ typename CMap::Vector compute_normal_of_cell_2
unsigned int nb = 0;
adart = start->beta(1);
const Point* prev = &CMap::point(start);
const Point* curr = &CMap::point(adart);
const Point* prev = &LCC::point(start);
const Point* curr = &LCC::point(adart);
for ( ; adart!=start && adart->other_extremity()!=NULL; adart=adart->beta(1) )
{
const Point* next = &LCC::point(adart->other_extremity());
if ( !typename LCC::Collinear()(*prev, *curr, *next) )
{
const Point* next = &CMap::point(adart->other_extremity());
if ( !typename CMap::Collinear()(*prev, *curr, *next) )
{
normal = typename CMap::Construct_sum_of_vectors()
(normal, typename CMap::Construct_normal()(*prev, *curr, *next));
prev = curr;
++nb;
}
curr = next;
normal = typename LCC::Construct_sum_of_vectors()
(normal, typename LCC::Construct_normal_3()(*prev, *curr, *next));
prev = curr;
++nb;
}
curr = next;
}
if ( nb<2 ) return normal;
return (typename CMap::Construct_scaled_vector()(normal, 1.0/nb));
return (typename LCC::Construct_scaled_vector()(normal, 1.0/nb));
// return normal / std::sqrt(normal * normal);
}
@ -87,109 +86,27 @@ typename CMap::Vector compute_normal_of_cell_2
* @param adart a dart incident to the vertex.
* @return the normal of the vertex.
*/
template <class CMap>
typename CMap::Vector compute_normal_of_cell_0
(const CMap& amap, typename CMap::Dart_const_handle adart)
template <class LCC>
typename LCC::Vector compute_normal_of_cell_0
(const LCC& amap, typename LCC::Dart_const_handle adart)
{
typedef typename CMap::Point Point;
typedef typename CMap::Vector Vector;
typedef typename LCC::Point Point;
typedef typename LCC::Vector Vector;
Vector normal(CGAL::NULL_VECTOR);
unsigned int nb = 0;
for ( CMap_one_dart_per_incident_cell_const_iterator<CMap,2,0> it(amap, adart);
it.cont(); ++it)
{
normal = typename CMap::Construct_sum_of_vectors()
(normal, CGAL::compute_normal_of_cell_2(amap,it));
++nb;
}
for ( CMap_one_dart_per_incident_cell_const_iterator<LCC,2,0> it(amap, adart);
it.cont(); ++it)
{
normal = typename LCC::Construct_sum_of_vectors()
(normal, CGAL::compute_normal_of_cell_2(amap,it));
++nb;
}
if ( nb<2 ) return normal;
return (typename CMap::Construct_scaled_vector()(normal, 1.0/nb));
return (typename LCC::Construct_scaled_vector()(normal, 1.0/nb));
// return normal / std::sqrt(normal * normal);
}
/** Insert a vertex in the center (barycenter) of the given facet,
* the facet is splitted in triangles, once for each inital edge of the facet.
* @param amap the used combinatorial map.
* @param adart a dart of the facet to triangulate.
* @return A dart incident to the new vertex.
*/
template<class CMap>
typename CMap::Dart_handle insert_center_cell_0_in_cell_2
(CMap& amap, typename CMap::Dart_handle adart)
{
CGAL_assertion(adart != NULL);
typename CMap::Vertex_attribute_handle v =
amap.create_vertex_attribute(amap.barycenter<2>(adart));
typename CMap::Dart_handle first =
CGAL::insert_cell_0_in_cell_2(amap, adart);
if (first != NULL) // If the triangulated facet was not made of one dart
amap.set_vertex_attribute(first, v);
else
amap.erase_vertex_attribute(v);
// CGAL_postcondition(amap.is_valid());
return first;
}
/** Insert a vertex in a given edge.
* @param amap the used combinatorial map.
* @param adart a dart of the edge (!=NULL).
* @param apoint the coordinates of the new vertex.
* @return a dart of the new vertex.
*/
template<class CMap>
typename CMap::Dart_handle insert_cell_0_in_cell_1
(CMap& amap, typename CMap::Dart_handle adart,
const typename CMap::Point& apoint)
{
typename CMap::Vertex_attribute_handle v=amap.create_vertex_attribute(apoint);
typename CMap::Dart_handle res = insert_cell_0_in_cell_1(amap,adart);
amap.set_vertex_attribute(res, v);
return res;
}
/** Insert a vertex in the middle of a given edge.
* @param amap the used combinatorial map.
* @param adart a dart of the edge (!=NULL).
* @return a dart of the new vertex.
*/
template<class CMap>
typename CMap::Dart_handle insert_middle_cell_0_in_cell_1
(CMap& amap, typename CMap::Dart_handle adart)
{
CGAL_assertion(adart!=NULL);
typename CMap::Dart_handle d2 = adart->other_extremity();
if ( d2==NULL )
return insert_cell_0_in_cell_1(amap, adart, CMap::point(adart));
return insert_cell_0_in_cell_1(amap, adart, typename CMap::Construct_midpoint()
(CMap::point(adart), CMap::point(d2)));
}
/** Insert a dangling edge in a given facet.
* @param amap the used combinatorial map.
* @param adart a dart of the facet (!=NULL).
* @param apoint the coordinates of the new vertex.
* @return a dart of the new edge, incident to the new vertex.
*/
template<class Map>
typename Map::Dart_handle insert_dangling_cell_1_in_cell_2
(Map& amap, typename Map::Dart_handle adart, const typename Map::Point& apoint)
{
typename Map::Vertex_attribute_handle
v = amap.create_vertex_attribute(apoint);
typename Map::Dart_handle res = insert_dangling_cell_1_in_cell_2(amap,adart);
amap.set_vertex_attribute(res, v);
return res;
}
/** Compute the dual of a combinatorial map.
* @param amap1 the initial map.
@ -199,7 +116,7 @@ typename Map::Dart_handle insert_dangling_cell_1_in_cell_2
*/
template<class Map>
typename Map::Dart_handle dual(Map& amap1, Map& amap2,
typename Map::Dart_handle adart=NULL)
typename Map::Dart_handle adart=NULL)
{
CGAL_assertion( amap1.is_without_boundary(Map::dimension) );
@ -227,41 +144,41 @@ typename Map::Dart_handle dual(Map& amap1, Map& amap2,
Dart_iterator it2=amap2.darts().begin();
for (Dart_iterator it=amap1.darts().begin(); it!=amap1.darts().end();
++it, ++it2)
{
d = it2; // The supposition on the order allows to avoid d=dual[it];
CGAL_assertion(it2 == dual[it]);
// First case outside the loop since we need to use link_beta1
if ( it->beta(Map::dimension)->beta(Map::dimension-1)!=Map::null_dart_handle )
amap2. template
link_beta<1>(d,
dual[it->beta(Map::dimension)->beta(Map::dimension-1)]);
// and during the loop we use link_beta(d1,d2,i)
for (unsigned int i=Map::dimension-2; i>=1; --i)
{
d = it2; // The supposition on the order allows to avoid d=dual[it];
CGAL_assertion(it2 == dual[it]);
// First case outside the loop since we need to use link_beta1
if ( it->beta(Map::dimension)->beta(Map::dimension-1)!=Map::null_dart_handle )
amap2. template
link_beta<1>(d,
dual[it->beta(Map::dimension)->beta(Map::dimension-1)]);
// and during the loop we use link_beta(d1,d2,i)
for (unsigned int i=Map::dimension-2; i>=1; --i)
{
if ( it->beta(Map::dimension)->beta(i)!=Map::null_dart_handle )
amap2.link_beta(d, dual[it->beta(Map::dimension)->beta(i)],
Map::dimension-i);
}
CGAL_assertion ( !it->is_free(Map::dimension) );
amap2.link_beta(d, dual[it->beta(Map::dimension)],Map::dimension);
if ( it->beta(Map::dimension)->beta(i)!=Map::null_dart_handle )
amap2.link_beta(d, dual[it->beta(Map::dimension)->beta(i)],
Map::dimension-i);
}
CGAL_assertion ( !it->is_free(Map::dimension) );
amap2.link_beta(d, dual[it->beta(Map::dimension)],Map::dimension);
}
// Now the map amap is topologically correct, we just need to add
// its geometry to each vertex (the barycenter of the corresponding
// volume in the initial map).
it2 = amap2.darts().begin();
for (Dart_iterator it(amap1.darts().begin());
it!=amap1.darts().end(); ++it, ++it2)
for (Dart_iterator it(amap1.darts().begin()); it!=amap1.darts().end();
++it, ++it2)
{
if (Map::vertex_attribute(it2) == NULL)
{
if (Map::vertex_attribute(it2) == NULL)
{
amap2.set_vertex_attribute(it2,
amap2.create_vertex_attribute
(amap1.barycenter<Map::dimension>(it)));
}
amap2.set_vertex_attribute(it2,
amap2.create_vertex_attribute
(amap1.barycenter<Map::dimension>(it)));
}
}
// CGAL_postcondition(amap2.is_valid());
@ -271,5 +188,5 @@ typename Map::Dart_handle dual(Map& amap1, Map& amap2,
} // namespace CGAL
#endif // CGAL_COMBINATORIAL_MAP_WITH_EMBEDDING_OPERATIONS_H //
#endif // CGAL_LINEAR_CELL_COMPLEX_OPERATIONS_H //
// EOF //

View File

@ -36,40 +36,24 @@ namespace CGAL {
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_d Point;
typedef typename Kernel::Vector_d Vector;
typedef typename Kernel::Direction_d Direction;
// Constructions
struct Construct_translated_point
{
Point operator() (const CGAL::Origin&, const Vector& v)
{ Point p(ambient_dimension, CGAL::Origin()); return p+v; }
Point operator() (const Point&p, const Vector& v)
{ return p+v; }
};
// TODO THE Construct_vector
struct Construct_vector : public Kernel::Construct_vector_d
{
using Kernel::Construct_vector_d::operator();
Vector operator() (typename Kernel::FT x1)
{
Vector v(d_, NULL_VECTOR); v[0]=x1;
return v;
}
Vector operator() (typename Kernel::FT x1, typename Kernel::FT x2)
{
Vector v(d_, NULL_VECTOR); v[0]=x1; v[1]=x2;
return v;
}
Vector operator() (typename Kernel::FT x1,
typename Kernel::FT x2,
typename Kernel::FT x3)
{
Vector v(d_, NULL_VECTOR); v[0]=x1; v[1]=x2; v[2]=x3;
return v;
}
Vector operator() (const Origin&, const Point& p)
{ return typename Kernel::Point_to_vector_d()(p); }
Vector operator() (const Point& p1, const Point& p2)
{ return p2-p1; }
Vector operator() (const CGAL::Origin&, const Point& p)
{ return operator() (Point(ambient_dimension, CGAL::Origin()),p); }
};
struct Construct_sum_of_vectors
{
Vector operator() (const Vector&v1, const Vector& v2)
@ -78,8 +62,7 @@ namespace CGAL {
struct Construct_scaled_vector
{
Vector operator() (const Vector& v,
typename Kernel::FT scale)
Vector operator() (const Vector& v, typename Kernel::FT scale)
{ return scale*v; }
};
@ -88,15 +71,6 @@ namespace CGAL {
Point operator() (const Point&p1, const Point& p2)
{ return typename Kernel::Midpoint_d()(p1, p2); }
};
// TODO Make the Construct_direction
// Predicates
struct Collinear
{
bool operator() (const Point&p1, const Point&p2, const Point&p3)
{ return ((p2-p1)*(p3-p2))==0; }
};
};
/** Trait class for Linear_cell_complex class.
@ -110,19 +84,12 @@ namespace CGAL {
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2 Point;
typedef typename Kernel::Vector_2 Vector;
typedef typename Kernel::Direction_2 Direction;
// Constructions
typedef typename Kernel::Construct_translated_point_2
Construct_translated_point;
// TODO THE Construct_vector functor with two operators () (verify the kernel doc)
struct Construct_vector : public Kernel::Construct_vector_2
{
using Kernel::Construct_vector_2::operator();
Vector operator() (typename Kernel::FT x1)
{ return Kernel::Construct_vector_2()(x1, 0); }
};
typedef typename Kernel::Construct_vector_2 Construct_vector;
typedef typename Kernel::Construct_sum_of_vectors_2
Construct_sum_of_vectors;
@ -132,18 +99,6 @@ namespace CGAL {
typedef typename Kernel::Construct_midpoint_2
Construct_midpoint;
typedef typename Kernel::Construct_direction_2
Construct_direction;
/* struct Vector_to_point TO REMOVE ?
{
Point operator() (const Vector&v)
{ return Kernel::Construct_translated_point(ORIGIN, v); }
};*/
// Predicates
typedef typename Kernel::Collinear_2 Collinear;
};
/** Trait class for Linear_cell_complex class.
@ -157,21 +112,12 @@ namespace CGAL {
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Kernel::Direction_3 Direction;
// Constructions
typedef typename Kernel::Construct_translated_point_3
Construct_translated_point;
// TODO the Construct_vector
struct Construct_vector : public Kernel::Construct_vector_3
{
using Kernel::Construct_vector_3::operator();
Vector operator() (typename Kernel::FT x1)
{ return Kernel::Construct_vector_3()(x1, 0, 0); }
Vector operator() (typename Kernel::FT x1, typename Kernel::FT x2)
{ return Kernel::Construct_vector_3()(x1, x2, 0); }
};
typedef typename Kernel::Construct_vector_3 Construct_vector;
typedef typename Kernel::Construct_sum_of_vectors_3
Construct_sum_of_vectors;
@ -181,15 +127,6 @@ namespace CGAL {
typedef typename Kernel::Construct_midpoint_3
Construct_midpoint;
typedef typename Kernel::Construct_direction_3
Construct_direction;
typedef typename Kernel::Construct_normal_3
Construct_normal;
// Predicates
typedef typename Kernel::Collinear_3 Collinear;
};
} // namespace CGAL