1 /****************************************************************************** 2 3 This source file is part of the Avogadro project. 4 5 Copyright 2013 Kitware, Inc. 6 7 This source code is released under the New BSD License, (the "License"). 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 15 ******************************************************************************/ 16 17 #ifndef AVOGADRO_RENDERING_GEOMETRYVISITOR_H 18 #define AVOGADRO_RENDERING_GEOMETRYVISITOR_H 19 20 #include "visitor.h" 21 22 #include <avogadro/core/vector.h> 23 24 #include <vector> 25 26 namespace Avogadro { 27 namespace Rendering { 28 29 /** 30 * @class GeometryVisitor geometryvisitor.h 31 * <avogadro/rendering/geometryvisitor.h> 32 * @brief Visitor that determines the geometry of the scene. 33 * @author Marcus D. Hanwell 34 * 35 * This visitor will attempt to determine the geometry of the scene, most 36 * notably the center and radius of the bounding sphere. 37 */ 38 39 class GeometryVisitor : public Visitor 40 { 41 public: 42 GeometryVisitor(); 43 ~GeometryVisitor() override; 44 45 /** 46 * The overloaded visit functions, the base versions of which do nothing. 47 */ visit(Node &)48 void visit(Node&) override { return; } visit(GroupNode &)49 void visit(GroupNode&) override { return; } visit(GeometryNode &)50 void visit(GeometryNode&) override { return; } 51 void visit(Drawable&) override; 52 void visit(SphereGeometry&) override; 53 void visit(AmbientOcclusionSphereGeometry&) override; visit(CylinderGeometry &)54 void visit(CylinderGeometry&) override { return; } visit(MeshGeometry &)55 void visit(MeshGeometry&) override { return; } visit(TextLabel2D &)56 void visit(TextLabel2D&) override { return; } visit(TextLabel3D &)57 void visit(TextLabel3D&) override { return; } 58 void visit(LineStripGeometry&) override; 59 60 /** 61 * Clear the state of the visitor. 62 */ 63 void clear(); 64 65 /** 66 * Get the position of the center of the scene. 67 */ 68 Vector3f center(); 69 70 /** 71 * Get the radius of the scene. 72 */ 73 float radius(); 74 75 private: 76 /** 77 * Get the average of the accumulated spherical centers and minimal radius. 78 */ 79 void average(); 80 81 Vector3f m_center; 82 float m_radius; 83 bool m_dirty; 84 85 std::vector<Vector3f> m_centers; 86 std::vector<float> m_radii; 87 }; 88 89 } // End namespace Rendering 90 } // End namespace Avogadro 91 92 #endif // AVOGADRO_RENDERING_GEOMETRYVISITOR_H 93