fixed: gcc8 compile issues
[opensg.git] / Source / Contrib / VTK / testVTKCluster.cpp
blobb24810e1bf3e00d5603a85f48ac1a22fb9de20b7
2 #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
3 #pragma GCC diagnostic warning "-Wold-style-cast"
4 #endif
6 #include "OSGConfig.h"
8 #ifdef OSG_WITH_VTK
10 // #define FRAMEINTERLEAVE
11 #include "OSGGLUT.h"
12 #include "OSGGLU.h"
13 #include "OSGConfig.h"
14 #include <iostream>
15 #include "OSGLog.h"
16 #include "OSGTransform.h"
17 #include "OSGGroup.h"
18 #include "OSGNode.h"
19 #include "OSGClusterWindow.h"
20 #include "OSGSceneFileHandler.h"
21 #include "OSGDirectionalLight.h"
22 #include "OSGSimpleGeometry.h"
23 #include "OSGCamera.h"
24 #include "OSGViewport.h"
25 #include "OSGPerspectiveCamera.h"
26 #include "OSGSolidBackground.h"
27 //#include "OSGGradientBackground.h"
28 #include "OSGTrackball.h"
29 #include "OSGVolumeDraw.h"
30 #include "OSGGLUTWindow.h"
31 #include "OSGRenderAction.h"
32 //#include "OSGDrawAction.h"
33 #include "OSGMultiDisplayWindow.h"
34 //#include "OSGSortFirstWindow.h"
35 #include "OSGChunkMaterial.h"
36 #include "OSGPolygonChunk.h"
37 #include "OSGTriangleIterator.h"
38 #include "OSGMaterialGroup.h"
39 //#include "OSGSortLastWindow.h"
40 #include "OSGImageComposer.h"
41 #include "OSGProxyGroup.h"
42 #ifdef FRAMEINTERLEAVE
43 #include "OSGFrameInterleaveWindow.h"
44 #endif
45 #include "OSGShearedStereoCameraDecorator.h"
46 #include "OSGNameAttachment.h"
47 #include "OSGColorBufferViewport.h"
49 #include "OSGVTKPolyDataMapper.h"
51 #include "vtkStructuredGridReader.h"
52 #include "vtkStructuredGrid.h"
53 #include "vtkPointData.h"
54 #include "vtkActor.h"
55 #include "vtkStructuredGridOutlineFilter.h"
56 #include "vtkPolyDataMapper.h"
57 #include "vtkProperty.h"
58 #include "vtkStructuredGridGeometryFilter.h"
59 #include "vtkPointSource.h"
60 #include "vtkRungeKutta4.h"
61 #include "vtkStreamLine.h"
62 #include "vtkTubeFilter.h"
63 #include "vtkPolyDataNormals.h"
65 OSG::Trackball tball;
66 int mouseb = 0;
67 int lastx=0, lasty=0;
68 int winwidth = 300;
69 int winheight = 300;
70 OSG::NodeRecPtr root;
71 OSG::TransformRecPtr cam_trans;
72 OSG::PerspectiveCameraRecPtr cam;
73 OSG::ClusterWindowRecPtr clusterWindow;
74 OSG::RenderActionRefPtr ract;
75 OSG::GLUTWindowRecPtr clientWindow;
77 #ifdef HAVE_SORT
78 OSG::SortFirstWindowRecPtr sortfirst;
79 OSG::SortLastWindowRecPtr sortlast;
80 #endif
82 #ifdef FRAMEINTERLEAVE
83 OSG::FrameInterleaveWindowRecPtr frameinterleave;
84 #endif
85 OSG::MultiDisplayWindowRecPtr multidisplay;
86 bool animate=false;
87 int animLoops=-1;
88 int animLength=30;
89 bool multiport=false;
90 float ca=-1,cb=-1,cc=-1;
91 OSG::Int32 stereoMode=0;
92 float eyedistance=1,zeroparallax=10;
93 int serverx=-1,servery=-1;
94 std::vector<OSG::Quaternion> animOri;
95 std::vector<OSG::Vec3f > animPos;
96 std::string animName="animation.txt";
97 OSG::Real32 animTime=0;
98 std::string serviceAddress;
99 bool serviceAddressValid = false;
100 OSG::UInt32 interleave=0;
101 OSG::Real32 _dsFactor = 1.0; // scale down factor.
102 bool _enablecc = true; // enable color correction.
103 OSG::PolygonChunkRecPtr polygonChunk;
104 bool prepared=false;
105 bool showInfo=false;
106 OSG::Time frame_time=0;
107 OSG::UInt32 sum_positions=0;
108 OSG::UInt32 sum_geometries=0;
109 OSG::UInt32 sum_triangles=0;
110 bool info = false;
111 std::string connectionDestination="";
112 std::string connectionInterface="";
113 OSG::SolidBackgroundRecPtr bkgnd;
114 OSG::UInt32 subtilesize=32;
116 void cleanup(void)
118 ract = NULL;
119 root = NULL;
120 cam_trans = NULL;
121 cam = NULL;
122 clusterWindow = NULL;
123 clientWindow = NULL;
124 #ifdef HAVE_SORT
125 sortfirst = NULL;
126 sortlast = NULL;
127 #endif
128 #ifdef FRAMEINTERLEAVE
129 frameinterleave = NULL;
130 #endif
131 multidisplay = NULL;
132 polygonChunk = NULL;
133 bkgnd = NULL;
135 OSG::osgExit();
138 /*! Simple show text function
140 void displayInfo(int x, int y)
142 int len, i;
143 #ifdef WIN32
144 #ifdef OSG_WIN32_CL
145 void *font = (void *) 2;
146 #else
147 void *font = 2;
148 #endif
149 #else
150 void *font = GLUT_BITMAP_9_BY_15;
151 #endif
153 char text[1024];
154 sprintf(text,
155 "FPS: %12.1f\n"
156 "Positions: %12u\n"
157 "Triangles: %12u\n"
158 "Geometries: %12u",
159 1.0/frame_time,
160 sum_positions,
161 sum_triangles,
162 sum_geometries);
164 glPushAttrib(GL_ALL_ATTRIB_BITS);
165 glDisable(GL_LIGHTING);
166 glEnable(GL_COLOR_MATERIAL);
167 glPushMatrix();
168 glLoadIdentity();
169 glMatrixMode(GL_PROJECTION);
170 glPushMatrix();
171 glLoadIdentity();
172 gluOrtho2D(0,clientWindow->getWidth(),0,clientWindow->getHeight());
173 glDisable(GL_DEPTH_TEST);
174 glEnable(GL_BLEND);
175 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
177 int x1=x-5;
178 int x2=x1+24*9+10;
179 int y1=y+14;
180 int y2=y1-4*20;
181 glBegin(GL_QUADS);
182 glColor4f(.1, .1, .7, .5);
183 glVertex2i(x1,y1);
184 glVertex2i(x1,y2);
185 glVertex2i(x2,y2);
186 glVertex2i(x2,y1);
187 glEnd();
188 glBegin(GL_LINE_LOOP);
189 glColor3f(1.0, 1.0, 0.0);
190 glVertex2i(x1,y1);
191 glVertex2i(x1,y2);
192 glVertex2i(x2,y2);
193 glVertex2i(x2,y1);
194 glEnd();
196 glColor3f(1.0, 1.0, 0.0);
197 glRasterPos2f(x, y);
198 len = int(strlen(text));
199 for (i = 0; i < len; i++) {
200 if(text[i] == '\n')
202 y-=20;
203 glRasterPos2f(x, y);
205 else
206 glutBitmapCharacter(font, text[i]);
208 glPopMatrix();
209 glMatrixMode(GL_MODELVIEW);
210 glPopMatrix();
211 glPopAttrib();
214 void prepareSceneGraph(OSG::Node * const node)
216 OSG::TriangleIterator f;
218 if(!prepared)
220 polygonChunk = OSG::PolygonChunk::create();
221 prepared = true;
224 OSG::NodeCore *core =node->getCore();
225 if(core != NULL)
227 OSG::Geometry *geo = dynamic_cast<OSG::Geometry *>(core);
228 if(geo != NULL)
230 OSG::Material *mat = geo->getMaterial();
231 if(mat != NULL)
233 OSG::ChunkMaterial *cmat =
234 dynamic_cast<OSG::ChunkMaterial *>(mat);
236 if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
238 cmat->addChunk(polygonChunk);
241 // get num positions
242 OSG::GeoVectorProperty *positionsPtr=geo->getPositions();
243 if(positionsPtr != NULL)
244 sum_positions += positionsPtr->size();
245 // get num triangles
246 for(f=geo->beginTriangles() ; f!=geo->endTriangles() ; ++f)
247 ++sum_triangles;
248 // sum of geometry nodes
249 ++sum_geometries;
251 else
253 OSG::MaterialGroup *matGrp =
254 dynamic_cast<OSG::MaterialGroup *>(core);
255 if(matGrp != NULL)
257 OSG::Material *mat = matGrp->getMaterial();
258 if(mat != NULL)
260 OSG::ChunkMaterial *cmat =
261 dynamic_cast<OSG::ChunkMaterial *>(mat);
263 if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
265 cmat->addChunk(polygonChunk);
269 else
271 OSG::ProxyGroup *proxy = dynamic_cast<OSG::ProxyGroup *>(core);
272 if(proxy != NULL)
274 sum_triangles += proxy->getTriangles();
275 sum_positions += proxy->getPositions();
276 sum_geometries += proxy->getGeometries();
281 for(OSG::MFUnrecChildNodePtr::const_iterator nI=node->getMFChildren()->begin();
282 nI != node->getMFChildren()->end();
283 ++nI)
285 prepareSceneGraph(*nI);
289 void loadAnim()
291 OSG::Real32 ax,ay,az,r,x,y,z;
292 FILE *file=fopen(animName.c_str(),"r");
294 animOri.clear();
295 animPos.clear();
296 if(!file)
297 return;
298 while(fscanf(file,"%f %f %f %f,%f %f %f",&ax,&ay,&az,&r,&x,&y,&z)==7)
300 animOri.push_back(OSG::Quaternion(OSG::Vec3f(ax,ay,az),r));
301 animPos.push_back(OSG::Vec3f(x,y,z));
303 fclose(file);
306 void display(void)
308 OSG::Time t;
310 t=-OSG::getSystemTime();
312 if(animate && animPos.size()>1)
314 OSG::UInt32 i= OSG::UInt32(animTime);
315 OSG::Real32 a=animTime-i;
317 printf("%d %" PRISize "\n",i,animPos.size());
318 OSG::Vec3f v=animPos[i] + (animPos[i+1] - animPos[i]) * a;
320 cam_trans->editMatrix().setTranslate(v[0],v[1],v[2]);
321 cam_trans->editMatrix().setRotate(
322 OSG::Quaternion::slerp(animOri[i],animOri[i+1],a));
324 else
326 cam_trans->editSFMatrix()->setValue( tball.getFullTrackballMatrix() );
331 OSG::Thread::getCurrentChangeList()->commitChanges();
332 #if 0
333 clusterWindow->activate();
334 clusterWindow->frameInit();
335 clusterWindow->renderAllViewports(ract);
336 #endif
337 clusterWindow->renderNoFinish(ract);
338 #if 0
339 if(showInfo)
341 displayInfo(10,90);
343 char text[1024];
344 sprintf(text,"FPS: %12.1f",1.0/frame_time);
345 showText(10,70,text);
346 sprintf(text,"Positions: %12d",sum_positions);
347 showText(10,50,text);
348 sprintf(text,"Triangles: %12d",sum_triangles);
349 showText(10,30,text);
350 sprintf(text,"Geometries: %12d",sum_geometries);
351 showText(10,10,text);
354 #endif
355 #if 0
356 clusterWindow->swap();
357 clusterWindow->frameExit();
358 #endif
359 clusterWindow->frameFinish();
361 // clear changelist from prototypes
362 OSG::Thread::getCurrentChangeList()->clear();
364 catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
366 std::cout << e.what() << std::endl;
367 cleanup();
368 exit(0);
371 t+=OSG::getSystemTime();
372 frame_time = t;
374 if(animate)
376 // OSG::Real32 a;
377 OSG::Vec3f v;
379 printf("Frame %8.3f %8.5f %8.3f\n",
380 animTime,
381 t,1/t);
383 animTime += (animPos.size()/float(animLength));
384 if(OSG::SizeT(animTime)+1 >= animPos.size())
386 animTime = 0;
388 if(animLoops > 0)
390 animLoops--;
391 if(!animLoops)
393 cleanup();
394 exit(0);
401 void reshape( int width, int height )
403 printf("reshape %d %d\n",width,height);
404 glViewport(0, 0, width, height);
405 clientWindow->resize( width, height );
406 glutPostRedisplay();
409 void motion(int x, int y)
411 OSG::Real32 w = clientWindow->getWidth(), h = clientWindow->getHeight();
414 OSG::Real32 a = -2. * ( lastx / w - .5 ),
415 b = -2. * ( .5 - lasty / h ),
416 c = -2. * ( x / w - .5 ),
417 d = -2. * ( .5 - y / h );
419 if ( mouseb & ( 1 << GLUT_LEFT_BUTTON ) )
421 tball.updateRotation( a, b, c, d );
423 else if ( mouseb & ( 1 << GLUT_MIDDLE_BUTTON ) )
425 tball.updatePosition( a, b, c, d );
427 else if ( mouseb & ( 1 << GLUT_RIGHT_BUTTON ) )
429 tball.updatePositionNeg( a, b, c, d );
431 lastx = x;
432 lasty = y;
433 glutPostRedisplay();
436 void mouse(int button, int state, int x, int y)
438 if ( state == 0 )
440 switch ( button )
442 case GLUT_LEFT_BUTTON: break;
443 case GLUT_MIDDLE_BUTTON:tball.setAutoPosition(true);
444 break;
445 case GLUT_RIGHT_BUTTON: tball.setAutoPositionNeg(true);
446 break;
448 mouseb |= 1 << button;
450 else if ( state == 1 )
452 switch ( button )
454 case GLUT_LEFT_BUTTON: break;
455 case GLUT_MIDDLE_BUTTON:tball.setAutoPosition(false);
456 break;
457 case GLUT_RIGHT_BUTTON: tball.setAutoPositionNeg(false);
458 break;
460 mouseb &= ~(1 << button);
462 lastx = x;
463 lasty = y;
464 glutPostRedisplay();
467 void setHEyeWallParameter(OSG::Real32 dsFactor, bool enablecc)
469 static char str[1024];
471 OSG::NameUnrecPtr parameters = dynamic_cast<OSG::Name *>(clusterWindow->findAttachment(OSG::Name::getClassType()));
473 if(parameters == NULL)
475 parameters = OSG::Name::create();
476 clusterWindow->addAttachment(parameters);
479 sprintf(str, "downScale=%f colorCorrection=%d", dsFactor, enablecc);
480 parameters->editFieldPtr()->getValue().assign(str);
483 void key(unsigned char key, int /*x*/, int /*y*/)
485 switch ( key )
487 case 'l':
489 loadAnim();
490 break;
492 case 'c':
494 FILE *file=fopen(animName.c_str(),"w");
495 fclose(file);
496 animOri.clear();
497 animPos.clear();
498 break;
500 case 's':
502 FILE *file=fopen(animName.c_str(),"a");
503 OSG::Matrix m=cam_trans->getMatrix();
504 OSG::Quaternion q(m);
505 OSG::Real32 ax,ay,az,r;
506 animPos.push_back(OSG::Vec3f(m[3][0],
507 m[3][1],
508 m[3][2]));
509 animOri.push_back(q);
510 q.getValueAsAxisRad(ax,ay,az,r);
511 fprintf(file,"%f %f %f %f,%f %f %f\n",ax,ay,az,r,
512 m[3][0],
513 m[3][1],
514 m[3][2]);
515 fclose(file);
516 break;
518 case 'S':
520 FILE *file=fopen((animName+".wrl").c_str(),"w");
521 std::vector<OSG::Quaternion>::iterator qit;
523 fprintf(file,"DEF OriInter OrientationInterpolator {\n\tkey [");
524 for(OSG::SizeT i = 0; i < animOri.size(); ++i)
526 fprintf(file, "%f", i / OSG::Real32(animOri.size() - 1) );
527 if(i < animOri.size() - 1)
528 fprintf(file,", ");
530 fprintf(file,"]\n\tkeyValue [");
531 for(qit = animOri.begin(); qit != animOri.end(); ++qit)
533 OSG::Real32 ax,ay,az,r;
534 (*qit).getValueAsAxisRad(ax,ay,az,r);
536 fprintf(file, "%f %f %f %f", ax, ay, az, r );
537 if(qit < animOri.end() - 1)
538 fprintf(file,", ");
540 fprintf(file,"]\n}\n\n");
542 std::vector<OSG::Vec3f>::iterator vit;
544 fprintf(file,"DEF PosInter PositionInterpolator {\n\tkey [");
545 for(OSG::SizeT i = 0; i < animPos.size(); ++i)
547 fprintf(file, "%f", i / OSG::Real32(animPos.size() - 1) );
548 if(i < animPos.size() - 1)
549 fprintf(file,", ");
551 fprintf(file,"]\n\tkeyValue [");
552 for(vit = animPos.begin(); vit != animPos.end(); ++vit)
554 OSG::Vec3f v = *vit;
556 fprintf(file, "%f %f %f, ", v[0], v[1], v[2] );
558 fprintf(file,"]\n}\n\n");
560 fclose(file);
561 break;
563 #ifdef HAVE_SORT
564 case 'j':
565 if(sortfirst!=NULL)
567 sortfirst->setCompression("JPEG");
569 break;
570 case 'r':
571 if(sortfirst!=NULL)
573 sortfirst->setCompression("RLE");
575 break;
576 case 'n':
577 if(sortfirst!=NULL)
579 sortfirst->getCompression().erase();
581 break;
582 #endif
583 case 'i':
584 showInfo = !showInfo;
585 break;
586 case 'w':
587 if(polygonChunk->getFrontMode() == GL_FILL)
588 polygonChunk->setFrontMode(GL_LINE);
589 else
590 polygonChunk->setFrontMode(GL_FILL);
592 if(polygonChunk->getBackMode() == GL_FILL)
593 polygonChunk->setBackMode(GL_LINE);
594 else
595 polygonChunk->setBackMode(GL_FILL);
597 break;
598 case 'a':
599 if(animate)
601 glutIdleFunc(NULL);
602 animate=false;
604 else
606 glutIdleFunc(display);
607 animate=true;
609 break;
610 case 'd':
611 // remove tree
612 while(root->getNChildren())
614 root->subChild(0u);
616 break;
617 case '+':
618 _dsFactor += 0.01f;
619 if(_dsFactor > 1.0f)
620 _dsFactor = 1.0f;
621 setHEyeWallParameter(_dsFactor, _enablecc);
622 break;
623 case '-':
624 _dsFactor -= 0.01f;
625 if(_dsFactor <= 0.0f)
626 _dsFactor = 0.01f;
627 setHEyeWallParameter(_dsFactor, _enablecc);
628 break;
629 case 'f':
630 if(_enablecc)
631 _enablecc = false;
632 else
633 _enablecc = true;
634 setHEyeWallParameter(_dsFactor, _enablecc);
635 break;
636 case 'B':
637 if(bkgnd->getColor()[0] == 0.0)
638 bkgnd->setColor( OSG::Color3f(1,1,1) );
639 else
640 bkgnd->setColor( OSG::Color3f(0,0,0) );
641 break;
642 case 27: // should kill the clients here
643 // exit
644 cleanup();
645 exit(0);
648 glutPostRedisplay();
651 void addActor(OSG::Node *pRoot,
652 vtkActor *pActor)
654 OSG::NodeUnrecPtr pTmpNode = OSG::Node ::create();
655 OSG::VTKPolyDataMapperUnrecPtr pTmpMapper =
656 OSG::VTKPolyDataMapper::create();
658 pTmpMapper->setActor(pActor );
659 pTmpNode ->setCore (pTmpMapper);
660 pRoot ->addChild(pTmpNode );
662 // pTmpMapper->execute();
665 OSG::NodeTransitPtr initVTK(void)
667 OSG::NodeUnrecPtr returnValue = NULL;
669 OSG::Char8 *szDataRoot = getenv("VTK_DATA_ROOT");
671 if(szDataRoot == NULL)
673 fprintf(stderr, "VTK_DATA_ROOT not set\n");
674 cleanup();
675 exit(0);
678 std::string szFilename;
680 szFilename.assign(szDataRoot);
681 szFilename += "/Data/office.binary.vtk";
683 vtkStructuredGridReader *reader = vtkStructuredGridReader::New();
685 reader->SetFileName(szFilename.c_str());
686 reader->Update();
688 #if 0
689 OSG::Real64 length = reader->GetOutput()->GetLength();
691 OSG::Real64 maxVelocity =
692 reader->GetOutput()->GetPointData()->GetVectors()->GetMaxNorm();
694 OSG::Real64 maxTime = 35.0 * length / maxVelocity;
695 #endif
698 returnValue = OSG::Node::create();
700 returnValue->setCore(OSG::Group::create());
702 // Create source for streamtubes
703 vtkPointSource *seeds = vtkPointSource::New();
704 seeds->SetRadius(0.15);
705 seeds->SetCenter(0.1, 2.1, 0.5);
706 seeds->SetNumberOfPoints(6);
708 vtkRungeKutta4 *integ = vtkRungeKutta4::New();
709 vtkStreamLine *streamer = vtkStreamLine::New();
710 streamer->SetInputConnection(reader->GetOutputPort());
711 #if VTK_MAJOR_VERSION >= 6
712 streamer->SetSourceData(seeds->GetOutput());
713 #else
714 streamer->SetSource(seeds->GetOutput());
715 #endif
716 streamer->SetMaximumPropagationTime(500);
717 streamer->SetStepLength(0.5);
718 streamer->SetIntegrationStepLength(0.05);
719 streamer->SetIntegrationDirectionToIntegrateBothDirections();
720 streamer->SetIntegrator(integ);
722 // The tube is wrapped around the generated streamline. By varying the
723 // radius by the inverse of vector magnitude, we are creating a tube
724 // whose radius is proportional to mass flux (in incompressible flow).
725 vtkTubeFilter *streamTube = vtkTubeFilter::New();
726 streamTube->SetInputConnection(streamer->GetOutputPort());
727 streamTube->SetRadius(0.02);
728 streamTube->SetNumberOfSides(12);
729 streamTube->SetVaryRadiusToVaryRadiusByVector();
730 vtkPolyDataMapper *mapStreamTube = vtkPolyDataMapper::New();
731 mapStreamTube->SetInputConnection(streamTube->GetOutputPort());
732 mapStreamTube->SetScalarRange(
733 reader->GetOutput()->GetPointData()->GetScalars()->GetRange());
734 vtkActor *streamTubeActor = vtkActor::New();
735 streamTubeActor->SetMapper(mapStreamTube);
736 streamTubeActor->GetProperty()->BackfaceCullingOn();
738 addActor(returnValue, streamTubeActor);
741 vtkStructuredGridGeometryFilter *table1 =
742 vtkStructuredGridGeometryFilter::New();
744 table1->SetInputConnection(reader->GetOutputPort());
745 table1->SetExtent(11, 15, 7, 9, 8, 8);
747 vtkPolyDataNormals *normTable1 = vtkPolyDataNormals::New();
748 normTable1->SetInputConnection(table1->GetOutputPort());
750 vtkPolyDataMapper *mapTable1 = vtkPolyDataMapper::New();
751 mapTable1->SetInputConnection(normTable1->GetOutputPort());
752 mapTable1->ScalarVisibilityOff();
754 vtkActor *table1Actor = vtkActor::New();
755 table1Actor->SetMapper(mapTable1);
756 table1Actor->GetProperty()->SetColor(.59, .427, .392);
758 addActor(returnValue, table1Actor);
762 vtkStructuredGridGeometryFilter *table2 =
763 vtkStructuredGridGeometryFilter::New();
764 table2->SetInputConnection(reader->GetOutputPort());
765 table2->SetExtent(11, 15, 10, 12, 8, 8);
767 vtkPolyDataNormals *normTable2 = vtkPolyDataNormals::New();
768 normTable2->SetInputConnection(table2->GetOutputPort());
770 vtkPolyDataMapper *mapTable2 = vtkPolyDataMapper::New();
771 mapTable2->SetInputConnection(normTable2->GetOutputPort());
772 mapTable2->ScalarVisibilityOff();
774 vtkActor *table2Actor = vtkActor::New();
775 table2Actor->SetMapper(mapTable2);
776 table2Actor->GetProperty()->SetColor(.59, .427, .392);
778 addActor(returnValue, table2Actor);
782 vtkStructuredGridGeometryFilter *FilingCabinet1 =
783 vtkStructuredGridGeometryFilter::New();
785 FilingCabinet1->SetInputConnection(reader->GetOutputPort());
786 FilingCabinet1->SetExtent(15, 15, 7, 9, 0, 8);
788 vtkPolyDataNormals *normFilingCabinet1 = vtkPolyDataNormals::New();
789 normFilingCabinet1->SetInputConnection(FilingCabinet1->GetOutputPort());
791 vtkPolyDataMapper *mapFilingCabinet1 = vtkPolyDataMapper::New();
792 mapFilingCabinet1->SetInputConnection(normFilingCabinet1->GetOutputPort());
793 mapFilingCabinet1->ScalarVisibilityOff();
795 vtkActor *FilingCabinet1Actor = vtkActor::New();
796 FilingCabinet1Actor->SetMapper(mapFilingCabinet1);
797 FilingCabinet1Actor->GetProperty()->SetColor(.8, .8, .6);
799 addActor(returnValue, FilingCabinet1Actor);
803 vtkStructuredGridGeometryFilter *FilingCabinet2 =
804 vtkStructuredGridGeometryFilter::New();
805 FilingCabinet2->SetInputConnection(reader->GetOutputPort());
806 FilingCabinet2->SetExtent(15, 15, 10, 12, 0, 8);
808 vtkPolyDataNormals *normFilingCabinet2 = vtkPolyDataNormals::New();
809 normFilingCabinet2->SetInputConnection(FilingCabinet2->GetOutputPort());
811 vtkPolyDataMapper *mapFilingCabinet2 = vtkPolyDataMapper::New();
812 mapFilingCabinet2->SetInputConnection(normFilingCabinet2->GetOutputPort());
813 mapFilingCabinet2->ScalarVisibilityOff();
815 vtkActor *FilingCabinet2Actor = vtkActor::New();
816 FilingCabinet2Actor->SetMapper(mapFilingCabinet2);
817 FilingCabinet2Actor->GetProperty()->SetColor(.8, .8, .6);
819 addActor(returnValue, FilingCabinet2Actor);
823 vtkStructuredGridGeometryFilter *bookshelf1Top =
824 vtkStructuredGridGeometryFilter::New();
825 bookshelf1Top->SetInputConnection(reader->GetOutputPort());
826 bookshelf1Top->SetExtent(13, 13, 0, 4, 0, 11);
828 vtkPolyDataNormals *normbookshelf1Top = vtkPolyDataNormals::New();
829 normbookshelf1Top->SetInputConnection(bookshelf1Top->GetOutputPort());
831 vtkPolyDataMapper *mapBookshelf1Top = vtkPolyDataMapper::New();
832 mapBookshelf1Top->SetInputConnection(normbookshelf1Top->GetOutputPort());
833 mapBookshelf1Top->ScalarVisibilityOff();
835 vtkActor *bookshelf1TopActor = vtkActor::New();
836 bookshelf1TopActor->SetMapper(mapBookshelf1Top);
837 bookshelf1TopActor->GetProperty()->SetColor(.8, .8, .6);
839 addActor(returnValue, bookshelf1TopActor);
843 vtkStructuredGridGeometryFilter *bookshelf1Bottom =
844 vtkStructuredGridGeometryFilter::New();
845 bookshelf1Bottom->SetInputConnection(reader->GetOutputPort());
846 bookshelf1Bottom->SetExtent(20, 20, 0, 4, 0, 11);
848 vtkPolyDataNormals *normbookshelf1Bottom = vtkPolyDataNormals::New();
849 normbookshelf1Bottom->SetInputConnection(
850 bookshelf1Bottom->GetOutputPort());
852 vtkPolyDataMapper *mapBookshelf1Bottom = vtkPolyDataMapper::New();
853 mapBookshelf1Bottom->SetInputConnection(
854 normbookshelf1Bottom->GetOutputPort());
855 mapBookshelf1Bottom->ScalarVisibilityOff();
857 vtkActor *bookshelf1BottomActor = vtkActor::New();
858 bookshelf1BottomActor->SetMapper(mapBookshelf1Bottom);
859 bookshelf1BottomActor->GetProperty()->SetColor(.8, .8, .6);
861 addActor(returnValue, bookshelf1BottomActor);
865 vtkStructuredGridGeometryFilter *bookshelf1Front =
866 vtkStructuredGridGeometryFilter::New();
867 bookshelf1Front->SetInputConnection(reader->GetOutputPort());
868 bookshelf1Front->SetExtent(13, 20, 0, 0, 0, 11);
870 vtkPolyDataNormals *normbookshelf1Front = vtkPolyDataNormals::New();
871 normbookshelf1Front->SetInputConnection(bookshelf1Front->GetOutputPort());
873 vtkPolyDataMapper *mapBookshelf1Front = vtkPolyDataMapper::New();
874 mapBookshelf1Front->SetInputConnection(
875 normbookshelf1Front->GetOutputPort());
876 mapBookshelf1Front->ScalarVisibilityOff();
878 vtkActor *bookshelf1FrontActor = vtkActor::New();
879 bookshelf1FrontActor->SetMapper(mapBookshelf1Front);
880 bookshelf1FrontActor->GetProperty()->SetColor(.8, .8, .6);
882 addActor(returnValue, bookshelf1FrontActor);
886 vtkStructuredGridGeometryFilter *bookshelf1Back =
887 vtkStructuredGridGeometryFilter::New();
888 bookshelf1Back->SetInputConnection(reader->GetOutputPort());
889 bookshelf1Back->SetExtent(13, 20, 4, 4, 0, 11);
891 vtkPolyDataNormals *normbookshelf1Back = vtkPolyDataNormals::New();
892 normbookshelf1Back->SetInputConnection(bookshelf1Back->GetOutputPort());
894 vtkPolyDataMapper *mapBookshelf1Back = vtkPolyDataMapper::New();
895 mapBookshelf1Back->SetInputConnection(normbookshelf1Back->GetOutputPort());
896 mapBookshelf1Back->ScalarVisibilityOff();
898 vtkActor *bookshelf1BackActor = vtkActor::New();
899 bookshelf1BackActor->SetMapper(mapBookshelf1Back);
900 bookshelf1BackActor->GetProperty()->SetColor(.8, .8, .6);
902 addActor(returnValue, bookshelf1BackActor);
906 vtkStructuredGridGeometryFilter *bookshelf1LHS =
907 vtkStructuredGridGeometryFilter::New();
908 bookshelf1LHS->SetInputConnection(reader->GetOutputPort());
909 bookshelf1LHS->SetExtent(13, 20, 0, 4, 0, 0);
911 vtkPolyDataNormals *normbookshelf1LHS = vtkPolyDataNormals::New();
912 normbookshelf1LHS->SetInputConnection(bookshelf1LHS->GetOutputPort());
914 vtkPolyDataMapper *mapBookshelf1LHS = vtkPolyDataMapper::New();
915 mapBookshelf1LHS->SetInputConnection(normbookshelf1LHS->GetOutputPort());
916 mapBookshelf1LHS->ScalarVisibilityOff();
918 vtkActor *bookshelf1LHSActor = vtkActor::New();
919 bookshelf1LHSActor->SetMapper(mapBookshelf1LHS);
920 bookshelf1LHSActor->GetProperty()->SetColor(.8, .8, .6);
922 addActor(returnValue, bookshelf1LHSActor);
926 vtkStructuredGridGeometryFilter *bookshelf1RHS =
927 vtkStructuredGridGeometryFilter::New();
928 bookshelf1RHS->SetInputConnection(reader->GetOutputPort());
929 bookshelf1RHS->SetExtent(13, 20, 0, 4, 11, 11);
931 vtkPolyDataNormals *normbookshelf1RHS = vtkPolyDataNormals::New();
932 normbookshelf1RHS->SetInputConnection(bookshelf1RHS->GetOutputPort());
934 vtkPolyDataMapper *mapBookshelf1RHS = vtkPolyDataMapper::New();
935 mapBookshelf1RHS->SetInputConnection(normbookshelf1RHS->GetOutputPort());
936 mapBookshelf1RHS->ScalarVisibilityOff();
938 vtkActor *bookshelf1RHSActor = vtkActor::New();
939 bookshelf1RHSActor->SetMapper(mapBookshelf1RHS);
940 bookshelf1RHSActor->GetProperty()->SetColor(.8, .8, .6);
942 addActor(returnValue, bookshelf1RHSActor);
946 vtkStructuredGridGeometryFilter *bookshelf2Top =
947 vtkStructuredGridGeometryFilter::New();
948 bookshelf2Top->SetInputConnection(reader->GetOutputPort());
949 bookshelf2Top->SetExtent(13, 13, 15, 19, 0, 11);
951 vtkPolyDataNormals *normbookshelf2Top = vtkPolyDataNormals::New();
952 normbookshelf2Top->SetInputConnection(bookshelf2Top->GetOutputPort());
954 vtkPolyDataMapper *mapBookshelf2Top = vtkPolyDataMapper::New();
955 mapBookshelf2Top->SetInputConnection(normbookshelf2Top->GetOutputPort());
956 mapBookshelf2Top->ScalarVisibilityOff();
958 vtkActor *bookshelf2TopActor = vtkActor::New();
959 bookshelf2TopActor->SetMapper(mapBookshelf2Top);
960 bookshelf2TopActor->GetProperty()->SetColor(.8, .8, .6);
962 addActor(returnValue, bookshelf2TopActor);
965 vtkStructuredGridGeometryFilter *bookshelf2Bottom =
966 vtkStructuredGridGeometryFilter::New();
967 bookshelf2Bottom->SetInputConnection(reader->GetOutputPort());
968 bookshelf2Bottom->SetExtent(20, 20, 15, 19, 0, 11);
970 vtkPolyDataNormals *normbookshelf2Bottom = vtkPolyDataNormals::New();
971 normbookshelf2Bottom->SetInputConnection(
972 bookshelf2Bottom->GetOutputPort());
974 vtkPolyDataMapper *mapBookshelf2Bottom = vtkPolyDataMapper::New();
975 mapBookshelf2Bottom->SetInputConnection(
976 normbookshelf2Bottom->GetOutputPort());
977 mapBookshelf2Bottom->ScalarVisibilityOff();
979 vtkActor *bookshelf2BottomActor = vtkActor::New();
980 bookshelf2BottomActor->SetMapper(mapBookshelf2Bottom);
981 bookshelf2BottomActor->GetProperty()->SetColor(.8, .8, .6);
983 addActor(returnValue, bookshelf2BottomActor);
987 vtkStructuredGridGeometryFilter *bookshelf2Front =
988 vtkStructuredGridGeometryFilter::New();
989 bookshelf2Front->SetInputConnection(reader->GetOutputPort());
990 bookshelf2Front->SetExtent(13, 20, 15, 15, 0, 11);
992 vtkPolyDataNormals *normbookshelf2Front = vtkPolyDataNormals::New();
993 normbookshelf2Front->SetInputConnection(bookshelf2Front->GetOutputPort());
995 vtkPolyDataMapper *mapBookshelf2Front = vtkPolyDataMapper::New();
996 mapBookshelf2Front->SetInputConnection(
997 normbookshelf2Front->GetOutputPort());
998 mapBookshelf2Front->ScalarVisibilityOff();
1000 vtkActor *bookshelf2FrontActor = vtkActor::New();
1001 bookshelf2FrontActor->SetMapper(mapBookshelf2Front);
1002 bookshelf2FrontActor->GetProperty()->SetColor(.8, .8, .6);
1004 addActor(returnValue, bookshelf2FrontActor);
1008 vtkStructuredGridGeometryFilter *bookshelf2Back =
1009 vtkStructuredGridGeometryFilter::New();
1010 bookshelf2Back->SetInputConnection(reader->GetOutputPort());
1011 bookshelf2Back->SetExtent(13, 20, 19, 19, 0, 11);
1013 vtkPolyDataNormals *normbookshelf2Back = vtkPolyDataNormals::New();
1014 normbookshelf2Back->SetInputConnection(bookshelf2Back->GetOutputPort());
1016 vtkPolyDataMapper *mapBookshelf2Back = vtkPolyDataMapper::New();
1017 mapBookshelf2Back->SetInputConnection(normbookshelf2Back->GetOutputPort());
1018 mapBookshelf2Back->ScalarVisibilityOff();
1020 vtkActor *bookshelf2BackActor = vtkActor::New();
1021 bookshelf2BackActor->SetMapper(mapBookshelf2Back);
1022 bookshelf2BackActor->GetProperty()->SetColor(.8, .8, .6);
1024 addActor(returnValue, bookshelf2BackActor);
1028 vtkStructuredGridGeometryFilter *bookshelf2LHS =
1029 vtkStructuredGridGeometryFilter::New();
1030 bookshelf2LHS->SetInputConnection(reader->GetOutputPort());
1031 bookshelf2LHS->SetExtent(13, 20, 15, 19, 0, 0);
1033 vtkPolyDataNormals *normbookshelf2LHS = vtkPolyDataNormals::New();
1034 normbookshelf2LHS->SetInputConnection(bookshelf2LHS->GetOutputPort());
1036 vtkPolyDataMapper *mapBookshelf2LHS = vtkPolyDataMapper::New();
1037 mapBookshelf2LHS->SetInputConnection(normbookshelf2LHS->GetOutputPort());
1038 mapBookshelf2LHS->ScalarVisibilityOff();
1039 vtkActor *bookshelf2LHSActor = vtkActor::New();
1040 bookshelf2LHSActor->SetMapper(mapBookshelf2LHS);
1041 bookshelf2LHSActor->GetProperty()->SetColor(.8, .8, .6);
1043 addActor(returnValue, bookshelf2LHSActor);
1047 vtkStructuredGridGeometryFilter *bookshelf2RHS =
1048 vtkStructuredGridGeometryFilter::New();
1049 bookshelf2RHS->SetInputConnection(reader->GetOutputPort());
1050 bookshelf2RHS->SetExtent(13, 20, 15, 19, 11, 11);
1052 vtkPolyDataNormals *normbookshelf2RHS = vtkPolyDataNormals::New();
1053 normbookshelf2RHS->SetInputConnection(bookshelf2RHS->GetOutputPort());
1055 vtkPolyDataMapper *mapBookshelf2RHS = vtkPolyDataMapper::New();
1056 mapBookshelf2RHS->SetInputConnection(normbookshelf2RHS->GetOutputPort());
1057 mapBookshelf2RHS->ScalarVisibilityOff();
1059 vtkActor *bookshelf2RHSActor = vtkActor::New();
1060 bookshelf2RHSActor->SetMapper(mapBookshelf2RHS);
1061 bookshelf2RHSActor->GetProperty()->SetColor(.8, .8, .6);
1063 addActor(returnValue, bookshelf2RHSActor);
1067 vtkStructuredGridGeometryFilter *window =
1068 vtkStructuredGridGeometryFilter::New();
1069 window->SetInputConnection(reader->GetOutputPort());
1070 window->SetExtent(20, 20, 6, 13, 10, 13);
1072 vtkPolyDataNormals *normWindow = vtkPolyDataNormals::New();
1073 normWindow->SetInputConnection(window->GetOutputPort());
1075 vtkPolyDataMapper *mapWindow = vtkPolyDataMapper::New();
1076 mapWindow->SetInputConnection(normWindow->GetOutputPort());
1077 mapWindow->ScalarVisibilityOff();
1079 vtkActor *windowActor = vtkActor::New();
1080 windowActor->SetMapper(mapWindow);
1081 windowActor->GetProperty()->SetColor(.3, .3, .5);
1083 addActor(returnValue, windowActor);
1087 vtkStructuredGridGeometryFilter *outlet =
1088 vtkStructuredGridGeometryFilter::New();
1089 outlet->SetInputConnection(reader->GetOutputPort());
1090 outlet->SetExtent(0, 0, 9, 10, 14, 16);
1092 vtkPolyDataNormals *normoutlet = vtkPolyDataNormals::New();
1093 normoutlet->SetInputConnection(outlet->GetOutputPort());
1095 vtkPolyDataMapper *mapOutlet = vtkPolyDataMapper::New();
1096 mapOutlet->SetInputConnection(normoutlet->GetOutputPort());
1097 mapOutlet->ScalarVisibilityOff();
1098 vtkActor *outletActor = vtkActor::New();
1099 outletActor->SetMapper(mapOutlet);
1100 outletActor->GetProperty()->SetColor(0, 0, 0);
1102 addActor(returnValue, outletActor);
1106 vtkStructuredGridGeometryFilter *inlet =
1107 vtkStructuredGridGeometryFilter::New();
1108 inlet->SetInputConnection(reader->GetOutputPort());
1109 inlet->SetExtent(0, 0, 9, 10, 0, 6);
1111 vtkPolyDataNormals *norminlet = vtkPolyDataNormals::New();
1112 norminlet->SetInputConnection(inlet->GetOutputPort());
1114 vtkPolyDataMapper *mapInlet = vtkPolyDataMapper::New();
1115 mapInlet->SetInputConnection(norminlet->GetOutputPort());
1117 mapInlet->ScalarVisibilityOff();
1118 vtkActor *inletActor = vtkActor::New();
1119 inletActor->SetMapper(mapInlet);
1120 inletActor->GetProperty()->SetColor(0, 0, 0);
1124 vtkStructuredGridOutlineFilter *outline =
1125 vtkStructuredGridOutlineFilter::New();
1127 outline->SetInputConnection(reader->GetOutputPort());
1129 vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
1130 mapOutline->SetInputConnection(outline->GetOutputPort());
1132 vtkActor *outlineActor = vtkActor::New();
1134 outlineActor->SetMapper(mapOutline);
1135 outlineActor->GetProperty()->SetColor(0, 0, 0);
1137 addActor(returnValue, outlineActor);
1139 return OSG::NodeTransitPtr(returnValue);
1142 void init(std::vector<std::string> &filenames)
1144 OSG::SizeT i;
1145 OSG::DirectionalLightUnrecPtr dl;
1146 OSG::Real32 x,y,z;
1147 OSG::BoxVolume volume;
1148 OSG::Vec3f min,max;
1149 OSG::Vec3f size;
1151 glEnable( GL_DEPTH_TEST );
1152 glEnable( GL_LIGHTING );
1153 glEnable( GL_LIGHT0 );
1154 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1156 // create the graph
1158 // beacon for camera and light
1159 OSG::NodeUnrecPtr b1n = OSG::Node::create();
1160 OSG::GroupUnrecPtr b1 = OSG::Group::create();
1162 b1n->setCore( b1 );
1164 // transformation
1165 OSG::NodeUnrecPtr t1n = OSG::Node::create();
1166 OSG::TransformUnrecPtr t1 = OSG::Transform::create();
1168 t1n->setCore( t1 );
1169 t1n->addChild( b1n );
1171 cam_trans = t1;
1173 // light
1175 OSG::NodeUnrecPtr dlight = OSG::Node::create();
1176 dl = OSG::DirectionalLight::create();
1179 dlight->setCore( dl );
1182 dl->setAmbient( .3, .3, .3, 1 );
1183 dl->setDiffuse( 1, 1, 1, 1 );
1184 dl->setDirection(0,0,1);
1185 dl->setBeacon( b1n);
1187 // root
1188 root = OSG::Node::create();
1189 OSG::GroupUnrecPtr gr1 = OSG::Group::create();
1191 root->setCore( gr1 );
1192 root->addChild( t1n );
1193 root->addChild( dlight );
1195 // Load the file
1196 OSG::NodeUnrecPtr scene = OSG::Node::create();
1198 scene->setCore(OSG::Group::create());
1200 OSG::NodeUnrecPtr file;
1202 for(i=0;i<filenames.size();i++)
1204 file = OSG::SceneFileHandler::the()->read(filenames[i].c_str(),0);
1205 if(file != NULL)
1206 scene->addChild(file);
1207 else
1208 std::cerr << "Couldn't load file, ignoring " << filenames[i] << std::endl;
1210 if ( filenames.size()==0 )
1212 // scene->addChild(makeTorus( .5, 2, 16, 16 ));
1213 // scene->addChild(makeBox(.6,.6,.6,5,5,5));
1214 scene->addChild(initVTK());
1217 prepareSceneGraph(scene);
1219 OSG::Thread::getCurrentChangeList()->commitChanges();
1221 scene->invalidateVolume();
1222 scene->updateVolume();
1223 volume=scene->getVolume();
1224 volume.getBounds(min,max);
1225 size = max-min;
1228 if(ca>0)
1230 if(cb==-1)
1231 cb=ca;
1232 if(cc==-1)
1233 cc=cb;
1235 OSG::NodeUnrecPtr node;
1236 OSG::NodeUnrecPtr geoNode;
1237 OSG::TransformUnrecPtr trans;
1238 for(x=-ca/2.0 ; x<ca/2.0 ; x++)
1239 for(y=-cb/2.0 ; y<cb/2.0 ; y++)
1240 for(z=-cc/2.0 ; z<cc/2.0 ; z++)
1242 trans=OSG::Transform::create();
1243 node=OSG::Node::create();
1245 node->setCore(trans);
1246 trans->editMatrix().setTranslate(
1247 x*size[0]*1.1,
1248 y*size[1]*1.1,
1249 z*size[2]*1.1);
1250 node->addChild( OSG::cloneTree(scene) );
1251 dlight->addChild(node);
1254 else
1256 dlight->addChild(scene);
1259 if(ca>0)
1261 sum_geometries*= OSG::UInt32(ca*cb*cc);
1262 sum_triangles *= OSG::UInt32(ca*cb*cc);
1263 sum_positions *= OSG::UInt32(ca*cb*cc);
1265 // dlight->invalidateVolume();
1267 dlight->updateVolume();
1269 // should check first. ok for now.
1270 const OSG::BoxVolume &vol = dlight->getVolume();
1272 OSG::Pnt3f center;
1274 vol.getBounds(min, max);
1275 vol.getCenter(center);
1277 size = max - min;
1279 std::cout << "Volume: from " << min << " to " << max << std::endl;
1282 // Camera
1284 OSG::PerspectiveCameraUnrecPtr cam = OSG::PerspectiveCamera::create();
1286 cam->setBeacon( b1n );
1287 cam->setFov( OSG::osgDegree2Rad( 60 ) );
1288 cam->setNear( 10 );
1289 cam->setFar( 50000 );
1291 // Solid Background
1292 bkgnd = OSG::SolidBackground::create();
1294 bkgnd->setColor( OSG::Color3f(0,0,0) );
1295 // bkgnd->setColor( OSG::Color3f(.1,.1,.6) );
1296 // bkgnd->setColor( OSG::Color3f(1,1,1) );
1298 // Viewport
1299 OSG::ViewportUnrecPtr vp1;
1300 OSG::ViewportUnrecPtr vp2;
1301 if(stereoMode == 0)
1303 vp1 = OSG::Viewport::create();
1305 vp1->setCamera ( cam );
1306 vp1->setBackground( bkgnd );
1307 vp1->setRoot ( root );
1308 vp1->setSize ( 0,0, 1,1 );
1310 if(multiport)
1312 vp2 = OSG::Viewport::create();
1314 vp2->setCamera ( cam );
1315 vp2->setBackground( bkgnd );
1316 vp2->setRoot ( root );
1317 vp2->setSize ( .1, .55, .7,.95 );
1320 else if(stereoMode == 1)
1322 OSG::ShearedStereoCameraDecoratorUnrecPtr deco;
1323 // left
1324 deco=OSG::ShearedStereoCameraDecorator::create();
1326 deco->setLeftEye(true);
1327 deco->setEyeSeparation(eyedistance);
1328 deco->setDecoratee(cam);
1329 deco->setZeroParallaxDistance(zeroparallax);
1330 vp1 = OSG::Viewport::create();
1332 vp1->setCamera ( deco );
1333 vp1->setBackground( bkgnd );
1334 vp1->setRoot ( root );
1335 vp1->setSize ( 0,0, .5,1 );
1337 // right
1338 deco=OSG::ShearedStereoCameraDecorator::create();
1340 deco->setLeftEye(false);
1341 deco->setEyeSeparation(eyedistance);
1342 deco->setDecoratee(cam);
1343 deco->setZeroParallaxDistance(zeroparallax);
1344 vp2 = OSG::Viewport::create();
1346 vp2->setCamera ( deco );
1347 vp2->setBackground( bkgnd );
1348 vp2->setRoot ( root );
1349 vp2->setSize ( .5,0,1,1 );
1351 else if(stereoMode == 2)
1353 OSG::ShearedStereoCameraDecoratorUnrecPtr deco;
1354 // left
1355 deco=OSG::ShearedStereoCameraDecorator::create();
1357 deco->setLeftEye(true);
1358 deco->setEyeSeparation(eyedistance);
1359 deco->setDecoratee(cam);
1360 deco->setZeroParallaxDistance(zeroparallax);
1362 OSG::ColorBufferViewportUnrecPtr cvp1 =
1363 OSG::ColorBufferViewport::create();
1365 cvp1->setCamera ( deco );
1366 cvp1->setBackground( bkgnd );
1367 cvp1->setRoot ( root );
1368 cvp1->setSize ( 0,0, 1,1 );
1369 cvp1->setRed(GL_FALSE);
1370 cvp1->setGreen(GL_TRUE);
1371 cvp1->setBlue(GL_TRUE);
1372 cvp1->setAlpha(GL_TRUE);
1374 vp1 = cvp1;
1376 // right
1377 deco=OSG::ShearedStereoCameraDecorator::create();
1379 deco->setLeftEye(false);
1380 deco->setEyeSeparation(eyedistance);
1381 deco->setDecoratee(cam);
1382 deco->setZeroParallaxDistance(zeroparallax);
1384 OSG::ColorBufferViewportUnrecPtr cvp2 =
1385 OSG::ColorBufferViewport::create();
1387 cvp2->setCamera ( deco );
1388 cvp2->setBackground( bkgnd );
1389 cvp2->setRoot ( root );
1390 cvp2->setSize ( 0,0,1,1 );
1391 cvp2->setRed(GL_TRUE);
1392 cvp2->setGreen(GL_FALSE);
1393 cvp2->setBlue(GL_FALSE);
1394 cvp2->setAlpha(GL_FALSE);
1396 vp2 = cvp2;
1399 GLint glvp[4];
1400 glGetIntegerv( GL_VIEWPORT, glvp );
1403 if(serverx>0 && servery>0)
1404 clusterWindow->setSize( serverx, servery );
1405 else
1406 clusterWindow->setSize( glvp[2], glvp[3] );
1407 clusterWindow->addPort( vp1 );
1409 if(multiport || stereoMode > 0)
1410 clusterWindow->addPort( vp2 );
1412 if(serviceAddressValid == true)
1414 clusterWindow->setServiceAddress(serviceAddress);
1416 fprintf(stderr, "tcclient use ba %s\n", serviceAddress.c_str());
1419 // tball
1421 OSG::Vec3f pos(min[0] + ((max[0] - min[0]) * 0.5),
1422 min[1] + ((max[1] - min[1]) * 0.5),
1423 max[2] + ( max[2] - min[2] ) * 1.5 );
1425 float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6;
1427 tball.setMode( OSG::Trackball::OSGObject );
1428 tball.setStartPosition( pos, true );
1429 tball.setSum( true );
1430 tball.setTranslationMode( OSG::Trackball::OSGFree );
1431 tball.setTranslationScale(scale);
1432 tball.setRotationCenter(center);
1433 tball.setTranslationGen(OSG::Trackball::OSGAbsoluteTranslation);
1435 // run...
1436 std::cout << size.length() << std::endl;
1437 cam->setFar (size.length() * 100.0);
1438 cam->setNear(size.length() * 100.0 / 10000.0);
1441 int doMain(int argc,char **argv)
1443 int i,winid;
1444 char *opt;
1445 std::vector<std::string> filenames;
1446 std::vector<std::string> servers;
1447 std::string connectionType = "Multicast";
1448 // std::string connectionType = "StreamSock";
1449 std::string connectionParameters;
1450 int rows=1;
1451 char type='M';
1452 bool clientRendering=true;
1453 #ifdef HAVE_SORT
1454 bool compose=false;
1455 #endif
1457 std::string composerType="";
1458 #ifdef HAVE_SORT
1459 OSG::ImageComposer *composer=NULL;
1460 #endif
1461 std::string autostart;
1463 for(i=1;i<argc;i++)
1465 if(strlen(argv[i])>1 && argv[i][0]=='-')
1467 switch(argv[i][1])
1469 case 'o':
1470 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1471 connectionParameters = opt;
1472 printf("connectionParameters: '%s'\n", connectionParameters.c_str());
1473 break;
1474 case 'A':
1475 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1476 autostart = opt;
1477 break;
1478 case 'D':
1479 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1480 if(sscanf(opt,"%f,%f,%f",&ca,&cb,&cc)!=3)
1482 std::cout << "Copy opton -D x,y,z" << std::endl;
1483 return 1;
1485 break;
1486 case 'b':
1487 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1488 serviceAddress.assign(opt);
1489 serviceAddressValid = true;
1490 break;
1491 case 'f':
1492 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1493 filenames.push_back(opt);
1494 printf("<%s>\n",opt);
1495 break;
1496 case 'm':
1497 connectionType="Multicast";
1498 break;
1499 case 'r':
1500 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1501 rows=atoi(opt);
1502 break;
1503 case 't':
1504 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1505 subtilesize=atoi(opt);
1506 break;
1507 #ifdef FRAMEINTERLEAVE
1508 case 'i':
1509 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1510 interleave=atoi(opt);
1511 break;
1512 #endif
1513 #ifdef HAVE_SORT
1514 case 'C':
1515 compose=true;
1516 break;
1517 #endif
1518 case 'F':
1519 type='F';
1520 break;
1521 case 'P':
1522 type='P';
1523 break;
1524 case 'L':
1526 type='L';
1527 int lpos=2;
1528 while(argv[i][lpos])
1530 if(argv[i][lpos] == 'B')
1531 composerType = "BinarySwapComposer";
1532 if(argv[i][lpos] == 'P')
1533 composerType = "PipelineComposer";
1534 if(argv[i][lpos] == 'S')
1535 composerType = "SepiaComposer";
1536 ++lpos;
1538 break;
1540 case 'M':
1541 type='M';
1542 break;
1543 case 'I':
1544 type='I';
1545 break;
1546 case 's':
1547 stereoMode=1;
1548 break;
1549 case 'c':
1550 stereoMode=2;
1551 break;
1552 case 'p':
1553 info=true;
1554 break;
1555 case 'e':
1556 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1557 sscanf(opt,"%f",&eyedistance);
1558 break;
1559 case 'z':
1560 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1561 sscanf(opt,"%f",&zeroparallax);
1562 break;
1563 case 'd':
1564 clientRendering=false;
1565 break;
1566 case 'v':
1567 multiport=true;
1568 break;
1569 case 'x':
1570 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1571 sscanf(opt,"%d",&serverx);
1572 break;
1573 case 'y':
1574 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1575 sscanf(opt,"%d",&servery);
1576 break;
1577 case 'a':
1578 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1579 animName=opt;
1580 loadAnim();
1581 glutIdleFunc(display);
1582 animate=true;
1583 break;
1584 case 'l':
1585 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1586 if(sscanf(opt,"%d,%d",&animLoops,&animLength) != 2)
1588 animLength = 30;
1589 if(sscanf(opt,"%d",&animLoops) != 1)
1591 animLoops = -1;
1594 break;
1595 case 'g':
1596 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1597 sscanf(opt,"%d,%d",&winwidth,&winheight);
1598 break;
1599 case 'G':
1600 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1601 connectionDestination = opt;
1602 break;
1603 case 'i':
1604 argv[i][2] != '\0' ? opt=argv[i]+2 : opt=argv[++i];
1605 connectionInterface = opt;
1606 break;
1607 case 'h':
1608 std::cout << argv[0]
1609 << "-ffile -m -rrows -C -M"
1610 << std::endl;
1611 std::cout << "-m use multicast" << std::endl
1612 << "-G multicast group" << std::endl
1613 << "-i interface" << std::endl
1614 << "-M multi display" << std::endl
1615 #ifdef FRAMEINTERLEAVE
1616 << "-I frame interleave" << std::endl
1617 #endif
1618 << "-r number of display rows" << std::endl
1619 << "-C compose" << std::endl
1620 << "-F sort-first" << std::endl
1621 << "-L sort-last" << std::endl
1622 << "-h this msg" << std::endl
1623 << "-s stereo" << std::endl
1624 << "-c red/cyan stereo" << std::endl
1625 << "-e eye distance" << std::endl
1626 << "-z zero parallax" << std::endl
1627 << "-d disable client rendering"<<std::endl
1628 << "-v use two viewports" << std::endl
1629 << "-x server x resolution" << std::endl
1630 << "-y server y resolution" << std::endl
1631 << "-t subtile size for img composition" << std::endl
1632 << "-D x,y,z duplicate geometry" << std::endl
1633 << "-A Autostart command" << std::endl
1634 << "-o connection parameter string e.g. \"TTL=8\"" << std::endl;
1635 return 0;
1638 else
1640 servers.push_back(argv[i]);
1644 if(servers.size() == 0)
1646 servers.push_back("foo");
1649 OSG::osgInit(argc, argv);
1650 glutInit(&argc, argv);
1651 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1652 glutInitWindowSize(winwidth,winheight);
1653 winid = glutCreateWindow("OpenSG Cluster Client");
1654 glutKeyboardFunc(key);
1655 glutReshapeFunc(reshape);
1656 glutDisplayFunc(display);
1657 glutMouseFunc(mouse);
1658 glutMotionFunc(motion);
1659 ract = OSG::RenderAction::create();
1661 // clear changelist from prototypes
1662 OSG::Thread::getCurrentChangeList()->clear();
1664 // create cluster window
1665 switch(type)
1667 case 'M':
1668 multidisplay=OSG::MultiDisplayWindow::create();
1669 clusterWindow=multidisplay;
1670 break;
1671 #ifdef HAVE_SORT
1672 case 'F':
1673 sortfirst=OSG::SortFirstWindow::create();
1675 if(compose)
1676 sortfirst->setCompose(true);
1677 else
1678 sortfirst->setCompose(false);
1680 clusterWindow=sortfirst;
1681 break;
1682 case 'L':
1683 sortlast=OSG::SortLastWindow::create();
1685 if(!composerType.empty())
1687 OSG::FieldContainerPtr fcPtr =
1688 OSG::FieldContainerFactory::the()->
1689 createFieldContainer(composerType.c_str());
1690 OSG::ImageComposerPtr icPtr = cast
1691 _dynamic<OSG::ImageComposerPtr>(fcPtr);
1693 if(icPtr != NULL)
1696 if(PipelineComposerPtr::dcast(icPtr) != NULL)
1697 PipelineComposerPtr::dcast(icPtr)->setTileSize(subtilesize);
1698 if(BinarySwapComposerPtr::dcast(icPtr) != NULL)
1699 BinarySwapComposerPtr::dcast(icPtr)->setTileSize(subtilesize);
1701 icPtr->setStatistics(info);
1702 // icPtr->setShort(false);
1703 sortlast->setComposer(icPtr);
1706 clusterWindow=sortlast;
1707 break;
1708 #endif
1709 #ifdef FRAMEINTERLEAVE
1710 case 'I':
1711 frameinterleaveOSG::=FrameInterleaveWindow::create();
1712 clusterWindow=frameinterleave;
1713 if(compose)
1714 frameinterleave->setCompose(true);
1715 else
1716 frameinterleave->setCompose(false);
1717 break;
1718 #endif
1719 #ifdef HAVE_SORT
1720 case 'P':
1721 sortfirst=OSG::SortFirstWindow::create();
1722 sortfirst->setCompose(false);
1723 clusterWindow=sortfirst;
1724 break;
1725 #endif
1728 if(!autostart.empty())
1729 clusterWindow->editMFAutostart()->push_back(autostart);
1731 for(i=0 ; OSG::SizeT(i)<servers.size() ; ++i)
1732 clusterWindow->editMFServers()->push_back(servers[i]);
1733 switch(type)
1735 case 'M':
1736 multidisplay->setHServers(
1737 clusterWindow->getMFServers()->size()/rows);
1738 multidisplay->setVServers(
1739 rows);
1740 break;
1742 #ifdef FRAMEINTERLEAVE
1743 clusterWindow->setInterleave(interleave);
1744 #endif
1746 // create client window
1747 clientWindow=OSG::GLUTWindow::create();
1748 // glutReshapeWindow(800,600);
1749 glutReshapeWindow(winwidth,winheight);
1750 clientWindow->setGlutId(winid);
1751 clientWindow->init();
1753 // init scene graph
1754 init(filenames);
1756 // init client
1757 clusterWindow->setConnectionType(connectionType);
1758 // needs to be called before init()!
1759 clusterWindow->setConnectionParams(connectionParameters);
1760 if(clientRendering)
1762 clusterWindow->setClientWindow(clientWindow);
1764 clusterWindow->init();
1765 clusterWindow->resize(winwidth,winheight);
1766 clientWindow->resize(winwidth,winheight);
1767 clusterWindow->setConnectionDestination(connectionDestination);
1768 clusterWindow->setConnectionInterface(connectionInterface);
1770 return 0;
1773 int main(int argc,char **argv)
1775 doMain(argc, argv);
1777 glutMainLoop();
1779 return 0;
1782 #else
1784 int main (int argc, char **argv)
1786 return 0;
1789 #endif