/// <summary> /// Allows to merge 2 Node hierarchy /// </summary> /// <param name="rootNode1">The root Node of the first Node Hierarchy</param> /// <param name="mergeNodeName1">The name of the node that we want to merge with mergeNodeName2</param> /// <param name="rootNode2">The root Node of the first Node Hierarchy</param> /// <param name="mergeNodeName2">The name of the node that we want to merge with mergdeNodeName1</param> /// <param name="childrenCopy">Should we make a simple jointure or only copy the nodes childrens</param> public static Node MergeNodeStructure(Node rootNode1, string mergeNodeName1, Node rootNode2, string mergeNodeName2, ref MergeBehaviour mergeBehav) { Node rootNode1Copy = rootNode1; if (mergeBehav.copyTreeNode1) rootNode1Copy = AssimpUtil.DuplicateNodeTree(rootNode1); Node rootNode2Copy = rootNode2; if (mergeBehav.copyTreeNode2) rootNode2Copy = AssimpUtil.DuplicateNodeTree(rootNode2); Node mergeNode1 = rootNode1Copy.FindNode(mergeNodeName1); Node mergeNode2 = rootNode2Copy.FindNode(mergeNodeName2); if (mergeBehav.childrenCopy) { foreach (Node tmp in mergeNode2.Children) mergeNode1.Children.Add(tmp); } else mergeNode1.Children.Add(mergeNode2); return rootNode1Copy; }
/// <summary> /// Allows to merge a kinect recorded scene with a leap motion recorded scene /// </summary> /// <param name="sceneKinect">The recorded Kinect Scene</param> /// <param name="sceneLeapMotion">The recorded LeapMotion Scene</param> /// <param name="handDirection">The direction of the hand, 1 is for the right direction and 2 for the left</param> public static Scene MergeBodyAndHand(ref KineapScene[] kineapSceneBucket) { Scene generatedScene = new Scene(); Scene kinectScene = kineapSceneBucket[0].Scene; KineapScene leftHandLeapMotionScene = kineapSceneBucket[1]; KineapScene rightHandLeapMotionScene = kineapSceneBucket[2]; string kinectHandfulLeft = KinectConverter.GetNodeIdName(Microsoft.Kinect.JointType.HandLeft); string kinectHandfulRight = KinectConverter.GetNodeIdName(Microsoft.Kinect.JointType.HandRight); Scene onlyAvailableLeapMotion = null; string kinectJointToMergeName = null; if (leftHandLeapMotionScene == null ^ rightHandLeapMotionScene == null) { if (leftHandLeapMotionScene != null) { onlyAvailableLeapMotion = leftHandLeapMotionScene.Scene; kinectJointToMergeName = kinectHandfulLeft; } else { onlyAvailableLeapMotion = rightHandLeapMotionScene.Scene; kinectJointToMergeName = kinectHandfulRight; } } if (kinectScene == null) throw (new ArgumentException("A skeleton should be at least present", "value")); else if (leftHandLeapMotionScene == null && rightHandLeapMotionScene == null) throw (new ArgumentException("One hand should be at least available", "value")); MergeBehaviour mergeBehaviour = new MergeBehaviour(); mergeBehaviour.childrenCopy = true; if (onlyAvailableLeapMotion != null) //if only one hand { generatedScene.RootNode = AssimpAnimFormatMerger.MergeNodeStructure( kinectScene.RootNode, kinectJointToMergeName, onlyAvailableLeapMotion.RootNode, onlyAvailableLeapMotion.RootNode.Children[0].Name, ref mergeBehaviour ); generatedScene.Animations.Add(AssimpAnimFormatMerger.MergeAnimations(kinectScene.Animations[0], onlyAvailableLeapMotion.Animations[0])); //We dont need the root nodeAnim anymore from the leap motion, we will only merge the children ExcludeNodeAnimation(generatedScene.Animations[0], onlyAvailableLeapMotion.RootNode.Name); } else // If both hands are presents { generatedScene.RootNode = AssimpAnimFormatMerger.MergeNodeStructure( kinectScene.RootNode, kinectHandfulLeft, leftHandLeapMotionScene.Scene.RootNode, leftHandLeapMotionScene.Scene.RootNode.Children[0].Name, ref mergeBehaviour ); generatedScene.Animations.Add(AssimpAnimFormatMerger.MergeAnimations(kinectScene.Animations[0], leftHandLeapMotionScene.Scene.Animations[0])); ExcludeNodeAnimation(generatedScene.Animations[0], leftHandLeapMotionScene.Scene.RootNode.Name); //We dont want to make copy that time, because we already did it mergeBehaviour.copyTreeNode1 = false; mergeBehaviour.copyTreeNode2 = true; AssimpAnimFormatMerger.MergeNodeStructure( generatedScene.RootNode, kinectHandfulRight, rightHandLeapMotionScene.Scene.RootNode, rightHandLeapMotionScene.Scene.RootNode.Children[0].Name, ref mergeBehaviour ); AssimpUtil.CopyAnimationInto(rightHandLeapMotionScene.Scene.Animations[0], generatedScene.Animations[0]); ExcludeNodeAnimation(generatedScene.Animations[0], rightHandLeapMotionScene.Scene.RootNode.Name); } return generatedScene; }