25 |
#define DIFFERENCE_HPP |
#define DIFFERENCE_HPP |
26 |
|
|
27 |
#include <Object.hpp> |
#include <Object.hpp> |
28 |
|
#include <list> |
29 |
|
|
30 |
/*! \class Difference |
/*! \class Difference |
31 |
|
|
32 |
This is the class which defines a Virtual Reality set operation: the |
This is the class which defines a Virtual Reality set operation: the |
38 |
: public Shape |
: public Shape |
39 |
{ |
{ |
40 |
private: |
private: |
41 |
|
typedef std::list<ReferenceCounting<Object> > ObjectList; |
42 |
|
|
43 |
|
public: |
44 |
|
typedef std::list<ReferenceCounting<Object> >::iterator iterator; |
45 |
|
typedef std::list<ReferenceCounting<Object> >::const_iterator const_iterator; |
46 |
|
|
47 |
|
private: |
48 |
//! The list of shapes contained in the difference. |
//! The list of shapes contained in the difference. |
49 |
std::vector<ReferenceCounting<Shape> > __shape; |
ObjectList __objects; |
50 |
|
|
51 |
//! Returns \p true if the point \a p is inside the Difference. |
//! Returns \p true if the point \a p is inside the Difference. |
52 |
inline const bool inShape (const TinyVector<3>& p) const; |
inline const bool inShape (const TinyVector<3>& p) const; |
56 |
|
|
57 |
public: |
public: |
58 |
|
|
59 |
//! Adds the shape \a O inside the Difference. |
const const_iterator begin() const |
60 |
inline void AddObject(const Object& O); |
{ |
61 |
|
return __objects.begin(); |
62 |
|
} |
63 |
|
|
64 |
//! Adds the Shape \a S inside the Difference. |
iterator begin() |
65 |
inline void AddObject(ReferenceCounting<Shape> s); |
{ |
66 |
|
return __objects.begin(); |
67 |
|
} |
68 |
|
|
69 |
//! Returns the Number of Objects contained in the Difference. |
|
70 |
inline const size_t NbObjects() const |
const const_iterator end() const |
71 |
{ |
{ |
72 |
return __shape.size(); |
return __objects.end(); |
73 |
} |
} |
74 |
|
|
75 |
//! Default constructor. |
iterator end() |
76 |
Difference(); |
{ |
77 |
|
return __objects.end(); |
78 |
|
} |
79 |
|
|
80 |
//! Constructs and Difference using an Object \a O. |
//! Adds the shape \a O inside the Difference. |
81 |
Difference(const Object& O); |
inline void push_back(const ReferenceCounting<Object>& o); |
82 |
|
|
83 |
|
//! Default constructor. |
84 |
|
Difference() |
85 |
|
: Shape(Shape::difference) |
86 |
|
{ |
87 |
|
; |
88 |
|
} |
89 |
|
|
90 |
//! Copy constructor. |
//! Copy constructor. |
91 |
Difference(const Difference& U); |
Difference(const Difference& D) |
92 |
|
: Shape(D), |
93 |
|
__objects(D.__objects) |
94 |
|
{ |
95 |
|
; |
96 |
|
} |
97 |
|
|
98 |
//! Destructor. |
//! Destructor. |
99 |
~Difference() |
~Difference() |
104 |
}; |
}; |
105 |
|
|
106 |
//! Adds the Object \a O inside the Difference. |
//! Adds the Object \a O inside the Difference. |
107 |
void Difference::AddObject(const Object& O) |
void Difference::push_back(const ReferenceCounting<Object>& o) |
|
{ |
|
|
__shape.push_back(O.shape()); |
|
|
} |
|
|
|
|
|
//! Adds the Shape \a S inside the Difference. |
|
|
void Difference::AddObject(ReferenceCounting<Shape> S) |
|
108 |
{ |
{ |
109 |
__shape.push_back(S); |
__objects.push_back(o); |
110 |
} |
} |
111 |
|
|
112 |
//! Returns \p true if the point \a p is inside the Difference. |
//! Returns \p true if the point \a p is inside the Difference. |
113 |
inline const bool Difference::inShape (const TinyVector<3>& p) const |
inline const bool Difference::inShape (const TinyVector<3>& p) const |
114 |
{ |
{ |
115 |
bool inside = (*__shape[0]).inside(p); |
assert(__objects.begin() != __objects.end()); |
116 |
|
|
117 |
|
const_iterator i = __objects.begin(); |
118 |
|
|
119 |
|
if (not((*(*i)).inside(p))) { |
120 |
|
return false; |
121 |
|
} |
122 |
|
++i; |
123 |
|
|
124 |
if (inside) { |
for (; i != __objects.end(); i++) { |
125 |
for (size_t i=1; i<NbObjects(); i++) { |
if((*(*i)).inside(p)) { |
126 |
if(((*__shape[i]).inside(p))) { |
return false; |
|
return false; |
|
|
} |
|
127 |
} |
} |
128 |
} |
} |
129 |
|
|
130 |
return inside; |
return true; |
131 |
} |
} |
132 |
|
|
133 |
#endif // DIFFERENCE_HPP |
#endif // DIFFERENCE_HPP |