[vtkusers] vtkSelection with GLOBALIDS, vtkExtractSelection returns empty

David E DeMarle dave.demarle at kitware.com
Thu Jul 9 14:04:41 EDT 2009


You should make up your own global ids and assign them at the reader
(early on in the pipeline). Their purpose is to give a consistent name
to each cell and/or point, unlike INDICES which are just offsets into
the cell and point arrays. INDICES can vary at every step of the
pipeline. For example, if a filter deletes half of the cells, the cell
at INDEX 0 may or may not be the same entity in the dataset before the
filter and in the dataset after. If the data has a GLOBALID array, the
cell with GLOBALID 0 will be the same entity either before or after,
even if it has moved to a different index.

To create global ids, create a vtkIdType Array, populate it with
unique values, and then mark it as the Active GlobalID array. I think
there is a filter which does this.

After that, once you use point picker, find the points' globalid
values, then populate the selection with that. Then run the data and
the selection through extract selection filter to make a new data set
consisting of only those points you've picked.

David E DeMarle
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x109



On Wed, Jul 8, 2009 at 7:30 PM, da xu<remywendy at gmail.com> wrote:
> I still haven't figured this out.
>
> When I look at my original datasets, I notice that the GlobalID array does
> not exist. I assmed that when I used vtkPointPIcker (with x,y,z=1)
> coordinates, vtkPointPicker::GetPointID() returns the global ID? I'm
> guessing it isnt; however trying with INDICES and PEDIGREEID yeilded empty
> extractions as well!
>
> On Wed, Jul 8, 2009 at 12:46 AM, John Platt <jcplatt at dsl.pipex.com> wrote:
>>
>> Hi,
>>
>> Try changing your selection array from vtkIntArray to vtkIdTypeArray and
>> check that the filters copy the GLOBALIDS (the default is not to copy or
>> interpolate).
>>
>> John.
>>
>> ----- Original Message -----
>> From: da xu
>> To: vtkusers at vtk.org
>> Sent: Wednesday, July 08, 2009 8:12 AM
>> Subject: [vtkusers] vtkSelection with GLOBALIDS,vtkExtractSelection
>> returns empty
>> Hey all,
>>
>> I am trying to extract a section of my datasets using vtkSelection. I
>> currently have a GUI that the user clicks on to select a start and end point
>> using vtkPointPicker, returning the PointID. With a starting POINTID and
>> ending POINTID, i then use a vtkSelection with field type POINT, ContentType
>> GLOBALIDS to extract a dataset containing the points (with
>> vtkSelectionNode's SetSelectionList correctly set I believe). However, I
>> always end up extracting an empty grid.
>>
>> I can't figure out if:
>>  My vtkSelectionNode is set up incorrectly
>>  I'm using vtkExtractSelection incorrectly.
>>  The vtkPointPicker doesnt actually get GLOBALIDS ?
>>  Missing an update somewhere?
>>
>> Here is the code:
>>
>> // Set up vtkSelectionNode
>>     vtkSelection* selection = vtkSelection::New();
>>     vtkSelectionNode* selectionNode = vtkSelectionNode::New();
>>     selectionNode->SetFieldType(
>> vtkSelectionNode::POINT);
>>     selectionNode->SetContentType(vtkSelectionNode::GLOBALIDS);
>>
>> // Populate the selection node with our GLOBALIDS (obtained from
>> vtkPointPicker)
>>     vtkIntArray* intarray = vtkIntArray::New();
>>     for (int a = first; a < second; a++)
>>     {
>>         intarray->InsertNextValue(a);
>>     }
>>     selectionNode->SetSelectionList(intarray);
>>     selection->AddNode(selectionNode);
>>
>> // Some setup stuff, Our source data is from a multiblock data set
>>     vtkMultiBlockDataSet *extractFrom =
>> vtkMultiBlockDataSet::SafeDownCast(m_v_modules.at(0)->getDataObject());
>>     int nblocks = extractFrom->GetNumberOfBlocks();
>>
>>     vtkGeometryFilter *filter = vtkGeometryFilter::New();
>>     vtkDataSetMapper *mapper = vtkDataSetMapper::New();
>>     int counter=0;
>>     vtkExtractSelection* extractSelection = vtkExtractSelection::New();
>>
>> // Iterate through our datasets (structured grids) and apply
>> vtkExtractSelection to them. Always extracts empty!
>>     vtkCompositeDataIterator *iter = extractFrom->NewIterator();
>>     iter->InitTraversal();
>>
>>     int totalpoints = 0;
>>     while (!iter->IsDoneWithTraversal())
>>     {
>>         vtkDataSet* ds =
>> vtkDataSet::SafeDownCast(iter->GetCurrentDataObject());
>>         if (ds)
>>         {
>>             const char* name = ds->GetClassName();    /// Temp debugger
>>             extractSelection->RemoveAllInputs();
>>             extractSelection->SetInput(0, ds);    /// Set the vtkDataSet
>> for extraction
>>             extractSelection->SetInput(1, selection);    /// Set the
>> vtkSelection for extraction
>>             vtkDataObject* extracted = extractSelection->GetOutput();
>>             extractSelection->Update();
>>             const char* name2 = extracted->GetClassName();    /// Temp
>> debugger
>>
>>             vtkUnstructuredGrid* unstructGridTest =
>> vtkUnstructuredGrid::SafeDownCast(extracted);
>>             int ntemp1 = unstructGridTest->GetNumberOfPoints();
>>             totalpoints += ntemp1;
>>             counter++;
>>         }
>>         iter->GoToNextItem();
>>     }
>>
>> ________________________________
>>
>> _______________________________________________
>> 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
>
>
> _______________________________________________
> 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
>
>



More information about the vtkusers mailing list