1 | #ifndef __MAILABLE_H
|
---|
2 | #define __MAILABLE_H
|
---|
3 |
|
---|
4 | #include "AxisAlignedBox3.h"
|
---|
5 | #include "Pvs.h"
|
---|
6 | #include <set>
|
---|
7 | #include "VssRay.h"
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | #define MAX_THREADS 2
|
---|
12 |
|
---|
13 | class Mailable {
|
---|
14 | public:
|
---|
15 | enum {STD_MAILABLE=0, INTERSECTABLE };
|
---|
16 |
|
---|
17 | // last mail id -> warning not thread safe!
|
---|
18 | // both mailId and mailbox should be unique for each thread!!!
|
---|
19 | static int ssMailId[MAX_THREADS];
|
---|
20 |
|
---|
21 | /// Mailbox used for traversals
|
---|
22 | int mMailbox[MAX_THREADS];
|
---|
23 |
|
---|
24 | // Get mailable Id has to be reimplemented for all objects which aim to
|
---|
25 | // have independent mailing
|
---|
26 | virtual int GetMailableId()
|
---|
27 | {
|
---|
28 | return STD_MAILABLE;
|
---|
29 | }
|
---|
30 |
|
---|
31 | ////////////////////////////////////////////////
|
---|
32 | // Mailing stuff
|
---|
33 | Mailable()
|
---|
34 | {
|
---|
35 | for (int i=0; i < MAX_THREADS; i++)
|
---|
36 | mMailbox[i] = 0;
|
---|
37 | }
|
---|
38 |
|
---|
39 | static int GetThreadId();
|
---|
40 |
|
---|
41 | static void NewMail(const int reserve = 1) {
|
---|
42 | int id = GetThreadId();
|
---|
43 | ssMailId[id] += reserve;
|
---|
44 | }
|
---|
45 |
|
---|
46 | void Mail() {
|
---|
47 | int id = GetThreadId();
|
---|
48 | Mail(id);
|
---|
49 | }
|
---|
50 | void Mail(const int threadId) {
|
---|
51 | mMailbox[threadId] = ssMailId[threadId];
|
---|
52 | }
|
---|
53 |
|
---|
54 | bool Mailed() const {
|
---|
55 | int id = GetThreadId();
|
---|
56 | return Mailed(id);
|
---|
57 | }
|
---|
58 |
|
---|
59 | bool Mailed(const int threadId) const {
|
---|
60 | return mMailbox[threadId] == ssMailId[threadId];
|
---|
61 | }
|
---|
62 |
|
---|
63 | void MailSpecial(const int threadId, const int mailbox) {
|
---|
64 | mMailbox[threadId] = ssMailId[threadId] + mailbox;
|
---|
65 | }
|
---|
66 |
|
---|
67 | bool MailedSpecial(const int threadId, const int mailbox) const {
|
---|
68 | return mMailbox[threadId] == ssMailId[threadId] + mailbox;
|
---|
69 | }
|
---|
70 |
|
---|
71 | int IncMail(const int threadId) {
|
---|
72 | return ++ mMailbox[threadId] - ssMailId[threadId];
|
---|
73 | }
|
---|
74 |
|
---|
75 | };
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 | #endif
|
---|