[vtkusers] How to select a specific cell/point attribute from a vtkDataSet? (Next)

Leguay Romain romain.leguay at etu.u-bordeaux1.fr
Mon May 23 12:01:20 EDT 2011


Hello Eric,
Thank you for your answer.

I try to do some color mapping with a specific cell attribute.

I write this function (in Java):

vtkActor colorMapping(String attributeName, vtkDataSet dataSet) {

		vtkDataArray attributeArray = null;
		if (dataSet.GetCellData() != null &&  
dataSet.GetCellData().GetNumberOfArrays() != 0) {
			attributeArray = dataSet.GetCellData().GetArray(attributeName);
		} else if (dataSet.GetPointData() != null &&  
dataSet.GetPointData().GetNumberOfArrays() != 0) {
			attributeArray = dataSet.GetCellData().GetArray(attributeName);
		}

		if (attributeArray == null) {
			System.err.println("No attribute with name " + attributeName);
			return null;
		}


		vtkMapper mapper = null;
		if (dataSet instanceof vtkUnstructuredGrid || dataSet instanceof  
vtkPolyData) {
			mapper = new vtkPolyDataMapper();
			((vtkPolyDataMapper)mapper).SetInput((vtkPolyData)dataSet);
			vtkLookupTable coldAndHot = new vtkLookupTable();
			coldAndHot.SetNumberOfColors(10000);
			coldAndHot.SetHueRange(240. / 360., 0.);
			coldAndHot.SetAlphaRange(1., 1.);
			coldAndHot.Build();
			mapper.SetLookupTable(coldAndHot);
		}

		if (mapper == null) {
			System.err.println("Unexpected dataSetType");
			return null;
		}

		vtkActor actor = new vtkActor();
		actor.SetMapper(mapper);
		return actor;
	}



I test this function with an unstrutured grid contains two cell  
attributes: (temperature, density). When I choose density or  
temperature, I have the same color mapping for my dataSet.
I don't see where is the problem with my code.
Has anyone got any ideas?

Thanks,
Romain


"Eric E. Monson" <emonson at cs.duke.edu> a écrit :

> Hello Romain,
>
> If I understand your question correctly, the standard way of  
> accessing attributes in a vtkDataSet is something like:
>
> imageData->GetPointData()->GetArray("array_name");
> polyData->GetCellData()->GetArray("array2_name");
>
> (with some other variations available). Both vtkCellData and  
> vtkPointData inherit from vtkDataSetAttributes, so many of the  
> methods you'll need are listed there or in it's superclass,  
> vtkFieldData:
>
> http://www.vtk.org/doc/nightly/html/classvtkDataSetAttributes.html
> http://www.vtk.org/doc/nightly/html/classvtkFieldData.html
>
> Hope this helps,
> -Eric
>
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
> Eric E Monson
> Duke Visualization Technology Group
>
>
> On May 23, 2011, at 3:22 AM, Leguay Romain wrote:
>
>> Hello everyone!
>> I found how to select a cell (or point) attribute with a  
>> vtkDataSetReader's method: SetScalarsName(const char*).
>> I try to do the same thing with a vtkDataSet.
>>
>> Has anyone got any leads?
>>
>> Thanks,
>> Romain LEGUAY
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at  
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:  
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



Romain LEGUAY




More information about the vtkusers mailing list