[vtkusers] I'm starting with VTK

adrien marion sinse49 at hotmail.com
Tue Feb 21 04:38:10 EST 2006


Good morning everybody,
I must continue a project realised with VTK and QT designer but I didn't 
know them before.
Can somebody explain to me this program?
I don't understand the vtkCutter class.
Thank you for your help...



vtkActor* va2d :: MakeContour2D(double NormalPlane[3],double 
OriginPlane[3],double Rotate[3],double AddPos[3],Contour2D cont)
{
	/*****************  plane  ************************/
	vtkPlane *plane = vtkPlane::New();
	plane->SetOrigin(OriginPlane[0], OriginPlane[1],OriginPlane[2]);
	plane->SetNormal(NormalPlane[0], NormalPlane[1], NormalPlane[2]);

	/******************  cutter  *********************/
	//Using a vtkCutter is a method to make the slide from  the volume.
	vtkCutter *cutEdges = vtkCutter::New();
	cutEdges->SetInput((cont.GetReader())->GetOutput());
	cutEdges->SetCutFunction(plane);
	cutEdges->GenerateCutScalarsOn();
	cutEdges->SetValue(0,0.5);

	/** *************** transformation**************************/
	/** Tranformation of the data to the good system */
	vtkTransform *transfo=vtkTransform ::New();
	transfo->SetMatrix(cont.GetTransformMatrix());
	vtkTransformPolyDataFilter *filter=vtkTransformPolyDataFilter::New();
	filter->SetTransform(transfo);
	filter->SetInput(cutEdges->GetOutput());

	/******************** surface **************************/
	//To construct the surface from the contour, we have to make the points and 
the lines in in.
	vtkStripper *strip = vtkStripper::New();
	vtkPolyData *cutPoly = vtkPolyData::New();
	vtkTriangleFilter *cutTriangle = vtkTriangleFilter::New();
	if(!cont.GetContour())
	{
		//construction of the surface with the contour in input
		//strip->SetInput(cutEdges->GetOutput());
		strip->SetInput(filter->GetOutput());
		strip->Update();
		cutPoly->SetPoints(strip->GetOutput()->GetPoints());
		cutPoly->SetPolys(strip->GetOutput()->GetLines());
		cutTriangle->SetInput(cutPoly);
	}

	/******************  Mapper  ************************************/
	vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
	mapper->ScalarVisibilityOff();
	//mapper->SetInput( cutEdges->GetOutput());
	mapper->SetInput( filter->GetOutput());
	//display contours
	if(cont.GetContour())	mapper->SetInput(cutEdges->GetOutput());

	//display surfaces
	if(!cont.GetContour())	mapper->SetInput(cutTriangle->GetOutput());

	/*********************  Actor   ************************/
	vtkActor *actor = vtkActor::New();
	actor->SetMapper(mapper);

	/*********************** color  *****************************/
	actor->GetProperty()->SetColor(cont.GetTabColor0(),cont.GetTabColor1(),cont.GetTabColor2());

	/*********************** width of the contours  
*****************************/
	actor->GetProperty()->SetLineWidth(cont.GetWidth());

	/**********************  visibility  ***************************/
	if(cont.GetVisible())		actor->VisibilityOn();
	if(!(cont.GetVisible()))	actor->VisibilityOff();

	/**********************  opacity  ***************************/
	actor->GetProperty()->SetOpacity(cont.GetOpacity());

	/************  rotation and translation of the actor  ******************/

	//Calulation of the center of the actor
	//float bounds[6];
	double bounds[6];
	actor->GetBounds(bounds);
	//the rotation center becomes the actor's center
	actor->SetOrigin((bounds[0]+bounds[1])/2,(bounds[2]+bounds[3])/2,(bounds[4]+bounds[5])/2);
	//rotation of the actor => same orientation as the IRM slide
	actor->RotateZ(Rotate[2]);
	actor->RotateY(Rotate[1]);
	actor->RotateX(Rotate[0]);
	//Reset of the center. Indispensable for translation.
	actor->SetOrigin(0,0,0);
	//translation of the actor => same plane as the IRM slide
	actor->AddPosition(AddPos[0],AddPos[1],AddPos[2]);


	/********************** actors cannot be picked  *******************/
	actor->PickableOff();

	/********************** delete  *******************/
	plane->Delete();
	cutEdges->Delete();
	mapper->Delete();

	return actor;

}

_________________________________________________________________
http://desktop.msn.fr/




More information about the vtkusers mailing list