[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"
|
---|
[1344] | 7 | #include "Triangle3.h"
|
---|
| 8 | #include "Polygon3.h"
|
---|
[162] | 9 |
|
---|
[1121] | 10 |
|
---|
[863] | 11 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 12 |
|
---|
[162] | 13 | Exporter *
|
---|
| 14 | Exporter::GetExporter(const string filename)
|
---|
| 15 | {
|
---|
[712] | 16 | Exporter *exporter = NULL;
|
---|
[162] | 17 |
|
---|
[712] | 18 | if (strstr(filename.c_str(), ".x3d"))
|
---|
| 19 | {
|
---|
| 20 | exporter = new X3dExporter(filename);
|
---|
| 21 | }
|
---|
| 22 | else if (strstr(filename.c_str(), ".wrl"))
|
---|
| 23 | {
|
---|
| 24 | exporter = new VrmlExporter(filename);
|
---|
[162] | 25 | }
|
---|
[712] | 26 | else
|
---|
| 27 | {
|
---|
| 28 | cerr<<"Error: Currently unsuported export format, filename " << filename << endl;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | return exporter;
|
---|
[162] | 32 | }
|
---|
| 33 |
|
---|
[1121] | 34 |
|
---|
| 35 | bool Exporter::ExportOspTree(const OspTree &ospTree, const int maxPvs)
|
---|
| 36 | {
|
---|
| 37 | vector<KdLeaf *> leaves;
|
---|
| 38 | ospTree.CollectLeaves(leaves);
|
---|
| 39 |
|
---|
| 40 | mUseForcedMaterial = true;
|
---|
| 41 |
|
---|
| 42 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
| 43 |
|
---|
| 44 | Material white;
|
---|
| 45 | white.mDiffuseColor.r = 1;
|
---|
| 46 | white.mDiffuseColor.g = 1;
|
---|
| 47 | white.mDiffuseColor.b = 1;
|
---|
| 48 |
|
---|
| 49 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
| 50 | {
|
---|
| 51 | KdLeaf *leaf = *it;
|
---|
| 52 |
|
---|
| 53 | SetWireframe();
|
---|
| 54 | SetForcedMaterial(white);
|
---|
[1144] | 55 | ExportBox(ospTree.GetBoundingBox(leaf));
|
---|
[1121] | 56 |
|
---|
| 57 | SetFilled();
|
---|
| 58 |
|
---|
| 59 | if (maxPvs) // color code pvs
|
---|
| 60 | {
|
---|
| 61 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
[1181] | 62 | const float importance = (float)leaf->mObjects.size() / (float)maxPvs;
|
---|
[1121] | 63 |
|
---|
| 64 | mForcedMaterial.mDiffuseColor.r = importance;
|
---|
| 65 | mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
|
---|
| 66 | }
|
---|
| 67 | else
|
---|
| 68 | {
|
---|
| 69 | SetForcedMaterial(RandomMaterial());
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[1287] | 72 | if (0) ExportGeometry(leaf->mObjects);
|
---|
[1121] | 73 | }
|
---|
| 74 |
|
---|
| 75 | return true;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[1181] | 78 |
|
---|
[1139] | 79 | void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
|
---|
| 80 | {
|
---|
[1233] | 81 | KdNode *node = kdObj.GetItem();
|
---|
[1139] | 82 |
|
---|
| 83 | Intersectable::NewMail();
|
---|
| 84 |
|
---|
[1144] | 85 | // todo: traverse to leaves
|
---|
[1139] | 86 | if (node->IsLeaf())
|
---|
| 87 | {
|
---|
[1144] | 88 | // eyport leaf pvs
|
---|
[1139] | 89 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
[1144] | 90 |
|
---|
[1139] | 91 | ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
|
---|
| 92 |
|
---|
| 93 | for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
|
---|
| 94 | {
|
---|
| 95 | Intersectable *obj = *oit;
|
---|
| 96 |
|
---|
| 97 | if (!obj->Mailed())
|
---|
| 98 | {
|
---|
| 99 | ExportIntersectable(obj);
|
---|
| 100 | obj->Mail();
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 |
|
---|
[1287] | 107 | bool Exporter::ExportBvHierarchy(const BvHierarchy &bvHierarchy,
|
---|
| 108 | const int maxPvs)
|
---|
| 109 | {
|
---|
| 110 | vector<BvhLeaf *> leaves;
|
---|
| 111 | bvHierarchy.CollectLeaves(leaves);
|
---|
| 112 |
|
---|
| 113 | mUseForcedMaterial = true;
|
---|
| 114 |
|
---|
| 115 | vector<BvhLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
| 116 |
|
---|
| 117 | Material white;
|
---|
| 118 | white.mDiffuseColor.r = 1;
|
---|
| 119 | white.mDiffuseColor.g = 1;
|
---|
| 120 | white.mDiffuseColor.b = 1;
|
---|
[1293] | 121 |
|
---|
[1287] | 122 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
| 123 | {
|
---|
| 124 | BvhLeaf *leaf = *it;
|
---|
| 125 |
|
---|
| 126 | SetWireframe();
|
---|
| 127 | SetForcedMaterial(white);
|
---|
| 128 | ExportBox(leaf->GetBoundingBox());
|
---|
| 129 |
|
---|
| 130 | SetFilled();
|
---|
| 131 |
|
---|
| 132 | if (maxPvs) // color code pvs
|
---|
| 133 | {
|
---|
| 134 | mForcedMaterial.mDiffuseColor.b = 1.0f;
|
---|
| 135 | const float importance = (float)leaf->mObjects.size() / (float)maxPvs;
|
---|
| 136 |
|
---|
| 137 | mForcedMaterial.mDiffuseColor.r = importance;
|
---|
| 138 | mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
|
---|
| 139 | }
|
---|
| 140 | else
|
---|
| 141 | {
|
---|
| 142 | SetForcedMaterial(RandomMaterial());
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | if (1)
|
---|
| 146 | {
|
---|
| 147 | SetFilled();
|
---|
| 148 | ExportGeometry(leaf->mObjects);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | return true;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
[1344] | 156 | void Exporter::ExportIntersectable(Intersectable *object)
|
---|
| 157 | {
|
---|
| 158 | switch (object->Type())
|
---|
| 159 | {
|
---|
| 160 | case Intersectable::MESH_INSTANCE:
|
---|
| 161 | ExportMeshInstance((MeshInstance *)object);
|
---|
| 162 | break;
|
---|
| 163 | case Intersectable::TRANSFORMED_MESH_INSTANCE:
|
---|
| 164 | ExportTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
|
---|
| 165 | break;
|
---|
| 166 | case Intersectable::VIEW_CELL:
|
---|
| 167 | ExportViewCell(dynamic_cast<ViewCell *>(object));
|
---|
| 168 | break;
|
---|
| 169 | case Intersectable::KD_INTERSECTABLE:
|
---|
| 170 | ExportKdIntersectable(*(dynamic_cast<KdIntersectable *>(object)));
|
---|
| 171 | break;
|
---|
| 172 | case Intersectable::TRIANGLE_INTERSECTABLE:
|
---|
| 173 | {
|
---|
| 174 | const Triangle3 triangle = dynamic_cast<TriangleIntersectable *>(object)->GetItem();
|
---|
| 175 |
|
---|
| 176 | VertexContainer vertices;
|
---|
| 177 | vertices.push_back(triangle.mVertices[0]);
|
---|
| 178 | vertices.push_back(triangle.mVertices[1]);
|
---|
| 179 | vertices.push_back(triangle.mVertices[2]);
|
---|
| 180 |
|
---|
| 181 | Polygon3 poly(vertices);
|
---|
| 182 | ExportPolygon(&poly);
|
---|
| 183 | break;
|
---|
| 184 | }
|
---|
| 185 | default:
|
---|
| 186 | cerr << "Sorry the export for object type " << Intersectable::GetTypeName(object) << " is not available yet" << endl;
|
---|
| 187 | break;
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | void Exporter::ExportMeshInstance(MeshInstance *object)
|
---|
| 192 | {
|
---|
| 193 | // $$JB$$
|
---|
| 194 | // in the future check whether the mesh was not already exported
|
---|
| 195 | // and use a reference to the that mesh instead
|
---|
| 196 | ExportMesh(object->GetMesh());
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | void Exporter::ExportTransformedMeshInstance(TransformedMeshInstance *mi)
|
---|
| 201 | {
|
---|
| 202 | Mesh mesh(*mi->GetMesh());
|
---|
| 203 |
|
---|
| 204 | Matrix4x4 m;
|
---|
| 205 | mi->GetWorldTransform(m);
|
---|
| 206 | mesh.ApplyTransformation(m);
|
---|
| 207 |
|
---|
| 208 | ExportMesh(&mesh);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | void Exporter::ExportViewCells(const ViewCellContainer &viewCells)
|
---|
| 213 | {
|
---|
| 214 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
| 215 |
|
---|
| 216 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
| 217 | {
|
---|
| 218 | ExportViewCell(*it);
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 |
|
---|
[860] | 224 | } |
---|