We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Working on TUIO, didn't recognize demo app syntax
Page Index Toggle Pages: 1
Working on TUIO, didn't recognize demo app syntax (Read 1539 times)
Working on TUIO, didn't recognize demo app syntax
Sep 25th, 2009, 12:48am
 
Hello,
I'm working my way through the demonstration sketches that come with the library, and I came across a syntax in the draw/object detection loop that I didn't recognize.  My only non-processing programming experience is PHP and max/msp/jitter, so I'm still out of my depth (for now!).

Anyway, thought I would defer to you fine folks for an explanation.

Code:
 Vector tuioCursorList = tuioClient.getTuioCursors();
  for (int i=0;i<tuioCursorList.size();i++) {
     TuioCursor tcur = (TuioCursor)tuioCursorList.elementAt(i);
     Vector pointList = tcur.getPath();


     TuioCursor tcur = (TuioCursor)tuioCursorList.elementAt(i); Now, I get that it's calling an attribute/element (not sure correct term) of the TuioCursorList using the i as a key for the array, no worries there (right?).  
My question lies in the brackets around the (TuioCursor) before that statement.  I'm just not sure what that is.  Semantically, I'd hazard a guess that it's identifying that vector as part of the broader TuioCursor object/class/whathaveyou for inheretence purposes....

Anyway, any explanation would be greatly appreciated, likewise a pointer in the direction of some further reading too!  Thanks in advance for the help.
Re: Working on TUIO, didn't recognize demo app syntax
Reply #1 - Sep 25th, 2009, 1:08am
 
Its a cast. As you can put any typ of Objects in a Vector JAVA needs to know, what typ your object is, when you calling  tuioCursorList.elementAt(i). Since java 1.5 you can explicit declare what typ of objects you wanna but in. So you don't need to cast and you get an error if you try to add a wrong typed object.

Code:

Vector<TuioCursor> tuioCursorList = new Vector<TuioCursor>();
Re: Working on TUIO, didn't recognize demo app syntax
Reply #2 - Sep 25th, 2009, 1:38am
 
hey I thought Processing didn't do generics, because it supposedly only supports java 1.4 grammar. And yet it does, so now I'm confused. PhiLo? anyone?
Re: Working on TUIO, didn't recognize demo app syntax
Reply #3 - Sep 25th, 2009, 2:04am
 
Maybe. I work with processing in eclipse over years so I did'tn recognize that.
Re: Working on TUIO, didn't recognize demo app syntax
Reply #4 - Sep 25th, 2009, 2:21am
 
eskimo: your example works with processing IDE, even with 1.0.3, but I thought it shouldn't. I even exported it to an applet, and it still works. Yet I see feature requests in the dev bugtracker, where people ask for generics support. So maybe processing has implemented some of the java 1.5 features, or else my Java installation is different (I have several JVMs installed by hand).
Re: Working on TUIO, didn't recognize demo app syntax
Reply #5 - Sep 25th, 2009, 3:25am
 
Quote:
your example works with processing IDE

Not for me.
I tried the simple code:
Code:
ArrayList al = new ArrayList();
for (int i = 0; i < 11; i++)
{
String s = String.format("Item %02d", (i + 1));
al.add(s);
}

for (int i = 0; i < al.size(); i++)
{
println((String) al.get(i));
}

OK. Now with generics:
Code:
ArrayList<String> al = new ArrayList<String>();
for (int i = 0; i < 11; i++)
{
String s = String.format("Item %02d", (i + 1));
al.add(s);
}

for (int i = 0; i < al.size(); i++)
{
println(al.get(i));
}

When running, I get:
Code:
processing.app.debug.RunnerException: unexpected token: <
at processing.app.Sketch.preprocess(Sketch.java:1362)
at processing.app.Sketch.build(Sketch.java:1473)
at processing.app.Sketch.compile(Sketch.java:1172)
at processing.app.Editor.handleRun(Editor.java:1574)
...

As expected... Sad Processing 1.0.5 on Windows XP.

Now, if you put such code in a .java file, it will work, even in the PDE.
Re: Working on TUIO, didn't recognize demo app syntax
Reply #6 - Sep 25th, 2009, 6:13am
 
Here's another example.
This has generics and works:

Code:

 Vector<Integer> numbers = new Vector();
 numbers.add(1);
 numbers.add(2);
 numbers.add(3);
 for (int i=0;i<numbers.size();i++) {
    Integer num = numbers.elementAt(i);
    print(num);
 }


This has no generics and fails:
Code:

 Vector numbers = new Vector();
 numbers.add(1);
 numbers.add(2);
 numbers.add(3);
 for (int i=0;i<numbers.size();i++) {
    Integer num = numbers.elementAt(i);
    print(num);
 }


see the weirdness?  Shocked
Re: Working on TUIO, didn't recognize demo app syntax
Reply #7 - Sep 25th, 2009, 8:44am
 
Wow, that's weird!  Shocked

I first though the code was incorrect, but javac issues only a warning "TestClass uses unchecked or unsafe operations".
But if I "fix" the code with:
Vector<Integer> numbers = new Vector<Integer>();
it no longer compiles in Processing!  Roll Eyes
And it still fails on a loop like:
for (num : numbers) print(num);

Looks like unfinished work...  Cool
Re: Working on TUIO, didn't recognize demo app syntax
Reply #8 - Sep 25th, 2009, 3:59pm
 
Oh wow.  Okay, that clears up some confusion, and adds more at the same time.  For those lagging a bit behind (like myself), I found this helped on a basic level. http://www.janeg.ca/scjp/oper/cast.html

Alright, so just to make clear, in this case the vector information from one object to another (making explicit).  To just clarify my understanding:

I'm working on another project where I'm storing float point numbers based on a series of jitter calculations in max/msp/jitter, and they're being stored in a text file.
Doing the visualization in processing, I am extracting the full string from the text file, breaking it up by line, then " " deliniation.
Instead of using functions to convert string to float or int, can I instead just do something like the following? (The syntax is kinda messy/wrongish... can I even do that with arrays?)
Code:

string[] storeslines;;;;;;
Float[][] d = new float d[storelines.length][5];
for(int i=0;i<data.length;i++){
    d[i][] = (float[])split(storeslines[i]," ");
}
Page Index Toggle Pages: 1