[vtkusers] Re: Using cell colors with point normals
Ron Inbar
ron at eun.co.il
Wed Jul 19 13:26:53 EDT 2000
Hi Nigel,
I did some probing into the vtkPolyDataMapper code and I found the answer:
the mapper behaves as desired if the following condition holds:
input->GetPointData()->GetNormals() != 0 &&
interpolation != VTK_FLAT &&
input->GetCellData()->GetNormals() == 0 &&
(this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA ||
input->GetPointData()->GetScalars() == 0)
What this means is that you need to have point normals and cell scalars (of
course), but no cell normals. So after you generate all the necessary data
(don't forget to update the mapper's input), just write:
mapper->GetInput()->GetCellData()->SetNormals(0);
and either
mapper->GetInput()->GetPointData()->SetScalars(0);
or more simply
mapper->SetScalarModeToUseCellData();
and off you go.
Hope this helps.
Ron
----- Original Message -----
From: Nigel Nunn <nNunn at ausport.gov.au>
To: <vtkusers at public.kitware.com>
Cc: <ron at eun.co.il>
Sent: éåí øáéòé 19 éåìé 2000 17:34
Subject: Re: Using cell colors with point normals
>
> 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.
>
>
> file://------------------------------------------------
> void CPANLDoc::UseCellValuesToColorPointData()
> file://------------------------------------------------
>
>
> // 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();
>
> file://-------------------------------------
> // First, update data for each CELL.
> file://-------------------------------------
>
> 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);
> file://cellData->SetScalar(i-1, 20 * m_FXPi(i,1));
> file://cellData->SetScalar(i-1, 10 * m_FYPi(i,1));
> cellData->SetScalar(i-1, 10 * m_FZPi(i,1));
> }
>
>
> file://-------------------------------------
> // Now update data for each NODE.
> // (Allocating values for the PointData
> // by averaging over cell values.)
> file://-------------------------------------
>
> 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