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