need animation programming

Mohamed Magdi m_magdi1 at hotmail.com
Wed Apr 26 20:51:32 EDT 2000


Hi vtkuser
i need how to animate by programming in C++ using vtk.(without using gimp or 
whirlgif, or any other program for animating gif).

look, my program reads binary file by using vtkPLOT3DReader, and then it 
generate the output as a whole, so i need to read this file partially
in order to control the output and can animate it.
and try to help us please quickly.

thanx again

NOTE: this is  my source code you will find it below, you have to change the 
path of the files in the main procedures,you will found these files on the 
CD\vtkdata.


//this is my code


#include"vtk.h"
class Fluid
{
public:
	vtkPLOT3DReader *pl3d;

	vtkLookupTable *lut;

	vtkStructuredGridGeometryFilter *floorComp;
	vtkPolyDataMapper *floorMapper;
	vtkActor *floorActor;

	vtkStructuredGridGeometryFilter *subFloorComp;
	vtkPolyDataMapper *subFloorMapper;
	vtkActor *subFloorActor;

	vtkStructuredGridGeometryFilter *subFloor2Comp;
	vtkPolyDataMapper *subFloor2Mapper;
	vtkActor *subFloor2Actor;

	vtkStructuredGridGeometryFilter *postComp;
	vtkPolyDataMapper *postMapper;
	vtkActor *postActor;

	vtkStructuredGridGeometryFilter *fanComp;
	vtkPolyDataMapper *fanMapper;
	vtkActor *fanActor;

	vtkPointSource *rake;

	vtkStructuredGridGeometryFilter *seedsComp;

	vtkStreamLine *streamers;

	vtkTubeFilter *tubes;
	vtkPolyDataMapper *mapTubes;
	vtkActor *tubesActor;

	vtkStructuredGridOutlineFilter *outline;
	vtkPolyDataMapper *outlineMapper;
	vtkActor *outlineActor;

	vtkRenderer *ren1;

	vtkRenderWindow *renWin;

	vtkRenderWindowInteractor *iren;

	vtkCamera *aCam;

public:
	Fluid();
	~Fluid();
	void RData(char* XYZFileName,char* QFileName);

	void SetHue(float x,float y);

	void  ComputedFloor(int Imin,int Imax, int Jmin,
						int Jmax,int Kmin,int Kmax);
	void FloorMap(int i);
	void FloorActor(int R,int G,int B ,int ws);

	void SubFloorComputed();
	void SubFloorMap();
	void SubFloorActor();

	void SubFloor2Computed();
	void SubFloor2Map();
	void SubFloor2Actor();

	void ComputedPost(int iMin,int iMax,int jMin,
						int jMax,int kMin,int kMax);
	void PostMap(int I);
	void PostActor(int r,int g,int b,int WS);
	void ComputedFan(int IMIN,int IMAX,int JMIN,
					  int JMAX,int KMIN,int KMAX);
	void FanMap(int j);
	void FanActor(int Red,int Green,int Blue,int Ws);

	void SetPoint();

	void SeedComputed();

	void StreamLine();

	void Tube();
	void TubeMap();
	void TubeActor();

	void Outline();
	void OutlineMapper();
	void OutlineActor();

	void SetCamera();

	void Settings();

	//void Output();
};

Fluid::Fluid()
{
	 this->pl3d=vtkPLOT3DReader::New();
	 this->lut = vtkLookupTable::New();
	 this->floorComp = vtkStructuredGridGeometryFilter::New();
	 this->floorMapper= vtkPolyDataMapper::New();
	 this->floorActor = vtkActor::New();
	 this->subFloorComp = vtkStructuredGridGeometryFilter::New();
	 this->subFloorMapper = vtkPolyDataMapper::New();
	 this->subFloorActor = vtkActor::New();
	 this->subFloor2Comp = vtkStructuredGridGeometryFilter::New();
	 this->subFloor2Mapper = vtkPolyDataMapper::New();
	 this->subFloor2Actor = vtkActor::New();
	 this->postComp = vtkStructuredGridGeometryFilter::New();
	 this->postMapper = vtkPolyDataMapper::New();
	 this->postActor = vtkActor::New();
	 this->fanComp = vtkStructuredGridGeometryFilter::New();
	 this->fanMapper = vtkPolyDataMapper::New();
	 this->fanActor = vtkActor::New();
	 this->rake = vtkPointSource::New();
	 this->seedsComp = vtkStructuredGridGeometryFilter::New();
	 this->streamers = vtkStreamLine::New();
	 this->tubes = vtkTubeFilter::New();
	 this->mapTubes = vtkPolyDataMapper::New();
	 this->tubesActor = vtkActor::New();
	 this->outline = vtkStructuredGridOutlineFilter::New();
	 this->outlineMapper = vtkPolyDataMapper::New();
	 this->outlineActor = vtkActor::New();
	 this->ren1 = vtkRenderer::New();
	 this->renWin = vtkRenderWindow::New();
	 this->iren  = vtkRenderWindowInteractor::New();
	 this->aCam = vtkCamera::New();
}
/******************************************************/
Fluid::~Fluid()
{
	pl3d->Delete();
	lut->Delete();
	floorComp->Delete();
	floorMapper->Delete();
	floorActor->Delete();
	subFloorComp->Delete();
	subFloorMapper->Delete();
	subFloorActor->Delete();
	subFloor2Comp->Delete();
	subFloor2Mapper->Delete();
	subFloor2Actor->Delete();
	postComp->Delete();
	postMapper->Delete();
	postActor->Delete();
	fanComp->Delete();
	fanMapper->Delete();
	fanActor->Delete();
	rake->Delete();
	seedsComp->Delete();
	streamers->Delete();
	tubes->Delete();
	mapTubes->Delete();
	tubesActor->Delete();
	outline->Delete();
	outlineMapper->Delete();
	outlineActor->Delete();
	ren1->Delete();
	renWin->Delete();
	iren->Delete();
	aCam->Delete();
}
/***************************************************/
void Fluid::RData(char* XYZFileName,char* QFileName)
{
		pl3d->SetXYZFileName (XYZFileName);
		pl3d->SetQFileName (QFileName);
		pl3d->SetScalarFunctionNumber(153);
		pl3d->SetVectorFunctionNumber(200);
		//pl3d->DebugOn();
		pl3d->Update();

}
/***************************************************/
void Fluid::SetHue(float x,float y)
{
	//hue ranges between 0 and 1
	lut->SetHueRange(x,y);
}
/***************************************************/
void  Fluid::ComputedFloor(int Imin,int Imax, int Jmin,
						   int Jmax,int Kmin,int Kmax)
{
	 floorComp->SetExtent(Imin,Imax,Jmin,Jmax,Kmin,Kmax);
	 floorComp->SetInput(pl3d->GetOutput());
	 floorComp->Update();
}
/***************************************************/
void  Fluid::FloorMap(int i)
{
		floorMapper->SetInput(floorComp->GetOutput());
		switch (i)
		{
			case 1:
				floorMapper->ScalarVisibilityOn();
				break;

			case 0:
				floorMapper->ScalarVisibilityOff();
				break;
			default:
				cout<<"Error: The parameter must be 0 or 1."<<endl;
				exit(1);
				break;
		}

		floorMapper->SetLookupTable(lut);
		//comment
		floorMapper->SetScalarRange(pl3d->GetOutput()->GetScalarRange());
}
/***************************************************/
void Fluid::FloorActor(int R,int G,int B ,int ws)
{
		floorActor->SetMapper(floorMapper);
		floorActor->GetProperty()->SetColor(R,G,B);
		switch (ws)
		{
			case 1:
				floorActor->GetProperty()->SetRepresentationToSurface();
				break;

			case 0:
				floorActor->GetProperty()->SetRepresentationToWireframe();
				break;
			default:
				cout<<"Error: The parameter must be 0 or 1."<<endl;
				exit(1);
				break;
		}
}
/***************************************************/
void Fluid::SubFloorComputed()
{

		subFloorComp->SetExtent(0,37,0,15,22,22);
		subFloorComp->SetInput(pl3d->GetOutput());
}
/***************************************************/
void Fluid::SubFloorMap()
{
		subFloorMapper->SetInput(subFloorComp->GetOutput());
		subFloorMapper->SetLookupTable(lut);
		subFloorMapper->SetScalarRange(pl3d->GetOutput()->GetScalarRange());
}
/***************************************************/
void Fluid::SubFloorActor()
{
		subFloorActor->SetMapper(subFloorMapper);
}
/***************************************************/
void Fluid::SubFloor2Computed()
{

		subFloor2Comp->SetExtent(0,37,60,75,22,22);
		subFloor2Comp->SetInput(pl3d->GetOutput());
}
/***************************************************/
void Fluid::SubFloor2Map()
{
		subFloor2Mapper->SetInput(subFloor2Comp->GetOutput());
		subFloor2Mapper->SetLookupTable(lut);
		subFloor2Mapper->SetScalarRange(pl3d->GetOutput()->GetScalarRange());
}
/***************************************************/
void Fluid::SubFloor2Actor()
{
		subFloor2Actor->SetMapper(subFloor2Mapper);

}
/***************************************************/
void Fluid::ComputedPost(int iMin,int iMax,int jMin,
						 int jMax,int kMin,int kMax)
{
		postComp->SetExtent(iMin,iMax,jMin,jMax,kMin,kMax);
		postComp->SetInput(pl3d->GetOutput());
}
/***************************************************/
void Fluid::PostMap(int I)
{
		postMapper->SetInput(postComp->GetOutput());
		switch (I)
		{
			case 1:
				postMapper->ScalarVisibilityOn();
				break;

			case 0:
				postMapper->ScalarVisibilityOff();
				break;
			default:
				cout<<"Error: The parameter must be 0 or 1."<<endl;
				exit(1);
				break;
		}

		postMapper->SetLookupTable(lut);
		//comment
		postMapper->SetScalarRange(pl3d->GetOutput()->GetScalarRange());
}
/***************************************************/
void Fluid::PostActor(int r,int g,int b,int WS)
{
		postActor->SetMapper(postMapper);
		postActor->GetProperty()->SetColor(r,g,b);
		switch (WS)
		{
			case 1:
				postActor->GetProperty()->SetRepresentationToSurface();
				break;

			case 0:
				postActor->GetProperty()->SetRepresentationToWireframe();
				break;
			default:
				cout<<"Error: The parameter must be 0 or 1."<<endl;
				exit(1);
				break;
		}
}
/***************************************************/
void Fluid::ComputedFan(int IMIN,int IMAX,int JMIN,
						int JMAX,int KMIN,int KMAX)
{
		fanComp->SetExtent(IMIN,IMAX,JMIN,JMAX,KMIN,KMAX);
		fanComp->SetInput(pl3d->GetOutput());
}
/***************************************************/
void Fluid::FanMap(int j)
{

		fanMapper->SetInput(fanComp->GetOutput());
		switch (j)
		{
			case 1:
				fanMapper->ScalarVisibilityOn();
				break;

			case 0:
				fanMapper->ScalarVisibilityOff();
				break;
			default:
				cout<<"Error: The parameter must be 0 or 1."<<endl;
				exit(1);
				break;
		}

		fanMapper->SetLookupTable(lut);
		//comment
		fanMapper->SetScalarRange(pl3d->GetOutput()->GetScalarRange());
}
/***************************************************/
void Fluid::FanActor(int Red,int Green,int Blue,int Ws)
{

		fanActor->SetMapper(fanMapper);
		fanActor->GetProperty()->SetColor(Red,Green,Blue);
		switch (Ws)
		{
			case 1:
				fanActor->GetProperty()->SetRepresentationToSurface();
				break;

			case 0:
				fanActor->GetProperty()->SetRepresentationToWireframe();
				break;
			default:
				cout<<"Error: The parameter must be 0 or 1."<<endl;
				exit(1);
				break;
		}
}
/***************************************************/
void Fluid::SetPoint()
{
		rake->SetCenter(-0.74,0,0.3);
		rake->SetNumberOfPoints(10);
}
/***************************************************/
void Fluid::SeedComputed()
{
		seedsComp->SetExtent(10,10,37,39,1,35);
		seedsComp->SetInput(pl3d->GetOutput());
}
/***************************************************/
void Fluid::StreamLine()
{
		streamers->SetInput(pl3d->GetOutput());
		streamers->SetSource(seedsComp->GetOutput());
		streamers->SetMaximumPropagationTime(250);
		streamers->SpeedScalarsOn();
		streamers->SetIntegrationStepLength(.2);
		streamers->SetStepLength(.25);
}
/***************************************************/
void Fluid::Tube()
{
		tubes->SetInput(streamers->GetOutput());
		tubes->SetNumberOfSides(8);
		tubes->SetRadius(.08);
		tubes->SetVaryRadius(0);
}
/***************************************************/
void Fluid::TubeMap()
{
		mapTubes->SetInput(tubes->GetOutput());
		mapTubes->SetScalarRange(pl3d->GetOutput()->GetScalarRange());
}
/***************************************************/
void Fluid::TubeActor()
{
		tubesActor->SetMapper(mapTubes);
}
/***************************************************/
void Fluid::Outline()
{
		outline->SetInput(pl3d->GetOutput());
}
/***************************************************/
void Fluid::OutlineMapper()
{
		outlineMapper->SetInput(outline->GetOutput());
}
/***************************************************/
void Fluid::OutlineActor()
{
		outlineActor->SetMapper(outlineMapper);
		//comment
		outlineActor->GetProperty()->SetColor(0,0,0);
}
/***************************************************/
void Fluid::SetCamera()
{
		aCam->SetFocalPoint(0.00657892,0,2.41026);
		aCam->SetPosition(-1.94838,-47.1275,39.4607);
		aCam->ComputeViewPlaneNormal();
		aCam->SetViewPlaneNormal(-0.0325936,-0.785725,0.617717);
		aCam->SetViewUp(0.00653193,0.617865,0.786257);
}
/***************************************************/
void Fluid::Settings()
{
	renWin->AddRenderer(ren1);
	iren->SetRenderWindow(renWin);



	ren1->AddActor(outlineActor);
	ren1->AddActor(floorActor);
	ren1->AddActor(subFloorActor);
	ren1->AddActor(subFloor2Actor);
	ren1->AddActor(postActor);
	ren1->AddActor(fanActor);
	ren1->AddActor(tubesActor);



	//Settings
	ren1->SetBackground(1.0,1.0,1.0);
	ren1->SetActiveCamera(aCam);
	renWin->SetSize(300,300);
	iren->Initialize();
	renWin->Render();

	iren->Start();


}
/***************************************************/

void main()
{

	char* XYZFileName;
	char* QFileName;
	//these files are found in the cd
	XYZFileName = "cd/vtkdata/postxyz.bin";
	QFileName = "cd/vtkdata/postq.bin";
//Set The Hue Range
	float x = 0.667;
	float y= 0.0;
//Set The Compute floor
	int Imin = 0;
	int Imax = 37;
	int Jmin = 0;
	int Jmax = 75;
	int Kmin = 0;
	int Kmax = 0;

	int i = 0;



	Fluid *f = new Fluid();
	f->RData(XYZFileName,QFileName);


	float pp = f->pl3d->GetR();
	cout<<"Reynold number> "<<pp<<endl;

	float xx = f->pl3d->GetFsmach ();
	cout<<"Mach number> "<<xx<<endl;

	f->SetHue(x,y);

	f->ComputedFloor(Imin,Imax,Jmin,Jmax,Kmin,Kmax);
	f->FloorMap(i);
	f->FloorActor(0,0,250,0);
	f->fanActor->GetProperty()->SetDiffuse(0.7);
	f->fanActor->GetProperty()->SetSpecular(0.4);
	f->fanActor->GetProperty()->SetSpecularPower(20);

	f->SubFloorComputed();
	f->SubFloorMap();
	f->SubFloorActor();

	f->SubFloor2Computed();
	f->SubFloor2Map();
	f->SubFloor2Actor();

	f->ComputedPost(10,10,0,75,0,37);
	f->PostMap(0);
	f->PostActor(0,0,0,0);

	f->ComputedFan(0,37,38,38,0,37);
	f->FanMap(0);
	f->FanActor(0,0,0,0	);
	f->fanActor->GetProperty()->SetColor(1,0,0);

	f->SetPoint();

	f->SeedComputed();

	f->StreamLine();

	f->Tube();
	f->TubeMap();
	f->TubeActor();

	f->Outline();
	f->OutlineMapper();
	f->OutlineActor();




	f->SetCamera();
	f->Settings();
	delete f;
}



________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list