Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-14 Thread Owen
On Mon, 2 Aug 2004 05:39:09 +
Markus Triska [EMAIL PROTECTED] wrote:

 Hello,
 
 a week or so ago, there was a request on comp.graphics.apps.gimp about the 
 availability of the PS extrude-filter, used for example in this tutorial:

 Current version of the plug-in: http://stud4.tuwien.ac.at/~e0225855/extrude.c
 Horrible picture mentioned: http://stud4.tuwien.ac.at/~e0225855/extrude.png
 



Hello,

This was an interesting plug-in, the latest one more interesting than the first.

Do you intend to have a user Dialogue interface for the plug-in?


-- 
Owen


___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-14 Thread Markus Triska
On Sunday 15 August 2004 12:56 am, you wrote:

 This was an interesting plug-in, the latest one more interesting than the 
first.

Thank you, the current version produces even better results (all sides are 
now drawn in correct order).

 Do you intend to have a user Dialogue interface for the plug-in?

Yes, now that I have got the basics somewhat right, the following parameters 
could be set/changed in a dialog:

*) height of pyramids  / random height? (boolean toggle)
*) size of pyramids 
*) viewing distance 
*) direction of light vector 

(later: pyramids/blocks; don't hide partially visible objects)

I still need to figure out useful default values for the settings (currently 
height = 80, size = 50, distance = 250, light vector = constantly changing to 
test the shading code, in the .c-file on the web it is (1,0,0), but need not 
be normalized).

If you are interested in coding up (parts of) the dialog, just fetch 
the .c-file from the web and insert the code wherever you see fit, I can 
merge your changes later with my own latest version.

The most appealing part of this task is probably the representation of the 
light vector - of course, 3 text-boxes each holding an integer would 
suffice (certainly for the initial version of the plug-in), but you may 
find an easy way to actually show and let users interactively edit the vector 
in pseudo-3D.

Best regards,
Markus.
___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-03 Thread Markus Triska

On Monday 02 August 2004 11:20 pm, you wrote:

 Well, the quick-and-dirty way of doing it would be to select a triangle
 shape and use the GIMP's fill function. :)

This is exactly what I want. For this I

#include libgimp/gimpselection_pdb.h   and
#include libgimp/gimpedit_pdb.h

Is there a drawback of this method or something else I should know (I found
 no core plug-in including a header ending _pdb.h, but I guess this is
 because none uses this)?

 I'm afraid I don't see why there is a lack of locality here: each triangle
 to be filled indeed has locality.  Of course, if the triangle is
 sufficiently small, only one tile needs to be involved.

Yes, each triangle has locality and of course, the whole effect also has
locality (the drawable), but I meant locality with regards to tiles when
using a tile iterator: I see no easy method to set up a tile iterator and
iterate by some constant amount, because no matter how big I make that
amount, there are always cases where triangles will cross a tile
intersection. I did not look at the select and fill code, so I am not sure
(especially wrt anti-aliasing) if a triangle started on tile A can be
continued on tile B without visible jags. When I have the effect working, I
will try such things, but it is not that important for now.

Markus.
___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-03 Thread Markus Triska
On Tuesday 03 August 2004 06:35 pm, Markus Triska wrote:

 This is exactly what I want. For this I

 #include libgimp/gimpselection_pdb.h   and
 #include libgimp/gimpedit_pdb.h

Can anybody beat this amount of stupidity? I just found out that these files 
are included via libgimp/gimp.h.

Markus.
___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-03 Thread Markus Triska
On Tuesday 03 August 2004 05:35 pm, Michael Schumacher wrote:

 May I suggest that you start from the gimp plug-in template? It help you
 to get e.g. the build configurations and the i18n of your plug-in right.


Thank you for this suggestion. I have successfully used the plug-in template 
before and will add i18n and so on later. I currently work only on one single 
file  (which can be conveniently compiled using gimptool), but as soon as I 
add Gtk UI code in a separate file, I will switch to using autotools.

Markus.
___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-03 Thread Michael Schumacher
Markus Triska wrote:
On Tuesday 03 August 2004 06:35 pm, Markus Triska wrote:

This is exactly what I want. For this I
#include libgimp/gimpselection_pdb.h   and
#include libgimp/gimpedit_pdb.h

Can anybody beat this amount of stupidity? I just found out that these files 
are included via libgimp/gimp.h.
May I suggest that you start from the gimp plug-in template? It help you 
to get e.g. the build configurations and the i18n of your plug-in right.

See http://developer.gimp.org for hints.
HTH,
Michael
--
The GIMP  http://www.gimp.org| IRC: irc://irc.gimp.org/gimp
Wiki  http://wiki.gimp.org   | .de: http://gimpforum.de
Sodipodi  http://sodipodi.sf.net | IRC: irc://irc.gimp.org/sodipodi
___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-03 Thread William Skaggs

Actually I would go about this differently:  Start by
making a list of all of the triangles, recording their
vertices.  Then go through the image, and for each pixel,
figure out which triangle is visible there, and render
its color.  I think this would be a lot faster, and it
lets you work with a tile iterator as well.

If you start searching from the center of the image, and
work outward, then the first triangle you find that 
overlies the point will be the one that is visible,
so the search can be done pretty efficiently.  In fact,
there may even be a way of calculating which triangle is
visible above a given pixel without having to do any
searching.

Best,
  -- Bill



 

 
__ __ __ __
Sent via the KillerWebMail system at primate.ucdavis.edu


 
   
___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Extrude-filter and lots of triangles

2004-08-02 Thread Nathan Carl Summers
On Mon, 2 Aug 2004, Markus Triska wrote:

 I'm for now using a quick and terrible hack to fill the triangles (see
 attached source if you are curious) and want to ask:  Which method do
 you recommend to fill lots of triangles from within a plug-in? Is there
 a (fast?) Gimp function for this that I can use, maybe capable of
 anti-aliasing?

Well, the quick-and-dirty way of doing it would be to select a triangle
shape and use the GIMP's fill function. :)

I'm afraid I don't see why there is a lack of locality here: each triangle
to be filled indeed has locality.  Of course, if the triangle is
sufficiently small, only one tile needs to be involved.

Perhaps what you are really saying is that the tile cache needs to be
really large to be effective because there is not much between-triangle
locality.

Rockwalrus

___
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer


[Gimp-developer] Extrude-filter and lots of triangles

2004-08-01 Thread Markus Triska
Hello,

a week or so ago, there was a request on comp.graphics.apps.gimp about the 
availability of the PS extrude-filter, used for example in this tutorial:

http://www.voidix.com/cystal.html

I spent a couple of hours working on a GIMP equivalent and I am attaching a 
horrible sample picture created with the plug-in as it stands so far (it 
currently uses random values for the colours of the pyramids and knows 
nothing about anti-aliasing). I'm for now using a quick and terrible hack to 
fill the triangles (see attached source if you are curious) and want to ask: 
Which method do you recommend to fill lots of triangles from within a 
plug-in? Is there a (fast?) Gimp function for this that I can use, maybe 
capable of anti-aliasing?

I think there is no obvious way to use tile iterators for this effect (little 
spatial locality), I am currently (g|s)etting the whole image at once - would 
you recommend that I get and set a region for each triangle I draw or some 
better compromise? I have not tried it yet -  could it be too slow if there 
are very many triangles, or slower than the swapping that could happen when 
processing the whole image at once? I'm asking this because I could only 
benchmark on my own system, which hardly is representative.

Best regards,
Markus.

External links:
Current version of the plug-in: http://stud4.tuwien.ac.at/~e0225855/extrude.c
Horrible picture mentioned: http://stud4.tuwien.ac.at/~e0225855/extrude.png
attachment: extrude.png/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* Plug-in (eventually) implementing Photoshop's Extrude effect
   Written by Markus Triska [EMAIL PROTECTED]
   August 2nd, 2004 - far from finished, just started working on it */



#include stdio.h
#include stdlib.h

#include libgimp/gimp.h



static void  query  (void);
static void  run(const char*name,
			 gint   nparams,
			 const GimpParam*param,
			 gint  *nreturn_vals,
			 GimpParam   **return_vals);

static void  extrude_render (GimpDrawable *drawable);

struct MemImage {
  long bpp;
  guchar *data;
  gint width, height, halfwidth, halfheight;
} theimage;


typedef struct pyramid_tag {
  GimpVector3 triangles[4][3]; /* four triangles */
  GimpRGB colours[4];
  int order[4];
} Pyramid;


GimpPlugInInfo PLUG_IN_INFO =
{
  NULL,  /* init_proc  */
  NULL,  /* quit_proc  */
  query, /* query_proc */
  run,   /* run_proc   */
};



void 
lines_intersection(GimpVector2 p1, GimpVector2 p2,
		GimpVector2 p3, GimpVector2 p4,
		GimpVector2 *intersectionpoint)
{

  float a1,b1,c1,  /* constants of linear equations */
a2,b2,c2,
det_inv,  /*  the inverse of the determinant of the coefficient */
m1,m2;/* the slopes of each line */

  /* compute slopes, note the kludge for infinity, however, this will
 be close enough */

  if ((p2.x-p1.x)!=0)
m1 = (p2.y-p1.y)/(p2.x-p1.x);
  else
m1 = (float)1e+10;   /* close enough to infinity */

  if ((p4.x-p3.x)!=0)
m2 = (p4.y-p3.y)/(p4.x-p3.x);
  else
m2 = (float)1e+10;   /* close enough to infinity */

  /* compute constants */

  a1 = m1;
  a2 = m2;
  
  b1 = -1;
  b2 = -1;
  
  c1 = (p1.y-m1*p1.x);
  c2 = (p3.y-m2*p3.x);

  /* compute the inverse of the determinant */

  det_inv = 1/(a1*b2 - a2*b1);

  /* use Cramer's rule to compute x and y */

  intersectionpoint-x=((b1*c2 - b2*c1)*det_inv);
  intersectionpoint-y=((a2*c1 - a1*c2)*det_inv);

}



static void 
fill_triangle(struct MemImage memimg, GimpVector2 *points, GimpRGB rgb)
{

  GimpVector2 tempvector,intersec1,intersec2;
  gint curr_y, sortruns = 0;

  if ((points[0].y == points[1].y)  (points[1].y == points[2].y)) return;

  /* 
 We enforce the following order on the points:
 (a) non-decreasing y coordinates
 (b) for y1 == y2, the point with lower x comes first

 This leaves 4 types of triangles to handle:

 0  10 0  0
    / \   /|  |\
 | /   /   \   1 / |  | \ 1
 |/   |-\\ |  | /
 2   1  2 \|22|/
  */

  GimpVector2 sortedpoints[3];
  sortedpoints[0] = points[0]; sortedpoints[1] = points[1];
  sortedpoints[2] = points[2];
  
  for