python_c_extension/_disptools.c
/*!
 * Method to compute a shape descriptor of a segment.
 */
Method to compute a shape descriptor of a segment.
Method to compute a shape descriptor of a segment .
static PyObject *method_shape_descriptor(PyObject *self, PyObject *args)
{
    FLOATING result;
    FLOATING centroid[3];
    FLOATING spacing[3];
    PyArrayObject *image = NULL;
    PyObject *centroid_tuple = NULL, *spacing_tuple = NULL;
    const char *descriptor;
    (void) self;
    if (!PyArg_ParseTuple(args, PY_FMT_SHAPE_DESCRIPTOR, &image, &centroid_tuple, &spacing_tuple, &descriptor)) {
        return NULL;
    }
    if (strcmp(descriptor, CUBENESS) && strcmp(descriptor, OCTAHEDRONESS)) {
        PyErr_Format(PyExc_ValueError, "Invalid shape descriptor '%s'.", descriptor);
        return NULL;
    }
    if (!image || !centroid_tuple || !spacing_tuple) {
        return NULL;
    }
    if (read_triplet(centroid_tuple, centroid, 3, "centroid")) {
        return NULL;
    }
    if (read_triplet(spacing_tuple, spacing, 3, "spacing")) {
        return NULL;
    }
    const int nz = PyArray_DIM(image, 0);
    const int ny = PyArray_DIM(image, 1);
    const int nx = PyArray_DIM(image, 2);
    FLOATING *image_data = (FLOATING*) PyArray_DATA(image);
    ShapeDescriptorFunction shape_descriptor_function = NULL;
    if (!strcmp(descriptor, CUBENESS)) {
        shape_descriptor_function = &cubeness;
    }
    else if (!strcmp(descriptor, OCTAHEDRONESS)) {
        shape_descriptor_function = &octahedroness;
    }
    result = shape_descriptor_function((void*) image_data,
                                       nx, ny, nz,
                                       centroid[0], centroid[1], centroid[2],
                                       spacing[0], spacing[1], spacing[2]);
    return Py_BuildValue(PY_FMT_FLOATING, result);
}
static PyObject * method_shape_descriptor ( PyObject * self , PyObject * args ) { FLOATING result ; FLOATING centroid [ 3 ] ; FLOATING spacing [ 3 ] ; PyArrayObject * image = NULL ; PyObject * centroid_tuple = NULL , * spacing_tuple = NULL ; const char * descriptor ; ( void ) self ; if ( ! PyArg_ParseTuple ( args , PY_FMT_SHAPE_DESCRIPTOR , & image , & centroid_tuple , & spacing_tuple , & descriptor ) ) { return NULL ; } if ( strcmp ( descriptor , CUBENESS ) && strcmp ( descriptor , OCTAHEDRONESS ) ) { PyErr_Format ( PyExc_ValueError , " " , descriptor ) ; return NULL ; } if ( ! image || ! centroid_tuple || ! spacing_tuple ) { return NULL ; } if ( read_triplet ( centroid_tuple , centroid , 3 , " " ) ) { return NULL ; } if ( read_triplet ( spacing_tuple , spacing , 3 , " " ) ) { return NULL ; } const int nz = PyArray_DIM ( image , 0 ) ; const int ny = PyArray_DIM ( image , 1 ) ; const int nx = PyArray_DIM ( image , 2 ) ; FLOATING * image_data = ( FLOATING * ) PyArray_DATA ( image ) ; ShapeDescriptorFunction shape_descriptor_function = NULL ; if ( ! strcmp ( descriptor , CUBENESS ) ) { shape_descriptor_function = & cubeness ; } else if ( ! strcmp ( descriptor , OCTAHEDRONESS ) ) { shape_descriptor_function = & octahedroness ; } result = shape_descriptor_function ( ( void * ) image_data , nx , ny , nz , centroid [ 0 ] , centroid [ 1 ] , centroid [ 2 ] , spacing [ 0 ] , spacing [ 1 ] , spacing [ 2 ] ) ; return Py_BuildValue ( PY_FMT_FLOATING , result ) ; }
Method to compute a shape descriptor of a segment.
Method to compute a shape descriptor of a segment .
/* Parse arguments */ /* Sanity check */ /* Error check */ /* Get the centroid */ /* Get the spacing */ /* Get the shape */ /* Get the data pointers */ /* Select the appropriate function for the algorithm */ /* Call the library function to compute the shape descriptor */