[vtkusers] How to show progress bar for vtkOBJReader file read ?

Geeta geeta_kapse at yahoo.com
Mon May 19 01:02:36 EDT 2014


Hi flaviu2,

Thanks 4 ur help. I sent e-mail to u. and here is  my simple vtk code.

Yes..I integrated VTK and MFC...

But I will send u sample code simple VTK application to check if what I
tried is correct or not.

My problem is how to get "Progress Value" when obj file read in progress?

once read started Progress = 0 and after finished it is 1
I want it like 0, 0.1, 0.2 till 1. 

void ProgressFunction(vtkObject* caller, long unsigned int eventId, void*
clientData, void* callData)
{
  vtkOBJReader* filter = static_cast<vtkOBJReader*>(caller);
  std::string strProgress;
   
  std::cout << "Progress: " << filter->GetProgress() << std::endl;
  filter->SetProgressText("Progress: ");
}


int main(int argc, char *argv[])
{
	std::string imagename =
"D:\\yogo-san\\TriangleMesh_OBJ\\TriangleMesh_OBJ_0.png";

	// Read the image which will be the texture

	std::cout << "Reading image " << imagename << "..." << std::endl;
	//vtkSmartPointer<vtkJPEGReader> jPEGReader =
vtkSmartPointer<vtkJPEGReader>::New();
	//jPEGReader->SetFileName ( imagename.c_str() );
	//jPEGReader->Update();
	
	vtkSmartPointer<vtkPNGReader> pngReader = 
vtkSmartPointer<vtkPNGReader>::New();
	pngReader->SetFileName ( imagename.c_str() );
	pngReader->Update();

	std::cout << "Done" << std::endl;

	// Creating the texture

	std::cout << "Making a texture out of the image... " << std::endl;

	vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();

//	texture->SetInputConnection(jPEGReader->GetOutputPort());

	texture->SetInputConnection(pngReader->GetOutputPort());

	std::cout << "Done" << std::endl;

	// Import geometry from an OBJ file
	std::string iname = "D:\\yogo-san\\TriangleMesh_OBJ\\TriangleMesh_OBJ.obj";

	std::cout << "Reading OBJ file " << iname << "..." << std::endl;

	vtkOBJReader* reader = vtkOBJReader::New();

	vtkSmartPointer<vtkCallbackCommand> progressCallback =
vtkSmartPointer<vtkCallbackCommand>::New();
	progressCallback->SetCallback(ProgressFunction);

	reader->SetFileName(iname.c_str());
	 
	reader->AddObserver(vtkCommand::ProgressEvent, progressCallback);

	reader->Update();

	vtkPolyData *polyData2 = reader->GetOutput();

	std::cout << "Obj reader = " << polyData2->GetNumberOfPoints() <<
std::endl;

	std::cout << "Obj point data = " <<
polyData2->GetPointData()->GetNumberOfArrays() << std::endl;

	std::cout << "Obj point data tuples = " <<
polyData2->GetPointData()->GetArray(0)->GetNumberOfTuples() << std::endl;

	std::cout << "Obj point data compon = " <<
polyData2->GetPointData()->GetArray(0)->GetNumberOfComponents() <<
std::endl;
	 
	vtkSmartPointer<CommandSubclass2> timerCallback =
vtkSmartPointer<CommandSubclass2>::New();

	// Renderer

	vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();

	mapper->SetInput(polyData2);

	vtkSmartPointer<vtkActor> texturedQuad = vtkSmartPointer<vtkActor>::New();

	texturedQuad->SetMapper(mapper);

	texturedQuad->SetTexture(texture);

	// Visualize the textured plane
	vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();

	renderer->AddActor(texturedQuad);

	renderer->SetBackground(0.2,0.5,0.6); // Background color white

	renderer->ResetCamera();

	vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();

	renderWindow->AddRenderer(renderer);

	vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

	renderWindowInteractor->SetRenderWindow(renderWindow);

	renderWindow->Render();

	renderWindowInteractor->Start();

	return EXIT_SUCCESS;
}




--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-show-progress-bar-for-vtkOBJReader-file-read-tp5727117p5727155.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list