void initScene(vtkSmartPointer<vtkRenderer> render, vtkSmartPointer<vtkRenderWindow> renWin, 
			   vtkSmartPointer<vtkRenderWindowInteractor> rwi, vtkSmartPointer<vtkInteractorStyleTrackballCamera> style){
   splatAssembly = 0;
   tranparencyEnabled = false;

	render->SetBackground(clear_color);		
	renWin->GetRenderers()->RemoveAllItems();
	renWin->AddRenderer(render);
	renWin->SetSize(window_width, window_height );	

	textActor->SetInput("Init");
	textActor->SetDisplayPosition(window_width*0.5, window_height*0.05);
	vtkTextProperty *tprop = textActor->GetTextProperty();
	tprop->SetColor(0.0,0.0,1.0);
	tprop->SetJustificationToCentered();
	render->AddViewProp(textActor);

	VTK_CREATE(vtkCallbackCommand, keyCommand);
	VTK_CREATE(vtkCallbackCommand, mouseCommand);
	keyCommand->SetClientData(style);
	keyCommand->SetCallback(keyCallback);
	mouseCommand->SetClientData(style);
	mouseCommand->SetCallback(mouseCallback);
	style->AddObserver(vtkCommand::KeyPressEvent, keyCommand);
	style->AddObserver(vtkCommand::MouseMoveEvent, mouseCommand);	
	style->AddObserver(vtkCommand::LeftButtonPressEvent, mouseCommand);	
	VTK_CREATE(vtkPointPicker, picker);
	rwi->SetPicker(picker);
	//picker->SetTolerance	(0.025);//0.025 is the defaul fraction of rendering window size. (Rendering window size is measured across diagonal.)

	// for drawing picked points
	pickSource->SetRadius(sphereRadius*pickRadiusRadio);	
	pickMapper->SetInputConnection(pickSource->GetOutputPort());	
	pickActors.clear();
	pickActors.reserve(npts);
	for(int i=0; i<npts; ++i){
		pickActors.push_back(0);
		pickPtsIdx[i] = 0.0;
	}
}
Exemple #2
0
int
outofcoreViewer (boost::filesystem::path tree_root, int depth, bool display_octree=true, unsigned int gpu_cache_size=512)
{
  cout << boost::filesystem::absolute (tree_root) << endl;

  // Create top level scene
  Scene *scene = Scene::instance ();

  // Clouds
  OutofcoreCloud *cloud = new OutofcoreCloud ("my_octree", tree_root);
  cloud->setDisplayDepth (depth);
  cloud->setDisplayVoxels (display_octree);
  OutofcoreCloud::cloud_data_cache.setCapacity(gpu_cache_size*1024);
  scene->addObject (cloud);

//  OutofcoreCloud *cloud2 = new OutofcoreCloud ("my_octree2", tree_root);
//  cloud2->setDisplayDepth (depth);
//  cloud2->setDisplayVoxels (display_octree);
//  scene->addObject (cloud2);

  // Add Scene Renderables
  Grid *grid = new Grid ("origin_grid");
  Axes *axes = new Axes ("origin_axes");
  scene->addObject (grid);
  scene->addObject (axes);

  // Create smart pointer with arguments
//  Grid *grid_raw = new Grid("origin_grid");
//  vtkSmartPointer<Grid> grid;
//  grid.Take(grid_raw);

  // Create window and interactor
  vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New ();
  window = vtkSmartPointer<vtkRenderWindow>::New ();
  window->SetSize (1000, 500);

  interactor->SetRenderWindow (window);
  interactor->Initialize ();
  interactor->CreateRepeatingTimer (100);

  // Viewports
  Viewport octree_viewport (window, 0.0, 0.0, 0.5, 1.0);
  Viewport persp_viewport (window, 0.5, 0.0, 1.0, 1.0);

  // Cameras
  Camera *persp_camera = new Camera ("persp", persp_viewport.getRenderer ()->GetActiveCamera ());
  Camera *octree_camera = new Camera ("octree", octree_viewport.getRenderer ()->GetActiveCamera ());
  scene->addCamera (persp_camera);
  scene->addCamera (octree_camera);
  octree_camera->setDisplay(true);

  // Set viewport cameras
  persp_viewport.setCamera (persp_camera);
  octree_viewport.setCamera (octree_camera);

  // Render once
  window->Render ();

  // Frame cameras
  Eigen::Vector3d min (cloud->getBoundingBoxMin ());
  Eigen::Vector3d max (cloud->getBoundingBoxMax ());
  octree_viewport.getRenderer ()->ResetCamera (min.x (), max.x (), min.y (), max.y (), min.z (), max.z ());
  persp_viewport.getRenderer ()->ResetCamera (min.x (), max.x (), min.y (), max.y (), min.z (), max.z ());

  cloud->setRenderCamera(octree_camera);

  // Interactor
  // -------------------------------------------------------------------------
  vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New ();
  style->SetAutoAdjustCameraClippingRange(false);
  interactor->SetInteractorStyle (style);

  // Callbacks
  // -------------------------------------------------------------------------
  vtkSmartPointer<vtkCallbackCommand> render_start_callback = vtkSmartPointer<vtkCallbackCommand>::New();
  render_start_callback->SetCallback(renderStartCallback);
  window->AddObserver(vtkCommand::StartEvent, render_start_callback);

  vtkSmartPointer<vtkCallbackCommand> render_end_callback = vtkSmartPointer<vtkCallbackCommand>::New();
  render_end_callback->SetCallback(renderEndCallback);
  window->AddObserver(vtkCommand::EndEvent, render_end_callback);

  vtkSmartPointer<KeyboardCallback> keyboard_callback = vtkSmartPointer<KeyboardCallback>::New ();
  interactor->AddObserver (vtkCommand::KeyPressEvent, keyboard_callback);

  interactor->CreateRepeatingTimer(1000);
  vtkSmartPointer<vtkCallbackCommand> render_timer_callback = vtkSmartPointer<vtkCallbackCommand>::New();
  render_timer_callback->SetCallback(renderTimerCallback);
  interactor->AddObserver(vtkCommand::TimerEvent, render_timer_callback);

  interactor->Start ();

  return 0;
}