[vtkusers] How to select a specific cell/point attribute from a vtkDataSet? (Next)
Leguay Romain
romain.leguay at etu.u-bordeaux1.fr
Tue May 24 01:48:24 EDT 2011
Hello Eric,
Thanks so much for your answer and your example.
Just to be sure, when I do a ug.GetPointData().GetArray("attribute"),
vtk reads this array, doesn't it? If I use another attribute, is the
previous array deleted (of course if I don't use it anymore)?
Thanks,
Romain
"Eric E. Monson" <emonson at cs.duke.edu> a écrit :
> Hey Romain,
>
> First, if you're using an unstructured grid I'd use vtkDataSetMapper
> rather than vtkPolyDataMapper. Maybe there's no problem, but I think
> the latter is supposed to be specifically for polydata.
>
> You can have the same data set which has both cell and point data
> going into the mapper, and then switch between whether you are
> coloring by point or cell attributes by doing something like this
> (sorry if there are syntax mistakes, I was testing in Python rather
> than Java):
>
> // Set up the original mapper
> vtkDataSetMapper mapper = new vtkDataSetMapper();
> mapper.SetInput(ug);
> mapper.SetScalarModeToUsePointData();
> mapper.ScalarVisibilityOn();
> mapper.SetLookupTable(coldAndHot);
> mapper.SetScalarRange(ug.GetPointData().GetArray("temperature").GetRange());
>
> // Switch to coloring by cell data
> mapper.SetScalarModeToUseCellData();
> mapper.SelectColorArray("density");
> mapper.SetScalarRange(elev.GetOutput().GetCellData().GetArray("density").GetRange());
>
> // Switch back to coloring by point data
> mapper.SetScalarModeToUsePointData();
> mapper.SelectColorArray("temperature");
> mapper.SetScalarRange(ug.GetPointData().GetArray("temperature").GetRange());
>
> So when you switch the attribute you're coloring by, you should only
> have to modify how the mapper is handling colors, and then call
> renderWindow.Render() to see the updated scene.
>
> -Eric
>
>
> On May 23, 2011, at 12:01 PM, Leguay Romain wrote:
>
>> 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
>>
>
>
Romain LEGUAY
More information about the vtkusers
mailing list