00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <sstream>
00047
00048 #include <OSGConfig.h>
00049 #include <OSGSystemDef.h>
00050 #include "OSGClusterWindow.h"
00051 #include "OSGDgramSocket.h"
00052 #include "OSGStreamSocket.h"
00053 #include "OSGRemoteAspect.h"
00054 #include "OSGConnection.h"
00055 #include "OSGBinaryMessage.h"
00056 #include "OSGRemoteAspect.h"
00057 #include "OSGConnectionFactory.h"
00058 #include "OSGClusterNetwork.h"
00059 #include "OSGXmlpp.h"
00060 #include "OSGDisplayCalibration.h"
00061 #include "OSGRenderOptions.h"
00062 #include "OSGGroupSockConnection.h"
00063
00064 #include "OSGDisplayFilterForeground.h"
00065 #include "OSGColorDisplayFilter.h"
00066 #include "OSGDistortionDisplayFilter.h"
00067 #include "OSGResolutionDisplayFilter.h"
00068
00069
00070 OSG_USING_NAMESPACE
00071
00084
00085
00086
00088
00089 void ClusterWindow::changed(BitVector whichField, UInt32 origin)
00090 {
00091 Inherited::changed(whichField, origin);
00092 }
00093
00095
00096 void ClusterWindow::dump( UInt32 ,
00097 const BitVector ) const
00098 {
00099 SLOG << "Dump ClusterWindow NI" << std::endl;
00100 }
00101
00102 void (*ClusterWindow::getFunctionByName ( const Char8 * ))()
00103 {
00104 return NULL;
00105 }
00106
00110 void ClusterWindow::init( void )
00111 {
00112 GroupConnection *connection;
00113 RemoteAspect *remoteAspect;
00114 int c,i,id;
00115 MFString::iterator s;
00116 Connection::Channel channel;
00117 bool directConnect=false;
00118
00119 if(getNetwork()->getMainConnection())
00120 {
00121 SWARNING << "init called twice" << std::endl;
00122 return;
00123 }
00124
00125 if(getConnectionType().empty())
00126 {
00127 setConnectionType("StreamSock");
00128 }
00129
00130 connection = ConnectionFactory::the().createGroup(getConnectionType());
00131 if(connection == NULL)
00132 {
00133 SFATAL << "Unknown connection type "
00134 << getConnectionType()
00135 << std::endl;
00136 return;
00137 }
00138
00139 connection->setDestination(getConnectionDestination());
00140 connection->setInterface(getConnectionInterface());
00141 connection->setParams(getConnectionParams());
00142
00143 getNetwork()->setMainConnection(connection);
00144
00145 remoteAspect = new RemoteAspect();
00146 getNetwork()->setAspect(remoteAspect);
00147 if(_statistics)
00148 remoteAspect->setStatistics(_statistics);
00149
00150
00151 std::string server;
00152 std::string autostart;
00153 std::string env;
00154
00155 Real32 progress = 0.0f;
00156 Real32 progressStep = 1.0f / Real32(getServers().size());
00157
00158 if(getAutostart().size())
00159 {
00160 progressStep /= 2;
00161 std::vector<FILE*> pipes;
00162
00163 for(id=0 ; id<getServers().size() ; ++id)
00164 {
00165 std::ostringstream command;
00166
00167 server = getServers()[id];
00168 int pos=server.find(":");
00169 if(pos>=0)
00170 server.erase(pos);
00171
00172 autostart = getAutostart()[id % getAutostart().size()];
00173
00174 for(c = 0 ; c < autostart.length() ; ++c)
00175 {
00176 if(autostart[c] == '%' && c+1 < autostart.length())
00177 switch(autostart[++c])
00178 {
00179 case 's':
00180 command << server;
00181 break;
00182 case 'n':
00183 command << getServers()[id];
00184 break;
00185 case 'i':
00186 command << id;
00187 break;
00188 case '{':
00189 env = "" ;
00190 while(++c < autostart.length() &&
00191 autostart[c] != '}')
00192 env += autostart[c];
00193 if(getenv(env.c_str()))
00194 command << getenv(env.c_str());
00195 break;
00196 case '%':
00197 command << '%';
00198 break;
00199 default:
00200 command << '%' << autostart[c];
00201 }
00202 else
00203 command << autostart[c];
00204 }
00205 SINFO << command.str() << std::endl;
00206 #ifdef WIN32
00207 FILE *pipe = _popen(command.str().c_str(),"r");
00208 #else
00209 FILE *pipe = popen(command.str().c_str(),"r");
00210 #endif
00211 if(!pipe)
00212 SFATAL << "Error starting: " << command << std::endl;
00213 pipes.push_back(pipe);
00214 }
00215 for(id=0 ; id<getServers().size() ; ++id)
00216 {
00217 if(pipes[id])
00218 {
00219
00220 if(_connectionFP != NULL)
00221 {
00222 std::string message;
00223 message += "Starting:" + getServers()[id];
00224 if(!_connectionFP(message, progress))
00225 {
00226
00227 for( ; id<getServers().size() ; ++id)
00228 {
00229 if(pipes[id])
00230 {
00231 #ifdef WIN32
00232 _pclose(pipes[id]);
00233 #else
00234 pclose(pipes[id]);
00235 #endif
00236 }
00237 throw AsyncCancel();
00238 }
00239 }
00240 }
00241 SINFO << "Waiting for " << getServers()[id] << " to start." << std::endl;
00242 char result;
00243 std::string line="";
00244 while((result=fgetc(pipes[id])) != EOF)
00245 {
00246 line += result;
00247 if(result == '\n')
00248 {
00249 SINFO << line;
00250 line = "";
00251 }
00252 }
00253 if(!line.empty())
00254 SINFO << line << std::endl;
00255 #ifdef WIN32
00256 _pclose(pipes[id]);
00257 #else
00258 pclose(pipes[id]);
00259 #endif
00260 SINFO << getServers()[id] << " started." << std::endl;
00261 progress += progressStep;
00262 }
00263 }
00264 }
00265
00266
00267 for(s =getServers().begin();
00268 s!=getServers().end();
00269 s++)
00270 {
00271 DgramSocket serviceSock;
00272 BinaryMessage msg;
00273 std::string respServer;
00274 std::string respAddress;
00275 bool retry=true;
00276
00277 if(strstr((*s).c_str(),":"))
00278 directConnect = true;
00279 else
00280 directConnect = false;
00281
00282 SINFO << "Connect to " << (*s) << std::endl;
00283 serviceSock.open();
00284 serviceSock.setTTL(8);
00285
00286
00287 if(!getServiceInterface().empty())
00288 {
00289 serviceSock.setMCastInterface(
00290 SocketAddress(getServiceInterface().c_str()));
00291 }
00292
00293 while(retry)
00294 {
00295 try
00296 {
00297
00298 if(_connectionFP != NULL)
00299 {
00300 std::string message;
00301 message += "Connecting:" + *s;
00302 if(!_connectionFP(message, progress))
00303 {
00304 serviceSock.close();
00305 throw AsyncCancel();
00306 }
00307 }
00308
00309
00310 try
00311 {
00312 if(directConnect)
00313 {
00314 channel = connection->connectPoint(*s,0.5);
00315 if(channel >= 0) {
00316 retry=false;
00317 SINFO << "Connected with address:" << *s << std::endl;
00318 break;
00319 }
00320 }
00321 }
00322 catch(...)
00323 {
00324 }
00325
00326 msg.clear();
00327 msg.putString(*s);
00328 msg.putString(getConnectionType());
00329
00330 if(_sfServiceAddress.getValue().size() != 0)
00331 {
00332 SINFO << "send request to:" <<
00333 _sfServiceAddress.getValue()
00334 << std::endl;
00335 serviceSock.sendTo(
00336 msg,SocketAddress(
00337 _sfServiceAddress.getValue().c_str(),
00338 getServicePort()));
00339 }
00340 SINFO << "send request to:"
00341 << SocketAddress(SocketAddress::BROADCAST,
00342 getServicePort()).getHost().c_str()
00343 << std::endl;
00344 serviceSock.sendTo(
00345 msg,SocketAddress(SocketAddress::BROADCAST,
00346 getServicePort()));
00347 if(serviceSock.waitReadable(0.1))
00348 {
00349 SocketAddress from;
00350 serviceSock.recvFrom(msg,from);
00351 msg.getString(respServer);
00352 msg.getString(respAddress);
00353 if(respServer == *s)
00354 {
00355 GroupSockConnection *pointSock =
00356 dynamic_cast<GroupSockConnection*> (connection);
00357 if(pointSock)
00358 {
00359
00360
00361
00362 char port[16];
00363 if(sscanf(respAddress.c_str(),
00364 "%*[^:]:%15s",port) == 1)
00365 respAddress = from.getHost() + ":" + port;
00366 }
00367 SINFO << "Found at address " << respAddress << std::endl;
00368
00369 channel = connection->connectPoint(respAddress);
00370 if(channel >= 0)
00371 retry=false;
00372 }
00373 }
00374 }
00375 catch(AsyncCancel &)
00376 {
00377 throw;
00378 }
00379 catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
00380 {
00381 SINFO << e.what() << std::endl;
00382 }
00383 }
00384 serviceSock.close();
00385 progress += progressStep;
00386 }
00387
00388 UInt8 serverLittleEndian;
00389 UInt8 forceNetworkOrder=false;
00390 #if BYTE_ORDER == LITTLE_ENDIAN
00391 UInt8 littleEndian = true;
00392 #else
00393 UInt8 littleEndian = false;
00394 #endif
00395 for(UInt32 i=0;i<getServers().size();++i)
00396 {
00397 channel = connection->selectChannel();
00398 connection->subSelection(channel);
00399 connection->getValue(serverLittleEndian);
00400 if(serverLittleEndian != littleEndian)
00401 {
00402 forceNetworkOrder=true;
00403 }
00404 }
00405 connection->resetSelection();
00406
00407 connection->putValue(forceNetworkOrder);
00408 connection->flush();
00409 connection->setNetworkOrder((forceNetworkOrder != 0));
00410 if(forceNetworkOrder)
00411 {
00412 SINFO << "Run clustering in network order mode" << std::endl;
00413 }
00414
00415 if(_connectionFP != NULL)
00416 _connectionFP("ok", 1.0);
00417 }
00418
00419 bool ClusterWindow::initAsync(connectioncbfp fp)
00420 {
00421 bool result;
00422 connectioncbfp saveFP = _connectionFP;
00423
00424 _connectionFP = fp;
00425 try
00426 {
00427 init();
00428 result = true;
00429 }
00430 catch(AsyncCancel &e)
00431 {
00432 result = false;
00433 }
00434 _connectionFP = saveFP;
00435
00436 return result;
00437 }
00438
00439 void ClusterWindow::setConnectionCB(connectioncbfp fp)
00440 {
00441 _connectionFP = fp;
00442 }
00443
00444 void ClusterWindow::render(RenderActionBase *action)
00445 {
00446 activate();
00447 frameInit();
00448 renderAllViewports(action);
00449 swap();
00450 frameExit();
00451 }
00452
00453 void ClusterWindow::activate( void )
00454 {
00455 }
00456
00457 void ClusterWindow::deactivate( void )
00458 {
00459 }
00460
00461 void ClusterWindow::swap( void )
00462 {
00463 if(getNetwork()->getMainConnection() && getNetwork()->getAspect())
00464 {
00465 clientSwap();
00466 }
00467 }
00468
00469 void ClusterWindow::renderAllViewports(RenderActionBase *action)
00470 {
00471 if(getNetwork()->getMainConnection() && getNetwork()->getAspect())
00472 {
00473 clientRender(action);
00474 }
00475 }
00476
00477 void ClusterWindow::frameInit(void)
00478 {
00479 ClusterWindowPtr ptr(this);
00480 Connection *connection =getNetwork()->getMainConnection();
00481 RemoteAspect *remoteAspect=getNetwork()->getAspect();
00482
00483 if(remoteAspect && connection)
00484 {
00485 if(_firstFrame)
00486 {
00487 beginEditCP(ptr,ClusterWindow::FrameCountFieldMask);
00488 setFrameCount(0);
00489 endEditCP(ptr,ClusterWindow::FrameCountFieldMask);
00490
00491 remoteAspect->sendSync(*connection);
00492 ChangeList cl;
00493 cl.clearAll();
00494 cl.merge(*Thread::getCurrentChangeList());
00495 Thread::getCurrentChangeList()->clearAll();
00496
00497 clientInit();
00498
00499 clientPreSync();
00500
00501 remoteAspect->sendSync(*connection);
00502 cl.merge(*Thread::getCurrentChangeList());
00503 Thread::getCurrentChangeList()->clearAll();
00504 Thread::getCurrentChangeList()->merge(cl);
00505 _firstFrame=false;
00506 }
00507 else
00508 {
00509 beginEditCP(ptr,ClusterWindow::FrameCountFieldMask);
00510 getFrameCount()++;
00511 endEditCP(ptr,ClusterWindow::FrameCountFieldMask);
00512 clientPreSync();
00513 remoteAspect->sendSync(*connection);
00514 }
00515 }
00516 }
00517
00518 void ClusterWindow::frameExit(void)
00519 {
00520 }
00521
00522
00523
00524
00525 void ClusterWindow::setStatistics(StatCollector *statistics)
00526 {
00527 _statistics = statistics;
00528 if(getNetwork()->getAspect())
00529 getNetwork()->getAspect()->setStatistics(statistics);
00530 }
00531
00532
00533
00534
00537 bool ClusterWindow::loadCalibration(std::istream &in)
00538 {
00539 ClusterWindowPtr ptr(this);
00540 DisplayCalibrationPtr calibPtr;
00541 xmlpp::xmlcontextptr ctxptr(new xmlpp::xmlcontext());
00542 xmlpp::xmldocument doc(ctxptr);
00543 xmlpp::xmlnodelist servers;
00544 xmlpp::xmlnodelist colors;
00545 xmlpp::xmlnodelist points;
00546 xmlpp::xmlnodelist rows;
00547 xmlpp::xmlnodelist::const_iterator sI;
00548 xmlpp::xmlnodelist::const_iterator nI;
00549 xmlpp::xmlnodelist::const_iterator cI;
00550 xmlpp::xmlnodelist::const_iterator rI;
00551 xmlpp::xmlnodelist::const_iterator pI;
00552 xmlpp::xmlstring serverTag("server");
00553 xmlpp::xmlstring colorTag("color");
00554 xmlpp::xmlstring rowTag("row");
00555 xmlpp::xmlstring pointTag("point");
00556 Matrix colorMatrix;
00557 Real32 gamma;
00558 xmlpp::xmlnodeptr nP;
00559
00560 getCalibration().clear();
00561 try
00562 {
00563 doc.load(in,ctxptr);
00564 servers = doc.select_nodes(serverTag);
00565
00566 for(sI = servers.begin() ; sI != servers.end(); ++sI)
00567 {
00568
00569 calibPtr = DisplayCalibration::create();
00570 beginEditCP(calibPtr);
00571 addRefCP(calibPtr);
00572 beginEditCP(ptr,CalibrationFieldMask);
00573 getCalibration().push_back(calibPtr);
00574 endEditCP(ptr,CalibrationFieldMask);
00575
00576
00577 if((*sI)->get_attrmap().count("name"))
00578 calibPtr->setServer((*sI)->get_attrmap()["name"]);
00579
00580
00581 for(nI = (*sI)->get_nodelist().begin();
00582 nI != (*sI)->get_nodelist().end();
00583 ++nI)
00584 {
00585 if((*nI)->get_name() == "colormatrix")
00586 {
00587 nP = (*nI);
00588 do
00589 nP = nP->get_nodelist().front();
00590 while (nP->get_nodelist().size() == 1);
00591 if(nP->get_type() == xmlpp::xml_nt_cdata)
00592 calibPtr->getColorMatrix().setValue(nP->get_cdata().c_str());
00593 }
00594
00595 if((*nI)->get_name() == "scaledown")
00596 {
00597 nP = (*nI);
00598 do
00599 nP = nP->get_nodelist().front();
00600 while (nP->get_nodelist().size() == 1);
00601 if(nP->get_type() == xmlpp::xml_nt_cdata)
00602 sscanf(nP->get_cdata().c_str(),"%f",&calibPtr->getScaleDown());
00603 }
00604
00605 if((*nI)->get_name() == "gamma")
00606 {
00607 nP = (*nI);
00608 do
00609 nP = nP->get_nodelist().front();
00610 while (nP->get_nodelist().size() == 1);
00611 if(nP->get_type() == xmlpp::xml_nt_cdata)
00612 sscanf(nP->get_cdata().c_str(),"%f",&calibPtr->getGamma());
00613 }
00614
00615 if((*nI)->get_name() == "gammaramp")
00616 {
00617 colors = (*nI)->select_nodes(colorTag);
00618 for(cI = colors.begin() ; cI != colors.end(); ++cI)
00619 {
00620 nP = (*cI);
00621 do
00622 nP = nP->get_nodelist().front();
00623 while (nP->get_nodelist().size() == 1);
00624 if(nP->get_type() == xmlpp::xml_nt_cdata)
00625 {
00626 Color3f col;
00627 col.setValue(nP->get_cdata().c_str());
00628 calibPtr->getGammaRamp().push_back(col);
00629 }
00630 }
00631 }
00632 if((*nI)->get_name() == "grid")
00633 {
00634 rows = (*nI)->select_nodes(rowTag);
00635 calibPtr->getGridHeight() = 0;
00636 for(rI = rows.begin() ; rI != rows.end(); ++rI)
00637 {
00638 calibPtr->getGridHeight()++;
00639 calibPtr->getGridWidth() = 0;
00640 points = (*rI)->select_nodes(pointTag);
00641 for(pI = points.begin() ; pI != points.end(); ++pI)
00642 {
00643 nP = (*pI);
00644 do
00645 nP = nP->get_nodelist().front();
00646 while (nP->get_nodelist().size() == 1);
00647 if(nP->get_type() == xmlpp::xml_nt_cdata)
00648 {
00649 Vec2f pos;
00650 calibPtr->getGridWidth()++;
00651 pos.setValueFromCString(nP->get_cdata().c_str());
00652 calibPtr->getGrid().push_back(pos);
00653 }
00654 }
00655 }
00656 }
00657 }
00658 endEditCP(calibPtr);
00659 }
00660 }
00661 catch (xmlpp::xmlerror e)
00662 {
00663
00664 xmlpp::xmllocation where( ctxptr->get_location() );
00665 xmlpp::xmlstring errmsg( e.get_strerror() );
00666 SFATAL << "XML error line " << where.get_line() << " "
00667 << "at position " << where.get_pos()
00668 << ": error: " << errmsg.c_str()
00669 << std::endl;
00670 return false;
00671 }
00672 return true;
00673 }
00674
00677 bool ClusterWindow::saveCalibration(std::ostream &out)
00678 {
00679 DisplayCalibrationPtr calibPtr;
00680 UInt32 c;
00681 UInt32 color,row,col,pos;
00682
00683 out << "<?xml version=\"1.0\"?>\n"
00684 << "<displaycalibration>\n";
00685 for(c=0 ; c<getCalibration().size() ; ++c)
00686 {
00687 calibPtr = getCalibration()[c];
00688 out << "<server name=\"" << calibPtr->getServer() << "\">\n";
00689 out << "<gamma>" << calibPtr->getGamma() << "</gamma>\n";
00690 out << "<scaledown>" << calibPtr->getScaleDown() << "</scaledown>\n";
00691 out << "<colormatrix>\n"
00692 << calibPtr->getColorMatrix()
00693 << "</colormatrix>\n";
00694 out << "<gammaramp>\n";
00695 for(color=0 ; color< calibPtr->getGammaRamp().size() ; ++color)
00696 out << "<color>"
00697 << calibPtr->getGammaRamp()[color]
00698 << "</color>\n";
00699 out << "</gammaramp>\n";
00700 out << "<grid>\n";
00701 for(row=0 ; row< calibPtr->getGridHeight() ; ++row)
00702 {
00703 out << "<row>\n";
00704 for(col=0 ; col< calibPtr->getGridWidth() ; ++col)
00705 {
00706 pos = row*calibPtr->getGridHeight()+col;
00707 out << "<point>";
00708 if(pos < calibPtr->getGrid().size())
00709 out << calibPtr->getGrid()[pos][0] << " "
00710 << calibPtr->getGrid()[pos][1];
00711 else
00712 out << col << " " << row;
00713 out << "</point>\n";
00714 }
00715 out << "</row>\n";
00716 }
00717 out << "</grid>\n";
00718 out << "</server>\n";
00719 }
00720 out << "</displaycalibration>\n";
00721 return true;
00722 }
00723
00744 bool ClusterWindow::loadFilter(std::istream &in)
00745 {
00746 ClusterWindowPtr ptr(this);
00747 DisplayFilterForegroundPtr filterFgnd;
00748 ColorDisplayFilterPtr colorFilter;
00749 DistortionDisplayFilterPtr distortionFilter;
00750 ResolutionDisplayFilterPtr resolutionFilter;
00751 xmlpp::xmlcontextptr ctxptr(new xmlpp::xmlcontext());
00752 xmlpp::xmldocument doc(ctxptr);
00753 xmlpp::xmlnodelist servers;
00754 xmlpp::xmlnodelist colors;
00755 xmlpp::xmlnodelist points;
00756 xmlpp::xmlnodelist::const_iterator sI;
00757 xmlpp::xmlnodelist::const_iterator fI;
00758 xmlpp::xmlnodelist::const_iterator nI;
00759 xmlpp::xmlnodelist::const_iterator cI;
00760 xmlpp::xmlnodelist::const_iterator pI;
00761 xmlpp::xmlstring serverTag("server");
00762 xmlpp::xmlstring colorTag("color");
00763 xmlpp::xmlstring pointTag("point");
00764 xmlpp::xmlnodeptr nP;
00765
00766 beginEditCP(ptr, FilterFieldMask | DirtyFieldMask);
00767 getFilter().clear();
00768 setDirty(true);
00769 endEditCP(ptr, FilterFieldMask | DirtyFieldMask);
00770
00771 try
00772 {
00773 doc.load(in, ctxptr);
00774 servers = doc.select_nodes(serverTag);
00775
00776
00777 for(sI = servers.begin(); sI != servers.end(); ++sI)
00778 {
00779
00780 filterFgnd = DisplayFilterForeground::create();
00781 addRefCP(filterFgnd);
00782
00783 beginEditCP(ptr, FilterFieldMask);
00784 getFilter().push_back(filterFgnd);
00785 endEditCP(ptr, FilterFieldMask);
00786
00787 beginEditCP(filterFgnd);
00788
00789
00790 if((*sI)->get_attrmap().count("name"))
00791 filterFgnd->setServer((*sI)->get_attrmap()["name"]);
00792
00793
00794 for(fI = (*sI)->get_nodelist().begin();
00795 fI != (*sI)->get_nodelist().end(); ++fI)
00796 {
00797 if ((*fI)->get_name() == "colordisplayfilter")
00798 {
00799 colorFilter = ColorDisplayFilter::create();
00800 addRefCP(colorFilter);
00801
00802 filterFgnd->getFilter().push_back(colorFilter);
00803
00804 beginEditCP(colorFilter);
00805
00806
00807 for(nI = (*fI)->get_nodelist().begin();
00808 nI != (*fI)->get_nodelist().end(); ++nI)
00809 {
00810 if((*nI)->get_name() == "colormatrix")
00811 {
00812 nP = (*nI);
00813 do
00814 nP = nP->get_nodelist().front();
00815 while (nP->get_nodelist().size() == 1);
00816
00817 if(nP->get_type() == xmlpp::xml_nt_cdata)
00818 colorFilter->getMatrix().setValue(nP->get_cdata().c_str());
00819 }
00820 if((*nI)->get_name() == "gamma")
00821 {
00822 nP = (*nI);
00823 do
00824 nP = nP->get_nodelist().front();
00825 while (nP->get_nodelist().size() == 1);
00826
00827 if(nP->get_type() == xmlpp::xml_nt_cdata)
00828 sscanf(nP->get_cdata().c_str(),"%f",
00829 &colorFilter->getGamma());
00830 }
00831 if((*nI)->get_name() == "size")
00832 {
00833 nP = (*nI);
00834 do
00835 nP = nP->get_nodelist().front();
00836 while (nP->get_nodelist().size() == 1);
00837
00838 if(nP->get_type() == xmlpp::xml_nt_cdata)
00839 sscanf(nP->get_cdata().c_str(),"%d %d %d",
00840 &colorFilter->getWidth(),
00841 &colorFilter->getHeight(),
00842 &colorFilter->getDepth());
00843 }
00844 if((*nI)->get_name() == "shadingtable")
00845 {
00846 colors = (*nI)->select_nodes(colorTag);
00847
00848 for(cI = colors.begin(); cI != colors.end(); ++cI)
00849 {
00850 nP = (*cI);
00851 do
00852 nP = nP->get_nodelist().front();
00853 while (nP->get_nodelist().size() == 1);
00854
00855 if(nP->get_type() == xmlpp::xml_nt_cdata)
00856 {
00857 Color3f col;
00858 col.setValue(nP->get_cdata().c_str());
00859 colorFilter->getTable().push_back(col);
00860 }
00861 }
00862 }
00863 }
00864 endEditCP(colorFilter);
00865 }
00866
00867 if ((*fI)->get_name() == "resolutiondisplayfilter")
00868 {
00869 resolutionFilter = ResolutionDisplayFilter::create();
00870 addRefCP(resolutionFilter);
00871
00872 filterFgnd->getFilter().push_back(resolutionFilter);
00873
00874 beginEditCP(resolutionFilter);
00875
00876 for(nI = (*fI)->get_nodelist().begin();
00877 nI != (*fI)->get_nodelist().end(); ++nI)
00878 {
00879 if((*nI)->get_name() == "downscale")
00880 {
00881 nP = (*nI);
00882 do
00883 nP = nP->get_nodelist().front();
00884 while (nP->get_nodelist().size() == 1);
00885
00886 if(nP->get_type() == xmlpp::xml_nt_cdata)
00887 sscanf(nP->get_cdata().c_str(),"%f",
00888 &resolutionFilter->getDownScale());
00889 }
00890 }
00891 endEditCP(resolutionFilter);
00892 }
00893
00894 if ((*fI)->get_name() == "distortiondisplayfilter")
00895 {
00896 distortionFilter = DistortionDisplayFilter::create();
00897 addRefCP(distortionFilter);
00898
00899 filterFgnd->getFilter().push_back(distortionFilter);
00900
00901 beginEditCP(distortionFilter);
00902
00903 for(nI = (*fI)->get_nodelist().begin();
00904 nI != (*fI)->get_nodelist().end(); ++nI)
00905 {
00906 if((*nI)->get_name() == "rows")
00907 {
00908 nP = (*nI);
00909 do
00910 nP = nP->get_nodelist().front();
00911 while (nP->get_nodelist().size() == 1);
00912
00913 if(nP->get_type() == xmlpp::xml_nt_cdata)
00914 sscanf(nP->get_cdata().c_str(),"%d",
00915 &distortionFilter->getRows());
00916 }
00917 if((*nI)->get_name() == "cols")
00918 {
00919 nP = (*nI);
00920 do
00921 nP = nP->get_nodelist().front();
00922 while (nP->get_nodelist().size() == 1);
00923
00924 if(nP->get_type() == xmlpp::xml_nt_cdata)
00925 sscanf(nP->get_cdata().c_str(),"%d",
00926 &distortionFilter->getColumns());
00927 }
00928 if((*nI)->get_name() == "positions")
00929 {
00930 points = (*nI)->select_nodes(pointTag);
00931
00932 for(pI = points.begin(); pI != points.end(); ++pI)
00933 {
00934 nP = (*pI);
00935 do
00936 nP = nP->get_nodelist().front();
00937 while (nP->get_nodelist().size() == 1);
00938
00939 if(nP->get_type() == xmlpp::xml_nt_cdata)
00940 {
00941 Vec2f pos;
00942 pos.setValueFromCString(nP->get_cdata().c_str());
00943 distortionFilter->getPositions().push_back(pos);
00944 }
00945 }
00946 }
00947 }
00948 endEditCP(distortionFilter);
00949 }
00950 }
00951
00952 endEditCP(filterFgnd);
00953 }
00954 }
00955 catch (xmlpp::xmlerror e)
00956 {
00957
00958 xmlpp::xmllocation where( ctxptr->get_location() );
00959 xmlpp::xmlstring errmsg( e.get_strerror() );
00960 SFATAL << "XML error line " << where.get_line() << " "
00961 << "at position " << where.get_pos()
00962 << ": error: " << errmsg.c_str()
00963 << std::endl;
00964 return false;
00965 }
00966 return true;
00967 }
00968
00969
00970
00971
00972 ClusterWindow::AsyncCancel::AsyncCancel()
00973 {
00974 }
00975
00976
00977
00978
00983 void ClusterWindow::clientInit( void )
00984 {
00985 }
00986
00994 void ClusterWindow::clientPreSync( void )
00995 {
00996 if(getClientWindow() != NullFC)
00997 {
00998 getClientWindow()->activate();
00999 getClientWindow()->frameInit();
01000 }
01001 }
01002
01010 void ClusterWindow::clientRender(RenderActionBase *action)
01011 {
01012 if(getClientWindow() != NullFC)
01013 {
01014 getClientWindow()->renderAllViewports( action );
01015 }
01016 }
01017
01024 void ClusterWindow::clientSwap( void )
01025 {
01026 if(getClientWindow() != NullFC)
01027 {
01028 getClientWindow()->swap( );
01029 getClientWindow()->frameExit();
01030 }
01031
01032 if (getDirty())
01033 {
01034 ClusterWindowPtr ptr(this);
01035
01036 beginEditCP(ptr, DirtyFieldMask);
01037 setDirty(false);
01038 endEditCP(ptr, DirtyFieldMask);
01039 }
01040 }
01041
01042
01043
01044
01045 bool ClusterWindow::updateFilter(WindowPtr window, UInt32 id,
01046 RenderActionBase *action)
01047 {
01048 bool found = false;
01049
01050 if (!getFilter().empty() && getDirty())
01051 {
01052 UInt32 c, p;
01053
01054 ClusterWindowPtr ptr(this);
01055
01056 beginEditCP(ptr, DirtyFieldMask);
01057 setDirty(false);
01058 endEditCP(ptr, DirtyFieldMask);
01059
01060
01061 for(p=0; p<window->getPort().size(); ++p)
01062 {
01063
01064 for(c=0; c<getFilter().size(); ++c)
01065 {
01066 std::string name = getServers()[id];
01067 char portName[64];
01068
01069 if(window->getPort().size() > 1)
01070 {
01071 sprintf(portName,"[%d]",p);
01072 name = name + portName;
01073 }
01074
01075 DisplayFilterForegroundPtr filterFgnd = getFilter()[c];
01076
01077 if(filterFgnd->getServer() == name)
01078 {
01079 beginEditCP(window->getPort()[p], Viewport::ForegroundsFieldMask);
01080
01081
01082 for (Int32 n=window->getPort()[p]->getForegrounds().size(), j=n-1;
01083 j>=0; j--)
01084 {
01085 MFForegroundPtr::iterator fgndIt =
01086 window->getPort()[p]->getForegrounds().begin() + j;
01087 if ( (*fgndIt) == filterFgnd )
01088 window->getPort()[p]->getForegrounds().erase(fgndIt);
01089 }
01090
01091
01092 window->getPort()[p]->getForegrounds().push_back(filterFgnd);
01093
01094 endEditCP(window->getPort()[p], Viewport::ForegroundsFieldMask);
01095
01096 found = true;
01097 break;
01098 }
01099 }
01100 }
01101 }
01102
01103 return found;
01104 }
01105
01114 void ClusterWindow::serverInit( WindowPtr ,
01115 UInt32 )
01116 {
01117 }
01118
01130 void ClusterWindow::serverRender( WindowPtr window,
01131 UInt32 id,
01132 RenderActionBase *action )
01133 {
01134 updateFilter(window, id, action);
01135
01136 RenderOptionsPtr ro;
01137
01138 window->activate();
01139 window->frameInit();
01140
01141 RenderAction *ract = dynamic_cast<RenderAction *>(action);
01142 if(ract != NULL)
01143 {
01144 MFViewportPtr::iterator portIt = window->getPort().begin();
01145 MFViewportPtr::const_iterator portEnd = window->getPort().end();
01146
01147 OSG::RenderOptionsPtr winRo = OSG::RenderOptionsPtr::dcast(
01148 window->findAttachment(OSG::RenderOptions::getClassType()));
01149 ract->setWindow(window.getCPtr());
01150 while(portIt != portEnd)
01151 {
01152
01153 OSG::RenderOptionsPtr vpRo = OSG::RenderOptionsPtr::dcast(
01154 (*portIt)->findAttachment(OSG::RenderOptions::getClassType()));
01155
01156 OSG::RenderOptionsPtr rootRo = NullFC;
01157 if((*portIt)->getRoot() != NullFC)
01158 {
01159 rootRo = OSG::RenderOptionsPtr::dcast(
01160 (*portIt)->getRoot()->findAttachment(OSG::RenderOptions::getClassType()));
01161 }
01162 if(rootRo != NullFC)
01163 ro = rootRo;
01164 else
01165 if(vpRo != NullFC)
01166 ro = vpRo;
01167 else
01168 ro = winRo;
01169 if(ro != NullFC)
01170 ro->activateOptions(ract);
01171 (*portIt)->render(ract);
01172 ++portIt;
01173 }
01174 } else {
01175 if(action)
01176 window->renderAllViewports(action);
01177 }
01178
01179
01180 DisplayCalibrationPtr calibPtr=NullFC;
01181 UInt32 c, p;
01182
01183
01184 for(p = 0 ; p<window->getPort().size() ; ++p)
01185 {
01186
01187 for(c=0 ; c<getCalibration().size() ; ++c)
01188 {
01189 std::string name = getServers()[id];
01190 char portName[64];
01191 if(window->getPort().size() > 1)
01192 {
01193 sprintf(portName,"[%d]",p);
01194 name = name + portName;
01195 }
01196 if(getCalibration()[c]->getServer() == name)
01197 {
01198 calibPtr = getCalibration()[c];
01199 calibPtr->calibrate(window->getPort()[p],action);
01200 break;
01201 }
01202 }
01203 }
01204 }
01205
01215 void ClusterWindow::serverSwap( WindowPtr window,
01216 UInt32)
01217 {
01218 window->swap();
01219 window->frameExit();
01220 }
01221
01222
01223
01224
01226
01227 ClusterWindow::ClusterWindow(void) :
01228 Inherited(),
01229 _firstFrame(true),
01230 _statistics(NULL),
01231 _connectionFP(NULL),
01232 _network(NULL)
01233 {
01234 }
01235
01237
01238 ClusterWindow::ClusterWindow(const ClusterWindow &source) :
01239 Inherited(source),
01240 _firstFrame(true),
01241 _statistics(NULL),
01242 _connectionFP(source._connectionFP),
01243 _network(NULL)
01244 {
01245 }
01246
01248
01249 ClusterWindow::~ClusterWindow(void)
01250 {
01251 if(_network)
01252 subRefP(_network);
01253 _network=NULL;
01254 }
01255
01256
01257
01258
01261 ClusterNetwork *ClusterWindow::getNetwork(void)
01262 {
01263 if(!_network)
01264 {
01265 ClusterWindowPtr ptr(this);
01266 _network=ClusterNetwork::getInstance(ptr.getFieldContainerId());
01267 addRefP(_network);
01268 }
01269 return _network;
01270 }
01271
01274 void ClusterWindow::initMethod (void)
01275 {
01276 }
01277
01278
01279
01280
01281
01282 #ifdef __sgi
01283 #pragma set woff 1174
01284 #endif
01285
01286 #ifdef OSG_LINUX_ICC
01287 #pragma warning( disable : 177 )
01288 #endif
01289
01290 namespace
01291 {
01292 static char cvsid_cpp[] = "@(#)$Id: $";
01293 static char cvsid_hpp[] = OSGCLUSTERWINDOW_HEADER_CVSID;
01294 static char cvsid_inl[] = OSGCLUSTERWINDOW_INLINE_CVSID;
01295 }