[vtkusers] Visualizing multiple isosurfaces using vtkContourFilter

Thommen Korah thkorah at hotmail.com
Tue Mar 1 21:59:54 EST 2011


Christian,Thanks for your response. I did some more extensive testing with gdb. This is what I've found. The function I use is pasted below. sampleGrid is the structure storing label ids. For the case where sampleGrid was a 125x125x150 volume, everything works correctly. For a larger volume of 313x313x300 grid, the function crashes in vtkDiscreteMarchingCubes.cxx on line 136:    s[0] = scalars[idx]This occurs at the very first iteration of the loop. I discovered that the local variable scalars (which points to the same address as sampleGrid) is no longer accessible within the function. Did VTK delete this structure somewhere between the time the classes were created and the time it was invoked? Any help would be appreciated!Thommen


void addMultiColorRois( short* sampleGrid, int numContours,
                              int dimX, int dimY, int dimZ,
                              double voxX, double voxY, double voxZ,
                              int minX, int minY, int minZ)
{
  // Use existing array of samples, such that vtk does not free memory.
  vtkShortArray* sampleData = vtkShortArray::New();
  int numSamples = dimX * dimY * dimZ;
  sampleData->SetArray( sampleGrid, numSamples, 1 );
  sampleData->SetNumberOfComponents( 1 );
  sampleData->SetNumberOfTuples( numSamples );
  sampleData->SetName( "values" );


  // Set up sampled data space
  vtkImageData* sampledSpace = vtkImageData::New();
  sampledSpace->SetDimensions( dimX, dimY, dimZ );
  sampledSpace->SetScalarTypeToShort();
  sampledSpace->GetPointData()->SetScalars( sampleData );
  sampledSpace->SetSpacing( voxX, voxY, voxZ );  // set dimensions of a voxel
  sampledSpace->SetOrigin( (double)minX,
                           (double)minY,
                           (double)minZ );       // set lower left corner location

  // Create isosurface
  vtkDiscreteMarchingCubes* dmc = vtkDiscreteMarchingCubes::New();
  dmc->SetInput(sampledSpace);
  dmc->GenerateValues(numContours,0,numContours-1);


  vtkLookupTable* lut = vtkLookupTable::New();
  lut->SetNumberOfColors (numContours);
  //lut->SetTableRange(0,numContours-1);
  lut->SetHueRange(0,0.667);
  lut->Build();
  for (int c = 0; c < numContours-1; c++)
  {
      float red,green,blue;
      red = (rand() % 256)/255.0;
      green = (rand() % 256)/255.0;
      blue = (rand() % 256)/255.0;
      lut->SetTableValue (c,red,green,blue,1.0);
  }



  // Create mapper and actor, and add to renderer
  vtkPolyDataMapper* contourMapper = vtkPolyDataMapper::New();
  contourMapper->SetInput( dmc->GetOutput() );
  contourMapper->SetLookupTable(lut);
  contourMapper->SetScalarRange (0,numContours-1);
  contourMapper->SetScalarModeToUseCellData();


  vtkActor* impGeoActor = vtkActor::New();
  impGeoActor->SetMapper( contourMapper );

  int pos = addActor( impGeoActor );

  contourMapper->Delete();
  dmc->Delete();
  sampledSpace->Delete();
  sampleData->Delete();
  lut->Delete();

  return pos;
}

------------------------------
Message: 12Date: Tue, 1 Mar 2011 10:26:45 +0100From: Christian Lackas <lackas at invicro.com>Subject: Re: [vtkusers] Visualizing multiple isosurfaces	usingvtkContourFilterTo: vtkusers at vtk.orgMessage-ID: <20110301092645.GB24647 at invicro.com>Content-Type: text/plain; charset=us-ascii* Thommen Korah <thkorah at hotmail.com> [110301 01:25]:Hi Thommen,> I noticed your thread where you were trying to do the same. Similar to> your example, I ended up calling generateValues to create N contours> and mapped it to colors in a lookup table. Thanks for your example.glad to hear it helped somebody else, also.> While this method works correctly for a 125x125x50 volume, a larger> 312x312x300 volume of short int causes a segmentation fault in> vtkDiscreteMarchingCubesComputeGradient().The volumes I have worked with can easily be larger than your example,however, I typically only have 5-10 ROIs.Did you look at the segfault in a debugger already (e.g. is this amemory issue or a floating point exception, etc...)? Have you triedturning off computation of gradients?It could also help if you can show your code preferably with an exampledataset.Christian-- http://www.invicro.com/------------------------------
From: thkorah at hotmail.com
To: karthik.krishnan at kitware.com; vtkusers at vtk.org; lackas at invicro.com; bill.lorensen at gmail.com
Subject: RE: [vtkusers] Visualizing multiple isosurfaces using vtkContourFilter
Date: Mon, 28 Feb 2011 19:24:50 -0500








Hi Christian,
I noticed your thread where you were trying to do the same. Similar to your example, I ended up calling generateValues to create N contours and mapped it to colors in a lookup table. Thanks for your example.
While this method works correctly for a 125x125x50 volume, a larger 312x312x300 volume of short int causes a segmentation fault in vtkDiscreteMarchingCubesComputeGradient(). The volume has approximately 250 disconnected ROIs labeled from 0-N. Is there a limit on how large the volume can be? Or will the labels cause this error since the class expects the scalars to adhere to a specific layout? 
Thanks,Thommen

Date: Thu, 24 Feb 2011 14:15:35 +0530
Subject: Re: [vtkusers] Visualizing multiple isosurfaces using vtkContourFilter
From: karthik.krishnan at kitware.com
To: thkorah at hotmail.com
CC: vtkusers at vtk.org

 Since this is a labelled image with several label (ids), you could use vtkDiscreteMarchingCubes once on each label of interest instead of vtkContourFilter. This will extract just the interface between the cells containing the label of interest and its neighbors, whatever id they may have.

 
--
karthik


On Thu, Feb 24, 2011 at 4:39 AM, Thommen Korah <thkorah at hotmail.com> wrote:


Thanks for your help. I decided to use the first method with separate filters. I have multiple segmented regions, and each voxel stores the id that it belongs to. So all cells belonging to object 3 will store the number 3. 


But when I create cf3 filter and call cf3->setValue(0,3), it creates the isosurface using all cells. My intent is to create the surface only using cells storing 3. Any idea why this might be?


Thanks.

> Date: Wed, 23 Feb 2011 08:23:29 -0500
> Subject: Re: [vtkusers] Visualizing multiple isosurfaces using vtkContourFilter
> From: bill.lorensen at gmail.com

> To: thkorah at hotmail.com
> CC: vtkusers at vtk.org 



> 
> There are two ways to do this:
> 
> 1) Create two ContourFilters. Use cf1->SetValue(0,val1) and
> cf2->SetValue(0,val2).
> You will need 2 mappers and actors.

> 2) Create one ContourFilter. Use cf->SetValue(0,val1) and cf->SetValue(1,val2).
> You will need 1 mapper and actor.
> 
> Both use share the same memory.
> 
> Coloring is easier in case 1).

> mapper1->SetInput(cf1->GetOutput());
> mapper1->ScalarVisibilityOff();
> actor1->SetMapper(mapper1);
> actor1->GetProperty()->SetDiffuseColor(r,g,b);
> mapper2->SetInput(cf2->GetOutput());

> mapper2->ScalarVisibilityOff();
> actor2->SetMapper(mapper2);
> actor2->GetProperty()->SetDiffuseColor(r,g,b);
> 
> Case 2 is trickier and involves mucking with lookup tables.
> 

> 
> 
> On Wed, Feb 23, 2011 at 1:16 AM, Thommen Korah <thkorah at hotmail.com> wrote:
> > Hi,
> > I have a pointcloud on which I perform segmentation to extract different

> > structures projecting out of a flat surface (a table for example). The
> > pointcloud is stored in a voxel data structure. I would now like to
> > visualize these segmented regions by creating  isosurfaces using

> > vtkContourFilter for each object. How can I generate multiple surfaces (eg.
> > book and a cup lying on the table) using the same shared data in memory? I
> > would also like to visualize each segmented region in a different color.

> > Thanks.
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at

> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:

> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers

> >
> >

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html


Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110301/9f1f4b91/attachment.htm>


More information about the vtkusers mailing list