Can I generate a representation of the cell tree locator?

Hello,

I don’t know the answer since the celltreelocator does not have levels but buckets.
Also I am rendering offscreen but it is working.

Thank you,

NAMESPACE:

namespace {class vtkSliderCallback : public vtkCommand
			{
			public:
			  static vtkSliderCallback* New()
			  { return new vtkSliderCallback;}

		  vtkSliderCallback() : Cell_Locator(0), Level(12), PolyData(0), Renderer(0)  {}

		  virtual void Execute(vtkObject* caller, unsigned long, void*)
		  { vtkSliderWidget* sliderWidget = reinterpret_cast<vtkSliderWidget*>(caller);
this->Level = vtkMath::Round(static_cast<vtkSliderRepresentation*>(sliderWidget->GetRepresentation())->GetValue());
		    this->Cell_Locator->GenerateRepresentation(this->Level, this->PolyData);
		    this->Renderer->Render();}
	          
		  vtkCellTreeLocator* Cell_Locator;
		  int Level;
		  vtkPolyData* PolyData;
		  vtkRenderer* Renderer;};}

MAIN CODE:

            vtkNew<vtkCellTreeLocator> cell_locator_2;
			cell_locator_2->SetDataSet(polydata);
			cell_locator_2->SetNumberOfBuckets(max_level);
			cell_locator_2->SetNumberOfCellsPerNode(cells_perbuckets);
			cell_locator_2->CacheCellBoundsOn();
			cell_locator_2->BuildLocator();	
			
			cell_locator_2->GenerateRepresentation(0, polydata);
			
			datastructuretype = "Tree Cell Locator";

			// Calculate the elapsed time

			
			buildtime = datastructuretype +"Build Time:  ";	

			
			datastructuretype = "Tree Cell Locator";

			// Calculate the elapsed time

			
			buildtime = datastructuretype +"Build Time:  ";		

	
    
    

  			     	
			
 cell_locator_2->GenerateRepresentation(0, polydata); 
	

		  
		 std::cout << "Cell Locator:  Num Levels:   " << cell_locator_2->GetLevel() << " Per Leave:  " << cell_locator_2->GetNumberOfBuckets()<<std::endl;	


		  vtkNew<vtkNamedColors> colors3;
		  vtkNew<vtkPolyDataMapper> pointsMapper;
		  pointsMapper->SetInputData(polydata);
  		          pointsMapper->ScalarVisibilityOff();
		  
		  vtkNew<vtkActor> pointsActor;
		  pointsActor->SetMapper(pointsMapper);
		  pointsActor->GetProperty()->SetInterpolationToFlat();
		  pointsActor->GetProperty()->SetColor(colors3->GetColor4d("Lime").GetData());
		  pointsActor->GetProperty()->SetOpacity(.2);

		  pointsActor->RotateWXYZ(-90.0, 1.0, 0.0, 0.0);
		  pointsActor->Modified();
		  
		  // Initialize the representation.

		  vtkNew<vtkPolyDataMapper> locatorTreeMapper;
		  locatorTreeMapper->SetInputData(polydata);

		  vtkNew<vtkActor> locatorTreeActor;
		  locatorTreeActor->SetMapper(locatorTreeMapper);
		  locatorTreeActor->GetProperty()->SetOpacity(.5);
		  locatorTreeActor->GetProperty()->EdgeVisibilityOn();
		  locatorTreeActor->GetProperty()->SetColor(colors3->GetColor4d("Green").GetData());
		  locatorTreeActor->GetProperty()->SetInterpolationToFlat();
		  locatorTreeActor->GetProperty()->SetRepresentationToWireframe();
		  locatorTreeActor->RotateWXYZ(-90.0, 1.0, 0.0, 0.0);
		  locatorTreeActor->Modified();

		  // A renderer and render window.
		  vtkNew<vtkRenderer> renderer;
		  vtkNew<vtkEGLRenderWindow> renderWindow;			  
		  renderWindow->AddRenderer(renderer);
		   
	/*	  vtkNew<vtkNamedColors> colors2;
		  vtkNew<vtkTextActor> txt;
		  txt->SetInput(buildtime.c_str());
		  vtkTextProperty* txtprop = txt->GetTextProperty();
		  txtprop->SetFontFamilyToArial();
		  txtprop->SetFontSize(15);
		  txtprop->SetColor(colors2->GetColor4d("Blue").GetData());
		  txt->SetDisplayPosition(20, 12);*/
	
		   // An interactor.
		  vtkNew<vtkInteractorStyleTrackballCamera> style;
		  vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
		  renderWindowInteractor->SetRenderWindow(renderWindow);
		  renderWindowInteractor->SetInteractorStyle(style);


		  // Add the actors to the scene.
		  renderer->AddActor(pointsActor);
		  renderer->AddActor(locatorTreeActor);
		  renderer->SetBackground(colors3->GetColor3d("Teal").GetData());
	//	  renderer->AddActor(txt);
		  renderer->UseHiddenLineRemovalOn();
		  renderer->Modified();
		  


		  renderWindow->OffScreenRenderingOn();
		  renderWindow->SetShowWindow(false);
		//renderWindow->WindowInitialize();
		  renderWindow->SetSize(640, 480);
		  renderWindow->SetWindowName("CellLocatorVisualization");
		  renderWindow->Render();

		   vtkNew<vtkSliderRepresentation2D> sliderRep;
		   sliderRep->SetMinimumValue(0);
		   sliderRep->SetMaximumValue(cell_locator_2->GetNumberOfBuckets());
		   sliderRep->SetValue(cell_locator_2->GetNumberOfBuckets());;


		//sliderRep->SetTitleText("MaxPointsPerRegion");
		  sliderRep->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedDisplay();
		  sliderRep->GetPoint1Coordinate()->SetValue(.2, .1);
		  sliderRep->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedDisplay();
		  sliderRep->GetPoint2Coordinate()->SetValue(.8, .1);
		  sliderRep->SetSliderLength(0.075);
		  sliderRep->SetSliderWidth(0.05);
		  sliderRep->SetEndCapLength(0.05);
		  sliderRep->GetTitleProperty()->SetColor(colors3->GetColor3d("Beige").GetData());
		  sliderRep->GetCapProperty()->SetColor(colors3->GetColor3d("MistyRose").GetData());
		  sliderRep->GetSliderProperty()->SetColor(colors3->GetColor3d("LightBlue").GetData());
		  sliderRep->GetSelectedProperty()->SetColor(colors3->GetColor3d("Violet").GetData());


		  vtkNew<vtkSliderWidget> sliderWidget;
		  sliderWidget->SetInteractor(renderWindowInteractor);
		  sliderWidget->SetRepresentation(sliderRep);
		  sliderWidget->SetAnimationModeToAnimate();
		  sliderWidget->EnabledOn();


		  vtkNew<vtkSliderCallback> callback;
          callback->Cell_Locator = cell_locator_2;  break;
		  
		  callback->PolyData = polydata;
		  callback->Renderer = renderer;
		  callback->Execute(sliderWidget,0 , 0);

		  sliderWidget->AddObserver(vtkCommand::InteractionEvent, callback);
		  
		  
		  renderWindowInteractor->Initialize();
     	  renderWindow->Render();
		  renderWindowInteractor->Start();


		  vtkNew<vtkWindowToImageFilter> windowToImageFilter;
		  windowToImageFilter->SetInput(renderWindow);
		  windowToImageFilter->Update();
		    
		  
		  vtkNew<vtkPNGWriter> writer;
		  writer->SetFileName(datastructuretype.c_str());
		  writer->SetInputConnection(windowToImageFilter->GetOutputPort());
		  writer->Write();

Hello,

This is definitely a bad idea.

I suggest using a separate object to store the visual representation of the spatial index.

best,

PC

1 Like

Hello,

Your tip worked fine for the OBBTree, CellLocator, and ModifiedBPSTree.
However, for the CellTreeLocator I still can’t get a representation. I made the changes from “levels” to “NumberOfBuckets” but it didn’t work.

CellLocator vs. CellTreeLocator:

Hi,

Please, try calling cell_locator_2->ForceBuildLocator() before GenerateRepresentation().

regards,

PC