/* openDCM, dimensional constraint manager Copyright (C) 2013 Stefan Troeger This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef DCM_EXTRACTOR_H #define DCM_EXTRACTOR_H #include "defines.hpp" #include #include namespace fusion = boost::fusion; namespace dcm { typedef std::ostream_iterator Iterator; template struct Extractor { typedef typename boost::graph_traits::vertex_iterator viter; typedef typename boost::graph_traits::edge_iterator eiter; void getVertexRange(typename Sys::Cluster& cluster, std::vector& range) { std::pair res = boost::vertices(cluster); for(; res.first != res.second; res.first++) range.push_back(cluster[*res.first]); }; void getEdgeRange(typename Sys::Cluster& cluster, std::vector >& range) { std::pair res = boost::edges(cluster); for(; res.first != res.second; res.first++) range.push_back(fusion::make_vector(cluster[*res.first], cluster.getGlobalVertex(boost::source(*res.first, cluster)), cluster.getGlobalVertex(boost::target(*res.first, cluster)))); }; void getGlobalEdgeSource(typename Sys::Cluster::edge_bundle_single b, int& source) { source = fusion::at_c<1>(b).source; }; void getGlobalEdgeTarget(typename Sys::Cluster::edge_bundle_single b, int& target) { target = fusion::at_c<1>(b).target; }; void getGlobalEdgeID(typename Sys::Cluster::edge_bundle_single b, int& id) { id = fusion::at_c<1>(b).ID; }; void setVertexID(typename Sys::Cluster* cluster, LocalVertex v, long& l) { if(v) l = cluster->getGlobalVertex(v); else l = 0; }; void getClusterRange(typename Sys::Cluster& cluster, std::vector > >& range) { typedef typename Sys::Cluster::const_cluster_iterator iter; for(iter it = cluster.m_clusters.begin(); it != cluster.m_clusters.end(); it++) { range.push_back(std::make_pair(cluster.getGlobalVertex((*it).first), (*it).second)); }; }; }; template struct Injector { void setClusterProperties(typename Sys::Cluster* cluster, typename details::pts::type& prop) { cluster->m_properties = prop; }; void setVertexProperties(typename Sys::Cluster* cluster, LocalVertex v, typename details::pts::type& prop) { fusion::at_c<1>(cluster->operator[](v)) = prop; }; void setVertexObjects(typename Sys::Cluster* cluster, LocalVertex v, typename details::sps::type& obj) { fusion::at_c<2>(cluster->operator[](v)) = obj; }; void setEdgeProperties(typename Sys::Cluster* cluster, LocalEdge e, typename details::pts::type& prop) { fusion::at_c<0>(cluster->operator[](e)) = prop; }; void setEdgeBundles(typename Sys::Cluster* cluster, LocalEdge e, std::vector& bundles) { fusion::at_c<1>(cluster->operator[](e)) = bundles; }; void setVertexProperty(typename Sys::Cluster* cluster, int value) { cluster->template setProperty(value); }; void addClusters(std::vector >& clusters, typename Sys::Cluster* cluster) { //vertices for the cluster need to be added already (as edges need vertices created) //so we don't create a vertex here. typename std::vector >::iterator it; for(it = clusters.begin(); it != clusters.end(); it++) { LocalVertex v = cluster->getLocalVertex((*it)->template getProperty()).first; cluster->m_clusters[v] = *it; }; }; }; }//namespace dcm #endif //DCM_GENERATOR_H