Javascript : hit test result trouble

benoitlahoz's picture

Hi !

I'm trying to perform a hit test between a structure of points and an object through a Javascript.

Eveything's ok until I have to go back to "false" when my points don't touch anything anymore.

I'm surely making an error, but I can't understand why the program can't :

  • send once the result after two tests : if / else, and only send it if it is in the "if" statement.

  • send the result from the "if" OR the "else" statement.

I'm asking for help, once more, to the kineme great masters ! :-)

Sorry for the big file, but my tested video is inside.

Thank you !

PreviewAttachmentSize
HIT_TEST_01.zip1.53 MB

Comment viewing options

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

usefuldesign.au's picture
Re: Javascript : hit test result trouble

I'm getting a few load exceptions:

> (null)
<QCNodeManager | namespace = "com.apple.QuartzComposer" | 727 nodes>: Patch with name "/carasuelo rdd sprite" is missing
 
> Macro Patch
Cannot create node of class "/carasuelo rdd sprite" and identifier "(null)"
 
> (null)
<QCNodeManager | namespace = "com.apple.QuartzComposer" | 727 nodes>: Patch with name "QCOpenCL" is missing
 
> PixelS Mono
Cannot create node of class "QCOpenCL" and identifier "(null)"
 
> PixelS Mono
Cannot create connection from ["output" @ "Splitter_1"] to ["Select" @ "OpenCL_1"]
 
> PixelS Mono
Cannot publish input port ["Custom-Device" @ "OpenCL_1"]
 
> PixelS Mono
Cannot publish input port ["Image" @ "OpenCL_1"]
 
> PixelS Mono
Cannot publish input port ["Boost" @ "OpenCL_1"]
 
> PixelS Mono
Cannot publish output port ["MonoStruct" @ "OpenCL_1"]
 
> Macro Patch
State restoration failed on node "Patch_3" <QCPatch = 0x0843FB80 "(null)">
 
> (null)
<QCNodeManager | namespace = "com.apple.QuartzComposer" | 727 nodes>: Patch with name "/pixels to units" is missing
 
> Render in Image
Cannot create node of class "/pixels to units" and identifier "(null)"
 
> (null)
<QCNodeManager | namespace = "com.apple.QuartzComposer" | 727 nodes>: Patch with name "/carasuelo rdd sprite" is missing
 
> Render in Image
Cannot create node of class "/carasuelo rdd sprite" and identifier "(null)"
 
> Render in Image
Cannot create connection from ["Units" @ "Patch_2"] to ["inputValue" @ "Math_3"]
 
> Render in Image
Cannot create connection from ["outputImage" @ "ImageCrop_1"] to ["Image" @ "Patch_1"]
 
> Render in Image
Cannot create connection from ["outputValue" @ "Math_3"] to ["Y_Position" @ "Patch_1"]
 
> Render in Image
Cannot create connection from ["output" @ "Splitter_3"] to ["Pixels" @ "Patch_2"]
 
> Render in Image
Cannot create connection from ["outputValue" @ "Math_3"] to ["X_Position" @ "Patch_1"]
 
> Macro Patch
State restoration failed on node "RenderInImage_1" <QCRenderInImage = 0x06F96D90 "(null)">
 
> (null)
<QCNodeManager | namespace = "com.apple.QuartzComposer" | 727 nodes>: Patch with name "/circle" is missing
 
> Macro Patch
Cannot create node of class "/circle" and identifier "(null)"
 
> (null)
<QCNodeManager | namespace = "com.apple.QuartzComposer" | 727 nodes>: Patch with name "/instructions" is missing
 
> Macro Patch
Cannot create node of class "/instructions" and identifier "(null)"
 
> Macro Patch
Cannot create connection from ["output" @ "Multiplexer_1"] to ["Text" @ "Patch_4"]
 
> Macro Patch
Cannot create connection from ["output" @ "Splitter_6"] to ["Radius" @ "Patch_1"]
 
> Macro Patch
Cannot create connection from ["output" @ "Splitter_1"] to ["Image" @ "Patch_2"]
 
> Macro Patch
Cannot create connection from ["output" @ "Splitter_3"] to ["X_Position" @ "Patch_1"]
 
> Macro Patch
Cannot create connection from ["output" @ "Splitter_5"] to ["Y_Position" @ "Patch_1"]
 
> Macro Patch
Cannot create connection from ["output" @ "Splitter_4"] to ["Boost" @ "Patch_3"]
 
> Macro Patch
Cannot create connection from ["outputImage" @ "RenderInImage_1"] to ["Image" @ "Patch_3"]
 
> Macro Patch
Cannot create connection from ["Mono_Structure" @ "Patch_3"] to ["BWImagePixelSStruct" @ "JavaScript_1"]
 
> (null)
State restoration failed on <QCPatch = 0x06FDAD20 "(null)">

If you can make Leopard friendly (no OpenCL!) and list plugins (and version, if any) I'm happy to look at the JS, which seems not too complex to check-out if composition is otherwise operational.

If you can make a demo comp just using the relevant JS patch(es) and some test data, that would be easier for me to look at on Leopard I think. Just save a few test structures of data to cover each condition and I can multiplex between them.

Cheers Alastair

idlefon's picture
Re: Javascript : hit test result trouble

There is a very important point in JS you should remember:

When the patch reaches "return" and executes it, the rest of the code will be skipped and it will start from the top again. So in you code the "i++" will never be executed.

I corrected your patch and attached the comp. I used "for" along "break"(when one of the points is inside the boundaries of the circle it breaks the loop and executes "return"), but I'm sure using "while" is no different.

BTW I played with the circle's color a bit, hope you don't mind :D

PreviewAttachmentSize
BEN_TRACKING_EDGES_03.qtz55.09 KB

benoitlahoz's picture
Re: Javascript : hit test result trouble

Thanks so much idlefon ! Thanks to you too Alastair.

Some esoteric thought I had : that the JS could return then begin once again the "for" loop.

The colors are perfect ! :-)

Thanks again.

jersmi's picture
Re: Javascript : hit test result trouble

benoitlahoz, this work you are doing in QC looks very interesting. makes me curious about your project. can you say more about what are doing with this good work?

checking out your comp and playing around with it -- check it out :)

PreviewAttachmentSize
BEN_TRACKING_EDGES_05.qtz165.25 KB

dust's picture
Re: Javascript : hit test result trouble

nice edge detection ben.

jersmi's picture
Re: Javascript : hit test result trouble

Edge detection, sure. I guess it's the manner in which it's done that appeals to me, nice and clear javascript and all. I can see interesting ways to develop it.

benoitlahoz's picture
Re: Javascript : hit test result trouble

Thanks jersmi and dust for your interest.

Actually we're working since january 2010 with the french research center on tracking shadow with the aim to be able to :

  • cancel it with video
  • fill it
  • applying effects to it
  • using it as an interactor

For the moment we are tracking the body masking an IR flow. Then we reproject a GLSL thresholded image on a screen. Tracking the shadow is a little bit more difficult if we don't use a screen flooded with IR, but we are studying a specific install to make it simple.

This is a shared research between a research center (CNRS), a theatre company (my part : L'ange Carasuelo) and the audience (scolars, people, ...).

Many projects (one big : a theatre spectacle allways in progress called "un petit à-côté du monde", adapted from books of Haruki Murakami, which premiere took place in january 2011 in Paris, and some "little" ones like installations) are involved in this research.

What I am beginning with this "edge detection" is to try to really get the edges coordinates (for the moment I have the inside of the shadow too) :

  • to use them as interactors on objects (passing through or pushing/dragging them)
  • to use them as attractors and limits for particles (this is the purpose of a specific installation I want to make).

Jersmi, your composition is great ! I like it very much and it's really a pleasure to see this old draft shadow we recorded in our beginnings, making other things than testing my tinkering !

The photos below are from "un petit à-côté du monde" (Dominique Chauvin, 2011). Thanks to vade's Rutt/Etra (and to Woody Vasulka !) and to blend modes...

PreviewAttachmentSize
lahoz_mur.png
lahoz_mur.png214.3 KB
thouseau_lahoz_rutt.png
thouseau_lahoz_rutt.png964.76 KB

franz's picture
Re: Javascript : hit test result trouble

nice ! mail me when there's a next show, I'd be happy to attend ! seems interesting....

benoitlahoz's picture
Re: Javascript : hit test result trouble

Thanks Frantz ! The next date is at Le Cube on the 20th of February (3 p.m.). I'd be glad to see you there.

Below, another comp with a "pong" attempt. I have few troubles with the velocities and directions, and I would like to make the ball reduce its speed after a while with a friction parameter, then to apply gravity.

Right now, I don't know where I have to work to make it possible. Working on it !

The video is in the original post.

PreviewAttachmentSize
BEN_TRACKING_EDGES_09_MVMT.qtz106.39 KB

benoitlahoz's picture
Re: PONG ! Javascript : hit test result trouble

Don't want to flood the forum with my little stuff, but well... that's a new work version, in which I changed the way to get the velocities to have the velocity of each point.

The "ball" behave stangely. Apart from my own errors, I guess that this is because of the contradictory velocities recorded while touching at a slow speed.

And the X & Y speed aren't well configurated. Some more work to come !

But well... I would love to manage to make a shadow pong so I can work on it with the scholars ! :-)

Thanks jersmi for the great iterator ! BTW : how do you make these colored horizontal and vertical lines ? I didn't find where it was in the patch. Is this in your image ?

Thanks all !

PreviewAttachmentSize
BEN_TRACKING_EDGES_13_MVMT_NEW_VEL.qtz196.24 KB

jersmi's picture
Re: PONG ! Javascript : hit test result trouble

Interesting work! Thanks for sharing. I'm working on a piece that may have some dates in Germany, Hungary and Portugal (in 2012, if the world doesn't end ;)). No dates in France yet but who knows. I'd come if I could! :)

Re: the iterator question, the lines are simply overlapping sprites when alpha < 1.

benoitlahoz's picture
Re: Splines Javascript : hit test result trouble

Well... no more hit test in this one, but reordering the found edges of the "shadow" then attach them to splines.

jersmi's picture
Re: Splines Javascript : hit test result trouble

inspiring work. happy to see it. more!

toneburst's picture
Re: Splines Javascript : hit test result trouble

Just saw this on Vimeo. Very impressive!

a|x

toneburst's picture
Re: Javascript : hit test result trouble

I think that's the same in most programming languages. I've seen 'early returns' used a lot in PHP as a feature to end a particular function early if a particular condition is true. Dunno if it's good practice to use it that way.

a|x

usefuldesign.au's picture
Re: Javascript : hit test result trouble

It's kind of like girl friends, there's nothing to say you can't have more than one, but it's definitely not to be encouraged ;-) Speaking as a girl who likes girls of course, not to sound like a sexist programmer.

jersmi's picture
Re: Splines Javascript : hit test result trouble

I have been learning much from your posts, thank you again for sharing. Curious about your spline comp -- you used javascript to sort the edges? Not that I am asking you to give away your secrets, but maybe I am. :) Would you share how you did it? I am playing around with it now, but haven't stumbled upon anything as nice yet...

Once again, your use of QC is very appealing.

benoitlahoz's picture
Re: Splines Javascript : hit test result trouble

Thank you so much for your interest jersmi, and you all. It makes me very happy.

Obviously I post this comp'. I will certainly use it for an installation soon, but my QC learnings entirely come from this site, from you all and your comps / plugins.

I made some tinkering more and now I'm on other researches (particularly, ordering the points - is it an obsession ??? - while recognizing if there are 2 or 3 persons in the image). I'm on, but everything would be easier if the PixelS was treating the image by the other side ("X" way). I didn't manage to understand the script... :-(

Javascript seems to slow a lot the comp'. Is OpenCL working with the GPU ? Too bad I don't understand this language (seems very difficult, isn't it ?).

Cheers ! And, please post, if you make those beautiful things I can see from you.

Ben

PS : The video is the same as the one in the zip file above. Be careful, it may be from my machine but I can't save if the viewer isn't on : it causes crash. I don't understand.

PreviewAttachmentSize
BEN_EDGES_30_WITH_ROT_STRUCT.qtz125.37 KB

jersmi's picture
Re: Splines Javascript : hit test result trouble

Thanks again, Ben! I am very interested -- this is really great work. I will indeed post anything I come up with.

Wow, you have given me a lot to look at in this comp. That is a lot of javascript... Ordering points is a worthwhile obsession. :)

Good luck diving in to openCL. Some great work being shown on kineme using it.

EDIT: Also, I have no problems saving file in any viewer state, etc.

cybero's picture
Re: Splines Javascript : hit test result trouble

If you are having problems when saving without Viewer on, it rather sounds like a local cache related issue. Yes OpenCL mainly works upon the GPU and can also access the CPU too. Brilliant looking composition BTW :-).

benoitlahoz's picture
Re: Splines Javascript : hit test result trouble

Thx cybero ! It happens only with this composition... Is there a way to resolve this problem ?

cybero's picture
Re: Splines Javascript : hit test result trouble

I cannot reproduce your problem, however, if it is a cache related issue, then you could [having closed down Quartz Composer aforehand], dive into ~/Library/Caches/ and delete

QCCompositionRepository-com.apple.QuartzComposer.editor.cache

and

QCCompositionRepository-com.apple.QuickLookDaemon.cache

I don't think you need to delete the Cache.db from the com.apple.QuartzComposer.editor folder. The deleted caches will recreate upon reopening the QC application.

If that doesn't sort the problem out, then I am left a little unsure.

benoitlahoz's picture
Re: Splines Javascript : hit test result trouble

Thanks a lot cybero. It doesn't solve the problem, but it seems to appear when I'm using splines...

cybero's picture
Re: Splines Javascript : hit test result trouble

That didn't solve the problem, and you say it happens when you are using Splines, well close down QC, download a fresh install of GL Tools 1.6 , de-install the existing GL Tools plugin and install from the freshly downloaded archive.

Can't think of much else. Basically, I can't reproduce your reported problem, what does the Crash Reporter say? Open Console application in Applications Utilities and see what it has to say about any reported Quartz Composer crashes.

You were using 1.6 already weren't you?

Anyone else got more than what is an increasingly foggy notion I have at my desktop for why benoit is suffering this difficulty when using Splines? Sorry benoit, it just isn't reproducible for me, but sounds similar to what those running earlier or beta versions of GL Tools have sometimes reported.

The only way that I could get close to crashing this composition of yours was when setting to debug in the Viewer.

Then QC crashes for me, failure on the Movie Importer. Not the same problem you reported, but an indication of an underlying structural problem. I'm sure that if you can achieve some greater efficiency within the Iterator, which I'm beginning to think is the source of your problems

benoitlahoz's picture
Re: Splines Javascript : hit test result trouble

Thanks a lot cybero for your full answer.

I have this message from the console (useful utility !) :

Quote:
12/02/11 01:11:33 Quartz Composer[6215] KinemeCore: Quartz Composer Editor crash detected: signal 10

It's a buggy comp'. You're right, I have to clean the Iterator and maybe make a few ones for the different displays instead of "one for all".

There are some bugs at the first launch of the Smooth Structure JS patch too. May be these are the cause of the crash... I shall take it step by step.

Thanks again !

(EDIT : in fact I was using the GL Tools 1.3 version. That resolved the problem !)

cybero's picture
Re: Splines Javascript : hit test result trouble

thought as much , GL Tools version problem, and in any case, improving the data flow throughput, process stages , the general construction will do your end product the world of good. Happy to hear you got that nailed down, creaky floorboards eh, got to dress and drape those nails so to speak :-). au revoir, et bientot