1 | #include "X3dExporter.h"
|
---|
2 | #include "VrmlExporter.h"
|
---|
3 | #include "OspTree.h"
|
---|
4 | #include "KdTree.h"
|
---|
5 | #include "KdIntersectable.h"
|
---|
6 | #include "BvHierarchy.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | Exporter *
|
---|
12 | Exporter::GetExporter(const string filename)
|
---|
13 | {
|
---|
14 | Exporter *exporter = NULL;
|
---|
15 |
|
---|
16 | if (strstr(filename.c_str(), ".x3d"))
|
---|
17 | {
|
---|
18 | exporter = new X3dExporter(filename);
|
---|
19 | }
|
---|
20 | else if (strstr(filename.c_str(), ".wrl"))
|
---|
21 | {
|
---|
22 | exporter = new VrmlExporter(filename);
|
---|
23 | }
|
---|
24 | else
|
---|
25 | {
|
---|
26 | cerr<<"Error: Currently unsuported export format, filename " << filename << endl;
|
---|
27 | }
|
---|
28 |
|
---|
29 | return exporter;
|
---|
30 | }
|
---|
31 |
|
---|
32 |
|
---|
33 | bool Exporter::ExportOspTree(const OspTree &ospTree, const int maxPvs)
|
---|
34 | {
|
---|
35 | vector<KdLeaf *> leaves;
|
---|
36 | ospTree.CollectLeaves(leaves);
|
---|
37 |
|
---|
38 | mUseForcedMaterial = true;
|
---|
39 |
|
---|
40 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
41 |
|
---|
42 | Material white;
|
---|
43 | white.mDiffuseColor.r = 1;
|
---|
44 | white.mDiffuseColor.g = 1;
|
---|
45 | white.mDiffuseColor.b = 1;
|
---|
46 |
|
---|
47 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
48 | {
|
---|
49 | KdLeaf *leaf = *it;
|
---|
50 |
|
---|
51 | SetWireframe();
|
---|
52 | SetForcedMaterial(white);
|
---|
53 | ExportBox(ospTree.GetBoundingBox(leaf));
|
---|
54 |
|
---|
55 | SetFilled();
|
---|
56 |
|
---|
57 | if (maxPvs) // color code pvs
|
---|
58 | {
|
---|
59 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
60 | const float importance = (float)leaf->mObjects.size() / (float)maxPvs;
|
---|
61 |
|
---|
62 | mForcedMaterial.mDiffuseColor.r = importance;
|
---|
63 | mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
|
---|
64 | }
|
---|
65 | else
|
---|
66 | {
|
---|
67 | SetForcedMaterial(RandomMaterial());
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (0) ExportGeometry(leaf->mObjects);
|
---|
71 | }
|
---|
72 |
|
---|
73 | return true;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
|
---|
78 | {
|
---|
79 | KdNode *node = kdObj.GetItem();
|
---|
80 |
|
---|
81 | Intersectable::NewMail();
|
---|
82 |
|
---|
83 | // todo: traverse to leaves
|
---|
84 | if (node->IsLeaf())
|
---|
85 | {
|
---|
86 | // eyport leaf pvs
|
---|
87 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
88 |
|
---|
89 | ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
|
---|
90 |
|
---|
91 | for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
|
---|
92 | {
|
---|
93 | Intersectable *obj = *oit;
|
---|
94 |
|
---|
95 | if (!obj->Mailed())
|
---|
96 | {
|
---|
97 | ExportIntersectable(obj);
|
---|
98 | obj->Mail();
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | bool Exporter::ExportBvHierarchy(const BvHierarchy &bvHierarchy,
|
---|
106 | const int maxPvs)
|
---|
107 | {
|
---|
108 | vector<BvhLeaf *> leaves;
|
---|
109 | bvHierarchy.CollectLeaves(leaves);
|
---|
110 |
|
---|
111 | mUseForcedMaterial = true;
|
---|
112 |
|
---|
113 | vector<BvhLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
114 |
|
---|
115 | Material white;
|
---|
116 | white.mDiffuseColor.r = 1;
|
---|
117 | white.mDiffuseColor.g = 1;
|
---|
118 | white.mDiffuseColor.b = 1;
|
---|
119 |
|
---|
120 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
121 | {
|
---|
122 | BvhLeaf *leaf = *it;
|
---|
123 |
|
---|
124 | SetWireframe();
|
---|
125 | SetForcedMaterial(white);
|
---|
126 | ExportBox(leaf->GetBoundingBox());
|
---|
127 |
|
---|
128 | SetFilled();
|
---|
129 |
|
---|
130 | if (maxPvs) // color code pvs
|
---|
131 | {
|
---|
132 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
133 | const float importance = (float)leaf->mObjects.size() / (float)maxPvs;
|
---|
134 |
|
---|
135 | mForcedMaterial.mDiffuseColor.r = importance;
|
---|
136 | mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
|
---|
137 | }
|
---|
138 | else
|
---|
139 | {
|
---|
140 | SetForcedMaterial(RandomMaterial());
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (1)
|
---|
144 | {
|
---|
145 | SetFilled();
|
---|
146 | ExportGeometry(leaf->mObjects);
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | return true;
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | } |
---|