/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * FillRegularGridAction.cpp * * Created on: Jan 12, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Atom/atom.hpp" #include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp" #include "CodePatterns/Log.hpp" #include "Descriptors/MoleculeOrderDescriptor.hpp" #include "Filling/Cluster.hpp" #include "Filling/Filler.hpp" #include "Filling/Mesh/CubeMesh.hpp" #include "Filling/Predicates/IsInsideSurface_FillPredicate.hpp" #include "Filling/Predicates/IsVoidNode_FillPredicate.hpp" #include "Filling/Predicates/Ops_FillPredicate.hpp" #include "LinkedCell/linkedcell.hpp" #include "LinkedCell/PointCloudAdaptor.hpp" #include "molecule.hpp" #include "MoleculeListClass.hpp" #include "Parser/FormatParserInterface.hpp" #include "Parser/FormatParserStorage.hpp" #include "Shapes/BaseShapes.hpp" #include "Tesselation/tesselation.hpp" #include "Tesselation/BoundaryLineSet.hpp" #include "Tesselation/BoundaryTriangleSet.hpp" #include "Tesselation/CandidateForTesselation.hpp" #include "World.hpp" #include #include #include #include #include "Actions/FillAction/FillRegularGridAction.hpp" using namespace MoleCuilder; // and construct the stuff #include "FillRegularGridAction.def" #include "Action_impl_pre.hpp" /** =========== define the function ====================== */ Action::state_ptr FillRegularGridAction::performCall() { typedef std::vector AtomVector; // obtain information getParametersfromValueStorage(); // get all present atoms for UndoState AtomVector presentatoms = World::getInstance().getAllAtoms(); // get the filler molecule and move to origin const std::vector< molecule *> molecules = World::getInstance().getSelectedMolecules(); if (molecules.size() != 1) { ELOG(1, "No exactly one molecule selected, aborting,"); return Action::failure; } molecule *filler = *(molecules.begin()); LOG(1, "INFO: Chosen molecule has " << filler->size() << " atoms."); // check for selected molecules and create surfaces from them std::vector atoms(World::getInstance().getSelectedAtoms()); FillPredicate * surface_predicate = NULL; LinkedCell_deprecated * LC = NULL; Tesselation * TesselStruct = NULL; if (params.SphereRadius != 0.) { if ( molecules.size() == 0) { ELOG(1, "You have given a sphere radius " << params.SphereRadius << " != 0, but have not select any molecules."); } // create adaptor for the selected atoms PointCloudAdaptor< std::vector > cloud(&atoms, std::string("Selected atoms")); // create tesselation LC = new LinkedCell_deprecated(cloud, 2.*params.SphereRadius); TesselStruct = new Tesselation; (*TesselStruct)(cloud, params.SphereRadius); // and create predicate surface_predicate = new FillPredicate( IsInsideSurface_FillPredicate( *TesselStruct, *LC ) ); } // create predicate, mesh, and filler { FillPredicate *voidnode_predicate = new FillPredicate( IsVoidNode_FillPredicate( Sphere(zeroVec, params.mindistance) ) ); FillPredicate Andpredicate = (*voidnode_predicate); if (surface_predicate != NULL) Andpredicate = (Andpredicate) && !(*surface_predicate); Mesh *mesh = new CubeMesh(params.counts, params.offset, World::getInstance().getDomain().getM()); // fill { Filler *fillerFunction = new Filler(*mesh, Andpredicate); ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape()) ); CopyAtoms_withBonds copyMethod; (*fillerFunction)(copyMethod, cluster); delete fillerFunction; } // remove delete mesh; delete voidnode_predicate; delete surface_predicate; delete LC; delete TesselStruct; } // generate list of newly created atoms // (we can in general remove more quickly from a list than a vector) AtomVector filleratoms = World::getInstance().getAllAtoms(); // LOG(0, filleratoms.size() << " atoms are present."); std::list filleratoms_list; std::copy( filleratoms.begin(), filleratoms.end(), std::back_inserter( filleratoms_list )); // LOG(0, filleratoms_list.size() << " atoms have been copied."); for (AtomVector::const_iterator iter = presentatoms.begin(); iter != presentatoms.end(); ++iter) { filleratoms_list.remove(*iter); } // LOG(0, filleratoms_list.size() << " atoms left after removal."); filleratoms.clear(); std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms )); // LOG(0, filleratoms.size() << " atoms have been inserted."); return Action::state_ptr(new FillRegularGridState(filleratoms,params)); } Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) { // FillRegularGridState *state = assert_cast(_state.get()); // // BOOST_FOREACH(atom *_atom, state->filleratoms) { // World::getInstance().destroyAtom(Walker); // } // // // as atoms and atoms from state are removed, we have to create a new one // std::vector filleratoms; // return Action::state_ptr(new FillRegularGridState(filleratoms,state->params)); return Action::failure; } Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){ //FillRegularGridState *state = assert_cast(_state.get()); return Action::failure; //return Action::state_ptr(_state); } bool FillRegularGridAction::canUndo() { return false; } bool FillRegularGridAction::shouldUndo() { return false; } /** =========== end of function ====================== */