Git Product home page Git Product logo

geometrytypes.jl's Introduction

GeometryTypes

Build Status Build status Coverage Status

Geometry primitives and operations building up on FixedSizeArrays.

Documentation is available here.

Some of the types offered by GeometryTypes visualized with GLVisualize:

HyperRectangle(Vec2f0(0), Vec2f0(100))

HyperRectangle(Vec3f0(0), Vec3f0(1))
HyperCube(Vec3f0(0), 1f0)

HyperSphere(Point2f0(100), 100f0)

HyperSphere(Point3f0(0), 1f0)

Pyramid(Point3f0(0), 1f0, 1f0)

load("cat.obj") # --> GLNormalMesh, via FileIO

Displaying primitives

To display geometry primitives, they need to be decomposable. This can be done for any arbitrary primitive, by overloading the following interface:

# Lets take SimpleRectangle as an example:
# Minimal set of decomposable attributes to build up a triangle mesh
isdecomposable{T<:Point, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true
isdecomposable{T<:Face, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true

# Example implementation of decompose for points
function decompose{PT}(P::Type{Point{3, PT}}, r::SimpleRectangle, resolution=(2,2))
    w,h = resolution
    vec(P[(x,y,0) for x=linspace(r.x, r.x+r.w, w), y=linspace(r.y, r.y+r.h, h)])
end

function decompose{T<:Face}(::Type{T}, r::SimpleRectangle, resolution=(2,2))
    w,h = resolution
    faces = vec([Face{4, Int}(
            sub2ind(resolution, i, j), sub2ind(resolution, i+1, j),
            sub2ind(resolution, i+1, j+1), sub2ind(resolution, i, j+1)
        ) for i=1:(w-1), j=1:(h-1)]
    )
    decompose(T, faces)
end

With these methods defined, this constructor will magically work:

rect = SimpleRectangle(...)
mesh = GLNormalMesh(rect)
vertices(mesh) == decompose(Point3f0, rect)

faces(mesh) == decompose(GLTriangle, rect) # GLFace{3} == GLTriangle
normals(mesh) # automatically calculated from mesh

As you can see, the normals are automatically calculated only with the faces and points. You can overwrite that behavior, by also defining decompose for the Normal type!

geometrytypes.jl's People

Contributors

blegat avatar crashburnrepeat avatar edljk avatar femtocleaner[bot] avatar jonvoxel8 avatar jw3126 avatar kristofferc avatar mohamed82008 avatar rdeits avatar rohitvarkey avatar simondanisch avatar sjkelly avatar staticfloat avatar tkelman avatar tkoolen avatar

Watchers

 avatar  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.