Changeset 69
- Timestamp:
- Jul 20, 2010, 10:44:13 AM (14 years ago)
- Location:
- osgVisual
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/bin/visual_master.bat
r26 r69 1 osgVisual.exe -C center -m --window 100 100 800 600 -m D:\OpenSceneGraph\VPB-Testdatensatz\DB_Small\database.ive -p salzburg.path1 osgVisual.exe -C center -m --window 950 50 600 350 D:/OpenSceneGraph/VPB-Testdatensatz/DB_Small/database.ive -p salzburg.path -
osgVisual/bin/visual_slave.bat
r26 r69 1 osgVisual.exe -C center -s -- window 100 100 800 600 -m D:\OpenSceneGraph\VPB-Testdatensatz\DB_Small\database.ive -p salzburg.path1 osgVisual.exe -C center -s --server localhost 12345 --window 950 450 600 350 D:/OpenSceneGraph/VPB-Testdatensatz/DB_Small/database.ive -p salzburg.path -
osgVisual/include/cluster/dataIO_cluster.h
r67 r69 16 16 */ 17 17 18 #include "osg/referenced" 18 #include <osg/referenced> 19 #include <osgViewer/Viewer> 19 20 20 21 #include "dataIO_slot.h" … … 59 60 * 60 61 */ 61 virtual void init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ) = 0;62 virtual void init( osg::ArgumentParser& arguments_, osgViewer::Viewer* viewer_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ) = 0; 62 63 64 void enableHardSync(bool hardSync_){hardSync=hardSync_;}; 65 66 bool isHardSyncEnabled(){return hardSync;}; 63 67 64 68 virtual void shutdown() = 0; … … 117 121 118 122 protected: 119 osgVisual::dataIO_cluster::clustermode clusterMode; // This variable only mirrors the variable of dataIO. will be set during initialize.123 osgVisual::dataIO_cluster::clustermode clusterMode; // This variable only mirrors the variable of dataIO. will be set during initialize. 120 124 bool initialized; 121 125 int port; 126 bool hardSync; 122 127 123 osg::ref_ptr<osgVisual::dataIO_transportContainer> sendContainer; 128 /** 129 * Referenced Pointer to the applications viewer. 130 */ 131 osg::ref_ptr<osgViewer::Viewer> viewer; 132 133 osg::ref_ptr<osgVisual::dataIO_transportContainer> sendContainer; // Points to the send container of dataIO. 134 std::string receivedTransportContainer; 124 135 }; 125 136 -
osgVisual/include/cluster/dataIO_clusterENet.h
r67 r69 18 18 #include <osg/notify> 19 19 #include <osg/ArgumentParser> 20 #include <osgDB/Registry> 21 #include <osgDB/ReaderWriter> 22 #include <iostream> 20 23 21 24 #include <dataIO_cluster.h> … … 39 42 virtual ~dataIO_clusterENet(void); 40 43 41 void init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ );44 void init( osg::ArgumentParser& arguments_, osgViewer::Viewer* viewer_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ); 42 45 void shutdown(); 43 46 … … 54 57 std::string serverToConnect; 55 58 osgVisual::dataIO_cluster::clustermode clusterMode; 59 std::string receivedTransportContainer; 60 61 osg::ref_ptr<osgDB::Options> readOptions; 62 osg::ref_ptr<osgDB::Options> writeOptions; 63 osg::ref_ptr<osgDB::ReaderWriter> rw; 56 64 }; 57 65 -
osgVisual/include/cluster/dataIO_clusterENet_implementation.h
r68 r69 29 29 { 30 30 public: 31 dataIO_clusterENet_implementation( );31 dataIO_clusterENet_implementation(std::string& receivedTransportContainer_); 32 32 ~dataIO_clusterENet_implementation(); 33 33 … … 54 54 std::vector<ENetPeer*> peerList; // client: only one peer to server, Server: multiple peers for all clients 55 55 ENetEvent event; 56 std::string& receivedTransportContainer; 56 57 }; 57 58 -
osgVisual/src/cluster/dataIO_clusterENet.cpp
r67 r69 23 23 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet constructed" << std::endl; 24 24 serverToConnect = "unknown"; 25 hardSync = false; // integrate into init() 26 port = 12345; // integrate into init() 25 27 } 26 28 … … 32 34 33 35 34 void dataIO_clusterENet::init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ )36 void dataIO_clusterENet::init( osg::ArgumentParser& arguments_, osgViewer::Viewer* viewer_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ) 35 37 { 36 38 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet init();" << std::endl; 37 39 40 // Store viewer 41 viewer = viewer_; 42 38 43 // Configure the clustermode 39 44 clusterMode = clusterMode_; … … 41 46 // store sendContainer 42 47 sendContainer = sendContainer_; 48 49 // Configure Compression and instantiate read/write-options 50 std::string readOptionString = ""; 51 std::string writeOptionString = ""; 52 if(asAscii_) 53 { 54 readOptionString = "Ascii"; 55 writeOptionString = "Ascii"; 56 } 57 if (compressionEnabled_) 58 writeOptionString+=" Compressor=zlib"; 59 readOptions = new osgDB::Options( readOptionString.c_str() ); 60 writeOptions = new osgDB::Options( writeOptionString.c_str() ); 61 62 // Get ReaderWriter 63 rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgb"); 43 64 44 65 // create ENet implementation object. 45 enet_impl = new osgVisual::dataIO_clusterENet_implementation( );66 enet_impl = new osgVisual::dataIO_clusterENet_implementation(receivedTransportContainer); 46 67 47 68 // initialize ENet implementation 48 69 if(clusterMode == MASTER) 49 70 { 71 std::cout << "Init dataIO_cluster_ENet as Server on port " << port << std::endl; 50 72 enet_impl->init(dataIO_clusterENet_implementation::SERVER, port); 51 73 … … 81 103 { 82 104 initialized = false; 83 std::cout << "Failed to establish connection to server " << serverToConnect << std::endl; 105 std::cout << "Finally failed to establish connection to server " << serverToConnect << std::endl; 106 exit(-1); 84 107 } 85 108 } // IF SLAVE END … … 95 118 bool dataIO_clusterENet::sendTO_OBJvaluesToSlaves() 96 119 { 97 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet sendTO_OBJvaluesToSlaves()" << std::endl; 98 120 //OSG_NOTIFY( osg::ALWAYS ) << "clusterENet sendTO_OBJvaluesToSlaves()" << std::endl; 121 122 if(sendContainer.valid()) 123 { 124 // Pack FrameID & Viewmatrix 125 sendContainer->setFrameID(viewer->getFrameStamp()->getFrameNumber()); 126 sendContainer->setViewMatrix(viewer->getCamera()->getViewMatrix()); 127 128 // Writing node to stream 129 std::stringstream myOstream; 130 if ( rw ) 131 { 132 osgDB::ReaderWriter::WriteResult wr = rw->writeObject( *sendContainer.get(), myOstream, writeOptions ); 133 if (wr.success() ) 134 { 135 // Send Data via ENet: 136 OSG_NOTIFY( osg::ALWAYS ) << "dataIO_clusterUDP::sendTO_OBJvaluesToSlaves() - Bytes to send: " << myOstream.str().length() << std::endl; 137 //sOSG_NOTIFY( osg::ALWAYS ) << "Send: " << myOstream.str() << std::endl; 138 ENetPacket * packet = enet_packet_create (myOstream.str().c_str(), 139 myOstream.str().size(), 140 ENET_PACKET_FLAG_RELIABLE); 141 142 // Send data 143 enet_impl->sendPacket( packet, 0, 0, true); 144 } 145 else OSG_NOTIFY( osg::WARN ) << "ERROR: dataIO_clusterENet::sendTO_OBJvaluesToSlaves() :: Save failed: " << wr.message() << std::endl; 146 } 147 else OSG_NOTIFY( osg::WARN ) << "ERROR: dataIO_clusterENet::sendTO_OBJvaluesToSlaves() :: Unable to get readerWriter for osgb" << std::endl; 148 } 149 else OSG_NOTIFY( osg::WARN ) << "ERROR: dataIO_clusterENet::sendTO_OBJvaluesToSlaves() :: Invalid transportContainer" << std::endl; 150 151 152 enet_impl->processEvents(); // As Master: process events AFTER doing anything to have up to have the "sent" commands in queue. 99 153 return true; 100 154 } … … 103 157 bool dataIO_clusterENet::readTO_OBJvaluesFromMaster() 104 158 { 105 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet readTO_OBJvaluesFromMaster()" << std::endl; 159 //OSG_NOTIFY( osg::ALWAYS ) << "clusterENet readTO_OBJvaluesFromMaster()" << std::endl; 160 enet_impl->processEvents(); // As Slave: process events BEFORE doing anything to have up to date values. 161 162 int bytes_received = receivedTransportContainer.size(); 163 if (bytes_received > 0 ) 164 { 165 OSG_NOTIFY( osg::ALWAYS ) << "dataIO_clusterENet::readTO_OBJvaluesFromMaster() - Bytes received: " << bytes_received << std::endl; 166 //OSG_NOTIFY( osg::ALWAYS ) << "Received: " << std::endl << receivedTransportContainer << std::endl; 167 168 // Unserialize data 169 if ( rw ) 170 { 171 std::stringstream test; 172 test << receivedTransportContainer; 173 osgDB::ReaderWriter::ReadResult rr = rw->readObject( test, readOptions ); 174 if (rr.success()) 175 { 176 sendContainer = dynamic_cast<osgVisual::dataIO_transportContainer*>(rr.takeObject()); 177 if (sendContainer) 178 { 179 OSG_NOTIFY( osg::ALWAYS ) << "Received::FrameID is: " << sendContainer->getFrameID() << std::endl; 180 // Restore Viewmatrix 181 viewer->getCamera()->setViewMatrix(sendContainer->getViewMatrix()); 182 } 183 else 184 OSG_NOTIFY( osg::WARN ) << "ERROR: dataIO_clusterENet::readTO_OBJvaluesFromMaster() - Unable to cast converted node to transportContainer" << std::endl; 185 } 186 else 187 OSG_NOTIFY( osg::WARN ) << "ERROR: dataIO_clusterENet::readTO_OBJvaluesFromMaster() - Unable to convert stream to node" << std::endl; 188 } 189 else 190 OSG_NOTIFY( osg::WARN ) << "ERROR: dataIO_clusterENet::readTO_OBJvaluesFromMaster() - Unable to get readerWriter for osgb" << std::endl; 191 } // IF bytes recv > 0 END 192 193 106 194 107 195 return true; … … 111 199 void dataIO_clusterENet::reportAsReadyToSwap() 112 200 { 201 if(!hardSync) 202 return; 203 113 204 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet reportAsReadyToSwap()" << std::endl; 114 205 } … … 116 207 bool dataIO_clusterENet::waitForSwap() 117 208 { 209 if(!hardSync) 210 return true; 211 118 212 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet waitForSwap()" << std::endl; 119 213 … … 124 218 bool dataIO_clusterENet::waitForAllReadyToSwap() 125 219 { 220 if(!hardSync) 221 return true; 222 126 223 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet waitForAllReadyToSwap()" << std::endl; 127 224 … … 132 229 bool dataIO_clusterENet::sendSwapCommand() 133 230 { 231 if(!hardSync) 232 return true; 233 134 234 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet sendSwapCommand()" << std::endl; 135 235 -
osgVisual/src/cluster/dataIO_clusterENet_implementation.cpp
r68 r69 21 21 int dataIO_clusterENet_implementation::activeENetInstances = 0; 22 22 23 dataIO_clusterENet_implementation::dataIO_clusterENet_implementation() 23 dataIO_clusterENet_implementation::dataIO_clusterENet_implementation(std::string& receivedTransportContainer_) 24 : receivedTransportContainer(receivedTransportContainer_) 24 25 { 25 26 std::cout << "Instantiated server class# "<< activeENetInstances << std::endl; … … 142 143 if( peerList.size() == 0 ) 143 144 { 144 std::cout << "dataIO_clusterENet_implementation::sendPacket() - ERROR: No connected peer available!" << std::endl;145 //std::cout << "dataIO_clusterENet_implementation::sendPacket() - ERROR: No connected peer available!" << std::endl; 145 146 return; 146 147 } … … 215 216 { 216 217 if(currentRole != dataIO_clusterENet_implementation::CLIENT) 218 { 219 std::cout << "dataIO_clusterENet_implementation::connectTo() : ERROR: ENet does not work as client - ignoring to connect!" << std::endl; 217 220 return false; 221 } 218 222 219 223 ENetAddress address; … … 257 261 void dataIO_clusterENet_implementation::onReceivePacket(ENetEvent* event_) 258 262 { 259 std::string datastring; 260 datastring.assign((char*)(event_->packet->data), event_->packet->dataLength); 261 std::cout << "A packet of length "<<event_->packet->dataLength<<" containing "<<datastring<<" was received from "<<datastring<<" on channel "<<(int)(event_->channelID)<<std::endl; 262 datastring+=std::string("answer"); 263 264 ENetPacket * packet = enet_packet_create (datastring.c_str(), 265 datastring.size(), 266 ENET_PACKET_FLAG_RELIABLE); 267 268 // Send answer 269 sendPacket( packet, 0, 0, true); 263 receivedTransportContainer.assign((char*)(event_->packet->data), event_->packet->dataLength); 264 //std::cout << "A packet of length "<<event_->packet->dataLength<<" containing "<<receivedTransportContainer<<" was received from "<<receivedTransportContainer<<" on channel "<<(int)(event_->channelID)<<std::endl; 270 265 } 271 266 -
osgVisual/src/cluster/dataIO_clusterUDP.cpp
r59 r69 128 128 else 129 129 OSG_NOTIFY( osg::WARN ) << "ERROR: dataIO_clusterUDP::readTO_OBJvaluesFromMaster() - Unable to get readerWriter for osgb" << std::endl; 130 } 130 } // IF bytes recv >0 131 131 132 132 -
osgVisual/src/core/visual_core.cpp
r68 r69 362 362 //test->init( rootNode, viewer ); 363 363 364 // Creating Testclasses 365 osg::ref_ptr<osgVisual::dataIO_transportContainer> test = new osgVisual::dataIO_transportContainer(); 366 osg::ref_ptr<osgVisual::dataIO_executer> testEx = new osgVisual::dataIO_executer(); 367 osg::ref_ptr<osgVisual::dataIO_slot> testSlot = new osgVisual::dataIO_slot(); 368 test->setFrameID( 22 ); 369 test->setName("ugamoep"); 370 testEx->setexecuterID( osgVisual::dataIO_executer::IS_COLLISION ); 371 testSlot->setVariableName(std::string("HalloName")); 372 testSlot->setdataDirection( osgVisual::dataIO_slot::TO_OBJ ); 373 testSlot->setvarType( osgVisual::dataIO_slot::DOUBLE ); 374 testSlot->setValue( 0.12345 ); 375 test->addExecuter( testEx ); 376 test->addSlot( testSlot ); 377 378 // Writing object to stream 379 //std::ofstream myOstream("test.txt" ); 380 std::stringstream myOstream; 381 std::string extension = "osgb"; 382 bool compressed = false; 383 osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(extension.c_str()); 384 if ( rw ) 385 { 386 osgDB::ReaderWriter::WriteResult wr; 387 388 if (extension == "osgb") 389 { 390 if (compressed) 391 wr = rw->writeObject( *test, myOstream, new osgDB::Options("Compressor=zlib") ); 392 else 393 wr = rw->writeObject( *test, myOstream ); 394 } 395 396 if (extension == "osgt") 397 { 398 if (compressed) 399 wr = rw->writeObject( *test, myOstream, new osgDB::Options("Ascii Compressor=zlib") ); 400 else 401 wr = rw->writeObject( *test, myOstream, new osgDB::Options("Ascii") ); 402 } 403 404 if (extension == "osgx") 405 { 406 if (compressed) 407 wr = rw->writeObject( *test, myOstream, new osgDB::Options("XML Compressor=zlib") ); 408 else 409 wr = rw->writeObject( *test, myOstream, new osgDB::Options("XML") ); 410 } 411 412 413 if (!wr.success() ) OSG_NOTIFY( osg::WARN ) << "ERROR: Save failed: " << wr.message() << std::endl; 414 } 415 else 416 OSG_NOTIFY( osg::WARN ) << "error getting readerWriter for osgt" << std::endl; 417 418 // Size ermitteln. 419 std::stringbuf *pbuf; 420 pbuf = myOstream.rdbuf(); 421 OSG_NOTIFY( osg::WARN ) << "PBUF Bytes available: " << pbuf->in_avail() << std::endl; 422 OSG_NOTIFY( osg::ALWAYS ) << "STRING Bytes available: " << myOstream.str().length() << std::endl; 423 OSG_NOTIFY( osg::ALWAYS ) << "STRING content: " << myOstream.str() << std::endl; 424 425 //Reading Stream to node 426 if ( rw ) 427 { 428 osgDB::ReaderWriter::ReadResult rr = rw->readObject( myOstream ); 429 osg::ref_ptr<osgVisual::dataIO_transportContainer> test2 = dynamic_cast<osgVisual::dataIO_transportContainer*>(rr.takeObject()); 430 if (test2) 431 { 432 OSG_NOTIFY( osg::WARN ) << "TEST::FrameID is: " << test->getFrameID() << std::endl; 433 } 434 else 435 OSG_NOTIFY( osg::WARN ) << "Error converting stream to Node" << std::endl; 436 } 437 } 364 //// Creating Testclasses 365 //osg::ref_ptr<osgVisual::dataIO_transportContainer> test = new osgVisual::dataIO_transportContainer(); 366 //osg::ref_ptr<osgVisual::dataIO_executer> testEx = new osgVisual::dataIO_executer(); 367 //osg::ref_ptr<osgVisual::dataIO_slot> testSlot = new osgVisual::dataIO_slot(); 368 //test->setFrameID( 22 ); 369 //test->setName("ugamoep"); 370 //testEx->setexecuterID( osgVisual::dataIO_executer::IS_COLLISION ); 371 //testSlot->setVariableName(std::string("HalloName")); 372 //testSlot->setdataDirection( osgVisual::dataIO_slot::TO_OBJ ); 373 //testSlot->setvarType( osgVisual::dataIO_slot::DOUBLE ); 374 //testSlot->setValue( 0.12345 ); 375 //test->addExecuter( testEx ); 376 //test->addSlot( testSlot ); 377 378 visual_dataIO::getInstance()->setSlotData("TestSlot1", osgVisual::dataIO_slot::TO_OBJ, 0.12345); 379 380 381 //// Writing object to stream 382 ////std::ofstream myOstream("test.txt" ); 383 //std::stringstream myOstream; 384 //std::string extension = "osgb"; 385 //bool compressed = false; 386 //osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(extension.c_str()); 387 //if ( rw ) 388 //{ 389 // osgDB::ReaderWriter::WriteResult wr; 390 391 // if (extension == "osgb") 392 // { 393 // if (compressed) 394 // wr = rw->writeObject( *test, myOstream, new osgDB::Options("Compressor=zlib") ); 395 // else 396 // wr = rw->writeObject( *test, myOstream ); 397 // } 398 399 // if (extension == "osgt") 400 // { 401 // if (compressed) 402 // wr = rw->writeObject( *test, myOstream, new osgDB::Options("Ascii Compressor=zlib") ); 403 // else 404 // wr = rw->writeObject( *test, myOstream, new osgDB::Options("Ascii") ); 405 // } 406 407 // if (extension == "osgx") 408 // { 409 // if (compressed) 410 // wr = rw->writeObject( *test, myOstream, new osgDB::Options("XML Compressor=zlib") ); 411 // else 412 // wr = rw->writeObject( *test, myOstream, new osgDB::Options("XML") ); 413 // } 414 415 416 // if (!wr.success() ) OSG_NOTIFY( osg::WARN ) << "ERROR: Save failed: " << wr.message() << std::endl; 417 //} 418 //else 419 // OSG_NOTIFY( osg::WARN ) << "error getting readerWriter for osgt" << std::endl; 420 421 //// Size ermitteln. 422 //std::stringbuf *pbuf; 423 //pbuf = myOstream.rdbuf(); 424 //OSG_NOTIFY( osg::WARN ) << "PBUF Bytes available: " << pbuf->in_avail() << std::endl; 425 //OSG_NOTIFY( osg::ALWAYS ) << "STRING Bytes available: " << myOstream.str().length() << std::endl; 426 //OSG_NOTIFY( osg::ALWAYS ) << "STRING content: " << myOstream.str() << std::endl; 427 428 ////Reading Stream to node 429 //if ( rw ) 430 //{ 431 // osgDB::ReaderWriter::ReadResult rr = rw->readObject( myOstream ); 432 // osg::ref_ptr<osgVisual::dataIO_transportContainer> test2 = dynamic_cast<osgVisual::dataIO_transportContainer*>(rr.takeObject()); 433 // if (test2) 434 // { 435 // OSG_NOTIFY( osg::WARN ) << "TEST::FrameID is: " << test->getFrameID() << std::endl; 436 // } 437 // else 438 // OSG_NOTIFY( osg::WARN ) << "Error converting stream to Node" << std::endl; 439 //} 440 } -
osgVisual/src/dataIO/visual_dataIO.cpp
r67 r69 78 78 #ifdef USE_CLUSTER_ENET 79 79 cluster = new dataIO_clusterENet(); 80 cluster->enableHardSync( false ); /** \todo : rebuild this structure in cluster.h and move it this way to a general implementation. */ 80 81 #endif 81 82 if(cluster.valid()) 82 cluster->init(arguments_, clusterMode, slotContainer, true, false); 83 //cluster->init(arguments_, clusterMode, slotContainer, true, false); 84 cluster->init(arguments_, viewer_, clusterMode, slotContainer, false, true); 83 85 84 86 // Create extLink.
Note: See TracChangeset
for help on using the changeset viewer.