Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AnalysisObject"/> class.
        /// </summary>
        /// <param name="title">The name or title of this object. This is used, e.g., for labels in the visualization.</param>
        /// <param name="id">The id of this object.</param>
        /// <param name="type">The <see cref="ObjectType"/> of this object.</param>
        /// <param name="parentId">The id of the parent object for this object. Should be -1 if the object has no parent.</param>
        /// <param name="dataSource">The data source for this object. This can be used to differentiate between different sensors or tracking systems.</param>
        /// <param name="unitfactor">The conversion factor between the samples' unit of length and 1m.</param>
        /// <param name="timeformat">The <see cref="TimeFormat"/> for this object</param>
        /// <param name="rotationformat">The <see cref="RotationFormat"/> for this object</param>
        /// <param name="conditions">An ordered <c>List</c> of <c>strings</c> representing the study conditions.</param>
        /// <param name="sessions">An ordered <c>List</c> of <see cref="Session"/> representing the study sessions.</param>
        /// <param name="color">The default <see cref="Color"/> for this object.</param>
        public AnalysisObject(
            string title,
            int id,
            ObjectType type,
            int parentId,
            string dataSource,
            float unitfactor,
            TimeFormat timeformat,
            RotationFormat rotationformat,
            List <string> conditions,
            List <Session> sessions,
            Color color)
        {
            Title                = title;
            Id                   = id;
            ObjectColor          = color;
            ParentObjectId       = parentId;
            ObjectDataSource     = dataSource;
            ObjectType           = type;
            UnitConversionFactor = unitfactor;
            RotationFormat       = rotationformat;
            TimeFormat           = timeformat;

            ConditionCount = conditions.Count;
            SessionCount   = sessions.Count;

            sampleArray = new List <Sample> [SessionCount, ConditionCount];
            maxSpeeds   = new float[SessionCount, ConditionCount];

            // create dictionaries for conditions
            ConditionToId = new Dictionary <string, int>(conditions.Count);
            IdToCondition = new Dictionary <int, string>(conditions.Count);

            for (int i = 0; i < conditions.Count; i++)
            {
                ConditionToId.Add(conditions[i], i);
                IdToCondition.Add(i, conditions[i]);
            }
        }
Example #2
0
        private Quaternion ParseStaticRotation(string rotX, string rotY, string rotZ, RotationFormat rotationFormat)
        {
            Quaternion result = ParseQuaternionFromSample(rotX.Substring(1, rotX.Length - 2), rotY.Substring(1, rotY.Length - 2), rotZ.Substring(1, rotZ.Length - 2), rotationFormat);

            result.Normalize();
            Matrix4x4 rotMatrixData  = Matrix4x4.Rotate(result);
            Matrix4x4 rotMatrixUnity = AxisTransformationMatrix4x4 * rotMatrixData * AxisTransformationMatrix4x4.inverse;

            result = rotMatrixUnity.rotation;

            return(result);
        }
Example #3
0
        /// <summary>
        /// Parses a <see cref="Quaternion"/> from the sample data given in three rotation components.
        /// </summary>
        /// <param name="rot_x">The x component of the rotation.</param>
        /// <param name="rot_y">The y component of the rotation.</param>
        /// <param name="rot_z">The z component of the rotation.</param>
        /// <param name="rotationFormat">The rotation format.
        /// Should be <see cref="RotationFormat.EULER_DEG"/>, <see cref="RotationFormat.EULER_RAD"/>, or <see cref="RotationFormat.DIRECTION_VECTOR"/></param>
        /// <returns>The <see cref="Quaternion"/>.</returns>
        internal static Quaternion ParseQuaternionFromSample(string rot_x, string rot_y, string rot_z, RotationFormat rotationFormat)
        {
            float x, y, z;

            x = float.Parse(rot_x, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat);
            y = float.Parse(rot_y, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat);
            z = float.Parse(rot_z, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat);

            Quaternion output = new Quaternion();

            if (rotationFormat == RotationFormat.EULER_DEG)
            {
                output.eulerAngles = new Vector3(x, y, z);
            }
            else if (rotationFormat == RotationFormat.EULER_RAD)
            {
                output.eulerAngles = new Vector3(x * Mathf.Rad2Deg, y * Mathf.Rad2Deg, z * Mathf.Rad2Deg);
            }
            else if (rotationFormat == RotationFormat.DIRECTION_VECTOR)
            {
                output.SetLookRotation(new Vector3(x, y, z));
            }

            return(output);
        }
Example #4
0
        private List <VisContainer> ParseAnchors(List <VisAnchor> anchorXml)
        {
            var results = new List <VisContainer>();

            foreach (var anchor in anchorXml)
            {
                // create struct with default data
                var visContainer = new VisContainer
                {
                    Position    = new float[] { 0, 0, 0 },
                    Scale       = new float[] { 1, 1, 1 },
                    Orientation = new float[] { 0, 0, 0, 1 },
                    Id          = anchor.Id,
                    ParentId    = anchor.ParentId,
                };
                float unitScaleFactor = 1.0f;
                switch (anchor.Units)
                {
                case "mm":
                    unitScaleFactor = 0.001f;
                    break;

                case "cm":
                    unitScaleFactor = 0.01f;
                    break;

                case "m":
                    unitScaleFactor = 1f;
                    break;
                }

                // rotation format
                RotationFormat rotationFormat = RotationFormat.QUATERNION;
                switch (anchor.RotationFormat)
                {
                case "euler_deg":
                    rotationFormat = RotationFormat.EULER_DEG;
                    break;

                case "euler_rad":
                    rotationFormat = RotationFormat.EULER_RAD;
                    break;

                case "quaternion":
                    rotationFormat = RotationFormat.QUATERNION;
                    break;

                case "direction_vector":
                    rotationFormat = RotationFormat.DIRECTION_VECTOR;
                    break;
                }

                if (IsLiteral(anchor.PositionX) && IsLiteral(anchor.PositionY) && IsLiteral(anchor.PositionZ))
                {
                    var position = ParseStaticPosition(anchor.PositionX, anchor.PositionY, anchor.PositionZ, unitScaleFactor);
                    visContainer.Position = new float[] { position.x, position.y, position.z };
                }

                if (IsLiteral(anchor.ScaleX) && IsLiteral(anchor.ScaleY) && IsLiteral(anchor.ScaleZ))
                {
                    var scale = ParseStaticScale(anchor.ScaleX, anchor.ScaleY, anchor.ScaleZ);
                    visContainer.Scale = new float[] { scale.x, scale.y, scale.z };
                }

                if (anchor.RotationW.Length == 0)
                {
                    if (IsLiteral(anchor.RotationX) && IsLiteral(anchor.RotationY) && IsLiteral(anchor.RotationZ))
                    {
                        var rotation = ParseStaticRotation(anchor.RotationX, anchor.RotationY, anchor.RotationZ, rotationFormat);
                        visContainer.Orientation = new float[] { rotation.x, rotation.y, rotation.z, rotation.w };
                    }
                }
                else
                {
                    if (IsLiteral(anchor.RotationW) && IsLiteral(anchor.RotationX) && IsLiteral(anchor.RotationY) && IsLiteral(anchor.RotationZ))
                    {
                        var rotation = ParseStaticRotation(anchor.RotationW, anchor.RotationX, anchor.RotationY, anchor.RotationZ);
                        visContainer.Orientation = new float[] { rotation.x, rotation.y, rotation.z, rotation.w };
                    }
                }

                results.Add(visContainer);
            }

            return(results);
        }
Example #5
0
        private Dictionary <int, AnalysisObject> ReadStaticData(StudyData studyXml)
        {
            var result = new Dictionary <int, AnalysisObject>();

            foreach (var studyObject in studyXml.Objects)
            {
                int    id   = studyObject.Id;
                string name = studyObject.Name;
                if (!Enum.TryParse(studyObject.ObjectType, true, out ObjectType Type))
                {
                    Type = ObjectType.UNKNOWN;
                }

                string source = studyObject.Source;
                int    parent = studyObject.ParentId;
                Color  color  = Color.HSVToRGB(studyObject.ColorHue, studyObject.ColorSaturation, studyObject.ColorValue);

                // rotation format
                RotationFormat rotationFormat = RotationFormat.QUATERNION;
                switch (studyObject.RotationFormat)
                {
                case "euler_deg":
                    rotationFormat = RotationFormat.EULER_DEG;
                    break;

                case "euler_rad":
                    rotationFormat = RotationFormat.EULER_RAD;
                    break;

                case "quaternion":
                    rotationFormat = RotationFormat.QUATERNION;
                    break;

                case "direction_vector":
                    rotationFormat = RotationFormat.DIRECTION_VECTOR;
                    break;
                }

                // time format
                TimeFormat timeFormat = TimeFormat.FLOAT;
                switch (studyObject.TimeFormat)
                {
                case "float":
                    timeFormat = TimeFormat.FLOAT;
                    break;

                case "long":
                    timeFormat = TimeFormat.LONG;
                    break;

                case "string":
                    timeFormat = TimeFormat.STRING;
                    break;
                }

                // scale factor depending on units; we need m
                float unitScaleFactor = 1.0f;
                switch (studyObject.Units)
                {
                case "mm":
                    unitScaleFactor = 0.001f;
                    break;

                case "cm":
                    unitScaleFactor = 0.01f;
                    break;

                case "m":
                    unitScaleFactor = 1f;
                    break;
                }

                var analysisObject = new AnalysisObject(name, id, Type, parent, source, unitScaleFactor, timeFormat, rotationFormat, studyXml.Conditions, studyXml.Sessions, color);

                // parse properties of the object description to get static data
                analysisObject = ParseStaticVariables(studyObject, analysisObject);

                // is the dataset/object static, i.e., not time-dependent?
                analysisObject.IsStatic = studyObject.IsStatic;

                // load model mesh if available
                Mesh objectMesh = null;
                if (studyObject.ModelFile != string.Empty)
                {
                    objectMesh = BasicObjImporter.ImportFromFile(Path.Combine(dataPath, studyObject.ModelFile));
                }

                analysisObject.ObjectModel = objectMesh;

                // add to dictionary
                result.Add(id, analysisObject);
            }

            return(result);
        }