[162] | 1 | #include "X3dExporter.h"
|
---|
[712] | 2 | #include "VrmlExporter.h"
|
---|
[1121] | 3 | #include "VspOspTree.h"
|
---|
| 4 | #include "KdTree.h"
|
---|
[162] | 5 |
|
---|
[1121] | 6 |
|
---|
[863] | 7 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 8 |
|
---|
[162] | 9 | Exporter *
|
---|
| 10 | Exporter::GetExporter(const string filename)
|
---|
| 11 | {
|
---|
[712] | 12 | Exporter *exporter = NULL;
|
---|
[162] | 13 |
|
---|
[712] | 14 | if (strstr(filename.c_str(), ".x3d"))
|
---|
| 15 | {
|
---|
| 16 | exporter = new X3dExporter(filename);
|
---|
| 17 | }
|
---|
| 18 | else if (strstr(filename.c_str(), ".wrl"))
|
---|
| 19 | {
|
---|
| 20 | exporter = new VrmlExporter(filename);
|
---|
[162] | 21 | }
|
---|
[712] | 22 | else
|
---|
| 23 | {
|
---|
| 24 | cerr<<"Error: Currently unsuported export format, filename " << filename << endl;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | return exporter;
|
---|
[162] | 28 | }
|
---|
| 29 |
|
---|
[1121] | 30 |
|
---|
| 31 | bool Exporter::ExportOspTree(const OspTree &ospTree, const int maxPvs)
|
---|
| 32 | {
|
---|
| 33 | vector<KdLeaf *> leaves;
|
---|
| 34 | ospTree.CollectLeaves(leaves);
|
---|
| 35 |
|
---|
| 36 | mUseForcedMaterial = true;
|
---|
| 37 |
|
---|
| 38 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
| 39 |
|
---|
| 40 | Material white;
|
---|
| 41 | white.mDiffuseColor.r = 1;
|
---|
| 42 | white.mDiffuseColor.g = 1;
|
---|
| 43 | white.mDiffuseColor.b = 1;
|
---|
| 44 |
|
---|
| 45 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
| 46 | {
|
---|
| 47 | KdLeaf *leaf = *it;
|
---|
| 48 |
|
---|
| 49 | SetWireframe();
|
---|
| 50 | SetForcedMaterial(white);
|
---|
| 51 | ExportBox(ospTree.GetBBox(leaf));
|
---|
| 52 |
|
---|
| 53 | SetFilled();
|
---|
| 54 |
|
---|
| 55 | if (maxPvs) // color code pvs
|
---|
| 56 | {
|
---|
| 57 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
| 58 | const float importance = (float)ospTree.ComputePvsSize(leaf->mObjects) / (float)maxPvs;
|
---|
| 59 |
|
---|
| 60 | mForcedMaterial.mDiffuseColor.r = importance;
|
---|
| 61 | mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
|
---|
| 62 | }
|
---|
| 63 | else
|
---|
| 64 | {
|
---|
| 65 | SetForcedMaterial(RandomMaterial());
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | ExportGeometry(leaf->mObjects);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | return true;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[860] | 74 | } |
---|