7. geometry — A generic interface to the Coords transformation methods — pyFormex 0.9.1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex 0.9.1 documentation >
- pyFormex reference manual >

# 7. `geometry` — A generic interface to the Coords transformation methods

This module defines a generic Geometry superclass which adds all the possibilities of coordinate transformations offered by the Coords class to the derived classes.

`Classes defined in module geometry`

class `geometry.` `Geometry`

  A generic geometry object allowing transformation of coords sets.

  The Geometry class is a generic parent class for all geometric classes, intended to make the Coords transformations available without explicit declaration. This class is not intended to be used directly, only through derived classes. Examples of derived classes are `Formex`, `Mesh`, `Curve`.

  There is no initialization to be done when constructing a new instance of this class. The class just defines a set of methods which operate on the attribute coords, which should be a Coords object. Most of the transformation methods of the Coords class are thus exported through the Geometry class to its derived classes, and when called, will get executed on the coords attribute. The derived class constructor should make sure that the coords attribute exists, has the proper type and contains the coordinates of all the points that should get transformed under a Coords transformation.

  Derived classes can (and in most cases should) declare a method _set_coords(coords) returning an object that is identical to the original, except for its coords being replaced by new ones with the same array shape.

  The Geometry class provides two possible default implementations:

  - _set_coords_inplace sets the coords attribute to the provided new coords, thus changing the object itself, and returns itself,
  - _set_coords_copy creates a deep copy of the object before setting the coords attribute. The original object is unchanged, the returned one is the changed copy.

  When using the first method, a statement like `B = A.scale(0.5)` will result in both A and B pointing to the same scaled object, while with the second method, A would still be the untransformed object. Since the latter is in line with the design philosophy of pyFormex, it is set as the default _set_coords method. Most derived classes that are part of pyFormex however override this default and implement a more efficient copy method.

  The following `Geometry` methods return the value of the same method applied on the coords attribute. Refer to the correponding `coords.Coords` method for their precise arguments.

  `x()`, `y()`, `z()`, `bbox()`, `center()`, `centroid()`, `sizes()`, `dsize()`, `bsphere()`, `inertia()`, `distanceFromPlane()`, `distanceFromLine()`, `distanceFromPoint()`, `directionalSize()`, `directionalWidth()`, `directionalExtremes()`, `__str__()`.

  The following `Coords` transformation methods can be directly applied to a `Geometry` object or a derived class object. The return value is a new object identical to the original, except for the coordinates, which will have been transformed by the specified method. Refer to the correponding `coords.Coords` method in for the precise arguments of these methods:

  `scale()`, `translate()`, `centered()`, `rotate()`, `shear()`, `reflect()`, `affine()`, `position()`, `cylindrical()`, `hyperCylindrical()`, `toCylindrical()`, `spherical()`, `superSpherical()`, `toSpherical()`, `bump()`, `bump1()`, `bump2()`, `flare()`, `map()`, `map1()`, `mapd()`, `replace()`, `swapAxes()`, `rollAxes()`, `projectOnPlane()`, `projectOnSphere()`, `projectOnCylinder()`, `isopar()`, `transformCS()`, `addNoise()`, `rot()`, `trl()`.

  `nelems`()

    Return the number of elements in the Geometry.

    This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

  `setProp`(prop=None, blocks=None)

    Create or destroy the property array for the Geometry.

    A property array is a rank-1 integer array with dimension equal to the number of elements in the Geometry. Each element thus has its own property number. These numbers can be used for any purpose. They play an import role when creating new geometry: new elements inherit the property number of their parent element. Properties are also preserved on most geometrical transformations.

    Because elements with different property numbers can be drawn in different colors, the property numbers are also often used to impose color.

    Parameters:

    - prop: a single integer value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

      The special value ‘range’ will set the property numbers equal to the element number.

      A value None (default) removes the properties from the Geometry.

    - blocks: a single integer value or a list/array of integer values. If the number of passed values is less than the length of prop, they wil be repeated. If you give more, they will be ignored. Every prop will be repeated the corresponding number of times specified in blocks.

  `toProp`(prop)

    Converts the argument into a legal set of properties for the object.

    The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

  `getCoords`()

    Get the coords data.

    Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

  `level`()

    Return the dimensionality of the Geometry, or -1 if unknown

  `copy`()

    Return a deep copy of the Geometry object.

    The returned object is an exact copy of the input, but has all of its data independent of the former.

  `splitProp`(prop=None)

    Partition a Geometry (Formex/Mesh) according to the values in prop.

    Parameters:

    - prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

    Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

    It prop is None and the the object has no prop attribute, an empty list is returned.

  `scale`(*args, **kargs)

    Apply ‘scale’ transformation to the Geometry object.

    See `coords.Coords.scale()` for details.

  `resized`(size=1.0, tol=1e-05)

    Return a copy of the Geometry scaled to the given size.

    size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

  `translate`(*args, **kargs)

    Apply ‘translate’ transformation to the Geometry object.

    See `coords.Coords.translate()` for details.

  `centered`(*args, **kargs)

    Apply ‘centered’ transformation to the Geometry object.

    See `coords.Coords.centered()` for details.

  `align`(*args, **kargs)

    Apply ‘align’ transformation to the Geometry object.

    See `coords.Coords.align()` for details.

  `rotate`(*args, **kargs)

    Apply ‘rotate’ transformation to the Geometry object.

    See `coords.Coords.rotate()` for details.

  `shear`(*args, **kargs)

    Apply ‘shear’ transformation to the Geometry object.

    See `coords.Coords.shear()` for details.

  `reflect`(*args, **kargs)

    Apply ‘reflect’ transformation to the Geometry object.

    See `coords.Coords.reflect()` for details.

  `affine`(*args, **kargs)

    Apply ‘affine’ transformation to the Geometry object.

    See `coords.Coords.affine()` for details.

  `position`(*args, **kargs)

    Apply ‘position’ transformation to the Geometry object.

    See `coords.Coords.position()` for details.

  `cylindrical`(*args, **kargs)

    Apply ‘cylindrical’ transformation to the Geometry object.

    See `coords.Coords.cylindrical()` for details.

  `hyperCylindrical`(*args, **kargs)

    Apply ‘hyperCylindrical’ transformation to the Geometry object.

    See `coords.Coords.hyperCylindrical()` for details.

  `toCylindrical`(*args, **kargs)

    Apply ‘toCylindrical’ transformation to the Geometry object.

    See `coords.Coords.toCylindrical()` for details.

  `spherical`(*args, **kargs)

    Apply ‘spherical’ transformation to the Geometry object.

    See `coords.Coords.spherical()` for details.

  `superSpherical`(*args, **kargs)

    Apply ‘superSpherical’ transformation to the Geometry object.

    See `coords.Coords.superSpherical()` for details.

  `egg`(*args, **kargs)

    Apply ‘egg’ transformation to the Geometry object.

    See `coords.Coords.egg()` for details.

  `toSpherical`(*args, **kargs)

    Apply ‘toSpherical’ transformation to the Geometry object.

    See `coords.Coords.toSpherical()` for details.

  `bump`(*args, **kargs)

    Apply ‘bump’ transformation to the Geometry object.

    See `coords.Coords.bump()` for details.

  `bump1`(*args, **kargs)

    Apply ‘bump1’ transformation to the Geometry object.

    See `coords.Coords.bump1()` for details.

  `bump2`(*args, **kargs)

    Apply ‘bump2’ transformation to the Geometry object.

    See `coords.Coords.bump2()` for details.

  `flare`(*args, **kargs)

    Apply ‘flare’ transformation to the Geometry object.

    See `coords.Coords.flare()` for details.

  `map`(*args, **kargs)

    Apply ‘map’ transformation to the Geometry object.

    See `coords.Coords.map()` for details.

  `map1`(*args, **kargs)

    Apply ‘map1’ transformation to the Geometry object.

    See `coords.Coords.map1()` for details.

  `mapd`(*args, **kargs)

    Apply ‘mapd’ transformation to the Geometry object.

    See `coords.Coords.mapd()` for details.

  `replace`(*args, **kargs)

    Apply ‘replace’ transformation to the Geometry object.

    See `coords.Coords.replace()` for details.

  `swapAxes`(*args, **kargs)

    Apply ‘swapAxes’ transformation to the Geometry object.

    See `coords.Coords.swapAxes()` for details.

  `rollAxes`(*args, **kargs)

    Apply ‘rollAxes’ transformation to the Geometry object.

    See `coords.Coords.rollAxes()` for details.

  `projectOnPlane`(*args, **kargs)

    Apply ‘projectOnPlane’ transformation to the Geometry object.

    See `coords.Coords.projectOnPlane()` for details.

  `projectOnSphere`(*args, **kargs)

    Apply ‘projectOnSphere’ transformation to the Geometry object.

    See `coords.Coords.projectOnSphere()` for details.

  `projectOnCylinder`(*args, **kargs)

    Apply ‘projectOnCylinder’ transformation to the Geometry object.

    See `coords.Coords.projectOnCylinder()` for details.

  `isopar`(*args, **kargs)

    Apply ‘isopar’ transformation to the Geometry object.

    See `coords.Coords.isopar()` for details.

  `transformCS`(*args, **kargs)

    Apply ‘transformCS’ transformation to the Geometry object.

    See `coords.Coords.transformCS()` for details.

  `addNoise`(*args, **kargs)

    Apply ‘addNoise’ transformation to the Geometry object.

    See `coords.Coords.addNoise()` for details.

  `rot`(*args, **kargs)

    Apply ‘rotate’ transformation to the Geometry object.

    See `coords.Coords.rotate()` for details.

  `trl`(*args, **kargs)

    Apply ‘translate’ transformation to the Geometry object.

    See `coords.Coords.translate()` for details.

  `write`(fil, sep=' ', mode='w')

    Write a Geometry to a .pgf file.

    If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

`Functions defined in module geometry`

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex 0.9.1 documentation >
- pyFormex reference manual >