AKTIVE

attributes.tcl at trunk
Login

attributes.tcl at trunk

File etc/accessor/attributes.tcl artifact 51ce8991c9 on branch trunk


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
   106
   107
   108
   109
   110
   111
   112
   113
   114
   115
   116
   117
   118
   119
   120
   121
   122
   123
   124
   125
   126
   127
   128
   129
   130
   131
   132
   133
   134
   135
   136
   137
   138
   139
   140
   141
   142
   143
   144
   145
   146
   147
   148
   149
   150
   151
   152
   153
   154
   155
   156
   157
   158
   159
   160
   161
   162
   163
   164
   165
   166
   167
   168
   169
   170
   171
   172
   173
   174
   175
   176
   177
   178
   179
   180
   181
   182
   183
   184
   185
   186
   187
   188
   189
   190
   191
   192
   193
   194
   195
   196
   197
   198
   199
   200
   201
   202
   203
   204
   205
   206
   207
   208
   209
   210
   211
   212
   213
   214
   215
   216
   217
   218
   219
   220
   221
   222
   223
   224
   225
   226
   227
   228
   229
   230
   231
   232
   233
   234
   235
   236
   237
   238
   239
   240
   241
   242
   243
   244
   245
   246
   247
   248
   249
   250
   251
   252
   253
   254
   255
   256
   257
   258
   259
   260
   261
   262
   263
   264
   265
   266
   267
   268
   269
   270
   271
   272
   273
   274
   275
   276
   277
   278
   279
   280
   281
   282
   283
   284
   285
   286
   287
   288
   289
   290
   291
   292
   293
   294
   295
   296
   297
   298
   299
   300
   301
   302
   303
   304
   305
   306
   307
   308
   309
   310
   311
   312
   313
   314
   315
   316
   317
   318
   319
   320
   321
   322
   323
   324
   325
   326
   327
   328
   329
   330
   331
   332
   333
   334
   335
   336
   337
   338
   339
   340
   341
   342
   343
   344
   345
   346
   347
   348
   349
   350
   351
   352
   353
   354
   355
   356
   357
   358
   359
   360
   361
   362
   363
## -*- mode: tcl ; fill-column: 90 -*-
# # ## ### ##### ######## ############# #####################
## Getters -- Retrieving image attributes

operator query::id {
    section accessor

    note Returns the input's implementation-specific image identity.

    # Example: makes no sense, would change with each run.
    #
    # This is special. It provides an identification of the image, i.e. a value unique to
    # it. This enables equality comparisons, and nothing else.
    #
    # BEWARE. This is the integerized memory address of the thing, with some whitening to
    # make it not as obvious.

    input

    return wide {
	Tcl_WideInt r = 0x25d94395245495a2 ^ (long int) src ;
	//                0123456789012345
	return r;
    }
}

operator query::type {
    section accessor

    example {
	aktive image zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }

    note Returns the input's type.

    input
    return image-type {
	aktive_image_type* r = aktive_image_get_type (src);
	return r;
    }
}

operator query::location {
    section accessor geometry

    example {
	aktive image zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }

    note Returns the input's location, a 2D point.

    input
    return point {
	aktive_point* r = aktive_image_get_location (src);
	return *r;
    }
}

operator query::domain {
    section accessor geometry

    example {
	aktive image zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }

    note Returns the input's domain, a 2D rectangle. I.e. location, width, and height.

    input
    return rect {
	aktive_rectangle* r = aktive_image_get_domain (src);
	return *r;
    }
}

operator query::geometry {
    section accessor geometry

    # !xref-mark geometry
    example {
	aktive image zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }
    # !xref-mark /end

    note Returns the input's full geometry, i.e. domain and depth.

    input
    return geometry {
	aktive_geometry* r = aktive_image_get_geometry (src);
	return *r;
    }
}

operator description {
    query::x    x
    query::xmax {maximum x}
    query::y    y
    query::ymax {maximum y}
} {
    section accessor geometry
    op -> _ attribute

    example {
	aktive image zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }

    note Returns the input's $description location.

    input

    return int {
	int r = aktive_image_get_@@attribute@@ (src);
	return r;
    }
}

operator description {
    query::width  width
    query::height height
    query::depth  depth
    query::pixels {number of pixels}
    query::pitch  {pitch, the number of values in a row, i.e. width times depth}
    query::size   {size, i.e. the number of pixels times depth}
} {
    section accessor geometry
    op -> _ attribute

    example {
	aktive image zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }

    note Returns the input's ${description}.

    input

    return uint {
	aktive_uint r = aktive_image_get_@@attribute@@ (src);
	return r;
    }
}

operator query::inputs {
    section accessor

    # Example: makes no sense, changes with each run (it is raw stuff)
    # ... Maybe by transforming to type, or something else stable.

    note Returns a list of the input's inputs.

    note For an image without inputs the result is the empty list.

    input

    return object0 {
	aktive_uint c = aktive_image_get_nsrcs (src);
	Tcl_Obj**   v = NALLOC (Tcl_Obj*, c);

	for (aktive_uint i = 0; i < c; i++) {
	  v [i] = aktive_new_image_obj  (aktive_image_get_src (src, i));
	}
	Tcl_Obj* r = Tcl_NewListObj (c, v);
	ckfree ((char*) v);
	return r;
    }
}

operator query::params {
    section accessor

    example {
	aktive image zone width 32 height 32 | -label zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1 | -label gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }

    note Returns a dictionary containing the input's parameters.

    note For an image without parameters the result is the empty dictionary.

    input

    return object0 {
	Tcl_Obj* r = aktive_op_params (ip, src);
	if (!r) { r = Tcl_NewDictObj (); }
	return r;
    }
}

operator query::setup {
    section accessor

    example {
	aktive image zone width 32 height 32 | -label zone width 32 height 32
	@1 | -text
    }
    example {
	aktive image gradient width 32 height 32 depth 1 first 0 last 1
	@1 | -text
    }

    note Returns a dictionary containing the input's setup.

    note This includes type, geometry, and parameters, if any. The inputs however are excluded.

    input

    return object0 {
	Tcl_Obj* r = aktive_op_setup (ip, src);
	return r;
    }
}

operator query::meta {
    section accessor metadata

    example {
	sines
	@1 | -text
    }

    note Returns a dictionary containing the input's meta data.

    input

    return object0 {
	Tcl_Obj* r = aktive_image_meta_get (src);
	if (!r) { r = Tcl_NewDictObj (); }
	return r;
    }
}

operator query::values {
    section accessor values

    example {
	aktive image gradient width 2 height 2 depth 1 first 0 last 1 | times 16
	@1 | -text
    }

    note Returns a list containing the input's pixel values.

    note The values are provided in row-major order.
    note The list has length \"<!xref: aktive query size> \\<src\\>\".

    input

    strict single \
	The image is materialized in memory.

    return object0 {
	Tcl_Obj* r = aktive_op_pixels (ip, src);
	if (r) { return r; }
	if (aktive_error_raised()) { return 0; }
	return Tcl_NewListObj (0, 0);
    }
}

operator query::value::at {
    section accessor values

    example {
	aktive image gradient width 2 height 2 depth 1 first 0 last 1 | times 16
	@1 x 0 y 1 | -text
    }

    note Returns the input's pixel value(s) at the given 2D point.

    note The result is __not__ an image. It is a list of floating point numbers \
	for a multi-band input, and a single floating point number otherwise.

    note Beware that the coordinate domain is `0..width|height`, \
	regardless of image location.

    strict single \
	The requested pixel is materialized in memory.

    input
    int   x	Physical x-coordinate of the pixel to query
    int   y	Physical y-coordinate of the pixel to query

    body {
	set src [aktive op select y $src from $y to $y]
	set src [aktive op select x $src from $x to $x]
	aktive query values $src
    }
}

operator query::value::around {
    section accessor values

    note Returns the input's pixel values for the region around \
	the specified 2D point, within the manhattan `radius`.

    note The result is __not__ an image.

    note Beware that the coordinate domain is `0..width|height`, \
	regardless of image location.

    strict single \
	The requested pixel region is materialized in memory.

    input

    int     x		Physical x-coordinate of the pixel to query
    int     y		Physical y-coordinate of the pixel to query
    uint? 1 radius	Region radius, defaults to 1, i.e. a 3x3 region.

    body {
	lassign [aktive query domain $src] _ _ w h

	if {(($x - $radius) <   0) ||
	    (($x + $radius) >= $w) ||
	    (($y - $radius) <   0) ||
	    (($y + $radius) >= $h) } {
	    aktive error "Unable to query locations outside of the image domain" }

	set x0 [expr {$x - $radius}]
	set x1 [expr {$x + $radius}]
	set y0 [expr {$y - $radius}]
	set y1 [expr {$y + $radius}]

	set src [aktive op select y $src from $y0 to $y1]
	set src [aktive op select x $src from $x0 to $x1]

	aktive query values $src
    }
}

##
# # ## ### ##### ######## ############# #####################
::return