diff --git a/Packages/Nef_3/include/CGAL/Nef_3/Normalizing.h b/Packages/Nef_3/include/CGAL/Nef_3/Normalizing.h new file mode 100644 index 00000000000..f2ac7914ee9 --- /dev/null +++ b/Packages/Nef_3/include/CGAL/Nef_3/Normalizing.h @@ -0,0 +1,130 @@ +// ============================================================================ +// +// Copyright (c) 1997-2002 The CGAL Consortium +// +// This software and related docuhmentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------------- +// +// release : $CGAL_Revision: $ +// release_date : $CGAL_Date: $ +// +// file : include/CGAL/Nef_3/SNC_constructor.h +// package : Nef_3 +// chapter : 3D-Nef Polyhedra +// +// revision : $Revision$ +// revision_date : $Date$ +// +// author(s) : Peter Hachenberger +// maintainer : Peter Hachenberger +// coordinator : MPI Saarbruecken +// +// helper functions for normalizing Plane_3, etc. +// ============================================================================ +#ifndef CGAL_NORMALIZING_H +#define CGAL_NORMALIZING_H + +#include +#undef _DEBUG +#define _DEBUG 307 +#include + +template +CGAL::Point_3 simplified(CGAL::Point_3& p) +{ + int deg = (p.hx().degree() > p.hy().degree() ? p.hx().degree() : p.hy().degree()); + deg = (p.hz().degree() > deg ? p.hz().degree() : deg); + return CGAL::Point_3(p.hx()(deg),p.hy()(deg),p.hz()(deg),p.hw()[0]); +} + +template +CGAL::Point_3 normalized(CGAL::Point_3& p) +{ + typedef typename R::RT RT; + + RT g = p.hw(); + g = (p.hx() == 0 ? g : gcd(g,p.hx())); + g = (p.hy() == 0 ? g : gcd(g,p.hy())); + g = (p.hz() == 0 ? g : gcd(g,p.hz())); + + RT x = p.hx()/g; + RT y = p.hy()/g; + RT z = p.hz()/g; + RT w = p.hw()/g; + + return CGAL::Point_3(x,y,z,w); +} + +template +CGAL::Plane_3 normalized(CGAL::Plane_3& h) +{ + + CGAL_nef3_assertion(!(h.a()==0 && h.b()==0 && h.c()==0 && h.d()==0)); + + typedef typename R::RT RT; + + RT x = (h.a()==0) ? ((h.b()==0) ? ((h.c()==0) ? ((h.d()==0) ? 1: h.d()): h.c()): h.b()): h.a(); + + TRACE("gcd... i"<<' '); + + if(h.b() != 0) + x = gcd(x,h.b()); + TRACE(x<<' '); + if(h.c() != 0) + x = gcd(x,h.c()); + TRACE(x<<' '); + if(h.d() !=0) + x = gcd(x,h.d()); + TRACEN(x); + + x = x.abs(); + + RT pa = h.a()/x; + RT pb = h.b()/x; + RT pc = h.c()/x; + RT pd = h.d()/x; + + TRACEN(" after normalizing " << CGAL::Plane_3(pa,pb,pc,pd)); + return CGAL::Plane_3(pa,pb,pc,pd); +} + +template +CGAL::Plane_3 normalized_old(CGAL::Plane_3& h) +{ + // TRACEN(" before normalizing "<(a/x,b/x,c/x,d/x)); + + + RT pa = a/x; + RT pb = b/x; + RT pc = c/x; + RT pd = h.d()/x; + + return CGAL::Plane_3(pa,pb,pc,pd); +} + +#endif // CGAL_NORMALIZING_H