| 1 | /*
|
|---|
| 2 | * PrincipalAxisSystemAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 12, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
|
|---|
| 11 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 12 | #include "Helpers/Log.hpp"
|
|---|
| 13 | #include "Helpers/Verbose.hpp"
|
|---|
| 14 | #include "LinearAlgebra/Matrix.hpp"
|
|---|
| 15 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 16 | #include "element.hpp"
|
|---|
| 17 | #include "molecule.hpp"
|
|---|
| 18 |
|
|---|
| 19 | #include <iostream>
|
|---|
| 20 | #include <string>
|
|---|
| 21 |
|
|---|
| 22 | using namespace std;
|
|---|
| 23 |
|
|---|
| 24 | #include "UIElements/UIFactory.hpp"
|
|---|
| 25 | #include "UIElements/Dialog.hpp"
|
|---|
| 26 | #include "Actions/ValueStorage.hpp"
|
|---|
| 27 |
|
|---|
| 28 | const char AnalysisPrincipalAxisSystemAction::NAME[] = "principal-axis-system";
|
|---|
| 29 |
|
|---|
| 30 | AnalysisPrincipalAxisSystemAction::AnalysisPrincipalAxisSystemAction() :
|
|---|
| 31 | Action(NAME)
|
|---|
| 32 | {}
|
|---|
| 33 |
|
|---|
| 34 | AnalysisPrincipalAxisSystemAction::~AnalysisPrincipalAxisSystemAction()
|
|---|
| 35 | {}
|
|---|
| 36 |
|
|---|
| 37 | void AnalysisPrincipalAxisSystem() {
|
|---|
| 38 | ActionRegistry::getInstance().getActionByName(AnalysisPrincipalAxisSystemAction::NAME)->call(Action::NonInteractive);
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | Dialog* AnalysisPrincipalAxisSystemAction::fillDialog(Dialog *dialog) {
|
|---|
| 42 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 43 |
|
|---|
| 44 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 45 |
|
|---|
| 46 | return dialog;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performCall() {
|
|---|
| 50 | molecule *mol = NULL;
|
|---|
| 51 | Matrix InertiaTensor;
|
|---|
| 52 |
|
|---|
| 53 | ValueStorage::getInstance().queryCurrentValue(NAME, mol);
|
|---|
| 54 | DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
|
|---|
| 55 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
|---|
| 56 | molecule *mol = iter->second;
|
|---|
| 57 | Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
|
|---|
| 58 |
|
|---|
| 59 | // reset inertia tensor
|
|---|
| 60 | InertiaTensor.zero();
|
|---|
| 61 |
|
|---|
| 62 | // sum up inertia tensor
|
|---|
| 63 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
|---|
| 64 | Vector x = (*iter)->getPosition();
|
|---|
| 65 | x -= *CenterOfGravity;
|
|---|
| 66 | const double mass = (*iter)->getType()->mass;
|
|---|
| 67 | InertiaTensor.at(0,0) += mass*(x[1]*x[1] + x[2]*x[2]);
|
|---|
| 68 | InertiaTensor.at(0,1) += mass*(-x[0]*x[1]);
|
|---|
| 69 | InertiaTensor.at(0,2) += mass*(-x[0]*x[2]);
|
|---|
| 70 | InertiaTensor.at(1,0) += mass*(-x[1]*x[0]);
|
|---|
| 71 | InertiaTensor.at(1,1) += mass*(x[0]*x[0] + x[2]*x[2]);
|
|---|
| 72 | InertiaTensor.at(1,2) += mass*(-x[1]*x[2]);
|
|---|
| 73 | InertiaTensor.at(2,0) += mass*(-x[2]*x[0]);
|
|---|
| 74 | InertiaTensor.at(2,1) += mass*(-x[2]*x[1]);
|
|---|
| 75 | InertiaTensor.at(2,2) += mass*(x[0]*x[0] + x[1]*x[1]);
|
|---|
| 76 | }
|
|---|
| 77 | // print InertiaTensor for debugging
|
|---|
| 78 | DoLog(0) && (Log() << Verbose(0) << "The inertia tensor is:" << InertiaTensor << endl);
|
|---|
| 79 | }
|
|---|
| 80 | return Action::success;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performUndo(Action::state_ptr _state) {
|
|---|
| 84 | return Action::success;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performRedo(Action::state_ptr _state){
|
|---|
| 88 | return Action::success;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | bool AnalysisPrincipalAxisSystemAction::canUndo() {
|
|---|
| 92 | return true;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | bool AnalysisPrincipalAxisSystemAction::shouldUndo() {
|
|---|
| 96 | return true;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | const string AnalysisPrincipalAxisSystemAction::getName() {
|
|---|
| 100 | return NAME;
|
|---|
| 101 | }
|
|---|