changed: gcc8 base update
[opensg.git] / Source / Contrib / VTK / testVTKClusterConnect.cpp
blobef5b7cf9e0c2ec00a3b6e3843097f48e9442d287
2 #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
3 #pragma GCC diagnostic warning "-Wold-style-cast"
4 #endif
6 // testDynamicClusterClient2
7 //
8 // OpenSG cluster client program where you can dynamicly connect/disconnect
9 // to the servers.
10 // It is similar to testDynamicClusterClient but this time we create from the
11 // current state a changelist and send this to the cluster servers.
12 // This variant is much easier to implement in your own app but could be
13 // problematic if you use more than one aspect in your app.
15 // To test it, run
16 // ./testClusterServer -w pipe0 &
17 // ./testDynamicClusterClient2 pipe0
19 // press 'c' to connect to the servers and 'd' to disconnect.
22 #include "OSGConfig.h"
24 #ifdef OSG_WITH_VTK
26 #include "OSGGLUT.h"
27 #include "OSGSimpleGeometry.h"
28 #include "OSGGLUTWindow.h"
29 #include "OSGSimpleSceneManager.h"
30 #include "OSGMultiDisplayWindow.h"
31 #include "OSGSceneFileHandler.h"
32 #include "OSGRemoteAspect.h"
33 #include "OSGFieldContainerFactory.h"
35 #include "OSGVTKPolyDataMapper.h"
37 #include "vtkStructuredGridReader.h"
38 #include "vtkStructuredGrid.h"
39 #include "vtkPointData.h"
40 #include "vtkActor.h"
41 #include "vtkStructuredGridOutlineFilter.h"
42 #include "vtkPolyDataMapper.h"
43 #include "vtkProperty.h"
44 #include "vtkStructuredGridGeometryFilter.h"
45 #include "vtkPointSource.h"
46 #include "vtkRungeKutta4.h"
47 #include "vtkStreamLine.h"
48 #include "vtkTubeFilter.h"
49 #include "vtkPolyDataNormals.h"
51 #include <string>
52 #include <vector>
54 // The SimpleSceneManager to manage simple applications
55 OSG::SimpleSceneManagerRefPtr _mgr;
56 OSG::GLUTWindowRecPtr _client_win = NULL;
57 OSG::MultiDisplayWindowRecPtr _cluster_win = NULL;
58 OSG::NodeRecPtr _root = NULL;
59 std::vector<std::string> _pipenames;
61 // forward declaration so we can have the interesting stuff upfront
62 int setupGLUT( int *argc, char *argv[] );
63 void display(void);
65 void addActor(OSG::Node *pRoot,
66 vtkActor *pActor)
68 OSG::NodeUnrecPtr pTmpNode = OSG::Node ::create();
69 OSG::VTKPolyDataMapperUnrecPtr pTmpMapper =
70 OSG::VTKPolyDataMapper::create();
72 pTmpMapper->setActor(pActor );
73 pTmpNode ->setCore (pTmpMapper);
74 pRoot ->addChild(pTmpNode );
76 fprintf(stderr, "%016" PRIX64 "\n",
77 OSG::VTKPolyDataMapper::ChangedCallbacksFieldMask);
78 fprintf(stderr, "%016" PRIX64 "\n",
79 OSG::VTKPolyDataMapper::AttachmentsFieldMask);
80 fprintf(stderr, "%016" PRIX64 "\n",
81 OSG::VTKPolyDataMapper::ParentsFieldMask);
82 fprintf(stderr, "%016" PRIX64 "\n",
83 OSG::VTKPolyDataMapper::RootFieldMask);
84 fprintf(stderr, "%016" PRIX64 "\n",
85 OSG::VTKPolyDataMapper::GeoRootsFieldMask);
86 fprintf(stderr, "%016" PRIX64 "\n",
87 OSG::VTKPolyDataMapper::NormalsFieldMask);
89 fprintf(stderr, "%016" PRIX64 "%016" PRIX64 "\n",
90 (OSG::VTKPolyDataMapper::GeoRootsFieldMask),
91 ~(OSG::VTKPolyDataMapper::GeoRootsFieldMask));
93 fprintf(stderr, "%016" PRIX64 "\n",
94 pTmpMapper->getFieldFlags()->_bClusterLocalFlags);
96 // pTmpMapper->execute();
99 OSG::NodeTransitPtr initVTK(void)
101 OSG::NodeUnrecPtr returnValue = NULL;
103 OSG::Char8 *szDataRoot = getenv("VTK_DATA_ROOT");
105 if(szDataRoot == NULL)
107 fprintf(stderr, "VTK_DATA_ROOT not set\n");
108 exit(0);
111 std::string szFilename;
113 szFilename.assign(szDataRoot);
114 szFilename += "/Data/office.binary.vtk";
116 vtkStructuredGridReader *reader = vtkStructuredGridReader::New();
118 reader->SetFileName(szFilename.c_str());
119 reader->Update();
121 #if 0
122 OSG::Real64 length = reader->GetOutput()->GetLength();
124 OSG::Real64 maxVelocity =
125 reader->GetOutput()->GetPointData()->GetVectors()->GetMaxNorm();
127 OSG::Real64 maxTime = 35.0 * length / maxVelocity;
128 #endif
131 returnValue = OSG::Node::create();
133 returnValue->setCore(OSG::Group::create());
135 // Create source for streamtubes
136 vtkPointSource *seeds = vtkPointSource::New();
137 seeds->SetRadius(0.15);
138 seeds->SetCenter(0.1, 2.1, 0.5);
139 seeds->SetNumberOfPoints(6);
141 vtkRungeKutta4 *integ = vtkRungeKutta4::New();
142 vtkStreamLine *streamer = vtkStreamLine::New();
143 streamer->SetInputConnection(reader->GetOutputPort());
144 #if VTK_MAJOR_VERSION >= 6
145 streamer->SetSourceData(seeds->GetOutput());
146 #else
147 streamer->SetSource(seeds->GetOutput());
148 #endif
149 streamer->SetMaximumPropagationTime(500);
150 streamer->SetStepLength(0.5);
151 streamer->SetIntegrationStepLength(0.05);
152 streamer->SetIntegrationDirectionToIntegrateBothDirections();
153 streamer->SetIntegrator(integ);
155 // The tube is wrapped around the generated streamline. By varying the
156 // radius by the inverse of vector magnitude, we are creating a tube
157 // whose radius is proportional to mass flux (in incompressible flow).
158 vtkTubeFilter *streamTube = vtkTubeFilter::New();
159 streamTube->SetInputConnection(streamer->GetOutputPort());
160 streamTube->SetRadius(0.02);
161 streamTube->SetNumberOfSides(12);
162 streamTube->SetVaryRadiusToVaryRadiusByVector();
163 vtkPolyDataMapper *mapStreamTube = vtkPolyDataMapper::New();
164 mapStreamTube->SetInputConnection(streamTube->GetOutputPort());
165 mapStreamTube->SetScalarRange(
166 reader->GetOutput()->GetPointData()->GetScalars()->GetRange());
167 vtkActor *streamTubeActor = vtkActor::New();
168 streamTubeActor->SetMapper(mapStreamTube);
169 streamTubeActor->GetProperty()->BackfaceCullingOn();
171 addActor(returnValue, streamTubeActor);
174 vtkStructuredGridGeometryFilter *table1 =
175 vtkStructuredGridGeometryFilter::New();
177 table1->SetInputConnection(reader->GetOutputPort());
178 table1->SetExtent(11, 15, 7, 9, 8, 8);
180 vtkPolyDataNormals *normTable1 = vtkPolyDataNormals::New();
181 normTable1->SetInputConnection(table1->GetOutputPort());
183 vtkPolyDataMapper *mapTable1 = vtkPolyDataMapper::New();
184 mapTable1->SetInputConnection(normTable1->GetOutputPort());
185 mapTable1->ScalarVisibilityOff();
187 vtkActor *table1Actor = vtkActor::New();
188 table1Actor->SetMapper(mapTable1);
189 table1Actor->GetProperty()->SetColor(.59, .427, .392);
191 addActor(returnValue, table1Actor);
195 vtkStructuredGridGeometryFilter *table2 =
196 vtkStructuredGridGeometryFilter::New();
197 table2->SetInputConnection(reader->GetOutputPort());
198 table2->SetExtent(11, 15, 10, 12, 8, 8);
200 vtkPolyDataNormals *normTable2 = vtkPolyDataNormals::New();
201 normTable2->SetInputConnection(table2->GetOutputPort());
203 vtkPolyDataMapper *mapTable2 = vtkPolyDataMapper::New();
204 mapTable2->SetInputConnection(normTable2->GetOutputPort());
205 mapTable2->ScalarVisibilityOff();
207 vtkActor *table2Actor = vtkActor::New();
208 table2Actor->SetMapper(mapTable2);
209 table2Actor->GetProperty()->SetColor(.59, .427, .392);
211 addActor(returnValue, table2Actor);
215 vtkStructuredGridGeometryFilter *FilingCabinet1 =
216 vtkStructuredGridGeometryFilter::New();
218 FilingCabinet1->SetInputConnection(reader->GetOutputPort());
219 FilingCabinet1->SetExtent(15, 15, 7, 9, 0, 8);
221 vtkPolyDataNormals *normFilingCabinet1 = vtkPolyDataNormals::New();
222 normFilingCabinet1->SetInputConnection(FilingCabinet1->GetOutputPort());
224 vtkPolyDataMapper *mapFilingCabinet1 = vtkPolyDataMapper::New();
225 mapFilingCabinet1->SetInputConnection(normFilingCabinet1->GetOutputPort());
226 mapFilingCabinet1->ScalarVisibilityOff();
228 vtkActor *FilingCabinet1Actor = vtkActor::New();
229 FilingCabinet1Actor->SetMapper(mapFilingCabinet1);
230 FilingCabinet1Actor->GetProperty()->SetColor(.8, .8, .6);
232 addActor(returnValue, FilingCabinet1Actor);
236 vtkStructuredGridGeometryFilter *FilingCabinet2 =
237 vtkStructuredGridGeometryFilter::New();
238 FilingCabinet2->SetInputConnection(reader->GetOutputPort());
239 FilingCabinet2->SetExtent(15, 15, 10, 12, 0, 8);
241 vtkPolyDataNormals *normFilingCabinet2 = vtkPolyDataNormals::New();
242 normFilingCabinet2->SetInputConnection(FilingCabinet2->GetOutputPort());
244 vtkPolyDataMapper *mapFilingCabinet2 = vtkPolyDataMapper::New();
245 mapFilingCabinet2->SetInputConnection(normFilingCabinet2->GetOutputPort());
246 mapFilingCabinet2->ScalarVisibilityOff();
248 vtkActor *FilingCabinet2Actor = vtkActor::New();
249 FilingCabinet2Actor->SetMapper(mapFilingCabinet2);
250 FilingCabinet2Actor->GetProperty()->SetColor(.8, .8, .6);
252 addActor(returnValue, FilingCabinet2Actor);
256 vtkStructuredGridGeometryFilter *bookshelf1Top =
257 vtkStructuredGridGeometryFilter::New();
258 bookshelf1Top->SetInputConnection(reader->GetOutputPort());
259 bookshelf1Top->SetExtent(13, 13, 0, 4, 0, 11);
261 vtkPolyDataNormals *normbookshelf1Top = vtkPolyDataNormals::New();
262 normbookshelf1Top->SetInputConnection(bookshelf1Top->GetOutputPort());
264 vtkPolyDataMapper *mapBookshelf1Top = vtkPolyDataMapper::New();
265 mapBookshelf1Top->SetInputConnection(normbookshelf1Top->GetOutputPort());
266 mapBookshelf1Top->ScalarVisibilityOff();
268 vtkActor *bookshelf1TopActor = vtkActor::New();
269 bookshelf1TopActor->SetMapper(mapBookshelf1Top);
270 bookshelf1TopActor->GetProperty()->SetColor(.8, .8, .6);
272 addActor(returnValue, bookshelf1TopActor);
276 vtkStructuredGridGeometryFilter *bookshelf1Bottom =
277 vtkStructuredGridGeometryFilter::New();
278 bookshelf1Bottom->SetInputConnection(reader->GetOutputPort());
279 bookshelf1Bottom->SetExtent(20, 20, 0, 4, 0, 11);
281 vtkPolyDataNormals *normbookshelf1Bottom = vtkPolyDataNormals::New();
282 normbookshelf1Bottom->SetInputConnection(
283 bookshelf1Bottom->GetOutputPort());
285 vtkPolyDataMapper *mapBookshelf1Bottom = vtkPolyDataMapper::New();
286 mapBookshelf1Bottom->SetInputConnection(
287 normbookshelf1Bottom->GetOutputPort());
288 mapBookshelf1Bottom->ScalarVisibilityOff();
290 vtkActor *bookshelf1BottomActor = vtkActor::New();
291 bookshelf1BottomActor->SetMapper(mapBookshelf1Bottom);
292 bookshelf1BottomActor->GetProperty()->SetColor(.8, .8, .6);
294 addActor(returnValue, bookshelf1BottomActor);
298 vtkStructuredGridGeometryFilter *bookshelf1Front =
299 vtkStructuredGridGeometryFilter::New();
300 bookshelf1Front->SetInputConnection(reader->GetOutputPort());
301 bookshelf1Front->SetExtent(13, 20, 0, 0, 0, 11);
303 vtkPolyDataNormals *normbookshelf1Front = vtkPolyDataNormals::New();
304 normbookshelf1Front->SetInputConnection(bookshelf1Front->GetOutputPort());
306 vtkPolyDataMapper *mapBookshelf1Front = vtkPolyDataMapper::New();
307 mapBookshelf1Front->SetInputConnection(
308 normbookshelf1Front->GetOutputPort());
309 mapBookshelf1Front->ScalarVisibilityOff();
311 vtkActor *bookshelf1FrontActor = vtkActor::New();
312 bookshelf1FrontActor->SetMapper(mapBookshelf1Front);
313 bookshelf1FrontActor->GetProperty()->SetColor(.8, .8, .6);
315 addActor(returnValue, bookshelf1FrontActor);
319 vtkStructuredGridGeometryFilter *bookshelf1Back =
320 vtkStructuredGridGeometryFilter::New();
321 bookshelf1Back->SetInputConnection(reader->GetOutputPort());
322 bookshelf1Back->SetExtent(13, 20, 4, 4, 0, 11);
324 vtkPolyDataNormals *normbookshelf1Back = vtkPolyDataNormals::New();
325 normbookshelf1Back->SetInputConnection(bookshelf1Back->GetOutputPort());
327 vtkPolyDataMapper *mapBookshelf1Back = vtkPolyDataMapper::New();
328 mapBookshelf1Back->SetInputConnection(normbookshelf1Back->GetOutputPort());
329 mapBookshelf1Back->ScalarVisibilityOff();
331 vtkActor *bookshelf1BackActor = vtkActor::New();
332 bookshelf1BackActor->SetMapper(mapBookshelf1Back);
333 bookshelf1BackActor->GetProperty()->SetColor(.8, .8, .6);
335 addActor(returnValue, bookshelf1BackActor);
339 vtkStructuredGridGeometryFilter *bookshelf1LHS =
340 vtkStructuredGridGeometryFilter::New();
341 bookshelf1LHS->SetInputConnection(reader->GetOutputPort());
342 bookshelf1LHS->SetExtent(13, 20, 0, 4, 0, 0);
344 vtkPolyDataNormals *normbookshelf1LHS = vtkPolyDataNormals::New();
345 normbookshelf1LHS->SetInputConnection(bookshelf1LHS->GetOutputPort());
347 vtkPolyDataMapper *mapBookshelf1LHS = vtkPolyDataMapper::New();
348 mapBookshelf1LHS->SetInputConnection(normbookshelf1LHS->GetOutputPort());
349 mapBookshelf1LHS->ScalarVisibilityOff();
351 vtkActor *bookshelf1LHSActor = vtkActor::New();
352 bookshelf1LHSActor->SetMapper(mapBookshelf1LHS);
353 bookshelf1LHSActor->GetProperty()->SetColor(.8, .8, .6);
355 addActor(returnValue, bookshelf1LHSActor);
359 vtkStructuredGridGeometryFilter *bookshelf1RHS =
360 vtkStructuredGridGeometryFilter::New();
361 bookshelf1RHS->SetInputConnection(reader->GetOutputPort());
362 bookshelf1RHS->SetExtent(13, 20, 0, 4, 11, 11);
364 vtkPolyDataNormals *normbookshelf1RHS = vtkPolyDataNormals::New();
365 normbookshelf1RHS->SetInputConnection(bookshelf1RHS->GetOutputPort());
367 vtkPolyDataMapper *mapBookshelf1RHS = vtkPolyDataMapper::New();
368 mapBookshelf1RHS->SetInputConnection(normbookshelf1RHS->GetOutputPort());
369 mapBookshelf1RHS->ScalarVisibilityOff();
371 vtkActor *bookshelf1RHSActor = vtkActor::New();
372 bookshelf1RHSActor->SetMapper(mapBookshelf1RHS);
373 bookshelf1RHSActor->GetProperty()->SetColor(.8, .8, .6);
375 addActor(returnValue, bookshelf1RHSActor);
379 vtkStructuredGridGeometryFilter *bookshelf2Top =
380 vtkStructuredGridGeometryFilter::New();
381 bookshelf2Top->SetInputConnection(reader->GetOutputPort());
382 bookshelf2Top->SetExtent(13, 13, 15, 19, 0, 11);
384 vtkPolyDataNormals *normbookshelf2Top = vtkPolyDataNormals::New();
385 normbookshelf2Top->SetInputConnection(bookshelf2Top->GetOutputPort());
387 vtkPolyDataMapper *mapBookshelf2Top = vtkPolyDataMapper::New();
388 mapBookshelf2Top->SetInputConnection(normbookshelf2Top->GetOutputPort());
389 mapBookshelf2Top->ScalarVisibilityOff();
391 vtkActor *bookshelf2TopActor = vtkActor::New();
392 bookshelf2TopActor->SetMapper(mapBookshelf2Top);
393 bookshelf2TopActor->GetProperty()->SetColor(.8, .8, .6);
395 addActor(returnValue, bookshelf2TopActor);
398 vtkStructuredGridGeometryFilter *bookshelf2Bottom =
399 vtkStructuredGridGeometryFilter::New();
400 bookshelf2Bottom->SetInputConnection(reader->GetOutputPort());
401 bookshelf2Bottom->SetExtent(20, 20, 15, 19, 0, 11);
403 vtkPolyDataNormals *normbookshelf2Bottom = vtkPolyDataNormals::New();
404 normbookshelf2Bottom->SetInputConnection(
405 bookshelf2Bottom->GetOutputPort());
407 vtkPolyDataMapper *mapBookshelf2Bottom = vtkPolyDataMapper::New();
408 mapBookshelf2Bottom->SetInputConnection(
409 normbookshelf2Bottom->GetOutputPort());
410 mapBookshelf2Bottom->ScalarVisibilityOff();
412 vtkActor *bookshelf2BottomActor = vtkActor::New();
413 bookshelf2BottomActor->SetMapper(mapBookshelf2Bottom);
414 bookshelf2BottomActor->GetProperty()->SetColor(.8, .8, .6);
416 addActor(returnValue, bookshelf2BottomActor);
420 vtkStructuredGridGeometryFilter *bookshelf2Front =
421 vtkStructuredGridGeometryFilter::New();
422 bookshelf2Front->SetInputConnection(reader->GetOutputPort());
423 bookshelf2Front->SetExtent(13, 20, 15, 15, 0, 11);
425 vtkPolyDataNormals *normbookshelf2Front = vtkPolyDataNormals::New();
426 normbookshelf2Front->SetInputConnection(bookshelf2Front->GetOutputPort());
428 vtkPolyDataMapper *mapBookshelf2Front = vtkPolyDataMapper::New();
429 mapBookshelf2Front->SetInputConnection(
430 normbookshelf2Front->GetOutputPort());
431 mapBookshelf2Front->ScalarVisibilityOff();
433 vtkActor *bookshelf2FrontActor = vtkActor::New();
434 bookshelf2FrontActor->SetMapper(mapBookshelf2Front);
435 bookshelf2FrontActor->GetProperty()->SetColor(.8, .8, .6);
437 addActor(returnValue, bookshelf2FrontActor);
441 vtkStructuredGridGeometryFilter *bookshelf2Back =
442 vtkStructuredGridGeometryFilter::New();
443 bookshelf2Back->SetInputConnection(reader->GetOutputPort());
444 bookshelf2Back->SetExtent(13, 20, 19, 19, 0, 11);
446 vtkPolyDataNormals *normbookshelf2Back = vtkPolyDataNormals::New();
447 normbookshelf2Back->SetInputConnection(bookshelf2Back->GetOutputPort());
449 vtkPolyDataMapper *mapBookshelf2Back = vtkPolyDataMapper::New();
450 mapBookshelf2Back->SetInputConnection(normbookshelf2Back->GetOutputPort());
451 mapBookshelf2Back->ScalarVisibilityOff();
453 vtkActor *bookshelf2BackActor = vtkActor::New();
454 bookshelf2BackActor->SetMapper(mapBookshelf2Back);
455 bookshelf2BackActor->GetProperty()->SetColor(.8, .8, .6);
457 addActor(returnValue, bookshelf2BackActor);
461 vtkStructuredGridGeometryFilter *bookshelf2LHS =
462 vtkStructuredGridGeometryFilter::New();
463 bookshelf2LHS->SetInputConnection(reader->GetOutputPort());
464 bookshelf2LHS->SetExtent(13, 20, 15, 19, 0, 0);
466 vtkPolyDataNormals *normbookshelf2LHS = vtkPolyDataNormals::New();
467 normbookshelf2LHS->SetInputConnection(bookshelf2LHS->GetOutputPort());
469 vtkPolyDataMapper *mapBookshelf2LHS = vtkPolyDataMapper::New();
470 mapBookshelf2LHS->SetInputConnection(normbookshelf2LHS->GetOutputPort());
471 mapBookshelf2LHS->ScalarVisibilityOff();
472 vtkActor *bookshelf2LHSActor = vtkActor::New();
473 bookshelf2LHSActor->SetMapper(mapBookshelf2LHS);
474 bookshelf2LHSActor->GetProperty()->SetColor(.8, .8, .6);
476 addActor(returnValue, bookshelf2LHSActor);
480 vtkStructuredGridGeometryFilter *bookshelf2RHS =
481 vtkStructuredGridGeometryFilter::New();
482 bookshelf2RHS->SetInputConnection(reader->GetOutputPort());
483 bookshelf2RHS->SetExtent(13, 20, 15, 19, 11, 11);
485 vtkPolyDataNormals *normbookshelf2RHS = vtkPolyDataNormals::New();
486 normbookshelf2RHS->SetInputConnection(bookshelf2RHS->GetOutputPort());
488 vtkPolyDataMapper *mapBookshelf2RHS = vtkPolyDataMapper::New();
489 mapBookshelf2RHS->SetInputConnection(normbookshelf2RHS->GetOutputPort());
490 mapBookshelf2RHS->ScalarVisibilityOff();
492 vtkActor *bookshelf2RHSActor = vtkActor::New();
493 bookshelf2RHSActor->SetMapper(mapBookshelf2RHS);
494 bookshelf2RHSActor->GetProperty()->SetColor(.8, .8, .6);
496 addActor(returnValue, bookshelf2RHSActor);
500 vtkStructuredGridGeometryFilter *window =
501 vtkStructuredGridGeometryFilter::New();
502 window->SetInputConnection(reader->GetOutputPort());
503 window->SetExtent(20, 20, 6, 13, 10, 13);
505 vtkPolyDataNormals *normWindow = vtkPolyDataNormals::New();
506 normWindow->SetInputConnection(window->GetOutputPort());
508 vtkPolyDataMapper *mapWindow = vtkPolyDataMapper::New();
509 mapWindow->SetInputConnection(normWindow->GetOutputPort());
510 mapWindow->ScalarVisibilityOff();
512 vtkActor *windowActor = vtkActor::New();
513 windowActor->SetMapper(mapWindow);
514 windowActor->GetProperty()->SetColor(.3, .3, .5);
516 addActor(returnValue, windowActor);
520 vtkStructuredGridGeometryFilter *outlet =
521 vtkStructuredGridGeometryFilter::New();
522 outlet->SetInputConnection(reader->GetOutputPort());
523 outlet->SetExtent(0, 0, 9, 10, 14, 16);
525 vtkPolyDataNormals *normoutlet = vtkPolyDataNormals::New();
526 normoutlet->SetInputConnection(outlet->GetOutputPort());
528 vtkPolyDataMapper *mapOutlet = vtkPolyDataMapper::New();
529 mapOutlet->SetInputConnection(normoutlet->GetOutputPort());
530 mapOutlet->ScalarVisibilityOff();
531 vtkActor *outletActor = vtkActor::New();
532 outletActor->SetMapper(mapOutlet);
533 outletActor->GetProperty()->SetColor(0, 0, 0);
535 addActor(returnValue, outletActor);
539 vtkStructuredGridGeometryFilter *inlet =
540 vtkStructuredGridGeometryFilter::New();
541 inlet->SetInputConnection(reader->GetOutputPort());
542 inlet->SetExtent(0, 0, 9, 10, 0, 6);
544 vtkPolyDataNormals *norminlet = vtkPolyDataNormals::New();
545 norminlet->SetInputConnection(inlet->GetOutputPort());
547 vtkPolyDataMapper *mapInlet = vtkPolyDataMapper::New();
548 mapInlet->SetInputConnection(norminlet->GetOutputPort());
550 mapInlet->ScalarVisibilityOff();
551 vtkActor *inletActor = vtkActor::New();
552 inletActor->SetMapper(mapInlet);
553 inletActor->GetProperty()->SetColor(0, 0, 0);
557 vtkStructuredGridOutlineFilter *outline =
558 vtkStructuredGridOutlineFilter::New();
560 outline->SetInputConnection(reader->GetOutputPort());
562 vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
563 mapOutline->SetInputConnection(outline->GetOutputPort());
565 vtkActor *outlineActor = vtkActor::New();
567 outlineActor->SetMapper(mapOutline);
568 outlineActor->GetProperty()->SetColor(0, 0, 0);
570 addActor(returnValue, outlineActor);
572 OSG::Thread::getCurrentChangeList()->dump();
574 return OSG::NodeTransitPtr(returnValue);
578 // Initialize GLUT & OpenSG and set up the scene
579 int doMain(int argc, char **argv)
581 std::cout << "start a cluster server with './testClusterServer -w pipe0'\n"
582 "press 'c' to connect to the servers.\n"
583 "press 'd' to disconnect from the servers.\n"
584 "press 'n' to delete current scene.\n"
585 "press 't' to create a torus.\n"
586 "press 'l' to load scene 'tie.wrl'.\n"
587 << std::endl;
589 // OSG init
590 OSG::osgInit(argc,argv);
592 OSG::VTKPolyDataMapper::getClassType().dump();
594 // GLUT init
595 int winid = setupGLUT(&argc, argv);
597 // the connection between GLUT and OpenSG
599 _client_win = OSG::GLUTWindow::create();
601 _client_win->setGlutId(winid);
602 _client_win->init();
603 _client_win->setSize(300,300);
605 for(OSG::Int32 i=0;i<argc-1;++i)
607 if(argv[i+1] != NULL)
608 _pipenames.push_back(argv[i+1]);
611 if(_pipenames.empty())
612 _pipenames.push_back("pipe0");
614 _root = OSG::Node::create();
616 _root->setCore(OSG::Group::create());
618 // create default scene
619 // NodePtr scene = makeTorus(.5, 2, 16, 16);
620 OSG::NodeUnrecPtr scene = initVTK();
622 _root->addChild(scene);
624 // create the SimpleSceneManager helper
625 _mgr = OSG::SimpleSceneManager::create();
627 // tell the manager what to manage
628 _mgr->setWindow(_client_win );
629 _mgr->setRoot (_root);
631 // show the whole scene
632 _mgr->showAll();
635 return 0;
638 // Initialize GLUT & OpenSG and set up the scene
639 int main(int argc, char **argv)
641 doMain(argc, argv);
643 // GLUT main loop
644 glutMainLoop();
646 return 0;
649 static void connectCluster(void)
651 if(_cluster_win != NULL)
652 return;
654 OSG::Viewport *clientvp = _client_win->getPort(0);
656 // create the viewports for the cluster just a simple one ...
657 OSG::ViewportUnrecPtr vp = OSG::Viewport::create();
659 vp->setCamera (_mgr->getCamera());
660 vp->setBackground(clientvp->getBackground());
661 vp->setRoot (clientvp->getRoot());
662 vp->setSize (0,0, 1,1);
664 // the connection between this client and the servers
665 _cluster_win = OSG::MultiDisplayWindow::create();
667 // all changes must be enclosed in beginEditCP and endEditCP
668 // otherwise the changes will not be transfered over the network.
670 for(OSG::UInt32 i=0;i<_pipenames.size();++i)
671 _cluster_win->editMFServers()->push_back(_pipenames[i]);
672 // dummy size for navigator
673 _cluster_win->setSize(300,300);
674 _cluster_win->addPort(vp);
676 OSG::Thread::getCurrentChangeList()->commitChangesAndClear();
677 OSG::Thread::getCurrentChangeList()->fillFromCurrentState();
678 OSG::Thread::getCurrentChangeList()->dump();
679 // create from the current state a changelist.
681 // initialize window
682 _cluster_win->init();
684 // apply changelist to the servers
685 _cluster_win->render((OSG::RenderAction *) _mgr->getRenderAction());
687 // clear changelist
688 OSG::Thread::getCurrentChangeList()->clear();
690 glutPostRedisplay();
693 static void disconnectCluster(void)
695 if(_cluster_win == NULL)
696 return;
698 _cluster_win = NULL;
702 // GLUT callback functions
705 // redraw the window
706 void display(void)
708 // redraw the client window
709 _mgr->redraw();
712 OSG::commitChanges();
716 if(_cluster_win != NULL)
718 OSG::Thread::getCurrentChangeList()->dump();
720 // redraw the server windows
721 _cluster_win->render((OSG::RenderAction *) _mgr->getRenderAction());
725 catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
727 //printf("error: '%s'\n", e.what());
728 printf("ClusterServer was killed!\n");
730 _cluster_win = NULL;
733 OSG::commitChanges();
734 OSG::clearChangeList();
737 // react to size changes
738 void reshape(int w, int h)
740 glutPostRedisplay();
743 // react to mouse button presses
744 void mouse(int button, int state, int x, int y)
746 if (state)
747 _mgr->mouseButtonRelease(button, x, y);
748 else
749 _mgr->mouseButtonPress(button, x, y);
751 glutPostRedisplay();
754 // react to mouse motions with pressed buttons
755 void motion(int x, int y)
757 _mgr->mouseMove(x, y);
759 glutPostRedisplay();
762 // react to keys
763 void keyboard(unsigned char k, int x, int y)
765 switch(k)
767 case 27:
769 _mgr = NULL;
770 _client_win = NULL;
771 _cluster_win = NULL;
772 _root = NULL;
773 OSG::osgExit();
774 exit(0);
776 case 'n':
777 while(_root->getNChildren() > 0)
778 _root->subChild(_root->getChild(0));
780 glutPostRedisplay();
781 break;
782 case 'l':
784 OSG::NodeUnrecPtr scene =
785 OSG::SceneFileHandler::the()->read("tie.wrl");
787 if(scene != NULL)
789 _root->addChild(scene);
791 _mgr->showAll();
793 glutPostRedisplay();
796 break;
797 case 't':
799 OSG::NodeUnrecPtr scene = OSG::makeTorus(.5, 2, 16, 16);
801 _root->addChild(scene);
803 _mgr->showAll();
805 glutPostRedisplay();
807 break;
808 case 'c':
809 connectCluster();
810 break;
811 case 'd':
812 disconnectCluster();
813 break;
817 // setup the GLUT library which handles the windows for us
818 int setupGLUT(int *argc, char *argv[])
820 glutInit(argc, argv);
821 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
823 int winid = glutCreateWindow("OpenSG");
825 glutReshapeFunc(reshape);
826 glutDisplayFunc(display);
827 glutMouseFunc(mouse);
828 glutMotionFunc(motion);
829 glutKeyboardFunc(keyboard);
831 return winid;
834 #else
836 int main (int argc, char **argv)
838 return 0;
841 #endif