123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- /**
- * SECTION:ufo-reader-task
- * @Short_description: Read TIFF and EDF files
- * @Title: reader
- *
- * The reader node loads single files from disk and provides them as a stream
- * The nominal resolution can be decreased by specifying the #UfoLaminoRampTask:x
- * and #UfoLaminoRampTask:y coordinates, and the #UfoLaminoRampTask:width and
- * #UfoLaminoRampTask:height of a region of interest.
- */
- #include <gmodule.h>
- #include <stdlib.h>
- #include <string.h>
- #include <glob.h>
- #ifdef __APPLE__
- #include <OpenCL/cl.h>
- #else
- #include <CL/cl.h>
- #endif
- #include "ufo-lamino-ramp-task.h"
- struct _UfoLaminoRampTaskPrivate {
- guint width;
- guint height;
- guint fill_width;
- gfloat theta;
- gfloat tau;
- cl_kernel kernel;
- gboolean done;
- };
- static void ufo_task_interface_init (UfoTaskIface *iface);
- G_DEFINE_TYPE_WITH_CODE (UfoLaminoRampTask, ufo_lamino_ramp_task, UFO_TYPE_TASK_NODE,
- G_IMPLEMENT_INTERFACE (UFO_TYPE_TASK,
- ufo_task_interface_init))
- #define UFO_LAMINO_RAMP_TASK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_LAMINO_RAMP_TASK, UfoLaminoRampTaskPrivate))
- enum {
- PROP_0,
- PROP_WIDTH,
- PROP_FILL_WIDTH,
- PROP_HEIGHT,
- PROP_THETA,
- PROP_TAU,
- N_PROPERTIES
- };
- static GParamSpec *properties[N_PROPERTIES] = { NULL, };
- UfoNode *
- ufo_lamino_ramp_task_new (void)
- {
- return UFO_NODE (g_object_new (UFO_TYPE_LAMINO_RAMP_TASK, NULL));
- }
- static int
- is_power_of_two (guint x)
- {
- return ((x != 0) && !(x & (x - 1)));
- }
- static void
- ufo_lamino_ramp_task_setup (UfoTask *task,
- UfoResources *resources,
- GError **error)
- {
- UfoLaminoRampTask *node;
- UfoLaminoRampTaskPrivate *priv;
- node = UFO_LAMINO_RAMP_TASK (task);
- priv = node->priv;
- if (!is_power_of_two (priv->width)) {
- g_set_error (error, UFO_TASK_ERROR, UFO_TASK_ERROR_SETUP,
- "Filter width `%i' is not a power of two", priv->width);
- return;
- }
- if (!is_power_of_two (priv->height)) {
- g_set_error (error, UFO_TASK_ERROR, UFO_TASK_ERROR_SETUP,
- "Filter height `%i' is not a power of two", priv->height);
- return;
- }
- priv->kernel = ufo_resources_get_kernel (resources,
- "lamino_ramp.cl",
- "lamino_ramp_create_filter",
- error);
- if (priv->kernel != NULL) {
- UFO_RESOURCES_CHECK_CLERR (clRetainKernel (priv->kernel));
- }
- }
- static void
- ufo_lamino_ramp_task_get_requisition (UfoTask *task,
- UfoBuffer **inputs,
- UfoRequisition *requisition)
- {
- UfoLaminoRampTaskPrivate *priv;
- priv = UFO_LAMINO_RAMP_TASK_GET_PRIVATE (UFO_LAMINO_RAMP_TASK (task));
- requisition->n_dims = 2;
- requisition->dims[0] = priv->width;
- requisition->dims[1] = priv->height;
- }
- static guint
- ufo_lamino_ramp_task_get_num_inputs (UfoTask *task)
- {
- return 0;
- }
- static guint
- ufo_lamino_ramp_task_get_num_dimensions (UfoTask *task,
- guint input)
- {
- return 0;
- }
- static UfoTaskMode
- ufo_lamino_ramp_task_get_mode (UfoTask *task)
- {
- return UFO_TASK_MODE_GENERATOR | UFO_TASK_MODE_GPU;
- }
- static gboolean
- ufo_lamino_ramp_task_generate (UfoTask *task,
- UfoBuffer *output,
- UfoRequisition *requisition)
- {
- UfoLaminoRampTaskPrivate *priv;
- UfoGpuNode *node;
- cl_command_queue cmd_queue;
- cl_mem out_mem;
- priv = UFO_LAMINO_RAMP_TASK_GET_PRIVATE (UFO_LAMINO_RAMP_TASK (task));
- if (priv->done)
- return FALSE;
- node = UFO_GPU_NODE (ufo_task_node_get_proc_node (UFO_TASK_NODE (task)));
- cmd_queue = ufo_gpu_node_get_cmd_queue (node);
- out_mem = ufo_buffer_get_device_array (output, cmd_queue);
- UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 0, sizeof(cl_mem), (void *) &out_mem));
- UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 1, sizeof(int), &priv->width));
- UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 2, sizeof(int), &priv->fill_width));
- UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 3, sizeof(int), &priv->height));
- UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 4, sizeof(float), &priv->theta));
- UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 5, sizeof(float), &priv->tau));
- UFO_RESOURCES_CHECK_CLERR (clEnqueueNDRangeKernel (cmd_queue, priv->kernel,
- 2, NULL, requisition->dims, NULL,
- 0, NULL, NULL));
- priv->done = TRUE;
- return TRUE;
- }
- static void
- ufo_lamino_ramp_task_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
- {
- UfoLaminoRampTaskPrivate *priv = UFO_LAMINO_RAMP_TASK_GET_PRIVATE (object);
- switch (property_id) {
- case PROP_WIDTH:
- priv->width = g_value_get_uint (value);
- break;
- case PROP_FILL_WIDTH:
- priv->fill_width = g_value_get_uint (value);
- break;
- case PROP_HEIGHT:
- priv->height = g_value_get_uint (value);
- break;
- case PROP_THETA:
- priv->theta = (gfloat) g_value_get_double (value);
- break;
- case PROP_TAU:
- priv->tau = (gfloat) g_value_get_double (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
- }
- static void
- ufo_lamino_ramp_task_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
- {
- UfoLaminoRampTaskPrivate *priv = UFO_LAMINO_RAMP_TASK_GET_PRIVATE (object);
- switch (property_id) {
- case PROP_WIDTH:
- g_value_set_uint (value, priv->width);
- break;
- case PROP_FILL_WIDTH:
- g_value_set_uint (value, priv->fill_width);
- break;
- case PROP_HEIGHT:
- g_value_set_uint (value, priv->height);
- break;
- case PROP_THETA:
- g_value_set_double (value, priv->theta);
- break;
- case PROP_TAU:
- g_value_set_double (value, priv->tau);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
- }
- static void
- ufo_lamino_ramp_task_finalize (GObject *object)
- {
- UfoLaminoRampTaskPrivate *priv = UFO_LAMINO_RAMP_TASK_GET_PRIVATE (object);
- if (priv->kernel != NULL) {
- clReleaseKernel (priv->kernel);
- priv->kernel = NULL;
- }
- G_OBJECT_CLASS (ufo_lamino_ramp_task_parent_class)->finalize (object);
- }
- static void
- ufo_task_interface_init (UfoTaskIface *iface)
- {
- iface->setup = ufo_lamino_ramp_task_setup;
- iface->get_num_inputs = ufo_lamino_ramp_task_get_num_inputs;
- iface->get_num_dimensions = ufo_lamino_ramp_task_get_num_dimensions;
- iface->get_mode = ufo_lamino_ramp_task_get_mode;
- iface->get_requisition = ufo_lamino_ramp_task_get_requisition;
- iface->generate = ufo_lamino_ramp_task_generate;
- }
- static void
- ufo_lamino_ramp_task_class_init (UfoLaminoRampTaskClass *klass)
- {
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->set_property = ufo_lamino_ramp_task_set_property;
- gobject_class->get_property = ufo_lamino_ramp_task_get_property;
- gobject_class->finalize = ufo_lamino_ramp_task_finalize;
- properties[PROP_WIDTH] =
- g_param_spec_uint("width",
- "Width of the 2D image filter (power of 2)",
- "Width of the 2D image filter (power of 2)",
- 1, 32768, 1.0,
- G_PARAM_READWRITE);
- properties[PROP_FILL_WIDTH] =
- g_param_spec_uint("fwidth",
- "Filling width of the 2D image filter",
- "Filling width of the 2D image filter",
- 1, 32768, 1.0,
- G_PARAM_READWRITE);
- properties[PROP_HEIGHT] =
- g_param_spec_uint("height",
- "Height of the 2D image filter",
- "Height of the 2D image filter",
- 1, 16384, 1.0,
- G_PARAM_READWRITE);
- properties[PROP_THETA] =
- g_param_spec_double("theta",
- "Laminographic angle in radians",
- "Resolution (pixel size) in microns",
- -4.0 * G_PI, +4.0 * G_PI, 0.0,
- G_PARAM_READWRITE);
- properties[PROP_TAU] =
- g_param_spec_double("tau",
- "Resolution (pixel size) in microns",
- "Resolution (pixel size) in microns",
- 0.0, /* minimum */
- 100000.0, /* maximum */
- 10.0, /* default */
- G_PARAM_READWRITE);
- for (guint i = PROP_0 + 1; i < N_PROPERTIES; i++)
- g_object_class_install_property (gobject_class, i, properties[i]);
- g_type_class_add_private (gobject_class, sizeof(UfoLaminoRampTaskPrivate));
- }
- static void
- ufo_lamino_ramp_task_init(UfoLaminoRampTask *self)
- {
- UfoLaminoRampTaskPrivate *priv = NULL;
- self->priv = priv = UFO_LAMINO_RAMP_TASK_GET_PRIVATE (self);
- priv->width = 4;
- priv->fill_width=2;
- priv->height = 1;
- priv->theta = 0.0;
- priv->tau = 10.0;
- priv->kernel = NULL;
- priv->done = FALSE;
- }
|