[vtkusers] vtkProgrammableFilter in C++

Richard Strelitz strelitz at lanl.gov
Wed Jan 16 11:00:55 EST 2002


Patrick,
 Here is an example for you.  It takes a data set of vectors,
normalizes it and rotates it by 90 deg.  I have also included
the call sequence and the invocation of the object that uses
its output.
 You can replace the argument (void *ThisFilter) with a structure
that contains components which are pointers to vtkObjects and
parameters for the filter, but I opted to make this simple.
Please note (KITWARE especially) that when I just tried to operate
on and output the vector components, the filter returned an empty
dataset.  It seems, for no logical reason, necessary to add a
scalar field.  The documentation should contain the appropriate
caveat, or the functionality should be changed.  Of course, it
could be easier to correct my misperception(s).
 Good luck.
  Richard Strelitz, Vis Team
   Advanced Computing Lab, Los Alamos Nat'l Lab
--------------  EXAMPLE FOLLOWS ---------------------



void rotateVector(void *ThisFilter)
{
  vtkProgrammableFilter *pF = (vtkProgrammableFilter *)ThisFilter;
   long NPoints =pF->GetStructuredPointsInput()->GetNumberOfPoints();
 vtkVectors *pVcomp = vtkVectors::New();
        pVcomp->Allocate(NPoints);
		pVcomp->SetNumberOfVectors(NPoints);
  vtkVectors *pVel = pF->GetInput()->GetPointData()->GetVectors();
  vtkScalars *pNew = vtkScalars::New();
    pNew->Allocate(NPoints);
	pNew->SetNumberOfScalars(NPoints);
 float* tempVec = new float[3];
  for(long i=0; i<NPoints; i++)
   {    pVel->GetVector(i,tempVec);
		vtkMath::Normalize(tempVec);
		pNew->SetScalar(i,vtkMath::Norm(tempVec));
        pVcomp->SetVector(i,tempVec[1],-tempVec[0],0);
        	//	printf("%4d %8.2f %8.2f %8.2f
\n",i,tempVel,tempVec[0],tempVec[1]);
	}
 pF->GetOutput()->GetPointData()->SetScalars(pNew);
 pF->GetOutput()->GetPointData()->SetVectors(pVcomp);
 pNew->Delete(); pVcomp->Delete(); delete [] tempVec;


 return;}

...
 vtkProgrammableFilter *pNP = vtkProgrammableFilter::New();
    pNP->SetExecuteMethod(rotateVector,(void *)pNP);
	pNP->SetInput(pShrink2->GetOutput());
	pNP->DebugOff();
	pNP->Update();

 vtkStreamLine *pFront = vtkStreamLine::New();
		pFront->SetInput(pNP->GetStructuredPointsOutput());
		pFront->SetSource(pMask2->GetOutput());
		pFront->SetIntegrationDirectionToIntegrateBothDirections();
		pFront->SetMaximumPropagationTime(2*(Xlen+Ylen));
		pFront->SetTerminalSpeed(0.5);
		pFront->SetStepLength(0.3);
		pFront->Update();

-------------- end of example ----------------------------------
-----Original Message-----
From: vtkusers-admin at public.kitware.com
[mailto:vtkusers-admin at public.kitware.com]On Behalf Of Patrick Neumann
Sent: Wednesday, January 16, 2002 4:21 AM
To: vtkusers at public.kitware.com
Subject: [vtkusers] vtkProgrammableFilter in C++


Hi,

has anyone a C++ example using a vtkProgrammableFilter?

I found some entries about this topic in the mailing list but no answer
till now.
The main problem is the usage of the undocumented arguments of the
SetExecuteMethod method.

Thanks in advance!

Patrick


_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers




More information about the vtkusers mailing list