[vtkusers] Re: Using cell colors with point normals
Nigel Nunn
nNunn at ausport.gov.au
Wed Jul 19 10:34:09 EDT 2000
To: Ron Inbar [ron at eun.co.il]]
Re: Using cell colors with point normals.
Was: Getting vtkPolyDataRenderer to use both
cell data and point data.
Hi Ron,
I just faced a similar problem.
Here is a first pass at a solution.
Nigel.
//------------------------------------------------
void CPANLDoc::UseCellValuesToColorPointData()
//------------------------------------------------
{
// Choose how to display the results.
if (m_bColorByPanelForces)
m_panelMapper->SetScalarModeToUseCellData();
else
m_panelMapper->SetScalarModeToUsePointData();
vtkUnstructuredGrid* pGrid = m_pVtkData->GetPanelGrid();
vtkVectors *cellVecs = pGrid->GetCellData()->GetVectors();
vtkScalars *cellData = pGrid->GetCellData()->GetScalars();
vtkScalars *nodeData = pGrid->GetPointData()->GetScalars();
//-------------------------------------
// First, update data for each CELL.
//-------------------------------------
double vec[3];
for (i=1; i<=m_nPanels; ++i)
{
vec[0] = (float) m_FXPi(i,1);
vec[1] = (float) m_FYPi(i,1);
vec[2] = (float) m_FZPi(i,1);
cellVecs->SetVector(i-1, vec);
//cellData->SetScalar(i-1, 20 * m_FXPi(i,1));
//cellData->SetScalar(i-1, 10 * m_FYPi(i,1));
cellData->SetScalar(i-1, 10 * m_FZPi(i,1));
}
//-------------------------------------
// Now update data for each NODE.
// (Allocating values for the PointData
// by averaging over cell values.)
//-------------------------------------
const int MAX_IDS_IN_CELL = 4;
int idc, nIDs;
double val=0.0;
vtkIdList *cellIds = vtkIdList::New();
cellIds->Allocate(MAX_IDS_IN_CELL);
for (i=0; i<m_nNodes; ++i)
{
// Get list of CELLS that use this NODE
pGrid->GetPointCells(i, cellIds);
nIDs = cellIds->GetNumberOfIds();
val=0.0;
for (int j=0; j < nIDs; ++j)
{
idc = cellIds->GetId(j);
val += cellData->GetScalar(idc);
}
val /= nIDs;
nodeData->SetScalar(i, val);
}
m_pVtkData->GetPanelGrid()->Modified();
// Adjust colors in LookupTable
m_pVtkData->BuildLookupTable();
this->UpdateAllViews(NULL,0,0);
}
More information about the vtkusers
mailing list