1 /*=========================================================================
4 Module: $RCSfile: clitkTrajectory2D.cxx,v $
6 Date: $Date: 2010/03/03 12:41:27 $
7 Version: $Revision: 1.1 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "clitkTrajectory2D.h"
21 //---------------------------------------------------------------------
22 void clitk::Trajectory2D::ResampleWithTimeWarpTo(int begin, int end, Trajectory2D & output) const {
25 int n = (int)lrint((end-begin)*GetSamplingPeriod()/output.GetSamplingPeriod());
28 double duration = (end-begin)*GetSamplingPeriod();
30 double sp = output.GetSamplingPeriod();
31 DD(output.GetTotalTimeDuration());
33 for(int i=0; i<n; i++) {
36 GetValueAtLin((i*sp)+(begin*GetSamplingPeriod()), p);
38 output.SetPoint(i, p);
41 //---------------------------------------------------------------------
44 //---------------------------------------------------------------------
45 bool clitk::Trajectory2D::Read(std::string filename) {
46 bool b = mU.Read(filename, 0);
48 b = mV.Read(filename, 1);
51 //---------------------------------------------------------------------
54 //---------------------------------------------------------------------
55 void clitk::Trajectory2D::GetValueAtLin(double t, Vector2d & p) const {
56 // Can be faster, I know ...
57 p[0] = mU.GetValueAtLin(t);
58 p[1] = mV.GetValueAtLin(t);
60 //---------------------------------------------------------------------
63 //---------------------------------------------------------------------
64 void clitk::Trajectory2D::ResampleWithTimeWarpTo(Trajectory2D & output) const {
65 ResampleWithTimeWarpTo(0, size(), output);
67 //---------------------------------------------------------------------
70 //---------------------------------------------------------------------
71 void clitk::Trajectory2D::Shift(double s) {
72 std::cout << "Shift s=" << s << std::endl;
73 int d = (int)lrint(s/GetSamplingPeriod()); // closest integer delta
75 clitk::Signal tempU((uint)size());
76 clitk::Signal tempV((uint)size());
77 for(int i=0; i<size(); i++) {
78 tempU[0] = mU[(i+d)%size()];
79 tempV[0] = mV[(i+d)%size()];
81 for(int i=0; i<size(); i++) {
86 //---------------------------------------------------------------------
89 //---------------------------------------------------------------------
90 void clitk::Trajectory2D::GetPoint(const int index, Vector2d & p) {
94 //---------------------------------------------------------------------
97 //---------------------------------------------------------------------
98 clitk::Trajectory2D & clitk::Trajectory2D::operator+(Trajectory2D & d) {
99 for(int i=0; i<size(); i++) {
105 //---------------------------------------------------------------------
108 //---------------------------------------------------------------------
109 clitk::Trajectory2D & clitk::Trajectory2D::operator-(Trajectory2D & d) {
110 for(int i=0; i<size(); i++) {
116 //---------------------------------------------------------------------
119 //---------------------------------------------------------------------
120 void clitk::Trajectory2D::GetMean(Vector2d & m) {
123 for(int i=0; i<size(); i++) {
130 //---------------------------------------------------------------------
133 //---------------------------------------------------------------------
134 double clitk::Trajectory2D::DistanceTo(int delta, const clitk::Trajectory2D & B) const {
136 for(int n=0; n<size(); n++) {
137 int i = n;//(n)%size();
138 int j = (n+delta)%B.size();
142 d += pow(mU[i] - B.GetU(j), 2) + pow(mV[i] - B.GetV(j), 2);
146 //---------------------------------------------------------------------
149 //---------------------------------------------------------------------
150 void clitk::Trajectory2D::Print(const std::string & name) const {
151 Print(name, 0, size());
153 //---------------------------------------------------------------------
156 //---------------------------------------------------------------------
157 void clitk::Trajectory2D::Print(const std::string & name, int begin, int end) const {
158 std::cout << "Traj " << name << " size = " << size()
159 << " from " << begin << " to " << end << std ::endl;
160 for(int i=begin; i<end; i++) {
161 std::cout << mU[i] << " " << mV[i] << std::endl;
164 //---------------------------------------------------------------------
167 //---------------------------------------------------------------------
168 void clitk::Trajectory2D::Substract(const Vector2d & m) {
172 //---------------------------------------------------------------------