39 |
class InsideListExpression |
class InsideListExpression |
40 |
: public Expression |
: public Expression |
41 |
{ |
{ |
42 |
|
protected: |
43 |
|
struct __ltv |
44 |
|
{ |
45 |
|
bool operator()(const TinyVector<3,real_t>& s1, const TinyVector<3,real_t>& s2) const |
46 |
|
{ |
47 |
|
if (s1[0]<s2[0]) |
48 |
|
return true; |
49 |
|
if (s1[0]==s2[0]) { |
50 |
|
if (s1[1]<s2[1]) |
51 |
|
return true; |
52 |
|
if (s1[1]==s2[1]) |
53 |
|
if (s1[2]<s2[2]) |
54 |
|
return true; |
55 |
|
} |
56 |
|
return false; |
57 |
|
} |
58 |
|
}; |
59 |
|
|
60 |
|
typedef std::map<TinyVector<3, real_t>, size_t, __ltv> ReferenceList; |
61 |
|
|
62 |
public: |
public: |
63 |
enum NodeType { |
enum NodeType { |
64 |
NodeAnd, |
NodeAnd, |
71 |
const NodeType __type; /**< node type */ |
const NodeType __type; /**< node type */ |
72 |
|
|
73 |
public: |
public: |
74 |
|
|
75 |
/** |
/** |
76 |
* Evaluates the domain shape |
* overloading of Expression::execute() |
77 |
|
* |
78 |
|
*/ |
79 |
|
void execute() |
80 |
|
{ |
81 |
|
this->subExecute(); |
82 |
|
this->checkReferencesUniqueness(); |
83 |
|
} |
84 |
|
|
85 |
|
/** |
86 |
|
* helps to break the execution into parts |
87 |
|
* |
88 |
|
*/ |
89 |
|
virtual void subExecute() = 0; |
90 |
|
|
91 |
|
/** |
92 |
|
* Checks that all given references are given only once |
93 |
|
* |
94 |
|
*/ |
95 |
|
void checkReferencesUniqueness() |
96 |
|
{ |
97 |
|
InsideListExpression::ReferenceList references; |
98 |
|
this->addReferences(references); |
99 |
|
for (ReferenceList::const_iterator i = references.begin(); |
100 |
|
i != references.end(); ++i) { |
101 |
|
if ((*i).second > 1) { |
102 |
|
fferr(0) << "POV-Ray reference " << (*i).first << " is used " |
103 |
|
<< (*i).second << " times in the domain definition\n"; |
104 |
|
fferr(0) << "only 1 is allowed\n"; |
105 |
|
std::exit(1); |
106 |
|
} |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
/** |
111 |
|
* Fills a list which counts POV-Ray references |
112 |
* |
* |
113 |
|
* @param references the references and their number of instance |
114 |
|
* |
115 |
|
*/ |
116 |
|
virtual void |
117 |
|
addReferences(InsideListExpression::ReferenceList& references) = 0; |
118 |
|
|
119 |
|
/** |
120 |
|
* Evaluates the domain shape |
121 |
* |
* |
122 |
* @return a shape. |
* @return a shape. |
123 |
*/ |
*/ |
187 |
ReferenceCounting<Object> objects(const Scene& S); |
ReferenceCounting<Object> objects(const Scene& S); |
188 |
|
|
189 |
/** |
/** |
190 |
* Overloading of Expression::execute() |
* Overloading of InsideListeExpression::subExecute() |
191 |
* |
* |
192 |
*/ |
*/ |
193 |
void execute() |
void subExecute() |
194 |
|
{ |
195 |
|
(*__node1).subExecute(); |
196 |
|
(*__node2).subExecute(); |
197 |
|
} |
198 |
|
|
199 |
|
/** |
200 |
|
* Fills a list which counts POV-Ray references |
201 |
|
* |
202 |
|
* @param references the references and their number of instance |
203 |
|
* |
204 |
|
*/ |
205 |
|
void |
206 |
|
addReferences(InsideListExpression::ReferenceList& references) |
207 |
{ |
{ |
208 |
(*__node1).execute(); |
(*__node1).addReferences(references); |
209 |
(*__node2).execute(); |
(*__node2).addReferences(references); |
210 |
} |
} |
211 |
|
|
212 |
/** |
/** |
275 |
ReferenceCounting<Object> objects(const Scene& S); |
ReferenceCounting<Object> objects(const Scene& S); |
276 |
|
|
277 |
/** |
/** |
278 |
* Overloading of Expression::execute() |
* Overloading of InsideListeExpression::subExecute() |
279 |
* |
* |
280 |
*/ |
*/ |
281 |
void execute() |
void subExecute() |
282 |
{ |
{ |
283 |
(*__node1).execute(); |
(*__node1).subExecute(); |
284 |
(*__node2).execute(); |
(*__node2).subExecute(); |
285 |
|
} |
286 |
|
|
287 |
|
/** |
288 |
|
* Fills a list which counts POV-Ray references |
289 |
|
* |
290 |
|
* @param references the references and their number of instance |
291 |
|
* |
292 |
|
*/ |
293 |
|
void |
294 |
|
addReferences(InsideListExpression::ReferenceList& references) |
295 |
|
{ |
296 |
|
(*__node1).addReferences(references); |
297 |
|
(*__node2).addReferences(references); |
298 |
} |
} |
299 |
|
|
300 |
/** |
/** |
363 |
ReferenceCounting<Object> objects(const Scene& S); |
ReferenceCounting<Object> objects(const Scene& S); |
364 |
|
|
365 |
/** |
/** |
366 |
* Overloading of Expression::execute() |
* Overloading of InsideListeExpression::subExecute() |
367 |
* |
* |
368 |
*/ |
*/ |
369 |
void execute() |
void subExecute() |
370 |
{ |
{ |
371 |
(*__node).execute(); |
(*__node).subExecute(); |
372 |
|
} |
373 |
|
|
374 |
|
/** |
375 |
|
* Fills a list which counts POV-Ray references |
376 |
|
* |
377 |
|
* @param references the references and their number of instance |
378 |
|
* |
379 |
|
*/ |
380 |
|
void |
381 |
|
addReferences(InsideListExpression::ReferenceList& references) |
382 |
|
{ |
383 |
|
(*__node).addReferences(references); |
384 |
} |
} |
385 |
|
|
386 |
/** |
/** |
443 |
ReferenceCounting<Object> objects(const Scene& S); |
ReferenceCounting<Object> objects(const Scene& S); |
444 |
|
|
445 |
/** |
/** |
446 |
* Overloading of Expression::execute() |
* Overloading of InsideListeExpression::subExecute() |
447 |
* |
* |
448 |
*/ |
*/ |
449 |
void execute() |
void subExecute() |
450 |
{ |
{ |
451 |
(*__leaf).execute(); |
(*__leaf).execute(); |
452 |
} |
} |
453 |
|
|
454 |
/** |
/** |
455 |
|
* Fills a list which counts POV-Ray references |
456 |
|
* |
457 |
|
* @param references the references and their number of instance |
458 |
|
* |
459 |
|
*/ |
460 |
|
void |
461 |
|
addReferences(InsideListExpression::ReferenceList& references) |
462 |
|
{ |
463 |
|
references[(*__leaf).reference()]++; |
464 |
|
} |
465 |
|
|
466 |
|
/** |
467 |
* Constructor |
* Constructor |
468 |
* |
* |
469 |
* @param leaf |
* @param leaf |