Skip to content
Georg Haaser edited this page Jul 30, 2014 · 11 revisions

Aardvark

Aardvark is a collection of libraries for real-time rendering and visualization developed at the VRVis Research Center since 2006. Since parts of our framework might be helpful for other visualization projects we decided to make them open source. Of course we would also be very happy to see other people contributing to the project. The repository currently contains our base library (Aardvark.Base).

Aardvark.Base is also distributed as a binary package via NuGet. See https://www.nuget.org/packages/Aardvark.Base.

Aardvark.Base

This library contains data types and algorithms commonly used in computer graphics, like

  • basic vector/matrix/color/range types
  • transformation utilities (quaternions, ...)
  • geometric primitives (e.g. triangle, polygon, line, etc.)
  • efficient tensor library (Vector, Matrix, Volume, Tensor4)
  • sorting algorithms (dual-pivot quick sort, timsort, etc.)
  • minimum spanning tree / shortest path / etc.
  • polynomial solver / LU-Factorization / QR-Factorization
  • ...

Quickstart

Vectors

Vector types are named V[dim][type], where dim is one of {2,3,4} and type is one of {i,l,f,d}. E.g. V3d is a 3-dimensional double vector, or V4i is a 4-dimensional int vector.

####Creation

v = new V3d(2,3,4);       // (2, 3, 4)
v = V3d.Zero;             // (0, 0, 0)
v = V3d.XAxis;            // (1, 0, 0)
v = V3d.YAxis;            // (0, 1, 0)
v = V3d.ZAxis;            // (0, 0, 1)
v = V3d.MaxValue;         // (double.MaxValue, double.MaxValue, double.MaxValue)
v = V3d.MinValue;         // (double.MinValue, double.MinValue, double.MinValue)
v = V3d.NegativeInfinity; // (double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity)
v = V3d.PositiveInfinity; // (double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)
v = V3d.NaN;              // (double.NaN, double.NaN, double.NaN)

###Arithmetic Operators

a + b        // component-wise addition
a - b        // component-wise subtraction
a * b        // component-wise multiplication
a / b        // component-wise division
a % b        // component-wise modulo

###Relational Operators

a == b               // component-wise comparison
a != b
a.AllSmaller(b)      // component-wise smaller-than (true if all comparisons are true)
a.AnySmaller(b)      // component-wise smaller-than (true if at least one comparison is true)
...                  // Smaller, SmallerEqual, Greater, GreaterEqual

###Swizzles

V3d v = new V3d(3,4,5);

v.X    -> 3
v.Y    -> 4
v.Z    -> 5
v.XYZ  -> (3,4,5)
v.XXX  -> (3,3,3)
v.YZ   -> (4,5)
v.XZYX -> (3,5,4,3)
v.XYO  -> (3,4,0)
v.IIY  -> (1,1,4)

###Properties and Methods

Properties by default DO NOT change the underlying data (vector), whereas methods usually DO.
E.g. v.Normalized returns a normalized copy of v but does not touch v itself, and v.Normalize() normalizes v itself (and returns this so one can chain method calls).
ATTENTION: since all vector and matrix types are value types returning this returns a copy and DOES NOT reference the original struct.
Properties

v.Length
v.LengthSquared
v.Negated
v.Normalized
v.Reciprocal   // returns component-wise reciprocal (1/x)

###Methods

v.Negate()
v.Normalize()
V3d.DotProduct(a, b)
V3d.CrossProduct(a, b)

###Matrices

Matrix types are named M[dim][type], where dim is one of {22,33,34,44} and type is one of {i,l,f,d}. E.g. M44d is a 4x4 double-precision matrix, or M22i is a 2x2 int matrix.

###Accessors

elements

M00 M01 M02 M03
M10 M11 M12 M13
M20 M21 M22 M23
M30 M31 M32 M33

columns

C0 C1 C2 C3

rows

R0
R1
R2
R3

###Transforming Vectors and Points

Matrices and vectors of the same dimension can be multiplied directly:

V4d v;
M44d m;
V4d r = m * v; // matrix * vector -> vector

In order to multiply 3-dim vectors by a 4x4 matrix (which is often the case in computer graphics) you have to use one of the Transform methods provided by matrix types:

V3d p, v;
M44d m;
V3d a = m.TransformPos(p);  // w-component assumed to be 1 (location)
V3d b = m.TransformDir(v);  // w-component assumed to be 0 (direction)

A Trafo3d is a Container for two M44d fields, a Matrix and its Inverse

Since it is often a lot easier to maintain the inverse of a matrix as opposed to computing the inverse as necessary, a special object that contains both, a matrix and its inverse, has been created. Thus a Trafo3d contains two M44d members, one called Forward, one called Backward .

Note also, that the multiplication of two M44d structs follows mathematical rules:

M44d m1;
M44d m2;
M44d m = m2 * m1; // transform first by m1, then by m2 !!!

whereas, the multiplication of two Trafo3d objects is defined differently:

Trafo3d t1;
Trafo3d t2;
Trafo3d t = t1 * t2; // transform first by t1, then by t2 !!!

###Geometry

Box[23][ilfd]
Circle2d
Hull3d
Line{2|3}d
Plane3d
Quad{2|3}d
Ray{2|3}d
Sphere3d
Triangle3d
Clone this wiki locally