// Gnurbs - A curve and surface library
// Copyright (C) 2008-2026 Eric Bechet
//
// See the LICENSE file for contributions and license information.
// Please report all bugs and problems to <bechet@cadxfem.org>.
//

#include <iostream>
#include <vector>
#include <fstream>

#include "nvtkdisplay.h"
#include "nbspline.h"
#include "nbsplinesurface.h"

#include "linear_algebra.h"

// function to init profiles
void init_profiles(std::vector<nbspline> &profiles);

// fonction that compute the final surface
void skin(std::vector<nbspline> &profiles,nbsplinesurface &surf)
{

}




int main(void)
{
  data_container data;
  nvtkdisplay display;

  std::vector<nbspline> profiles(10);
  for (int n=0;n<profiles.size();++n) profiles[n].reset(6+2*n,2+n);
  nbsplinesurface skin_surface; // skin of the profiles

  init_profiles(profiles);


  // display the profiles
  for (int i=0;i<profiles.size();++i) profiles[i].Display(data);
  skin(profiles,skin_surface); // function call to compute the skin surface

  skin_surface.Display(data);
  display.init_data(data);
  display.display();
  return 0;
}

void init_profiles(std::vector<nbspline> &profiles)
{
  
  for (int n=0;n<profiles.size();++n)
  {
    int degree=profiles[n].degree();
    int nCP=profiles[n].nb_CP();
  // profil in the  x-y plane, basepoint = frame origin
  //nodal sequence
    for (int i=0;i<degree+1;++i)
    {
      profiles[n].u(i)=0;
      profiles[n].u(i+nCP)=nCP-degree;
    }
    for (int i=1;i<nCP-degree;++i)
    {
      profiles[n].u(i+degree)=i;
    }

    double c=10.; //chord
    double t=0.15; //thickness
    // control points
    for (int i=0;i<nCP/2;++i)
    {
      double x=c*(nCP/2-i)/(nCP/2);
      double y=(t*c/0.2)*(0.2969*sqrt(x/c)-0.1260*(x/c)-0.3516*(x*x/(c*c))+0.2843*(x*x*x/(c*c*c))-0.1015*(x*x*x*x/(c*c*c*c)));
      double z= (c*n)/(profiles.size()-1);    
      profiles[n].CP(i)=npoint(x,y+z*z/c,z,1.0);
      profiles[n].CP(nCP-1-i)=npoint(x,-y+z*z/c,z,1.0);
    }
  }
}
