1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
//
// Lynkeos
// $Id$
//
// Created by Jean-Etienne LAMIAUD on Thu May 8 2008.
// Copyright (c) 2008-2018. Jean-Etienne LAMIAUD
//
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#include "LynkeosBasicAlignResult.h"
/* For compatibility, we keep the same string as MyImageAligner */
NSString * const LynkeosAlignRef = @"MyImageAligner";
NSString * const LynkeosAlignResultRef = @"AlignResult";
#define K_ALIGN_OFFSET @"offset"
#define K_ALIGN_TRANSFORM @"transform"
@interface LynkeosBasicAlignResult(Private)
- (void) cacheValues;
@end
@implementation LynkeosBasicAlignResult(Private)
- (void) cacheValues
{
NSAffineTransformStruct m = [_transform transformStruct];
// As the determinant is a surface ratio, and the scaling is homothetic,
// the scale is its square root
_scale = sqrt(m.m11*m.m22 - m.m12*m.m21);
// The "unscaled" matrix is a pure rotation matrix, therefore, the rotation
// angle is extracted from its transform of the X unit vector
_rotation = atan2(m.m21/_scale, m.m11/_scale)/M_PI*180.0;
}
@end
@implementation LynkeosBasicAlignResult
- (id) init
{
if ( (self = [super init]) != nil )
{
_transform = [[NSAffineTransform transform] retain];
_scale = 1.0;
_rotation = 0.0;
}
return( self );
}
- (id) initWithCoder:(NSCoder *)decoder
{
self = [self init];
if ( self != nil )
{
if ( [decoder containsValueForKey:K_ALIGN_OFFSET] )
{
_offset = [decoder decodePointForKey:K_ALIGN_OFFSET];
}
if ( [decoder containsValueForKey:K_ALIGN_TRANSFORM] )
{
// Replace the transform
[_transform release];
_transform = [[decoder decodeObjectForKey:K_ALIGN_TRANSFORM] retain];
}
else
// V2 document
[_transform translateXBy:_offset.x yBy:_offset.y];
}
[self cacheValues];
return( self );
}
- (void) dealloc
{
[_transform release];
[super dealloc];
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_transform forKey: K_ALIGN_TRANSFORM];
[encoder encodePoint:_offset forKey:K_ALIGN_OFFSET];
}
- (void) setTransformStruct:(NSAffineTransformStruct)m
{
[_transform setTransformStruct:m];
[self cacheValues];
}
- (void) setOffset:(NSPoint)offset
{
_offset = offset;
}
- (NSNumber*) dx
{
return( [NSNumber numberWithDouble:_offset.x] );
}
- (NSNumber*) dy
{
return( [NSNumber numberWithDouble:_offset.y] );
}
- (NSAffineTransform*) alignTransform
{
return( _transform );
}
- (NSNumber*)rotation
{
return( [NSNumber numberWithDouble:_rotation] );
}
- (NSNumber*)scale
{
return( [NSNumber numberWithDouble:_scale] );
}
@end
/*!
* @abstract Class for reading files up to V2.2
*/
@interface MyImageAlignerResult : NSObject <LynkeosProcessingParameter>
{
}
@end
@implementation MyImageAlignerResult
- (id) init
{
[self release];
self = (MyImageAlignerResult*)[[LynkeosBasicAlignResult alloc] init];
return( self );
}
- (void)encodeWithCoder:(NSCoder *)encoder
{ [self doesNotRecognizeSelector:_cmd]; }
- (id) initWithCoder:(NSCoder *)decoder
{
[self release];
self = (MyImageAlignerResult*)[[LynkeosBasicAlignResult alloc] initWithCoder:decoder];
return( self );
}
@end
|