Coder Social home page Coder Social logo

octree's Introduction

Octree

Octree library in C++.

Contained entirely in a header file.

Usage:

    // Class that holds your data.
    class Node
    {
        ...
    };

    // Initialize octree.
    // cellSize is the minimum subdivided cell size.
    float min[3] = {0.0f, 0.0f, 0.0f};
    float max[3] = {1.0f + EPSILON, 1.0f + EPSILON, 1.0f + EPSILON};
    float cellSize[3] = {0.1, 0.1, 0.1};
    Octree<Node> octree(min, max, cellSize);

    // Add data to the octree.
    // Data will be added to the leaves.
    for (int i = 0; i < NUM_ELEMENTS; i++)
    {
        // getCell returns the octree leaf cell (of size
        // cellSize or larger) that contains the passed
        // position.
        Node& n = octree.getCell(position[i]);
        // Set your data in the cell.
        // e.g. add something to a std::vector, etc.
        n. ... = ...;
    }
    
    // Traverse octree.
    // Create callback class.
    class Callback: public Octree<Node>::Callback
    {
    public:
        // State variables.
        ...
        // Callback functor. 
        // Returns: true = continue and traverse subcells; false = abort branch.
        virtual bool operator()(const float min[3], const float max[3], Node& nodeData)
        {
            ...
        }
    };
    // Invoke traversal.
    Callback cb;
    octree.traverse(&cb);

See sample.cpp for a more extensive sample.

octree's People

Contributors

eduardop avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.