27 |
TransformCoordSysBase() : t() { } |
TransformCoordSysBase() : t() { } |
28 |
TransformCoordSysBase(const Transform &tr) : t(tr) { } |
TransformCoordSysBase(const Transform &tr) : t(tr) { } |
29 |
virtual void setParams(float *params) { |
virtual void setParams(float *params) { |
30 |
t.setParams(params); |
t.setParams(params, super); |
31 |
} |
} |
32 |
bool canPerformGL() { |
bool canPerformGL() { |
33 |
return t.canPerformGL() && super->canPerformGL(); |
return t.canPerformGL() && super->canPerformGL(); |
125 |
float params[7]; |
float params[7]; |
126 |
public: |
public: |
127 |
enum { NParams = 7 }; |
enum { NParams = 7 }; |
128 |
template<class Ptr> void setParams(Ptr p) { |
template<class Ptr> void setParams(Ptr p, CoordSys *super) { |
129 |
for(int i=0; i<7; i++) |
for(int i=0; i<7; i++) |
130 |
params[i] = p[i]; |
params[i] = p[i]; |
131 |
} |
} |
185 |
float a, s, c; |
float a, s, c; |
186 |
public: |
public: |
187 |
enum { NParams = 1 }; |
enum { NParams = 1 }; |
188 |
template<class Ptr> void setParams(Ptr p) { |
template<class Ptr> void setParams(Ptr p, CoordSys *super) { |
189 |
a = p[0]; |
a = p[0]; |
190 |
angleWasSet(); |
angleWasSet(); |
191 |
} |
} |
221 |
} |
} |
222 |
}; |
}; |
223 |
|
|
224 |
|
/** Translation. |
225 |
|
* Parameter layout: x, y, z |
226 |
|
*/ |
227 |
|
class TranslateXYZCoords { |
228 |
|
protected: |
229 |
|
ZVec vec; |
230 |
|
public: |
231 |
|
TranslateXYZCoords() { } |
232 |
|
TranslateXYZCoords(ZVec vec) : vec(vec) { } |
233 |
|
enum { NParams = 3 }; |
234 |
|
template<class Ptr> void setParams(Ptr p, CoordSys *super) { |
235 |
|
vec.x = p[0]; |
236 |
|
vec.y = p[1]; |
237 |
|
vec.z = p[2]; |
238 |
|
} |
239 |
|
/** Perform the internal transformation of this |
240 |
|
* coordsys. |
241 |
|
*/ |
242 |
|
void tr(const ZPt &from, ZPt &to) const { |
243 |
|
to = from + vec; |
244 |
|
} |
245 |
|
float tr_radius(const ZPt &from, float radius) const { |
246 |
|
return radius; |
247 |
|
} |
248 |
|
bool canPerformGL() { return true; } |
249 |
|
bool performGL() { |
250 |
|
glTranslatef(vec.x, vec.y, vec.z); |
251 |
|
return true; |
252 |
|
} |
253 |
|
typedef TranslateXYZCoords InverseType; |
254 |
|
TranslateXYZCoords inverseTransform() { |
255 |
|
TranslateXYZCoords inv(-vec); |
256 |
|
return inv; |
257 |
|
} |
258 |
|
float nonlinearity(const ZPt &p, float radius) { |
259 |
|
return 0; |
260 |
|
} |
261 |
|
}; |
262 |
|
|
263 |
|
/** Buoy coordinates. |
264 |
|
* This is an interesting cs: it is essentially a translation, |
265 |
|
* but it reads its coordinates differently. |
266 |
|
* This means that |
267 |
|
* interpolation happens differently. |
268 |
|
* <p> |
269 |
|
* This is very different from other CS since it also |
270 |
|
* uses its upper-level coordinate system at setParams |
271 |
|
* time. Also, it doesn't hierarchically transform by |
272 |
|
* the upper coordinate system. This means that it |
273 |
|
* can't be implemented as a TransformCoordSys. |
274 |
|
* <p> |
275 |
|
* Parameter layout: |
276 |
|
* x_circle, y_circle, radius, x_projpoint, y_projpoint |
277 |
|
*/ |
278 |
|
class BuoyOnCircleCoords : public CoordSys { |
279 |
|
ZVec tr; |
280 |
|
public: |
281 |
|
BuoyOnCircleCoords() : tr() { } |
282 |
|
BuoyOnCircleCoords(ZVec tr) : tr(tr) { } |
283 |
|
enum { NParams = 5 }; |
284 |
|
virtual void setParams(float *params) { |
285 |
|
ZVec ctr(params[0], params[1], 0); |
286 |
|
ZVec proj(params[3], params[4], 0); |
287 |
|
float radius = params[2]; |
288 |
|
|
289 |
|
// Get the anchor of the buoy |
290 |
|
ZPt anchor = super->transform(ZPt(0,0,0)); |
291 |
|
// Now that we have the anchor, project |
292 |
|
// from it to the circle. |
293 |
|
ZVec amc = proj - ctr; amc.z = 0; |
294 |
|
ZVec v = anchor - proj; v.z = 0; |
295 |
|
// coeffs of 2nd degree eq |
296 |
|
float a = v.dot(v); |
297 |
|
float b = 2*v.dot(amc); |
298 |
|
float c = amc.dot(amc) - radius*radius; |
299 |
|
|
300 |
|
float det = b*b - 4*a*c; |
301 |
|
if(det <= 0) { |
302 |
|
tr = ZVec(0,0,0); |
303 |
|
return; |
304 |
|
} |
305 |
|
float ans = (-b + sqrt(det)) / (2*a); |
306 |
|
ZPt pt = proj + ans * v; |
307 |
|
|
308 |
|
tr = pt; |
309 |
|
} |
310 |
|
virtual CoordSys *createInverse() { |
311 |
|
return new BuoyOnCircleCoords(-tr); |
312 |
|
} |
313 |
|
virtual void vertex(const ZPt &p) const { |
314 |
|
ZPt n = p + tr; |
315 |
|
glVertex3f(n.x, n.y, n.z); |
316 |
|
} |
317 |
|
virtual ZPt transform(const ZPt &p) const { |
318 |
|
return p + tr; |
319 |
|
} |
320 |
|
virtual bool canPerformGL() { return true; } |
321 |
|
virtual bool performGL() { |
322 |
|
glTranslatef(tr.x, tr.y, tr.z); |
323 |
|
return true; |
324 |
|
} |
325 |
|
}; |
326 |
|
|
327 |
/** Rotation around 3D vector. |
/** Rotation around 3D vector. |
328 |
* Params: x, y, z, angle |
* Params: x, y, z, angle |
329 |
*/ |
*/ |
331 |
ZVec vec; float a, s, c; |
ZVec vec; float a, s, c; |
332 |
public: |
public: |
333 |
enum { NParams = 4 }; |
enum { NParams = 4 }; |
334 |
template<class Ptr> void setParams(Ptr p) { |
template<class Ptr> void setParams(Ptr p, CoordSys *super) { |
335 |
vec.x = p[0]; |
vec.x = p[0]; |
336 |
vec.y = p[1]; |
vec.y = p[1]; |
337 |
vec.z = p[2]; |
vec.z = p[2]; |
385 |
ZVec vec; |
ZVec vec; |
386 |
public: |
public: |
387 |
enum { NParams = 3 }; |
enum { NParams = 3 }; |
388 |
template<class Ptr> void setParams(Ptr p) { |
template<class Ptr> void setParams(Ptr p, CoordSys *super) { |
389 |
vec.x = p[0]; |
vec.x = p[0]; |
390 |
vec.y = p[1]; |
vec.y = p[1]; |
391 |
vec.z = p[2]; |
vec.z = p[2]; |
436 |
F distort; |
F distort; |
437 |
public: |
public: |
438 |
enum { NParams = 6 }; |
enum { NParams = 6 }; |
439 |
template<class Ptr> void setParams(Ptr p) { |
template<class Ptr> void setParams(Ptr p, CoordSys *super) { |
440 |
x = p[0]; |
x = p[0]; |
441 |
y = p[1]; |
y = p[1]; |
442 |
mmax = exp(p[2]); |
mmax = exp(p[2]); |
500 |
virtual int nparams() { return C::NParams; } |
virtual int nparams() { return C::NParams; } |
501 |
virtual CoordSys *create() { return new TransformCoordSys<C>(); } |
virtual CoordSys *create() { return new TransformCoordSys<C>(); } |
502 |
}; |
}; |
503 |
|
template<class C> class NoTransFactory : public SomeFactory { |
504 |
|
public: |
505 |
|
virtual int nparams() { return C::NParams; } |
506 |
|
virtual CoordSys *create() { return new C(); } |
507 |
|
}; |
508 |
|
|
509 |
extern SomeFactory* facs[]; |
extern SomeFactory* facs[]; |
510 |
|
|
518 |
new Factory<DistortCoords<Fisheye::vector_mag_isotropic<Fisheye::scalar_mag_atan> > >(), |
new Factory<DistortCoords<Fisheye::vector_mag_isotropic<Fisheye::scalar_mag_atan> > >(), |
519 |
new Factory<RotateXYZCoords>(), |
new Factory<RotateXYZCoords>(), |
520 |
new Factory<ScaleXYZCoords>(), |
new Factory<ScaleXYZCoords>(), |
521 |
|
new Factory<TranslateXYZCoords>(), |
522 |
|
new NoTransFactory<BuoyOnCircleCoords>(), |
523 |
0 |
0 |
524 |
}; |
}; |
525 |
|
|