1

I am using the Kinect Toolbox, so I have a list of ReplaySkeletonFrames in my hand. I am iterating over this list, getting the first tracked skeleton and modifying some properties.

As we know, when we change an object we also change the original object.

I need to make a copy of an skeleton.

Note: I can't use CopySkeletonDataTo() because my frame is a ReplaySkeletonFrame and not the ReplayFrame of the "normal" Kinect.

I tried to make my own method that copies property by property, but some properties could not be copied. look...

 public static Skeleton Clone(this Skeleton actualSkeleton)
    {
        if (actualSkeleton != null)
        {
            Skeleton newOne = new Skeleton();

 // doesn't work - The property or indexer 'Microsoft.Kinect.SkeletonJoints'
 // cannot be used in this context because the set accessor is inaccessible
            newOne.Joints = actualSkeleton.Joints;

 // doesn't work - The property or indexer 'Microsoft.Kinect.SkeletonJoints' 
 // cannot be used in this context because the set accessor is inaccessible
            JointCollection jc = new JointCollection();
            jc = actualSkeleton.Joints;
            newOne.Joints = jc;

            //...

        }

        return newOne;

    }

How to solve it?

Junuxx
  • 14,011
  • 5
  • 41
  • 71
Ewerton
  • 4,046
  • 4
  • 30
  • 56

1 Answers1

1

with more search i ended up whit the following solution: Serialize the skeleton to the memory, deserialize to a new object

Here is the code

 public static Skeleton Clone(this Skeleton skOrigin)
    {
        // isso serializa o skeleton para a memoria e recupera novamente, fazendo uma cópia do objeto
        MemoryStream ms = new MemoryStream();
        BinaryFormatter bf = new BinaryFormatter();

        bf.Serialize(ms, skOrigin);

        ms.Position = 0;
        object obj = bf.Deserialize(ms);
        ms.Close();

        return obj as Skeleton;
    }
Ewerton
  • 4,046
  • 4
  • 30
  • 56
  • While looking into this question earlier I ran across the link below, but hadn't found if `Skeleton` was serializable yet. It basically does the same thing, but does so in a more generic way so you don't have to extend the `Skeleton` object and you can use it over and over. http://stackoverflow.com/questions/78536/cloning-objects-in-c-sharp – Nicholas Pappas Nov 26 '12 at 18:16