LDraw.org Discussion Forums

Full Version: Img4Dat
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Hello,
 
long time ago I started implementing a tool to convert images to LDraw compatible .dat files. The first name was Img2Dat; but during the time the ‘version’ increased. Here is only a short description.
 
You can download the tool here (sorry, but I have to write this: the application, can be downloaded as it is. I do not take charge for errors or any kind of damage to your system that is caused by this software.): Img4Dat.zip
It is a beta version – there are some issues I that need an improvement. But I think it is stable enough for playing. It is written in C# for the .NET Framework 3.5 (so Windows).
 
If you open the application, you can open a bitmap (currently only .bmp) – it will be shown in the left half of the GUI.
[attachment=3455]
 
Now you can choose colors for the color quantization by right click on the source image (select the background color first). The result will be shown in the right half of the GUI.
It is the base for the path findings (around the areas with the same color). After choosing the colors it is possible to clean the result a little bit (and to remove the obsolete areas in the background). 
[attachment=3456]
You can save the result image to rework it in a different tool or just for backup.
You can search for the paths now, by clicking the 'FindPaths' button. The result will be shown on top of the original image.
Again, a little bit of cleaning can be done (here undo is possible):
  • Select one point and create a circle (with the connected points); you can define the number of points in the circle.
  • Select more then two points. The points will be projected on the line between the first and the last selected point.
  • Select more then three points. The points will be projected on a circle. The first and the last point will not change. You have to select the points in the right order.
  • Select two points. They will become one at the cut of the connected lines.
  • Select more then two points. The distance between this points will be recalculated. Here you also have to select the points in the right order.
  • When you have selected one point, you can delete it with pressing d-key.
  • When you have selected two points, you cann add a point between them by pressing the a-key.
[attachment=3457]
You can also add a ‘template’ where the image should be patterned for, and scale and adjust it (currently only torso and tile 2x2 round).
[attachment=3458]
When the result is fine, the triangles can be created by clicking the 'CreateTriangles' button  – a .dat file with the name of the source image becomes created in the folder of the source image. The colors need to be adjusted to LDraw colors.
[attachment=3459]
(One hint: The triangle generation will not work correct, when two lines cross after cleaning the paths or adding the template.)

I would be happy, if someone gives it a try.

Rolf
Had a quick try on my laptop (not home currently) and so far I'm not very successfull... get a crash whan I try to generate triangles, or when I try to save bitmap. I'll try again when home!
Attached the bitmap I used.
(2019-02-27, 16:02)Philippe Hurbain Wrote: [ -> ]Had a quick try on my laptop (not home currently) and so far I'm not very successfull... get a crash whan I try to generate triangles, or when I try to save bitmap. I'll try again when home!
Attached the bitmap I used.

Ok, did you get an error message?

I was able to create the file (without path cleaning). But as you can see here, there is still some work to do... There are red colored triangles, that needs to be adjusted (and one wrong blue  Angry ). 

[attachment=3461]

Rolf
(2019-02-27, 16:44)Rolf Osterthun Wrote: [ -> ]Ok, did you get an error message?

I was able to create the file (without path cleaning). But as you can see here, there is still some work to do... There are red colored triangles, that needs to be adjusted (and one wrong blue  Angry ).

Tried again on my main machine, same problem when I try to triangulate. Here is the error message:
Code:
Consultez la fin de ce message pour plus de détails sur l'appel du débogage
juste-à-temps (JIT) à la place de cette boîte de dialogue.

************** Texte de l'exception **************
System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
  à Img4Dat.Triangulator.SimpleTriangulator.addPoint(Point p)
  à Img4Dat.Triangulator.SimpleTriangulator.Triangulate(Int32 width, Int32 height)
  à Img4Dat.MainForm.toolStripButtonCreateTriangles_Click(Object sender, EventArgs e)
  à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
  à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
  à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
  à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
  à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
  à System.Windows.Forms.Control.WndProc(Message& m)
  à System.Windows.Forms.ToolStrip.WndProc(Message& m)
  à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Assemblys chargés **************
mscorlib
   Version de l'assembly : 2.0.0.0
   Version Win32 : 2.0.50727.5420 (Win7SP1.050727-5400)
   CodeBase : file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
Img4Dat
   Version de l'assembly : 1.0.6997.21469
   Version Win32 : 1.0.*
   CodeBase : file:///D:/Mes%20documents/Mod%E9lisation%20LDraw/Pi%E8ces%20en%20cours/Img4Dat.exe
----------------------------------------
System.Windows.Forms
   Version de l'assembly : 2.0.0.0
   Version Win32 : 2.0.50727.5420 (Win7SP1.050727-5400)
   CodeBase : file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
   Version de l'assembly : 2.0.0.0
   Version Win32 : 2.0.50727.5420 (Win7SP1.050727-5400)
   CodeBase : file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
   Version de l'assembly : 2.0.0.0
   Version Win32 : 2.0.50727.5420 (Win7SP1.050727-5400)
   CodeBase : file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Core
   Version de l'assembly : 3.5.0.0
   Version Win32 : 3.5.30729.5420 built by: Win7SP1
   CodeBase : file:///C:/Windows/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
mscorlib.resources
   Version de l'assembly : 2.0.0.0
   Version Win32 : 2.0.50727.5420 (Win7SP1.050727-5400)
   CodeBase : file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
System.Windows.Forms.resources
   Version de l'assembly : 2.0.0.0
   Version Win32 : 2.0.50727.4927 (NetFXspW7.050727-4900)
   CodeBase : file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_fr_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

And the questions/wishes...
- how do I fit the image to the template?
- I can delete one single vertex from a path. I wish I could select several with a marquee and delete them all.
(2019-03-03, 9:17)Philippe Hurbain Wrote: [ -> ]And the questions/wishes...
- how do I fit the image to the template?
- I can delete one single vertex from a path. I wish I could select several with a marquee and delete them all.

Hello Philo,

you have to fit the template to the image. By using the 4 NumerUpDown fields in the left bottom area, you can scale and move the template. It works the easiest if you select the field and use the mouse wheel.

And I think that this is also the reason for the exception. You added a template, but did not move it, so that there are negative values in the 'template path'. Currently the application can not handle such situations. I will catch them in the next version.
So now, you either can move and scale the template or you can create the triangles without a template (but then the size will not match the needed one). Does this help?

I will try to add the 'multi-delete'.

Rolf
Hello,

there is a new version available now (same location). In that, you can also delete 'multi-selects' by pressing 'd'.

Rolf
(2019-03-04, 21:36)Rolf Osterthun Wrote: [ -> ]Hello,

there is a new version available now (same location). In that, you can also delete 'multi-selects' by pressing 'd'.
Thanks Rolf, I was able to adjust template, and multi-delete works fine. But I still get an instant crash when I try to triangulate (with or without template Sad)
(2019-03-05, 9:07)Philippe Hurbain Wrote: [ -> ]Thanks Rolf, I was able to adjust template, and multi-delete works fine. But I still get an instant crash when I try to triangulate (with or without template Sad)


Hello Philo,

thank you for testing and reporting. I am really sorry, that it is not working on your side. I uploaded a new version. This time a few debug messages were added (via log4net). That means the application will create a log.txt file where you can see, what it is doing – and where it is stopping.

A few posts up you wrote, that you were also not able to save the bitmap. Could it be that the application is not allowed to create files on your system?

Rolf
(2019-03-05, 10:57)Rolf Osterthun Wrote: [ -> ]thank you for testing and reporting. I am really sorry, that it is not working on your side.
So am I Wink

Quote:I uploaded a new version. This time a few debug messages were added (via log4net). That means the application will create a log.txt file where you can see, what it is doing – and where it is stopping.
Attached two log files (with different source images). About the same result (and crash in both cases).
Quote:A few posts up you wrote, that you were also not able to save the bitmap. Could it be that the application is not allowed to create files on your system?
That was on my laptop (and there I only tried once, maybe I goofed). Here it works fine, as you see in a log file (I used the continue possibility after triangulation crash).
(2019-03-05, 11:55)Philippe Hurbain Wrote: [ -> ]So am I Wink

Attached two log files (with different source images). About the same result (and crash in both cases).
That was on my laptop (and there I only tried once, maybe I goofed). Here it works fine, as you see in a log file (I used the continue possibility after triangulation crash).

Thanks again.

In both cases the application tried to add a point directly on the edge of the image (x coordinate = 0). This is something I did not expect / did not test deep enough. I expected that the pattern is always surrounded by the back color (at least after cleaning the quantized image).
A new version is uploaded that should be able to handle these situations.

I hope it works now.

Rolf
Pages: 1 2 3 4 5 6