[vtkusers] single actor with different cell-colors

jeando.barnichon at free.fr jeando.barnichon at free.fr
Thu Nov 16 05:34:03 EST 2006


Jens,
I basically need to do the same thing as you,
but still i did not succeed (i.e. all faces of the actor are still of the same
color). I obviously do something wrong but can´t see what.
Here below is the small piece of code I´m using.
Do you see anything wrong with it, or could you tell me a bit more on how you
achieve things in your case.
Thanks in advance,
Jean-Do


Begin Code snipet

...
vtkPolydata *m_pMeshPolyData = vtkPolydata::New();
... // reading of m_pMeshPolyData from elsewhere

// Define scalar array
vtkIntArray *m_pSoilArray = vtkIntArray::New();
m_pSoilArray->SetName("SoilArray");

// Fill the m_pSoilArray
m_pSoilArray->SetNumberOfValues(m_pMeshPolyData->GetNumberOfCells());
// numcell is the number of cells in the input polydata m_pMeshPolyData
for (int i=0; i<m_pMeshPolyData->GetNumberOfCells(); i++) {
  m_pSoilArray->SetValue(i,property[i]); //property array defined elsewhere
}

// Build a lookup table
vtkLookupTable *Lut = vtkLookupTable::New();
Lut->SetNumberOfTableValues(numSoils);
for (int IdSoil=0; IdSoil<numSoils; IdSoil++) {
  // Set the soil color (red green blue are red from elsewhere)
  Lut->SetTableValue(IdSoil,red,green,blue,1.0);
}
Lut->Build();

// Then try to set mapper to use color based on the scalar array "SoilArray"
// using cell field data
vtkPolyDataMapper *FaceMapper = vtkPolyDataMapper::New();
FaceMapper->SetInput(m_pMeshPolyData);
FaceMapper->SetLookupTable(Lut);
FaceMapper->ScalarVisibilityOn();
FaceMapper->SelectColorArray("SoilArray");
FaceMapper->SetScalarModeToUseCellFieldData();
FaceMapper->SetColorModeToMapScalars();
FaceMapper->Update();

// Add mapper to actor, and actor to renderer
vtkActor *FaceActor = vtkActor::New();
FaceActor->SetMapper(FaceMapper);
Renderer->AddActor(FaceActor);
...

End Code snipet



Jens jens-devel at gmx.de
Wed Nov 8 08:10:17 EST 2006

Previous message: [vtkusers] single actor with different cell-colors
Next message: [vtkusers] single actor with different cell-colors
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

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

solved - found the functions in vtkMapper.

Jens schrieb:
> Hi,
>
> I would like to color cells depending on there cell-data.
>
> Is it possible to have one _single_ actor out of an unstructured grid,
> which cells are in different colors depending on the cell-data?
>
> I was searching for a possibility like that but only found ways to set
> the color of a whole actor.
>
> The only solution I can see now is to split the unstructured grid using
> vtkThreshold into  a bunch of small grids and create actors out of them.
> That would take much memory and time because each cell belongs to more
> than one color-region. I would have to run through the whole pipeline
> each time the user changes the color-region.
>
> Any other ideas?
>
> Greetings
> Jens
> _______________________________________________
> 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