Thank you for your advice.I find it was the input problem,but I got a  new 
one.When I run my filter ,I got an error:Cell array cell types with 1 
components, has only 18 tuples but there are 180 cells .

The below is how  my RequestData() write.I am sorry to type long boring code . 
I have tried to settle it by myself,but it seems a long time job. I write the 
filter almost follow the source code vtkAppendFilter .I make my own code 
bold-faced.I just want to add some lines to the input dataset. I know I should 
add the cell data when I insert the line cells,but I don't know how to add.

code:
//get the output info object
vtkInformation *outInfo= outputVector->GetInformationObject(0);
//get the output
vtkUnstructuredGrid* output = 
vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkIdType numPts,numCells,ptOffset;
int tenth,count,abort = 0;
float decimal;
vtkPoints *newPts;
vtkPointData *pd;
vtkCellData *cd;
vtkIdList *ptIds,*newPtIds;
int idx;
vtkDataSet *ds;
vtkIdType ptId,cellId,newCellId;
vtkPointData *outputPD=output->GetPointData();
vtkCellData *outPutCD = output ->GetCellData();
vtkDebugMacro(<<"Appending data together");
count = 0 ;
decimal = 0 ;
numPts = 0;
numCells = 0;
int numInputs = inputVector[0]->GetNumberOfInformationObjects();
vtkDataSetAttributes::FieldList ptList(numInputs);
vtkDataSetAttributes::FieldList cellList(numInputs);
int firstPD = 1;
int firstCD = 1;
vtkInformation *inInfo = 0;
for(idx = 0;idx<numInputs;++idx)
{
inInfo = inputVector[0]->GetInformationObject(idx);
ds = 0;
if(inInfo)
{
ds  = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
}
if(ds!=NULL)
{
{
if(ds->GetNumberOfPoints()<=0&&ds->GetNumberOfCells()<=0)
continue;
}
numPts +=ds->GetNumberOfPoints();
numCells+=ds->GetNumberOfCells();
pd = ds->GetPointData();
if(firstPD)
{
ptList.InitializeFieldList(pd);
firstPD = 0;
}
else ptList.IntersectFieldList(pd);
cd = ds->GetCellData();
if(firstCD)
{
cellList.InitializeFieldList(cd);
firstCD = 0;
}
else cellList.IntersectFieldList(cd);
}//if non-empty dataset
}//for all inputs
if(numPts<1)
{
vtkDebugMacro(<<"No data to append!");
return 1;
}
//

int numRays;
vector<WaveRay*> rayVector;
numRays = IcosahedronModel::GenerateRays(&rayVector,TF);

//now can allocate
output->Allocate(numCells+numRays);
outputPD->CopyGlobalIdsOn();
outputPD->CopyAllocate(ptList,numPts);
outPutCD->CopyGlobalIdsOn();
outPutCD->CopyAllocate(cellList,numCells);
newPts = vtkPoints::New();
newPts->SetNumberOfPoints(numPts+2*numRays);
ptIds = vtkIdList::New();ptIds->Allocate(VTK_CELL_SIZE);
newPtIds = vtkIdList::New();newPtIds->Allocate(VTK_CELL_SIZE);
//append each input dataset together
tenth = (numPts+numCells)/10+1;
ptOffset = 0;
int inputCount = 0;
for(idx = 0;idx <numInputs&&!abort;++idx)
{
inInfo = inputVector[0]->GetInformationObject(idx);
ds = 0;
if(inInfo)
{
ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
}
if(ds!=NULL&&(ds->GetNumberOfCells()>0||ds->GetNumberOfPoints()>0))
{
numPts = ds->GetNumberOfPoints();
numCells = ds->GetNumberOfCells();
pd = ds->GetPointData();
for(ptId = 0;ptId<numPts&&!abort;ptId++)
{
newPts->SetPoint(ptId+ptOffset,ds->GetPoint(ptId));
outputPD->CopyData(ptList,pd,inputCount,ptId,ptId+ptOffset);
//Update progress
count++;
if(!(count%tenth))
{
decimal+=0.1;
this->UpdateProgress(decimal);
abort= this->GetAbortExecute();
}
}
cd = ds->GetCellData();
for(cellId = 0;cellId<numCells&&!abort;cellId++)
{
ds->GetCellPoints(cellId,ptIds);
newPtIds->Reset();
for(int i =0;i<ptIds->GetNumberOfIds();i++)
{
newPtIds->InsertId(i,ptIds->GetId(i)+ptOffset);
}
newCellId = output->InsertNextCell(ds->GetCellType(cellId),newPtIds);
outPutCD->CopyData(cellList,cd,inputCount,cellId,newCellId);
//Update progress
count++;
if(!(count%tenth))
{
decimal+=0.1;
this->UpdateProgress(decimal);
abort = this->GetAbortExecute();
}
}
ptOffset+=numPts;
++inputCount;
}
}
//Add lines to the input dataset
vtkLine* line;
for(idx = 0;idx<numRays;++idx)
{
//newPts->InsertNextPoint(();
//newPts->InsertNextPoint();
newPts->SetPoint(ptOffset++,((WaveRay*)rayVector[idx])->GetPosition());
newPts->SetPoint(ptOffset++,((WaveRay*)rayVector[idx])->GetLinePosition(2));
line = vtkLine::New();
line->GetPointIds()->SetId(0,ptOffset-2);
line->GetPointIds()->SetId(1,ptOffset-1);
output->InsertNextCell(line->GetCellType(),line->GetPointIds());
//I know I should add cell data attributes,but how?

line->Delete();
}

//Update ourselves and release memory

output->SetPoints(newPts);
newPts->Delete();
ptIds->Delete();
newPtIds->Delete();





 
2009-09-24 



young_jh123 



发件人: Utkarsh Ayachit 
发送时间: 2009-09-22  22:25:12 
收件人: young_jh123 
抄送: Moreland, Kenneth; [email protected] 
主题: Re: [Paraview] Problems with user defined filter 
 
So you have written a vtk filter, then I am assuming you have some main() in 
which you are creating a VTK-pipeline to use this filter? Are you setting up 
the inputs correctly? Try calling Update() directly on  the filter, does that 
result in calling of your RequestData() method? 


Utkarsh


On Tue, Sep 22, 2009 at 9:04 AM, young_jh123 <[email protected]> wrote:

I want to write VTK filter first.Because I  think it will be easier coding in 
windows than in linux,and if a VTK filter can work I know how to change a it to 
a  paraview plugin filter.
I'll try to write it as a paraview plugin directly.Thank you !

2009-09-22 



young_jh123 



发件人: Moreland, Kenneth 
发送时间: 2009-09-22  06:59:07 
收件人: young_jh123; [email protected] 
抄送: 
主题: Re: [Paraview] Problems with user defined filter 
How are you trying to use your filter?  Are you trying to define it in a 
ParaView plugin?  If so, you should be able to leave out any of the _EXPORT 
declarations and it should work OK.

-Ken


On 9/21/09 9:02 AM, "young_jh123" <[email protected]> wrote:


I write a filter class just like the vtkAppendFilter ,and change a little on 
the mothod RequestData ..My class also inherited from 
vtkUnstructuredGridAlgorithm .I did the job all on windows vs2008.The 
vtkAppendFilter.h defines the class with VTK_GRAPHICS_EXPORT which means 
__declspec( dllimport ) on my computer,but if I used that macro to define my 
own filter class it would met some link errors .If I use the macro VTK_EXPORT 
or did not use macro to  define my filter class ,it can complie well,but it did 
not work.I tried the debug.I found it would not invoke my RequestData function 
at all,and the it would not invoke vtkUnstructuredGridAlgorithm'RequestData 
methord either.The program invoked the method RequestData form vtkAlgorithm 
class directly.I don't know why? what should I do if want to define my own 
filter? Thanks a lot!
 
2009-09-21 


young_jh123  




   ****      Kenneth Moreland
    ***      Sandia National Laboratories
***********  
*** *** ***  email: [email protected]
**  ***  **  phone: (505) 844-8919
    ***      web:   http://www.cs.unm.edu/~kmorel



_______________________________________________
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 ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview
_______________________________________________
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 ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to