[vtkusers] Passing in vtkImageData to vtkMarchingCubes
    ThinkFlow 
    neto at caltech.edu
       
    Tue Aug 27 19:24:07 EDT 2013
    
    
  
Hi,
I have some vtkrectilineargrid data, and I converted it into vtkImageData.
Then, I tried to pass this vtkImageData through vtkMarchingCubes. However,
the number of points in the output of vtkMarchingCubes is 0, while prior,
the number of points in vtkImageData is not zero. i was wondering if there
was something I might have forgotten to do in getting all the parameters of
vtkImageData. Here is some of my code:
If you would like, I can attach my full code.
grid is of type vtkRectilinearGrid.
    vtkImageData *vid = vtkImageData::New();
    vid->SetExtent(grid->GetExtent());	
    vid->GetPointData()->ShallowCopy(grid->GetPointData());
    vid->GetCellData()->ShallowCopy(grid->GetCellData());
     /* compute bounds */ 
    double bounds[6];
    vid->GetBounds(bounds);
    /* desired volume spacing */
    double spacing[3];
    spacing[0] = 0.1;
    spacing[1] = 0.1;
    spacing[2] = 0.1;
    vid->SetSpacing(spacing);
    /* compute dimensions */
    int dim[3];
    for (int i = 0; i < 3; i++)
    {
        dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) /
spacing[i]));
    }
    vid->SetDimensions(dim);
   /* compute the origin */
    double origin[3];
    for (int t = 0; t < 3; t++)
    {
        if (bounds[2*t] < 0)
            origin[t] = bounds[2*t] - spacing[t]/10;
        else
            origin[t] = bounds[2*t] + spacing[t]/10;
    }
    vid->SetOrigin(origin);
    #if VTK_MAJOR_VERSION <= 5
        vid->SetScalarTypeToUnsignedChar();
        vid->AllocateScalars();
    #else
        vid->AllocateScalars(VTK_UNSIGNED_CHAR,1);
    #endif
    // fill the image with foreground voxels:
    unsigned char inval = 255;
    unsigned char outval = 0;
    vtkIdType count = vid->GetNumberOfPoints();
    for (vtkIdType s = 0; s < count; ++s)
    {
        vid->GetPointData()->GetScalars()->SetTuple1(s, inval);
    }
    //Prepare surface generation
    vtkMarchingCubes *contour = vtkMarchingCubes::New(); //for label images
    contour->SetInput(vid);
Thanks
--
View this message in context: http://vtk.1045678.n5.nabble.com/Passing-in-vtkImageData-to-vtkMarchingCubes-tp5723066.html
Sent from the VTK - Users mailing list archive at Nabble.com.
    
    
More information about the vtkusers
mailing list