Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
improve #3
  • Loading branch information
patmo141 committed Jul 4, 2016
1 parent 0cb5b50 commit 135e1b7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 24 deletions.
58 changes: 34 additions & 24 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ def make_pairs(align_obj, base_obj, base_bvh, vlist, thresh, sample = 0, calc_st
vlist is a list of vertex indices in the align object to use
for alignment. Will be in align_obj local space!
'''

mx1 = align_obj.matrix_world
mx2 = base_obj.matrix_world

Expand Down Expand Up @@ -404,7 +403,7 @@ class AlignmentAddonPreferences(AddonPreferences):

min_start = FloatProperty(
name="Minimum Starting Dist",
description = "Only verts closer than this distance will be included in each iteration",
description = "Only verts closer than this distance will be used in each iteration",
default = 0.5,
min = 0,
max = 20)
Expand Down Expand Up @@ -447,7 +446,8 @@ class ComplexAlignmentPanel(bpy.types.Panel):
bl_region_type = 'TOOLS'

def draw(self, context):
settings = context.user_preferences.addons['object_alignment'].preferences
settings = get_settings()

layout = self.layout


Expand Down Expand Up @@ -498,7 +498,8 @@ def draw(self, context):

row = layout.row()
row.operator('object.align_icp_redraw')

row = layout.row()
row.prop(settings, 'redraw_frequency')
row = layout.row()
row.prop(settings, 'icp_iterations')
row = layout.row()
Expand Down Expand Up @@ -529,8 +530,11 @@ def poll(cls, context):
def execute(self, context):

if 'icp_include' not in context.object.vertex_groups:

new_group = context.object.vertex_groups.new(name = 'icp_include')
#remove the exclude group
if 'icp_exclude' in context.object.vertex_groups:
g = context.object.vertex_groups['icp_exclude']
context.object.vertex_groups.remove(g)

bpy.ops.object.vertex_group_set_active(group = 'icp_include')

Expand Down Expand Up @@ -581,7 +585,10 @@ def execute(self, context):

if 'icp_exclude' not in context.object.vertex_groups:
new_group = context.object.vertex_groups.new(name = 'icp_exclude')

#remove the exclude group
if 'icp_include' in context.object.vertex_groups:
g = context.object.vertex_groups['icp_include']
context.object.vertex_groups.remove(g)
bpy.ops.object.vertex_group_set_active(group = 'icp_exclude')

if context.mode != 'PAINT_WEIGHT':
Expand Down Expand Up @@ -830,7 +837,8 @@ def align_obj(self,context):


#test new method
align_meth = context.user_preferences.addons['object_alignment'].preferences.align_meth
settings = get_settings()
align_meth = settings.align_meth

if align_meth == '0': #rigid transform
M = affine_matrix_from_points(A, B, shear=False, scale=False, usesvd=True)
Expand Down Expand Up @@ -947,7 +955,8 @@ def poll(cls, context):
return condition_1 and condition_1

def execute(self, context):
align_meth = context.user_preferences.addons['object_alignment'].preferences.align_meth
settings = get_settings()
align_meth = settings.align_meth
start = time.time()
align_obj = context.object
base_obj = [obj for obj in context.selected_objects if obj != align_obj][0]
Expand Down Expand Up @@ -980,12 +989,12 @@ def execute(self, context):
else:
vlist = [v.index for v in align_obj.data.vertices]


thresh = context.user_preferences.addons['object_alignment'].preferences.min_start
sample = context.user_preferences.addons['object_alignment'].preferences.sample_fraction
iters = context.user_preferences.addons['object_alignment'].preferences.icp_iterations
target_d = context.user_preferences.addons['object_alignment'].preferences.target_d
use_target = context.user_preferences.addons['object_alignment'].preferences.use_target
settings = get_settings()
thresh = settings.min_start
sample = settings.sample_fraction
iters = settings.icp_iterations
target_d = settings.target_d
use_target = settings.use_target
factor = round(1/sample)

n = 0
Expand Down Expand Up @@ -1081,7 +1090,7 @@ def poll(cls, context):

def iterate(self,context):

(A, B, self.d_stats) = make_pairs(self.align_obj, self.base_obj, self.vlist, self.thresh, self.sample_factor, calc_stats = self.use_target)
(A, B, self.d_stats) = make_pairs(self.align_obj, self.base_obj, self.base_bvh, self.vlist, self.thresh, self.sample_factor, calc_stats = self.use_target)


if self.align_meth == '0': #rigid transform
Expand Down Expand Up @@ -1123,11 +1132,12 @@ def invoke(self,context, event):
wm.modal_handler_add(self)



self.align_meth = context.user_preferences.addons['object_alignment'].preferences.align_meth
settings = get_settings()
self.align_meth = settings.align_meth
self.start = time.time()
self.align_obj = context.object
self.base_obj = [obj for obj in context.selected_objects if obj != self.align_obj][0]
self.base_bvh = BVHTree.FromObject(self.base_obj, context.scene)
self.align_obj.rotation_mode = 'QUATERNION'

self.vlist = []
Expand Down Expand Up @@ -1157,14 +1167,14 @@ def invoke(self,context, event):
self.vlist = [v.index for v in self.align_obj.data.vertices]
#vlist = [range(0,len(align_obj.data.vertices] #perhaps much smarter


self.thresh = context.user_preferences.addons['object_alignment'].preferences.min_start
self.sample_fraction = context.user_preferences.addons['object_alignment'].preferences.sample_fraction
self.iters = context.user_preferences.addons['object_alignment'].preferences.icp_iterations
self.target_d = context.user_preferences.addons['object_alignment'].preferences.target_d
self.use_target = context.user_preferences.addons['object_alignment'].preferences.use_target
settings = get_settings()
self.thresh = settings.min_start
self.sample_fraction = settings.sample_fraction
self.iters = settings.icp_iterations
self.target_d = settings.target_d
self.use_target = settings.use_target
self.sample_factor = round(1/self.sample_fraction)
self.redraw_frequency = context.user_preferences.addons['object_alignment'].preferences.redraw_frequency
self.redraw_frequency = settings.redraw_frequency

self.total_iters = 0
self.converged = False
Expand Down
22 changes: 22 additions & 0 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@author: Patrick
'''
import os

import bpy
import bgl
Expand All @@ -12,6 +13,27 @@
from bpy_extras.view3d_utils import location_3d_to_region_2d, region_2d_to_vector_3d
from bpy_extras.view3d_utils import region_2d_to_location_3d, region_2d_to_origin_3d

#Borrowed from retopoflow @CGCookie, Jonathan Wiliamson, Jon Denning, Patrick Moore
def get_settings():
if not get_settings.cached_settings:
addons = bpy.context.user_preferences.addons
#frame = inspect.currentframe()
#frame.f_code.co_filename
folderpath = os.path.dirname(os.path.abspath(__file__))
while folderpath:
folderpath,foldername = os.path.split(folderpath)
if foldername in {'lib','addons'}: continue
if foldername in addons: break
else:
assert False, 'Could not find non-"lib" folder'

get_settings.cached_settings = addons[foldername].preferences

return get_settings.cached_settings

get_settings.cached_settings = None


def bversion():
bversion = '%03d.%03d.%03d' % (bpy.app.version[0],bpy.app.version[1],bpy.app.version[2])
return bversion
Expand Down

0 comments on commit 135e1b7

Please sign in to comment.