1 | #include "X3dExporter.h"
|
---|
2 | #include "VrmlExporter.h"
|
---|
3 | #include "OspTree.h"
|
---|
4 | #include "KdTree.h"
|
---|
5 | #include "KdIntersectable.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace GtpVisibilityPreprocessor {
|
---|
9 |
|
---|
10 | Exporter *
|
---|
11 | Exporter::GetExporter(const string filename)
|
---|
12 | {
|
---|
13 | Exporter *exporter = NULL;
|
---|
14 |
|
---|
15 | if (strstr(filename.c_str(), ".x3d"))
|
---|
16 | {
|
---|
17 | exporter = new X3dExporter(filename);
|
---|
18 | }
|
---|
19 | else if (strstr(filename.c_str(), ".wrl"))
|
---|
20 | {
|
---|
21 | exporter = new VrmlExporter(filename);
|
---|
22 | }
|
---|
23 | else
|
---|
24 | {
|
---|
25 | cerr<<"Error: Currently unsuported export format, filename " << filename << endl;
|
---|
26 | }
|
---|
27 |
|
---|
28 | return exporter;
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | bool Exporter::ExportOspTree(const OspTree &ospTree, const int maxPvs)
|
---|
33 | {
|
---|
34 | vector<KdLeaf *> leaves;
|
---|
35 | ospTree.CollectLeaves(leaves);
|
---|
36 |
|
---|
37 | mUseForcedMaterial = true;
|
---|
38 |
|
---|
39 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
40 |
|
---|
41 | Material white;
|
---|
42 | white.mDiffuseColor.r = 1;
|
---|
43 | white.mDiffuseColor.g = 1;
|
---|
44 | white.mDiffuseColor.b = 1;
|
---|
45 |
|
---|
46 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
47 | {
|
---|
48 | KdLeaf *leaf = *it;
|
---|
49 |
|
---|
50 | SetWireframe();
|
---|
51 | SetForcedMaterial(white);
|
---|
52 | ExportBox(ospTree.GetBoundingBox(leaf));
|
---|
53 |
|
---|
54 | SetFilled();
|
---|
55 |
|
---|
56 | if (maxPvs) // color code pvs
|
---|
57 | {
|
---|
58 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
59 | const float importance = (float)leaf->mObjects.size() / (float)maxPvs;
|
---|
60 |
|
---|
61 | mForcedMaterial.mDiffuseColor.r = importance;
|
---|
62 | mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
|
---|
63 | }
|
---|
64 | else
|
---|
65 | {
|
---|
66 | SetForcedMaterial(RandomMaterial());
|
---|
67 | }
|
---|
68 |
|
---|
69 | ExportGeometry(leaf->mObjects);
|
---|
70 | }
|
---|
71 |
|
---|
72 | return true;
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
|
---|
77 | {
|
---|
78 | KdNode *node = kdObj.GetItem();
|
---|
79 |
|
---|
80 | Intersectable::NewMail();
|
---|
81 |
|
---|
82 | // todo: traverse to leaves
|
---|
83 | if (node->IsLeaf())
|
---|
84 | {
|
---|
85 | // eyport leaf pvs
|
---|
86 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
87 |
|
---|
88 | ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
|
---|
89 |
|
---|
90 | for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
|
---|
91 | {
|
---|
92 | Intersectable *obj = *oit;
|
---|
93 |
|
---|
94 | if (!obj->Mailed())
|
---|
95 | {
|
---|
96 | ExportIntersectable(obj);
|
---|
97 | obj->Mail();
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | } |
---|