RE: cross-sections of 3D objects

Hi Bill,

Thanks for the pointer.  I did try the method that you suggested of using 
IsoContour to get a single iso-line to represent the intersection of a 3D 
surface and a plane.  However, iso-line doesn't seem to properly capture the 
cross-section.  For example, when I tried to cut a sphere with a plane having 
a normal vector of <0,1,0>, the iso-line at times showed a distorted diamond 
and other times nothing at all depending on the position of the plane along 
the y-axis.  Initially I thought this was occurring because we are setting the 
base contour = d (from ax+by+cz=d and in my case the equation reduces to y = 
d), only a few points computed from domain Set of the manifold dimension=2 
Gridded3Dset can actually be used for the contour.  In other words, maybe the 
plane wasn't "catching" the points I have used for the 3D shape.

So the next thing I tried was to generate my shape with the Gridded3DSet by 
moving along the y-axis.  I would create the sphere by drawing circles as I 
move up the y-axis incrementally.  Now, in theory if I set the base contour 
equal to one of the y increment that I used to construct sphere, the iso-line 
should be a circle, but the same problem described above persisted.

I am not sure where the problem might be or maybe I didn't code it properly.  
I have included the piece of code in case you would like to take a look.  
Thanks in advance for any comments.

John

    float a = 0.f;
    float b = 1.f;
    float c = 0.f;
    if (p == null) p = new RealType("plane", null, null);
    FunctionType pfunction = new FunctionType(xyz, p);
    FlatField fplane = new FlatField(pfunction, set);
    float[][] set_samples = set.getSamples(true); //getting domain samples 
from the 3D shape.
    float[][] p_samples = new float[1][Mfold[0]*Mfold[1]];

    //Computing ax+by+cz = d
    for(int i=0;i<p_samples[0].length;i++)
    {
        p_samples[0][i] = 
a*set_samples[0][i]+b*set_samples[1][i]+c*set_samples[2][i];
    }

    fplane.setSamples(p_samples);

    display2D = new DisplayImplJ2D("display1");

    // Get display's graphics mode control and draw scales
    GraphicsModeControl dispGMC = (GraphicsModeControl)  
display2D.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);

    ScalarMap tempzMap = new ScalarMap( z,    Display.YAxis );
    ScalarMap tempxMap = new ScalarMap( x, Display.XAxis );
    ScalarMap tempIsoMap = new ScalarMap( p,  Display.IsoContour );
    ScalarMap tempRGBMap = new ScalarMap( p,  Display.RGB );

    // Add maps to display

    display2D.addMap( tempzMap );
    display2D.addMap( tempxMap );

    display2D.addMap( tempIsoMap );
    display2D.addMap( tempRGBMap );

    // The ContourControl
    // Note that we get the control from the IsoContour map
    ContourControl isoControl = (ContourControl) tempIsoMap.getControl();
    // Define some parameters for contour lines
    float interval = 100.f;  // interval between lines
    float lowValue = -100.f;   // lowest value
    float highValue = 100.f;    // highest value
    float base = p_samples[0][400]; //  starting at this base value

    System.out.println("base = "+base);
    System.out.println("set_samples = "+set_samples[1][400]); //the y values 
of the 3D shape.
    //the above lines give the same value.

    // ...and set the lines with the method
    isoControl.setContourInterval(interval, lowValue, highValue, base);
    isoControl.enableLabels(true);

    // Create a data reference and set the FlatField as our data
    DataReference p_ref = new DataReferenceImpl("p_ref");
    p_ref.setData( fplane );

    // Add reference to display
    display2D.addReference( p_ref );


>===== Original Message From Bill Hibbard <billh@xxxxxxxxxxxxx> ====
>Hi John,
>
>VisAD doesn't currently include operations for computing
>the intersections of surfaces and planes in 3-D. However,
>you might hack it as follows. Your plance can be defined by:
>
>  ax + by + cz = d
>
>So define a FlatField with MathType:
>
>  ((x, y, z) -> plane)
>
>and with your mainfold dimension = 2 Gridded3DSet as its
>domain Set. Compute the 'plane' value at each sample
>location as:
>
>  ax + by + cz
>
>Then create the ScalarMap plane -> IsoContour and set the
>base contour = d (with a very large contour interval so you
>only get one contour curve). That is, the IsoContour will
>be a set of iso-lines on the surface (not an iso-surface),
>but you only want one iso-line.
>
>Good luck,
>Bill


  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: