~esys-p-dev/esys-particle/gengeo

90 by Dion Weatherley
Purely cosmetic change of ComplementVol to DifferenceVol.
1
/////////////////////////////////////////////////////////////
2
//                                                         //
124 by Vince Boros
Copyright, Centre name, Centre address updates
3
// Copyright (c) 2007-2014 by The University of Queensland //
4
// Centre for Geoscience Computing                         //
5
// http://earth.uq.edu.au/centre-geoscience-computing      //
90 by Dion Weatherley
Purely cosmetic change of ComplementVol to DifferenceVol.
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 "DifferenceVol.h"
14
15
//--- 
16
#include <cmath>
17
#include <cstdlib>
18
19
using std::cos;
20
using std::sin; 
21
22
// --- STL includes ---
23
#include <utility>
24
25
using std::make_pair;
26
27
DifferenceVol::DifferenceVol()
28
{
133 by Vince Boros
``cout'' replaces ``cerr'' as a temporary measure until someone has time to
29
  std::cout << "WARNING: DifferenceVol is an experimental feature and may not always work as expected. For details see doc/CSG.readme" << std::endl;
90 by Dion Weatherley
Purely cosmetic change of ComplementVol to DifferenceVol.
30
  m_vol1 = NULL; 
31
  m_vol2 = NULL; 
32
}
33
34
DifferenceVol::DifferenceVol(AVolume3D& v1, AVolume3D& v2)
35
{
133 by Vince Boros
``cout'' replaces ``cerr'' as a temporary measure until someone has time to
36
  std::cout << "WARNING: DifferenceVol is an experimental feature and may not always work as expected. For details see doc/CSG.readme" << std::endl;
90 by Dion Weatherley
Purely cosmetic change of ComplementVol to DifferenceVol.
37
  m_vol1 = &v1;
38
  m_vol2 = &v2;
39
40
//  std::cout << m_vol1 << std::endl;
41
//  std::cout << m_vol2 << std::endl;
42
}
43
44
pair<Vector3,Vector3> DifferenceVol::getBoundingBox()
45
{
46
  return m_vol1->getBoundingBox();
47
}
48
49
Vector3 DifferenceVol::getAPoint(int ivol) const
50
{
51
  Vector3 aPoint;
52
  bool found = false;
53
54
  while (!(found)) {
55
     aPoint = m_vol1->getAPoint(ivol);
56
     found = !(m_vol2->isIn(aPoint));
57
  }
58
59
  return aPoint;
60
}
61
62
const map<double,const AGeometricObject*> DifferenceVol::getClosestObjects(const Vector3& P,int ival) const
63
{
64
  map<double,const AGeometricObject*> res;
65
  map<double,const AGeometricObject*> res2;
66
67
  res = m_vol1->getClosestObjects(P,ival);
68
  res2 = m_vol2->getClosestObjects(P,ival);
69
70
  res.insert(res2.begin(), res2.end());
71
72
  return res;  
73
}
74
75
bool DifferenceVol::isIn(const Vector3& P) const
76
{
77
  bool res = false;
78
79
  if ((m_vol1->isIn(P)) && (!(m_vol2->isIn(P)))) {
80
    res = true;
81
  }
82
83
  return res;
84
}
85
86
bool DifferenceVol::isIn(const Sphere& S)
87
{
88
  return m_vol1->isIn(S) && m_vol2->isFullyOutside(S);
89
}
90
91
/*!
92
  Check if a sphere is fully outside the volume. Tests if the sphere 
93
  is fully outside volume1 or fully inside volume2.
94
95
  \param S the sphere
96
*/
97
bool DifferenceVol::isFullyOutside(const Sphere& S)
98
{
99
  return m_vol2->isIn(S) || m_vol1->isFullyOutside(S);
100
}
101
102
ostream& operator << (ostream& ost,const DifferenceVol& T)
103
{
104
   return ost;
105
}