Re: image generation in C++
- From: Nguyen Vinh Phu <nvinhphu@xxxxxxxxx>
- Date: Fri, 20 Jun 2008 01:47:17 -0700 (PDT)
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]
.
- References:
- image generation in C++
- From: Nguyen Vinh Phu
- Re: image generation in C++
- From: [Jongware]
- image generation in C++
- Prev by Date: Re: Point projection a plane
- Next by Date: Re: Point projection a plane
- Previous by thread: Re: image generation in C++
- Next by thread: tree node parent, trees as data structure
- Index(es):
Relevant Pages
|