| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_RENDERING_GEOMETRYVISITOR_H |
| 7 |
#define AVOGADRO_RENDERING_GEOMETRYVISITOR_H |
| 8 |
|
| 9 |
#include "visitor.h" |
| 10 |
|
| 11 |
#include <avogadro/core/vector.h> |
| 12 |
|
| 13 |
#include <vector> |
| 14 |
|
| 15 |
namespace Avogadro { |
| 16 |
namespace Rendering { |
| 17 |
|
| 18 |
/** |
| 19 |
* @class GeometryVisitor geometryvisitor.h |
| 20 |
* <avogadro/rendering/geometryvisitor.h> |
| 21 |
* @brief Visitor that determines the geometry of the scene. |
| 22 |
* @author Marcus D. Hanwell |
| 23 |
* |
| 24 |
* This visitor will attempt to determine the geometry of the scene, most |
| 25 |
* notably the center and radius of the bounding sphere. |
| 26 |
*/ |
| 27 |
|
| 28 |
class GeometryVisitor : public Visitor |
| 29 |
{ |
| 30 |
public: |
| 31 |
GeometryVisitor(); |
| 32 |
~GeometryVisitor() override; |
| 33 |
|
| 34 |
/** |
| 35 |
* The overloaded visit functions, the base versions of which do nothing. |
| 36 |
*/ |
| 37 |
void visit(Node&) override { return; } |
| 38 |
void visit(GroupNode&) override { return; } |
| 39 |
void visit(GeometryNode&) override { return; } |
| 40 |
void visit(Drawable&) override; |
| 41 |
void visit(SphereGeometry&) override; |
| 42 |
void visit(AmbientOcclusionSphereGeometry&) override; |
| 43 |
void visit(CurveGeometry&) override; |
| 44 |
void visit(CylinderGeometry&) override { return; } |
| 45 |
void visit(MeshGeometry&) override { return; } |
| 46 |
void visit(TextLabel2D&) override { return; } |
| 47 |
void visit(TextLabel3D&) override { return; } |
| 48 |
void visit(LineStripGeometry&) override; |
| 49 |
void visit(WideLineGeometry&) override; |
| 50 |
|
| 51 |
/** |
| 52 |
* Clear the state of the visitor. |
| 53 |
*/ |
| 54 |
void clear(); |
| 55 |
|
| 56 |
/** |
| 57 |
* Get the position of the center of the scene. |
| 58 |
*/ |
| 59 |
Vector3f center(); |
| 60 |
|
| 61 |
/** |
| 62 |
* Get the radius of the scene. |
| 63 |
*/ |
| 64 |
float radius(); |
| 65 |
|
| 66 |
private: |
| 67 |
/** |
| 68 |
* Get the average of the accumulated spherical centers and minimal radius. |
| 69 |
*/ |
| 70 |
void average(); |
| 71 |
|
| 72 |
Vector3f m_center; |
| 73 |
float m_radius; |
| 74 |
bool m_dirty; |
| 75 |
|
| 76 |
std::vector<Vector3f> m_centers; |
| 77 |
std::vector<float> m_radii; |
| 78 |
}; |
| 79 |
|
| 80 |
} // End namespace Rendering |
| 81 |
} // End namespace Avogadro |
| 82 |
|
| 83 |
#endif // AVOGADRO_RENDERING_GEOMETRYVISITOR_H |