[vtkusers] single actor with different cell-colors

jeando.barnichon at free.fr jeando.barnichon at free.fr
Fri Nov 17 04:35:40 EST 2006


Chavdar,
Herebelow is the corrected version :
hth,
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
}

// Add m_pSoilArray data array to the cell field data of m_pMeshPolyData
m_pMeshPolyData->GetCellData()->AddArray(m_pSoilArray);

// 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 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


Selon Chavdar Papazov <chenkaz at yahoo.com>:

> Hi to all,
>
>   it seems so, that I have a similar problem: I would like to have the
> surface of a single vtkPolyData object in differen colors.
>   Do you have any ideas how to achieve this?
>
>   I'm sorry but I have missed the beginning of this email-serie. Would you
> resend me the other emails, please.
>
>   Thanks.
>
>   Che
>
>
> Jean-Do Barnichon <jeando.barnichon at free.fr> wrote:  Yes,
> that was the exact problem, and everything is fine now.
> Thanks for helping
> Jean-Do
>
> Obada Mahdi a écrit :
> > Hi Jean-Do,
> >
> > on a quick note, it seems that the "SoilArray" data array is never
> > being added to the cell field data of m_pMeshPolyData.  After cerating
> > "m_pSoilArray", try
> >
> >  m_pMeshPolyData->GetCellData()->AddArray(m_pSoilArray);
> >
> > HTH,
> >
> > Obada
> >
> >
>
> _______________________________________________
> 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
>
>
>
> ---------------------------------
> Sponsored Link
>
> $420,000 Mortgage for $1,399/month -   Think You Pay Too Much For Your
> Mortgage? Find Out!





More information about the vtkusers mailing list