/* Copyright 2013 Pierre SMARS (smars@yuntech.edu.tw) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include "SimpleOpt.h" #include "vtkMath.h" enum { OPT_HELP, OPT_VAL, OPT_VECT, OPT_SCAL, OPT_PRECISION }; //--------------------------------------------------------------------------- CSimpleOpt::SOption g_rgOptions[] = { { OPT_VAL, _T("-s"), SO_NONE }, { OPT_VAL, _T("-s1"), SO_NONE }, { OPT_VAL, _T("-s2"), SO_NONE }, { OPT_VAL, _T("-s3"), SO_NONE }, { OPT_VECT, _T("-v"), SO_NONE }, { OPT_VECT, _T("-v1"), SO_NONE }, { OPT_VECT, _T("-v2"), SO_NONE }, { OPT_VECT, _T("-v3"), SO_NONE }, { OPT_SCAL, _T("-x"), SO_NONE }, { OPT_SCAL, _T("--scale"), SO_NONE }, { OPT_PRECISION, _T("-p"), SO_REQ_SEP }, { OPT_PRECISION, _T("--precision"), SO_REQ_SEP }, { OPT_HELP, _T("-?"), SO_NONE }, { OPT_HELP, _T("--help"), SO_NONE }, SO_END_OF_OPTIONS }; //--------------------------------------------------------------------------- int error(int val) { // #include "tenseigen.help" [used to get the manual page.. other files needed...] return val; } //--------------------------------------------------------------------------- int main( int argc, char *argv[] ) { int pre = 6; bool s1,s2,s3; bool v1,v2,v3; s1=s2=s3=false; v1=v2=v3=false; bool scale = true; CSimpleOpt args(argc, argv, g_rgOptions); while (args.Next()) { if (args.LastError() == SO_SUCCESS) { if (args.OptionId() == OPT_HELP) return error(0); else if (args.OptionId() == OPT_SCAL) scale = true; else if (args.OptionId() == OPT_VAL) { std::string code(args.OptionText()); if (code == "-s") { s1 = true; s2 = true; s3 = true; } else if (code == "-s1") s1 = true; else if (code == "-s2") s2 = true; else if (code == "-s3") s3 = true; } else if (args.OptionId() == OPT_VECT) { std::string code(args.OptionText()); if (code == "-v") { v1 = true; v2 = true; v3 = true; } else if (code == "-v1") v1 = true; else if (code == "-v2") v2 = true; else if (code == "-v3") v3 = true; } else if (args.OptionId() == OPT_PRECISION) { std::istringstream i(args.OptionArg()); i >> pre; } else return error(-1); // handle option, using OptionId(), OptionText() and OptionArg() } else { return error(args.LastError()); // handle error, one of: SO_OPT_INVALID, SO_OPT_MULTIPLE, // SO_ARG_INVALID, SO_ARG_INVALID_TYPE, SO_ARG_MISSING } } int nmats; std::cin >> nmats; std::cout << nmats << std::endl; std::cout << std::fixed << std::setprecision(pre); double ** a = new double *[3]; double * w = new double[3]; double ** v = new double *[3]; for (int i = 0; i < 3; i++) { a[i] = new double[3]; v[i] = new double[3]; } if (scale) { for (int k = 0; k < nmats; k++) { std::cin >> a[0][0] >> a[1][1] >> a[2][2] >> a[0][1] >> a[1][2] >> a[2][0]; a[1][0] = a[0][1]; a[2][1] = a[1][2]; a[0][2] = a[2][0]; vtkMath::Jacobi(a,w,v); if (s1) std::cout << w[0] << " "; if (s2) std::cout << w[1] << " "; if (s3) std::cout << w[2] << " "; if (v1) std::cout << w[0]*v[0][0] << " " << w[0]*v[1][0] << " " << w[0]*v[2][0] << " "; if (v2) std::cout << w[1]*v[0][1] << " " << w[1]*v[1][1] << " " << w[1]*v[2][1] << " "; if (v3) std::cout << w[2]*v[0][2] << " " << w[2]*v[1][2] << " " << w[2]*v[2][2]; std::cout << std::endl; } } else { for (int k = 0; k < nmats; k++) { std::cin >> a[0][0] >> a[1][1] >> a[2][2] >> a[0][1] >> a[1][2] >> a[2][0]; a[1][0] = a[0][1]; a[2][1] = a[1][2]; a[0][2] = a[2][0]; vtkMath::Jacobi(a,w,v); if (s1) std::cout << w[0] << " "; if (s2) std::cout << w[1] << " "; if (s3) std::cout << w[2] << " "; if (v1) std::cout << v[0][0] << " " << v[1][0] << " " << v[2][0] << " "; if (v2) std::cout << v[0][1] << " " << v[1][1] << " " << v[2][1] << " "; if (v3) std::cout << v[0][2] << " " << v[1][2] << " " << v[2][2]; std::cout << std::endl; } } for (int i = 0; i < 3; i++) { delete a[i]; delete v[i]; } delete a; delete v; return 0; }