Permalink
Browse files

Initial commit.

Signed-off-by: Israel Buitron <israel.buitron@gmail.com>
  • Loading branch information...
neoriddle committed Mar 26, 2013
0 parents commit dd07b1b9808b0fb44357714ef2496b0768a8ed23
Showing with 184 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE.txt
  4. +30 −0 README.md
  5. +1 −0 Rakefile
  6. +87 −0 lib/voxel4r.rb
  7. +3 −0 lib/voxel4r/version.rb
  8. +20 −0 voxel4r.gemspec
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in voxel4r.gemspec
+gemspec
@@ -0,0 +1,22 @@
+Copyright (c) 2013 TODO: Write your name
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
+# Voxel4r
+
+Voxels generator library.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'voxel4r'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install voxel4r
+
+## Usage
+
+There is not usable yet. :P
+Please wait.
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,87 @@
+require "voxel4r/version"
+
+require 'rasem'
+require 'yaml'
+
+module Voxel4r
+
+ class VoxelGraph
+ def initialize(data, unitary_length, theta)
+ @edge_length = unitary_length
+ @data = data
+ @theta = theta
+
+ compute_dimensions!
+ end
+
+ def drawVoxelGraph
+ lines = []
+
+ # Join vertices
+ @data.each do |v|
+ flb = compute_2d_flb_point(v)
+ voxel_edges = compute_voxel_edges(flb[0],flb[1])
+ voxel_edges.each { |l| lines << l }
+ end
+
+ # Draw lines in SVG image
+ img = Rasem::SVGImage.new(@width, @height) do
+ lines.each { |l| line l[0], l[1], l[2], l[3] }
+ end
+
+ img
+ end
+
+ private
+
+ def compute_voxel_edges(flb_x,flb_y)
+ # Voxel vertices offsets
+ x1, x2, x3 = @alpha_x, @edge_length, @gamma_x
+ y1, y2, y3 = @alpha_y, @edge_length, @gamma_y
+
+ m = [[ 0,x2,x2, 0, 0,x2,x2, 0,x1,x3,x3,x1],
+ [ 0, 0,y2,y2, 0, 0,y2,y2,y1,y1,y3,y3],
+ [x2,x2, 0, 0,x1,x3,x3,x1,x3,x3,x1,x1],
+ [ 0,y2,y2, 0,y1,y1,y3,y3,y1,y3,y3,y1]]
+ m[0].map! {|x| flb_x + x }
+ m[1].map! {|y| flb_y - y }
+ m[2].map! {|x| flb_x + x }
+ m[3].map! {|y| flb_y - y }
+ m = m.transpose
+ end
+
+ def compute_2d_flb_point(voxel_index)
+ x = voxel_index[0]
+ y = voxel_index[1]
+ z = voxel_index[2]
+
+ flb_x = @edge_length * (x + (z * Math.cos(@theta)))
+ flb_y = @edge_length * ((@max_y+1-y) + ((@max_z+1-z) * Math.sin(@theta)))
+
+ [flb_x,flb_y]
+ end
+
+ def compute_dimensions!
+ @max_x, @max_y, @max_z = 0,0,0
+
+ # Set maximums and minimums voxels
+ @data.each do |v|
+ @max_x = v[0] if v[0] > @max_x
+ @max_y = v[1] if v[1] > @max_y
+ @max_z = v[2] if v[2] > @max_z
+ end
+
+ # Compute helper lengths
+ @alpha_x = @edge_length * Math.cos(@theta)
+ @gamma_x = @alpha_x + @edge_length
+ @alpha_y = @edge_length * Math.sin(@theta)
+ @gamma_y = @alpha_y + @edge_length
+
+ # Compute SVG image dimensions
+ @width = (@edge_length * ((@max_x+1) + (@max_z+1) * Math.cos(@theta))).ceil
+ @height = (@edge_length * ((@max_y+1) + (@max_z+1) * Math.sin(@theta))).ceil
+ end
+
+ end
+
+end
@@ -0,0 +1,3 @@
+module Voxel4r
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,20 @@
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'voxel4r/version'
+
+Gem::Specification.new do |gem|
+ gem.name = "voxel4r"
+ gem.version = Voxel4r::VERSION
+ gem.authors = ["Israel Buitron"]
+ gem.email = ["israel.buitron@gmail.com"]
+ gem.description = %q{Voxels generator library}
+ gem.summary = %q{Simply library to generate voxels.}
+ gem.homepage = "http://computacion.cs.cinvestav.mx/~ibuitron"
+
+ gem.add_dependency "rasem"
+
+ gem.files = `git ls-files`.split($/)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.require_paths = ["lib"]
+end

3 comments on commit dd07b1b

vic replied Mar 26, 2013

Wow, this is awesome, looks like a cool project !!. Have you seen http://voxelbuilder.com/ and related projects like https://github.com/maxogden/voxel-engine ?

Owner

neoriddle replied Mar 27, 2013

Hi Vic, thank you very much for your comments.
This voxels will be used to generate hamiltonian paths. These paths can be used in zero-knowledge proofs.
If you are interested and if you want to contribute, just join and fork this project.

Please sign in to comment.