Re: [osg-users] osgViewer takes over my standard input

2012-09-26 Thread Christoffer Pettersson
I tried switching to getline stringstream combo and also using the ignore 
statement to ignore previous content in the buffer. It still gave me the same 
non blocking result though.

I received your code, I will have a look at it, thanks :)

Kind Regards
Christoffer

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50306#50306





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Christoffer Pettersson
Hello, I'm trying to write a program where the renderer is running on a 
separate thread. On the main thread I want to control the command line inputs 
but as soon as I add scenedata to the osgViewer which is stored in the renderer 
then the renderer takes over the standard input. std::cin in the main thread is 
ignored. If I put std::cin in the renderer thread however the program pauses 
and expects an input from the command line.

Does anyone know how I can prevent osgViewer from taking over the command line? 
I have attached sample code to this post where I demonstrate the problem.


Code:

#include 
#include 
#include 

class MiniRenderer: public OpenThreads::Thread 
{ 
public: 
void addModel(osg::Node* node) 
{ 
_nodes.push_back(node); 
} 

void run() 
{ 
_viewer.setUpViewInWindow(0, 0, 640, 480); 
_viewer.realize(); 
_sceneRoot = new osg::Group; 
_run = true; 
while(_run) 
{ 
if(_nodes.size()0) 
{ 
for(unsigned int i = 0; i  _nodes.size(); ++i) 
_sceneRoot-addChild(_nodes[i]); 
_nodes.clear(); 
_viewer.setSceneData(_sceneRoot.get()); 
} 
int test = -2; 
std::cout  In Thread:   std::endl; 
std::cin  test; 
std::cout  In Thread :   test  std::endl; 
_viewer.frame(); 
} 
} 
bool _run; 
osg::ref_ptr _sceneRoot; 
osgViewer::Viewer _viewer; 
std::vector  _nodes; 
}; 


int main( int argc, char **argv ) 
{ 
std::cout  Starting thread  std::endl; 
MiniRenderer *minirenderer = new MiniRenderer(); 
mr-startThread(); 

osg::ref_ptr root = osgDB::readNodeFile(cessna.osg); 
minirenderer-addModel(root); 
int test = -1; 

std::cout  Main cin  std::endl; 
std::cin  test; 
std::cout  Main cin:   test  std::endl; 

while(true) 
{ 

} 
return 0; 
} 




Edit: Parts of my code seem to have gone missing after I posted this, so here's 
a pastebin link with the code: 

pastebin . com / GxFAbZvf

I found one way to be able to get input from the console by using 
std::cin.clear() and std::ignore(std::numeric_limitstd::streamsize::max, 
'\n'). But this code would work in some places but not in others, so I can't 
use this since it's very unreliable..

Kind Regards
Hoffe

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49913#49913





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Christoffer Pettersson
Hello,

This problem occurs when I run the code on an old machine with intel core 2 
duo,Nvidia quadro FX 580, 4gb ram, OS=Slackware. If I run this code on another 
machine with Intel i7-3770, AMD Radeon 7800 series (2gb), 12gb ram, OS=Red Hat 
then the code runs just fine.

Do you have any ideas as to why this older hardware does not handle this code 
properly?


 
 Using standard input is a bit unusual for a rendering application, 
 might I suggest you just read the keyboard input from the actual 
 rendering window itself?


Unfortunately this is not an option. I'm writing a test framework which depends 
on input from the console.

Kind Regards
Christoffer

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50279#50279





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Robert Osfield
Hi Christoffer,

On 25 September 2012 12:39, Christoffer Pettersson hoffe...@hotmail.com wrote:
 This problem occurs when I run the code on an old machine with intel core 2 
 duo,Nvidia quadro FX 580, 4gb ram, OS=Slackware. If I run this code on 
 another machine with Intel i7-3770, AMD Radeon 7800 series (2gb), 12gb ram, 
 OS=Red Hat then the code runs just fine.

 Do you have any ideas as to why this older hardware does not handle this code 
 properly?

As I mentioned in my previous email handling of cin won't be releated
to the OSG itself, and I'd go further and say it will not have
anything to do with the hardware and drivers as well.

This will be compiler or terminal interaction.

I'll also state, write a proper gui.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Christoffer Pettersson
hmm ok. I tried the code on another computer with specifications between the 
two computers mentioned before. This one running Slackware as well. And the 
code ran fine on this one. Theyre using the same terminal and as far as I know 
they also use the same compiler.

As I mentioned before, Writing a proper gui is not an option. The framework 
needs to be controlled from the terminal.

Kind Regards
Christoffer

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50285#50285





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Jason Daly

On 09/25/2012 12:04 PM, Christoffer Pettersson wrote:

hmm ok. I tried the code on another computer with specifications between the 
two computers mentioned before. This one running Slackware as well. And the 
code ran fine on this one. Theyre using the same terminal and as far as I know 
they also use the same compiler.

As I mentioned before, Writing a proper gui is not an option. The framework 
needs to be controlled from the terminal.


Hi, Christoffer,

As Robert has hinted at, the OSG isn't really designed to be used from 
the command line, and as such, it doesn't provide any interfaces to do 
so.  That usage model is rather antiquated and graphical interfaces are 
by far the norm these days.


As luck would have it, however, I recently implemented a tool that was 
also required to be console-driven.  The easiest way to handle it is to 
use a separate thread to wait for and read your input (this way, stdin 
can block as usual while waiting for a command, while the main viewer 
threads can proceed merrily on their way).  I'll send you my console app 
(off-list), so you can have an example to follow.


--J

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Jorge Izquierdo Ciges
Maybe would be easier to do a client-server approach to give orders to the
renderer (server) and that the client program would hear the terminal
orders.

2012/9/25 Jason Daly jd...@ist.ucf.edu

 On 09/25/2012 12:04 PM, Christoffer Pettersson wrote:

 hmm ok. I tried the code on another computer with specifications between
 the two computers mentioned before. This one running Slackware as well. And
 the code ran fine on this one. Theyre using the same terminal and as far as
 I know they also use the same compiler.

 As I mentioned before, Writing a proper gui is not an option. The
 framework needs to be controlled from the terminal.


 Hi, Christoffer,

 As Robert has hinted at, the OSG isn't really designed to be used from the
 command line, and as such, it doesn't provide any interfaces to do so.
  That usage model is rather antiquated and graphical interfaces are by far
 the norm these days.

 As luck would have it, however, I recently implemented a tool that was
 also required to be console-driven.  The easiest way to handle it is to use
 a separate thread to wait for and read your input (this way, stdin can
 block as usual while waiting for a command, while the main viewer threads
 can proceed merrily on their way).  I'll send you my console app
 (off-list), so you can have an example to follow.

 --J


 __**_
 osg-users mailing list
 osg-users@lists.**openscenegraph.org osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.**org/listinfo.cgi/osg-users-**
 openscenegraph.orghttp://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Christoffer Pettersson
Hi Robert,

That is pretty much what I'm doing, just the other way around. The main thread 
is responsible for handling standard inputs, while the second thread is 
responsible for handling the renderer. 

Hi Jorge,
That is exactly what I try to mimic using the current design :) I cant add 
network support at the moment so I need to use the sort of design I have 
presented.

Kind Regards
Christoffer

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50290#50290





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Jason Daly

On 9/25/2012 5:01 PM, Christoffer Pettersson wrote:

Hi Jason,

That is pretty much what I'm doing, just the other way around. The main thread 
is responsible for handling standard inputs, while the second thread is 
responsible for handling the renderer.
   


I didn't see the code you posted earlier (just looked it up on the forum).

I'm a bit confused as to why you're reading from cin in both threads.  
That is definitely going to cause a problem.  You should only be reading 
from cin in the main thread in your case.  I'd expect the viewer thread 
to be hanging up on that cin call in the run() function on every frame.


Another potential issue I saw is that you're not protecting your _nodes 
vector at all.  You could theoretically be trying to add a model to it 
in the main thread at the same time as you're pulling models off of it 
in the renderer thread.


--J

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Christoffer Pettersson
The cin in the thread is only there for demonstration purposes. It was used to 
test the blocking of the cin function. If i write cin in the render thread then 
the program is halted. If i write it in the main thread it is not halted. The 
model code is also just for demonstration. That part of the code works. It's 
essentially just there to recreate the cin problem

Kind regards
Christoffer

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50292#50292





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Jason Daly

On 9/25/2012 5:27 PM, Christoffer Pettersson wrote:

The cin in the thread is only there for demonstration purposes. It was used to 
test the blocking of the cin function. If i write cin in the render thread then 
the program is halted. If i write it in the main thread it is not halted. The 
model code is also just for demonstration. That part of the code works. It's 
essentially just there to recreate the cin problem
   


Maybe I'm missing your point, but that behavior is exactly what I would 
expect.


If you try to read from cin in the same thread that you're using for the 
OSG rendering, it will block waiting for input every time.  As far as I 
know, there's no way for it to not block.  The way to get around this is 
to read commands from cin in a different thread and store the commands 
in a buffer, and then process the buffered commands in the render thread 
between frames.


--J

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Christoffer Pettersson
The cin in the render thread is not supposed to be there. They were just put 
there to see if they would block or not, which they did.  The problem i have is 
that if i write cin in any other thread than the render thread, then the thread 
containing the cin command does not block. It jumps over the cin command giving 
me an empty buffer. This happens on 1 out of the 3 computers i have tested the 
code on. On the other 2, the cin command succesfully blocks.

Kind regards 
Christoffer

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50294#50294





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-25 Thread Jason Daly

On 09/25/2012 05:45 PM, Christoffer Pettersson wrote:

The cin in the render thread is not supposed to be there. They were just put 
there to see if they would block or not, which they did.  The problem i have is 
that if i write cin in any other thread than the render thread, then the thread 
containing the cin command does not block. It jumps over the cin command giving 
me an empty buffer. This happens on 1 out of the 3 computers i have tested the 
code on. On the other 2, the cin command succesfully blocks.


Ah, OK, now I understand the problem.  Thanks  :-)

Not sure about your case, but usually when std::cin doesn't block, it 
means that there's something left to be read from the stream.  What 
happens if you switch to using std::getline() instead?  You can then 
process the entire line of input using a stringstream, and there's no 
chance a stray \n will get stuck in the stream.  It's usually better to 
process console input in a line-oriented way.



Take a look at this question on Stack Overflow:

http://stackoverflow.com/questions/11354936/why-doesnt-stdgetline-block


--J

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgViewer takes over my standard input

2012-09-17 Thread Robert Osfield
Hi Christoffer,

The OSG does absolutely nothing with standard input, go have a look at
the whole source code base.  standard error and standard output are
used for debug and info messages but nothing is read.

So... this has to be a non OSG specific programming question, which I
suspect is likely to be down to a platform oddity on the platform you
are using.

Using standard input is a bit unusual for a rendering application,
might I suggest you just read the keyboard input from the actual
rendering window itself?

Robert.

On 11 September 2012 09:20, Christoffer Pettersson hoffe...@hotmail.com wrote:
 Hello, I'm trying to write a program where the renderer is running on a 
 separate thread. On the main thread I want to control the command line inputs 
 but as soon as I add scenedata to the osgViewer which is stored in the 
 renderer then the renderer takes over the standard input. std::cin in the 
 main thread is ignored. If I put std::cin in the renderer thread however the 
 program pauses and expects an input from the command line.

 Does anyone know how I can prevent osgViewer from taking over the command 
 line? I have attached sample code to this post where I demonstrate the 
 problem.


 Code:

 #include
 #include
 #include

 class MiniRenderer: public OpenThreads::Thread
 {
 public:
 void addModel(osg::Node* node)
 {
 _nodes.push_back(node);
 }

 void run()
 {
 _viewer.setUpViewInWindow(0, 0, 640, 480);
 _viewer.realize();
 _sceneRoot = new osg::Group;
 _run = true;
 while(_run)
 {
 if(_nodes.size()0)
 {
 for(unsigned int i = 0; i  _nodes.size(); ++i)
 _sceneRoot-addChild(_nodes[i]);
 _nodes.clear();
 _viewer.setSceneData(_sceneRoot.get());
 }
 int test = -2;
 std::cout  In Thread:   std::endl;
 std::cin  test;
 std::cout  In Thread :   test  std::endl;
 _viewer.frame();
 }
 }
 bool _run;
 osg::ref_ptr _sceneRoot;
 osgViewer::Viewer _viewer;
 std::vector  _nodes;
 };


 int main( int argc, char **argv )
 {
 std::cout  Starting thread  std::endl;
 MiniRenderer *minirenderer = new MiniRenderer();
 mr-startThread();

 osg::ref_ptr root = osgDB::readNodeFile(cessna.osg);
 minirenderer-addModel(root);
 int test = -1;

 std::cout  Main cin  std::endl;
 std::cin  test;
 std::cout  Main cin:   test  std::endl;

 while(true)
 {

 }
 return 0;
 }




 Kind Regards
 Hoffe

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=49913#49913





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org