The Big Bad G'MIC Thread of Silly Questions

Low? Why not write iterative commands instead?

Easier to debug, and G’MIC seems to fit the iterative model better.

Even in the Python community where there are more people that use recursive coding, and the level permitted is higher will support iterative approach instead.

64 stack slots (aka ‘scopes’), 0 ⇒ 63, no?

  1. slot 0: belongs to the interpreter. That’s maps to the scope to the left of / (it’s invisible).
  2. slot 1: associated with /, is the scope to the right of ‘/’ and associated with the pipeline that has been typed after $gmic. That pipeline invokes custom command foo inducing a second scope elevation.
  3. slot 2: associated with /foo echos its argument, 0, but is misinformed. It is running two scope levels behind what’s to the left of /.

61 + 2 = 63.

So I think throwing an exception at scope level 63, mislabeled 61, is fine. Or am I cheating by claiming a scope to the left of /?

(Nothing to do with the previous “scopes” question)

Is there a way to add images to a stored selection, during a loop, instead of replacing it?

For now i’m just doing this, which is probably not the best thing to do :


repeat 10 { sp =>. SEL store[SEL] 1,SEL$> }
# i could probably just use store after this loop 
# but in my case it would just be useless, 
# as i may just as well keep the images in the list

*stuff happening*

# retrieve the SEL list
repeat 10 { ${SEL$>} }
# and above i wish i could just do : $SEL
# to retrieve the whole list, but since store is in a loop, i can't. 

blend[SEL] alpha

*do more stuff...*

Or maybe something like this could work?

# input $SEL each time?
repeat 10 { $SEL sp =>. SEL store[SEL] 1,SEL } 

$SEL # retrieve all

edit : obviously doesn’t work. i’m now trying to find out how i can make this work : if $SEL $SEL fi (with $SEL being a stored image (list) )

I guess i can only do something like this (forget about compression during the loop though, very slow, but i can compress the whole list at the end) :
gmic run 'stored=0 repeat 5 if $stored $SMP fi sp =>. SAMPLE store[SAMPLE] SMP stored+=1 done $SMP store 1,SMP'
ain’t that ugly? :slight_smile:

To add a image to store, you can do something like this within loop: img_count=$! $stored sp cat store[$img_count--1] stored

1 Like

Thanks, but if i don’t add stored=0 to your example i get an error when retrieveing $stored the first time.
Unknown command or filename ''; did you mean '%'?
But doing so, it adds an empty image to the stored list (that i can remove anyway).

Yes, but it is not recommended, for performance reasons.
A working solution (not recommended!) would be :

list=
repeat 20 {
  l[] { 
    if narg($list) $list fi # Get previous list stored, if it exists
    sp ? 
    store list
  }
}
$list

But clearly, it becomes really slow as you insert new images in your list. Why ? Because store has to “convert” your whole (growing) list of images into a G’MIC variable each time you invoke it.
And this is too bad because most of your image data are actually already there, in the variable.
So, this technique is not recommended, definitely.

So, what’s the possible workarounds ?

  • If the images have the same size, it may be interesting to stack them in a 3D volumetric image (depth>1). Particularly, if you know how many images you will get at the end, you can pre-allocate a 3D image with the correct size, then just use command draw to put each new image in each slice
    (or alternatively you can stack those images along the c-axis if they are scalar images).

  • It the images have different sizes, then you could just insert them in the image list between some named positions so you can be sure you know exactly where it starts and where it ends. Like:

foo :
  0x2 => begin,end

  repeat 20 {
    sp ?
    mv. $end
  }

  # Here, you know that your images are located between indices $begin and $end.
  # So you can do a unique store to save them.
  store[{$begin+1}-{$end-1}] list

In the end, a simple blend alpha works just as well for me (i can’t let these images eat so much ram)!
I’ll revert to the store command if i ever need to modify these images (shadows) separately . I’ll try to modify them before this step if i can (some shadows need to be shifted to simulate depth. All this is kinda tricky).

Yes, performance really suffers if i use compression with store, but without it’s ok i think. Just probably not needed in my case.

Is it possible to change the origin or pivot point of a (group of) 3d object(s)?

(I guess i have to move it/them to the pivot point?)

Yes basically:

-3d[obj] $x,$y,$z rotate3d[obj] 1,0,0,90 +3d[obj] $x,$y,$z

where $x,$y,$z is your pivot point.

1 Like

Thanks, saved me a few operations for… this :sweat_smile:

It’s still hard to find out where the pivot point should be though.
Is there an easy way to find vertices coordinates?

Yes, it’s not always easy to find the right position in space.

foo :
  box3d 1,0.3,0.02 c3d. +3d. 0,0,-0.5 repeat 3 { +r3d. 0,1,0,90 } +3d[-4--1]

G’MIC is not really intended to be a 3D mesh modeler though :slight_smile:
I’ve added basic 3D capabilities basically to visualize simple things related to volumetric images.

1 Like

Whoops. Too late. Took me some time to figure that out though.

It’s not a modeller, but brick building with primitives is ok :wink: Never tried this with a script before, but i think G’mic can do some nice stuff already.

Another quick question : I know i can show the outline with the “O” key in the display window, but how can i add it to snapshot3d?
Should i just cheat it with primitives3d and blend 2 snapshots (and a bit of dilate/erode)?

BTW your example is what i was looking to do. Only need to add something in the corners.

There’s that rendering thing? How do you map textures into say a cube. I’d like to render my 3D Menger variant, and I have a funny idea to try to make it the Borg cube.

As I’ve been bedridden with strong back pains for 4 days now (couldn’t stand up), i got so bored i started G’micing a little bit.
I absolutely don’t know what i’m doing but i like what i’m getting with isosurface3d:



isosurface3d '"
(cos(y) * sin(x) * 0.5 + x^2 * x + cos(y) * z * -z ) * 2"',.3,-15,-15,-15,15,15,15,8,64,64
c3d. n3d. 
m3d. 3 d0.

Not sure what i could use this for though.
Can someone point me towards some website(s) with cool formulas to mess with?

1 Like

I wish G’MIC had better 3D rendering capacity, it would be a interesting space to explore.

Oh but i kinda always liked the flat shaded look of low poly 3d models anyway. It just needs cast shadows. But sure, for some reason, i’d rather use G’mic than trying to learn Povray…
Probably because i can make filters with G’mic, so it’s not totally a waste of time :slight_smile:

EDIT : Here’s some space debris :


2 Likes

Hi, feeling a bit better now but still hurts to pick up stuff on a table…

Anyway, i started playing lego again :




I guess you could call this an imperfect parametric castle part?
It’s built wirth a few variables for Size, Height, Brick W/H/Z…
I also made it so the walls look a bit “used” and uneven. Yes, crazy me.
I’m trying to find the right formula to create the cylinders at the right size / position in the corners for each case (size, height)… kinda tricky.

BTW, is there a reason why cylinder3d and cone3d are not facing up upon creation? I have to rotate them 90°.

3 Likes

Speaking of random questions… this has probably been asked before, but is there a built-in variable which returns the current 1D buffer index within a fill for example?

I’ve always just calculated it from x,y,z, but it might be needless cpu time - is there such a thing?

Absolutely, using function c2o() (_a.k.a coordinates to offset), like:

$ gmic 100,100,1,1,"c2o(x,y,z,c)"

PS : Function o2c() also exists.

1 Like

Is it possible to separate assembled (with +3d) 3d objects to change their colors?
I don’t know how to use t3d coordinates. Tried to use split3d then [5] as coords but i’m not sure if it’s meant for this.

Maybe it’s possible to “mess” with the “colors” image given by split3d ?