Documentation/Ptc API - PixieWiki

# Documentation/Ptc API

### From PixieWiki

< Documentation

An API has been added which allows both reading and writing of point cloud files. Point clouds can be turned into brickmaps via `texmake -texture3d <in> <out>`, so this also allows an external program to generate brickmaps for efficient rendering of 3d texture data.

To use the API, include `ptcapi.h`, and link with `libri`. The following functions are defined:

# [edit] Reading

## [edit] Open an existing point cloud

    PtcPointCloud PtcOpenPointCloudFile(char *filename, int *nvars, char **vartypes, char **varnames);

Open filename, and retrieve the number of channels defined in the pointcloud. The types (color,float,point,normal,matrix and so on) of each named channel are returned in the varnames array:

    int nv;
    char *types[256];
    char *names[256];
    PtcPointCloud myPtc = PtcOpenPointCloudFile("cloud.ptc", int *nvars, types, names);
    // nv = number of channels
    // types[0] = first channel type
    // names[1] = first channel name

## [edit] Get info on the point cloud

    int PtcGetPointCloudInfo(PtcPointCloud pointcloud, char *request, void *result);

Get information about a previously opened point cloud. Request may be one of:

`"npoints"`
  the number of points in the file
`"bbox"`
  the bounding box of the points
`"datasize"`
  the size in floats of each point (the sum of all channel sizes)
`"world2eye"`
  the world to eye transformation
`"world2ndc"`
  the world to NDC transformation when the file was created

## [edit] Read a single point

    int PtcReadDataPoint(PtcPointCloud pointcloud, float *point, float *normal, float *radius, float *data);

This function will return the next point from a previously opened file `point` (3 floats) will recieve the position, `normal` (3 floats) gets the normal of the point, and the radius of the point is returned in `radius`. The data itself is returned in the `data` array which must be large enough to cope with `datasize` floats.

## [edit] Close the file

    void PtcClosePointCloudFile(PtcPointCloud pointcloud);

Close a previously read-opened file.

# [edit] Writing

## [edit] Create a blank point cloud with nvars channels

    PtcPointCloud PtcCreatePointCloudFile(char *filename, int nvars, char **vartypes, char **varnames,
         float *world2eye, float *world2ndc, float *format);

    Returns a handle to the newly opend file, which has nvars channels, described by vartypes and varnames.  You need to provide the world to eye transform world2eye, a 4x4 matrix of floats.  Also specify world2ndc for the transform to the normalized device coordinate system in which the cloud was generated.  Note that currently this NDC transformation is simply stored for informational purposes.    The format parameter is currently unused.

## [edit] Write a point to the file

    void PtcWriteDataPoint(PtcPointCloud pointcloud, float *point, float *normal, float radius, float *data);

Write `data` with the specified `point`, `radius` and `normal` to the file.

## [edit] Finish an close the file

    void PtcFinishPointCloudFile(PtcPointCloud pointcloud);

Finish and close a file which was opened for writing.

Retrieved from "http://www.george-graphics.co.uk/pixiewiki/Documentation/Ptc_API"

##### Views

- Article
- Discussion
- Edit
- History

##### Personal tools

- Log in / create account

##### Search

##### Toolbox

- What links here
- Related changes
- Upload file
- Special pages
- Printable version
- Permanent link