[vtkusers] CopyAllocate
McClennan, Scott Andrew
mcclennan at wai.com
Thu Mar 11 20:25:15 EST 2010
Hi,
I'm trying to divide a large vtkStructuredGrid data set into smaller vtkUnstructuredGrid data sets to plot individually, but I do not want to make deep copies of the data. Is there a way to map cell data from the original data set to a sub-grid?
I think vtkDataSetAttributes::CopyAllocate() should help me, but it doesn't work as I think it should. I pasted the code I have so far below, which does indeed divide the grid up and I don't think it makes deep copies, but the colors are not mapped properly to the sub-grid. Can anyone help?
Thanks,
Scott
PS. I made the MaterialGridFilter to do what I think vtkThreshold should do, but it didn't seem to work for me.
...
std::vector< vtkSmartPointer<vtkUnstructuredGrid> > usgVector;
VTK_NEW_PTR(pusg,vtkUnstructuredGrid);
pusg->SetPoints(points);
pusg->Update();
for(int ic=0; ic<nmat-1; ic++){
usgVector.push_back(pusg);
}
MaterialGridFilter(usgVector,sgrid);
...
void MaterialGridFilter(std::vector< vtkSmartPointer<vtkUnstructuredGrid> > & usgVector, vtkSmartPointer<vtkStructuredGrid> & sgrid){
int nmat = usgVector.size();
// set up cell data for each material
std::vector< vtkSmartPointer<vtkCellArray> > caVector;
VTK_NEW_PTR(polys,vtkCellArray);
for(int ic=0;ic<nmat;ic++){
caVector.push_back(polys);
}
// loop through cells in the base grid
int niel=nd1-1,njel=nd2-1,nkel=nd3-1;
if (niel==0) niel=1;
if (njel==0) njel=1;
if (nkel==0) nkel=1;
int nel=niel*njel*nkel;
int iel=0;
int imat=0;
int cid=0;
VTK_NEW_PTR(nodelist,vtkIdList);
sgrid->Print(cout);
for(int k=0; k<nkel; k++){
for(int j=0; j<njel; j++){
for(int i=0; i<niel; i++){
imat = (int)sgrid->GetCellData()->GetScalars()->GetComponent(iel,0);
// construct Unstructured grid cell
if(imat<nmat){
cid=caVector[imat]->InsertNextCell(sgrid->GetCell(iel));
}
iel++;
}
}
}
// loop through materials and set cell data for each unstructured grid
vtkCellData *pd = sgrid->GetCellData();
int isize=0;
for(int ic=0;ic<nmat;ic++){
usgVector[ic]->SetCells(12,caVector[ic]);
isize = usgVector[ic]->GetNumberOfCells();
usgVector[ic]->GetCellData()->CopyAllocate(pd,isize,0,1);
usgVector[ic]->GetCellData()->CopyData(pd,1,1);
usgVector[ic]->Update();
usgVector[ic]->Print(cout);
}
}
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."
"Please consider our environment before printing this email."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100311/e7110e5a/attachment.htm>
More information about the vtkusers
mailing list