/// <summary> /// Similar to create, with an additional Starting vector (to indicate the lowest position used from Shape). /// </summary> public static Octree <T> Create(IInfiniteShape <T> Shape, Vector <int> Start, int Depth) { if (Depth == 0) { return(Singleton(Shape.Lookup(Start))); } else { int hsize = _Pow2(Depth - 1); Octree <T>[] childrens = new Octree <T> [8]; int i = 0; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { for (int z = 0; z < 2; z++) { childrens[i] = Create(Shape, Vector.Add(Start, new Vector <int>(x * hsize, y * hsize, z * hsize)), Depth - 1); i++; } } } return(HashedRecursiveSpatialStructure <T, Octree <T> > .Get(Depth, childrens)); } }
/// <summary> /// Gets a subsection of the specified shape. /// </summary> public static IBoundedShape <T> Subsection <T>(IInfiniteShape <T> Source, Vector <int> Size, Vector <int> Start) { IDivisibleInfiniteShape <T> dis = Source.Extend <IDivisibleInfiniteShape <T> >(); if (dis != null) { return(dis.Subsection(Start, Size)); } return(new SubsectionShape <T>() { Source = Source, Start = Start, Size = Size }); }
/// <summary> /// Transforms a shape by applying a mapping on all its values. /// </summary> public static IInfiniteShape <F> Transform <T, F>(IInfiniteShape <T> Source, Func <T, F> Mapping) { ITransformableInfiniteShape <T> tis = Source.Extend <ITransformableInfiniteShape <T> >(); if (tis != null) { return(tis.Transform <F>(Mapping)); } return(new TransformedInfiniteShape <T, F>() { Source = Source, Mapping = Mapping }); }
/// <summary> /// Reorients a shape so that the x axis is transformed to the specified axis. /// </summary> public static IInfiniteShape <T> Orient <T>(IInfiniteShape <T> Source, Axis Axis) { IOrientableInfiniteShape <T> ois = Source.Extend <IOrientableInfiniteShape <T> >(); if (ois != null) { return(ois.Orient(Axis)); } return(new OrientedInfiniteShape <T>() { Source = Source, Axis = Axis }); }
/// <summary> /// Produces a surface using the specified source shape and a surfacization function. /// </summary> public static ISurface <F> Form <T, F>(IInfiniteShape <T> Source, Surfacize <T, F> Surfacization) where F : IEquatable <F> { ISurfaceFormableShape <T> sfs = Source.Extend <ISurfaceFormableShape <T> >(); if (sfs != null) { return(sfs.FormSurface <F>(Surfacization)); } return(new FormSurface <T, F>() { Source = Source, Surfacization = Surfacization }); }
/// <summary> /// Creates an octree representation of the data specified in "Shape" with the /// specified depth. /// </summary> public static Octree <T> Create(IInfiniteShape <T> Shape, int Depth) { return(Create(Shape, new Vector <int>(0, 0, 0), Depth)); }