Hi,

I'v been trying to associate a TiledCameraDecorator with a
MultiDisplayWindow all the day.

But the remote render node displays nothing

Since I have to demo my progress to my advisor tomorrow, I must solve this
problem today.

I have attached my code with this email, please help check the code.

I have simplified the code, and highlighted the problem part; so you don't
need to check every thing. If correct, it will display a torus on the screen
of render node.

To run my program,
1) start a render server at local machine,
2) type: [program_name] -m [server_name]

actually, I have tested the TiledCameraDecorator in a normal OpenSG program,
it works perfectly.
Problem only occurs when I implement it in a cluster client program.

I hope this will not take too much of your time. I appreciate your every
effort.

Thanks~~

-- 
Jie Liu
Visualization Research Group
Center for Information Science, School of EECS,
Room 2104, Science Building No.2,
Peking University, Beijing 100871, China
#include <OpenSG/OSGConfig.h>	// we need this file in every OpenSG project

#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGGLUTWindow.h>

#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGLog.h>

// Geometry and material
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGImage.h>				// to support image background
#include <OpenSG/OSGSimpleTexturedMaterial.h>	// to support textured material
#include <OpenSG/OSGSolidBackground.h>

// MultiDisplay support
#include <OpenSG/OSGMultiDisplayWindow.h>

// Tiled camera
#include <OpenSG/OSGTileCameraDecorator.h>

#include <string.h>
#include <iostream>
#include <vector>
#include <string.h>

//#include "ImageFileHandler.h"

OSG_USING_NAMESPACE
using namespace std;

//=====================================================
//	global declarations
//=====================================================
SimpleSceneManager *g_SceneManager;

// Some fieldcontainer pointers that we require for interaction
NodePtr      g_SceneRoot	= NullFC;	

// geometry
NodePtr			g_ptrGeoNode;
GeometryPtr		g_ptrGeoQuad;	// a quad geometry

ViewportPtr*			g_pptrViewport;
TileCameraDecoratorPtr*	g_pptrCamDeco;

int g_ndivx = 1, g_ndivy = 1;

// animation settings
int   animate  = 0;
float aniSpeed = 0.5;
float lastFrame;

//=====================================================
//	forward declaration of global function
//=====================================================
int setupGLUT( int *argc, char *argv[] );
void flipimage(int dir, bool redraw=true);
void createscenegraph();

int main(int argc, char **argv)
{
	ChangeList::setReadWriteDefault();
	osgInit(argc,argv);

	int winid = setupGLUT(&argc, argv);

	MultiDisplayWindowPtr MDWndPtr = MultiDisplayWindow::create();

	// edit MultiDisplayWindow
	char*	opt;	//options

	int iserver = 0, ifile = 0;
	beginEditCP(MDWndPtr);
	{
		// check parameters
		for( int i = 1; i < argc; ++i )
		{
			switch(argv[i][1])
			{
			case 'm':	// to support multicast
				MDWndPtr->setConnectionType("Multicast");
				std::cout<<"use Multicast connection..."<<std::endl;
				break;
			case 'p':
				MDWndPtr->setConnectionType("SocketPipeline");
				std::cout<<"use SocketPipeline connection..."<<std::endl;
				break;
			case 'i': opt = argv[i][2] ? argv[i]+2 : argv[++i];
				if(opt != argv[argc])
					MDWndPtr->setConnectionInterface(opt);
				break;
			case 's':
				while( i<(argc-1) && argv[i+1][0] != '-')
				{
					cout<<"push '"<<argv[++i]<<"' into the server list"<<endl;
					MDWndPtr->getServers().push_back(argv[i]);
					iserver++;
				}
				break;
/*			case 'f':
				g_file_name.clear();
				while(i<(argc-1) && argv[i+1][0] != '-')
				{	
					cout<<"push '"<<argv[++i]<<"' into the display list"<<endl;
					g_file_name.push_back(argv[i]);
					ifile++;
				}
				break;
			case 'd':
				if( i>= (argc-1) || argv[i+1][0] == '-')
				{
					cout<<"-d <directory path>"<<endl;
					exit(0);
				}
				ifile = GetImageNamesInDir(argv[++i]);			
				break;
*/			case 'x':
				opt = argv[i][2] ? argv[i]+2 : argv[++i];
				if ( opt !=  argv[argc] )
					MDWndPtr->setHServers(atoi(opt));
				break;
			case 'y':
				opt = argv[i][2] ? argv[i]+2 : argv[++i];
				if ( opt != argv[argc] )
					MDWndPtr->setVServers(atoi(opt));
				break;
			case 'h':
			default:  
				std::cout << argv[0] <<endl
					<< " -m multicast\n"
					<< " -p pear to pear\n"
					<< " -i interface\n"
					<< " -f file1 file2...\n"
					<< " -d directory path\n"
					<< " -s server list\n"
					<< " -x horizontal server count\n"
					<< " -y vertical server count\n"
					<< endl;
				return 0;
			}
		}
	}

	if( iserver == 0 )
	{
		cout<<"no server name input! use '"<<argv[0]<<" -h' to see all command line options."<<endl;
		exit(0);
	}

	if( ifile == 0 )
	{
		cout<<"no file name input! ! use '"<<argv[0]<<" -h' to see all command line options."<<endl;
	}

	MDWndPtr->setSize(300, 300);	// dummy size for navigator
	endEditCP(MDWndPtr);

	//createscenegraph();
	g_ptrGeoNode = makeTorus(1, 3, 10, 10);

//==================================================================
// please help check the below code
// =================================================================	
	g_SceneManager = new SimpleSceneManager;
	g_SceneManager->setWindow   (MDWndPtr);
	g_SceneManager->setRoot     (g_ptrGeoNode);
	g_SceneManager->setHighlight(g_ptrGeoNode);

	ViewportPtr ptrViewport = MDWndPtr->getPort(0);

	PerspectiveCameraPtr ptrCam = PerspectiveCameraPtr::dcast(ptrViewport->getCamera());
	beginEditCP(ptrCam);
	ptrCam->setFov(deg2rad(90));
	endEditCP(ptrCam);

	Navigator* ptrNav = g_SceneManager->getNavigator();
	ptrNav->setAt(Pnt3f(0,0,0));
	ptrNav->setDistance(1.5);

	g_SceneManager->showAll();

	SolidBackgroundPtr ptrBackground = SolidBackground::create();
	beginEditCP(ptrBackground);
	{
		ptrBackground->setColor(Color3f(0,0.1,0));
	}
	endEditCP(ptrBackground);

	g_pptrViewport = new ViewportPtr[g_ndivx*g_ndivy];
	g_pptrCamDeco  = new TileCameraDecoratorPtr[g_ndivx*g_ndivy];

	for( int i = 0; i < g_ndivy; i++ )
	{
		for( int j = 0; j < g_ndivx; j++ )
		{
			int idx = i * g_ndivx + j;
			float l = 1./g_ndivx*j;
			float b = 1./g_ndivy*i;
			float r = 1./g_ndivx*(j+1);
			float t = 1./g_ndivy*(i+1);

			g_pptrViewport[idx] = Viewport::create();
			g_pptrViewport[idx]->setBackground(ptrViewport->getBackground());
			g_pptrViewport[idx]->setRoot(ptrViewport->getRoot());
			g_pptrViewport[idx]->setSize(0, 0, 1, 1);//(l, b, r, t);

			float dx = 0;//(r-l)*0.1;
			float dy = 0;//(t-b)*0.1;
			g_pptrCamDeco[idx] = TileCameraDecorator::create();
			g_pptrCamDeco[idx]->setDecoratee(ptrCam);
			g_pptrCamDeco[idx]->setSize(0, 0, 1, 1);//(l+dx, b+dy, r-dx, t-dy);

			g_pptrCamDeco[idx]->setFullSize(800, 800);	// ??? what size, seems the ratio

			g_pptrViewport[idx]->setCamera(g_pptrCamDeco[idx]);
		}
	}

	beginEditCP(MDWndPtr);
	//MDWndPtr->subPort(ptrViewport);	// if we delete the port0, the render node will display nothing 
	for(int i = 0; i < g_ndivx*g_ndivy; i++)
	{
		cout<<i<<endl;
		MDWndPtr->addPort(g_pptrViewport[i]);
	}
	endEditCP(MDWndPtr);

	g_SceneManager->setWindow(MDWndPtr);
	g_SceneManager->showAll();

	MDWndPtr->init();
//=============================================================================
// End of the problem code
// ============================================================================
	glutMainLoop();

	return 0;
}

void display(void)
{
	static float last_time = glutGet(GLUT_ELAPSED_TIME);
	if (animate)
	{
		float cur_time = glutGet(GLUT_ELAPSED_TIME);

		if( (cur_time-last_time) >= 3000 )
		{	
			flipimage(1, false);
			last_time = cur_time;
		}
	}

	g_SceneManager->redraw();

	OSG::Thread::getCurrentChangeList()->clearAll();
	glClear(GL_COLOR_BUFFER_BIT);
	glutSwapBuffers();
}

void reshape(int w, int h)
{
	g_SceneManager->resize(w, h);
	glutPostRedisplay();
}

void mouse(int button, int state, int x, int y)
{
	if (state)
		g_SceneManager->mouseButtonRelease(button, x, y);
	else
		g_SceneManager->mouseButtonPress(button, x, y);

	glutPostRedisplay();
}

void motion(int x, int y)
{
	g_SceneManager->mouseMove(x, y);
	glutPostRedisplay();
}

void keyboard(unsigned char k, int OSG_CHECK_ARG(x), int OSG_CHECK_ARG(y))
{
	switch(k)
	{
	case 27:        
		{
			OSG::osgExit();
			exit(0);
		}
		break;
	case 't':
		cout<<"I am still working..."<<endl;
		break;
	case 'a':
		{
			animate = 1 - animate;
		}
		break;
	}
}

void specialkeyboard(int key, int x, int y)
{
	switch(key)
	{
	case GLUT_KEY_LEFT:
		flipimage(-1);
		break;
	case GLUT_KEY_RIGHT:
		flipimage(1);
		break;
	}
}

int setupGLUT(int *argc, char *argv[])
{
	glutInit(argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

	int winid = glutCreateWindow("Image display - Client");

	glutReshapeFunc(reshape);
	glutDisplayFunc(display);
	glutMouseFunc(mouse);
	glutMotionFunc(motion);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(specialkeyboard);

	glutIdleFunc(display);

	return winid;
}

void flipimage(int dir, bool redraw)
{
/*
	static int index = 0;
	int n=(int)g_file_name.size();
	if ( n == 0 ) return;

	if( dir == 0 )
	{
		index = 0;
	}
	else
	{
		index = (index + dir + n) % n;
	}

	ImagePtr tImage = Image::create();
	tImage->read(g_file_name[index].c_str());

	// print image info
	cout<<"flip image: "<<g_file_name[index].c_str()<<endl;
	cout<<"size: "<<tImage->getWidth()<<" x "<<tImage->getHeight()<<endl;

	SimpleTexturedMaterialPtr tGeoTex = SimpleTexturedMaterial::create();
	beginEditCP(tGeoTex);
	tGeoTex->setMinFilter(GL_LINEAR);
	tGeoTex->setImage(tImage);
	//	g_ptrGeoTex->setMagFilter(GL_NEAREST);
	//g_ptrGeoTex->setEnvMode( GL_MODULATE );
	endEditCP(tGeoTex);

	beginEditCP(g_ptrGeoQuad);
	g_ptrGeoQuad->setMaterial(tGeoTex);
	endEditCP(g_ptrGeoQuad);

	if(redraw)
		glutPostRedisplay();
*/

}
/*
void createscenegraph()
{
	GeoPTypesPtr		ptrGeoType;	
	GeoPLengthsPtr		ptrGeoLen;	
	GeoColors3fPtr		ptrGeoColor;	
	GeoPositions3fPtr	ptrGeoVertex;	
	GeoTexCoords2fPtr	ptrGeoTexCoords;

	ImagePtr			ptrImage;
	SimpleTexturedMaterialPtr	ptrGeoTex;

	// type
	ptrGeoType = GeoPTypesUI8::create();
	beginEditCP(ptrGeoType, GeoPTypesUI8::GeoPropDataFieldMask);
	ptrGeoType->addValue(GL_QUADS);
	endEditCP(ptrGeoType, GeoPTypesUI8::GeoPropDataFieldMask);

	// length
	ptrGeoLen = GeoPLengthsUI32::create();
	beginEditCP(ptrGeoLen, GeoPLengthsUI32::GeoPropDataFieldMask);
	ptrGeoLen->addValue(4);
	endEditCP(ptrGeoLen, GeoPLengthsUI32::GeoPropDataFieldMask);

	// color
	ptrGeoColor = GeoColors3f::create();
	beginEditCP(ptrGeoColor);
	ptrGeoColor->addValue(Color3f(0.0, 0.2, 0.8));
	ptrGeoColor->addValue(Color3f(0.0, 0.2, 0.8));
	ptrGeoColor->addValue(Color3f(0.0, 0.2, 0.8));
	ptrGeoColor->addValue(Color3f(0.0, 0.2, 0.8));
	endEditCP(ptrGeoColor);

	// vertex
	float x = 1, y = 0.75;
	ptrGeoVertex = GeoPositions3f::create();
	beginEditCP(ptrGeoVertex, GeoPositions3f::GeoPropDataFieldMask);
	ptrGeoVertex->addValue(Pnt3f(-x, -y, 0));
	ptrGeoVertex->addValue(Pnt3f( x, -y, 0));
	ptrGeoVertex->addValue(Pnt3f( x,  y, 0));
	ptrGeoVertex->addValue(Pnt3f(-x,  y, 0));
	endEditCP(ptrGeoVertex, GeoPositions3f::GeoPropDataFieldMask);

	// texture coords
	ptrGeoTexCoords = GeoTexCoords2f::create();
	beginEditCP(ptrGeoTexCoords);
	ptrGeoTexCoords->addValue(Pnt2f(0, 0));
	ptrGeoTexCoords->addValue(Pnt2f(1, 0));
	ptrGeoTexCoords->addValue(Pnt2f(1, 1));
	ptrGeoTexCoords->addValue(Pnt2f(0, 1));
	endEditCP(ptrGeoTexCoords);

	// the geometry: quad
	g_ptrGeoQuad = Geometry::create();
	beginEditCP(g_ptrGeoQuad);
	g_ptrGeoQuad->setTypes(ptrGeoType);
	g_ptrGeoQuad->setLengths(ptrGeoLen);
	g_ptrGeoQuad->setPositions(ptrGeoVertex);
	g_ptrGeoQuad->setColors(ptrGeoColor);
	//g_ptrGeoQuad->setMaterial(ptrGeoTex);
	g_ptrGeoQuad->setTexCoords(ptrGeoTexCoords);
	endEditCP(g_ptrGeoQuad);

	flipimage(0);

	g_ptrGeoNode = Node::create();
	beginEditCP(g_ptrGeoNode);
	g_ptrGeoNode->setCore(g_ptrGeoQuad);
	endEditCP(g_ptrGeoNode);
}*/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to