Class: Vissen::Output::VixelStack

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vissen/output/vixel_stack.rb

Overview

Stack

TODO: Document this class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, layer_count) ⇒ VixelStack

TODO: Make palettes a keyword argument in the next minor version.

Parameters:

  • context (Context)

    the context in which the stack exist.

  • layer_count (Integer)

    the number of layers in the stack.

Raises:

  • (RangeError)

    if layer_count <= 0.



31
32
33
34
35
36
37
38
# File 'lib/vissen/output/vixel_stack.rb', line 31

def initialize(context, layer_count)
  raise RangeError if layer_count <= 0

  @context = context
  @layers  = Array.new(layer_count) { VixelBuffer.new context }

  freeze
end

Instance Attribute Details

#contextContext (readonly)

Returns the context in which the stack exist.

Returns:

  • (Context)

    the context in which the stack exist.



17
18
19
# File 'lib/vissen/output/vixel_stack.rb', line 17

def context
  @context
end

#layersArray<VixelBuffer> (readonly)

Returns the layers that make up the stack.

Returns:

  • (Array<VixelBuffer>)

    the layers that make up the stack.



14
15
16
# File 'lib/vissen/output/vixel_stack.rb', line 14

def layers
  @layers
end

Instance Method Details

#[](layer, *args) ⇒ Vixel?

Accesses a vixel in one of the vixelbuffers stored in the stack.

Parameters:

  • layer (Integer)

    the index of the layer that is accessed.

Returns:

  • (Vixel, nil)

    the vixel at the given layer.



53
54
55
# File 'lib/vissen/output/vixel_stack.rb', line 53

def [](layer, *args)
  @layers[layer][*args]
end

#freezeself

Prevents more layers and palettes from being added.

Returns:

  • (self)


43
44
45
46
# File 'lib/vissen/output/vixel_stack.rb', line 43

def freeze
  @layers.freeze
  super
end

#pixel_bufferPixelBuffer

Returns a new, uninitialized pixel buffer.

Returns:



58
59
60
# File 'lib/vissen/output/vixel_stack.rb', line 58

def pixel_buffer
  PixelBuffer.new context
end

#point_countInteger Also known as: vixel_count

Returns the number of points in each layer of the stack.

Returns:

  • (Integer)

    the number of points in each layer of the stack.



21
# File 'lib/vissen/output/vixel_stack.rb', line 21

def_delegators :@context, :point_count

#render(pixel_buffer, intensity: 1.0) ⇒ PixelBuffer

Renders each layer and combines the result in the given buffer.

TODO: Could we cache the result of this operation at time t to an

internal PixelGrid and copy the stored information for subsequent
requests at or around the same time?

Parameters:

  • pixel_buffer (PixelBuffer)

    the buffer to store the resulting colors of each point in.

  • intensity (Numeric) (defaults to: 1.0)

    the intensity to scale the vixels intensity with.

Returns:

  • (PixelBuffer)

    the same buffer that was given as a parameter.

Raises:

  • (ContextError)

    if the pixel buffer does not share the same context.



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/vissen/output/vixel_stack.rb', line 76

def render(pixel_buffer, intensity: 1.0)
  raise ContextError unless context == pixel_buffer.context

  pixel_buffer.clear!

  @layers.reduce(pixel_buffer) do |a, e|
    e.render a, intensity: intensity
  end

  pixel_buffer.finalize!
end