This file is indexed.

/usr/include/simgear/scene/util/QuadTreeBuilder.hxx is in libsimgear-dev 3.4.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (C) 2008  Tim Moore
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#ifndef SIMGEAR_QUADTREEBUILDER_HXX
#define SIMGEAR_QUADTREEBUILDER_HXX 1

#include <algorithm>
#include <functional>
#include <vector>
#include <osg/BoundingBox>
#include <osg/ref_ptr>
#include <osg/Node>
#include <osg/Group>
#include <osg/Matrix>
#include <osg/Vec2>
#include <osg/LOD>
#include "VectorArrayAdapter.hxx"

namespace simgear
{
typedef std::map<osg::ref_ptr<osg::Node>,int> LodMap;

// Create a quad tree based on x, y extents
template <typename LeafType, typename ObjectType, typename MakeLeaf,
          typename AddLeafObject, typename GetObjectLocalCoords>
class QuadTreeBuilder {
public:
    QuadTreeBuilder(const GetObjectLocalCoords& getLocalCoords,
                    const AddLeafObject& addLeafObject, int depth = 2,
                    const MakeLeaf& makeLeaf = MakeLeaf()) :
        _root(new osg::Group), _depth(depth),
        _dimension(1 << depth), _leafStorage(_dimension * _dimension),
        _leaves(_leafStorage, _dimension),
        _leafParents(_leafParentStorage, _dimension / 2),
        _getLocalCoords(getLocalCoords),
        _addLeafObject(addLeafObject), _makeLeaf(makeLeaf)
    {
        using namespace std;
        using namespace osg;
        vector<Group*> parentNodes(1);
        parentNodes[0] = _root.get();
        unsigned leafDim = 2;
        for (int i = 0; i < depth - 1;  ++i, leafDim *= 2) {
            VectorArrayAdapter<vector<Group*> > parents(parentNodes, leafDim / 2);
            vector<Group*> interiorNodes(leafDim * leafDim);
            VectorArrayAdapter<vector<Group*> > interiors(interiorNodes, leafDim);
            for (unsigned j = 0; j < leafDim; ++j) {
                for (unsigned k = 0; k < leafDim; ++k) {
                    interiors(j, k) = new Group;
                    parents(j / 2, k / 2)->addChild(interiors(j, k));
                }
            }
            parentNodes.swap(interiorNodes);
        }
        // Save leaf parents for later when we add leaves
        _leafParentStorage = parentNodes;
    }
    osg::Vec2 getMin() { return _min; }
    void setMin(const osg::Vec2& min) { _min = min; }
    osg::Vec2 getMax() { return _max; }
    void setMax(const osg::Vec2& max) { _max = max; }
    ~QuadTreeBuilder() {}
    osg::Group* getRoot() { return _root.get(); }

    void addNode(ObjectType& obj)
    {
        using namespace osg;
        const Vec3 center(_getLocalCoords(obj));
        int x = 0;
        if (_max.x() != _min.x())
            x = (int)(_dimension * (center.x() - _min.x())
                      / (_max.x() - _min.x()));
        x = clampTo(x, 0, (_dimension - 1));
        int y = 0;
        if (_max.y() != _min.y())
            y = (int)(_dimension * (center.y() - _min.y())
                      / (_max.y() - _min.y()));
        y = clampTo(y, 0, (_dimension -1));
        if (!_leaves(y, x)) {
            _leaves(y, x) = _makeLeaf();
            _leafParents(y / 2, x / 2)->addChild(_leaves(y, x));
        }
        _addLeafObject(_leaves(y, x), obj);
    }
    // STL craziness
    struct AddNode
    {
        AddNode(QuadTreeBuilder* qt) : _qt(qt) {}
        AddNode(const AddNode& rhs) : _qt(rhs._qt) {}
        void operator() (ObjectType& obj) const { _qt->addNode(obj); }
        QuadTreeBuilder *_qt;
    };
    // Make a quadtree of nodes from a map of nodes and LOD values
    template <typename ForwardIterator>
    void buildQuadTree(const ForwardIterator& begin,
                       const ForwardIterator& end)
    {
        using namespace osg;
        BoundingBox extents;
        for (ForwardIterator iter = begin; iter != end; ++iter) {
            const Vec3 center = _getLocalCoords(*iter);
            extents.expandBy(center);
        }
        _min = Vec2(extents.xMin(), extents.yMin());
        _max = Vec2(extents.xMax(), extents.yMax());
        std::for_each(begin, end, AddNode(this));
    }

protected:
    typedef std::vector<LeafType> LeafVector;
    osg::ref_ptr<osg::Group> _root;
    osg::Vec2 _min;
    osg::Vec2 _max;
    int _depth;
    int _dimension;
    LeafVector _leafStorage;
    VectorArrayAdapter<LeafVector> _leaves;
    std::vector<osg::Group*> _leafParentStorage;
    VectorArrayAdapter<std::vector<osg::Group*> > _leafParents;
    const GetObjectLocalCoords _getLocalCoords;
    const AddLeafObject _addLeafObject;
    const MakeLeaf _makeLeaf;
};

}
#endif