Faster generation of fan geometry to visualize laser

I am trying to visualize data from a laser range-finder. I got some excellent help earlier ( … highlight= ) and came up with the visualization and code below. Basically, the data comes in as a list of ranges, a start degree, and a degree increment, and I adapted some code from clcheung’s demomaster to procedurally generate the corresponding geometry. (Note: the map in the visualization is imported to panda separately from the laser data via an entirely different system.)

The problem is now that I need to be able to do it faster. The sensor gives me 10 readings a second, each of which consists of 1081 ranges. Even when I downsample so that I only take 1 reading a second and only 108 ranges per reading, the system halts noticeably (~.1 second) every time a new reading is rendered. Of course, ideally I wouldn’t have to downsample at all, but I really need to be able to get at least 270 ranges per reading with 2 readings per second. Any advice?

As always, thanks so much for the help.

    def _getVisualization(self, ranges, angleMin, angleIncrement):
        vis = NodePath('Laser Visualization')
        self._getWedgeHalo(ranges, angleMin, angleIncrement).reparentTo(vis)
        self._getBoarder(ranges, angleMin, angleIncrement).reparentTo(vis)
        return vis
    def _getWedgeHalo(self, ranges, startDegree, degreesBetweenReadings):
        """Make the laser lensor display vis.
        degreesBetweenReadings -- the angle measurement between each reading
        startDegree -- the measure of the angle between straight forward and the first laser beam.  default is 0.  Directly to the right is -90
        returns a NodePath to the wedge vis
        pointList = self._getPoints(ranges, startDegree, degreesBetweenReadings)
        #copied from "makeEggWedge"
        data = EggData()
        vp = EggVertexPool('fan')
        poly = EggPolygon()
        v = EggVertex()
        v.setPos(pointList[0])#changed from makeEggWedge
        for point in pointList:
            v = EggVertex()
        #make last point at 0,0,0
        v = EggVertex()
        node = loadEggData(data)
        np = NodePath(node)
        return NodePath(node)
    def _getBoarder(self, distanceList, startDegree, degreesBetweenReadings):
        """Draw Arc"""
        pointList = self._getPoints(distanceList, startDegree, degreesBetweenReadings)
        ls = LineSegs()
        ls.setColor(0,0,.2, 1)
        for point in pointList:

        node = ls.create()
        return NodePath(node)

As we discussed in previous post, it is better to use the other two ways suggested. Dynamic model generation is too slow.

Since your requirement is just a 2D look, may be you can just update a 2D texture instead of keep generating models ?

If you really want to squeeze every microsecond out of it, implement the geometry-generation in C++ - it will be just a bit faster.

Simply using the GeomVertexWriter mechanism of dynamic geometry generation, rather than going through the egg loader, will probably make a huge improvement in performance, without having to abandon Python.


Fantastic! Thank you all so much. Switching from the egg loader to the GeomVertex writer completely eliminated the need for down-sampling.

You may try MeshDrawer for even more speed.