// Reconstruction - A tool for building cad models from meshes
// Copyright (C) 2010-2026 Eric Bechet, Borhen Louhichi
//
// See the LICENSE file for license information and contributions.
// Please report all bugs and problems to <bechet@cadxfem.org>.


#include "RecIncludes.h"
#include <vector>


#ifndef __OUTIL_H
#define __OUTIL_H


///********************************************************************************
/// Calculate the Thin Plate Surface
///********************************************************************************
class Tps
{
private:
  double tps_base_func(double r);

public:
  //Tps();

  std::vector<std::vector<gp_Pnt> > calc_tps(std::vector<gp_Pnt > control_points, int GRID_W, int GRID_H, double Umin, double Umax, double Vmin, double Vmax);
  std::vector<std::vector<gp_Pnt> > calc_tps_Revol(std::vector<gp_Pnt > control_points, int GRID_W, int GRID_H, double Umin, double Umax, double Vmin, double Vmax, double Rayon);


};

///*********************************************************************************
/// Calculate the Average Plane
///*********************************************************************************
class AveragePlane
{
private:

  Handle_TColgp_HArray1OfPnt myPts;
  double myUmax;
  double myVmax;
  double myVmin;
  double myUmin;
  Handle_Geom_Plane myPlane;
  double myTol;
  Handle_Geom_Line myLine;
  gp_Vec myOX;
  gp_Vec myOY;
  gp_Pnt myG;
  int myNbBoundPoints;

public:

  AveragePlane(std::vector<gp_Pnt> & Pts, int NbBoundPoints, double Tol, int POption=2, int NOption=1);
  gp_Vec DefPlan(int NOption);
  void BasePlan(gp_Vec& OZ);

  void MinMaxBox(double& Umin, double& Umax, double& Vmin, double& Vmax);
  Handle(Geom_Plane) Plane();
  Handle(Geom_Line) Line();
  bool IsPlane();
  bool IsLine();


};




/// Thibaud Mouton 2010
class Bucket
{
private:
  gp_Pnt _min;
  gp_Pnt _max;
  int _nx;
  int _ny;
  int _nz;
  int _maxn;;
  double _ref_size;
  std::vector<std::vector<gp_Pnt *> > _bucket;
  std::vector<int> _flag;
  int _request_id;
public:
  Bucket(gp_Pnt min, gp_Pnt max, double enlarge, int max_size);
  void get_coord(gp_Pnt *pt, int &x, int &y, int &z);
  int get_index(int x, int y, int z);
  gp_Pnt *get_closest_in_bucket(int index, gp_Pnt *pt, double *dist);
  void add_point(gp_Pnt *pt);
  gp_Pnt *get_closest(gp_Pnt *pt);
  int contain(gp_Pnt *pt);
  void dump();
};





#endif //__OUTIL_H
