[vtkusers] Setting scalar point attributes in a contour

Christian Zemlin zemlinc at upstate.edu
Tue Jun 12 14:56:39 EDT 2007


Dear Marc,

thank you very much for your help.  My first question is completely 
answered,  and for the second one, I basically know what to do, and did it. 
The program runs but does not color the vertices as I want yet, but I think 
it should be a small mistake.  Could you look through the code I made 
following your suggestions and let me know if you see what I am missing?

Best wishes,

Christian

--------------------------

vtkContourFilter *contours = vtkContourFilter::New();
  contours->SetInputConnection(myFilter->GetOutputPort());
  contours->GenerateValues(1, isoLevel, isoLevel);
  contours->Update();
  int numPoints = contours->GetOutput()->GetNumberOfPoints();

  // Get the poly data
  vtkPolyData *polys = vtkPolyData::New();
  polys=contours->GetOutput();

  // Make a 1D float array in which entries equal row numbers
  vtkFloatArray* vm = vtkFloatArray::New();
  vm->SetNumberOfValues(numPoints);
  int vertex;
  for (vertex=0; vertex<numPoints; vertex++)
    vm->SetValue(vertex, (float) vertex);

  // Make a vtkFieldData object that contains the 1D array
  vtkFieldData* vmField = vtkFieldData::New();
  vmField->AddArray(vm);

  // Attribute the field data to the poly data
    polys->SetFieldData(vmField);

  // Define lookup table
    vtkLookupTable *lut= vtkLookupTable::New();
    lut->SetHueRange(0.4,0.0);
    lut->SetSaturationRange(1,1);
    lut->SetValueRange(1,1);

  // map the contours to graphical primitives
  vtkPolyDataMapper *contMapper = vtkPolyDataMapper::New();
  contMapper->SetInput(polys);
  contMapper-> SetScalarVisibility(1);
  contMapper->SetLookupTable(lut);
  contMapper->SetScalarRange(0.0, 100000.0);  // there are between 80,000 
and 90,000 vertices

  // create an actor for the contours
  vtkActor *contActor = vtkActor::New();
  contActor->SetMapper(contMapper);










----- Original Message ----- 
From: "Marc Cotran" <marc at cotran.ca>
To: "Christian Zemlin" <zemlinc at upstate.edu>
Cc: <vtkusers at vtk.org>
Sent: Sunday, June 10, 2007 12:23 PM
Subject: Re: [vtkusers] Setting scalar point attributes in a contour


> Hi Christian,
>
> For 1) - You can use vtkMassProperties to get the number of polygons in 
> your isosurface. You may wish to use a vtkTriangleFilter first to ensure 
> that only triangle polys are present. You can also look at the vtkPolyData 
> instance directly. In your case, yourContourFilter->GetOutput() is a 
> vtkPolyData instance, which is composed of:
>
>    * Points - a vtkPoints instance defining the geometry of the isosurface
>    * Cells - 4 vtkCellArray instances defining how the points are
>      connected together to make the isosurface's triangles, vertices,
>      lines, and triangle strips
>
> You can either vtkPolyData::GetNumberOfPolys() or 
> vtkPolyData::GetPolys()::GetNumberOfCells. Before using any of these 
> methods, make sure you Update() the pipeline (eg. 
> yourContourFilter->Update) .
>
> For 2) - Take a look at vtkFieldData and vtkDataObject (of which 
> vtkPolyData is a subclass). You can create your attribute scalar data for 
> the points as a vtkFieldData object, and then vtkDataObject::SetFieldData 
> with that object. You may wish to vtkMapper::SetScalarVisibility(1) in 
> order to visualize the scalars. If you do so, you will need to 
> vtkMapper::SetLookupTable as well.
>
> hth
>
> Marc
>
> Christian Zemlin wrote:
>> Dear vtk-experts,
>>  I would like to assign a scalar attribute to each vertex of an 
>> isosurface that I generated using vtkContourFilter.
>> 1) How can I determine the number of triangles that a contour consists of 
>> ?
>> 2) How can I assign scalar properties to a particular vertex of a 
>> contour?
>>  Thank you,
>>  Christian
>>
>> ------------------------------------------------------------------------
>> _______________________________________________
>> This is the private VTK discussion list.
>> Please keep messages on-topic. Check the FAQ at: 
>> http://www.vtk.org/Wiki/VTK_FAQ
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> This is the private VTK discussion list. Please keep messages on-topic. 
>> Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>> 




More information about the vtkusers mailing list