This file is indexed.

/usr/include/Field3D/FieldMapping.h is in libfield3d-dev 1.6.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
//----------------------------------------------------------------------------//

/*
 * Copyright (c) 2009 Sony Pictures Imageworks Inc
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the
 * distribution.  Neither the name of Sony Pictures Imageworks nor the
 * names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

//----------------------------------------------------------------------------//

/*! \file FieldMapping.h
  \ingroup field
  \brief Contains the FieldMapping base class and the NullFieldMapping and
  MatrixFieldMapping subclasses.
*/

//----------------------------------------------------------------------------//

#ifndef _INCLUDED_Field3D_FieldMapping_H_
#define _INCLUDED_Field3D_FieldMapping_H_

#include <vector>
#include <algorithm>

#include "Curve.h"
#include "Exception.h"
#include "RefCount.h"
#include "Types.h"

//----------------------------------------------------------------------------//

#include "ns.h"

FIELD3D_NAMESPACE_OPEN

//----------------------------------------------------------------------------//
// FieldMapping
//----------------------------------------------------------------------------//

/*! \class FieldMapping
  \ingroup field
  \brief Base class for mapping between world-, local- and voxel coordinates.

  Refer to \ref using_mappings for examples of how to use this in your code.

  Local coordinates (ls) are defined as [0,1] over the FieldData object's
  -extents- (not data window). Thus, if the extents.min isn't at origin, 
  the coordinate system stays the same as if it was. 

  Voxel coordinates (vs) are defined as [0,size-1] over the FieldData object's
  -extents- (not data window).

  \note The center of a voxel at (i,j) in integer coordinates is (i+0.5,j+0.5) 
  in continuous coordinates.
*/

//----------------------------------------------------------------------------//

class FIELD3D_API FieldMapping : public RefBase
{
 public:

  // Typedefs ------------------------------------------------------------------

  typedef boost::intrusive_ptr<FieldMapping> Ptr;

  // RTTI replacement ----------------------------------------------------------

  typedef FieldMapping class_type;
  DEFINE_FIELD_RTTI_ABSTRACT_CLASS;
  
  static const char* staticClassType()
  {
    return "FieldMapping";
  }

  // Ctors, dtor ---------------------------------------------------------------

  //! \name Constructors & destructor
  //! \{

  //! Constructor
  FieldMapping();
  //! Construct with known extents
  FieldMapping(const Box3i &extents);
  //! Destructor
  virtual ~FieldMapping();

  //! \}

  // Main methods --------------------------------------------------------------

  //! This sets the field extents information to use for defining the
  //! local coordinate space.
  //! \note You need to call this again if you change the resolution of the
  //! field after creation. We grab the extents information in this call because
  //! it would be too slow to do so in every transformation.
  void setExtents(const Box3i &extents);

  //! Returns the origin
  const V3d& origin() const
  { return m_origin; }
  //! Returns the resolution
  const V3d& resolution() const
  { return m_res; }
  
  // To be implemented by subclasses -------------------------------------------

  //! \name To be implemented by subclasses
  //! \{

  //! Returns a pointer to a copy of the mapping, pure virtual so ensure
  //! derived classes properly implement it
  virtual Ptr clone() const = 0;

  //! Transform from world space position into voxel space
  virtual void worldToVoxel(const V3d &wsP, V3d &vsP) const = 0;
  virtual void worldToVoxel(const V3d &wsP, V3d &vsP, float time) const = 0;
  //! Transform from voxel space position into world space
  virtual void voxelToWorld(const V3d &vsP, V3d &wsP) const = 0;
  virtual void voxelToWorld(const V3d &vsP, V3d &wsP, float time) const = 0;
  //! Transform from world space position into local space
  virtual void worldToLocal(const V3d &wsP, V3d &lsP) const = 0;
  virtual void worldToLocal(const V3d &wsP, V3d &lsP, float time) const = 0;
  //! Transform from local space position into world space
  virtual void localToWorld(const V3d &lsP, V3d &wsP) const = 0;
  virtual void localToWorld(const V3d &lsP, V3d &wsP, float time) const = 0;

  //! Returns world-space size of a voxel at the specified coordinate
  virtual V3d wsVoxelSize(int i, int j, int k) const = 0;

  //! Implement this if the subclass needs to update itself when the 
  //! resolution changes.
  virtual void extentsChanged()
  { /* Empty */ }
  
  //! Returns the FieldMapping type name. Used when writing/reading from disk
  virtual std::string className() const = 0;

  //! Whether the mapping is identical to another mapping
  virtual bool isIdentical(FieldMapping::Ptr other, 
                           double tolerance = 0.0) const = 0;

  //! \}

  // Transform calls -----------------------------------------------------------

  //! \name Transforms implemented in this class
  //! \{

  //! Transform from local space to voxel space. This is just a multiplication
  //! by the resolution of the Field that we're mapping.
  void localToVoxel(const V3d &lsP, V3d &vsP) const;
  //! Inverse of localToVoxel.
  void voxelToLocal(const V3d &vsP, V3d &lsP) const;

  //! \}
  
protected:

  //! The integer voxel-space origin of the underlying Field object.
  //! Is equal to field.extents.min
  V3d m_origin;
  //! The integer voxel-space resolution of the underlying Field object.
  //! Is equal to field.extents.max - field.extents.min + 1
  V3d m_res;

private:

  // Typedefs ------------------------------------------------------------------

  //! Convenience typedef for referring to base class
  typedef RefBase base;  

};

//----------------------------------------------------------------------------//
// Utilities
//----------------------------------------------------------------------------//

//! Computes a voxel space bounds given a bounding box in world space.
//! This is done by transforming each corner vertex from world to voxel 
//! space and bounding the result.
void worldToVoxel(const Field3D::FieldMapping* mapping,
                  const Box3d &wsBounds,
                  Box3d &vsBounds);

//----------------------------------------------------------------------------//
// NullFieldMapping
//----------------------------------------------------------------------------//

/*! \class NullFieldMapping
  \ingroup field
  \brief Trivial class, world space is equal to local space, i.e. the field
  is contained in the unit cube [0..1] in all axes.

  Refer to \ref using_mappings for examples of how to use this in your code.
*/

//----------------------------------------------------------------------------//

class FIELD3D_API NullFieldMapping : public FieldMapping
{
public:

  // Typedefs ------------------------------------------------------------------

  //! Convenience typedef
  typedef boost::intrusive_ptr<NullFieldMapping> Ptr;

  // RTTI replacement ----------------------------------------------------------

  typedef NullFieldMapping class_type;
  DEFINE_FIELD_RTTI_CONCRETE_CLASS;
  
  static const char* staticClassType()
  {
    return "NullFieldMapping";
  }

  // Ctors, dtor ---------------------------------------------------------------

  //! \name Constructors & destructor
  //! \{

  NullFieldMapping()
    : FieldMapping()
  { /* Empty */ }
  NullFieldMapping(const Box3i &extents)
    : FieldMapping(extents)
  { /* Empty */ }

  //! \}

  // From FieldMapping ---------------------------------------------------------

  //! \name From FieldMapping
  //! \{

  virtual void worldToVoxel(const V3d &wsP, V3d &vsP) const 
  { localToVoxel(wsP, vsP); }
  virtual void worldToVoxel(const V3d &wsP, V3d &vsP, float /*time*/) const 
  { localToVoxel(wsP, vsP); }

  virtual void voxelToWorld(const V3d &vsP, V3d &wsP) const 
  { voxelToLocal(vsP, wsP); }
  virtual void voxelToWorld(const V3d &vsP, V3d &wsP, float /*time*/) const 
  { voxelToLocal(vsP, wsP); }

  virtual void worldToLocal(const V3d &wsP, V3d &lsP) const 
  { lsP = wsP; }
  virtual void worldToLocal(const V3d &wsP, V3d &lsP, float /*time*/) const 
  { lsP = wsP; }

  virtual void localToWorld(const V3d &lsP, V3d &wsP) const 
  { wsP = lsP; }
  virtual void localToWorld(const V3d &lsP, V3d &wsP, float /*time*/) const 
  { wsP = lsP; }

  virtual std::string className() const;

  virtual bool isIdentical(FieldMapping::Ptr other, 
                           double tolerance = 0.0) const;

  virtual V3d wsVoxelSize(int /*i*/, int /*j*/, int /*k*/) const
  { return V3d(1.0 / m_res.x, 1.0 / m_res.y, 1.0 / m_res.z); }

  virtual FieldMapping::Ptr clone() const;

  //! \}
  
private:

  // Typedefs ------------------------------------------------------------------

  //! Convenience typedef for referring to base class
  typedef FieldMapping base;  

};

//----------------------------------------------------------------------------//
// MatrixFieldMapping
//----------------------------------------------------------------------------//

/*! \class MatrixFieldMapping
  \ingroup field
  \brief Represents the mapping of a field by a matrix transform

  Refer to \ref using_mappings for examples of how to use this in your code.

  \note Regarding time-varying matrices. If setLocalToWorld(M44d) is called,
  an underlying Curve object is created with just one sample at time=0.0.

  \todo Add calls for easily specifying the transform given grid size,
  offset, rotation, etc.
*/

//----------------------------------------------------------------------------//

class FIELD3D_API MatrixFieldMapping : public FieldMapping
{
public:

  // Typedefs ------------------------------------------------------------------

  //! Convenience typedef
  typedef boost::intrusive_ptr<MatrixFieldMapping> Ptr;
  //! Time-varying matrix
  typedef Curve<Imath::M44d> MatrixCurve;

  // RTTI replacement ----------------------------------------------------------

  typedef MatrixFieldMapping class_type;
  DEFINE_FIELD_RTTI_CONCRETE_CLASS;
  
  static const char* staticClassType()
  {
    return "MatrixFieldMapping";
  }

  // Ctors, dtor ---------------------------------------------------------------

  //! \name Constructors & destructor
  //! \{

  MatrixFieldMapping();
  MatrixFieldMapping(const Box3i &extents);

  //! \}

  // Main methods --------------------------------------------------------------
  
  //! Sets the local to world transform. All other matrices will be updated
  //! based on this.
  //! \note This resets the Curve to contain just one sample at time=0.0
  void setLocalToWorld(const M44d &lsToWs);
  //! Sets the local to world transform at a given time.
  void setLocalToWorld(float t, const M44d &lsToWs);

  //! Returns a reference to the local to world transform. 
  //! \note This assumes the query to be at time=0.0
  const M44d& localToWorld() const
  { return m_lsToWs; }

  //! Returns a reference to the world to voxel space transform. 
  //! \note This assumes the query to be at time=0.0
  const M44d& worldToVoxel() const
  { return m_wsToVs; }

  //! Returns a reference to the voxel to world space transform. 
  //! \note This assumes the query to be at time=0.0
  const M44d& voxelToWorld() const
  { return m_vsToWs; }

  //! Returns a vector of all motion samples for local to world transform.
  const MatrixCurve::SampleVec& localToWorldSamples() const
  { return m_lsToWsCurve.samples(); } 

  //! Sets the transform to identity. This makes it functionally equivalent to
  //! a NullFieldMapping.
  void makeIdentity();

  // From FieldMapping ---------------------------------------------------------

  //! \name From FieldMapping
  //! \{

  virtual void worldToVoxel(const V3d &wsP, V3d &vsP) const 
  { m_wsToVs.multVecMatrix(wsP, vsP); }
  virtual void worldToVoxel(const V3d &wsP, V3d &vsP, float time) const 
  { 
    if (!m_isTimeVarying) {
      m_wsToVs.multVecMatrix(wsP, vsP);
    } else {
      M44d wsToVs = m_vsToWsCurve.linear(time).inverse();
      wsToVs.multVecMatrix(wsP, vsP);
    }
  }

  virtual void voxelToWorld(const V3d &vsP, V3d &wsP) const 
  { m_vsToWs.multVecMatrix(vsP, wsP); }
  virtual void voxelToWorld(const V3d &vsP, V3d &wsP, float time) const 
  { 
    if (!m_isTimeVarying) {
      m_vsToWs.multVecMatrix(vsP, wsP); 
    } else {
      M44d vsToWs = m_vsToWsCurve.linear(time);
      vsToWs.multVecMatrix(vsP, wsP);
    }
  }

  virtual void worldToLocal(const V3d &wsP, V3d &lsP) const 
  { m_wsToLs.multVecMatrix(wsP, lsP); }
  virtual void worldToLocal(const V3d &wsP, V3d &lsP,
                            float time) const 
  { 
    if (!m_isTimeVarying) {
      m_wsToLs.multVecMatrix(wsP, lsP); 
    } else {
      M44d wsToLs = m_lsToWsCurve.linear(time).inverse();
      wsToLs.multVecMatrix(wsP, lsP);
    }
  }

  virtual void localToWorld(const V3d &lsP, V3d &wsP) const 
  { m_lsToWs.multVecMatrix(lsP, wsP); }
  virtual void localToWorld(const V3d &lsP, V3d &wsP, float time) const 
  { 
    if (!m_isTimeVarying) {
      m_lsToWs.multVecMatrix(lsP, wsP); 
    } else {
      M44d lsToWs = m_lsToWsCurve.linear(time);
      lsToWs.multVecMatrix(lsP, wsP);
    }
  }

  //! \todo Generalize and make time-dependent.
  void worldToVoxelDir(const V3d &wsV, V3d &vsV) const 
  { m_wsToVs.multDirMatrix(wsV, vsV); }

  //! \todo Generalize and make time-dependent.
  void voxelToWorldDir(const V3d &vsV, V3d &wsV) const 
  { m_vsToWs.multDirMatrix(vsV, wsV); }

  //! \todo Generalize and make time-dependent.
  void worldToLocalDir(const V3d &wsV, V3d &lsV) const 
  { m_wsToLs.multDirMatrix(wsV, lsV); }

  //! \todo Generalize and make time-dependent.
  void localToWorldDir(const V3d &lsV, V3d &wsV) const 
  { m_lsToWs.multDirMatrix(lsV, wsV); }

  virtual void extentsChanged();

  virtual std::string className() const;

  virtual bool isIdentical(FieldMapping::Ptr other, 
                           double tolerance = 0.0) const;

  virtual V3d wsVoxelSize(int /*i*/, int /*j*/, int /*k*/) const
  { return m_wsVoxelSize; }

  virtual FieldMapping::Ptr clone() const;

  //! \}
  
private:

  //! Updates the local to world transformation matrix
  void updateTransform();

  //! \todo Unit test this
  void getLocalToVoxelMatrix(M44d &result);

  // Data members -------------------------------------------------------------

  //! Local space to world space
  //! \note This is used only when m_lsToWsCurve has zero or one samples.
  M44d m_lsToWs;
  //! World space to local space
  //! \note This is used only when m_lsToWsCurve has zero or one samples.
  M44d m_wsToLs;
  //! Voxel space to world space
  //! \note This is used only when m_lsToWsCurve has zero or one samples.
  M44d m_vsToWs;
  //! World space to voxel space
  //! \note This is used only when m_lsToWsCurve has zero or one samples.
  M44d m_wsToVs;

  //! Time-varying local to world space transform
  MatrixCurve m_lsToWsCurve;
  //! Time-varying voxel to world space transform
  MatrixCurve m_vsToWsCurve;

  //! Stores whether the curve has more than one time sample.
  //! \note This is set by updateTransform().
  bool m_isTimeVarying;

  //! Precomputed world-space voxel size. Calculations may assume orthogonal
  //! transformation for efficiency
  V3d m_wsVoxelSize;

  // Typedefs ------------------------------------------------------------------

  //! Convenience typedef for referring to base class
  typedef FieldMapping base;  
};

//----------------------------------------------------------------------------//
// FrustumFieldMapping
//----------------------------------------------------------------------------//

/*! \class FrustumFieldMapping
  \ingroup field
  \brief Represents the mapping of a field by a perspective transform

  Refer to \ref using_mappings for examples of how to use this in your code.

  Frustum mappings can use two approaches in determining the distribution
  of "Z slices". By transforming from world space into screen space and using
  the Z component in perspective space, the slices in Z will be distributed
  in world space accordingly. It is also possible to use a uniform distribution
  of Z slices by specifying a near and far clip plane and normalizing the
  camera-space Z distance between those. 

  \note Screen space is defined left-handed as [-1.0,1.0] in all three 
  dimensions

  \note Camera space is defined right-handed with the camera looking down
  negative Z.

  \todo Define local perspective space

  \note Regarding time-varying matrices. If setTransforms() is called,
  an underlying Curve object is created with just one sample at time=0.0.
*/

//----------------------------------------------------------------------------//

class FIELD3D_API FrustumFieldMapping : public FieldMapping
{
public:

  // Typedefs ------------------------------------------------------------------

  //! Convenience typedef
  typedef boost::intrusive_ptr<FrustumFieldMapping> Ptr;
  //! Time-varying matrix
  typedef Curve<Imath::M44d> MatrixCurve;
  //! Time-varying float
  typedef Curve<double> FloatCurve;

  // Exceptions ----------------------------------------------------------------

  DECLARE_FIELD3D_GENERIC_EXCEPTION(BadPerspectiveMatrix, Exc::Exception)

  // Enums ---------------------------------------------------------------------

  //! Enumerates the Z slice distribution. .f3d files will store values as
  //! an int, so be very careful not to change the order of these.
  enum ZDistribution {
    PerspectiveDistribution,
    UniformDistribution
  };

  // RTTI replacement ----------------------------------------------------------

  typedef FrustumFieldMapping class_type;
  DEFINE_FIELD_RTTI_CONCRETE_CLASS;
  
  static const char* staticClassType()
  {
    return "FrustumFieldMapping";
  }

  // Ctors, dtor ---------------------------------------------------------------

  //! \name Constructors & destructor
  //! \{

  FrustumFieldMapping();
  FrustumFieldMapping(const Box3i &extents);

  //! \}

  // Main methods --------------------------------------------------------------
  
  //! Sets the screenToWorld and cameraToWorld transforms. 
  //! All other internal matrices will be updated based on these.
  //! \note This resets the transform Curve instances to contain just one
  //! sample at time=0.0
  //! \param ssToWs See class documentation for definition.
  //! \param csToWs See class documentation for definition.
  void setTransforms(const M44d &ssToWs, const M44d &csToWs);
  //! Sets time-varying screenToWorld and cameraToWorld transforms.
  //! All other internal matrices will be updated based on these.
  //! \param ssToWs See class documentation for definition.
  //! \param csToWs See class documentation for definition.
  void setTransforms(float t, const M44d &ssToWs, const M44d &csToWs);

  //! Sets the z slice distribution
  void setZDistribution(ZDistribution dist)
  { m_zDistribution = dist; }
  //! Returns the z slice distribution
  ZDistribution zDistribution() const
  { return m_zDistribution; }

  //! Returns a reference to the screen to world space transform. 
  //! \note This assumes the query to be at time=0.0
  const M44d screenToWorld() const
  { return m_ssToWsCurve.linear(0.0); }

  //! Returns a reference to the camera to world space transform. 
  //! \note This assumes the query to be at time=0.0
  const M44d cameraToWorld() const
  { return m_csToWsCurve.linear(0.0); }

  //! Returns a vector of all motion samples for screen to world transform.
  const MatrixCurve::SampleVec& screenToWorldSamples() const
  { return m_ssToWsCurve.samples(); } 

  //! Returns a vector of all motion samples for camera to world transform.
  const MatrixCurve::SampleVec& cameraToWorldSamples() const
  { return m_csToWsCurve.samples(); } 

  //! Returns a vector of all motion samples for near plane.
  const FloatCurve::SampleVec& nearPlaneSamples() const
  { return m_nearCurve.samples(); } 

  //! Returns a vector of all motion samples for far plane.
  const FloatCurve::SampleVec& farPlaneSamples() const
  { return m_farCurve.samples(); } 

  //! Returns the near plane
  double nearPlane() const 
  { return m_nearCurve.linear(0.0); }

  //! Returns the far plane
  double farPlane() const
  { return m_farCurve.linear(0.0); }

  //! Resets the transform. Makes a perspective transform at the origin,
  //! looking down the negative Z axis with a 45 degree FOV and square 
  //! projection.
  void reset();

  // From FieldMapping ---------------------------------------------------------

  //! \name From FieldMapping
  //! \{

  virtual void worldToVoxel(const V3d &wsP, V3d &vsP) const;
  virtual void worldToVoxel(const V3d &wsP, V3d &vsP, float time) const;

  virtual void voxelToWorld(const V3d &vsP, V3d &wsP) const;
  virtual void voxelToWorld(const V3d &vsP, V3d &wsP, float time) const;

  virtual void worldToLocal(const V3d &wsP, V3d &lsP) const;
  virtual void worldToLocal(const V3d &wsP, V3d &lsP, float time) const;

  virtual void localToWorld(const V3d &lsP, V3d &wsP) const;
  virtual void localToWorld(const V3d &lsP, V3d &wsP, float time) const;

  virtual void extentsChanged();

  virtual std::string className() const;

  virtual bool isIdentical(FieldMapping::Ptr other, 
                           double tolerance = 0.0) const;

  virtual V3d wsVoxelSize(int i, int j, int k) const;

  virtual FieldMapping::Ptr clone() const;

  //! \}
  
private:

  //! Updates the local to world transformation matrix
  void computeVoxelSize();

  //! \todo Unit test this
  void getLocalToVoxelMatrix(M44d &result);

  //! Clears all Curve data members. Used by setTransforms() to prepare
  //! for the first sample to be added.
  void clearCurves();

  // Data members -------------------------------------------------------------

  //! Slice distribution type
  ZDistribution m_zDistribution;

  //! Time-varying local perspective to world space transform
  //! This is not used in calculations, but rather as the public interface
  //! to the class.
  MatrixCurve m_ssToWsCurve;
  //! Time-varying camera to world space transform
  MatrixCurve m_csToWsCurve;
  //! Time-varying local perspective to world space transform.
  //! Computed from m_ssToWsCurve
  MatrixCurve m_lpsToWsCurve;
  //! Time-varying near plane. Computed from m_lpsToWsCurve
  FloatCurve m_nearCurve;
  //! Time-varying far plane. Computed from m_lpsToWsCurve
  FloatCurve m_farCurve;

  //! Precomputed world-space voxel size. Calculations may assume orthogonal
  //! transformation for efficiency
  std::vector<V3d> m_wsVoxelSize;

  //! Boolean to tell us if the mapping is in its 'default' state.
  //! This is needed because the class has a default configuration where
  //! there is a single sample in all the curves. Once a new transform is
  //! set through setTransforms(), the default samples must be cleared.
  bool m_defaultState;

  // Typedefs ------------------------------------------------------------------

  //! Convenience typedef for referring to base class
  typedef FieldMapping base;

};

//----------------------------------------------------------------------------//

FIELD3D_NAMESPACE_HEADER_CLOSE

//----------------------------------------------------------------------------//

#endif // Include guard