Hi,
I have 1 actor with 100s of cubes (just a starter project). I create the cubes like this:
// create points
int bias=0;
for (const QRect & rect : layer->rects()) {
QRectF r = rect;
points->InsertNextPoint(r.left(), r.bottom(), layer->z());
points->InsertNextPoint(r.right(), r.bottom(), layer->z());
points->InsertNextPoint(r.right(), r.top(), layer->z());
points->InsertNextPoint(r.left(), r.top(), layer->z());
// Cell Array
polys->InsertNextCell({bias+0,bias+1,bias+2,bias+3});
bias += 4;
}
// create polydata
auto polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->SetPolys(polys);
// Linear extrusion
auto extrude = vtkSmartPointer<vtkLinearExtrusionFilter>::New();
extrude->SetInputData(polydata);
extrude->SetVector(0.0, 0.0, layer->layerThick()+grow);
// Mapper
layer->mapper()->SetInputConnection(extrude->GetOutputPort());
layer->mapper()->SetColorModeToDefault();
// Actor
layer->actor()->SetMapper(layer->mapper());
layer->actor()->GetProperty()->SetColor(layer->color().r(), layer->color().g(), layer->color().b());
I implemented a Cell Picker like this: ( Copied from the example: https://lorensen.github.io/VTKExamples/site/Cxx/Picking/CellPicking/ )
auto picker = vtkSmartPointer<vtkCellPicker>::New();
if (!picker) { return; }
int success = picker->Pick(_rbEndPt[0], _rbEndPt[1], 5000., CurrentRenderer);
if (!success) {
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->RemoveActor(_selectedActor);
return;
}
double* worldPosition = picker->GetPickPosition();
vtkSmartPointer<vtkNamedColors> colors = vtkSmartPointer<vtkNamedColors>::New();
qDebug() << "Cell id is: " << picker->GetCellId();
if (picker->GetCellId() != -1)
{
qDebug() << "Pick position is: " << worldPosition[0] << " " << worldPosition[1] << " " << worldPosition[2];
vtkSmartPointer<vtkIdTypeArray> ids = vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);
ids->InsertNextValue(picker->GetCellId());
vtkSmartPointer<vtkSelectionNode> selectionNode = vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::CELL);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);
vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
vtkSmartPointer<vtkExtractSelection> extractSelection = vtkSmartPointer<vtkExtractSelection>::New();
extractSelection->SetInputData(0, picker->GetActor()->GetMapper()->GetInput());
extractSelection->SetInputData(1, selection);
extractSelection->Update();
// In selection
vtkSmartPointer<vtkUnstructuredGrid> selected = vtkSmartPointer<vtkUnstructuredGrid>::New();
selected->ShallowCopy(extractSelection->GetOutput());
qDebug() << "There are " << selected->GetNumberOfPoints() << " points in the selection.";
qDebug() << "There are " << selected->GetNumberOfCells() << " cells in the selection.";
_selectedMapper->SetInputData(selected);
_selectedActor->SetMapper(_selectedMapper);
_selectedActor->GetProperty()->EdgeVisibilityOn();
_selectedActor->GetProperty()->SetColor(colors->GetColor3d("Red").GetData());
_selectedActor->GetProperty()->SetLineWidth(3);
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(_selectedActor);
}
I was expecting the selected cell to have 8 points (4 for the bottom square, 4 for the top square), but
I get a 4 point plane of one of the sides, or the top of the cube instead.
Is there a way I can get all the points of the selected cube?
Thanks,
UJ