//===========================================================================
// GoTools - SINTEF Geometry Tools version 1.0
//
// GoTools module: Implicitization, version 0.9
//
// Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
//
// This program is free software; you can redistribute it and/or          
// modify it under the terms of the GNU General Public License            
// as published by the Free Software Foundation version 2 of the License. 
//
// This program is distributed in the hope that it will be useful,        
// but WITHOUT ANY WARRANTY; without even the implied warranty of         
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
// GNU General Public License for more details.                           
//
// You should have received a copy of the GNU General Public License      
// along with this program; if not, write to the Free Software            
// Foundation, Inc.,                                                      
// 59 Temple Place - Suite 330,                                           
// Boston, MA  02111-1307, USA.                                           
//
// Contact information: e-mail: tor.dokken@sintef.no                      
// SINTEF ICT, Department of Applied Mathematics,                         
// P.O. Box 124 Blindern,                                                 
// 0314 Oslo, Norway.                                                     
//
// Other licenses are also available for this software, notably licenses
// for:
// - Building commercial software.                                        
// - Building software whose source code you wish to keep private.        
//===========================================================================
#ifndef _BERNSTEINUTILS_H
#define _BERNSTEINUTILS_H


#include "BernsteinPoly.h"
#include "BernsteinMulti.h"
#include "Array.h"
#include <vector>


namespace Go {
///\addtogroup implicitization
///\{



class SplineCurve;
class SplineSurface;


/**
 * Takes a segment (defined as having numCoefs() == order() and an
 * order()-regular knot vector) and returns a bernstein polynomial
 * equal to the curve's coordinate number dd. Allowed values for dd
 * are in [0, dimension()-1] for nonrational segments, and in [0,
 * dimension()] for rational (NURBS) segments. The polynomials
 * returned in the rational case are the weighted coordinate functions
 * for dd in [0, dimension()-1] and to the weight polynomial for dd
 * equal to dimension().
 */
void spline_to_bernstein(const SplineCurve& seg, int dd,
			 BernsteinPoly& bp);

/**
 * Converts the dd-component of a surface patch on SplineSurface form to a
 * BernsteinMulti
 */
void spline_to_bernstein(const SplineSurface& pat, int dd,
			 BernsteinMulti& bm);

/// Converts a curve segment on SplineCurve form to a vector of
/// BernsteinPolys
void spline_to_bernstein(const SplineCurve& seg,
			 std::vector<BernsteinPoly>& seg_bp);


/// Converts a surface patch on SplineSurface form to a vector of
/// BernsteinMultis
void spline_to_bernstein(const SplineSurface& pat,
			 std::vector<BernsteinMulti>& pat_bm);


/**
 * Converts a curve segment on SplineCurve form to an Array of Dim
 * BernsteinPolys
 */
template <int Dim>
void spline_to_bernstein(const SplineCurve& seg,
			 Array<BernsteinPoly, Dim>& curve_bp)
{
    for (int i = 0; i < Dim; ++i)
	spline_to_bernstein(seg, i, curve_bp[i]);
    return;
}


/**
 * Converts a surface patch on SplineSurface form to an Array of Dim
 * BernsteinMultis
 */
template <int Dim>
void spline_to_bernstein(const SplineSurface& pat,
			 Array<BernsteinMulti, Dim>& surf_bm)
{
    for (int i = 0; i < Dim; ++i)
	spline_to_bernstein(pat, i, surf_bm[i]);
    return;
}


///\}
} // namespace Go


#endif // _BERNSTEINUTILS_H


