| 1 |
/* Procrustes.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1993-2019 David Weenink |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
/* |
| 20 |
djmw 2001 |
| 21 |
djmw 20020813 GPL header |
| 22 |
djmw 20040117 Corrected bug in classProcrustes_transform: scale (s) was not used. |
| 23 |
djmw 20050406 Renamed Procrustus Procrustes |
| 24 |
djmw 20071012 Added: o_CAN_WRITE_AS_ENCODING.h |
| 25 |
djmw 20110304 Thing_new |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "Procrustes.h" |
| 29 |
|
| 30 |
#include "oo_DESTROY.h" |
| 31 |
#include "Procrustes_def.h" |
| 32 |
#include "oo_COPY.h" |
| 33 |
#include "Procrustes_def.h" |
| 34 |
#include "oo_EQUAL.h" |
| 35 |
#include "Procrustes_def.h" |
| 36 |
#include "oo_CAN_WRITE_AS_ENCODING.h" |
| 37 |
#include "Procrustes_def.h" |
| 38 |
#include "oo_WRITE_TEXT.h" |
| 39 |
#include "Procrustes_def.h" |
| 40 |
#include "oo_WRITE_BINARY.h" |
| 41 |
#include "Procrustes_def.h" |
| 42 |
#include "oo_READ_TEXT.h" |
| 43 |
#include "Procrustes_def.h" |
| 44 |
#include "oo_READ_BINARY.h" |
| 45 |
#include "Procrustes_def.h" |
| 46 |
#include "oo_DESCRIPTION.h" |
| 47 |
#include "Procrustes_def.h" |
| 48 |
|
| 49 |
Thing_implement (Procrustes, AffineTransform, 0); |
| 50 |
|
| 51 |
void structProcrustes :: v_transform (MATVU const& out, constMATVU const& in) { |
| 52 |
Melder_assert (in.nrow == out.nrow && in.ncol == out.ncol); |
| 53 |
Melder_assert (in.ncol == dimension); |
| 54 |
mul_MAT_out (out, in, our r.get()); |
| 55 |
out *= our s; |
| 56 |
out += our t.all(); |
| 57 |
} |
| 58 |
|
| 59 |
autoAffineTransform structProcrustes :: v_invert () { |
| 60 |
autoProcrustes thee = Data_copy (this); |
| 61 |
/* |
| 62 |
R is symmetric rotation matrix --> |
| 63 |
inverse is transpose! |
| 64 |
*/ |
| 65 |
thy s = ( our s == 0.0 ? 1.0 : 1.0 / our s ); |
| 66 |
thy r.all() <<= our r.transpose(); |
| 67 |
mul_VEC_out (thy t.get(), our r.get(), our t.get()); |
| 68 |
thy t.get() *= - thy s; |
| 69 |
return thee.move(); // explicit move() seems to be needed because of the type difference |
| 70 |
} |
| 71 |
|
| 72 |
static void Procrustes_setDefaults (Procrustes me) { |
| 73 |
my s = 1.0; |
| 74 |
my t.all() <<= 0.0; |
| 75 |
my r.all() <<= 0.0; |
| 76 |
my r.diagonal() <<= 1.0; |
| 77 |
} |
| 78 |
|
| 79 |
autoProcrustes Procrustes_create (integer dimension) { |
| 80 |
try { |
| 81 |
autoProcrustes me = Thing_new (Procrustes); |
| 82 |
AffineTransform_init (me.get(), dimension); |
| 83 |
Procrustes_setDefaults (me.get()); |
| 84 |
return me; |
| 85 |
} catch (MelderError) { |
| 86 |
Melder_throw (U"Procrustes not created."); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/* End of file Procrustes.c */ |