Hi,
There is a ruby wrapper available for vtk which works, more or less,
fine. For those who are not familiar with vtk, it is avisualisation
library written in c++ and the output is a native window showing some
interactive OpenGL graphics.
The VTK code usually ends with:
iren = Vtk::RenderWindowInteractor.new
iren.start()
Here is where the problem comes: iren.start() starts a new thread in
c++, while, I am trying to run the script in irb and interactively
change the objects properties and see the live results in the OpenGL
window. Unfortunately, after iren.start() ruby goes to a deep sleep.
This is the irb output:
?> iren.Start()
which obviously does not let me to enter any more commands unless I
close the window:
=> nil
which is too late for manipulating objects interactively.
It is surprising when a multi-threaded c++ library is single-threaded
after wrapping to ruby. If this does something have to do with ruby not
supporting native threads, perhaps it is a big sacrifice for
portability.
What is the best way to have irb command line, while also having the
graphics rendering window?
···
--
Posted via http://www.ruby-forum.com/\.
I don't have any of this stuff installed, so I'm guessing, but couldn't
you just do e.g.:
winthr = Thread.new { iren.Start() }
// do whatever else you need to do
winthr.kill # or close the window may be better
Obviously I don't know about the concurrency issues but with this being
interactive I'd guess it's not something you'd worry much about.
···
On Fri, 2006-11-10 at 02:09 +0900, Aureliano Buendia wrote:
There is a ruby wrapper available for vtk which works, more or less,
fine. For those who are not familiar with vtk, it is avisualisation
library written in c++ and the output is a native window showing some
interactive OpenGL graphics.
The VTK code usually ends with:
iren = Vtk::RenderWindowInteractor.new
iren.start()
Here is where the problem comes: iren.start() starts a new thread in
c++, while, I am trying to run the script in irb and interactively
change the objects properties and see the live results in the OpenGL
window. Unfortunately, after iren.start() ruby goes to a deep sleep.
This is the irb output:
>>
?> iren.Start()
which obviously does not let me to enter any more commands unless I
close the window:
=> nil
>>
which is too late for manipulating objects interactively.
--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk
Ross Bamford wrote:
winthr = Thread.new { iren.Start() }
// do whatever else you need to do
winthr.kill # or close the window may be better
I get the same thing:
?> winthr = Thread.new { iren.Start() }
Still no command line. All I want is a command line with access to the
the objects in the running thread.
You do not need to have access to this library, it can be emulated
easily: Assume you want to run a very long process names
VeryLongProcess(). I want a command line when VeryLongProcess() is
running and I want this command line to have acees to all the objects
that VeryLongProcess() has access to them.
···
--
Posted via http://www.ruby-forum.com/\.
Ross Bamford wrote:
> winthr = Thread.new { iren.Start() }
>
> // do whatever else you need to do
>
> winthr.kill # or close the window may be better
>
I get the same thing:
?> winthr = Thread.new { iren.Start() }
Still no command line. All I want is a command line with access to the
the objects in the running thread.
Well, it looks like something in the library is blocking the calling
process (and all Ruby's green threads) completely. If so, it's probably
something you'd have to talk to the binding's maintainer about.
I did just try to install VTK but it barfed horribly on my Linux box so
I'm afraid I can't be much more help.
You do not need to have access to this library, it can be emulated
easily: Assume you want to run a very long process names
VeryLongProcess(). I want a command line when VeryLongProcess() is
running and I want this command line to have acees to all the objects
that VeryLongProcess() has access to them.
Assuming you mean 'process' in the sense of 'something happening in
Ruby', then the thread thing I suggested should work. If OTOH I'm
missing something and you're referring to actual processes, then it gets
more involved...
···
On Fri, 2006-11-10 at 02:36 +0900, Aureliano Buendia wrote:
--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk
Ross,
Forget about vtk, put it this way. Save this in a script and run it by
irb:
i = 1
while 1
puts i
end
It doesn't allow you to add any more command lines unless the
never-ending while-loop is over. Wrapping this in a thread does not help
it too:
Thread.new{
i = 1
while 1
puts i
end
}
All I want to do is to have the while loop, and then enter
i = 2
in the command line to get 2 printed.
···
--
Posted via http://www.ruby-forum.com/.
Ross,
Forget about vtk, put it this way. Save this in a script and run it by
irb:
i = 1
while 1
puts i
end
It doesn't allow you to add any more command lines unless the
never-ending while-loop is over.
True.
Wrapping this in a thread does not help it too:
Thread.new{
i = 1
while 1
puts i
end
}
Apart from the fact that the output makes it difficult to type, that works fine for me, with one small change - you need to declare 'i' before you start the thread - otherwise, it'll be local to the block you run in the thread. So try (rubified a bit):
i = 1
Thread.new { loop { puts i } }
You'll get lots of '1's printed out. If you just jump in and type 'i = 2' and hit return, the '1's become '2's. Does that not work for you?
···
On Thu, 09 Nov 2006 18:21:38 -0000, Aureliano Buendia <saveez@hotmail.com> wrote:
--
Ross Bamford - rosco@roscopeco.remove.co.uk
Message-ID: <321ad0f7032e5797ad32f03f78ddda74@ruby-forum.com>
It doesn't allow you to add any more command lines unless the
never-ending while-loop is over. Wrapping this in a thread does not help
it too:
What is your OS ?
If it is Windows, your trouble may depends on console I/O.
Console I/O of Win (e.g. to get a conmmand line on IRB)
blocks thread-switching of Ruby.
# Please see [ruby-talk:223935] also.
···
From: Aureliano Buendia <saveez@hotmail.com>
Subject: Re: Ruby and threads: a VTK example
Date: Fri, 10 Nov 2006 03:21:38 +0900
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
Hidetoshi NAGAI wrote:
It doesn't allow you to add any more command lines unless the
never-ending while-loop is over. Wrapping this in a thread does not help
it too:
What is your OS ?
If it is Windows, your trouble may depends on console I/O.
Console I/O of Win (e.g. to get a conmmand line on IRB)
blocks thread-switching of Ruby.
# Please see [ruby-talk:223935] also.
Hidetoshi,
The OS is WinXP, I have also tried IRB with eclipse as an external tool
with no luck. What Ross described does not work on windows as he has
ruby on a linux box. The example you mentioned in runy-talk was done
with tk. Is there any ways or doing this in simple dos command prompt
(or eclipse)? I expected ruby to me more portable than this!
···
--
Posted via http://www.ruby-forum.com/\.
Message-ID: <d789bb9a08469ba828641bdc2e4bb95c@ruby-forum.com>
The example you mentioned in runy-talk was done
with tk. Is there any ways or doing this in simple dos command prompt
(or eclipse)?
I'm sorry, but I have no idea. If I had, I didn't make irbtkw.rbw.
Probably, it requires rewriting IRB::StdioInputMethod#gets.
I don't know how it has to be changed, because I'm not familiar with
programing on Windows.
···
From: Aureliano Buendia <saveez@hotmail.com>
Subject: Re: Ruby and threads: a VTK example
Date: Sat, 11 Nov 2006 02:18:18 +0900
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)