move compute_normal in Polygon Mesh Processing package

This commit is contained in:
Sébastien Loriot 2015-01-06 15:32:45 +01:00
parent 59c0d3e8d5
commit 85dce701b9
17 changed files with 46 additions and 167 deletions

View File

@ -1,44 +0,0 @@
#ifndef _COMPUTE_NORMAL_
#define _COMPUTE_NORMAL_
template <class Facet, class Kernel>
typename Kernel::Vector_3 compute_facet_normal(const Facet& f)
{
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Facet::Halfedge_around_facet_const_circulator HF_circulator;
Vector normal = CGAL::NULL_VECTOR;
HF_circulator he = f.facet_begin();
HF_circulator end = he;
CGAL_For_all(he,end)
{
const Point& prev = he->prev()->vertex()->point();
const Point& curr = he->vertex()->point();
const Point& next = he->next()->vertex()->point();
Vector n = CGAL::cross_product(next-curr,prev-curr);
normal = normal + (n / std::sqrt(n*n));
}
return normal / std::sqrt(normal * normal);
}
template <class Vertex, class Kernel>
typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v)
{
typedef typename Kernel::Vector_3 Vector;
typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator;
typedef typename Vertex::Facet Facet;
Vector normal = CGAL::NULL_VECTOR;
HV_circulator he = v.vertex_begin();
HV_circulator end = he;
CGAL_For_all(he,end)
{
if(!he->is_border())
{
Vector n = compute_facet_normal<Facet,Kernel>(*he->facet());
normal = normal + (n / std::sqrt(n*n));
}
}
return normal / std::sqrt(normal * normal);
}
#endif // _COMPUTE_NORMAL_

View File

@ -2,7 +2,7 @@
#define _GL_RENDER_
#include <CGAL/gl.h>
#include <CGAL/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
template <class Polyhedron>
void gl_render_facets(Polyhedron& polyhedron)
@ -28,7 +28,7 @@ void gl_render_facets(Polyhedron& polyhedron)
// If Flat shading: 1 normal per polygon
if (shading == GL_FLAT)
{
Vector n = compute_facet_normal<Facet,Kernel>(*f);
Vector n = CGAL::Polygon_mesh_processing::compute_facet_normal<Kernel>(*f);
::glNormal3d(n.x(),n.y(),n.z());
}
@ -40,7 +40,7 @@ void gl_render_facets(Polyhedron& polyhedron)
// If Gouraud shading: 1 normal per vertex
if (shading == GL_SMOOTH)
{
Vector n = compute_vertex_normal<typename Polyhedron::Vertex,Kernel>(*he->vertex());
Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal<Kernel>(*he->vertex());
::glNormal3d(n.x(),n.y(),n.z());
}

View File

@ -41,6 +41,8 @@
- `CGAL::self_intersect()`
- `CGAL::do_self_intersect()`
- `CGAL::orient_polygon_soup()`
- `CGAL::Polygon_mesh_processing::compute_facet_normal()`
- `CGAL::Polygon_mesh_processing::compute_vertex_normal()`
## Classes ##
- `CGAL::Polygon_soup_to_polyhedron_3`

View File

@ -19,10 +19,17 @@
// Author(s) : Pierre Alliez
#ifndef CGAL_INTERNAL_OPERATIONS_ON_POLYHEDRA_COMPUTE_NORMAL_H
#define CGAL_INTERNAL_OPERATIONS_ON_POLYHEDRA_COMPUTE_NORMAL_H
#ifndef CGAL_POLYGON_MESH_PROCESSING_COMPUTE_NORMAL_H
#define CGAL_POLYGON_MESH_PROCESSING_COMPUTE_NORMAL_H
template <class Facet, class Kernel>
namespace CGAL{
namespace Polygon_mesh_processing{
/// \ingroup PkgPolygonMeshProcessing
/// computes the outward unit vector normal to facet `f`.
/// `%Kernel::%FT` should be a model of `FieldWithSqrt`
template <class Kernel, class Facet>
typename Kernel::Vector_3 compute_facet_normal(const Facet& f)
{
typedef typename Kernel::Point_3 Point;
@ -42,12 +49,14 @@ typename Kernel::Vector_3 compute_facet_normal(const Facet& f)
return normal / std::sqrt(normal * normal);
}
template <class Vertex, class Kernel>
/// \ingroup PkgPolygonMeshProcessing
/// computes the unit normal at vertex `v` as the average of the normals of incident facets.
/// `%Kernel::%FT` should be a model of `FieldWithSqrt`
template <class Kernel, class Vertex>
typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v)
{
typedef typename Kernel::Vector_3 Vector;
typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator;
typedef typename Vertex::Facet Facet;
Vector normal = CGAL::NULL_VECTOR;
HV_circulator he = v.vertex_begin();
HV_circulator end = he;
@ -55,11 +64,13 @@ typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v)
{
if(!he->is_border())
{
Vector n = compute_facet_normal<Facet,Kernel>(*he->facet());
Vector n = compute_facet_normal<Kernel>(*he->facet());
normal = normal + (n / std::sqrt(n*n));
}
}
return normal / std::sqrt(normal * normal);
}
#endif // CGAL_INTERNAL_OPERATIONS_ON_POLYHEDRA_COMPUTE_NORMAL_H
} } // end of namespace CGAL::Polygon_mesh_processing
#endif // CGAL_POLYGON_MESH_PROCESSING_COMPUTE_NORMAL_H

View File

@ -23,7 +23,7 @@
#define CGAL_ORIENT_POLYHEDRON_3
#include <algorithm>
#include <CGAL/internal/Operations_on_polyhedra/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
namespace CGAL {
namespace internal {
@ -69,7 +69,7 @@ bool is_oriented(const Polyhedron& polyhedron) {
= std::min_element(polyhedron.vertices_begin(), polyhedron.vertices_end(), internal::Axis_compare<axis>());
typedef typename Polyhedron::Traits K;
const typename K::Vector_3& normal_v_min = compute_vertex_normal<typename Polyhedron::Vertex, K>(*v_min);
const typename K::Vector_3& normal_v_min = Polygon_mesh_processing::compute_vertex_normal<K>(*v_min);
CGAL_warning(normal_v_min[axis] != 0);
return normal_v_min[axis] < 0;

View File

@ -29,7 +29,7 @@
#include <CGAL/Constrained_triangulation_plus_2.h>
#include <CGAL/Triangulation_2_filtered_projection_traits_3.h>
#include <CGAL/internal/Operations_on_polyhedra/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <queue>
#include <vector>
@ -103,7 +103,7 @@ public:
{
Facet_handle fit = *fit_it;
typename Traits::Vector_3 normal =
compute_facet_normal<Facet,Traits>(*fit);
Polygon_mesh_processing::compute_facet_normal<Traits>(*fit);
P_traits cdt_traits(normal);
CDT cdt(cdt_traits);

View File

@ -10,7 +10,7 @@
#include <QApplication>
#include <CGAL/Monge_via_jet_fitting.h>
#include <CGAL/internal/Operations_on_polyhedra/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
class Polyhedron_demo_jet_fitting_plugin :
public QObject,
@ -99,7 +99,7 @@ void Polyhedron_demo_jet_fitting_plugin::on_actionEstimateCurvature_triggered()
// make monge form comply with vertex normal (to get correct
// orientation)
typedef Kernel::Vector_3 Vector;
Vector n = compute_vertex_normal<Polyhedron::Vertex,Kernel>(*v);
Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal<Kernel>(*v);
monge_form.comply_wrt_given_normal(n);
Vector umin = min_edge_len * monge_form.minimal_principal_direction();

View File

@ -77,13 +77,14 @@ public slots:
if(!eit_copy->is_border()) {
Polyhedron::Facet_handle fh1 = eit_copy->facet();
Polyhedron::Facet_handle fh2 = eit_copy->opposite()->facet();
typedef Polyhedron::Facet Facet;
if( fh1 != fh2 &&
!eit_copy->vertex()->is_bivalent() &&
!eit_copy->opposite()->vertex()->is_bivalent())
{
Kernel::Vector_3 v1 = compute_facet_normal<Facet, Kernel>(*fh1);
Kernel::Vector_3 v2 = compute_facet_normal<Facet, Kernel>(*fh2);
Kernel::Vector_3 v1 =
CGAL::Polygon_mesh_processing::compute_facet_normal<Kernel>(*fh1);
Kernel::Vector_3 v2 =
CGAL::Polygon_mesh_processing::compute_facet_normal<Kernel>(*fh2);
if(v1 * v2 > 0.99) {
std::cerr << "join\n";
// pMesh->is_valid(true);

View File

@ -51,7 +51,7 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item
positions[counter*3+2] = vb->point().z();
const Polyhedron::Traits::Vector_3& n =
compute_vertex_normal<Polyhedron::Vertex, Polyhedron::Traits>(*vb);
CGAL::Polygon_mesh_processing::compute_vertex_normal<Polyhedron::Traits>(*vb);
normals[counter*3] = n.x();
normals[counter*3+1] = n.y();

View File

@ -8,7 +8,7 @@
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/boost/graph/properties_Polyhedron_3.h>
#include <CGAL/internal/Operations_on_polyhedra/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <iostream>
#include <fstream>
@ -658,7 +658,7 @@ protected:
{
std::size_t id = vd->id();
const Polyhedron::Traits::Vector_3& n =
compute_vertex_normal<Polyhedron::Vertex, Polyhedron::Traits>(*vd);
CGAL::Polygon_mesh_processing::compute_vertex_normal<Polyhedron::Traits>(*vd);
normals[id*3] = n.x();
normals[id*3+1] = n.y();
normals[id*3+2] = n.z();

View File

@ -1,6 +1,6 @@
#include "Scene_points_with_normal_item.h"
#include "Polyhedron_type.h"
#include <CGAL/internal/Operations_on_polyhedra/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/write_off_points.h>
@ -53,7 +53,7 @@ Scene_points_with_normal_item::Scene_points_with_normal_item(const Polyhedron& i
for (v = input_mesh.vertices_begin(); v != input_mesh.vertices_end(); v++)
{
const Kernel::Point_3& p = v->point();
Kernel::Vector_3 n = compute_vertex_normal<Polyhedron::Vertex,Kernel>(*v);
Kernel::Vector_3 n = CGAL::Polygon_mesh_processing::compute_vertex_normal<Kernel>(*v);
m_points->push_back(UI_point(p,n));
}

View File

@ -244,7 +244,7 @@ public:
it != end; ++it)
{
const Kernel::Vector_3 n =
compute_facet_normal<Polyhedron::Facet,Kernel>(**it);
CGAL::Polygon_mesh_processing::compute_facet_normal<Kernel>(**it);
::glNormal3d(n.x(),n.y(),n.z());
Polyhedron::Halfedge_around_facet_circulator

View File

@ -2,7 +2,7 @@
#define _GL_RENDER_
#include <CGAL/gl.h>
#include <CGAL/internal/Operations_on_polyhedra/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
@ -26,7 +26,6 @@ void gl_render_facets(Polyhedron& polyhedron, const std::vector<QColor>& colors)
typedef typename Polyhedron::Traits Kernel;
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Polyhedron::Facet Facet;
typedef typename Polyhedron::Facet_iterator Facet_iterator;
typedef typename Polyhedron::Halfedge_around_facet_circulator HF_circulator;
@ -51,7 +50,7 @@ void gl_render_facets(Polyhedron& polyhedron, const std::vector<QColor>& colors)
// If Flat shading: 1 normal per polygon
if (shading == GL_FLAT)
{
Vector n = compute_facet_normal<Facet,Kernel>(*f);
Vector n = CGAL::Polygon_mesh_processing::compute_facet_normal<Kernel>(*f);
::glNormal3d(n.x(),n.y(),n.z());
}
@ -63,7 +62,7 @@ void gl_render_facets(Polyhedron& polyhedron, const std::vector<QColor>& colors)
// If Gouraud shading: 1 normal per vertex
if (shading == GL_SMOOTH)
{
Vector n = compute_vertex_normal<typename Polyhedron::Vertex,Kernel>(*he->vertex());
Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal<Kernel>(*he->vertex());
::glNormal3d(n.x(),n.y(),n.z());
}

View File

@ -1,44 +0,0 @@
#ifndef _COMPUTE_NORMAL_
#define _COMPUTE_NORMAL_
template <class Facet, class Kernel>
typename Kernel::Vector_3 compute_facet_normal(const Facet& f)
{
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Facet::Halfedge_around_facet_const_circulator HF_circulator;
Vector normal = CGAL::NULL_VECTOR;
HF_circulator he = f.facet_begin();
HF_circulator end = he;
CGAL_For_all(he,end)
{
const Point& prev = he->prev()->vertex()->point();
const Point& curr = he->vertex()->point();
const Point& next = he->next()->vertex()->point();
Vector n = CGAL::cross_product(next-curr,prev-curr);
normal = normal + (n / std::sqrt(n*n));
}
return normal / std::sqrt(normal * normal);
}
template <class Vertex, class Kernel>
typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v)
{
typedef typename Kernel::Vector_3 Vector;
typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator;
typedef typename Vertex::Facet Facet;
Vector normal = CGAL::NULL_VECTOR;
HV_circulator he = v.vertex_begin();
HV_circulator end = he;
CGAL_For_all(he,end)
{
if(!he->is_border())
{
Vector n = compute_facet_normal<Facet,Kernel>(*he->facet());
normal = normal + (n / std::sqrt(n*n));
}
}
return normal / std::sqrt(normal * normal);
}
#endif // _COMPUTE_NORMAL_

View File

@ -25,8 +25,7 @@
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/compute_average_spacing.h>
#include "compute_normal.h"
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <deque>
#include <cstdlib>
@ -183,7 +182,7 @@ int main(int argc, char * argv[])
for (v = input_mesh.vertices_begin(); v != input_mesh.vertices_end(); v++)
{
const Point& p = v->point();
Vector n = compute_vertex_normal<Polyhedron::Vertex,Kernel>(*v);
Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal<Kernel>(*v);
points.push_back(Point_with_normal(p,n));
}
}

View File

@ -1,44 +0,0 @@
#ifndef _COMPUTE_NORMAL_
#define _COMPUTE_NORMAL_
template <class Facet, class Kernel>
typename Kernel::Vector_3 compute_facet_normal(const Facet& f)
{
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Facet::Halfedge_around_facet_const_circulator HF_circulator;
Vector normal = CGAL::NULL_VECTOR;
HF_circulator he = f.facet_begin();
HF_circulator end = he;
CGAL_For_all(he,end)
{
const Point& prev = he->prev()->vertex()->point();
const Point& curr = he->vertex()->point();
const Point& next = he->next()->vertex()->point();
Vector n = CGAL::cross_product(next-curr,prev-curr);
normal = normal + (n / std::sqrt(n*n));
}
return normal / std::sqrt(normal * normal);
}
template <class Vertex, class Kernel>
typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v)
{
typedef typename Kernel::Vector_3 Vector;
typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator;
typedef typename Vertex::Facet Facet;
Vector normal = CGAL::NULL_VECTOR;
HV_circulator he = v.vertex_begin();
HV_circulator end = he;
CGAL_For_all(he,end)
{
if(!he->is_border())
{
Vector n = compute_facet_normal<Facet,Kernel>(*he->facet());
normal = normal + (n / std::sqrt(n*n));
}
}
return normal / std::sqrt(normal * normal);
}
#endif // _COMPUTE_NORMAL_

View File

@ -23,8 +23,7 @@
#include <CGAL/property_map.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/compute_average_spacing.h>
#include "compute_normal.h"
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <deque>
#include <cstdlib>
@ -128,7 +127,7 @@ int main(int argc, char * argv[])
for (v = input_mesh.vertices_begin(); v != input_mesh.vertices_end(); v++)
{
const Point& p = v->point();
Vector n = compute_vertex_normal<Polyhedron::Vertex,Kernel>(*v);
Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal<Kernel>(*v);
points.push_back(Point_with_normal(p,n));
}
}