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 › get object[] into int[][]
Page Index Toggle Pages: 1
get object[] into int[][] (Read 740 times)
get object[] into int[][]
Jul 4th, 2007, 7:48pm
 
how can I get object[] into int[][]?
Re: get object[] into int[][]
Reply #1 - Jul 4th, 2007, 8:28pm
 
If you know that your object is actually an int array then I think the following should work.

Code:

for(int i=0;i<objArray.length;i++)
{
intArrayArray[i]=(int[])objArray[i];
}
Re: get object[] into int[][]
Reply #2 - Jul 4th, 2007, 8:42pm
 
It's not working

Object[] a = theOscMessage.arguments();
int [] aa;
for(int i=0;i<a.length;i++)
 {
 aa[i]=(int[])a[i];
 }

Semantic Error: The type of the right sub-expression, "int[]", is not assignable to the variable, of type "int".


Re: get object[] into int[][]
Reply #3 - Jul 4th, 2007, 10:33pm
 
you are trying to cast a int value to an array of int
for that to atleast compile you would need to change

int[] a to int [][]a;
Re: get object[] into int[][]
Reply #4 - Jul 5th, 2007, 11:41am
 
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
int[][] a;
boolean hide;
Object[] oba;

void setup(){
 size(800,600);
 //frameRate(1);

 smooth();
 strokeWeight(10);
 
 oscP5 = new OscP5(this,12000);
 myRemoteLocation = new NetAddress("127.0.0.1",12000);
}

void oscEvent(OscMessage theOscMessage) {
 if(theOscMessage.checkAddrPattern("/test")==true) {  
// println(theOscMessage.arguments());
// theOscMessage.print();  
//  println(" timetag: "+theOscMessage.timetag());
oba = theOscMessage.arguments();
  println(oba[1]);
 }
}



void draw(){
 background(100);
 osc2();
 //println(a);
   if(hide){
      groad();
   }

}

void osc2(){
for(int i=0;i<oba.length;i++)  
 {  
 a[i]=(int[])oba[i];
 }
}

oba = theOscMessage.arguments();  will get the {23,3,45,45...}
but the   a[i]=(int[])oba[i];
java.lang.ClassCastException: java.lang.Integer


Re: get object[] into int[][]
Reply #5 - Jul 5th, 2007, 1:33pm
 
hi aaajiao,
values contained in an osc messages received via oscP5 come as a 1 dimensional array. to access this array you can use theOscMessage.arguments() which will return a 1 dimensional Object array, which means that the objects contained in this array are not of type int, float, etc. yet. that would be your job then to cast/parse the values. but it is not possible to cast an element of this array into e.g. an int array due to the 1 dimensionality as mentioned.
to get an idea of how to parse osc messages you can take a look http://www.sojamo.de/oscP5 . examples like oscP5oscArgument or oscP5parsing show how to extract values from an osc message, e.g. theOscMessage.get(0).intValue() gives you the first osc argument as an int.
hope this helps,
andi
Re: get object[] into int[][]
Reply #6 - Jul 5th, 2007, 2:08pm
 
theOscMessage.get(0).intValue()  can only get the first osc argunment.

I konw how to send the int[][], but the receiving.
I found the  theOscMessage.print();
show that

-OscMessage----------
received from/127.0.0.1:49219
addrpattern /test
typetagiiiiiiii
[0] 146
[1] 0
[2] 103
[3] 49
[4] 186
[5] 9
[6] 25
[7] 21

 
I want to get the part like  
[0] 146
[1] 0
[2] 103
[3] 49
[4] 186
[5] 9
[6] 25
[7] 21

 
but I cann't find the method to get.
Re: get object[] into int[][]
Reply #7 - Jul 5th, 2007, 3:24pm
 
please try,

Code:


int[] yourIntArray;

void oscEvent(OscMessage theOscMessage) {
if(theOscMessage.checkAddrPattern("/test")==true) {
yourIntArray = new int[theOscMessage.arguments().length];
for(int i=0;i<theOscMessage.arguments().length;i++) {
yourIntArray[i] = theOscMessage.get(i).intValue();
}
}
}

Re: get object[] into int[][]
Reply #8 - Jul 5th, 2007, 4:22pm
 
Code:
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
int[][] a;
boolean hide;
Object[] oba;

void setup(){
 size(800,600);
 //frameRate(1);

 smooth();
 strokeWeight(10);
 
 oscP5 = new OscP5(this,12000);
 myRemoteLocation = new NetAddress("127.0.0.1",12000);
}

int[] yourIntArray;

void oscEvent(OscMessage theOscMessage) {
if(theOscMessage.checkAddrPattern("/test")==true) {
yourIntArray = new int[theOscMessage.arguments().length];
for(int i=0;i<theOscMessage.arguments().length;i++) {
  yourIntArray[i] = theOscMessage.get(i).intValue();
}
   }
}



void draw(){
 background(100);
 osc2();

   if(hide){
      groad();
   }

}

void osc2(){
 a = new int[yourIntArray.length][];
  for(int i=0;i<yourIntArray.length;i++) {
  a[i] = yourIntArray[i];}
}

void keyPressed(){
if (key == 'h' || key =='H') {
   hide = !hide;
   println("switch box");
 }  
}  

void groad(){
  for(int i=0;i<a.length;i++){
   //&#20013;&#28857;++++++++++++++++++++++++++++++++++++++++++  
   int pointX2 = a[i][0] + a[i][2]/2;
   int pointY2 = a[i][1] + a[i][3]/2;
   println(a[i][3]);
   //&#28857;&#38754;&#31215;++++++++++++++++++++++++++++++++++++++++++
   int totalLenght=a[i][2]+a[i][3];
   if(totalLenght >= 250){
     totalLenght = 250;
   }
   if(totalLenght <= 20){
     totalLenght = 20;
   }
   //&#36793;&#26694;++++++++++++++++++++++++++++++++++++++++++
   if(hide){
     stroke(255,0,0);
     rect(a[i][0], a[i][1], a[i][2], a[i][3]);
   }
   //&#32447;&#26465;++++++++++++++++++++++++++++++++++++++++++
    if(i!=0){
     int totalLenght1=a[i-1][2]+a[i-1][3];  
     if(totalLenght1>=70 && totalLenght>=70){  
       int pointX1 = a[i-1][0] + a[i-1][2]/2;  
       int pointY1 = a[i-1][1] + a[i-1][3]/2;  
       int val=1;  
       int step=6;  
       for(int j=0;j<step;j++){
         int lineWidth=val*j;  
         int alpha=100-100/step*j;  
         stroke(50,150,255,alpha);  
         line( pointX1+lineWidth,pointY1-lineWidth,pointX2+lineWidth, pointY2-lineWidth);
         line( pointX1-lineWidth,pointY1+lineWidth,pointX2-lineWidth, pointY2+lineWidth);
       }
     }
   }
   //&#22278;&#24418;++++++++++++++++++++++++++++++++++++++++++
   int dia=totalLenght/4;  
   int val2=6;  
   int step2=totalLenght/5;  
   noStroke();
   fill(255,255-255/dia*2);
   ellipse(pointX2, pointY2,dia, dia);  

   for(int j=0;j<step2;j++){
     noFill();
     int diameter=dia+val2*j;  
     int alpha=150-150/step2*j;  
     stroke(0, 150, 255,alpha);  
     ellipse(pointX2, pointY2, diameter, diameter);  
   }
 }
}  



thanks sojamo first

void osc2(){
 a = new int[yourIntArray.length][];
  for(int i=0;i<yourIntArray.length;i++) {
  a[i] = yourIntArray[i];}
}

but I want to get the int[][]
osc message come from

globBoxes()
returns a list of bounding boxes for each glob.
this is a list of rects.
Lingo: [rect,rect,rect]
Java: int[][4]

you can use this like int[][] a= m.globBoxes();
it can works on void groad();

now It get int[]
how I can bulid the int[][];

void osc2(){
 a = new int[yourIntArray.length][];
  for(int i=0;i<yourIntArray.length;i++) {
  a[i] = yourIntArray[i];}
}
this is not working

void osc2(){
 a = new int[yourIntArray.length][4];
  for(int i=0;i<yourIntArray.length;i++) {
    for(int j=0; j<4;j++){
  a[i][j] = yourIntArray[i];}
}
}
this is working but the result is not like int[][] a= m.globBoxes();

@_@b

Page Index Toggle Pages: 1