Sign in to follow this  
Followers 0
Ego Eram Reputo

CellMaker (obsolete - use Cellmaker Rev)

25 posts in this topic

This plugin has been superseded by Cellmaker Rev(isited) by zoonel, release date: Dec 06, 2009
you can find it here: Cellmaker Rev

This plugin is very similar to the Gridmaker plugin. It simply makes a grid of cells within a given selection. There are three corner options, hard, soft (corner pixels are removed) and rounded (three of the corner pixels are removed for a rounded look).

[edit]
Thanks to a number of suggestions from Madjik the code has been sped up considerably, hence the new numbering: CellMaker 3.3 replaces all previous versions. Note: The function of the plugin has not altered between versions, only the rendering speed.

CellMaker is now found under the RENDER submenu (Ash's request).


It works like this:

Cellmaker.png

Note: if you really want this plugin, you can find it in my plugin pack http://forums.getpaint.net/index.php?/topic/110145-eers-plugin-pack/

0

Share this post


Link to post
Share on other sites

Cool! this is "new plugin day" or what?

Thanks for the plugin! :D

0

Share this post


Link to post
Share on other sites

Great plugin! I know it has nothing to do with Paint.NET but I muck around with LEGO sometimes and use grids exactely like this to help me make mosaics from scratch so thanks.

0

Share this post


Link to post
Share on other sites
That's cool!

Next one : bee grid ? (hexagonal!)

Hasn't the hexagonal fill plugin already been done?

viewtopic.php?p=26008#p26008

CellMaker v2.0 is a piece of a larger project (codename:Prim - for those intrigued) and is my first foray into C#, so I'll gladly accept criticisms of my code.

0

Share this post


Link to post
Share on other sites
That's cool!

Next one : bee grid ? (hexagonal!)

Hasn't the hexagonal fill plugin already been done?

viewtopic.php?p=26008#p26008

CellMaker v2.0 is a piece of a larger project (codename:Prim - for those intrigued) and is my first foray into C#, so I'll gladly accept criticisms of my code.

I was joking about hexa...

But from coding point of view, the hexagrid plugin is a great piece of code!

____________________

Your actual version is really slow with small grid step...

This is due to your way of coding.

Plugins are really efficient if we use the y,x loops.

You could have a read with a variable x if you stay with the same y.

But if you try to change y, then the running time start to increase.

And the more you change y, the more the process is slow.

The 'rect' in the code is an horizontal part of the source image with only few lines.

If you read with 'y + something' you will ask too often to read outside the 'rect'.

This will create memory usage and slow down the whole process.

I hope I'm clear enough. I'm perhaps not 100% correct but the idea is here.

These are the lines I'm talkng about:

 // Loop through all the cells in the selection
 for ( int x = 0; x < GridWidth; x++ )
 {
   for ( int y = 0; y < GridHeight; y++ )
   {
 ///// y loop should be the first !

if (selectionRegion.IsVisible(Left,Top) && selectionRegion.IsVisible(Right, Top) && selectionRegion.IsVisible(Left, Bottom) && selectionRegion.IsVisible(Right, Bottom))    
///// as top & bottom are variables!

dst[ Left , Top+j ] = PrimaryColor;    // draw left wall
dst[ Right , Top+j ] = PrimaryColor;   // draw right wall

dst[ Left + 1 , Top + 1 ] = PrimaryColor;   // fill in the extra squares
dst[ Right - 1, Top + 1 ] = PrimaryColor;
dst[ Left + 1 , Bottom - 1 ] = PrimaryColor;
dst[ Right - 1 , Bottom - 1 ] = PrimaryColor;    
///// as top & bottom are variables AND you are using +/- 1 !!

A better way to code this should be like:

This version doesn't take care if the corners of each cell are entirely contained within the selection.

// CellMaker v2.0m (modified by MadJik).
//
// Makes a grid of cells inside a given selection. 
// The selection may be more than one area. 
// Cell walls drawn in Primary color.
//  

int Amount1=5;  // [2,255] Cell Width
int Amount2=5;  // [2,255] Cell Height
int Amount3=2;  // [0,2] Corners: Hard, Soft, Rounded
// Soft corners makes subsequent wall removal easier as the corner 
// pixels are not drawn making the four cell walls discontinuous.

void Render(Surface dst, Surface src, Rectangle rect)
{

 //     Other variables
 PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
 Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 
 ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
 ColorBgra Pix;

 int GridWidth, GridHeight, Top, Bottom, Left, Right, CellWidth, CellHeight;

 CellWidth = (int) Amount1 + 1 ;
 CellHeight = (int) Amount2 + 1;
 GridWidth = (int) (dst.Width / CellWidth);
 GridHeight = (int) (dst.Height / CellHeight); 

 //  Clear the canvas in the case of changed parameters
 for(int y = rect.Top; y < rect.Bottom; y++) 
   for (int x = rect.Left; x < rect.Right; x++) 
     dst[x,y] = src[x,y]; 

 // Loop through all the cells in the selection
 for(int y = rect.Top; y < rect.Bottom; y++) 
 {
   Top = (int)( y / CellHeight ) * CellHeight;
   Bottom = Top + CellHeight;
   for (int x = rect.Left; x < rect.Right; x++) 
   {
     // Find the values for each of the cell vertices                   
     Left = (int)( x / CellWidth ) * CellWidth;
     Right = Left + CellWidth;
     Pix = src[x,y];

     // tests for the crossings effects
     switch (Amount3)
     {
       case 0:  // Easy: just test if we are on the grid, draw PrimaryColor
         if ((x==Left)||(x==Right)||(y==Top)||(y==Bottom)) Pix = PrimaryColor;
         break;
       case 1: // Corner level 1, one x or y must be on the grid but not the both!
         int Corner = 0; 
         if ((x==Left)||(x==Right)) ++Corner;
         if ((y==Top)||(y==Bottom)) ++Corner;
         if (Corner==1) Pix = PrimaryColor;
         break;
       case 2: // Corner level 2, more test to define if we need to draw the pixel!
         if ((x==Left)||(x==Right)) { if ((Math.Abs(y - Top)>1)&&(Math.Abs(y - Bottom)>1)) Pix = PrimaryColor; }
         else if ((y==Top)||(y==Bottom)) { if ((Math.Abs(x - Left)>1)&&(Math.Abs(x - Right)>1)) Pix = PrimaryColor; }
         else if (( ( ((y - Top)==1) || ((Bottom - y)==1) ) ) && ( ((x - Left)==1) || ((Right - x)==1) ) ) Pix = PrimaryColor;
         break;
       default:
         break;
     }
     dst[x,y] = Pix;
   }
 }
}   

As I said this version doesn't take care if the corners of each cell are entirely contained within the selection.

I just provide it to show you a good way to use the y,x loops. Up to you now to see how to add the tests for it...

Just because you accept criticisms....

0

Share this post


Link to post
Share on other sites

Your actual version is really slow with small grid step...

This is due to your way of coding.

Plugins are really efficient if we use the y,x loops.

You could have a read with a variable x if you stay with the same y.

But if you try to change y, then the running time start to increase.

And the more you change y, the more the process is slow.

The 'rect' in the code is an horizontal part of the source image with only few lines.

If you read with 'y + something' you will ask too often to read outside the 'rect'.

This will create memory usage and slow down the whole process.

I hope I'm clear enough. I'm perhaps not 100% correct but the idea is here.

These are the lines I'm talkng about:

 // Loop through all the cells in the selection
 for ( int x = 0; x   {
   for ( int y = 0; y     {
 ///// y loop should be the first !

if (selectionRegion.IsVisible(Left,Top) && selectionRegion.IsVisible(Right, Top) && selectionRegion.IsVisible(Left, Bottom) && selectionRegion.IsVisible(Right, Bottom))    
///// as top & bottom are variables!

dst[ Left , Top+j ] = PrimaryColor;    // draw left wall
dst[ Right , Top+j ] = PrimaryColor;   // draw right wall

dst[ Left + 1 , Top + 1 ] = PrimaryColor;   // fill in the extra squares
dst[ Right - 1, Top + 1 ] = PrimaryColor;
dst[ Left + 1 , Bottom - 1 ] = PrimaryColor;
dst[ Right - 1 , Bottom - 1 ] = PrimaryColor;    
///// as top & bottom are variables AND you are using +/- 1 !!

As I said this version doesn't take care if the corners of each cell are entirely contained within the selection.

I just provide it to show you a good way to use the y,x loops. Up to you now to see how to add the tests for it...

Thanks for the code examples and your tutorial! I had not considered that the y,x loops would be appreciably quicker than the x,y loops.

Each cell must be inside the selection so that a valid maze can be constructed (the next step - CellMaker was just the preliminary construction but it worked well so I thought I'd release it).

Just because you accept criticisms....

I do, and I'll learn plenty from your post. I'll study your code over the next few days and see what I can come up with. Thanks again.

0

Share this post


Link to post
Share on other sites

Hmmmm... I hadn't thought of that either.... good point about the y,x vs. x,y given the way the "rois" are passed in. While in theory, I had been focusing on the point that you cannot make assumptions about how the rois are passed in, I have observed that they are always (in my testing so far at least) are horizontal slices, very long in the x direction and very short in the y direction. Thanks for the tip.

0

Share this post


Link to post
Share on other sites
Hmmmm... I hadn't thought of that either.... good point about the y,x vs. x,y given the way the "rois" are passed in. While in theory, I had been focusing on the point that you cannot make assumptions about how the rois are passed in, I have observed that they are always (in my testing so far at least) are horizontal slices, very long in the x direction and very short in the y direction. Thanks for the tip.

Madjik really knows what he's talking about. I just ran a simple test on the value of y,x loops vs x,y loops. Without changing any other code I found the speed increase impressive!

1600x1200 pixel canvas:

CellMaker2.0@12,12,2 = 62 seconds

CellMaker2.0 (with y,x loops) @12,12,2 = 31 seconds

0

Share this post


Link to post
Share on other sites

Have you updated the attachment to CellMaker2.0 (with y,x loops) on your 1st post?

Please also add the date of the update, so users will know if the plugin have been updated or not.

Thanks.

0

Share this post


Link to post
Share on other sites
Have you updated the attachment to CellMaker2.0 (with y,x loops) on your 1st post?

Please also add the date of the update, so users will know if the plugin have been updated or not.

Thanks.

Done!

0

Share this post


Link to post
Share on other sites
Have you updated the attachment to CellMaker2.0 (with y,x loops) on your 1st post?

Please also add the date of the update, so users will know if the plugin have been updated or not.

Thanks.

Done!

Thank you :D

Edit:

Bother you 2 more things, Please keep the dll same file name, and only add the version number for the zip, so users don't need to always remember to delete the old file, and can just replace it.

Please put in "render"

Thanks.

0

Share this post


Link to post
Share on other sites

Bother you 2 more things, Please keep the dll same file name, and only add the version number for the zip, so users don't need to always remember to delete the old file, and can just replace it.

Please put in "render"

Thanks.

*.dll now just called CellMaker (with no version number) and placed in Render as requested. New ZIP file added (YMD: 10/02/08) to incorporate these changes.

0

Share this post


Link to post
Share on other sites

Thank you for your time! :)

0

Share this post


Link to post
Share on other sites

Hi I think this is a great plugin since with this I can have different width, height in my grids.

But I miss one option; I want to be able to choose the width of the lines used to draw.

I really would appriciate if you could make this.

0

Share this post


Link to post
Share on other sites
Hi I think this is a great plugin since with this I can have different width, height in my grids.

But I miss one option; I want to be able to choose the width of the lines used to draw.

I really would appriciate if you could make this.

Sorry that is beyond the algorithm I'm using to draw the cells. You should investigate Madjiks Gridmaker plugin as this will allow you to set height, width and brushwidth. here's the link: Grid Maker Plugin (2007/05/24) v3.0 http://paintdotnet.12.forumer.com/viewtopic.php?t=4879

0

Share this post


Link to post
Share on other sites

What does CellMaker look like with an image, please attach a screenshot of the image in Paint.net with CellMaker turned on? Grid, from the fuel menu, is much too small to see unless zoomed in quite a bit!

0

Share this post


Link to post
Share on other sites

Look at the first post, there are screenshots.

0

Share this post


Link to post
Share on other sites

just saw this too and that is quite a smart idea especially how it stops at the border of the image or designated area, thanks

0

Share this post


Link to post
Share on other sites

This plugin has been superseded by Cellmaker Rev(isited) by zoonel, release date: Dec 06, 2009
you can find it here: Cellmaker Rev

Edited by Ego Eram Reputo
Updated forum link
0

Share this post


Link to post
Share on other sites

Found this plugin was broken under PDN 4.0 so I updated it.

You should still use the enhanced version, which you can find here: Cellmaker Rev

0

Share this post


Link to post
Share on other sites

The version of this plugin in my Plugin Pack has been updated.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0