[162] | 1 | #include "X3dExporter.h"
|
---|
[712] | 2 | #include "VrmlExporter.h"
|
---|
[1233] | 3 | #include "OspTree.h"
|
---|
[1121] | 4 | #include "KdTree.h"
|
---|
[1315] | 5 | #include "IntersectableWrapper.h"
|
---|
[1287] | 6 | #include "BvHierarchy.h"
|
---|
[162] | 7 |
|
---|
[1121] | 8 |
|
---|
[863] | 9 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 10 |
|
---|
[162] | 11 | Exporter *
|
---|
| 12 | Exporter::GetExporter(const string filename)
|
---|
| 13 | {
|
---|
[712] | 14 | Exporter *exporter = NULL;
|
---|
[162] | 15 |
|
---|
[712] | 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);
|
---|
[162] | 23 | }
|
---|
[712] | 24 | else
|
---|
| 25 | {
|
---|
| 26 | cerr<<"Error: Currently unsuported export format, filename " << filename << endl;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | return exporter;
|
---|
[162] | 30 | }
|
---|
| 31 |
|
---|
[1121] | 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);
|
---|
[1144] | 53 | ExportBox(ospTree.GetBoundingBox(leaf));
|
---|
[1121] | 54 |
|
---|
| 55 | SetFilled();
|
---|
| 56 |
|
---|
| 57 | if (maxPvs) // color code pvs
|
---|
| 58 | {
|
---|
| 59 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
[1181] | 60 | const float importance = (float)leaf->mObjects.size() / (float)maxPvs;
|
---|
[1121] | 61 |
|
---|
| 62 | mForcedMaterial.mDiffuseColor.r = importance;
|
---|
| 63 | mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
|
---|
| 64 | }
|
---|
| 65 | else
|
---|
| 66 | {
|
---|
| 67 | SetForcedMaterial(RandomMaterial());
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[1287] | 70 | if (0) ExportGeometry(leaf->mObjects);
|
---|
[1121] | 71 | }
|
---|
| 72 |
|
---|
| 73 | return true;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[1181] | 76 |
|
---|
[1139] | 77 | void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
|
---|
| 78 | {
|
---|
[1233] | 79 | KdNode *node = kdObj.GetItem();
|
---|
[1139] | 80 |
|
---|
| 81 | Intersectable::NewMail();
|
---|
| 82 |
|
---|
[1144] | 83 | // todo: traverse to leaves
|
---|
[1139] | 84 | if (node->IsLeaf())
|
---|
| 85 | {
|
---|
[1144] | 86 | // eyport leaf pvs
|
---|
[1139] | 87 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
[1144] | 88 |
|
---|
[1139] | 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 |
|
---|
[1287] | 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;
|
---|
[1293] | 119 |
|
---|
[1287] | 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 |
|
---|
[860] | 154 | } |
---|