Re: image generation in C++



Hello flagos and Jongware,

All your post are invaluable to me. Thank you very much.
I am implementing it.

Regards,

Phu

On Jun 17, 12:01 pm, "[Jongware]" <so...@xxxxxxxxxxx> wrote:
Nguyen Vinh Phu wrote:

[...]

These images are in fact 2D slices of a 3D image of a cube containing
a set of layered spheres. A layered sphere is a set of concentric
spheres of
different colors (called grains). So, in my program, I have the
coordinates of
the center of the grains, its radii and the colors of each layers.

As the easiest way, I have used the Povray (www.povray.org/) program
by writing my grains data to text file of format required by Povray.
With this way, I can generate image of up to about 3000 grains. More
than that, the tracing progress of Povray is so slow.

Can Povray render a slice through solid spheres? Or am I
misunderstanding your requirement?

I have therefore been looking for other more effective approaches. The
first one is to use a free C++ image library that can write images
containing spheres. The second way is to write my data to pixels.

If all you want to see is axis-aligned slices (along the x-, y-, or
z-axis), it seems to me it can be programmed quite straightforward. That
is, if you are content with just colored circles -- no ray tracing here.
So, no textures, shadows, or lighting -- but you can get raw speed, fast
enough for interactive manipulation.

My question is how to realize these two ways in real C++ code. Please
help me.

I think this could work for a slice through a top-down view:
1. Create two 3d objects per grain: one with a z value of its highest
point (center coordinates /minus/ radius) and one with a z value of its
lowest point (center coordinates /plus/ radius). The x,y values should
be those of the original grain. These objects should contain a pointer
to their parent object, so you can find stuff like color, radius, etc.
2. Sort the objects along their z (depth) axis.
3. Select a z value you want to see :-)
4. For each grain intersecting the z coordinate, calculate the radius of
the intersection circle on that z. Basic math here. Store this result in
a new list; the x,y coordinates are /still/ the same of the original sphere.
5. Sort the list on circle radius.
6. Draw all circles, starting with the largest.

Since the grains can have layers around a common center point -- like a
jawbreaker, covered with layers of different colored sugar? --, you can
probably optimise a lot. For example, if a large grain is not visible at
all, you don't have to test each of the smaller ones inside it.

A drawback of this method is that you need separate routines for
top-down, left-right, and front-back views (aligned with z, y, and x
axes), but it should be very fast.
Alternatively -- and more difficult --, you can slice through the cube
with a plane at any angle, which has the disadvantage that I would have
to revise my math before even checking how to start :-) but the huge
advantage is that you can view the intersection plane from /any/ angle.

So if you're after a (simple) interactive program, writing a custom one
is the way to go. If you need pixel perfect rendering, stick to adopting
your data to a format for another program.

[Jongware]

.



Relevant Pages

  • Re: How to calculate the volume involved inside three spheres?
    ... Consider there are three equal spheres, ... involved all three spheres if the radius of spheres are all R and they ... A better starting point might be the problem involving 3 circles whose ... Then let r = sqrtfor the final integration. ...
    (sci.math)
  • Re: image generation in C++
    ... a set of layered spheres. ... the center of the grains, its radii and the colors of each layers. ... if you are content with just colored circles -- no ray tracing here. ... Create two 3d objects per grain: one with a z value of its highest point (center coordinates /minus/ radius) and one with a z value of its lowest point. ...
    (comp.graphics.algorithms)
  • Re: How to calculate the volume involved inside three spheres?
    ... Consider there are three equal spheres, ... involved all three spheres if the radius of spheres are all R and they ...
    (sci.math)
  • Re: Spark Gap Electrodes?
    ... spheres and toroidal shapes as the capacitive element. ... The larger the radius of curvature the greater the voltage before ...
    (sci.physics)
  • Re: Plasic balls
    ... >imagine how spheres are routinely ground by the million to fine tolerances ... >on radius and surface finish. ...
    (uk.rec.models.engineering)