[vtkusers] How to add a filter in ParaView for vtp files

Vidya Raghavan vidya_raghavan at hotmail.com
Wed Oct 6 19:39:03 EDT 2004


Hi all,

I'm sorry for being so persistent, but I looked at PVLocal example to add a 
filter, but it's basically a simple cone display. Basically, I need to 
enable a filter when I load a vtp file, and obtain the surface normals of 
the ploygonal data. I have code below which does it, but am finding it 
difficult to transform the vtk code below as a plug-in to paraview. Several 
questions that I have unanswered are:
1) How do I enable the filter when I load a .vtp file?
2) How do I apply this code below to the current vtp file loaded in 
Paraview?

If someone can help me with this, I think I can go further with this on my 
own, since I need to integrate some code with this that does some processing 
on surface normal values.

I would really appreciate your help!


-------------------------------------------------------------------------------------------------------------------



#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkXMLPolyDataReader.h"
#include "vtkPolyDataNormals.h"
#include "vtkPolyData.h"
#include "vtkPointData.h"
#include "vtkProperty.h"

int main( int argc, char *argv[] )
{
	vtkXMLPolyDataReader *reader1 = vtkXMLPolyDataReader::New();
	reader1->SetFileName("model1.vtp");

	vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
	mapper1->SetInput(reader1->GetOutput());

	vtkProperty *prop1 = vtkProperty::New();
                prop1->SetDiffuseColor(0.5, 0.5, 0.5);
	prop1->SetSpecularPower(50);
	prop1->SetSpecular(.5);
	prop1->SetDiffuse(.8);

	vtkActor *actor1 = vtkActor::New();
	actor1->SetMapper(mapper1);
	actor1->SetProperty(prop1);

	vtkRenderer *ren= vtkRenderer::New();
	ren->AddActor(actor1);

	vtkPolyDataNormals *dataset = vtkPolyDataNormals::New();
	dataset->SetInput(reader1->GetOutput());
	dataset->SetFeatureAngle(60.0);
	dataset->FlipNormalsOff();
	dataset->Update();


	//to access the values:

	for (int pointID=0; pointID < dataset->GetOutput()->GetNumberOfPoints(); 
pointID++) {
		float *point = 
(float*)reader1->GetOutput()->GetPointData()->GetNormals()->GetTuple(pointID);

	/*	printf("x -> %f",(float)point[0]);
		printf("y -> %f",(float)point[1]);
		printf("z -> %f",(float)point[2]);*/
	}


	vtkRenderWindow *renWin = vtkRenderWindow::New();


	renWin->AddRenderer(ren);
	renWin->SetSize(800, 800 );

	renWin->Render();

               reader1->Delete();
               dataset->Delete();
               actor1->Delete();
               prop1->Delete();
               ren->Delete();
              renWin->Delete();
              return 0;
}

_________________________________________________________________
Apply to over 65,000 jobs now. 
http://www.naukri.com/msn/index.php?source=hottag Post your CV on naukri.com 
today.




More information about the vtkusers mailing list