std::size_t ElementValueModification::condense(MeshLib::Mesh &mesh) { auto* property_value_vector = mesh.getProperties().getPropertyVector<int>("MaterialIDs"); if (!property_value_vector) { return 0; } std::vector<int> value_mapping( getSortedPropertyValues(*property_value_vector)); std::vector<int> reverse_mapping(value_mapping.back()+1, 0); std::size_t const nValues (value_mapping.size()); for (std::size_t i=0; i<nValues; ++i) reverse_mapping[value_mapping[i]] = i; std::size_t const n_property_values(property_value_vector->size()); for (std::size_t i = 0; i < n_property_values; ++i) (*property_value_vector)[i] = reverse_mapping[(*property_value_vector)[i]]; return nValues; }
std::size_t ElementValueModification::condense(MeshLib::Mesh &mesh) { boost::optional<MeshLib::PropertyVector<int> &> optional_property_value_vec( mesh.getProperties().getPropertyVector<int>("MaterialIDs") ); if (!optional_property_value_vec) { return 0; } MeshLib::PropertyVector<int> & property_value_vector( optional_property_value_vec.get() ); std::vector<int> value_mapping( getSortedPropertyValues(property_value_vector) ); std::vector<int> reverse_mapping(value_mapping.back()+1, 0); std::size_t const nValues (value_mapping.size()); for (std::size_t i=0; i<nValues; ++i) reverse_mapping[value_mapping[i]] = i; std::size_t const n_property_values(property_value_vector.size()); for (std::size_t i=0; i<n_property_values; ++i) property_value_vector[i] = reverse_mapping[property_value_vector[i]]; return nValues; }
std::size_t ElementValueModification::condense(MeshLib::Mesh &mesh) { MeshLib::PropertyVector<int>* property_value_vector = nullptr; try { property_value_vector = mesh.getProperties().getPropertyVector<int>( "MaterialIDs", MeshLib::MeshItemType::Cell, 1); } catch (std::runtime_error const& e) { ERR("%s", e.what()); return 0; } std::vector<int> value_mapping( getSortedPropertyValues(*property_value_vector)); std::vector<int> reverse_mapping(value_mapping.back() + 1, 0); std::size_t const nValues(value_mapping.size()); for (std::size_t i = 0; i < nValues; ++i) { reverse_mapping[value_mapping[i]] = i; } std::size_t const n_property_values(property_value_vector->size()); for (std::size_t i = 0; i < n_property_values; ++i) { (*property_value_vector)[i] = reverse_mapping[(*property_value_vector)[i]]; } return nValues; }
void flip_nodes(Alignment& a, set<int64_t> ids, const std::function<size_t(int64_t)>& node_length) { Path* path = a.mutable_path(); for(size_t i = 0; i < path->mapping_size(); i++) { // Grab each mapping (includes its position) Mapping* mapping = path->mutable_mapping(i); if(ids.count(mapping->position().node_id())) { // We need to flip this mapping *mapping = reverse_mapping(*mapping, node_length); } } }