Hi, All:
For context, I am working on interference elimination between a spindle/cutter and a work piece. There are numerous algorithms available from which to detect interference, but the program must iterate the spindle/cutter out of the interference state by rotational adjustment. In addition to code efficiency, I find that visual inspection of the “attack angle” improves my confidence that selected algorithm is doing its job in all areas of the work piece. For simplification, the work piece is meshed, and the attack angle is determined by the normal vector from the mesh face in addition to angular adjustment when required. From the screen grabs below, the mesh faces that need angular adjustment are converted to Breps and displayed in red.
The respective mesh face number is also displayed to isolate errant interference calculations. (I hope to learn about transparency, but that isn’t top of mind just now.)
Given the context, though there are a number of posts regarding DisplayConduit and the use of caching or “buckets” to improve the frame rate of Rhino viewports, I am still struggling to implement the swiftest algorithm.
For the Brep faces that signify angular adjustment, the DisplayConduit class is inherited by the VIZ_Evalute class, and has a property of a List<RhinoList>. (These are a list of lists of Breps as there are 13 milling levels in this example. The less curved Breps have fewer or no interference faces.)
public static List<RhinoList<Brep>>? CachedIntFerBreps { get; set; }
The milling level to display is selected from the List< RhinoLists> by the LvlBrepMeshNo integer and drawn within the PreDrawObjects event. A similar pattern is used when displaying the mesh face numbers.
protected override void PreDrawObjects(DrawEventArgs e)
if (MathParams.Viz_IntFerFaces)
{
List<RhinoList<Brep>> IntFers = CachedIntFerBreps;
RhinoList<Brep> intFerFaces = IntFers[GetParams.LvlBrepMeshNo];
foreach(Brep face in intFerFaces)
{
DisplayMaterial BrepMat3 = new DisplayMaterial();
BrepMat3.Transparency = .2;
BrepMat3.Diffuse = System.Drawing.Color.Red;
e.Display.DrawBrepShaded(face, BrepMat3);
}
}
It seems obvious that a foreach loop within the PreDrawObjects event delays output of the viewport frame. The question is how to make the display faster as Rhino is pushing events to the DisplayConduit with every mouse motion in the viewport.
Options I have considered are:
-
Before reaching PreDrawObjects event, create a mesh that includes Mesh, Brep faces and the mesh face numbers for each milling level. To have a preconstructed “thing” to draw, this seems the fastest, but the “thing” will take some time to create. However, during an evaluation cycle, each milling level only needs to be created once. Not sure how to make such a mesh but I am willing to try.
-
Push the face Breps and face numbers to an Array, and then use Span to iterate the array within the PreDrawObject event.
A face Brep seems is a heavy object to display in multiples, would a DrawSurface method be faster?
Can an object be create that holds all three elements: mesh, Brep, and face numbers, and an instance of that object be displayed with the DrawObject method? (A separate instance for each milling level.)
Would appreciate any advise and examples.
Thanks,
Dave