2 #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
3 #pragma GCC diagnostic warning "-Wold-style-cast"
10 // #define FRAMEINTERLEAVE
13 #include "OSGConfig.h"
16 #include "OSGTransform.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"
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"
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"
71 OSG::TransformRecPtr cam_trans
;
72 OSG::PerspectiveCameraRecPtr cam
;
73 OSG::ClusterWindowRecPtr clusterWindow
;
74 OSG::RenderActionRefPtr ract
;
75 OSG::GLUTWindowRecPtr clientWindow
;
78 OSG::SortFirstWindowRecPtr sortfirst
;
79 OSG::SortLastWindowRecPtr sortlast
;
82 #ifdef FRAMEINTERLEAVE
83 OSG::FrameInterleaveWindowRecPtr frameinterleave
;
85 OSG::MultiDisplayWindowRecPtr multidisplay
;
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
;
106 OSG::Time frame_time
=0;
107 OSG::UInt32 sum_positions
=0;
108 OSG::UInt32 sum_geometries
=0;
109 OSG::UInt32 sum_triangles
=0;
111 std::string connectionDestination
="";
112 std::string connectionInterface
="";
113 OSG::SolidBackgroundRecPtr bkgnd
;
114 OSG::UInt32 subtilesize
=32;
122 clusterWindow
= NULL
;
128 #ifdef FRAMEINTERLEAVE
129 frameinterleave
= NULL
;
138 /*! Simple show text function
140 void displayInfo(int x
, int y
)
145 void *font
= (void *) 2;
150 void *font
= GLUT_BITMAP_9_BY_15
;
164 glPushAttrib(GL_ALL_ATTRIB_BITS
);
165 glDisable(GL_LIGHTING
);
166 glEnable(GL_COLOR_MATERIAL
);
169 glMatrixMode(GL_PROJECTION
);
172 gluOrtho2D(0,clientWindow
->getWidth(),0,clientWindow
->getHeight());
173 glDisable(GL_DEPTH_TEST
);
175 glBlendFunc(GL_SRC_ALPHA
,GL_ONE_MINUS_SRC_ALPHA
);
182 glColor4f(.1, .1, .7, .5);
188 glBegin(GL_LINE_LOOP
);
189 glColor3f(1.0, 1.0, 0.0);
196 glColor3f(1.0, 1.0, 0.0);
198 len
= int(strlen(text
));
199 for (i
= 0; i
< len
; i
++) {
206 glutBitmapCharacter(font
, text
[i
]);
209 glMatrixMode(GL_MODELVIEW
);
214 void prepareSceneGraph(OSG::Node
* const node
)
216 OSG::TriangleIterator f
;
220 polygonChunk
= OSG::PolygonChunk::create();
224 OSG::NodeCore
*core
=node
->getCore();
227 OSG::Geometry
*geo
= dynamic_cast<OSG::Geometry
*>(core
);
230 OSG::Material
*mat
= geo
->getMaterial();
233 OSG::ChunkMaterial
*cmat
=
234 dynamic_cast<OSG::ChunkMaterial
*>(mat
);
236 if(cmat
->find(OSG::PolygonChunk::getClassType()) == NULL
)
238 cmat
->addChunk(polygonChunk
);
242 OSG::GeoVectorProperty
*positionsPtr
=geo
->getPositions();
243 if(positionsPtr
!= NULL
)
244 sum_positions
+= positionsPtr
->size();
246 for(f
=geo
->beginTriangles() ; f
!=geo
->endTriangles() ; ++f
)
248 // sum of geometry nodes
253 OSG::MaterialGroup
*matGrp
=
254 dynamic_cast<OSG::MaterialGroup
*>(core
);
257 OSG::Material
*mat
= matGrp
->getMaterial();
260 OSG::ChunkMaterial
*cmat
=
261 dynamic_cast<OSG::ChunkMaterial
*>(mat
);
263 if(cmat
->find(OSG::PolygonChunk::getClassType()) == NULL
)
265 cmat
->addChunk(polygonChunk
);
271 OSG::ProxyGroup
*proxy
= dynamic_cast<OSG::ProxyGroup
*>(core
);
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();
285 prepareSceneGraph(*nI
);
291 OSG::Real32 ax
,ay
,az
,r
,x
,y
,z
;
292 FILE *file
=fopen(animName
.c_str(),"r");
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
));
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
));
326 cam_trans
->editSFMatrix()->setValue( tball
.getFullTrackballMatrix() );
331 OSG::Thread::getCurrentChangeList()->commitChanges();
333 clusterWindow
->activate();
334 clusterWindow
->frameInit();
335 clusterWindow
->renderAllViewports(ract
);
337 clusterWindow
->renderNoFinish(ract
);
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);
356 clusterWindow
->swap();
357 clusterWindow
->frameExit();
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
;
371 t
+=OSG::getSystemTime();
379 printf("Frame %8.3f %8.5f %8.3f\n",
383 animTime
+= (animPos
.size()/float(animLength
));
384 if(OSG::SizeT(animTime
)+1 >= animPos
.size())
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
);
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
);
436 void mouse(int button
, int state
, int x
, int y
)
442 case GLUT_LEFT_BUTTON
: break;
443 case GLUT_MIDDLE_BUTTON
:tball
.setAutoPosition(true);
445 case GLUT_RIGHT_BUTTON
: tball
.setAutoPositionNeg(true);
448 mouseb
|= 1 << button
;
450 else if ( state
== 1 )
454 case GLUT_LEFT_BUTTON
: break;
455 case GLUT_MIDDLE_BUTTON
:tball
.setAutoPosition(false);
457 case GLUT_RIGHT_BUTTON
: tball
.setAutoPositionNeg(false);
460 mouseb
&= ~(1 << button
);
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*/)
494 FILE *file
=fopen(animName
.c_str(),"w");
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],
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
,
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)
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)
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)
551 fprintf(file
,"]\n\tkeyValue [");
552 for(vit
= animPos
.begin(); vit
!= animPos
.end(); ++vit
)
556 fprintf(file
, "%f %f %f, ", v
[0], v
[1], v
[2] );
558 fprintf(file
,"]\n}\n\n");
567 sortfirst
->setCompression("JPEG");
573 sortfirst
->setCompression("RLE");
579 sortfirst
->getCompression().erase();
584 showInfo
= !showInfo
;
587 if(polygonChunk
->getFrontMode() == GL_FILL
)
588 polygonChunk
->setFrontMode(GL_LINE
);
590 polygonChunk
->setFrontMode(GL_FILL
);
592 if(polygonChunk
->getBackMode() == GL_FILL
)
593 polygonChunk
->setBackMode(GL_LINE
);
595 polygonChunk
->setBackMode(GL_FILL
);
606 glutIdleFunc(display
);
612 while(root
->getNChildren())
621 setHEyeWallParameter(_dsFactor
, _enablecc
);
625 if(_dsFactor
<= 0.0f
)
627 setHEyeWallParameter(_dsFactor
, _enablecc
);
634 setHEyeWallParameter(_dsFactor
, _enablecc
);
637 if(bkgnd
->getColor()[0] == 0.0)
638 bkgnd
->setColor( OSG::Color3f(1,1,1) );
640 bkgnd
->setColor( OSG::Color3f(0,0,0) );
642 case 27: // should kill the clients here
651 void addActor(OSG::Node
*pRoot
,
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");
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());
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
;
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());
714 streamer
->SetSource(seeds
->GetOutput());
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
)
1145 OSG::DirectionalLightUnrecPtr dl
;
1147 OSG::BoxVolume volume
;
1151 glEnable( GL_DEPTH_TEST
);
1152 glEnable( GL_LIGHTING
);
1153 glEnable( GL_LIGHT0
);
1154 glPixelStorei( GL_UNPACK_ALIGNMENT
, 1 );
1158 // beacon for camera and light
1159 OSG::NodeUnrecPtr b1n
= OSG::Node::create();
1160 OSG::GroupUnrecPtr b1
= OSG::Group::create();
1165 OSG::NodeUnrecPtr t1n
= OSG::Node::create();
1166 OSG::TransformUnrecPtr t1
= OSG::Transform::create();
1169 t1n
->addChild( b1n
);
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
);
1188 root
= OSG::Node::create();
1189 OSG::GroupUnrecPtr gr1
= OSG::Group::create();
1191 root
->setCore( gr1
);
1192 root
->addChild( t1n
);
1193 root
->addChild( dlight
);
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);
1206 scene
->addChild(file
);
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
);
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(
1250 node
->addChild( OSG::cloneTree(scene
) );
1251 dlight
->addChild(node
);
1256 dlight
->addChild(scene
);
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();
1274 vol
.getBounds(min
, max
);
1275 vol
.getCenter(center
);
1279 std::cout
<< "Volume: from " << min
<< " to " << max
<< std::endl
;
1284 OSG::PerspectiveCameraUnrecPtr cam
= OSG::PerspectiveCamera::create();
1286 cam
->setBeacon( b1n
);
1287 cam
->setFov( OSG::osgDegree2Rad( 60 ) );
1289 cam
->setFar( 50000 );
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) );
1299 OSG::ViewportUnrecPtr vp1
;
1300 OSG::ViewportUnrecPtr vp2
;
1303 vp1
= OSG::Viewport::create();
1305 vp1
->setCamera ( cam
);
1306 vp1
->setBackground( bkgnd
);
1307 vp1
->setRoot ( root
);
1308 vp1
->setSize ( 0,0, 1,1 );
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
;
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 );
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
;
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
);
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
);
1400 glGetIntegerv( GL_VIEWPORT
, glvp
);
1403 if(serverx
>0 && servery
>0)
1404 clusterWindow
->setSize( serverx
, servery
);
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());
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
);
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
)
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
;
1452 bool clientRendering
=true;
1457 std::string composerType
="";
1459 OSG::ImageComposer
*composer
=NULL
;
1461 std::string autostart
;
1465 if(strlen(argv
[i
])>1 && argv
[i
][0]=='-')
1470 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1471 connectionParameters
= opt
;
1472 printf("connectionParameters: '%s'\n", connectionParameters
.c_str());
1475 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
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
;
1487 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1488 serviceAddress
.assign(opt
);
1489 serviceAddressValid
= true;
1492 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1493 filenames
.push_back(opt
);
1494 printf("<%s>\n",opt
);
1497 connectionType
="Multicast";
1500 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1504 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1505 subtilesize
=atoi(opt
);
1507 #ifdef FRAMEINTERLEAVE
1509 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1510 interleave
=atoi(opt
);
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";
1556 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1557 sscanf(opt
,"%f",&eyedistance
);
1560 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1561 sscanf(opt
,"%f",&zeroparallax
);
1564 clientRendering
=false;
1570 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1571 sscanf(opt
,"%d",&serverx
);
1574 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1575 sscanf(opt
,"%d",&servery
);
1578 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1581 glutIdleFunc(display
);
1585 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1586 if(sscanf(opt
,"%d,%d",&animLoops
,&animLength
) != 2)
1589 if(sscanf(opt
,"%d",&animLoops
) != 1)
1596 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1597 sscanf(opt
,"%d,%d",&winwidth
,&winheight
);
1600 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1601 connectionDestination
= opt
;
1604 argv
[i
][2] != '\0' ? opt
=argv
[i
]+2 : opt
=argv
[++i
];
1605 connectionInterface
= opt
;
1608 std::cout
<< argv
[0]
1609 << "-ffile -m -rrows -C -M"
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
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
;
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
1668 multidisplay
=OSG::MultiDisplayWindow::create();
1669 clusterWindow
=multidisplay
;
1673 sortfirst
=OSG::SortFirstWindow::create();
1676 sortfirst
->setCompose(true);
1678 sortfirst
->setCompose(false);
1680 clusterWindow
=sortfirst
;
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
);
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
;
1709 #ifdef FRAMEINTERLEAVE
1711 frameinterleaveOSG::=FrameInterleaveWindow::create();
1712 clusterWindow
=frameinterleave
;
1714 frameinterleave
->setCompose(true);
1716 frameinterleave
->setCompose(false);
1721 sortfirst
=OSG::SortFirstWindow::create();
1722 sortfirst
->setCompose(false);
1723 clusterWindow
=sortfirst
;
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
]);
1736 multidisplay
->setHServers(
1737 clusterWindow
->getMFServers()->size()/rows
);
1738 multidisplay
->setVServers(
1742 #ifdef FRAMEINTERLEAVE
1743 clusterWindow
->setInterleave(interleave
);
1746 // create client window
1747 clientWindow
=OSG::GLUTWindow::create();
1748 // glutReshapeWindow(800,600);
1749 glutReshapeWindow(winwidth
,winheight
);
1750 clientWindow
->setGlutId(winid
);
1751 clientWindow
->init();
1757 clusterWindow
->setConnectionType(connectionType
);
1758 // needs to be called before init()!
1759 clusterWindow
->setConnectionParams(connectionParameters
);
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
);
1773 int main(int argc
,char **argv
)
1784 int main (int argc
, char **argv
)