SoTimerSensor-> socket animation (PLEASE HELP)

SoTimerSensor-> socket animation (PLEASE HELP)

Post by Tom Impellus » Wed, 27 Nov 1996 04:00:00



Total exasperation!

OK!  Please help

I am trying to write an open inventor code that draws, say,
a sphere of a given radius.

The radius will be read from a UNIX socket, or file, or
even generated internally, by a function.

I am trying to find a way to make the scene redraw every time
data is read, and data is being read CONTINUSOUSLY

In other words, I would like to call a function fxn() that
sets a global variable, say, size, to be used in the scaleing
of an image.

The only tool I can see of any use is SoTimerSenso, but that one
creates a callback that is called every 1/30 of a second, so
in my mind, it is NOT a process that is running in the background
behind Xtmainloop.

It seems sill that there is no node that does nothing but loop over:
1) calls a function to set variables (whether from file, socket, etc.)
2) redraws the scene.

I see rotor objects, translation objects, but those do not
allow me to plot a trajectory.

Other objects allow me to calcualte a trajectory, but then I lose
the ablility to continuosly call that function in the background.

OpenGL's GLUT library has this option:

glutIdleFunc(tick);

where tick is continuosly called in the background.

For example, look at example 17-3 in the text.

I would like to render this way:

                SbViewportRegion myViewport(WINWIDTH, WINHEIGHT);
                SoGLRenderAction myRenderAction(myViewport);
                myRenderAction.apply(root);
                glXSwapBuffers(display, window);
                myRenderAction.apply(root);
                SONODEFOREVER(myFunction());
                while(1)

something like that?

I look at the SoCalculator, and can envision a way I can kludge this
to make it work, but what I am trying to do seems so basic that I must
be missing something.

Please advise.

Tom

 
 
 

SoTimerSensor-> socket animation (PLEASE HELP)

Post by Kiril Vidimc » Wed, 27 Nov 1996 04:00:00



> Total exasperation!

> OK!  Please help

> I am trying to write an open inventor code that draws, say,
> a sphere of a given radius.

> The radius will be read from a UNIX socket, or file, or
> even generated internally, by a function.

> I am trying to find a way to make the scene redraw every time
> data is read, and data is being read CONTINUSOUSLY

If I understood you right, you need to constantly read input
and according to it to do changes in the Inventor scene.
In order to achieve this, you could use your own infite loop
(instead of using SoXt::mainloop ()):

   XtAppContext context = SoXt::getAppContext ();
   XEvent event;
   while (1)
   {
      SoXt::nextEvent (context, &event);
      SoXt::dispatchEvent (&event);
      // read data
      // do changes in the inventor scene
   }

KV
--

Kiril N. Vidimce                    Computer Science,

P.O. Box 3167, MS State, MS 39762   Engineering Research Center for CFS

 
 
 

SoTimerSensor-> socket animation (PLEASE HELP)

Post by Stephane Morva » Mon, 02 Dec 1996 04:00:00



> If I understood you right, you need to constantly read input
> and according to it to do changes in the Inventor scene.
> In order to achieve this, you could use your own infite loop
> (instead of using SoXt::mainloop ()):

>    XtAppContext context = SoXt::getAppContext ();
>    XEvent event;
>    while (1)
>    {
>       SoXt::nextEvent (context, &event);
>       SoXt::dispatchEvent (&event);
>       // read data
>       // do changes in the inventor scene
>    }

> KV

I think I tried that and it behaved really strangely. It was
practically impossibe for me to get the changes to be done at regular
intervals. Looked like the process was getting attention from the OS only
when the mouse was on the window. Then, I switched back to the SoTimerSensor.

If you want to do multithreading, then you will have to look into functions
such as sproc() and the alike. Are you sure you cannot wait the sensor's
callback to be executed, and let inventor take care of everything ?

--
Stephane Morvan

*************************************************************************
*                  Clemson Design Methodology Group                     *
*                                                                       *
* Home  : (864)-653-6762  Office : (864)-656-7189                       *

* WWW   : http://design.eng.clemson.edu/dmg/people/students/morvan.html *
*                                                                       *
*************************************************************************

 
 
 

SoTimerSensor-> socket animation (PLEASE HELP)

Post by Kiril Vidimc » Mon, 02 Dec 1996 04:00:00



> I think I tried that and it behaved really strangely. It was
> practically impossibe for me to get the changes to be done at regular
> intervals. Looked like the process was getting attention from the OS only
> when the mouse was on the window. Then, I switched back to the SoTimerSensor.

You are right. I tried the above method after I posted the message (I
should've done that *before* %-), and it seems like events get in only
when the mouse is above the render area *and* moving. So, I mailed the
poster (who had asked the original question) and suggested using
SoTimerSensor.

Here is a sample code if someone is interested in using SoTimerSensor:

#include <Inventor/Xt/SoXt.h>
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoTransform.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/sensors/SoTimerSensor.h>

void mySensorCB (void *data, SoSensor *)
{
  static float translate = 0.0, change = .05;

  if ((translate > 10.0) || (translate < 0.0))
    change *= -1.0;
  translate += change;

  SoTransform *xform = (SoTransform *) data;
  xform -> translation.setValue (translate, 0, 0);

Quote:}

void
main ()
{
  Widget w = SoXt::init ("Test");

  SoSeparator *root = new SoSeparator;
  root -> ref ();

  SoMaterial *mat = new SoMaterial ();
  mat -> diffuseColor.setValue (1, 0, 0);
  root -> addChild (mat);

  root -> addChild (new SoSphere ());

  SoTransform *xform = new SoTransform ();
  xform -> translation.setValue (10, 0, 0);
  root -> addChild (xform);

  mat = new SoMaterial ();
  mat -> diffuseColor.setValue (0, 1, 0);
  root -> addChild (mat);

  root -> addChild (new SoSphere ());

  SoXtExaminerViewer *viewer = new SoXtExaminerViewer (w);
  viewer -> setSceneGraph (root);
  viewer -> viewAll ();
  viewer -> show ();

  SoTimerSensor *timerSensor = new SoTimerSensor ();
  timerSensor -> setBaseTime (SbTime (0.0));
  timerSensor -> setInterval (SbTime (0.03));
  timerSensor -> setData (xform);
  timerSensor -> setFunction (mySensorCB);
  timerSensor -> schedule ();

  SoXt::show (w);
  SoXt::mainLoop ();

Quote:}

--

Kiril N. Vidimce                    Computer Science,

P.O. Box 3167, MS State, MS 39762   Engineering Research Center for CFS

 
 
 

SoTimerSensor-> socket animation (PLEASE HELP)

Post by Harri Holopain » Tue, 03 Dec 1996 04:00:00





..
>If I understood you right, you need to constantly read input
>and according to it to do changes in the Inventor scene.
>In order to achieve this, you could use your own infite loop
>(instead of using SoXt::mainloop ()):

Which will work nicely until you try to mix it with RapidApp/ViewKit.
Using your own main loop will then cause your dialog menus to be
left empty (just try it. ViewKit manuals say that you must use the
ViewKit main loop, but doesn't say where you are supposed to put
your select()s). Using XtAppAddInput will busyloop on my 5.3 Indy
(am I doing something wrong??). The work-around has been using the ViewKit mainloop
for a second, and then forgetting about it and processing all events
in a video lib frame transfer callback. Having Inventor viewer components in
RapidApp is nice but ViewKit often proves out to be much less nice.

..
>--

>Kiril N. Vidimce                    Computer Science,

>P.O. Box 3167, MS State, MS 39762   Engineering Research Center for CFS

--

 
 
 

SoTimerSensor-> socket animation (PLEASE HELP)

Post by Harri Holopain » Tue, 03 Dec 1996 04:00:00




Quote:>Total exasperation!

>OK!  Please help

>I am trying to write an open inventor code that draws, say,
>a sphere of a given radius.

>The radius will be read from a UNIX socket, or file, or
>even generated internally, by a function.

>I am trying to find a way to make the scene redraw every time
>data is read, and data is being read CONTINUSOUSLY

Looks like you would need to implement an Inventor engine. An engine
is a node with an output of desired type; if you've got a radius you'd
obviously need an engine with a SoFloat output. Every time your graph
needs a redraw or something has changed, the 'evaluate' method of your
engine is called. If your incoming data changes, there is a mechanism
to trigger a redraw only when necessary. Implementing an Inventor engine
for this (as opposed to a custom executable) has the nice feature
that if you make it a dso or dll it will work on every Inventor viewer
and scene automatically (and cause core dumps in crappy file converter
utils :).

I've actually coded a socket-reader engine which outputs floats. Currently
it has an internal timer sensor for read-checks. When the timer callback
triggers, I check for incoming data and if there is something, I update
the engine output accordingly and touch a field of the engine to trigger
graph redraw. A better method would be introducing a select() call
for the socket to the main loop (which would be trivial). Using the
timer sensor won't need modifications on non-X platforms though.

Quote:>In other words, I would like to call a function fxn() that
>sets a global variable, say, size, to be used in the scaleing
>of an image.

>The only tool I can see of any use is SoTimerSenso, but that one
>creates a callback that is called every 1/30 of a second, so
>in my mind, it is NOT a process that is running in the background
>behind Xtmainloop.

uh? then what would that be instead?

Quote:>It seems sill that there is no node that does nothing but loop over:
>1) calls a function to set variables (whether from file, socket, etc.)
>2) redraws the scene.

Using engines you really don't need to worry about redraws, they are
normally handled automatically. If you just loop in a timer sensor
callback in your program and update field values you'll get automatic
redraws.

Quote:>I see rotor objects, translation objects, but those do not
..
>I would like to render this way:

>                SbViewportRegion myViewport(WINWIDTH, WINHEIGHT);
>                SoGLRenderAction myRenderAction(myViewport);
>                myRenderAction.apply(root);
>                glXSwapBuffers(display, window);
>                myRenderAction.apply(root);
>            SONODEFOREVER(myFunction());
>            while(1)

IMO a far better approach to general cases is to implement stand-alone
engine classes. The Inventor handbooks have the annoying feature of
making all examples as silly little example executables and the only
hint to a far better strategy is the vague 'some platforms may support
dynamically linked objects' or something like that. And yeah I know
adding chapters for every dll/dso implementation would be out scope
for Inventor manuals but still.

Quote:>I look at the SoCalculator, and can envision a way I can kludge this
>to make it work, but what I am trying to do seems so basic that I must
>be missing something.

it would seem so:)

Quote:>Please advise.

>Tom

--

 
 
 

SoTimerSensor-> socket animation (PLEASE HELP)

Post by Dave Shreine » Wed, 04 Dec 1996 04:00:00






> ..
> >If I understood you right, you need to constantly read input
> >and according to it to do changes in the Inventor scene.
> >In order to achieve this, you could use your own infite loop
> >(instead of using SoXt::mainloop ()):

> Which will work nicely until you try to mix it with RapidApp/ViewKit.
> Using your own main loop will then cause your dialog menus to be
> left empty (just try it. ViewKit manuals say that you must use the
> ViewKit main loop, but doesn't say where you are supposed to put
> your select()s). Using XtAppAddInput will busyloop on my 5.3 Indy
> (am I doing something wrong??). The work-around has been using the
> ViewKit mainloop for a second, and then forgetting about it and
> processing all events in a video lib frame transfer callback. Having
> Inventor viewer components in RapidApp is nice but ViewKit often
> proves out to be much less nice.

   The reason that the menus don't appear is that they are constructed
in a work proc.  As such, if you don't call XtAppNextEvent(), the
work proc is never called, and no menus.

   As for the socket thingy, I would have suggested using
XtAppAddInput() as well.  I'm not sure why this causes a busy loop
for you.  Can you provide any other details?

Thanx,
Dave

  ---------------------------------------------------------------------


   Silicon Graphics, Inc.                            (301) 572-3290

 
 
 

1. Please >>>Video Post help (much wringing of hands)

Help (in a Kramer voice: "Im' beggin' ya Jerry, I'm beggin' ya!")

I'm working on learning particles/lens effects/and Video Post in max2
Running Windows 95 on PII 266 w/ 128megs of Ram).

Created a wand with sparks shooting out of it.
Opened video post, added a glow effect on the sparks and some
electricity from Inferno. Now for me, this was very cool. I was really
enjoying myself.
Set it up as input, filter, output. No indenting.

Executed/rendered animation scene in Video Post and it looked good but I
can't save it as an AVI or anything that I can view seperately. Only
thing available from the pull down menu is an AST digital recorder
(which I don't have). Shouldn't AVI be available in the output menu?

I saw the Video Post in the track view listing so I tried rendering the
animation from there... that didn't work either. (:>(

Checked the manual, checked Max 2 Fundmentals. Help!

What am I doing wrong?

Thanks in advance.

PS: Yes I downloaded the update from Kinitex.

2. import<>export srtata studio pro<>3ds max

3. HELP PLEASE Need AVI >>>>>>>>>>>> FLI

4. Help with script-fu

5. animation data via socket

6. Sorting Plugins

7. >>Please help: jpeg problems....

8. ILM Rendering....

9. Please help: Slides >> jpeg

10. >>REQ:Help:Planetary backlight:Clarification needed Please

11. Animation Please Please Help

12. HELP FOR 3DS4 >>>>>K6