// ----------------------------------------------- Main -------------------------------------------- int main(int argc, char **argv){ Graph G; char filename[BUFFSIZE]; int source, destination; double elapsed_time; clock_t start, end; // Parsing arguments switch(argc){ case(4): if((sscanf(argv[2], "%d", &source) != 1) || (sscanf(argv[3], "%d", &destination) != 1)){ printf("Inputs must be integers.\n"); exit(1); } case(3): VERBOSE = 1; case(2): sscanf(argv[1], "%s", filename); break; default: printf("Wrong number of arguments.\n"); exit(1); } // Reading Graph G = readGraph(filename); // Printing graphs information printf("-------------------------------------------------------\n"); printf("There are %d nodes and %d edges!\n", G->V, G->E); printf("There are %d nodes and %d edges on the 'residual' network!\n", 2*G->V, 4*G->E + 2*G->V); printf("-------------------------------------------------------\n"); // If there is a defined pair of nodes only compute its path if(argc == 4){ if(EdmondsKarp(G, source, destination + NETSIZE)) findNodes(G, source, destination); // Else, compute all of them }else{ start = clock(); for(source = 0; source < NETSIZE; source++) for(destination = source + 1; destination < NETSIZE; destination++) if(source != destination) if(EdmondsKarp(G, source, destination + NETSIZE)) findNodes(G, source, destination); end = clock(); elapsed_time = (double)(end - start)/CLOCKS_PER_SEC; printResult(G); printf("Algorithm takes %f seconds\n", elapsed_time); printf("-------------------------------------------------------\n"); } // Free Memory allocated previously memoryCheck(G); exit(0); }
/** * FUNCTION NAME: clientCreate * * DESCRIPTION: client side CREATE API * The function does the following: * 1) Constructs the message * 2) Finds the replicas of this key * 3) Sends a message to the replica */ void MP2Node::clientCreate(string key, string value) { /* * Implement this */ /* * Hash the key and modulo by number of members in the ring * Find the Node where that key should be present * Also, replicate that key on the next 2 neighbors * Message all those nodes to save this key */ // find the destination 3 nodes where this key needs to go vector<Node> destination_nodes = findNodes(key); // print the location of nodes just for debugging for(int i = 0; i < destination_nodes.size(); i++){ cout << "Key = " << key << " Replica = "; printAddress(destination_nodes[i].getAddress()); cout << endl; } // Create a create message with key and value and replica type and send each replica create message according to its type Message *msg; ReplicaType type; for (int i = 0; i < RF; i++){ // Loop over each replica type = static_cast<ReplicaType>(i); // convert int type into enum ReplicaType msg = new Message(this->transaction_id, getMemberNode()->addr, CREATE, key, value, type); //create a create type message emulNet->ENsend(&getMemberNode()->addr, destination_nodes[i].getAddress(), msg->toString()); free(msg); // free message } // Increment this node transaction_id and set other transaction details like key, value and MessageType initTransactionCount(this->transaction_id++, key, value, CREATE); }
void findAll(const Path& path, const dom::NodePtr node, NodeList& result) { const detail::LocationStepList& steps = path.getStepList().steps; detail::Context context(node.get()); result.clear(); detail::NodePtrVec temp; findNodes(context,steps.begin(),steps.end(),temp,false); for( detail::NodePtrVec::const_iterator it=temp.begin(); it!=temp.end(); ++it ) { result.push_back( (*it)->self().lock() ); } }
XcodeMl::NnsTable expandNnsTable(const XcodeMl::NnsTable &table, xmlNodePtr nnsTableNode, xmlXPathContextPtr ctxt) { auto newTable = table; const auto definitions = findNodes(nnsTableNode, "*", ctxt); for (auto &&definition : definitions) { XcodeMLNNSAnalyzer.walk(definition, ctxt, newTable); } return newTable; }
void find(const Path& path, const dom::NodePtr node, dom::NodePtr& result) { const detail::LocationStepList& steps = path.getStepList().steps; detail::Context context(node.get()); detail::NodePtrVec temp; findNodes(context,steps.begin(),steps.end(),temp,true); if( !temp.empty() ) { result = temp.front()->self().lock(); } else { result = dom::NodePtr(); } }
XcodeMl::NnsTable analyzeNnsTable(xmlNodePtr nnsTable, xmlXPathContextPtr ctxt) { if (nnsTable == nullptr) { return initialNnsTable; } XcodeMl::NnsTable map = initialNnsTable; auto nnsNodes = findNodes(nnsTable, "*", ctxt); for (auto &&nnsNode : nnsNodes) { XcodeMLNNSAnalyzer.walk(nnsNode, ctxt, map); } return map; }
/** * FUNCTION NAME: clientDelete * * DESCRIPTION: client side DELETE API * The function does the following: * 1) Constructs the message * 2) Finds the replicas of this key * 3) Sends a message to the replica */ void MP2Node::clientDelete(string key){ /* * Implement this */ Message msg = Message(g_transID, memberNode->addr, DELETE, key); buff.push_back(Transaction(g_transID, DELETE, key)); g_transID += 1; vector<Node> replica = findNodes(key); for (vector<Node>::iterator it = replica.begin(); it != replica.end(); ++it) { emulNet->ENsend(&memberNode->addr, &it->nodeAddress, msg.toString()); } return; }
void NearestNodeLocator::reinit() { // Reset all data delete _slave_node_range; _slave_node_range = NULL; _nearest_node_info.clear(); _first = true; _slave_nodes.clear(); _neighbor_nodes.clear(); // Redo the search findNodes(); }
//----------------------------------------------------------------------------- //! Scans the assimp scene graph structure and populates nameToNode void SLAssimpImporter::findNodes(aiNode* node, SLstring padding, SLbool lastChild) { SLstring name = node->mName.C_Str(); /* /// @todo we can't allow for duplicate node names, ever at the moment. The 'solution' below /// only hides the problem and moves it to a different part. // rename duplicate node names SLstring renamedString; if (_nodeMap.find(name) != _nodeMap.end()) { SLint index = 0; std::ostringstream ss; SLstring lastMatch = name; while (_nodeMap.find(lastMatch) != _nodeMap.end()) { ss.str(SLstring()); ss.clear(); ss << name << "_" << std::setw( 2 ) << std::setfill( '0' ) << index; lastMatch = ss.str(); index++; } ss.str(SLstring()); ss.clear(); ss << "(renamed from '" << name << "')"; renamedString = ss.str(); name = lastMatch; }*/ // this should not happen assert(_nodeMap.find(name) == _nodeMap.end() && "Duplicated node name found!"); _nodeMap[name] = node; //logMessage(LV_Detailed, "%s |\n", padding.c_str()); logMessage(LV_detailed, "%s |-[%s] (%d children, %d meshes)\n", padding.c_str(), name.c_str(), node->mNumChildren, node->mNumMeshes); if (lastChild) padding += " "; else padding += " |"; for (SLuint i = 0; i < node->mNumChildren; i++) { findNodes(node->mChildren[i], padding, (i == node->mNumChildren-1)); } }
void MainWindow::initialFindDock () { findDock = new QDockWidget( tr( "Find"), this ); findWidget = new XMLerFindWidget( findDock ); findDock->setWidget ( findWidget ); findDock->setAllowedAreas ( Qt::BottomDockWidgetArea ); findDock->setFeatures ( QDockWidget::AllDockWidgetFeatures ); addDockWidget( Qt::BottomDockWidgetArea, findDock ); findDock->hide(); /* signals from finder to findDock */ connect ( model->finder(), SIGNAL(done()), this, SLOT(foundedNodes()) ); connect ( findWidget, SIGNAL(FindNodes(QString)), model, SLOT(findNodes(QString)) ); connect ( findWidget, SIGNAL(Show(BaseXMLNode*)), this, SLOT(showFounded(BaseXMLNode*))); }
/** * FUNCTION NAME: clientCreate * * DESCRIPTION: client side CREATE API * The function does the following: * 1) Constructs the message * 2) Finds the replicas of this key * 3) Sends a message to the replica */ void MP2Node::clientCreate(string key, string value) { /* * Implement this */ Message msg_0 = Message(g_transID, memberNode->addr, CREATE, key, value, PRIMARY); Message msg_1 = Message(g_transID, memberNode->addr, CREATE, key, value, SECONDARY); Message msg_2 = Message(g_transID, memberNode->addr, CREATE, key, value, TERTIARY); buff.push_back(Transaction(g_transID, CREATE, key, value)); g_transID += 1; vector<Node> replica = findNodes(key); //printAddress(&replica.at(0).nodeAddress); //printAddress(&replica.at(1).nodeAddress); //printAddress(&replica.at(2).nodeAddress); emulNet->ENsend(&memberNode->addr, &replica.at(0).nodeAddress, msg_0.toString()); emulNet->ENsend(&memberNode->addr, &replica.at(1).nodeAddress, msg_1.toString()); emulNet->ENsend(&memberNode->addr, &replica.at(2).nodeAddress, msg_2.toString()); return; }
/** * FUNCTION NAME: clientDelete * * DESCRIPTION: client side DELETE API * The function does the following: * 1) Constructs the message * 2) Finds the replicas of this key * 3) Sends a message to the replica */ void MP2Node::clientDelete(string key){ /* * Implement this */ //find the destination 3 nodes where this key needs to go vector<Node> destination_nodes = findNodes(key); // Create a delete message with key and send each replica this message Message *msg; for (int i = 0; i < RF; i++){ msg = new Message(this->transaction_id, getMemberNode()->addr, DELETE, key); emulNet->ENsend(&getMemberNode()->addr, destination_nodes[i].getAddress(), msg->toString()); free(msg); } // Increment this node transaction_id and set other transaction details like key, value and MessageType initTransactionCount(this->transaction_id++, key, "", DELETE); }
/** * FUNCTION NAME: clientUpdate * * DESCRIPTION: client side UPDATE API * The function does the following: * 1) Constructs the message * 2) Finds the replicas of this key * 3) Sends a message to the replica */ void MP2Node::clientUpdate(string key, string value){ /* * Implement this */ //find the destination 3 nodes where this key needs to go vector<Node> destination_nodes = findNodes(key); // Create a update message with key and value and send each replica this message according to their type Message *msg; ReplicaType type; for (int i = 0; i < RF; i++){ type = static_cast<ReplicaType>(i); msg = new Message(this->transaction_id, getMemberNode()->addr, UPDATE, key, value, type); emulNet->ENsend(&getMemberNode()->addr, destination_nodes[i].getAddress(), msg->toString()); free(msg); } // Increment this node transaction_id and set other transaction details like key, value and MessageType initTransactionCount(this->transaction_id++, key, value, UPDATE); }
int SceneManager::findNodes( SceneNode *startNode, const string &name, int type ) { int count = 0; if( type == SceneNodeTypes::Undefined || startNode->_type == type ) { if( name == "" || startNode->_name == name ) { _findResults.push_back( startNode ); ++count; } } for( uint32 i = 0; i < startNode->_children.size(); ++i ) { count += findNodes( startNode->_children[i], name, type ); } return count; }
//----------------------------------------------------------------------------- //! Populates nameToNode, nameToBone, jointGroups, skinnedMeshes void SLAssimpImporter::performInitialScan(const aiScene* scene) { // populate the _nameToNode map and print the assimp structure on detailed log verbosity. logMessage(LV_detailed, "[Assimp scene]\n"); logMessage(LV_detailed, " Cameras: %d\n", scene->mNumCameras); logMessage(LV_detailed, " Lights: %d\n", scene->mNumLights); logMessage(LV_detailed, " Meshes: %d\n", scene->mNumMeshes); logMessage(LV_detailed, " Materials: %d\n", scene->mNumMaterials); logMessage(LV_detailed, " Textures: %d\n", scene->mNumTextures); logMessage(LV_detailed, " Animations: %d\n", scene->mNumAnimations); logMessage(LV_detailed, "---------------------------------------------\n"); logMessage(LV_detailed, " Node node tree: \n"); findNodes(scene->mRootNode, " ", true); logMessage(LV_detailed, "---------------------------------------------\n"); logMessage(LV_detailed, " Searching for skinned meshes and scanning joint names.\n"); findJoints(scene); findSkeletonRoot(); }
unsigned char nav_zones(unsigned char key) { int i; if(!zdispcfg.showCurSelection) { switch (key) { case ESC: if (active.menu != &root_menu) active = *(--mstack_ptr); // POP_MENU; return MNU_CLR_ALL; case UP: if(zdispcfg.curSelIdx) { if(zdispcfg.curSelIdx == zdispcfg.upperZone2Disp) zdispcfg.upperZone2Disp--; zdispcfg.curSelIdx--; } else { zdispcfg.curSelIdx = strgGetZonesNum() - 1; zdispcfg.upperZone2Disp = (zdispcfg.curSelIdx > 4) ? zdispcfg.curSelIdx - 5 : 0; } return MNU_UPDATE; case DOWN: if(++zdispcfg.curSelIdx >= strgGetZonesNum()) { zdispcfg.curSelIdx = 0; zdispcfg.upperZone2Disp = 0; } else if((zdispcfg.curSelIdx - zdispcfg.upperZone2Disp) > 4) zdispcfg.upperZone2Disp = zdispcfg.curSelIdx; return MNU_UPDATE; case ENTER: zdispcfg.showCurSelection = 1; zdispcfg.selectedNodeIdx = 0; findNodes(zdispcfg.curSelIdx); i = /*zdispcfg.upperZone2Disp +*/ zdispcfg.curSelIdx; // zdispcfg.prevStatYesMsg = *(char **)(yes_itemEx.data); // *(char **)(yes_itemEx.data) = zoneState(i, ZONE_STATE_ON) ? SetZone_Msg : ClrZone_Msg; zdispcfg.prevStatYesMsg = set_statusbar_usrtext(&yes_itemEx, zoneState(i, ZONE_STATE_ON) ? ClrZone_Msg : SetZone_Msg); return MNU_CLR_ALL; default: break; } } else { switch (key) { case ESC: zdispcfg.showCurSelection = 0; *(char **)(yes_itemEx.data) = zdispcfg.prevStatYesMsg; return MNU_CLR_ALL; case UP: menu_dec_node_cnt(); return MNU_UPDATE; case DOWN: menu_inc_node_cnt(); return MNU_UPDATE; case ENTER: i = /*ispcfg.upperZone2Disp +*/ zdispcfg.curSelIdx; // zoneSet(i, zoneState(i, ZONE_STATE_ON) ? ZONE_STATE_ON : ~ZONE_STATE_ON, ZONE_STATE_ON); if(zoneState(i, ZONE_STATE_ON)) { zoneSet(i, ~ZONE_STATE_ON, ZONE_STATE_ON); set_statusbar_usrtext(&yes_itemEx, SetZone_Msg); } else { zoneSet(i, ZONE_STATE_ON, ZONE_STATE_ON); set_statusbar_usrtext(&yes_itemEx, ClrZone_Msg); } compileSysState(); // if(IS_ZONE_ON(zone_state[i])) // ZONE_STATE return MNU_UPDATE; default: break; } } return 0; }
int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is a utility for converting between various input and output databases formats."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); //arguments.getApplicationUsage()->addCommandLineOption("--formats","List supported file formats"); //arguments.getApplicationUsage()->addCommandLineOption("--plugins","List database olugins"); // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { osg::setNotifyLevel(osg::NOTICE); usage( arguments.getApplicationName().c_str(), 0 ); //arguments.getApplicationUsage()->write(std::cout); return 1; } if (arguments.read("--help-env")) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE); return 1; } if (arguments.read("--plugins")) { osgDB::FileNameList plugins = osgDB::listAllAvailablePlugins(); for(osgDB::FileNameList::iterator itr = plugins.begin(); itr != plugins.end(); ++itr) { std::cout<<"Plugin "<<*itr<<std::endl; } return 0; } std::string plugin; if (arguments.read("--plugin", plugin)) { osgDB::outputPluginDetails(std::cout, plugin); return 0; } std::string ext; if (arguments.read("--format", ext)) { plugin = osgDB::Registry::instance()->createLibraryNameForExtension(ext); osgDB::outputPluginDetails(std::cout, plugin); return 0; } if (arguments.read("--formats")) { osgDB::FileNameList plugins = osgDB::listAllAvailablePlugins(); for(osgDB::FileNameList::iterator itr = plugins.begin(); itr != plugins.end(); ++itr) { osgDB::outputPluginDetails(std::cout,*itr); } return 0; } if (arguments.argc()<=1) { arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } FileNameList fileNames; OrientationConverter oc; bool do_convert = false; if (arguments.read("--use-world-frame")) { oc.useWorldFrame(true); } std::string str; while (arguments.read("-O",str)) { osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options; options->setOptionString(str); osgDB::Registry::instance()->setOptions(options); } while (arguments.read("-e",ext)) { std::string libName = osgDB::Registry::instance()->createLibraryNameForExtension(ext); osgDB::Registry::instance()->loadLibrary(libName); } std::string libName; while (arguments.read("-l",libName)) { osgDB::Registry::instance()->loadLibrary(libName); } while (arguments.read("-o",str)) { osg::Vec3 from, to; if( sscanf( str.c_str(), "%f,%f,%f-%f,%f,%f", &from[0], &from[1], &from[2], &to[0], &to[1], &to[2] ) != 6 ) { float degrees; osg::Vec3 axis; // Try deg-axis format if( sscanf( str.c_str(), "%f-%f,%f,%f", °rees, &axis[0], &axis[1], &axis[2] ) != 4 ) { usage( argv[0], "Orientation argument format incorrect." ); return 1; } else { oc.setRotation( degrees, axis ); do_convert = true; } } else { oc.setRotation( from, to ); do_convert = true; } } while (arguments.read("-s",str)) { osg::Vec3 scale(0,0,0); if( sscanf( str.c_str(), "%f,%f,%f", &scale[0], &scale[1], &scale[2] ) != 3 ) { usage( argv[0], "Scale argument format incorrect." ); return 1; } oc.setScale( scale ); do_convert = true; } float simplifyPercent = 1.0; bool do_simplify = false; while ( arguments.read( "--simplify",str ) ) { float nsimp = 1.0; if( sscanf( str.c_str(), "%f", &nsimp ) != 1 ) { usage( argv[0], "Scale argument format incorrect." ); return 1; } std::cout << str << " " << nsimp << std::endl; simplifyPercent = nsimp; osg::notify( osg::INFO ) << "Simplifying with percentage: " << simplifyPercent << std::endl; do_simplify = true; } while (arguments.read("-t",str)) { osg::Vec3 trans(0,0,0); if( sscanf( str.c_str(), "%f,%f,%f", &trans[0], &trans[1], &trans[2] ) != 3 ) { usage( argv[0], "Translation argument format incorrect." ); return 1; } oc.setTranslation( trans ); do_convert = true; } FixTransparencyVisitor::FixTransparencyMode fixTransparencyMode = FixTransparencyVisitor::NO_TRANSPARANCY_FIXING; std::string fixString; while(arguments.read("--fix-transparency")) fixTransparencyMode = FixTransparencyVisitor::MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE; while(arguments.read("--fix-transparency-mode",fixString)) { if (fixString=="MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE") fixTransparencyMode = FixTransparencyVisitor::MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE; if (fixString=="MAKE_ALL_STATESET_OPAQUE") fixTransparencyMode = FixTransparencyVisitor::MAKE_ALL_STATESET_OPAQUE; }; bool pruneStateSet = false; while(arguments.read("--prune-StateSet")) pruneStateSet = true; osg::Texture::InternalFormatMode internalFormatMode = osg::Texture::USE_IMAGE_DATA_FORMAT; while(arguments.read("--compressed") || arguments.read("--compressed-arb")) { internalFormatMode = osg::Texture::USE_ARB_COMPRESSION; } while(arguments.read("--compressed-dxt1")) { internalFormatMode = osg::Texture::USE_S3TC_DXT1_COMPRESSION; } while(arguments.read("--compressed-dxt3")) { internalFormatMode = osg::Texture::USE_S3TC_DXT3_COMPRESSION; } while(arguments.read("--compressed-dxt5")) { internalFormatMode = osg::Texture::USE_S3TC_DXT5_COMPRESSION; } bool smooth = false; while(arguments.read("--smooth")) { smooth = true; } bool addMissingColours = false; while(arguments.read("--addMissingColours") || arguments.read("--addMissingColors")) { addMissingColours = true; } bool do_overallNormal = false; while(arguments.read("--overallNormal") || arguments.read("--overallNormal")) { do_overallNormal = true; } bool enableObjectCache = false; while(arguments.read("--enable-object-cache")) { enableObjectCache = true; } // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occurred when parsing the program arguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return 1; } for(int pos=1;pos<arguments.argc();++pos) { if (!arguments.isOption(pos)) { fileNames.push_back(arguments[pos]); } } if (enableObjectCache) { if (osgDB::Registry::instance()->getOptions()==0) osgDB::Registry::instance()->setOptions(new osgDB::Options()); osgDB::Registry::instance()->getOptions()->setObjectCacheHint(osgDB::Options::CACHE_ALL); } std::string fileNameOut("converted.osg"); if (fileNames.size()>1) { fileNameOut = fileNames.back(); fileNames.pop_back(); } osg::Timer_t startTick = osg::Timer::instance()->tick(); osg::ref_ptr<osg::Node> root = osgDB::readNodeFiles(fileNames); if (root.valid()) { osg::Timer_t endTick = osg::Timer::instance()->tick(); osg::notify(osg::INFO)<<"Time to load files "<<osg::Timer::instance()->delta_m(startTick, endTick)<<" ms"<<std::endl; } if (pruneStateSet) { PruneStateSetVisitor pssv; root->accept(pssv); } if (fixTransparencyMode != FixTransparencyVisitor::NO_TRANSPARANCY_FIXING) { FixTransparencyVisitor atv(fixTransparencyMode); root->accept(atv); } if ( root.valid() ) { if (smooth) { osgUtil::SmoothingVisitor sv; root->accept(sv); } if (addMissingColours) { AddMissingColoursToGeometryVisitor av; root->accept(av); } auto to_lower = std::bind(&boost::to_lower_copy<std::string>,std::placeholders::_1,std::locale()); // all names to lower Utils::CommonVisitor<osg::Node> names_lower( [=](osg::Node& n)->void { n.setName(to_lower(n.getName())); }); root->accept(names_lower); // optimize the scene graph, remove rendundent nodes and state etc. osgUtil::Optimizer optimizer; FindNodeVisitor::nodeNamesList list_name; for(int i=0; i<sizeof(do_not_optimize::names)/sizeof(do_not_optimize::names[0]);++i) { list_name.push_back(do_not_optimize::names[i]); } FindNodeVisitor findNodes(list_name,FindNodeVisitor::not_exact); root->accept(findNodes); const FindNodeVisitor::nodeListType& wln_list = findNodes.getNodeList(); for(auto it = wln_list.begin(); it != wln_list.end(); ++it ) { optimizer.setPermissibleOptimizationsForObject(*it,0); } optimizer.optimize(root.get(), osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS | osgUtil::Optimizer::REMOVE_REDUNDANT_NODES | osgUtil::Optimizer::SHARE_DUPLICATE_STATE | osgUtil::Optimizer::MERGE_GEOMETRY | osgUtil::Optimizer::MERGE_GEODES | osgUtil::Optimizer::STATIC_OBJECT_DETECTION ); boost::filesystem::path pathFileOut(fileNameOut); std::string base_file_name = pathFileOut.parent_path().string() + "/" + pathFileOut.stem().string(); cg::point_3 offset; bool res = generateBulletFile(base_file_name + ".bullet", root, offset); if (res) { osg::notify(osg::NOTICE)<<"Data written to '"<< base_file_name + ".bullet"<<"'."<< std::endl; } else { osg::notify(osg::NOTICE)<< "Error Occurred While Writing to "<< base_file_name + ".bullet"<< std::endl; } osg::Group* newroot = dynamic_cast<osg::Group*>(findFirstNode(root,"Root")); if(newroot==nullptr) { newroot = new osg::Group; newroot->setName("Root"); newroot->addChild( root ); root = newroot; } std::ofstream filelogic( base_file_name + ".stbin", std::ios_base::binary ); std::ofstream logfile ( base_file_name + std::string("_structure") + ".txt" ); heilVisitor hv(filelogic, logfile, offset); hv.apply(*root.get()); if( do_convert ) root = oc.convert( root.get() ); FIXME(Without textures useless) #if 0 const std::string name = pathFileOut.stem().string(); osgDB::FilePathList fpl_; fpl_.push_back(pathFileOut.parent_path().string() + "/"); std::string mat_file_name = osgDB::findFileInPath(name+".dae.mat.xml", /*fpl.*/fpl_,osgDB::CASE_INSENSITIVE); MaterialVisitor::namesList nl; nl.push_back("building"); nl.push_back("default"); nl.push_back("tree"); nl.push_back("ground"); nl.push_back("concrete"); nl.push_back("mountain"); nl.push_back("sea"); nl.push_back("railing"); nl.push_back("panorama"); nl.push_back("plane"); //nl.push_back("rotor"); /// �ללללללללללללל נאסךמלוםעאנטע� ט הטםאלטקוסךטי ףבתועס� MaterialVisitor mv ( nl, std::bind(&creators::createMaterial,sp::_1,sp::_2,name,sp::_3,sp::_4),creators::computeAttributes,mat::reader::read(mat_file_name)); root->accept(mv); #endif if (internalFormatMode != osg::Texture::USE_IMAGE_DATA_FORMAT) { std::string ext = osgDB::getFileExtension(fileNameOut); CompressTexturesVisitor ctv(internalFormatMode); root->accept(ctv); ctv.compress(); osgDB::ReaderWriter::Options *options = osgDB::Registry::instance()->getOptions(); if (ext!="ive" || (options && options->getOptionString().find("noTexturesInIVEFile")!=std::string::npos)) { ctv.write(osgDB::getFilePath(fileNameOut)); } } // scrub normals if ( do_overallNormal ) { DefaultNormalsGeometryVisitor dngv; root->accept( dngv ); } // apply any user-specified simplification if ( do_simplify ) { osgUtil::Simplifier simple; simple.setSmoothing( smooth ); osg::notify( osg::ALWAYS ) << " smoothing: " << smooth << std::endl; simple.setSampleRatio( simplifyPercent ); root->accept( simple ); } osgDB::ReaderWriter::WriteResult result = osgDB::Registry::instance()->writeNode(*root,fileNameOut,osgDB::Registry::instance()->getOptions()); if (result.success()) { osg::notify(osg::NOTICE)<<"Data written to '"<<fileNameOut<<"'."<< std::endl; } else if (result.message().empty()) { osg::notify(osg::NOTICE)<<"Warning: file write to '"<<fileNameOut<<"' not supported."<< std::endl; } else { osg::notify(osg::NOTICE)<<result.message()<< std::endl; } } else {
int ProjectShell::computeIntersections() { // will start at 2 triangles, and advance an intersection front (2 queues, one for red triangles, one for blue ..) // will mark a red triangle that is processed, and add to the queue // for each red triangle will find all the blue triangles that are intersected // find first 2 triangles that intersect: these will be the seeds for intersection int startRed=0; int startBlue = 0; for (startBlue = 0; startBlue<m_numNeg; startBlue++) { double area = 0; // if area is > 0 , we have intersections double P[24]; // max 6 points, but it may grow bigger; why worry int nP = 0; int n[3];// sides computeIntersectionBetweenRedAndBlue(/* red */0, startBlue, P, nP, area,n); if (area>0) break; // found 2 triangles that intersect; these will be the seeds } if (startBlue==m_numNeg) { // can't find any triangle stop exit (1); } // on the red edges, we will keep a list of new points (in 2D) // they will be used to create or not new points for points P from intersection // (sometimes the points P are either on sides, or on vertices of blue or even red triangles) /* matlab code: function M=InterfaceMatrix(Na,Ta,Nb,Tb); % INTERFACEMATRIX projection matrix for nonmatching triangular grids % M=InterfaceMatrix(Na,Ta,Nb,Tb); takes two triangular meshes Ta % and Tb with associated nodal coordinates in Na and Nb and % computes the interface projection matrix M bl=[1]; % bl: list of triangles of Tb to treat bil=[1]; % bil: list of triangles Ta to start with bd=zeros(size(Tb,1)+1,1); % bd: flag for triangles in Tb treated bd(end)=1; % guard, to treat boundaries bd(1)=1; % mark first triangle in b list. M=sparse(size(Nb,2),size(Na,2)); while length(bl)>0 bc=bl(1); bl=bl(2:end); % bc: current triangle of Tb al=bil(1); bil=bil(2:end); % triangle of Ta to start with ad=zeros(size(Ta,1)+1,1); % same as for bd ad(end)=1; ad(al)=1; n=[0 0 0]; % triangles intersecting with neighbors while length(al)>0 ac=al(1); al=al(2:end); % take next candidate [P,nc,Mc]=Intersect(Nb(:,Tb(bc,1:3)),Na(:,Ta(ac,1:3))); if ~isempty(P) % intersection found M(Tb(bc,1:3),Ta(ac,1:3))=M(Tb(bc,1:3),Ta(ac,1:3))+Mc; t=Ta(ac,3+find(ad(Ta(ac,4:6))==0)); al=[al t]; % add neighbors ad(t)=1; n(find(nc>0))=ac; % ac is starting candidate for neighbor end end tmp=find(bd(Tb(bc,4:6))==0); % find non-treated neighbors idx=find(n(tmp)>0); % take those which intersect t=Tb(bc,3+tmp(idx)); bl=[bl t]; % and add them bil=[bil n(tmp(idx))]; % with starting candidates Ta bd(t)=1; end */ std::queue<int> blueQueue; // these are corresponding to Ta, blueQueue.push( startBlue); std::queue<int> redQueue; redQueue.push (startRed); // the flags are used for marking the triangles already considered int * blueFlag = new int [m_numNeg+1]; // number of blue triangles + 1, to account for the boundary int k=0; for (k=0; k<m_numNeg; k++) blueFlag[k] = 0; blueFlag[m_numNeg] = 1; // mark the "boundary"; stop at the boundary blueFlag[startBlue] = 1; // mark also the first one // also, red flag is declared outside the loop int * redFlag = new int [m_numPos+1]; if (dbg) mout.open("patches.m"); while( !blueQueue.empty() ) { int n[3]; // flags for the side : indices in red mesh start from 0!!! (-1 means not found ) for (k=0; k<3; k++) n[k] = -1; // a paired red not found yet for the neighbors of blue int currentBlue = blueQueue.front(); blueQueue.pop(); for (k=0; k<m_numPos; k++) redFlag[k] = 0; redFlag[m_numPos] = 1; // to guard for the boundary int currentRed = redQueue.front(); // where do we check for redQueue???? // red and blue queues are parallel redQueue.pop();// redFlag[currentRed] = 1; // std::queue<int> localRed; localRed.push(currentRed); while( !localRed.empty()) { // int redT = localRed.front(); localRed.pop(); double P[24], area; int nP = 0; // intersection points int nc[3]= {0, 0, 0}; // means no intersection on the side (markers) computeIntersectionBetweenRedAndBlue(/* red */redT, currentBlue, P, nP, area,nc); if (nP>0) { // intersection found: output P and original triangles if nP > 2 if (dbg && area>0) { //std::cout << "area: " << area<< " nP:"<<nP << " sources:" << redT+1 << ":" << m_redMesh[redT].oldId << // " " << currentBlue+1<< ":" << m_blueMesh[currentBlue].oldId << std::endl; } if (dbg) { mout << "pa=[\n"; for (k=0; k<nP; k++) { mout << P[2*k] << "\t " ; } mout << "\n"; for (k=0; k<nP; k++) { mout << P[2*k+1] << "\t "; } mout << " ]; \n"; mout << " patch(pa(1,:),pa(2,:),'m'); \n"; } // add neighbors to the localRed queue, if they are not marked for (int nn= 0; nn<3; nn++) { int neighbor = m_redMesh[redT].t[nn]; if (redFlag[neighbor] == 0) { localRed.push(neighbor); redFlag[neighbor] =1; // flag it to not be added anymore } // n(find(nc>0))=ac; % ac is starting candidate for neighbor if (nc[nn]>0) // intersected n[nn] = redT;// start from 0!! } if (nP>1) // this will also construct triangles, if needed findNodes(redT, currentBlue, P, nP); } } for (int j=0; j<3; j++) { int blueNeigh = m_blueMesh[currentBlue].t[j]; if (blueFlag[blueNeigh]==0 && n[j] >=0 ) // not treated yet and marked as a neighbor { // we identified triangle n[j] as intersecting with neighbor j of the blue triangle blueQueue.push(blueNeigh); redQueue.push(n[j]); if (dbg) std::cout << "new triangles pushed: blue, red:" << blueNeigh+1 << " " << n[j]+1 << std::endl; blueFlag[blueNeigh] = 1; } } } delete [] redFlag; redFlag = NULL; delete [] blueFlag; // get rid of it blueFlag = NULL; if (dbg) mout.close(); return 0; }