Breve as a backend to a Java Application

Hello. I'm trying to create a program in Java that will act as a front end to a breve simulation. I want to load images into the Java program, then feed them into a breve simulation.

The breve simulation will break up the images into smaller images, and then send data about those images back to the java program. I don't need to actually display anything in breve, I just want to create agents to collect data.

My problem is that I'm not exactly sure how to call breve from a java program, and also that I'm not sure how to have java read the data that breve would be outputting. My first option is to read and write the date to/from text files, which I'd rather not do. I've been looking at running the commandline version from breve using the Java Runtime class, which seems to claim it can get output (print statements?). I could also try to accomplish this using sockets. Does anyone have experience with this kind of project?

Why not use the python front

Why not use the python front end? Perhaps you should consider writing your frontend in Jython since that is a compromise between the two. What exactly do you want to do in breve that you can't do with the Image class?

Image isn't the problem

The image class isn't the problem. The image class is the reason I'm using breve to do the image processing in the first place.

I want the program to ask the user to provide an image, (eventually a group of images). When the user clicks a button in the GUI, it will prompt the user for the number of boxes Breve should divide the image into.

The GUI will then run breve with the images and number of boxes per image fed to it as command-line arguments. Breve will do all of the image processing itself, and (the part I'm confused about implementing) feed the data I want to collect back to my Java program.

As I'm running Windows XP, I can't create the GUI using Steve, the options just aren't there (although this may have changed and I can't find it anywhere).

All of the 'intelligent' work will be done in the breve simulation, I just want to use Java to act as a front end. I believe it is possible to run breve in Java, the only thing I want to know is how to get the data from the breve simulation back to the Java program.

Sorry that the interface

Sorry that the interface functionality is not so advanced under Windows as it is under Mac OS X -- a new Qt-based frontend is in the works for a future release which will address this. Also in the works for a future release is better XML support, so that will be an option then as well.

In the meantime, you could communicate between breve and Python by writing out files with the File class, or by writing data to standard output and reading it in Java.

- jon

Jon, I've been trying

Jon, I've been trying writing stuff out to the log using 'print' but my java code's input stream won't seem to read the input from breve, in either Steve or Python. I'm sort of new to this whole thing, so it's possible it's an error in my java code, but I know that the breve program is running, the output just isn't going anywhere.

Is there a different print function I should be using that I just haven't read about, or is 'print 'blah'' the thing I want to use? I'd rather not write to files if I can avoid it, to make the whole thing function better. Below is the test program I wrote in Breve.


@use Control.

Controller HelloWorld.

Control : HelloWorld {
+ to init:
printf "Hello, world!\n".
print "This is a test!!!!!\n".
print "Is this working?!".
+to iterate:
#the java program is supposed to stop reading the file when it receives 'Done!'
print "Done!".
super iterate.

}

If I run this from the command line, I get plenty of text coming out, but if I run it from my Java program (using the same call that worked on the command line, 'breve.exe -x -u test.tz') it seems to load the file and then not display anything.

Is it possible this is a problem with breve and I have to do something there, or is the error in my Java code? I've never written a program to do this before, so I'm really not used to this at all.

Thanks a lot for your help.

getOutputStream()?

I'm looking at the Java docs for the Runtime.exec method, and it looks like you would need to read the program output using getOutputStream() -- are you using this call? I wouldn't expect the simulation to display anything out to the console because it's all being redirected internally in Java.

If you're already doing this, one possibility is that the output is buffered until the simulation ends. I'm not sure about Java, but in many languages, the standard "system" call to execute a command will buffer output until the command is completed. I'm betting that the simulation is running, but you're not getting output because the simulation isn't ending.

To test this, try making the simulation exit after 10 seconds:

breve.exe -x -t 10.0 test.tz

- jon

Fixed it

Okay, I fixed the problem. For some reason, all of the outputs went to the 'ErrorInputStream' not the 'InputStream'. I'm gonna do some more checking with this, but that's what seems to be happening.... This is different than it would do for anything else, and is either a bug or the way I have the command line setup... I guess.

It's the Error stream

Actually, I was just about to chime in to confirm this. In my experience, breve print commands output to the error stream instead of the standard output stream. Of course, in my case, this may only be because every time I run breve I get some unimportant warning messages about sound/Python, which should validly go to the error stream. Why everything else goes there as well is a mystery to me.

-Jacob

Yeah, I'm having that exact

Yeah, I'm having that exact same issue... Also, Jon if you're still reading this, I was wondering if there might be a way to speed my simulation up at all by loading the image in java and using shared data structures in memory. Is such a thing possible?

Hey guys, looks like it's

Hey guys,
looks like it's been this way for quite a while -- I'll see that this gets addressed for the next release.

- jon

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.