[vtkusers] Crashing on GetGlobalIds

meakcey meakcey at gmail.com
Sat Nov 24 09:17:20 EST 2018


Hi

I am trying to set and get GlobalIds which assigned in PolyData

Creating polydata snippet as follows

pcl::PointCloud<pcl::PointNormal>::Ptr pointCloud(new
pcl::PointCloud<pcl::PointNormal>);
pcl::io::loadPLYFile("scansample/constructedcloud.ply", *pointCloud);
qInfo() << "Size of point cloud " << pointCloud->size();

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetName ("Colors");

// Set point normals
vtkSmartPointer<vtkDoubleArray> pointNormalsArray =
vtkSmartPointer<vtkDoubleArray>::New();
pointNormalsArray->SetNumberOfComponents(3); //3d normals (ie x,y,z)
pointNormalsArray->SetName("Normals");

vtkSmartPointer<vtkIdTypeArray> pointIds =
vtkSmartPointer<vtkIdTypeArray>::New();
pointIds->SetNumberOfComponents(1);
pointIds->SetName("pointIds");

vtkSmartPointer<vtkIdTypeArray> globalIds =
vtkSmartPointer<vtkIdTypeArray>::New();
globalIds->SetNumberOfComponents(1);
globalIds->SetName("globalIds");

unsigned char tmpColor[3] = {200, 200, 100};
for(unsigned int i=0; i<pointCloud->size(); i++){
points->InsertNextPoint(pointCloud->points[i].x, pointCloud->points[i].y,
pointCloud->points[i].z);
double pn[3] = {pointCloud->points[i].normal_x,
pointCloud->points[i].normal_y, pointCloud->points[i].normal_z};
pointNormalsArray->InsertNextTypedTuple(pn);
colors->InsertNextTypedTuple(tmpColor);
pointIds->InsertNextValue(i);
globalIds->InsertNextValue(i);
}

vtkSmartPointer<vtkPolyData> pointsPoly =
vtkSmartPointer<vtkPolyData>::New();
pointsPoly->SetPoints(points);

vtkSmartPointer<vtkVertexGlyphFilter> vertexFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
//vertexFilter->SetInputConnection(idFilter->GetOutputPort());
vertexFilter->SetInputData(pointsPoly);
vertexFilter->Update();

vPointCloud = vtkSmartPointer<vtkPolyData>::New();
vPointCloud->ShallowCopy(vertexFilter->GetOutput());
vPointCloud->GetPointData()->SetScalars(colors);
vPointCloud->GetPointData()->SetNormals(pointNormalsArray);
vPointCloud->GetPointData()->AddArray(pointIds);

vPointCloud->GetPointData()->SetGlobalIds(globalIds);
vPointCloud->GetPointData()->CopyGlobalIdsOn();


Trying to reach pointdata through rubber band pick as follows


void interactorArea::OnLeftButtonUp(){

    // Forward events
    vtkInteractorStyleRubberBandPick::OnLeftButtonUp();

    if(this->CurrentMode == VTKISRBP_SELECT){
        vtkPlanes* frustum =
static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();
        vtkSmartPointer<vtkExtractGeometry> extractGeometry =
vtkSmartPointer<vtkExtractGeometry>::New();
        extractGeometry->SetImplicitFunction(frustum);
        extractGeometry->SetInputData(this->Points);
        extractGeometry->Update();

        vtkSmartPointer<vtkSelectVisiblePoints> visiblePoints =
vtkSmartPointer<vtkSelectVisiblePoints>::New();
        extractGeometry->GetOutput()->GetPointData()->CopyGlobalIdsOn();
        visiblePoints->SetInputConnection(extractGeometry->GetOutputPort());
       
visiblePoints->SetRenderer(this->GetInteractor()->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
        visiblePoints->Update();

        vtkSmartPointer<vtkVertexGlyphFilter> visibleFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
        visiblePoints->GetOutput()->GetPointData()->CopyGlobalIdsOn();
        visibleFilter->SetInputConnection(visiblePoints->GetOutputPort());
        visibleFilter->Update();
        vtkPolyData* visibles = visibleFilter->GetOutput();

        std::cout << "Visible points " << visibles->GetNumberOfPoints() <<
std::endl;
        
        if(selected->GetNumberOfPoints() <= 0){
            std::cout << "Nothing selected" << std::endl;
            return;
        }
        
        selectedIds = vtkSmartPointer<vtkIdTypeArray>::New();
        selectedIds =
vtkIdTypeArray::SafeDownCast(visibles->GetPointData()->GetArray("pointIds"));
        unsigned int idsize = selectedIds->GetNumberOfTuples();

        for(unsigned int j=0; j<idsize; j++)
            std::cout << selectedIds->GetValue(j) << " ";
        std::cout << std::endl;

        vtkSmartPointer<vtkIdTypeArray> globalIds =
vtkSmartPointer<vtkIdTypeArray>::New();
        globalIds =
vtkIdTypeArray::SafeDownCast(visibles->GetPointData()->GetGlobalIds());
        assert(globalIds);
        std::cout << "Nof globalIds " << globalIds->GetNumberOfComponents()
<< " " << globalIds->GetNumberOfTuples() << std::endl;

    }
}

I could get pointIds but could not get any part of the globalIds.
Program crashing at the line of 
std::cout << "Nof globalIds " << globalIds->GetNumberOfComponents() << " "
<< globalIds->GetNumberOfTuples() << std::endl;

What's wrong with that?

Thanks



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list