[vtkusers] marching cubes output

anast.jm at pg.com anast.jm at pg.com
Wed Apr 7 16:46:56 EDT 2004


>From your description, your dataset seems to be 5x6x5 but your coded data 
extent is 6x6x6...I'm suprised this didn't generate an error.

volReader->SetDataExtent(0,5,0,5,0,5);


also I'm a bit rusty on marching cubes but don't you need a value between 
0 and 1 to create the isosurface you are after??

iso->SetValue(0,1);

....john






"Vetria Byrd" <byrdv at cis.uab.edu>
Sent by: vtkusers-admin at vtk.org
04/07/2004 04:05 PM
Please respond to byrdv

 
        To:     <vtkusers at vtk.org>
        cc:     (bcc: John Anast-JM/PGI)
        Subject:        [vtkusers] marching cubes output


I have written a program to extract data from 2D slices of data files.
Five data files were manually created.  Each of the data files look like 
this:
 
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
 
Where the 0's indicate the object is outside the cube and 1 indicates the 
object is inside the cube.
When I run the program (which compiles and runs with no problems) I 
expected to get a solid object representing the center of the 5x5x5 
rendered object since only the center values of the data (input) show that 
the object is inside but what I get is shown in the 1st figure.  Viewing the wire frame display (2nd figure) shows the 5x5x5 grid with an unexpected dip in the top row.
 
I am missing something, I just don't know what that "something" is.
What I want the algorithm to do is render the object based on which values 
of the data indicate the object is present.
 
Here's the code:
//
// This example reads a volume dataset, extracts an isosurface and 
displays it.
//
 
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolumeReader.h"
#include "vtkImageReader2.h"
#include "vtkMarchingCubes.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPolyDataNormals.h"
#include "vtkContourFilter.h"
 
int main ()
{
 
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
 
  vtkImageReader2 *volReader = vtkImageReader2::New();
  volReader->SetDataExtent(0,5,0,5,0,5);
  volReader->SetFilePrefix("C:/data/cube/slice");
  volReader->SetDataSpacing(1,1,1);
  volReader->Update();
 
 
  // An isosurface, or contour value of 1 is known to correspond to the
  // object
  vtkMarchingCubes *iso =vtkMarchingCubes::New();
     iso->SetInput(volReader->GetOutput() );
     iso->SetValue(0,1); 
 
  vtkPolyDataMapper *isoMapper = vtkPolyDataMapper::New();
      isoMapper->SetInput(iso->GetOutput() );
 
  vtkActor *isoActor = vtkActor::New();
      isoActor->SetMapper(isoMapper);
 
  vtkOutlineFilter *outline = vtkOutlineFilter::New();
      outline->SetInput( (vtkDataSet *) volReader->GetOutput() );
 
   vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
      outlineMapper->SetInput(outline->GetOutput() );
 
   vtkActor *outlineActor = vtkActor::New();
      outlineActor->SetMapper(outlineMapper);
      outlineActor->VisibilityOff();
 
   //
   // Add the actors to the renderer, set the background and size
   //
   ren->AddActor(outlineActor);
   ren->AddActor(isoActor);
   ren->SetBackground(0.2,0.3,0.4);
   renWin->SetSize(450,450);
   ren->GetActiveCamera()->Elevation(90);
   ren->GetActiveCamera()->SetViewUp(0,0,-1);
 
   iren->Initialize();
 
   // render the image
   iren->Start();
 
 
   return 0;
}
 
Thanks.
_______________
Vetria L. Byrd
 
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040407/1519bdbe/attachment.htm>


More information about the vtkusers mailing list