[vtkusers] Help on coloring with scalars

knut.bredemeier at technoteam.de knut.bredemeier at technoteam.de
Wed Sep 11 04:51:53 EDT 2002


Hi,

I wrote a litle vtk-program that shows a 3d representation of illumination distribution from lamps. I create scalar values for coloring and triangle strips and put them into vtkPolyData.

The xyz - coordinates are calculated with the angles of the illumination values in this way:
            x = [illumination val]*cos(Phi)*sin(Theta);
            y = [illumination val]*sin(Phi)*sin(Theta);
            z = [illumination val]*cos(Theta);
The scalars that I'm using for coloring are the illumination values.

The 3d - visualisation works fine but there are some triangles that are not correctly colored. I put a screenshot (19kB) on out server, so you can have a look at it if you like:
http://www.technoteam.de/temp/3d.jpg

Here some information about my environment:
- Vtk 4.0
- Windows 2000
- C++

This is my function to create the polydata:
-------
vtkPolyData *TVtk3DView::_pXYZToPolyData(float *_fpX, float *_fpY, float *_fpZ, float *_fpScalars, int _iYCnt, int _iXCnt, int _iClosedFlag)
{
	vtkPolyData *pPolydata = vtkPolyData::New();

	vtkFloatArray *pScalars = vtkFloatArray::New();
	float *fpPtr = _fpScalars;
	for(int i = 0; i < _iYCnt*_iXCnt; i++)
		pScalars->InsertTuple1(i, *fpPtr++);

	pPolydata->GetPointData()->SetScalars(pScalars);
	pScalars->Delete();

	vtkPoints *pPoints = vtkPoints::New();
	pPoints->SetNumberOfPoints(_iYCnt*_iXCnt);
	float *fpXPtr = _fpX;
	float *fpYPtr = _fpY;
	float *fpZPtr = _fpZ;
	for(int i = 0; i < _iYCnt*_iXCnt; i++)
		pPoints->SetPoint(i, *fpXPtr++, *fpYPtr++, *fpZPtr++);

	pPolydata->SetPoints(pPoints);
	pPoints->Delete();

	vtkCellArray *pStrips = vtkCellArray::New();
	int i = 0;
	for(int yi = 0; yi < _iYCnt-1; yi++)
	{
		pStrips->InsertNextCell(_iXCnt*2);
		for(int xi = 0; xi < _iXCnt; xi++)
		{
			pStrips->InsertCellPoint(i);
			pStrips->InsertCellPoint(i+_iXCnt);
			i++;
		}
	}

	pPolydata->SetStrips(pStrips);
	pStrips->Delete();

    vtkCleanPolyData *pCleanPolyData = vtkCleanPolyData::New();
    pCleanPolyData->SetInput(pPolydata);

    pPolydata->Delete();
    
    return pCleanPolyData->GetOutput();
}
-------

And here's the visualisation:

-------
	vtkPolyData *pPolydata = _pXYZToPolyData(_fpX, _fpY, _fpZ,
				 _fpScalars, _iYCnt, _iXCnt, _iClosedFlag);

	vtkPolyDataNormals *pNormals = vtkPolyDataNormals::New();
	pNormals->SetInput(pPolydata);

	float fMin, fMax;
	_vGetVectorMinMax(_fpScalars, _iYCnt * _iXCnt, &fMin, &fMax);

	vtkLookupTable *pLut = vtkLookupTable::New();

	vtkPolyDataMapper *pMapper = vtkPolyDataMapper::New();
	pMapper->SetScalarRange(fMin, fMax);
	pMapper->ImmediateModeRenderingOn();
	pMapper->SetLookupTable(pLut);
	pMapper->SetInput(pNormals->GetOutput());

	...
-------

What is wrong with my solution? Or is it the renderer? 

Many thanks for any hints,

Knut Bredemeier

--
knut.bredemeier at technoteam.de




More information about the vtkusers mailing list