Exemple #1
0
        public void LoadAnalysisVisualizationValues(IEnumerable <AGCElement> elems, string visualizationName, string schemeName, IList <string> unitNames, IList <double> unitMultipliers)
        {
            var numOfMeasurments = GetMaxNumOfMeasurments(elems);
            var sfm          = GetSpatialFieldManager(numOfMeasurments);
            var resultSchema = new AnalysisResultSchema(schemeName, visualizationName);

            resultSchema.SetUnits(unitNames, unitMultipliers);
            var schemaIdx = sfm.RegisterResult(resultSchema);

            foreach (var elem in elems)
            {
                foreach (var faceVals in elem.FaceUVValues)
                {
                    if (null != faceVals)
                    {
                        var primIdx = sfm.AddSpatialFieldPrimitive(faceVals.Face, Transform.Identity);
                        try {
                            var paramUVs           = new List <UV>();
                            var paramUVValsAtPoint = new List <ValueAtPoint>();
                            foreach (var vals in faceVals)
                            {
                                paramUVs.Add(vals.Key);
                                paramUVValsAtPoint.Add(new ValueAtPoint(vals.Value));
                            }
                            var domPts    = new FieldDomainPointsByUV(paramUVs);
                            var fieldVals = new FieldValues(paramUVValsAtPoint);
                            sfm.UpdateSpatialFieldPrimitive(primIdx, domPts, fieldVals, schemaIdx);
                        } catch (Exception x) {
                            sfm.RemoveSpatialFieldPrimitive(primIdx);
                            GCLogger.AppendLine("Failed to add face values: {0}, {1}", x.Message, x.StackTrace);
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Set up the AVF spatial field manager
        /// for the given view.
        /// </summary>
        static void SetUpAvfSfm(
            View view,
            Reference faceReference)
        {
            if (view.AnalysisDisplayStyleId
                == ElementId.InvalidElementId)
            {
                SetAvfDisplayStyle(view);
            }

            _sfm = SpatialFieldManager
                   .GetSpatialFieldManager(view);

            if (null == _sfm)
            {
                _sfm = SpatialFieldManager
                       .CreateSpatialFieldManager(view, 1);
            }
            else if (0 < _sfp_index)
            {
                _sfm.RemoveSpatialFieldPrimitive(
                    _sfp_index);
            }

            _sfp_index = _sfm.AddSpatialFieldPrimitive(
                faceReference);

            if (-1 != _schemaId)
            {
                IList <int> results = _sfm.GetRegisteredResults();
                if (!results.Contains(_schemaId))
                {
                    _schemaId = -1;
                }
            }

            if (-1 == _schemaId)
            {
                AnalysisResultSchema schema
                    = new AnalysisResultSchema("Attenuation",
                                               "RvtFader signal attenuation");

                List <string> unitNames = new List <string>(new string[1] {
                    "dB"
                });
                List <double> unitFactors = new List <double>(new double[1] {
                    1.0
                });
                schema.SetUnits(unitNames, unitFactors);

                _schemaId = _sfm.RegisterResult(schema);
            }
        }
Exemple #3
0
        private static AnalysisResultSchema CreateResultSchemaWithUnitNames()
        {
            var resultSchema = new AnalysisResultSchema(
                // the name value of an AnalysisResultSchema must be unique, hence Date-Seconds
                "Space Syntax from " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"),
                "Space Syntax");

            var unitNames = new List <string>();

            unitNames.Add("Points");

            var multipliers = new List <double>();

            multipliers.Add(1.0);

            resultSchema.SetUnits(unitNames, multipliers);

            return(resultSchema);
        }
Exemple #4
0
        /// <summary>
        /// Get the AnalysisResultsSchemaIndex for the SpatialFieldManager
        /// </summary>
        /// <returns></returns>
        protected virtual int GetAnalysisResultSchemaIndex(string resultsSchemaName, string resultsDescription, Type unitType)
        {
            // Get the AnalysisResultSchema index - there is only one for Dynamo
            var schemaIndex = 0;

            if (!SpatialFieldManager.IsResultSchemaNameUnique(resultsSchemaName, -1))
            {
                var arses = SpatialFieldManager.GetRegisteredResults();
                schemaIndex =
                    arses.First(
                        x => SpatialFieldManager.GetResultSchema(x).Name == resultsSchemaName);
            }
            else
            {
                var ars = new AnalysisResultSchema(resultsSchemaName, resultsDescription);

                if (unitType != null)
                {
                    if (typeof(SIUnit).IsAssignableFrom(unitType))
                    {
                        var prop        = unitType.GetProperty("Conversions");
                        var conversions = (Dictionary <string, double>)prop.GetValue(null, new object[] { });
                        if (conversions != null)
                        {
                            var unitNames   = conversions.Keys.ToList();
                            var multipliers = conversions.Values.ToList();
                            ars.SetUnits(unitNames, multipliers);
                            ars.CurrentUnits = 0;
                        }
                    }
                }

                schemaIndex = SpatialFieldManager.RegisterResult(ars);
            }

            return(schemaIndex);
        }
Exemple #5
0
        public bool AnalysisByElements()
        {
            bool result = false;

            try
            {
                if (areaDictionary.Count > 0)
                {
                    int  resultIndex = FindIndexOfResult(sfm);
                    bool firstLoop   = true;
                    foreach (int areaId in areaDictionary.Keys)
                    {
                        AreaProperties ap      = areaDictionary[areaId];
                        List <double>  dblList = new List <double>(); //double values to be displayed on the face.
                        Face           face    = ap.BaseFace;
                        dblList.Add(ap.FAR);

                        if (dblList.Count != sfm.NumberOfMeasurements)
                        {
                            continue;
                        }

                        int                  index   = sfm.AddSpatialFieldPrimitive(face, Transform.Identity);
                        IList <UV>           uvPts   = new List <UV>();
                        IList <ValueAtPoint> valList = new List <ValueAtPoint>();
                        BoundingBoxUV        bb      = face.GetBoundingBox();
                        UV faceCenter = (bb.Min + bb.Max) / 2; //only collect a center point.

                        uvPts.Add(faceCenter);
                        valList.Add(new ValueAtPoint(dblList));
                        //dblList.Clear();

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

                        AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                        resultSchema.SetUnits(unitNames, multipliers);
                        if (unitNames.Contains(settings.Units))
                        {
                            resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                        }

                        if (overwriteResult)
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }
                        else if (firstLoop)
                        {
                            resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                        }
                        else
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }

                        sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                    }
                    SetCurrentStyle();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to visulaize the FAR data. \n" + ex.Message, "FARCalculator : AnalysisByElements", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
Exemple #6
0
        public bool AnalysisByElements()
        {
            bool result = false;

            try
            {
                if (radianceDictionary.Count > 0)
                {
                    int                  resultIndex = FindIndexOfResult(sfm);
                    bool                 firstLoop   = true;
                    int                  index       = sfm.AddSpatialFieldPrimitive();//not associated with any geometry
                    IList <XYZ>          xyzPoints   = new List <XYZ>();
                    IList <ValueAtPoint> valList     = new List <ValueAtPoint>();

                    foreach (int keyIndex in radianceDictionary.Keys)
                    {
                        RadianceResult rr      = radianceDictionary[keyIndex];
                        List <double>  dblList = new List <double>(); //double values to be displayed on the face.

                        dblList.Add(rr.Value1);
                        dblList.Add(rr.Value2);
                        dblList.Add(rr.Value3);

                        if (dblList.Count != sfm.NumberOfMeasurements)
                        {
                            continue;
                        }

                        xyzPoints.Add(rr.PointXYZ);
                        valList.Add(new ValueAtPoint(dblList));
                        //dblList.Clear();
                    }
                    FieldDomainPointsByXYZ domainPoints = new FieldDomainPointsByXYZ(xyzPoints);
                    FieldValues            values       = new FieldValues(valList);

                    AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                    resultSchema.SetUnits(unitNames, multipliers);
                    if (unitNames.Contains(settings.Units))
                    {
                        resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                    }

                    if (overwriteResult)
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }
                    else if (firstLoop)
                    {
                        resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                    }
                    else
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }

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

                    SetCurrentStyle();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to visulaize the FAR data. \n" + ex.Message, "FARCalculator : AnalysisByElements", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
        /// <summary>
        /// Create Visualization framework for view
        /// </summary>
        /// <param name="uvPts"></param>
        /// <param name="valList"></param>
        /// <param name="calcFace"></param>
        /// <param name="faceTransform"></param>
        private void DoVisualization(IList<UV> uvPts, IList<ValueAtPoint> valList, Face calcFace, Transform faceTransform)
        {
            // Visualization framework
            FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts);
            FieldValues vals = new FieldValues(valList);
            AnalysisResultSchema resultSchema = new AnalysisResultSchema("Point by Point", "Illumination Point-by-Point");

            // Units
            IList<string> names = new List<string> { "FC" };
            IList<double> multipliers = new List<double> { 1 };
            resultSchema.SetUnits(names, multipliers);

            // Add field primative to view
            int idx = m_sfm.AddSpatialFieldPrimitive(calcFace, faceTransform);
            int resultIndex = m_sfm.RegisterResult(resultSchema);

            // Update Field Primatives
            m_sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, resultIndex);
        }
Exemple #8
0
        //accumulative values on grid points
        private bool MeasureAccDistance()
        {
            bool result = false;

            try
            {
                //find walls located inside the selected rooms
                FindWallFacesOnRoom();

                //Find point of view from the sphere element
                FamilyInstance sphere = FindPointOfView();
                if (null != sphere)
                {
                    LocationPoint location = sphere.Location as LocationPoint;
                    XYZ           pointXYZ = location.Point;
                    XYZ           vectorZ  = new XYZ(0, 0, 1);
#if RELEASE2013
                    Transform transform = Transform.get_Translation(vectorZ);
#else
                    Transform transform = Transform.CreateTranslation(vectorZ);
#endif

                    int  resultIndex = FindIndexOfResult(sfm);
                    bool firstLoop   = true;
                    foreach (int roomId in roomFaces.Keys)
                    {
                        Face                 roomFace    = roomFaces[roomId];
                        int                  index       = sfm.AddSpatialFieldPrimitive(roomFace, transform);
                        List <double>        doubleList  = new List <double>();
                        IList <UV>           uvPoints    = new List <UV>();
                        IList <ValueAtPoint> valList     = new List <ValueAtPoint>();
                        BoundingBoxUV        boundingBox = roomFace.GetBoundingBox();
                        for (double u = boundingBox.Min.U; u < boundingBox.Max.U; u = u + (boundingBox.Max.U - boundingBox.Min.U) / 15)
                        {
                            for (double v = boundingBox.Min.V; v < boundingBox.Max.V; v = v + (boundingBox.Max.V - boundingBox.Min.V) / 15)
                            {
                                UV  uvPoint  = new UV(u, v);
                                XYZ xyzPoint = roomFace.Evaluate(uvPoint);
                                uvPoints.Add(uvPoint);
#if RELEASE2013
                                Line line = doc.Application.Create.NewLine(pointXYZ, xyzPoint, true);
#else
                                Line line = Line.CreateBound(pointXYZ, xyzPoint);
#endif
                                //double dblValue = 1 / (line.ApproximateLength);
                                double dblValue = 1;

                                IntersectionResultArray resultArray;
                                foreach (int wallId in wallFaces.Keys)
                                {
                                    Face wallFace = wallFaces[wallId];
                                    SetComparisonResult compResult = wallFace.Intersect(line, out resultArray);
                                    if (compResult == SetComparisonResult.Overlap && null != resultArray)
                                    {
                                        if (dblValue > 0)
                                        {
                                            dblValue = 0 - resultArray.Size;
                                        }
                                        else
                                        {
                                            dblValue = -resultArray.Size;
                                        }
                                    }
                                }
                                doubleList.Add(dblValue);
                                valList.Add(new ValueAtPoint(doubleList));
                                doubleList.Clear();
                            }
                        }

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

                        AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                        resultSchema.SetUnits(unitNames, multipliers);
                        if (unitNames.Contains(settings.Units))
                        {
                            resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                        }

                        if (overwriteResult)
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }
                        else if (firstLoop)
                        {
                            resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                        }
                        else
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }

                        sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to measure distance from the point element to the points on Room face.\n" + ex.Message, "FieldOfViewAnalysis", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                result = false;
            }
            return(result);
        }
        private bool AnalysisByFaces(SpatialFieldManager sfm)
        {
            bool result = false;

            progressBar.Maximum = settings.SelectedElements.Count;
            try
            {
                Options options = new Options();
                options.ComputeReferences = true;

                Dictionary <ElementId, Dictionary <Reference, Face> > selectedFaces = new Dictionary <ElementId, Dictionary <Reference, Face> >();
                selectedFaces = settings.SelectedFaces;

                Dictionary <Face, Dictionary <Reference, List <double> /*paramValues*/> > faceDictionary = new Dictionary <Face, Dictionary <Reference, List <double> /*paramValues*/> >();
                foreach (Element element in settings.SelectedElements)
                {
                    ElementId elementId = element.Id;
                    if (!selectedFaces.ContainsKey(elementId))
                    {
                        continue;
                    }

                    List <double> valueLists = new List <double>();
                    foreach (string paramName in settings.Configurations.Keys)
                    {
#if RELEASE2015 || RELEASE2016 || RELEASE2017
                        Parameter param = element.LookupParameter(paramName);
#else
                        Parameter param = element.get_Parameter(paramName);
#endif

                        if (param != null)
                        {
                            double value = param.AsDouble();
                            valueLists.Add(value);
                        }
                        else
                        {
                            valueLists.Add(0);
                        }
                    }

                    foreach (Reference reference in selectedFaces[elementId].Keys)
                    {
                        if (null != selectedFaces[elementId][reference] && valueLists.Count == settings.NumberOfMeasurement)
                        {
                            Face face = selectedFaces[elementId][reference];
                            faceDictionary.Add(face, new Dictionary <Reference, List <double> >());
                            faceDictionary[face].Add(reference, valueLists);
                            //break;
                        }
                    }
                    progressBar.PerformStep();
                }

                int  resultIndex = FindIndexOfResult(sfm);
                bool firstLoop   = true;
                foreach (Face face in faceDictionary.Keys)
                {
                    Reference     reference = faceDictionary[face].Keys.First();
                    List <double> dblList   = new List <double>();//double values to be displayed on the face.
                    dblList = faceDictionary[face][reference];
                    int                  index   = sfm.AddSpatialFieldPrimitive(reference);
                    IList <UV>           uvPts   = new List <UV>();
                    IList <ValueAtPoint> valList = new List <ValueAtPoint>();
                    BoundingBoxUV        bb      = face.GetBoundingBox();
                    UV faceCenter = (bb.Min + bb.Max) / 2; //only collect a center point.

                    uvPts.Add(faceCenter);
                    valList.Add(new ValueAtPoint(dblList));
                    //dblList.Clear();

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

                    AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                    resultSchema.SetUnits(unitNames, multipliers);
                    if (unitNames.Contains(settings.Units))
                    {
                        resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                    }

                    if (overwriteResult)
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }
                    else if (firstLoop)
                    {
                        resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                    }
                    else
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }

                    sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                }
                SetCurrentStyle();
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to analyze elements. \n" + ex.Message, "AnalysisDataManager : ElementAnalysis", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
        /// <summary>
        /// The unique name for Dynamo's Analysis Results.  Used to identify
        /// the results scheme.
        /// </summary>
        //protected static string ResultsSchemaName = "Dynamo Analysis Results";

        /// <summary>
        /// Get the AnalysisResultsSchemaIndex for the SpatialFieldManager
        /// </summary>
        /// <returns></returns>
        protected virtual int GetAnalysisResultSchemaIndex(string resultsSchemaName, string resultsDescription, Type unitType)
        {
            // Get the AnalysisResultSchema index - there is only one for Dynamo
            var schemaIndex = 0;
            if (!SpatialFieldManager.IsResultSchemaNameUnique(resultsSchemaName, -1))
            {
                var arses = SpatialFieldManager.GetRegisteredResults();
                schemaIndex =
                    arses.First(
                        x => SpatialFieldManager.GetResultSchema(x).Name == resultsSchemaName);
            }
            else
            {
                var ars = new AnalysisResultSchema(resultsSchemaName, resultsDescription);
                
                if (unitType != null)
                {
                    if (typeof(SIUnit).IsAssignableFrom(unitType))
                    {
                        var prop = unitType.GetProperty("Conversions");
                        var conversions = (Dictionary<string, double>)prop.GetValue(null, new object[] { });
                        if (conversions != null)
                        {
                            var unitNames = conversions.Keys.ToList();
                            var multipliers = conversions.Values.ToList();
                            ars.SetUnits(unitNames, multipliers);
                            ars.CurrentUnits = 0;
                        }
                    }
                }

                schemaIndex = SpatialFieldManager.RegisterResult(ars);
            }

            return schemaIndex;
        }