# Path: pyKinectTools/dataset_readers/CADPlayer.py
# def read_labels(base_dir='.', subjects=[1], actions=[0], instances=[0]):	
# 
# 	action_names = os.listdir(base_dir+'/Subject1_rgbd_images')
# 	action_names = filter(lambda x:x[0]!='.', action_names)
# 
# 	for s in subjects:
# 		for a in actions:
# 			label_folder = "{}/Subject{}_annotations/{}/".format(base_dir,s,action_names[a])
# 			instance_names = os.listdir(label_folder)
# 			instance_names = [x[:-4] for x in instance_names if x[:-4].isdigit()]
# 
# 			filename = "{}/activityLabel.txt".format(label_folder)
# 			activity_labels = read_activity_labels(filename)
# 
# 			filename = "{}/labeling.txt".format(label_folder)
# 			subactivity_labels = read_subaction_labels(filename)
# 			
# 			for i in instances:
# 				objects = []
# 				object_filenames = os.listdir(label_folder)
# 				object_filenames = [x for x in object_filenames if x.find(instance_names[i])>=0 and x.find("obj")>=0]
# 				for o_name in object_filenames:
# 					filename = "{}/{}".format(label_folder, o_name)
# 					tmp = read_object_labels(filename)
# 					objects += [tmp]
# 				
# 				filename = "{}/{}_globalTransform.txt".format(label_folder, instance_names[i])
# 				global_transform = read_global_transform(filename)
# 
# 				activity = activity_labels[int(instance_names[i])]
# 				subactivity = subactivity_labels[int(instance_names[i])]
# 
# 				yield activity, subactivity, objects, s


import numpy as np
from collections import Counter
from pyKinectTools.dataset_readers.CADPlayer import read_labels
from pylab import bar, show, xticks

base_dir = '/Users/colin/Data/CAD_120/'

labels_all = []
labels = read_labels(base_dir, [1,3,4,5], np.arange(10), np.arange(3))
try:
	while 1:
		labels_all += [labels.next()]
except:
	pass

x = labels_all[0]

actions = [x[0]['activity'] for x in labels_all]
subactions = [[y[1][x]['subaction'] for x in y[1]] for y in labels_all]
subactions = np.hstack(subactions)
objects = np.hstack([x[0]['objects'].values() for x in labels_all])
affordances = [np.hstack([y[1][x]['objects'].values() for x in y[1]]) for y in labels_all]

# Path: pyKinectTools/dataset_readers/CADPlayer.py
# def read_labels(base_dir='.', subjects=[1], actions=[0], instances=[0]):	
# 
# 	action_names = os.listdir(base_dir+'/Subject1_rgbd_images')
# 	action_names = filter(lambda x:x[0]!='.', action_names)
# 
# 	for s in subjects:
# 		for a in actions:
# 			label_folder = "{}/Subject{}_annotations/{}/".format(base_dir,s,action_names[a])
# 			instance_names = os.listdir(label_folder)
# 			instance_names = [x[:-4] for x in instance_names if x[:-4].isdigit()]
# 
# 			filename = "{}/activityLabel.txt".format(label_folder)
# 			activity_labels = read_activity_labels(filename)
# 
# 			filename = "{}/labeling.txt".format(label_folder)
# 			subactivity_labels = read_subaction_labels(filename)
# 			
# 			for i in instances:
# 				objects = []
# 				object_filenames = os.listdir(label_folder)
# 				object_filenames = [x for x in object_filenames if x.find(instance_names[i])>=0 and x.find("obj")>=0]
# 				for o_name in object_filenames:
# 					filename = "{}/{}".format(label_folder, o_name)
# 					tmp = read_object_labels(filename)
# 					objects += [tmp]
# 				
# 				filename = "{}/{}_globalTransform.txt".format(label_folder, instance_names[i])
# 				global_transform = read_global_transform(filename)
# 
# 				activity = activity_labels[int(instance_names[i])]
# 				subactivity = subactivity_labels[int(instance_names[i])]
# 
# 				yield activity, subactivity, objects, s


# Path: pyKinectTools/dataset_readers/CAD_Stats.py
import numpy as np
from collections import Counter
from pyKinectTools.dataset_readers.CADPlayer import read_labels
from pylab import bar, show, xticks


base_dir = '/Users/colin/Data/CAD_120/'

labels_all = []
labels = read_labels(base_dir, [1,3,4,5], np.arange(10), np.arange(3))
try:
	while 1:
		labels_all += [labels.next()]
except:
	pass

x = labels_all[0]

actions = [x[0]['activity'] for x in labels_all]
subactions = [[y[1][x]['subaction'] for x in y[1]] for y in labels_all]
subactions = np.hstack(subactions)
objects = np.hstack([x[0]['objects'].values() for x in labels_all])
affordances = [np.hstack([y[1][x]['objects'].values() for x in y[1]]) for y in labels_all]

affordances = np.hstack(affordances)