1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "moss.h" |
25 |
|
|
#include "privateMoss.h" |
26 |
|
|
|
27 |
|
|
int |
28 |
|
|
_mossHestTransformParse (void *ptr, char *_str, char err[AIR_STRLEN_HUGE]) { |
29 |
|
|
char me[]="_mossHestTransformParse", *str; |
30 |
|
|
double **matP, tx, ty, sx, sy, angle, mat[6], shf, sha; |
31 |
|
|
airArray *mop; |
32 |
|
|
|
33 |
|
|
if (!(ptr && _str)) { |
34 |
|
|
sprintf(err, "%s: got NULL pointer", me); |
35 |
|
|
return 1; |
36 |
|
|
} |
37 |
|
|
matP = (double **)ptr; |
38 |
|
|
mop = airMopNew(); |
39 |
|
|
*matP = (double *)calloc(6, sizeof(double)); |
40 |
|
|
airMopMem(mop, matP, airMopOnError); |
41 |
|
|
str = airToLower(airStrdup(_str)); |
42 |
|
|
airMopMem(mop, &str, airMopAlways); |
43 |
|
|
|
44 |
|
|
if (!strcmp("identity", str)) { |
45 |
|
|
mossMatIdentitySet(*matP); |
46 |
|
|
|
47 |
|
|
} else if (1 == sscanf(str, "flip:%lf", &angle)) { |
48 |
|
|
mossMatFlipSet(*matP, angle); |
49 |
|
|
|
50 |
|
|
} else if (2 == sscanf(str, "translate:%lf,%lf", &tx, &ty)) { |
51 |
|
|
mossMatTranslateSet(*matP, tx, ty); |
52 |
|
|
} else if (2 == sscanf(str, "t:%lf,%lf", &tx, &ty)) { |
53 |
|
|
mossMatTranslateSet(*matP, tx, ty); |
54 |
|
|
|
55 |
|
|
} else if (1 == sscanf(str, "rotate:%lf", &angle)) { |
56 |
|
|
mossMatRotateSet(*matP, angle); |
57 |
|
|
} else if (1 == sscanf(str, "r:%lf", &angle)) { |
58 |
|
|
mossMatRotateSet(*matP, angle); |
59 |
|
|
|
60 |
|
|
} else if (2 == sscanf(str, "scale:%lf,%lf", &sx, &sy)) { |
61 |
|
|
mossMatScaleSet(*matP, sx, sy); |
62 |
|
|
} else if (2 == sscanf(str, "s:%lf,%lf", &sx, &sy)) { |
63 |
|
|
mossMatScaleSet(*matP, sx, sy); |
64 |
|
|
|
65 |
|
|
} else if (2 == sscanf(str, "shear:%lf,%lf", &shf, &sha)) { |
66 |
|
|
mossMatShearSet(*matP, shf, sha); |
67 |
|
|
|
68 |
|
|
} else if (6 == sscanf(str, "%lf,%lf,%lf,%lf,%lf,%lf", |
69 |
|
|
mat+0, mat+1, mat+2, mat+3, mat+4, mat+5)) { |
70 |
|
|
MOSS_MAT_COPY(*matP, mat); |
71 |
|
|
|
72 |
|
|
} else { |
73 |
|
|
sprintf(err, "%s: couldn't parse \"%s\" as a transform", me, _str); |
74 |
|
|
airMopError(mop); return 1; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
airMopOkay(mop); |
78 |
|
|
return 0; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
hestCB |
82 |
|
|
_mossHestTransform = { |
83 |
|
|
sizeof(double*), |
84 |
|
|
"2D transform", |
85 |
|
|
_mossHestTransformParse, |
86 |
|
|
airFree |
87 |
|
|
}; |
88 |
|
|
|
89 |
|
|
hestCB * |
90 |
|
|
mossHestTransform = &_mossHestTransform; |
91 |
|
|
|
92 |
|
|
/* ----------------------------------------------------------------- */ |
93 |
|
|
|
94 |
|
|
/* |
95 |
|
|
** _mossHestOriginParse() |
96 |
|
|
** |
97 |
|
|
** parse an origin specification |
98 |
|
|
** p(x,y): absolute pixel position --> val[3] = (0,x,y) |
99 |
|
|
** u(x,y): position in unit box [0,1]x[0,1] --> val[3] = (1,x,y) |
100 |
|
|
*/ |
101 |
|
|
int |
102 |
|
|
_mossHestOriginParse (void *ptr, char *str, char err[AIR_STRLEN_HUGE]) { |
103 |
|
|
char me[]="_mossHestOriginParse"; |
104 |
|
|
double **valP; |
105 |
|
|
airArray *mop; |
106 |
|
|
|
107 |
|
|
valP = (double **)ptr; |
108 |
|
|
mop = airMopNew(); |
109 |
|
|
*valP = (double *)calloc(3, sizeof(double)); |
110 |
|
|
airMopMem(mop, valP, airMopOnError); |
111 |
|
|
if (2 == sscanf(str, "p:%lf,%lf", *valP + 1, *valP + 2)) { |
112 |
|
|
(*valP)[0] = 0; |
113 |
|
|
} else if (2 == sscanf(str, "u:%lf,%lf", *valP + 1, *valP + 2)) { |
114 |
|
|
(*valP)[0] = 1; |
115 |
|
|
} else { |
116 |
|
|
sprintf(err, "%s: couldn't parse \"%s\" as origin", me, str); |
117 |
|
|
airMopError(mop); return 1; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
airMopOkay(mop); |
121 |
|
|
return 0; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
hestCB |
125 |
|
|
_mossHestOrigin = { |
126 |
|
|
sizeof(double*), |
127 |
|
|
"origin specification", |
128 |
|
|
_mossHestOriginParse, |
129 |
|
|
airFree |
130 |
|
|
}; |
131 |
|
|
|
132 |
|
|
hestCB * |
133 |
|
|
mossHestOrigin = &_mossHestOrigin; |
134 |
|
|
|