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 & HelpOther Libraries › tuioZones - a lot of problems D:
Page Index Toggle Pages: 1
tuioZones - a lot of problems D: (Read 3481 times)
tuioZones - a lot of problems D:
May 27th, 2010, 5:03am
 
Hi there,

I'm currently working on a uni project that is using tuioZones and oscP5 as libraries. I came across some problems when I try to use the isZoneToggleOn(String zName) method. Once the zones are toggled on, even I touch on the zones again, they won't toggle off.

these are parts of my code inside a class
Code:

void setting(){
   statusH = 50;

   //Arrays for the share list
   positions = new String[] {
     "Chief", "Attendant", "Resident", "Intern"    };
   chief = new String[] {
     "Martin", "Elmo"    };

   docImg = loadImage("doc.png");
   hole = loadImage("pigeon_hole.png");

   zones.setZone("shareList", -100, -100, -10, -10);
   zones.setZone("pos0", -100,-100,  10, 10);
   zones.setZone("pos1", -100,-100,  10, 10);
   zones.setZone("pos2", -100,-100,  10, 10);
   zones.setZone("pos3", -100,-100,  10, 10);
   zones.setZone("hole", -100, -100, 10, 10);
 }


Code:

void drawZone(){
if(zones.isZoneToggleOn("pos0")){
     for(int j=0; j< chief.length; j++){          
       fill(255,0);
       stroke(100, 150, 250);
       strokeWeight(3);
       rect(zones.getZoneX("pos0"), zones.getZoneY("pos0"), zones.getZoneWidth("pos0")-2.5, zones.getZoneHeight("pos0")-2.5);

       doc = "chief" + j;
       zones.setZone(doc, cellX, cellY, cellW-5, (cellH/4)*3);

       fill(150);
       strokeWeight(2);
       stroke(50);
       zones.drawRect(doc);

       image(docImg, zones.getZoneX(doc)+5, zones.getZoneY(doc)+5, zones.getZoneHeight(doc)-10, zones.getZoneHeight(doc)-10);

       fill(255);
       textFont(font,20);
       text(chief[j], zones.getZoneX(doc)+gap+30, zones.getZoneY(doc)+(zones.getZoneHeight(doc)/4)*3);

       cellY = cellY + (cellH/4)*3;
     }
   }
}


Code:

void updateZones(){
   for(int j=0; j< chief.length; j++){
     doc = "chief" + j;
     if(zones.isZoneToggleOn(doc)){
       fill(255, 0);
       strokeWeight(2);
       stroke(100, 150, 250);
       zones.drawRect(doc);
       zones.setZoneData("hole", zones.getZoneX(doc)-statusH, zones.getZoneY(doc), zones.getZoneWidth(doc), zones.getZoneHeight(doc)*3);
       fill(255);
       textFont(font,15);
       text(text(chief[j], zones.getZoneX("hole")+70, zones.getZoneY("hole")+20);
     }
  }
}


in this part of the code above, when a position array for a category of doctors(i.e Chief) is selected then the according array of names should appear along with creating a zone for each.

When a name(zone) is toggled on, the 'hole' zone should snap to the correct position as called in the setZoneData().

Okay, now, here is the problem. I should be able to toggle off the name(zone) which should make the name(zone) as well as the 'hole' disappear, however the name(zone) cannot be toggled off and the blue outline remains(zones.drawRect(doc)Wink. WHY?!! The logic seems to be correct.

PLEASE HELP!
Re: tuioZones - isZoneToggleOn problem
Reply #1 - Jun 1st, 2010, 7:59pm
 
I think the problem is with layering.  The last zone set (example: zones.setZone("hole", -100, -100, 10, 10)) is on top and the zones below do not "sense" a touch---therefore do not toggle.  You can use methods like pullZoneToTop() or killZone to change the layering of zones.

Hope that makes sense and gives some thoughts on a work-around.
Re: tuioZones - a lot of problems D:
Reply #2 - Jun 1st, 2010, 9:36pm
 
Okay, so here is our problem. We are trying to create a drawing tool through storing points in an array which then the array is stored in a vector.

Every time a point is dragged to draw, it will increase the vector but somehow we get an 'ArrayIndexOutOfBoundsException'. I don't understand why..I think the logic is correct but I guess it isn't?

Please help!!


Code:
 
//////////////// method to draw line ////////////////////////////////////////  
 void checkDraw(String zName, int x, int y, int w, int h) {
   int[][] coord = zones.getPoints();
   stroke(250,0,0);
   strokeWeight(5);
   //track the movement on the screen
   if (coord.length>0){
for (int i=0;i<coord.length;i++){
 ellipse(coord[i][0],coord[i][1],10,10);
 int [][] trail=zones.getTrail(coord[i][2]);
 if (trail.length>1){
   for (int j=0;j<trail.length;j++){
//check if the trail is located within the area
if(trail[j][0]>=x && trail[j][0]<=x+w && trail[j][1]>=y && trail[j][1]<=y+h){
 //draw the movement as a line on the screen
 //line(trail[j][0],trail[j][1],trail[j-1][0],trail[j-1][1]);
 drawLine = new int[2];
 drawLine[0] = trail[j][0];
 drawLine[1] = trail[j][1];
 drawings.add(drawLine);
}
   }
//////////////// this is the part with problems ////////////////////////////////

   int sizeOfVector;
   for(sizeOfVector = 2; drawings.size() > 2; sizeOfVector++){
drawVector();
   }
 }
}
   }
 }


 void drawVector(){
   for(int v = 0; v < drawings.size(); v++){
int[] start = (int[])drawings.get(v);
int[] end = (int[])drawings.get(v + 1);

x1 = start[0];
y1 = start[1];
x2 = end[0];
y2 = end[1];
line(x1, y1, x2, y2);
   }
 }
//////////////// gets a ArrayOutOfBoundsException //////////////////////////////
//////////////// whenever I call the drawVector function ///////////////////////
////////////////////////////////////////////////////////////////////////////////
Re: tuioZones - a lot of problems D:
Reply #3 - Jun 2nd, 2010, 1:48am
 
Quote:
for(sizeOfVector = 2; drawings.size() > 2; sizeOfVector++){

Strange stop factor... drawings.size() isn't supposed to change, no?

Quote:
for(int v = 0; v < drawings.size(); v++){
     int[] start = (int[])drawings.get(v);
     int[] end = (int[])drawings.get(v + 1);

v+1 goes beyond the limit of drawings, you might want:
for(int v = 0; v < drawings.size() - 1; v++){

Are you sure that's an ArrayOutOfBoundsException? Can you show the exact message and location where it happens?
Re: tuioZones - a lot of problems D:
Reply #4 - Jun 7th, 2010, 7:05pm
 
hi PhiLho,

thanks for your help! And sorry for the late reply, I had an x-code assignment due recently and had been tied down by that:(

Anyhow, I really appreciate your help! I used the code you posted and it works now! Finally one of the few problems have been fixed.

However, I still can't get the drawing to save and stay on the image. My tutor suggested that I save the array of points into a vector which will keep the lines on the image, but it's not working..I don't know why. Can you see a problem in the same code as before?
Re: tuioZones - a lot of problems D:
Reply #5 - Jun 8th, 2010, 2:02am
 
Have you changed the first for loop I point to?
Re: tuioZones - a lot of problems D:
Reply #6 - Jun 8th, 2010, 6:14am
 
hi PhiLho,

do you mean this loop?
Code:
for(int v = 0; v < drawings.size() - 1; v++){ 
int[] start = (int[])drawings.get(v);
int[] end = (int[])drawings.get(v + 1);
}


yes, this works now, I don't get the ArrayIndexOutOfBoundsException error anymore Cheesy

but as I mentioned previously, I'm trying to create a drawing tool through storing points in an array which then the array is stored in a vector. It does the draw line part now, but somehow the line still disappears when I remove my finger D:
Re: tuioZones - a lot of problems D:
Reply #7 - Jun 8th, 2010, 7:02am
 
No, the line with for(sizeOfVector = 2; drawings.size() > 2; sizeOfVector++){

It is hard to help on code fragments (but anyway, I don't have a device to use with Tuio...).
Re: tuioZones - a lot of problems D:
Reply #8 - Jun 8th, 2010, 9:02am
 
oh, for that line, I just commented it out cause I thought I did it wrong.

I'm using the tuioZones library for multitouch, there's a getPoints method that can get the x and y of the point I'm touching on the table. The vector problem I was working on is to store the points and draw a line with the points.

But somehow even though I can store the line now, the line only displays on screen when my finger is touching the table, when I lift my finger the drawing will be gone D: and when I touch the table again, the previous line is still there, it just doesn't show up when no touch point is found
Page Index Toggle Pages: 1