From: Jamie R. <jam...@gm...> - 2009-07-29 02:33:33
|
I have a VPython faces based object. I would like the user to be able to change fundamental parameters that affect its shape (like setting numSides on a Polygon), but I can't seem to get VPython to re-render the new shape. I've tried to "Del" the existing face list, then create a new one, but the old object is still shown. Any suggestions? Thank - Jamie Riotto |
From: Bruce S. <Bru...@nc...> - 2009-07-29 15:53:06
|
Could you please post a short test routine that illustrates the problem? Thanks. Bruce Sherwood Jamie Riotto wrote: > I have a VPython faces based object. I would like the user to be able to change > fundamental parameters that affect its shape (like setting numSides on > a Polygon), > but I can't seem to get VPython to re-render the new shape. I've tried > to "Del" the > existing face list, then create a new one, but the old object is still > shown. Any suggestions? > > Thank - Jamie Riotto > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |
From: Jamie R. <jam...@gm...> - 2009-07-29 16:56:52
|
Sure, here is a scaled down version of the surface demo. I expect to see only one triangle after the "clearSurface" but I still see two. Thanks - jamie from __future__ import division from PyQt4.QtCore import * from PyQt4.QtGui import * from visual import * newframe = frame class Object(object): def __init__(self, parent=None, frame=None, pos=(0,0,0), axis=(1,0,0), color=color.green): self.frame = newframe(frame=frame, pos=pos, axis=axis) self.surface = faces(frame=self.frame) self.color = color self.vertexList = [] self.normalList = [] self.colorList = [] def clearSurface(self): del self.surface self.surface = faces(frame=self.frame) self.vertexList = [] self.normalList = [] def addTri(self, p1, p2, p3): """Add a triangle to the model""" v1 = vector(p1) v2 = vector(p2) v3 = vector(p3) try: normal = norm( cross(v2-v1, v3-v1) ) except: normal = vector(0,0,0) self.vertexList = self.vertexList + [v1,v2,v3] self.normalList = self.normalList + [normal,normal,normal] self.colorList = self.colorList + [self.color,self.color,self.color] def computeSurface(self): """ Create faces out of vertex, normal and color info""" self.surface = faces(frame=self.frame, pos=self.vertexList, normal=self.normalList, color=self.colorList) if __name__ == '__main__': # origin sphere for reference sphere(radius=0.1) p1 = (-2, -1, 0) p2 = (-1, 1, 0) p3 = (-2, 1, 0) p4 = (3, -1, 0) p5 = (5, -1, 0) p6 = (4, 2, 0) x=Object() x.addTri(p1, p2, p3) x.computeSurface() print "new surface" x.clearSurface() x.addTri(p4, p5, p6) x.computeSurface() print x.vertexList On Wed, Jul 29, 2009 at 8:52 AM, Bruce Sherwood<Bru...@nc...> wrote: > Could you please post a short test routine that illustrates the problem? > Thanks. > > Bruce Sherwood > > Jamie Riotto wrote: >> I have a VPython faces based object. I would like the user to be able to change >> fundamental parameters that affect its shape (like setting numSides on >> a Polygon), >> but I can't seem to get VPython to re-render the new shape. I've tried >> to "Del" the >> existing face list, then create a new one, but the old object is still >> shown. Any suggestions? >> >> Thank - Jamie Riotto >> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: Bruce S. <Bru...@nc...> - 2009-07-29 18:15:34
|
You merely need to make the object invisible before deleting it: def clearSurface(self): self.surface.visible = False del self.surface ..... The issue is this: The human viewer counts as a reference for a VPython object. For example, if you create ball = sphere() and then later say ball = 3, there is no longer any way to reference the sphere and in a non-VPython program Python would be free to delete the sphere. But because the sphere is still visible on the screen, the reference count does not go to zero and the human viewer can still view the sphere. Hence the documented rule that you need to make an object invisible to get rid of it (though the documentation could be a bit clearer on this). Bruce Sherwood Jamie Riotto wrote: > Sure, here is a scaled down version of the surface demo. I expect > to see only one triangle after the "clearSurface" but I still see two. > > Thanks - jamie > > > > from __future__ import division > from PyQt4.QtCore import * > from PyQt4.QtGui import * > from visual import * > > newframe = frame > > class Object(object): > > def __init__(self, parent=None, frame=None, pos=(0,0,0), axis=(1,0,0), > color=color.green): > self.frame = newframe(frame=frame, pos=pos, axis=axis) > self.surface = faces(frame=self.frame) > self.color = color > self.vertexList = [] > self.normalList = [] > self.colorList = [] > > def clearSurface(self): > del self.surface > self.surface = faces(frame=self.frame) > self.vertexList = [] > self.normalList = [] > > def addTri(self, p1, p2, p3): > """Add a triangle to the model""" > v1 = vector(p1) > v2 = vector(p2) > v3 = vector(p3) > > try: > normal = norm( cross(v2-v1, v3-v1) ) > except: > normal = vector(0,0,0) > > self.vertexList = self.vertexList + [v1,v2,v3] > self.normalList = self.normalList + [normal,normal,normal] > self.colorList = self.colorList + [self.color,self.color,self.color] > > > def computeSurface(self): > """ Create faces out of vertex, normal and color info""" > self.surface = faces(frame=self.frame, pos=self.vertexList, > normal=self.normalList, > color=self.colorList) > > > > if __name__ == '__main__': > # origin sphere for reference > sphere(radius=0.1) > > p1 = (-2, -1, 0) > p2 = (-1, 1, 0) > p3 = (-2, 1, 0) > > > p4 = (3, -1, 0) > p5 = (5, -1, 0) > p6 = (4, 2, 0) > > x=Object() > x.addTri(p1, p2, p3) > x.computeSurface() > > print "new surface" > x.clearSurface() > x.addTri(p4, p5, p6) > x.computeSurface() > print x.vertexList > > > On Wed, Jul 29, 2009 at 8:52 AM, Bruce Sherwood<Bru...@nc...> wrote: >> Could you please post a short test routine that illustrates the problem? >> Thanks. >> >> Bruce Sherwood >> >> Jamie Riotto wrote: >>> I have a VPython faces based object. I would like the user to be able to change >>> fundamental parameters that affect its shape (like setting numSides on >>> a Polygon), >>> but I can't seem to get VPython to re-render the new shape. I've tried >>> to "Del" the >>> existing face list, then create a new one, but the old object is still >>> shown. Any suggestions? >>> >>> Thank - Jamie Riotto >>> >>> ------------------------------------------------------------------------------ >>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >>> trial. Simplify your report design, integration and deployment - and focus on >>> what you do best, core application coding. Discover what's new with >>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>> _______________________________________________ >>> Visualpython-users mailing list >>> Vis...@li... >>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |
From: Jamie R. <jam...@gm...> - 2009-07-29 18:31:34
|
Bruce, Wow, thanks, that clears up a lot. I've been confused (obviously) about the invisible / delete relationship for a while. Cheers - jamie On Wed, Jul 29, 2009 at 11:15 AM, Bruce Sherwood<Bru...@nc...> wrote: > You merely need to make the object invisible before deleting it: > > def clearSurface(self): > self.surface.visible = False > del self.surface > ..... > > The issue is this: The human viewer counts as a reference for a VPython > object. For example, if you create ball = sphere() and then later say > ball = 3, there is no longer any way to reference the sphere and in a > non-VPython program Python would be free to delete the sphere. But > because the sphere is still visible on the screen, the reference count > does not go to zero and the human viewer can still view the sphere. > Hence the documented rule that you need to make an object invisible to > get rid of it (though the documentation could be a bit clearer on this). > > Bruce Sherwood > > Jamie Riotto wrote: >> Sure, here is a scaled down version of the surface demo. I expect >> to see only one triangle after the "clearSurface" but I still see two. >> >> Thanks - jamie >> >> >> >> from __future__ import division >> from PyQt4.QtCore import * >> from PyQt4.QtGui import * >> from visual import * >> >> newframe = frame >> >> class Object(object): >> >> def __init__(self, parent=None, frame=None, pos=(0,0,0), axis=(1,0,0), >> color=color.green): >> self.frame = newframe(frame=frame, pos=pos, axis=axis) >> self.surface = faces(frame=self.frame) >> self.color = color >> self.vertexList = [] >> self.normalList = [] >> self.colorList = [] >> >> def clearSurface(self): >> del self.surface >> self.surface = faces(frame=self.frame) >> self.vertexList = [] >> self.normalList = [] >> >> def addTri(self, p1, p2, p3): >> """Add a triangle to the model""" >> v1 = vector(p1) >> v2 = vector(p2) >> v3 = vector(p3) >> >> try: >> normal = norm( cross(v2-v1, v3-v1) ) >> except: >> normal = vector(0,0,0) >> >> self.vertexList = self.vertexList + [v1,v2,v3] >> self.normalList = self.normalList + [normal,normal,normal] >> self.colorList = self.colorList + [self.color,self.color,self.color] >> >> >> def computeSurface(self): >> """ Create faces out of vertex, normal and color info""" >> self.surface = faces(frame=self.frame, pos=self.vertexList, >> normal=self.normalList, >> color=self.colorList) >> >> >> >> if __name__ == '__main__': >> # origin sphere for reference >> sphere(radius=0.1) >> >> p1 = (-2, -1, 0) >> p2 = (-1, 1, 0) >> p3 = (-2, 1, 0) >> >> >> p4 = (3, -1, 0) >> p5 = (5, -1, 0) >> p6 = (4, 2, 0) >> >> x=Object() >> x.addTri(p1, p2, p3) >> x.computeSurface() >> >> print "new surface" >> x.clearSurface() >> x.addTri(p4, p5, p6) >> x.computeSurface() >> print x.vertexList >> >> >> On Wed, Jul 29, 2009 at 8:52 AM, Bruce Sherwood<Bru...@nc...> wrote: >>> Could you please post a short test routine that illustrates the problem? >>> Thanks. >>> >>> Bruce Sherwood >>> >>> Jamie Riotto wrote: >>>> I have a VPython faces based object. I would like the user to be able to change >>>> fundamental parameters that affect its shape (like setting numSides on >>>> a Polygon), >>>> but I can't seem to get VPython to re-render the new shape. I've tried >>>> to "Del" the >>>> existing face list, then create a new one, but the old object is still >>>> shown. Any suggestions? >>>> >>>> Thank - Jamie Riotto >>>> >>>> ------------------------------------------------------------------------------ >>>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >>>> trial. Simplify your report design, integration and deployment - and focus on >>>> what you do best, core application coding. Discover what's new with >>>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>>> _______________________________________________ >>>> Visualpython-users mailing list >>>> Vis...@li... >>>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>> ------------------------------------------------------------------------------ >>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >>> trial. Simplify your report design, integration and deployment - and focus on >>> what you do best, core application coding. Discover what's new with >>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>> _______________________________________________ >>> Visualpython-users mailing list >>> Vis...@li... >>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>> >> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: Jamie R. <jam...@gm...> - 2009-08-03 18:29:09
|
Bruce, Your suggestion for a quicker way to reset faces objects works great. Thanks for pointing this out. It is a significant speedup if recalculating lots of faces objects. Also, I copied the "try norm" lines right out of faces_heightfield.py in the examples folder. Probably should change that as it looks like it is no longer (if it ever was) needed. Thanks for you time on this - Jamie Riotto On Sat, Aug 1, 2009 at 3:09 PM, Bruce Sherwood<Bru...@nc...> wrote: > It occurred to me to try a different approach to the issue of deleting a > faces object and recreating it. I would guess that performance ought to > be significantly better if you simply change the faces.pos array as in > the following version. > > Also note the minor point that it isn't necessary to "try" whether > norm(v) works and then making v = vector(0,0,0) if it doesn't work. As > the documentation for vector operations in Visual says, if v is > vector(0,0,0), as a convenience norm(v) returns vector(0,0,0), just as > you wanted. > > Bruce Sherwood > ------------------------- > > from __future__ import division > from visual import * > > newframe = frame > > class Object(object): > > def __init__(self, parent=None, frame=None, pos=(0,0,0), axis=(1,0,0), > color=color.green): > self.frame = newframe(frame=frame, pos=pos, axis=axis) > self.surface = faces(frame=self.frame) > self.color = color > self.clearSurface() > > def clearSurface(self): > self.surface.pos = [] > self.vertexList = [] > self.normalList = [] > self.colorList = [] > > def addTri(self, p1, p2, p3): > """Add a triangle to the model""" > v1 = vector(p1) > v2 = vector(p2) > v3 = vector(p3) > > normal = norm( cross(v2-v1, v3-v1) ) > > ## try is not necessary; norm(vector(0,0,0)) is vector(0,0,0) - see docs > ## try: > ## normal = norm( cross(v2-v1, v3-v1) ) > ## except: > ## normal = vector(0,0,0) > > self.vertexList = self.vertexList + [v1,v2,v3] > self.normalList = self.normalList + [normal,normal,normal] > self.colorList = self.colorList + > [self.color,self.color,self.color] > > def computeSurface(self): > """ Create faces out of vertex, normal and color info""" > self.surface.pos = self.vertexList > self.surface.normal = self.normalList > self.surface.color = self.colorList > ## self.surface = faces(frame=self.frame, pos=self.vertexList, > ## normal=self.normalList, > ## color=self.colorList) > > if __name__ == '__main__': > # origin sphere for reference > sphere(radius=0.1) > > p1 = (-2, -1, 0) > p2 = (-1, 1, 0) > p3 = (-2, 1, 0) > > > p4 = (3, -1, 0) > p5 = (5, -1, 0) > p6 = (4, 2, 0) > > x=Object() > x.addTri(p1, p2, p3) > x.computeSurface() > scene.mouse.getclick() > > print "new surface" > x.clearSurface() > x.addTri(p4, p5, p6) > x.computeSurface() > print x.vertexList > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: Bruce S. <Bru...@nc...> - 2009-08-03 22:45:37
|
Thanks! I've removed that old code from faces_heightfield.py. I notice that the program was written by David Scherer in 2001. Bruce Sherwood Jamie Riotto wrote: > Bruce, > Your suggestion for a quicker way to reset faces objects works great. > Thanks for pointing this out. > It is a significant speedup if recalculating lots of faces objects. > > Also, I copied the "try norm" lines right out of faces_heightfield.py > in the examples folder. > Probably should change that as it looks like it is no longer (if it > ever was) needed. > > Thanks for you time on this - Jamie Riotto > > > |
From: Bruce S. <Bru...@nc...> - 2009-08-01 22:10:22
|
It occurred to me to try a different approach to the issue of deleting a faces object and recreating it. I would guess that performance ought to be significantly better if you simply change the faces.pos array as in the following version. Also note the minor point that it isn't necessary to "try" whether norm(v) works and then making v = vector(0,0,0) if it doesn't work. As the documentation for vector operations in Visual says, if v is vector(0,0,0), as a convenience norm(v) returns vector(0,0,0), just as you wanted. Bruce Sherwood ------------------------- from __future__ import division from visual import * newframe = frame class Object(object): def __init__(self, parent=None, frame=None, pos=(0,0,0), axis=(1,0,0), color=color.green): self.frame = newframe(frame=frame, pos=pos, axis=axis) self.surface = faces(frame=self.frame) self.color = color self.clearSurface() def clearSurface(self): self.surface.pos = [] self.vertexList = [] self.normalList = [] self.colorList = [] def addTri(self, p1, p2, p3): """Add a triangle to the model""" v1 = vector(p1) v2 = vector(p2) v3 = vector(p3) normal = norm( cross(v2-v1, v3-v1) ) ## try is not necessary; norm(vector(0,0,0)) is vector(0,0,0) - see docs ## try: ## normal = norm( cross(v2-v1, v3-v1) ) ## except: ## normal = vector(0,0,0) self.vertexList = self.vertexList + [v1,v2,v3] self.normalList = self.normalList + [normal,normal,normal] self.colorList = self.colorList + [self.color,self.color,self.color] def computeSurface(self): """ Create faces out of vertex, normal and color info""" self.surface.pos = self.vertexList self.surface.normal = self.normalList self.surface.color = self.colorList ## self.surface = faces(frame=self.frame, pos=self.vertexList, ## normal=self.normalList, ## color=self.colorList) if __name__ == '__main__': # origin sphere for reference sphere(radius=0.1) p1 = (-2, -1, 0) p2 = (-1, 1, 0) p3 = (-2, 1, 0) p4 = (3, -1, 0) p5 = (5, -1, 0) p6 = (4, 2, 0) x=Object() x.addTri(p1, p2, p3) x.computeSurface() scene.mouse.getclick() print "new surface" x.clearSurface() x.addTri(p4, p5, p6) x.computeSurface() print x.vertexList |