---
name: "Extract"
section: "3"
platform: "linux"
package: "libvolpack1-dev"
version: "1.0b3-10"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Extract"
---

# Extract(3)

extract one field from a rectangular region of a volume

## NAME

vpExtract - extract one field from a rectangular region of a volume

## SYNOPSIS

\#include \<volpack.h\>

vpResult

**vpExtract(***vpc, volume\_type, x0, y0, z0, x1, y1, z1, field, dst,* *dst\_size, dst\_xstride, dst\_ystride, dst\_zstride***)**

-

  vpContext \**vpc;*

-

  int *volume\_type;*

-

  int *x0, y0, z0;*

-

  int *x1, y1, z1;*

-

  int *field;*

-

  void \**dst;*

-

  int *dst\_size;*

-

  int *dst\_xstride, dst\_ystride, dst\_zstride;*

## ARGUMENTS

- *vpc*

  VolPack context from **vpCreateContext.**

- *volume\_type*

  A code indicating which volume data structure to extract the region from (VP\_RAW\_VOLUME, VP\_CLASSIFIED\_VOLUME, VP\_CLX\_VOLUME, VP\_CLY\_VOLUME or VP\_CLZ\_VOLUME)

- *x0, y0, z0*

  Origin of the extracted region in the voxel array.

- *x1, y1, z1*

  Opposite corner of the extracted region in the voxel array.

- *field*

  A voxel field number identifying the field to extract, or one of these special codes: VP\_OPACITY\_FIELD, VP\_CORRECTED\_OPAC\_FIELD, VP\_COLOR\_FIELD.

- *dst*

  Destination array.

- *dst\_size*

  Size of destination array in bytes.

- *dst\_xstride, dst\_ystride, dst\_zstride*

  Strides (in bytes) for the X, Y and Z dimensions of the destination array.

## DESCRIPTION

**vpExtract** is used to extract one field from a rectangular region of the 3D voxel array or the preclassified volume and store the result in a separate array.  It is also possible to retrieve computed voxel opacities or colors.

The *volume\_type* argument is used to choose which data structure the region should be extracted from.  The choices are:

- VP\_RAW\_VOLUME

  Extract from the 3D voxel array (see vpSetRawVoxels(3)).

- VP\_CLASSIFIED\_VOLUME

  Extract from the preclassified volume (see vpClassifyVolume(3)).  The are three copies of the voxel data in the preclassified volume, one for each principal viewing axis.  The copy which will result in the fastest access (best memory stride) is selected.

- VP\_CLX\_VOLUME

  Extract from the preclassified volume used for X-axis viewing.

- VP\_CLY\_VOLUME

  Extract from the preclassified volume used for Y-axis viewing.

- VP\_CLZ\_VOLUME

  Extract from the preclassified volume used for Z-axis viewing.

The last three choices for the *volume\_type* argument are usually used only for debugging.

The next six arguments give the coordinates of the corners of the extracted region in the volume.  The coordinates are indexes into the array.

The *field* argument is used to select which voxel field to extract.  Any of the voxel field numbers previously specified with **vpVoxelField** may be specified.  The output array must be sized appropriately for the dimensions of the region and the size of the extracted field.  The following special constants may also be used instead of a voxel field number:

- VP\_OPACITY\_FIELD

  Return voxel opacities for voxels in the indicated region.  If the 3D voxel array is selected then the opacities are computed on-the-fly using the current opacity transfer function.  The minimum opacity threshold is ignored.  If the preclassified volume is selected then the precomputed opacities are extracted.  Opacities below the minimum opacity threshold at the time the volume was classified are set to 0. The output array should have type unsigned char, and the opacities are stored as number between 0 (transparent) and 255 (opaque).

- VP\_CORRECTED\_OPAC\_FIELD

  This option is the same as the VP\_OPACITY\_FIELD option, except that voxel opacities are corrected for the current view transformation.  The opacity transfer function is assumed to produce the opacity of a voxel viewed perpendicular to one face of the volume with no scale factor. If the voxel has been scaled or rotated with respect to the viewer then the apparent opacity must be corrected.

- VP\_COLOR\_FIELD

  Return voxel colors for voxels in the indicated region.  The colors are computed on-the-fly using the current shading, lighting and material parameters.  The output array should have type unsigned char, and each color channel is stored as number between 0 (off) and 255 (full intensity).  The number of color channels per pixels is determined by the current shading parameters.  (Not currently supported for preclassified volumes.)

The remaining arguments specify the output array, its size (for error checking), and the stride for each dimension (to allow padding the end of scanlines or storing the result in a higher-dimension array).

## ERRORS

The normal return value is VP\_OK.  The following error return values are possible:

- VPERROR\_BAD\_VALUE

  The volume coordinates are out of bounds or invalid (x0 \> x1, etc.), or the field number is invalid.

- VPERROR\_BAD\_SIZE

  The destination array size is incorrect.

- VPERROR\_BAD\_VOLUME

  The volume data does not exist.

- VPERROR\_BAD\_OPTION

  The *volume\_type* argument is invalid.

- VPERROR\_BAD\_VOLUME

  The volume size or data is missing or invalid.

- VPERROR\_BAD\_VOXEL

  The voxel fields are incorrectly defined.

- VPERROR\_BAD\_CLASSIFIER

  The opacity transfer function is incorrectly specified.

- VPERROR\_BAD\_SHADER

  The shading parameters have been incorrectly specified.

- VPERROR\_SINGULAR

  One or more of the view transformation matrices is singular.

## SEE ALSO

[VolPack(3)](/VolPack/3.md), vpCreateContext(3)
