public bool ReadResults()
        {
            bool result = false;

            try
            {
                if (File.Exists(dataFilePath))
                {
                    string extension = Path.GetExtension(dataFilePath);
                    if (extension == ".dat")
                    {
                        if (dataFilePath.EndsWith("df.dat"))
                        {
                            analysisType = DataType.Daylight_Factor;
                        }
                        else
                        {
                            analysisType = DataType.Radiation_Map;
                        }
                    }
                    else if (extension == ".DA")
                    {
                        analysisType = DataType.Daylight_Autonomy;
                    }

                    int index = 0;
                    using (StreamReader reader = new StreamReader(dataFilePath))
                    {
                        string line      = string.Empty;
                        char[] delimiter = { ' ', '\t' };

                        while ((line = reader.ReadLine()) != null)
                        {
                            if (line.StartsWith("#"))
                            {
                                continue;
                            }
                            string[]      splitVals = line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                            DataContainer container = new DataContainer();
                            container.Index = index;

                            if (analysisType == DataType.Daylight_Factor || analysisType == DataType.Radiation_Map) //dat file
                            {
                                NodePoint node   = new NodePoint(double.Parse(splitVals[0]), double.Parse(splitVals[1]), double.Parse(splitVals[2]));
                                double    rVal   = double.Parse(splitVals[6]);
                                double    gVal   = double.Parse(splitVals[7]);
                                double    bVal   = double.Parse(splitVals[8]);
                                double    calVal = (rVal * 0.265 + gVal * 0.67 + bVal * 0.065) * 179;

                                container.Node        = node;
                                container.ResultValue = calVal;
                            }
                            else if (analysisType == DataType.Daylight_Autonomy) //da file
                            {
                                NodePoint node  = new NodePoint(double.Parse(splitVals[0]), double.Parse(splitVals[1]), double.Parse(splitVals[2]));
                                double    daVal = double.Parse(splitVals[3]);

                                container.Node        = node;
                                container.ResultValue = daVal;
                            }

                            if (dataDictionary.ContainsKey(index))
                            {
                                dataDictionary.Remove(index);
                            }
                            dataDictionary.Add(index, container);
                            index++;
                        }
                        reader.Close();
                    }
                    result = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read result data.\n" + ex.Message, "Analysis Data Manager - Read Results", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
        public bool VisualizeData()
        {
            bool result = false;

            try
            {
                string    viewIdValue       = RegistryKeyManager.GetRegistryKeyValue("RevitOutgoingViewId");
                ElementId viewId            = new ElementId(int.Parse(viewIdValue));
                Autodesk.Revit.DB.View view = m_doc.GetElement(viewId) as Autodesk.Revit.DB.View;
                if (null != view)
                {
                    SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view);
                    if (null == sfm)
                    {
                        sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1);
                    }
                    AnalysisResultSchema resultSchema = new AnalysisResultSchema(analysisType.ToString(), "Imported from DIVA");

                    int resultIndex = -1;

                    //check order
                    DataContainer      tempContainer = dataDictionary[0];
                    XYZ                node          = new XYZ(tempContainer.Node.XValue, tempContainer.Node.YValue, tempContainer.Node.ZValue);
                    IntersectionResult intersection  = displayingFaces[0].Project(node);
                    if (null == intersection)
                    {
                        displayingFaces.Reverse();
                    }                                                        //reverse the order of faces

                    foreach (int keyIndex in dataDictionary.Keys)
                    {
                        DataContainer container = dataDictionary[keyIndex];
                        Face          face      = displayingFaces[keyIndex];
                        List <double> dblList   = new List <double>();
                        dblList.Add(container.ResultValue);

                        XYZ                  vectorZ   = new XYZ(0, 0, -1);
                        Transform            transform = Transform.CreateTranslation(vectorZ);
                        int                  index     = sfm.AddSpatialFieldPrimitive(face, transform);
                        IList <UV>           uvPts     = new List <UV>();
                        IList <ValueAtPoint> valList   = new List <ValueAtPoint>();

                        XYZ nodePoint = new XYZ(container.Node.XValue, container.Node.YValue, container.Node.ZValue);
                        IntersectionResult intersect = face.Project(nodePoint);
                        if (null != intersect)
                        {
                            UV nodeUV = intersect.UVPoint;
                            uvPts.Add(nodeUV);
                            valList.Add(new ValueAtPoint(dblList));

                            FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPts);
                            FieldValues           values       = new FieldValues(valList);

                            FieldValues vals = new FieldValues(valList);

                            if (resultIndex == -1)
                            {
                                resultIndex = sfm.RegisterResult(resultSchema);
                            }
                            else
                            {
                                sfm.SetResultSchema(resultIndex, resultSchema);
                            }

                            sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                        }

                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to visualize the result data.\n" + ex.Message, "Analysis Data Manager - Visualize Data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                result = false;
            }
            return(result);
        }