Discussion:
[vtkusers] Crashing on GetGlobalIds
meakcey
2018-11-24 14:17:20 UTC
Permalink
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 &lt;&lt; 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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
meakcey
2018-11-24 14:47:44 UTC
Permalink
Cleaner comparison to problem

*Code below is working*

vtkPlanes* frustum =
static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();
vtkSmartPointer<vtkExtractGeometry> extractGeometry =
vtkSmartPointer<vtkExtractGeometry>::New();
extractGeometry->SetImplicitFunction(frustum);
extractGeometry->SetInputData(this->Points);
extractGeometry->Update();
extractGeometry->GetOutput()->GetPointData()->CopyGlobalIdsOn();

vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(extractGeometry->GetOutputPort());
glyphFilter->Update();
glyphFilter->GetOutput()->GetPointData()->CopyGlobalIdsOn();
vtkPolyData* selected = glyphFilter->GetOutput();

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

*Code below is crashing at the line of cout
*
vtkPlanes* frustum =
static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();
vtkSmartPointer<vtkExtractGeometry> extractGeometry =
vtkSmartPointer<vtkExtractGeometry>::New();
extractGeometry->SetImplicitFunction(frustum);
extractGeometry->SetInputData(this->Points);
extractGeometry->Update();
extractGeometry->GetOutput()->GetPointData()->CopyGlobalIdsOn();

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

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

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






--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
David E DeMarle via vtkusers
2018-11-30 15:30:25 UTC
Permalink
vtkSmartPointer<vtkIdTypeArray> globalIds =
vtkSmartPointer<vtkIdTypeArray>::New();
globalIds =
vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetGlobalIds());
assert(globalIds);

I think the assert tells you that the smartpointer itself exists, but it
doesn't say anything about the vtkIdTypeArray pointed to by the
smartpointer. I suspect if you assert(globalIds.GetPointer()) it will fail.
If that is the case, since it is null, gloablids->* crashes on the next
line.

Why it is null will take some more tracking down.

One thing to note about globalids is that VTK is conservative about
preserving their meaning and throws them away when it can't do that. For
example they won't be interpolated like most arrays are because averaging
ids or (i.e. names) is undefined. Likewise filters that don't simply copy
cells/points across won't attempt to preserve globalids. So what you should
do is trace through the filters you are using to see where specifically the
globalids are lost.

hth

David E DeMarle
Kitware, Inc.
Principal Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909
Post by meakcey
Cleaner comparison to problem
*Code below is working*
vtkPlanes* frustum =
static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();
vtkSmartPointer<vtkExtractGeometry> extractGeometry =
vtkSmartPointer<vtkExtractGeometry>::New();
extractGeometry->SetImplicitFunction(frustum);
extractGeometry->SetInputData(this->Points);
extractGeometry->Update();
extractGeometry->GetOutput()->GetPointData()->CopyGlobalIdsOn();
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(extractGeometry->GetOutputPort());
glyphFilter->Update();
glyphFilter->GetOutput()->GetPointData()->CopyGlobalIdsOn();
vtkPolyData* selected = glyphFilter->GetOutput();
vtkSmartPointer<vtkIdTypeArray> globalIds =
vtkSmartPointer<vtkIdTypeArray>::New();
globalIds =
vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetGlobalIds());
assert(globalIds);
std::cout << "Nof globalIds " << globalIds->GetNumberOfComponents() << " "
<< globalIds->GetNumberOfTuples() << std::endl;
*Code below is crashing at the line of cout
*
vtkPlanes* frustum =
static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();
vtkSmartPointer<vtkExtractGeometry> extractGeometry =
vtkSmartPointer<vtkExtractGeometry>::New();
extractGeometry->SetImplicitFunction(frustum);
extractGeometry->SetInputData(this->Points);
extractGeometry->Update();
extractGeometry->GetOutput()->GetPointData()->CopyGlobalIdsOn();
vtkSmartPointer<vtkSelectVisiblePoints> visiblePoints =
vtkSmartPointer<vtkSelectVisiblePoints>::New();
visiblePoints->SetInputConnection(extractGeometry->GetOutputPort());
visiblePoints->SetRenderer(this->GetInteractor()->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
visiblePoints->Update();
visiblePoints->GetOutput()->GetPointData()->CopyGlobalIdsOn();
vtkSmartPointer<vtkVertexGlyphFilter> visibleFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
visibleFilter->SetInputConnection(visiblePoints->GetOutputPort());
visibleFilter->Update();
visibleFilter->GetOutput()->GetPointData()->CopyGlobalIdsOn();
vtkPolyData* visibles = visibleFilter->GetOutput();
vtkSmartPointer<vtkIdTypeArray> globalIds =
vtkSmartPointer<vtkIdTypeArray>::New();
globalIds =
vtkIdTypeArray::SafeDownCast(visibles->GetPointData()->GetGlobalIds());
assert(globalIds);
std::cout << "Nof globalIds " << globalIds->GetNumberOfComponents() << " "
<< globalIds->GetNumberOfTuples() << std::endl;
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
Search the list archives at: http://markmail.org/search/?q=vtkusers
https://public.kitware.com/mailman/listinfo/vtkusers
meakcey
2018-12-03 21:02:44 UTC
Permalink
Thank you for your suggestion
assert(globalIds); line is not crashing. That means as you pointed out,
visible filter should be throwing out the globalids.
Could you guide me through the source of filters?




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

Loading...