Deviations between points and a wall

Deviations between points and a wall

helene.macher
Participant Participant
2,107 Views
4 Replies
Message 1 of 5

Deviations between points and a wall

helene.macher
Participant
Participant

Hi everybody,

 

As mentioned in the title, I want to compute the deviations between points belonging to a point cloud and a wall and display the deviations with a colormap. I already managed to do the following steps:

 

1. Prompt the user to select a wall and a point cloud

 

2. Filter the points located in a given distance of the wall (to select points of interest)

PointCloudFilter filter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);
PointCollection points = pointCloudInstance.GetPoints (filter,0.000001,999999);

3. Calculate the distances between the collected points and the wall using a foreach loop and the ReferenceIntersector class

List<double> list = new List<double>();
foreach (CloudPoint point in points)
   {
     XYZ tpoint = trf.OfPoint(point);
     double length = CalculateDeviation(doc, wall, tpoint, orientation);
     list.Add(length);
   }

private Double CalculateDeviation(Document doc, Wall wall, XYZ origin, XYZ rayDirection)
    {
        FilteredElementCollector collector = new FilteredElementCollector(doc);
        bool isNotTemplate(View v3) => !(v3.IsTemplate);
        View3D view3D = collector.OfClass(typeof(View3D)).Cast<View3D().First<View3D (isNotTemplate);
        ElementId eid = wall.Id as ElementId;
        ReferenceIntersector refIntersector = new ReferenceIntersector(eid, FindReferenceTarget.All, view3D);
        ReferenceWithContext referenceWithContext = refIntersector.FindNearest(origin, rayDirection);

        if (referenceWithContext != null)
        {
            Reference reference = referenceWithContext.GetReference();
            XYZ intersection = reference.GlobalPoint;
            
            double length = intersection.DistanceTo(origin);
            return length;
        }
    }

I manage to calculate the deviations but since I would like to calculate deviations for as much as possible points (numPoints = 999999 for the GetPoints method of pointCloudInstance) to see small deformations, it takes really a long time.

 

I started programming in C# only two weeks ago so my first question is can I reduce the time required for the calculation of deviations either by modifying some functions or using an other method.

 

Moreover, I would like to display the deviations by applying a custom colormap to points. I already have a look at the help documentation (PointCloudColorSettings and PointCloudColorMode) but I’m not sure I can do that. Do you have any idea if it’s possible or not?

 

Thanks in advance,

Hélène

 

0 Likes
Accepted solutions (2)
2,108 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution

You can definitely improve performance by not filtering for a 3D view with every point iteration i.e. find the View3D higher up and pass into the CalculateDeviation function.

 

Unclear on what direction you are using for the ray? If you obtain the faces of the wall you can get the distance of a point from the face by using Face.Project method and reading Distance property of IntersectionResult.

 

I'm not overly familiar with the use of point clouds within the API but each CloudPoint appears to have a color field set by integer. Have you tried setting this? Would probably have to do it in combination with correct PointCloudColorMode value, probably PointCloudColorMode.NoOverride by the look of it.

 

Integer color value obtained as follows

https://forums.autodesk.com/t5/revit-api-forum/how-to-change-text-color/m-p/7812764/highlight/true#M...

 

Failing that CloudPoint derives from element and most elements can have their colour overridden in view (View.SetElementOverrides). However it seems like the first option is the intended approach.

 

There is a property PointCloudInstance.SupportsOverrides so evidently not all point clouds support overrides for some reason.

0 Likes
Message 3 of 5

helene.macher
Participant
Participant

Thank you very much for your answer.

 

Indeed, if I find the View3D higher up and pass it into CalculateDeviation function it improves the performance but it is still not so fast. I should have saw that.

 

The direction I use for the ray is the orientation of the wall. Following your advise I had a closer look to the properties of a wall and the methods associated to the faces and I found a faster way to calculate the deviations. Before the foreach loop, I find the two faces with the normal corresponding to the orientation. Then in the foreach loop I determine the distances between a point and the two faces and I keep the smallest one. Now, I can calculate deviations for 1M points only in a few seconds.

 

Regarding the color of the points, I will do more research and try your first option. I will perhaps post a more detailed question about that if I still don't manage to do this.

 

Best,

Hélène

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Hélène,

 

You can use the analysis visualisation framework AVF to display a colour map on the wall face:

 

http://thebuildingcoder.typepad.com/blog/avf

 

You could project the deviations of the points into colours in the colour map.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 5

helene.macher
Participant
Participant

Let me summarize the different ways to apply a colormap to a point cloud for those who are interested with this subject.

I first tried to set the Colorfield of points contained in a PointCollection directly in my foreach loop. Unfortunately, it seems that I can access the Color of a point (point.Color) but I can’t set it. My understanding is that points in PointCollection are in a read-only mode but perhaps I am wrong.

Therefore, I had a look to the Analysis Visualization Framework (AVF). Thank you very much Jeremy, I didn’t know AVF. AVF enables to draw color graphics on the screen in a Revit Project. The results data is transient; it is stored only in the model until the document is closed. There are two options:

 

OPTION 1: AVF – Analysis display with markers
A new point cloud is created and colorized based on the deviations from the wall. This requires XYZ points and values attributed to these points (distances from the wall in my case). In order to do this, the point cloud has to be splitted into smaller ones (it is recommended to create multiple primitives with no more than 500 points; I tried multiple primitives with 1000 points and it works). Additionally, the number of points is limited to around 800000 according to my readings.

 

Display with markers - Visual Style: Hidden LineDisplay with markers - Visual Style: Hidden LineDisplay with markers - Visual Style: WireframeDisplay with markers - Visual Style: Wireframe

OPTION 2: AVF – Analysis display on wall surface
Wall face is colorized based on deviation values. This requires UV points i.e. points in the local coordinate system of the wall and values attributed to these points. I calculated the projection of the XYZ points into the wall face to obtain the UV points (IntersectionResult ir = face.Project(p); UV uvpoint = ir.UVPoint;). Of course, I have to separate the deviations for the two sides of the wall.

 

Display on surface - Result offset from the wall faceDisplay on surface - Result offset from the wall face

The benefit of using markers is that we can see occluded parts of a wall. For a colorized surface, color values are also assigned to occluded parts (interpolation of the color even if there is no points). But perhaps a colorized surface is more suitable for visualization purpose because markers are located both inside and outside the wall. I can use the Wireframe visual style to see all the points but it make the colormap disappear (see images above). I still don’t have decided which option is the better one. I have to do some tests on a bigger project with much more points to determine which is the most suitable.

The last thing I have to address is how to manage the views. I am not familiar with views in Revit. Currently I use the default 3D view to display the result but I would like to create a new view with only the analyzed wall and the result of the analysis. However, I don’t want that this view affect the others.