Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectImportHelper"/> class.
 /// </summary>
 /// <param name="source">The <see cref="ObjectSource"/> containing the meta data of the object.</param>
 /// <param name="analysisObject">The <see cref="AnalysisObject"/> already containing the static data of the object.</param>
 public ObjectImportHelper(ObjectSource source, AnalysisObject analysisObject)
 {
     Source                      = source;
     ObjectId                    = source.ObjectId;
     SessionId                   = source.SessionId;
     ConditionId                 = source.ConditionId;
     ImportData                  = new CsvImportBlock(source);
     Parsers                     = new List <ParserFunc>();
     ParserIndices               = new List <int[]>();
     StaticPosition              = analysisObject.LocalPosition;
     StaticOrientation           = analysisObject.LocalRotation;
     StaticScale                 = analysisObject.LocalScale;
     UnitConversionFactor        = analysisObject.UnitConversionFactor;
     RotationFormat              = analysisObject.RotationFormat;
     timeFormat                  = analysisObject.TimeFormat;
     axisTransformationMatrix4x4 = Services.DataManager().AxisTransformationMatrix4x4;
 }
Ejemplo n.º 2
0
        private AnalysisObject ParseStaticVariables(StudyObject objectXml, AnalysisObject analysisObject)
        {
            // variables used during parsing of the data
            Vector3    staticPosition    = Vector3.zero;
            Vector3    staticScale       = Vector3.one;
            Quaternion staticRotation    = Quaternion.identity;
            bool       useStaticPosition = false;
            bool       useStaticScale    = false;
            bool       useStaticRotation = false;
            float      unitScaleFactor   = analysisObject.UnitConversionFactor;

            if (objectXml.PositionXSource.Length == 0 || objectXml.PositionYSource.Length == 0 || objectXml.PositionZSource.Length == 0)
            {
                staticPosition    = Vector3.zero;
                useStaticPosition = true;
            }
            else if (IsLiteral(objectXml.PositionXSource) && IsLiteral(objectXml.PositionYSource) && IsLiteral(objectXml.PositionZSource))
            {
                staticPosition    = ParseStaticPosition(objectXml.PositionXSource, objectXml.PositionYSource, objectXml.PositionZSource, unitScaleFactor);
                useStaticPosition = true;
            }

            if (objectXml.ScaleXSource.Length == 0 || objectXml.ScaleYSource.Length == 0 || objectXml.ScaleZSource.Length == 0)
            {
                staticScale    = Vector3.one;
                useStaticScale = true;
            }
            else if (IsLiteral(objectXml.ScaleXSource) && IsLiteral(objectXml.ScaleYSource) && IsLiteral(objectXml.ScaleZSource))
            {
                staticScale    = ParseStaticScale(objectXml.ScaleXSource, objectXml.ScaleYSource, objectXml.ScaleZSource);
                useStaticScale = true;
            }

            if (objectXml.RotationXSource.Length == 0 || objectXml.RotationYSource.Length == 0 || objectXml.RotationZSource.Length == 0)
            {
                staticRotation    = Quaternion.identity;
                useStaticRotation = true;
            }
            else if (objectXml.RotationWSource.Length == 0)
            {
                if (IsLiteral(objectXml.RotationXSource) && IsLiteral(objectXml.RotationYSource) && IsLiteral(objectXml.RotationZSource))
                {
                    staticRotation    = ParseStaticRotation(objectXml.RotationXSource, objectXml.RotationYSource, objectXml.RotationZSource, objectXml.RotationFormat);
                    useStaticRotation = true;
                }
            }
            else
            {
                if (IsLiteral(objectXml.RotationWSource) && IsLiteral(objectXml.RotationXSource) && IsLiteral(objectXml.RotationYSource) && IsLiteral(objectXml.RotationZSource))
                {
                    staticRotation    = ParseStaticRotation(objectXml.RotationWSource, objectXml.RotationXSource, objectXml.RotationYSource, objectXml.RotationZSource);
                    useStaticRotation = true;
                }
            }

            // assign static data to analysis object
            analysisObject.UseStaticPosition = useStaticPosition;
            analysisObject.UseStaticRotation = useStaticRotation;
            analysisObject.UseStaticScale    = useStaticScale;
            analysisObject.LocalPosition     = staticPosition;
            analysisObject.LocalRotation     = staticRotation;
            analysisObject.LocalScale        = staticScale;

            return(analysisObject);
        }
Ejemplo n.º 3
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);
        }