Skip to content

Commit

Permalink
- Comments and more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoern Rennhak committed Apr 14, 2012
1 parent f7689e8 commit 72a47e6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 29 deletions.
48 changes: 48 additions & 0 deletions lib/Helpers.rb
@@ -0,0 +1,48 @@
#!/usr/bin/ruby19
#


# @class class Helpers # {{{
# @brief The helpers class provides some means of assistance for common tasks
class Helpers

# @fn def initialize # {{{
# @brief The constructor for the helpers class
def initialize
end # }}}


# @fn def hashes_to_ostruct object # {{{
# @brief This function turns a nested hash into a nested open struct
#
# @author Dave Dribin (Reference: http://www.dribin.org/dave/blog/archives/2006/11/17/hashes_to_ostruct/)
# @author Bjoern Rennhak
#
# @param [Object] object Value can either be of type Hash or Array, if other then it is returned and not changed
# @returns [OStruct] Returns nested open structs
def hashes_to_ostruct object = nil

raise ArgumentError, "Object cannot be nil" if( object.nil? )

return case object
when Hash
object = object.clone
object.each { |key, value| object[key] = hashes_to_ostruct(value) }
OpenStruct.new( object )
when Array
object = object.clone
object.map! { |i| hashes_to_ostruct(i) }
else
object
end
end # of def hashes_to_ostruct }}}

end # of class Helpers # }}}


# Direct Invocation
if __FILE__ == $0 # {{{
end # of if __FILE__ == $0 # }}}


# vim:ts=2:tw=100:wm=100
57 changes: 28 additions & 29 deletions lib/Repair.rb
Expand Up @@ -18,7 +18,9 @@
#######


# Libaries
$:.push('.')
require 'Helpers.rb'


# @class class Repair # {{{
Expand All @@ -27,6 +29,10 @@ class Repair

# @fn def initialize # {{{
# @brief Default constructor of the Repair class
#
# @param [Logger] logger Logger class
# @param [OpenStruct] yaml OpenStruct containing the loaded yaml
# @param [Fixnum] threshhold Threshhold for the repair detection
def initialize logger = nil, yaml = nil, threshhold = nil

# Sanity check
Expand All @@ -46,7 +52,13 @@ def initialize logger = nil, yaml = nil, threshhold = nil

# @fn def run
# @brief Run checks the motion data for problems and tries to repair it
def run motion_capture_data
#
# @param [ADT] motion_capture_data Motion Capture class MotionX::ADT
def run motion_capture_data = nil

# Sanity check
raise ArgumentError, "Motion capture data cannot be nil" if( motion_capture_data.nil? )

@logger.message( :info, "Running repair" )

result = motion_capture_data
Expand Down Expand Up @@ -74,7 +86,7 @@ def run motion_capture_data
end # of segments.each

# Turn hash into proper ostruct
data = hashes_to_ostruct( data )
data = Helpers.new.hashes_to_ostruct( data )

@logger.message( :debug, "[ Frame: #{frame_index.to_s} ]" )
@logger.message( :debug, "\tChecking if head needs repair" )
Expand Down Expand Up @@ -106,16 +118,25 @@ def run motion_capture_data

end # of repair_hand


end # of 0.upto( frames - 1 )

# Return result
result
end # of def run # }}}


# @fn def repair_hand? # {{{
# @brief Checks if the hand markers need repairing
# @fn def repair_hand? # {{{
# @brief Checks if the hand markers need repairing
#
# @param [Array] rwra Array for the rwra marker
# @param [Array] rwrb Array for the rwrb marker
# @param [Array] lwra Array for the lwra marker
# @param [Array] lwrb Array for the lwrb marker
# @param [Array] lfin Array for the lfin marker
# @param [Array] rfin Array for the rfin marker
# @param [Fixnum] threshhold Threshhold to determine if a marker is broken or not
#
# @return Returns boolean, true if needs to be repaired, false if not.
def repair_hand? rwra = nil, rwrb = nil, lwra = nil, lwrb = nil, lfin = nil, rfin = nil, threshhold = @threshhold

# check sanity
Expand All @@ -125,6 +146,8 @@ def repair_hand? rwra = nil, rwrb = nil, lwra = nil, lwrb = nil, lfin = nil, rfi
raise ArgumentError, "lwrb can't be nil" if( lwrb.nil? )
raise ArgumentError, "lfin can't be nil" if( lfin.nil? )
raise ArgumentError, "rfin can't be nil" if( rfin.nil? )
raise ArgumentError, "threshhold can't be nil" if( threshhold.nil? )


result = false
frame_hand = []
Expand Down Expand Up @@ -571,30 +594,6 @@ def eucledian_distance point1 = nil, point2 = nil
end # of def eucledian_distance point1, point2 }}}


# This function turns a nested hash into a nested open struct
#
# @author Dave Dribin
# Reference: http://www.dribin.org/dave/blog/archives/2006/11/17/hashes_to_ostruct/
#
# @param [Object] object Value can either be of type Hash or Array, if other then it is returned and not changed
# @returns [OStruct] Returns nested open structs
def hashes_to_ostruct object # {{{

return case object
when Hash
object = object.clone
object.each { |key, value| object[key] = hashes_to_ostruct(value) }
OpenStruct.new( object )
when Array
object = object.clone
object.map! { |i| hashes_to_ostruct(i) }
else
object
end

end # of def hashes_to_ostruct }}}


end # of class Repair }}}


Expand Down

0 comments on commit 72a47e6

Please sign in to comment.