[Paraview] how to get all the arrays associated with Point and Cell data in a filter

FISSELL at pitt.edu FISSELL at pitt.edu
Tue Sep 13 17:59:10 EDT 2011


Hi,

I am writing a custom filter that takes polydata as input and outputs
polydata
that contains a subset of the cells in the input polydata.
I would like the output polydata to include all the vector/scalar etc arrays
associated with the input, appropriately subsetted.
I think I have working code, but I think it only grabs e.g. 1 scalar array
associated with point data (via input->GetPointData()->GetScalars();)
 How would I access multiple associated scalar arrays ?

The only way I found to implement getting even just the single scalar array
is a sort of brute force loop that saves point/cell ids I want to keep
(code snippet below).
Is this the best way to implement this ?

thanks
kate


=========================================================
// code snippet for filter to take polydata as input and output polydata
// with a subset of input polydata cells

int vtkMyFilter::RequestData(vtkInformation *vtkNotUsed(request),
                                         vtkInformationVector **inputVector,
                                         vtkInformationVector *outputVector)
{

// allocate vectors to store vtk ids of cells and points I want to keep
vtkIdList *outcellids = vtkIdList::New ();
outcellids->Allocate(num_cells_in,0);

vtkIdList *outptids = vtkIdList::New ();
outptids->Allocate(num_points_in,0);


// loop over input lines, decide what to keep
for(lines->InitTraversal(); lines->GetNextCell(npts,pts); num_poly++) {

	if (I want this cell) {

		out_line_cnt++;
		out_tot_pt_ctr = out_tot_pt_ctr + npts;

		// collect pt ids for output vectors
		for (k=0; k < npts; k++) {
			outptids->InsertNextId ((const vtkIdType) in_tot_pt_ctr++);
		}

		// collect cell ids for output
		outcellids->InsertNextId ((const vtkIdType) num_poly);

	}
	// not adding this line, just update points counter for input points array
	else {
		in_tot_pt_ctr =  in_tot_pt_ctr + npts;
	}
}


// copy line/point data to output
outcellids->Squeeze();
outptids->Squeeze();
output->Allocate(input,num_cells_in,0);
output->CopyCells(input, outcellids, NULL);
output->Squeeze();

/////// copy point data active??? vectors
invec = input->GetPointData()->GetVectors();
if (invec != NULL) {
	num_comp = invec->GetNumberOfComponents();

	outvec =  invec->NewInstance();
	outvec->SetNumberOfComponents(num_comp);
	outvec->SetNumberOfTuples(out_tot_pt_ctr);
	outvec->SetName(invec->GetName());
	for (i=0; i<out_tot_pt_ctr; i++) {
		outvec->InsertTuple(i,invec->GetTuple(outptids->GetId(i)));
	}
	output->GetPointData()->SetVectors(outvec);
}

// repeat for
//	input->GetPointData()->GetScalars();
//	input->GetCellData()->GetVectors();
//	input->GetCellData()->GetScalars();
//	etc

}



==========================================================



More information about the ParaView mailing list