Re: [PyOpenGL-Users] Pyopengl - slow performance using
Brought to you by:
mcfletch
From: Jonathan H. <ta...@ta...> - 2011-01-13 12:16:30
|
On 13/01/2011 11:29, pm...@gm... wrote: > Hi all, > > I am developing an application using pyopenGL to read data from a shape file and to draw it in 2D using openGl. However, the performance is really bad; it takes up to 20 seconds to draw the map. I am using Ubuntu and nVidia NVS 3100M. > > The shape file being read has the following characteristics: > > - 50 000 entries containing the description roads segments; each road segment has the associated geometry (set of (x,y) points ) > - +/- 350 000 points in total > > > A simplified version of the code is shown bellow: > > a) to get data from shapefile (using pyshapelib) and store it in a list of lists of tuples (python): > ... > self.shp = [] > self.extents = [] > self.array = [] > ... > self.shp = shapelib.ShapeFile(filename) > for i in range(self.shp.info()[0]): > lineVert = self.shp.read_object(i).vertices() > tempArray = [] > for j in lineVert[0]: > tempArray.append([j[0],j[1]]) > self.array.append(tempArray) > > b) to draw the data using pyopenGL: > ... > glEnableClientState(GL_VERTEX_ARRAY) > # obtained from the shapefile(array element) > arrayList = self.map.getArrayList() > if len(arrayList)> 0: > for objMap in arrayList: > self.drawPolyline(objMap) > > def drawPolyline(self,inArray): > #glColor(1.0, 0.0, 0.0) > glVertexPointerf(inArray) > glDrawArrays(GL_LINE_STRIP, 0, len(inArray)) > > - Do you have any hints how to improve the performance dramatically and make it usable? I tried several options but none worked out. For instance I tried to replace python list with numpy arrays but the performance was not significantly changed. > > - Do I need execute the OpenGL code in C? Altough I could do this, I still need to use python as scripting language due to other dependencies of the implementation. > > Thank you in advance for your help! > > Best Regards, > > Pedro > Hey there, Have you profiled or timed your code to see precisely which parts are taking all the time? Personally I highly recommend using RunSnakeRun to draw diagrams from the output of stdlib cProfile. Let me know if you'd like to do this but are having problems, I'll help you out. Since GIS data is mostly static (i.e. not animated), so that you don't need to process every vertex every frame, I would be very surprised if you had to move from Python to C for performance reasons. I am confident that you will be able to optimise this code to be fast. I'd guess that part (a) of the code, constructing the arrays, is probably pretty expensive, since you are processing every individual vertex. Importantly, this code should only need to be run at application start-up, not every frame, is this correct? Also, in part (b) of the code, where you loop over the objects in arrayList: for objMap in arrayList: self.drawPolyline(objMap) I can see that the value of objMap represents a vertex array, but how many vertices are generally in it? You may find substantial acceleration from increasing the number of vertices in an array, and hence decreasing the number of times this loop needs to iterate. In order to do this, you will need to put the arrays for several roads into a single array. I don't know whether it will be useful to put the vertices for *all* roads into a single array - there may be an upper limit on the useful size of vertex arrays. Doubtless someone cleverer than me on the list will know this. Also, a very minor point: if len(arrayList)> 0: for objMap in arrayList: self.drawPolyline(objMap) If arrayList is a normal Python iterable (e.g. a list), then this could be written more simply as: for objMap in arrayList: self.drawPolyline(objMap) Best regards, Jonathan -- Jonathan Hartley Made of meat. http://tartley.com ta...@ta... +44 7737 062 225 twitter/skype: tartley |