[162] | 1 | #include "X3dExporter.h"
|
---|
[712] | 2 | #include "VrmlExporter.h"
|
---|
[1233] | 3 | #include "OspTree.h"
|
---|
[1121] | 4 | #include "KdTree.h"
|
---|
[1139] | 5 | #include "KdIntersectable.h"
|
---|
[162] | 6 |
|
---|
[1121] | 7 |
|
---|
[863] | 8 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 9 |
|
---|
[162] | 10 | Exporter *
|
---|
| 11 | Exporter::GetExporter(const string filename)
|
---|
| 12 | {
|
---|
[712] | 13 | Exporter *exporter = NULL;
|
---|
[162] | 14 |
|
---|
[712] | 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);
|
---|
[162] | 22 | }
|
---|
[712] | 23 | else
|
---|
| 24 | {
|
---|
| 25 | cerr<<"Error: Currently unsuported export format, filename " << filename << endl;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | return exporter;
|
---|
[162] | 29 | }
|
---|
| 30 |
|
---|
[1121] | 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);
|
---|
[1144] | 52 | ExportBox(ospTree.GetBoundingBox(leaf));
|
---|
[1121] | 53 |
|
---|
| 54 | SetFilled();
|
---|
| 55 |
|
---|
| 56 | if (maxPvs) // color code pvs
|
---|
| 57 | {
|
---|
| 58 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
[1181] | 59 | const float importance = (float)leaf->mObjects.size() / (float)maxPvs;
|
---|
[1121] | 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 |
|
---|
[1181] | 75 |
|
---|
[1139] | 76 | void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
|
---|
| 77 | {
|
---|
[1233] | 78 | KdNode *node = kdObj.GetItem();
|
---|
[1139] | 79 |
|
---|
| 80 | Intersectable::NewMail();
|
---|
| 81 |
|
---|
[1144] | 82 | // todo: traverse to leaves
|
---|
[1139] | 83 | if (node->IsLeaf())
|
---|
| 84 | {
|
---|
[1144] | 85 | // eyport leaf pvs
|
---|
[1139] | 86 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
[1144] | 87 |
|
---|
[1139] | 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 |
|
---|
[860] | 104 | } |
---|