|
From: Nick C. <nic...@ve...> - 2011-02-24 14:41:09
|
Ah, I see. You need to create a new class that implements StyleOGL2D. Changing the color of an agent based on a property is certainly supported there. Use this class that agent style in place of the DefaultStyleOGL2D. Here's the javadoc for StyleOGL2D: http://repast.sourceforge.net/docs/api/repastjava/repast/simphony/visualizationOGL2D/StyleOGL2D.html Attached is an example, that shows the agent's as circles and sets their color using the agent's "id" property. More complicated shapes, icons etc are also possible. Below is a description of how to achieve more complicated styles with StyleOGL2D: "You can programmatically set the icon by using your own style class. The class needs to implement the StyleOGL2D interface. The Java Doc for that is at: http://repast.sourceforge.net/docs/api/repastjava/repast/simphony/visualizationOGL2D/StyleOGL2D.html Most of the methods should be straight forward. Simphony will pass an agent as an Object to each method and return the appropriately value (typically based on some agent property). Two methods that are little more complicated are init and getVSpatial. A ShapeFactory2D is passed to init. You can use this ShapeFactory to create your own VSpatials (the visual representation an agent). Here's an example of how that works for icons. public class AgentStyle implements StyleOGL2D<Object> { private ShapeFactory2D shapeFactory; public void init(ShapeFactory2D fac) { this.shapeFactory = fac; try { Map<String, String> props = new HashMap<String, String>(); ImageSpatialSource imgSource = new ImageSpatialSource("lock", "/Users/nick/Documents/workspace/RepastSimphony2/jzombies/icons/zombie.png"); imgSource.registerSource(fac, props); } catch (IOException ex) { ex.printStackTrace(); } } The idea here is that you store reference to the factory, then create an ImageSpatialSource. The constructor of that takes a unique id for the image, and a path to the actual icon file. You then register the source calling registerSource on the ImageSpatialSource. That will register the image with the factory and the factory can now be used to produce VSpatial icons with that image. For example, public VSpatial getVSpatial(Object agent, VSpatial spatial) { if (spatial == null) { return shapeFactory.getNamedSpatial("lock"); } return null; } Here's we use the shapeFactory stored in init above to return the "lock" image that we created in init. Note that the existing VSpatial for the agent is passed in. The first time this is called the spatial will be null and we have to return a VSpatial. If we don't want to change the VSpatial in subsequent calls then we can just return null or the passed in spatial. To change the icon, you'd return a different named spatial that you created in init. That new icon VSpatial would then be used to represent that agent." Nick On Feb 23, 2011, at 12:20 PM, Miguel Garzon wrote: > Hi Nick > > Thanks for your quick answer > > In my old repast model when my model agents change some properties values this is visualized in the simmulation screen changing their color in their grid position, is a simple behavior, however when I migrate my model to new repast version I had to create a new display and I just have the option repast.simphony.visualizationOGL2D.DefaultStyleOGL2D to select in the style class parameter, this one does not "copy" my old repast style class behavior. > > Attached are the screenshots for both version model execution window, with v2.0 as soon as model runs, after tick 0 the display window change grid information. > > Your help is very appreciated, please let me know your thoughts..... > > Slds, > > Miguel > > > From: Nick Collier <nic...@ve...> > To: Miguel Garzon <mig...@ya...> > Cc: Rep...@li... > Sent: Wed, February 23, 2011 10:39:31 AM > Subject: Re: [Repast-interest] Display Problem in Repast 2.0 > > This should be possible, I think, but you won't be able to use the wizard to create the display. You will have to write the code yourself. If that's OK, let me know and I can explain how to do it. > > Also, can you email me off list describing what is missing for you from the jogl-2D. I realize there are less options in the style but it would be good to get the details of your use case. > > thanks, > > Nick > > On Feb 23, 2011, at 9:59 AM, Miguel Garzon wrote: > >> Hello all >> >> I have been developed a model using Repast v1.2, my agents use a 2D Style class called TestStyle2D which implements an Style2D<Object>, when I migrate my model to Repast v2.0 I am not able to use this same class style in my display configuration, instead I had to use JOGL-2D visualization which change completely my model appearance and does not visualize the graphical information that I need. >> >> There is a way to include my previous display class in new repast version? please let me know what information you need from my model in order to add it yo my post >> >> Thanks in advance for your help. >> >> Slds, >> >> Miguel >> >> ------------------------------------------------------------------------------ >> Free Software Download: Index, Search & Analyze Logs and other IT data in >> Real-Time with Splunk. Collect, index and harness all the fast moving IT data >> generated by your applications, servers and devices whether physical, virtual >> or in the cloud. Deliver compliance at lower cost and gain new business >> insights. http://p.sf.net/sfu/splunk-dev2dev >> _______________________________________________ >> Repast-interest mailing list >> Rep...@li... >> https://lists.sourceforge.net/lists/listinfo/repast-interest > > > <Repast.rar> |