stippled line variable point spacing from raster
 1-5  6-25  26-45  46-60

Previous
Next
 From:  Michael Gibson
10809.26 In reply to 10809.25 
Hi Brian,

re:
> Does MoI Image command work with image files with 8 or 16 bits-per-pixel,
> Static, or dynamic, (Whatever those mean), or HDRI (high dynamic-range imaging)?

It only works with images in PNG, TIF, JPEG, GIF, and BMP formats and I don't think that any of those can contain HDRI image data.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.27 
This link has some generic code for "transforming the coordinates from the specified coordinate system into pixel coordinates."
(2.1.2 Real-number Coordinate Systems)

https://math.hws.edu/graphicsbook/c2/s1.html#:~:text=In%20terms%20of%20coordinates%2C%20a,to%20right%2C%20starting%20with%20zero.

One step is to set up the various image rectangles. These are world, local, canvas, and primary.
MoI World coordinates come from MoI Local (cplane) coordinates using .evaluate. (See Michaels code.)

The primary image is the source PNG, TIF, JPEG, GIF, or BMP.
A primary image ( width, height ) ( 1920, 1080 ), has 1920 pixel columns, and 1080 pixel rows.
A test primary image will be ( 6, 5 ). (or maybe ( 12, 8 ).

The address for a pixel is ( rowNum, colNum )
the pixel columns and rows are zero indexed, with upper left corner ( 0, 0, 0 ).

The canvas image is similar to the primary image. (?) (Heightmap divides x by 2)
Reversing row number from bottom to top to top to bottom: ( oldrowNumber - numRows ) ?

- Brian

I am going to assume that a screen point that falls on a pixel boundary is in the pixel to the left, or above. (???)
Except uppermost edge and leftmost edge?

EDITED: 12 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.28 
Based upon Peer's initial description:

I am thinking that the "intensity-to-points-array" should be done from a 2d CPlane.
Convert CPlane local coordinates over the image, into pixel (row,column) address of the canvas image.
World coordinates just complicate the script.
At the end of the script, the CPlane can be reset.

The reason for this is that the 2d image can be in any view, for example Top, Front, Right, etc.
Or even at some other angle. The ( X, Y ) coordinate of a local point is to be converted to a pixel address.
World coordinates could introduce z into the (x,y) mix, and mess up the conversion to pixel address.
For example, Front view is 2d world ( x, z ), but local ( X, Y ), with Z = 0, or Z = constant.
Right view is 2d world ( y, z ), but local ( X, Y ), with Z = 0, or Z = constant.

?

- Brian

I'll make the assumption that the canvas image is the same "resolution" as the primary (e.g. PNG) image.
I guess that the canvas image is somewhere in memory, not a MoI geometry object. (?)

The method to ghet the 2d CPlane of an image was given by Michael, I think.

So divide the local image by columnNum zones, along X,
and divide the local image by rowNum zones, along Y.
(Convert real number X, Y coordinates into integers for each zone...)
Reverse Y coordinates for rowNum to be zero at upper left corner.

EDITED: 12 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.29 In reply to 10809.5 
Hi PEER,

>>>But maybe before going into details, can you think of another way of spacing out points along a curve so the the distance between each pair of points is roughly proportional to the local luminance of an underlying image? Maybe there's a straighter path that I'm not thinking of.

If you have a mathematical formula for the "raster gradient" of the luminance, that could perhaps be used to array the points along the curve.

The programs that create the raster gradients use some mathematical method. See their source code, or do internet search?

https://gis.stackexchange.com/questions/311688/how-to-make-a-raster-gradient-in-any-direction-in-r

https://www.i-programmer.info/programming/javascript/14966-javascript-canvas-gradient-a-pattern-fills.html

https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

https://www.youtube.com/watch?v=nMUMZ5YRxHI

- Brian

EDITED: 12 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10809.30 In reply to 10809.29 
Brian,

I got pretty close to what I want working in another program. For now I'm going to use that.

Have a good weekend!

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.31 
Congratulations PEER.

I might do a little more work on a version of "array by luminance".

This morning I found some "simple" code to convert from a 2D ScreenCanvas to pRaster coordinates (pixel).

https://www.scratchapixel.com/lessons/3d-basic-rendering/computing-pixel-coordinates-of-3d-point/mathematics-computing-2d-coordinates-of-3d-points.

Note that the link is doing something slightly different than the "array by luminance", but the code can be (easily I think) altered to apply.

Definitions:
The 2D ScreenCanvas is the 2D image on the MoI screen.
The cPlane coordinate system has its origin at the center of the 2D ScreenCanvas.
code:
(Note, the user picks the lower left corner of the MoI Image with pointpicker, and cPlaneInitial is created.
the cPlane Frame is created from cPlaneInitial, as in the recent Elastica script.)

Point Pprime is a MoI point on (or on top of) the 2D ScreenCanvas.
code:
(Note that ScreenCanvas is different from the Canvas of Heightmap.)
"Since P' is a 2D point, it is defined with respect to a 2D coordinate system which in CG we call the image or screen coordinate system. This coordinate system marks the centre of the (screen)canvas;"


code:
"The first thing we are going to do is to remap P' coordinates in the range [0,1]. This is mathematically easy. Since we know the dimension of the (screen) canvas, all we need to do is apply the following formulas:

P′normalized.x=P′.x+width/2width
P′normalised.y=P′.y+height/2height
Because the coordinates of the projected point P' are now in the range [0,1], we say that the coordinates are normalized. For this reason, we also call the coordinate system in which the points are defined after normalization, the NDC coordinate system or NDC space. NDC stands for Normalized Device Coordinate. The NDC coordinate system's origin is situated in the lower-left corner of the canvas. Note that at this point, the coordinates are still real numbers, only they are now in the range [0,1].

The last step is simple. All we need to do is now multiply the projected point x- and y-coordinates in NDC space, by the actual image pixel width and pixel height respectively. This is a simple remapping of the range [0,1] to the range [0,Pixel Width] for the x-coordinate, and [0,Pixel Height] for the y-coordinate respectively. Now though that pixel coordinates are integers, thus rounding off the resulting numbers to the smallest following integer value is necessary (to do that, we will use the mathematical floor function; it rounds off a real number to its smallest following integer). After this final step, P' coordinates are defined in raster space:

P′raster.x=⌊P′normalized.x∗ Pixel Width⌋
P′raster.y=⌊P′normalized.y∗Pixel Height⌋
In mathematics, ⌊a⌋, denotes the floor function.

There is a small detail though we need to take care of. The y-axis in the NDC coordinate system points up while in the raster coordinate system points down. Thus, to go from one coordinate system to the other, P' y-coordinate also needs to be inverted. We can easily account for this by doing a small modification to the above equations:

P′raster.x=⌊P′normalized.x∗ Pixel Width⌋
P′raster.y=⌊(1−P′normalized.y)∗Pixel Height⌋"


P′raster.x and P′raster.y will then be used in Heightmap modified code, with the Heightmap canvas, to get the RGB or RGBA
data.
One of the several Luminance formulas will give the luminance value of the pixel.

Repeat for remaining points on the (Line) curve overlying the MoI image.
Node that the (Line) curve can be at an angle theta...

- Brian

EDITED: 13 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.32 
I guess the code broke the Edit feature.

To add:
P′raster.x and P′raster.y are the coordinates of the primary image (PDF, JPEG, TIF, BMP, etc) pixel associated with Pprime.

The second and third "pseudo" code blocks above, are quotes from the link.

Elsewhere, I found more definitions of "luminance" calculation using RRBGGG / 6, etc.

- Brian

The (line) curve, and its angle theta, can be used to calculate the distance along the line for the next pPrime point.
Calculate the width and height of a rectangle by dividing 2d screen image dimensions by number of primary row and column pixels.
The distance is a hypotenuse. Use trigonometry or pythagorean formula.
Or just add dx and dy to old (pPrime point.)

It is nice to find some (relatively easy) code and explanations.

EDITED: 13 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.33 
Given a (continuous) curve in an ( x, y ) plane, which goes from xMin to xMax, and which for every x, has a single y value.
(Like for a single valued function.)
A circle and ellipse do not qualify. The bottom half of a circle would qualify.


How to Array the start point along the curve, with constant x intervals.
I do not think that there is a script for doing this?
ArrayCurve of startpoint of the curve usually is spaced differently.

This can be done by placing a horizontal line below the curve, and using ArrayCurve to array the startpoint of the line along the line, and then projecting the points to the "single valued curve".

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.34 In reply to 10809.33 
Hi Brian,

re:
> How to Array the start point along the curve, with constant x intervals.

Probably you'd need to create a vertical line at every x position and then use the 'intersect' factory (see Intersect.js) to intersect the line with your function curve, that should generate a point object.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.35 In reply to 10809.34 
Hi Michael,

Intersections is a good idea.

Create guide line above curve, and guide line below curve.
Run LineWeb to get uniform deltaX lines between the two guide lines.
Intersect lines with curve to create points on the curve.
Investigate the order of the points.

Look for algorithm to scan the points on a curve, from curve start to curve end, and place the points in ordered array.
This could then apply to curves which loop back .
(Unless MoI already orders the points along a curve?)

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.36 In reply to 10809.35 
Hi Brian,

re:
> Look for algorithm to scan the points on a curve, from curve start to curve end, and
> place the points in ordered array.
> This could then apply to curves which loop back .
> (Unless MoI already orders the points along a curve?)

In your script you can call intersect separately for each vertical line with the function curve
and since you are making those vertical lines you should generate them in increasing order
so that your intersections will be ordered also.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.37 In reply to 10809.36 
Thank you Michael.

I have been getting some really weird results, with LineWeb and Intersect commands.
Intersections are sometimes double points, or for a curve crossing itself, 3 points.

Either my curves are weird, or a bug?

I'll post a .3dm later.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.38 In reply to 10809.37 
If I rebuild the looped curve, the "double" intersection problems go away.

If I separate a fresh curve, or a rebuilt curve, and then (re) Join it,
then the Intersect script causes "double" intersect points.

It seems like the intersect script is detecting pre-join curve segments???

Sometimes the crossover yields 3 points from intersect.

- Brian

ps I think my mouse has been acting a little strange lately, so I gave it a rap on the mousepad :-)
Seems to have helped with mouse selection.

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.39 In reply to 10809.38 
Hi Brian, I'm a little confused because previously you wrote:

> Given a (continuous) curve in an ( x, y ) plane, which goes from xMin to xMax, and which for every x, has a single y value.
> (Like for a single valued function.)
> A circle and ellipse do not qualify. The bottom half of a circle would qualify.

But all of the curves you just posted are not function curves like that.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.40 In reply to 10809.39 
Hi Michael,

The initial curve was traveling from left to right, without curving back above previous portion, for which it is "easier" to find constant deltaX points.

Since then, I have been trying to extend the curve with it "looping" back, a more difficult curve to place constant deltaX point on.
So I did a bit of experimenting.

A curve crossing over itself, (e.g. figure eight) might be more difficult yet.

Anyway, then I inadvertently trimmed the curve with many lineweb lines, and rejoined it, (without being very aware)
Then the "double" intersect points problem occurred.

Attached is a "left to right" curve, which was trimmed to segments, and rejoined.
The double intersect points problem also occurs with this curve.

I have always thought that a re-Joined curve was the same as the initial single curve, but there must be some difference?
So the curve "remembers" is former segments, unless Rebuild is used?

- Brian

Another thought was that MoI joins curve segments "head to tail", and so apparently knows the sequential order of end points and start points.

Google search of "sort points on curve algorithm" did not seem to be very fruitful.

hmm, I see that spell checker is working on editing posts.

(So I thought I should report an unexpected (for myself) result.)

EDITED: 16 Aug 2022 by BEMFARMER


  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.41 In reply to 10809.40 
Projecting 10 points on the bottom line, up to the (10 segments but rejoined) curve, also results in 18 points.
( 2 times 8) + 2.
As if each former curve segment is being projected to.
(Same result as intersect.)

- Brian

(I thing MoI4 had similar results, a very brief test.)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.42 In reply to 10809.40 
Hi Brian, I'll see if I can get the Intersect command to weed out duplicate intersections. For the current version I guess you would need your script to do that itself.

re:
> I have always thought that a re-Joined curve was the same as the initial single curve, but there must be some difference?
> So the curve "remembers" is former segments, unless Rebuild is used?

Yes Join on curves will generate a parent curve that has a list of head to tail segments in it. It doesn't automatically merge segments together. So if you use Edit > Separate on it it should break apart into the same pieces you had before using Join.

In v5 you can use the Merge command on it to merge segments that meet smoothly into longer segments.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.43 In reply to 10809.42 
Thank you Michael.

Merge improvement is good to know.

Using Merge just now, in MoI5beta, and the intersection came out correct.
And Project of bottom line points also came out correct.

One last observation for tonight: MoI5beta:
Using the last .3dm, with 10 vertical LineWeb lines:
(Without Merge)
If the re-joined curve is shifted over a bit, so the LineWeb lines do not intersect the former segment ends,
the intersect occurs correctly, (but of course in different locations.)

- Brian

As expected, Merge does not help with getting correct Intersections or Projections, in MoI4,
(in the current situation anyway).

EDITED: 16 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10809.44 In reply to 10809.43 
Brian,

I've also noticed that Construct > Curve > Isect sometimes gives multiple points when I'm expecting 1. For example, if I draw 3 lines through the origin (by using Grid Snap), select the 3 lines, and run Isect, I get 3 points:

I worried that maybe the redundant points would be at locations around .001 units apart http://moi3d.com/forum/lmessages.php?webtag=MOI&msg=8468.19, so I ran
code:
var pts = moi.geometryDatabase.getSelectedObjects().getPoints();

for ( var i = 0; i < pts.length; ++i )
{
	moi.ui.alert
	(
		'point ' + i + '\n' +
		'x = ' + pts.item(i).pt.x + '\n' +
		'y = ' + pts.item(i).pt.y + '\n' +
		'z = ' + pts.item(i).pt.z + '\n'
	)
}


(Is there an easier way to get accurate point coordinates?)

But, In the case of the location where the curve crosses over itself in WeirdIntersectionOne.3dm

I see that 2 of the points are in exactly the same location and the 3rd is only different along y in the 13th decimal place:

point 0
x = 20.826530612244895
y = 37.74721822498999
z = 0

point 1
x = 20.826530612244895
y = 37.74721822498999
z = 0

point 2
x = 20.826530612244895
y = 37.747218224989986
z = 0

In the example with straight lines above all 3 points are at 0,0,0. I tried moving one of the lines by only .0001 units, thinking that this might cause problems, but the 3 intersection points created look to be at exactly the right locations:

- Peer

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.45 In reply to 10809.44 
Hi PEER

A brief partial reply on lunch break:

I use the script _PointCoordinates3, which is ParseFloat to 6 decimal places, and does one point at a time.
I think it uses the same data as your script.

I've read in the past that computer binary representations of real numbers are not perfect. They only go to, or are accurate to, a certain number of decimals. The programmer does the best that they can...

3 points sounds like the combination of 3 things, taken two at a time.

I figured that "crossing over" might cause some type of problem.

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
Show messages:  1-5  6-25  26-45  46-60