~ubuntu-branches/ubuntu/quantal/python-demgengeo/quantal

« back to all changes in this revision

Viewing changes to sphere_fitting/Sphere2DFitter.cc

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2011-11-18 21:47:18 UTC
  • Revision ID: package-import@ubuntu.com-20111118214718-4ysqm3dhpqwdd7gd
Tags: upstream-0.99~bzr106
ImportĀ upstreamĀ versionĀ 0.99~bzr106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////
 
2
//                                                         //
 
3
// Copyright (c) 2007-2011 by The University of Queensland //
 
4
// Earth Systems Science Computational Centre (ESSCC)      //
 
5
// http://www.uq.edu.au/esscc                              //
 
6
//                                                         //
 
7
// Primary Business: Brisbane, Queensland, Australia       //
 
8
// Licensed under the Open Software License version 3.0    //
 
9
// http://www.opensource.org/licenses/osl-3.0.php          //
 
10
//                                                         //
 
11
/////////////////////////////////////////////////////////////
 
12
 
 
13
#include "Sphere2DFitter.h"
 
14
 
 
15
// --- project includes ---
 
16
#include "nvector.h"
 
17
#include "nfunction.h"
 
18
#include "simplex.h"
 
19
#include "fit_2d_sphere.h"
 
20
 
 
21
// --- IO includes ---
 
22
#include <iostream>
 
23
 
 
24
Sphere FitSphere2D(const AGeometricObject* GO1,
 
25
                   const AGeometricObject* GO2,
 
26
                   const AGeometricObject* GO3,
 
27
                   const Vector3& spos,
 
28
                   int max_iter,double prec)
 
29
{
 
30
  Sphere res;
 
31
 
 
32
  simplex_method<double,2> *simplex;
 
33
  nvector<double,2> start,sol;
 
34
  fit_2d_sphere_fn* sfn;
 
35
 
 
36
  // set initial position to barycenter of input spheres
 
37
  start[0]=spos.x();
 
38
  start[1]=spos.y();
 
39
 
 
40
  // set fitting function
 
41
  sfn=new fit_2d_sphere_fn(GO1,GO2,GO3);
 
42
  
 
43
  // solve for center 
 
44
  simplex=new simplex_method<double,2>(sfn);
 
45
  sol=simplex->solve(prec,start,max_iter);
 
46
 
 
47
  // calc radius : min radius relative to 3 spheres - tol
 
48
  Vector3 center=Vector3(sol[0],sol[1],0.0);
 
49
  double r1=GO1->getDist(center);
 
50
  double r2=GO2->getDist(center);
 
51
  double r3=GO3->getDist(center);
 
52
 
 
53
  double r=(r1<r2) ? r1 : r2;
 
54
  r= (r < r3) ? r : r3;
 
55
 
 
56
  res=Sphere(center,r-0.1*prec);
 
57
 
 
58
  // clean up
 
59
  delete simplex;
 
60
  delete sfn;
 
61
 
 
62
  return res;
 
63
}
 
64