/****************************************************************************** * Loads a native plugin's library. ******************************************************************************/ void NativePlugin::loadPluginImpl() { NativeOvitoObjectType* linkedListBefore = nullptr; if(isCore() == false) { linkedListBefore = NativeOvitoObjectType::_firstInfo; // Load dynamic library. if(_library == nullptr || _library->isLoaded() == false) { if(libraryFilename().isEmpty()) throw Exception(QString("The manifest file of the native plugin %1 does not specify the library name.").arg(pluginId())); _library = new QLibrary(libraryFilename(), this); _library->setLoadHints(QLibrary::ExportExternalSymbolsHint); if(!_library->load()) { throw Exception(QString("Failed to load native plugin library.\nLibrary file: %1\nError: %2").arg(libraryFilename(), _library->errorString())); } } } NativeOvitoObjectType* linkedListAfter = NativeOvitoObjectType::_firstInfo; // Initialize all newly loaded classes and connect them with this plugin. for(NativeOvitoObjectType* clazz = linkedListAfter; clazz != linkedListBefore; clazz = clazz->_next) { if(clazz->pluginId() != pluginId()) throw Exception(QString("Plugin ID %1 assigned to class %2 does not match plugin %3 that contains the class.").arg(clazz->pluginId()).arg(clazz->name()).arg(pluginId())); OVITO_ASSERT(clazz->plugin() == nullptr); clazz->initializeClassDescriptor(this); registerClass(clazz); } }
/******************************************************************** * Calculates the Direct Structure Reachability [DirREACH(v,w)] * of a given node. Will return all w E N. ********************************************************************/ std::set<Edge> Scan::dirReach(uint v, const double epsilon, const int mi) { std::set<Edge> s; if (isCore(v, epsilon, mi)) { s = neighborhood(v, epsilon); } return s; }
void PartRepresentation::addSubtreeToBodyMessage( robogenMessage::Body *bodyMessage, bool amIRoot) { // first, insert self robogenMessage::BodyPart* serialization = bodyMessage->add_part(); // required string id = 1; serialization->set_id(id_); // required string type = 2; serialization->set_type(this->getType()); // required bool root = 3; serialization->set_root(amIRoot); // repeated EvolvableParameter evolvableParam = 4; for (unsigned int i = 0; i < params_.size(); ++i) { robogenMessage::EvolvableParameter *param = serialization->add_evolvableparam(); //convert parameters from [0,1] back to valid range std::pair<double, double> ranges = PART_TYPE_PARAM_RANGE_MAP.at( std::make_pair(this->getType(), i)); double paramValue = (fabs(ranges.first - ranges.second) < 1e-6) ? ranges.first : (params_[i] * (ranges.second - ranges.first)) + ranges.first; param->set_paramvalue(paramValue); } // required int32 orientation = 5; serialization->set_orientation(orientation_); // treat children, including connection for (unsigned int i = 0; i < arity_; i++) { if (this->getChild(i)) { robogenMessage::BodyConnection *connection = bodyMessage->add_connection(); connection->set_src(id_); if (isCore(this->getType())) { connection->set_srcslot(i); } else { connection->set_srcslot(i+1); } connection->set_dest(this->getChild(i)->getId()); connection->set_destslot(0); this->getChild(i)->addSubtreeToBodyMessage(bodyMessage, false); } } }
/****************************************************************************** * Constructor for the NativePlugin class. ******************************************************************************/ NativePlugin::NativePlugin(const QString& manifestFile) : Plugin(manifestFile), _library(nullptr) { // Get the name of the shared library file. QString libBasename = metadata().object().value(QStringLiteral("native-library")).toString(); if(libBasename.isEmpty()) throw Exception(tr("Invalid plugin manifest file %1. 'native-library' element not present.").arg(manifestFile)); // Resolve the filename by adding the platform specific suffix/extension // and make the path absolute. QDir baseDir; if(isCore()) // The core library is not in the plugins directory. baseDir = QCoreApplication::applicationDirPath(); else baseDir = QFileInfo(manifestFile).dir(); #if defined(Q_OS_WIN) QFileInfo libFile(baseDir.absoluteFilePath(libBasename + ".dll")); #else QFileInfo libFile(baseDir.absoluteFilePath(libBasename + ".so")); #endif _libraryFilename = QDir::cleanPath(libFile.absoluteFilePath()); }
/******************************************************************** * Main SCAN algorithm ********************************************************************/ void Scan::run(const double epsilon, const int mi) { // All vertices begin unclassified // So let's begin. We will iterate the labels list. In no moment // can a label became "unclassified" again, so this loop will // do the trick. hmap::iterator node; uint cnt = 0; for (node = g.graph_map.begin(); node != g.graph_map.end(); ++node) { // Making sure this node was not yet evaluated if (getClusterLabel(node->first) == -1) { // Is it a core? if (isCore(node->first, epsilon, mi)) { //std::cout << node->first << " is a core!\n"; // Will begin a new cluster int cid = getNewClusterID(); // Put all the e-neighborhood of the node in a queue std::set<Edge> x; x = neighborhood(node->first, epsilon); std::queue<uint> q; std::set<Edge>::iterator it; //std::cout << node->first << " nhood is:"; for (it = x.begin(); it != x.end(); ++it) { //std::cout << " " << it->getNode() << std::endl; q.push(it->getNode()); } while (!q.empty()) { uint y = q.front(); q.pop(); std::set<Edge> r; r = dirReach(y, epsilon, mi); std::set<Edge>::iterator setIt; for (setIt = r.begin(); setIt != r.end(); ++setIt) { // If the node is unclassified if (getClusterLabel(setIt->getNode()) == -1) { addToCluster(setIt->getNode(), cid); q.push(setIt->getNode()); } // If the node is a non-member of the cluster if (getClusterLabel(setIt->getNode()) == 0) { addToCluster(setIt->getNode(), cid); } } } } else { // Not a Core, so it will be labeled as non-member (0) setClusterLabel(node->first, 0); } } else { // Node already evaluated. Move along. continue; } } // Further classifies non-members hmap_ii::iterator nmnode; for (nmnode = cluster_label.begin(); nmnode != cluster_label.end(); ++nmnode) { if (nmnode->second == 0) { std::set<uint> tmp; tmp = getNeighborClusters(nmnode->first); if (tmp.size() > 1) { addHub(nmnode->first, tmp); } else { std::pair<uint, uint> o(nmnode->first,*tmp.begin()); outliers.push_back(o); } } } std::cout << "SCAN finished."; std::cout << std::endl; }