using namespace gismo;
int main(
int argc,
char *argv[])
{
bool save = false;
real_t lambda = 1e-07;
real_t threshold = 1e-02;
real_t tolerance = 1e-02;
real_t refPercent = 0.1;
std::string fn = "fitting/deepdrawingC.xml";
gsCmdLine cmd(
"Fit parametrized sample data with a surface patch. Expected input file is an XML "
"file containing two matrices (<Matrix>), with \nMatrix id 0 : contains a 2 x N matrix. "
"Every column represents a (u,v) parametric coordinate\nMatrix id 1 : contains a "
"3 x N matrix. Every column represents a point (x,y,z) in space.");
cmd.addSwitch("save", "Save result in XML format", save);
cmd.addInt("c", "parcor", "Steps of parameter correction", maxPcIter);
cmd.addInt("i", "iter", "number of iterations", iter);
cmd.addInt("x", "deg_x", "degree in x direction", deg_x);
cmd.addInt("y", "deg_y", "degree in y direction", deg_y);
cmd.addReal("s", "lambda", "smoothing coefficient", lambda);
cmd.addReal("t", "threshold", "error threshold (special valule -1)", threshold);
cmd.addReal("p", "refPercent", "percentage of points to refine in each iteration", refPercent);
cmd.addInt("q", "extension", "extension size", extension);
cmd.addInt("r", "urefine", "initial uniform refinement steps", numURef);
cmd.addReal("e", "tolerance", "error tolerance (desired upper bound for pointwise error)", tolerance);
cmd.addString("d", "data", "Input sample data", fn);
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
if (deg_x < 1)
{ gsInfo << "Degree x must be positive.\n"; return 0;}
if (deg_y < 1)
{ gsInfo << "Degree y must be positive.\n"; return 0;}
if (extension < 0)
{ gsInfo << "Extension must be non negative.\n"; return 0;}
if ( tolerance < 0 )
{
gsInfo << "Error tolerance cannot be negative, setting it to default value.\n";
tolerance = 1e-02;
}
if (threshold > 0 && threshold > tolerance )
{
gsInfo << "Refinement threshold is over tolerance, setting it the same as tolerance.\n";
threshold = tolerance;
}
GISMO_ASSERT( uv.cols() == xyz.cols() && uv.rows() == 2 && xyz.rows() == 3,
"Wrong input");
real_t u_min = uv.row(0).minCoeff(),
u_max = uv.row(0).maxCoeff(),
v_min = uv.row(1).minCoeff(),
v_max = uv.row(1).maxCoeff();
T_tbasis.uniformRefine( (1<<numURef)-1 );
std::vector<unsigned> ext;
ext.push_back(extension);
ext.push_back(extension);
const std::vector<real_t> & errors = ref.pointWiseErrors();
gsInfo<<"Fitting "<< xyz.cols() <<" samples.\n";
gsInfo<<"----------------\n";
gsInfo<<"Cell extension : "<< ext[0]<<" "<<ext[1]<<".\n";
if ( threshold >= 0.0 )
gsInfo<<"Ref. threshold : "<< threshold<<".\n";
else
gsInfo<<"Cell refinement : "<< 100*refPercent<<"%%.\n";
gsInfo<<"Error tolerance : "<< tolerance<<".\n";
gsInfo<<"Smoothing parameter: "<< lambda<<".\n";
for(int i = 0; i <= iter; i++)
{
gsInfo<<"----------------\n";
gsInfo<<"Iteration "<<i<<".."<<"\n";
ref.nextIteration(tolerance, threshold, maxPcIter);
gsInfo<<"Fitting time: "<< time <<"\n";
gsInfo<<
"Fitted with "<< ref.result()->
basis() <<
"\n";
gsInfo<<"Min distance : "<< ref.minPointError() <<" / ";
gsInfo<<"Max distance : "<< ref.maxPointError() <<"\n";
gsInfo<<
"Points below tolerance: "<< 100.0 * ref.numPointsBelow(tolerance)/errors.
size()<<
"%.\n";
if ( ref.maxPointError() < tolerance )
{
gsInfo<<"Error tolerance achieved after "<<i<<" iterations.\n";
break;
}
}
gsInfo<<"----------------\n";
if ( save )
{
gsInfo<<"Done. Writing solution to file fitting_out.xml\n";
fd << *ref.result() ;
fd.dump("fitting_out");
}
else
gsInfo << "Done. No output created, re-run with --save to get a xml "
"file containing the solution.\n";
return 0;
}