Code Monkey home page Code Monkey logo

hash3's Introduction

hash3

This is a C++ class template for 3D spatial hashing.

It is a work in progress

Usage

hash3 is designed to be used with any type that has a 3D vector type as a member. hash3 and its support files will take care of the rest.

A usage example is provided in this repo. For this example, consider a spatial hashing of particles, where a particle is as follows:

class particle
{
public:

/***
 * to work with hash3, the below needs to be
 * added -- one typedef and the two get_xyz
 * functions. The get_xyz only can return anything
 * that has T.x, T.y, T.z
 **/

typedef double num_type;
typedef myvect3d vect_type;

static const vect_type& get_xyz(const particle& p){
    return p.m_r;
}

/***
 * end hash3 boilerplate
 **/

particle(const vect_type& v, const vect_type& r,
    long id):
    m_r(r),m_v(v),m_idx(id)
{}

particle(const particle& x):
    m_r(x.m_r),m_v(x.m_v),m_idx(x.m_idx)
{}

particle(particle&& x):
    m_r(x.m_r),m_v(x.m_v),m_idx(x.m_idx)
{}

virtual ~particle(){};

vect_type     m_r;
vect_type     m_v;
long int    m_idx;
};

Note that vect_type, in this case, is defined by the client, ie, it is not necessary for the client code to change whatever 3D vector type it is already using.

I opted to require some boilerplate to the type to be hashed in favor of more complex C++ machinery. I am open to simple suggestions which could allow hash3 to be used on classes that can't be modified, for whatever reason.

We can then create a hash of particles with something like:

typedef myvect3d vect3_t;
typedef hash3::int3<int>       idx_t;

std::vector<particle> particles;
std::random_device r;
std::default_random_engine e1(r());
std::uniform_real_distribution<double> uniform_dist(0, 10.0);

for(int i = 0; i < 200; i++)
{
    particles.push_back( particle(  vect3_t(uniform_dist(e1),uniform_dist(e1),uniform_dist(e1) ),
                                    vect3_t(uniform_dist(e1),uniform_dist(e1),uniform_dist(e1) ), i ) );
}

hash3::hash3<particle> storage(std::move(particles), idx_t(5,5,5));

hash3's People

Contributors

sgh1 avatar

Watchers

James Cloos 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.