Load a C3D file:

you can load file from path:

C3DFile file = C3DFile.LoadFromFile("FILE PATH");

or from a stream:

C3DFile file = C3DFile.LoadFromStream(stream);

Read file header property:

you can read property from file header:

UInt16 firstFrameIndex = file.Header.FirstFrameIndex;

and the events in the header:

C3DHeaderEvent[] events = file.Header.GetAllHeaderEvents();

Read parameter:

you can read parameter by "GROUPNAME:PARAMETERNAME":

UInt16 pointCount = file.Parameters["POINT:USED"].GetData<UInt16>();

the type supports Byte, Char, Int16, UInt16(only v0.3+), Single, String and their arrays

or you can split names like this:

String[] pointLabels = file.Parameters["POINT", "LABEL"].GetData<String[]>();

or like this(only v0.2+), this method would not throw any exceptions when parameter does not exist: 

String[] pointLabels = file.Parameters.GetParameterData<String[]>("POINT", "LABEL");

or you can use a non-generic method:

Object scale = file.Parameters["POINT", "SCALE"].GetData();

Read all 3D points:

UInt16 firstFrameIndex = file.Header.FirstFrameIndex;
UInt16 pointCount = file.Parameters["POINT:USED"].GetData<UInt16>();

for (Int32 i = 0; i < file.AllFrames.Count; i++)
{
    //you can also use file.AllFrames[i].Point3Ds.Length
    for (Int32 j = 0; j < pointCount; j++)
    {
        Console.WriteLine("Frame {0} : X = {1}, Y = {2}, Z = {3}",
            firstFrameIndex + i,
            file.AllFrames[i].Point3Ds[j].X,
            file.AllFrames[i].Point3Ds[j].Y ,
            file.AllFrames[i].Point3Ds[j].Z);
        //or you can use this method
        Console.WriteLine("Frame {0} : X = {1}, Y = {2}, Z = {3}",
            firstFrameIndex + i,
            file.AllFrames.Get3DPoint(i, j).X,
            file.AllFrames.Get3DPoint(i, j).Y,
            file.AllFrames.Get3DPoint(i, j).Z);
    }
}

Read all analog points:

Single frameRate = file.Parameters["POINT", "RATE"].GetData<Single>();
UInt16 analogChannelCount = file.Parameters["ANALOG", "USED"].GetData<UInt16>();
UInt16 analogSamplesPerFrame = (UInt16)(file.Parameters["ANALOG", "RATE"].GetData<UInt16>() / frameRate);

for (Int32 i = 0; i < file.AllFrames.Count; i++)
{
    //you can also use file.AllFrames[i].AnalogSamples.Length
    for (Int32 j = 0; j < analogChannelCount; j++)
    {
        //you can also use file.AllFrames[i].AnalogSamples[j].SampleCount
        for (Int32 k = 0; k < analogSamplesPerFrame; k++)
        {
            Console.WriteLine("Frame {0}, Sample {1} : {2}",
                firstFrameIndex + i, j + 1,
                file.AllFrames[i].AnalogSamples[j][k]);
            //or this method
            Console.WriteLine("Frame {0}, Sample {1} : {2}",
                firstFrameIndex + i, j + 1,
                file.AllFrames.GetAnalogSample(i, j)[k]);
        }
    }
}

If you like read file per frame, you can use C3DReader:

using (FileStream fs = new FileStream("FILE PATH", FileMode.Open, FileAccess.Read))
{
    C3DReader reader = new C3DReader(fs);
    C3DParameterDictionary dictionary = reader.ReadParameters();
C3DParameterCache paramCache = C3DParameterCache.CreateCache(dictionary); while (true) { C3DFrame frame = reader.ReadNextFrame(paramCache); if (frame == null) { break; } //TODO } }

Create a new C3D file:

C3DFile file = C3DFile.Create();
file.SaveTo("FILE PATH");

Add parameter:

fisrt, you should add group by group id, group name and description:

file.Parameters.SetGroup(1, "POINT", "");

and then you can add parameter to a group using group id, 
you can set parameter name, description and data in one line:

file.Parameters[1].Add("USED", "").SetData<UInt16>(5);

or like this(only v0.2+):

file.Parameters.SetParameter<UInt16>("POINT", "USED", 5);

Add Frame:

//you can add 3D point like this
file.AllFrames.Add(new C3DFrame(new C3DPoint3DData[] {
    new C3DPoint3DData() { X = x, Y = y, Z = z, Residual = residual, CameraMask = cameraMask},
    new C3DPoint3DData() { X = x, Y = y, Z = z, Residual = residual, CameraMask = cameraMask},
    new C3DPoint3DData() { X = x, Y = y, Z = z, Residual = residual, CameraMask = cameraMask},
    new C3DPoint3DData() { X = x, Y = y, Z = z, Residual = residual, CameraMask = cameraMask},
    new C3DPoint3DData() { X = x, Y = y, Z = z, Residual = residual, CameraMask = cameraMask} }));

Last edited Dec 2, 2013 at 6:08 AM by mayswind, version 20