[162] | 1 | #include "X3dExporter.h"
|
---|
[712] | 2 | #include "VrmlExporter.h"
|
---|
[1121] | 3 | #include "VspOspTree.h"
|
---|
| 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;
|
---|
| 59 | const float importance = (float)ospTree.ComputePvsSize(leaf->mObjects) / (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 |
|
---|
[1139] | 75 | void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
|
---|
| 76 | {
|
---|
| 77 | KdNode *node = kdObj.GetNode();
|
---|
| 78 |
|
---|
| 79 | Intersectable::NewMail();
|
---|
| 80 |
|
---|
[1144] | 81 | // todo: traverse to leaves
|
---|
[1139] | 82 | if (node->IsLeaf())
|
---|
| 83 | {
|
---|
[1144] | 84 | // eyport leaf pvs
|
---|
[1139] | 85 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
[1144] | 86 |
|
---|
[1139] | 87 | ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
|
---|
| 88 |
|
---|
| 89 | for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
|
---|
| 90 | {
|
---|
| 91 | Intersectable *obj = *oit;
|
---|
| 92 |
|
---|
| 93 | if (!obj->Mailed())
|
---|
| 94 | {
|
---|
| 95 | ExportIntersectable(obj);
|
---|
| 96 | obj->Mail();
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
[860] | 103 | } |
---|