~ubuntu-branches/ubuntu/saucy/python-demgengeo/saucy

« back to all changes in this revision

Viewing changes to geometry/Sphere.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 "Sphere.h"
 
14
 
 
15
// --- System includes ---
 
16
#include <cmath>
 
17
 
 
18
using std::sqrt;
 
19
 
 
20
double Sphere::NearZero=1e-8;
 
21
int Sphere::s_output_style=0;
 
22
unsigned int Sphere::s_current_id=0;
 
23
 
 
24
/*!
 
25
  construct "invalid" Sphere
 
26
*/
 
27
Sphere::Sphere()
 
28
{
 
29
  m_valid=false;
 
30
  m_id=0;
 
31
  m_tag=0;
 
32
}
 
33
 
 
34
/*!
 
35
  construct valid Sphere
 
36
 
 
37
  \param center the center of the circle
 
38
  \param rad the radius
 
39
*/
 
40
Sphere::Sphere(const Vector3& center,double rad)
 
41
{
 
42
  m_center=center;
 
43
  m_rad=rad;
 
44
  m_valid=true;
 
45
  m_id=Sphere::s_current_id;
 
46
  Sphere::s_current_id++;
 
47
  m_tag=0;
 
48
}
 
49
 
 
50
/*!
 
51
  copy constructor
 
52
 
 
53
  \param S the original
 
54
*/
 
55
Sphere::Sphere(const Sphere& S)
 
56
{
 
57
  m_center=S.m_center;
 
58
  m_rad=S.m_rad;
 
59
  m_valid=S.m_valid;
 
60
  m_id=S.m_id;
 
61
  m_tag=S.m_tag; 
 
62
}
 
63
 
 
64
/*!
 
65
  get distance between given point and the surface of the Sphere
 
66
 
 
67
  \param P the point
 
68
*/
 
69
double  Sphere::getDist(const Vector3& P) const
 
70
{
 
71
  return (P-m_center).norm()-m_rad;
 
72
}
 
73
 
 
74
 
 
75
/*!
 
76
  Set id of sphere. If higher than current_id, increase current_id
 
77
  accordingly
 
78
 
 
79
  \param i the new id of the sphere
 
80
*/
 
81
void Sphere::setId(int i)
 
82
{
 
83
  m_id=i;
 
84
  if(i>s_current_id) {
 
85
    s_current_id=i;
 
86
  }
 
87
}
 
88
 
 
89
/*!
 
90
  Set output style
 
91
 
 
92
  \param style the output style: 0=Debug, 1=.geo
 
93
*/
 
94
void Sphere::SetOutputStyle(int style)
 
95
{
 
96
  Sphere::s_output_style=style;
 
97
}
 
98
 
 
99
ostream& operator << (ostream& ost, const Sphere& S)
 
100
{
 
101
  if(Sphere::s_output_style==0){
 
102
    if(S.m_valid){
 
103
      ost << S.m_center << " | " << S.m_rad << " |  " << S.m_id; 
 
104
    } else {
 
105
      ost << "invalid Sphere";
 
106
    }
 
107
  } else if (Sphere::s_output_style==1){
 
108
    if(S.m_valid){
 
109
      ost << S.m_center << " "  << S.m_rad << " " << S.m_id << " " << S.m_tag;
 
110
    } 
 
111
  }
 
112
  
 
113
  return ost;
 
114
}