/*========================================================================= Program: clitk Module: $RCSfile: clitkSignalApparentMotionTrackingFilter.cxx,v $ Language: C++ Date: $Date: 2010/03/03 12:41:27 $ Version: $Revision: 1.1 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "clitkSignalApparentMotionTrackingFilter.h" #include #include //--------------------------------------------------------------------- void clitk::SignalApparentMotionTrackingFilter::SetParameters(args_info_clitkSignalApparentMotionTracking & a) { args_info = a; } //--------------------------------------------------------------------- //--------------------------------------------------------------------- void clitk::SignalApparentMotionTrackingFilter::ComputeMeanAndIsoPhase(clitk::Signal & s, int delay, int L, int nbIsoPhase, clitk::Signal & mean, clitk::Signal & isoPhase) { int mMaxIteration = 1; // Compute augmented signal clitk::Signal sx; clitk::Signal sy; s.ComputeAugmentedSpace(sx, sy, delay); // DEBUG augmented space static int tt=0; ofstream os; if (tt==0) os.open("augmentedU.sig"); else os.open("augmentedV.sig"); tt++; for(uint i=0; i e; int n = s.size()-L-delay; for(int t=0; tComputeCenter()); // DD(B->ComputeSemiAxeLengths()); } // Get mean and isoPhase //mean.resize(n); isoPhase.resize(n); ComputeIsoPhaseFromListOfEllipses(e, sx, sy, nbIsoPhase, delay, L, isoPhase); for(unsigned int i=0; i & isoPhase) { // Extract signal (slow I know) clitk::Signal U(s.GetU()); clitk::Signal V(s.GetV()); clitk::Signal & meanU = mean.GetU(); clitk::Signal & meanV = mean.GetV(); meanU.resize(s.size()); meanV.resize(s.size()); clitk::Signal isoPhaseU; clitk::Signal isoPhaseV; DD(U.size()); DD(V.size()); // Compute mean and iso independently ComputeMeanAndIsoPhase(U, delay, L, nbIsoPhase, meanU, isoPhaseU); ComputeMeanAndIsoPhase(V, delay, L, nbIsoPhase, meanV, isoPhaseV); // Check isphase ??? ??? isoPhase.resize(s.size()); for(unsigned int i=0; i & bd) { // File format : 2 columns by point (U,V), time by line std::ifstream is(filename.c_str()); skipComment(is); std::string line; std::getline(is, line); // Compute nb of column in this first line std::istringstream iss(line); std::string s; int nb = 0; while (iss>>s) { nb++; } DD(nb); if (nb%2 == 1) { std::cout << "ERROR in the file '" << filename << "', I read " << nb << " columns, which is not odd." << std::endl; } nb = nb/2; DD(nb); // Read trajectories bd.resize(nb); while (is) { std::istringstream iss(line); std::string s; int i=0; while (iss>>s) { double u = atof(s.c_str()); iss >> s; double v = atof(s.c_str()); bd[i].push_back(u,v); i++; } std::getline(is, line); } DD(bd[0].size()); } //--------------------------------------------------------------------- //--------------------------------------------------------------------- void clitk::SignalApparentMotionTrackingFilter::Update() { // ----------------------------------------------------- // Read and build initial DB ReadDB(args_info.ref_arg, mReferenceTrajectoriesBD); mReferencePhase.Read(args_info.refphase_arg); mReferencePhase.SetSamplingPeriod(args_info.refsampling_arg); DD(mReferencePhase.GetSamplingPeriod()); DD(mReferencePhase.size()); DD(mReferenceTrajectoriesBD.size()); mReferenceMean.resize(mReferenceTrajectoriesBD.size()); for(unsigned int i=0; i isophase; double d = args_info.delay_arg; int L = args_info.windowLength_arg; int nbiso = args_info.nbiso_arg; isophase.resize(mInput.size()); ComputeMeanAndIsoPhase(mInput, d, L, nbiso, mInputMean, isophase); // ----------------------------------------------------- // Substract mean to trajectory std::cout << "Build relative traj" << std::endl; mInputRelative.resize(mInput.size()); for(int i=0; i isophaseIndex; int previous = isophase[0]; for(uint i=0; i::max(); int imin =0; for(int i=0; i & meanlist, const Vector2d & mean) { // Brute force for the moment double dmin = numeric_limits::max(); double imin=0; for(uint i=0; i