Example #1
0
def removePlaneAndBeyond(polyData, expectedNormal=[1,0,0], filterRange=[-np.inf, -0.03], whichAxis=1, whichAxisLetter='y', percentile = 95):

    yvalues = vnp.getNumpyFromVtk(polyData, 'Points')[:, whichAxis]
    backY = np.percentile(yvalues, percentile)

    if ( percentile > 50):
        searchRegion = segmentation.thresholdPoints(polyData, whichAxisLetter, [backY - 0.1, np.inf])
    else:
        searchRegion = segmentation.thresholdPoints(polyData, whichAxisLetter, [-np.inf, backY + 0.1])

    vis.updatePolyData(searchRegion, 'search region', parent="segmentation", colorByName=whichAxisLetter, visible=False)

    # find the plane of the back wall, remove it and the points behind it:
    _, origin, normal = segmentation.applyPlaneFit(searchRegion, distanceThreshold=0.02, expectedNormal=expectedNormal, perpendicularAxis=expectedNormal, returnOrigin=True)

    points = vnp.getNumpyFromVtk(polyData, 'Points')
    dist = np.dot(points - origin, normal)
    vnp.addNumpyToVtk(polyData, dist, 'dist_to_plane')

    backFrame = transformUtils.getTransformFromOriginAndNormal(origin, normal, normalAxis=2)
    vis.updateFrame(backFrame, 'back frame', parent='segmentation', scale=0.15 , visible=False)
    vis.updatePolyData(polyData, 'dist to back', parent='segmentation', visible=False)

    polyData = segmentation.thresholdPoints(polyData, 'dist_to_plane', filterRange)
    vis.updatePolyData(polyData, 'back off and all', parent='segmentation', visible=False)

    return polyData
Example #2
0
def fitObjectsOnShelf(polyData, maxHeight = 0.25):
    # find the shelf plane:
    polyDataWithoutFront, _ = segmentation.removeMajorPlane(polyData, distanceThreshold=0.02)
    polyDataPlaneFit, origin, normal = segmentation.applyPlaneFit(polyDataWithoutFront,  expectedNormal=np.array([0.0,0.0,1.0]), perpendicularAxis=np.array([0.0,0.0,1.0]), returnOrigin=True)
    vis.updatePolyData(polyDataPlaneFit, 'polyDataPlaneFit', parent='segmentation', visible=False)

    shelfSurfacePoints = segmentation.thresholdPoints(polyDataPlaneFit, 'dist_to_plane', [-0.01, 0.01])
    shelfCenter = segmentation.computeCentroid(shelfSurfacePoints)
    shelfFrame = transformUtils.getTransformFromOriginAndNormal(shelfCenter, normal, normalAxis=2)
    vis.showFrame(shelfFrame, 'shelfFrame', parent='segmentation', scale=0.15 , visible=False)

    # find the points near to the shelf plane and find objects on it:
    points = vnp.getNumpyFromVtk(polyData, 'Points')
    dist = np.dot(points - origin, normal)
    vnp.addNumpyToVtk(polyData, dist, 'dist_to_plane')
    shelfPoints = segmentation.thresholdPoints(polyData, 'dist_to_plane', [-0.01, maxHeight])
    vis.updatePolyData(shelfPoints, 'shelf', parent='segmentation', visible=False)

    data = segmentation.segmentTableScene(shelfPoints, shelfCenter, filterClustering = False )
    vis.showClusterObjects(data.clusters + [data.table], parent='segmentation')

    # remove the points that we considered from the orginal cloud
    dists = vnp.getNumpyFromVtk(polyData, 'dist_to_plane')
    diffShelf = ( ((dists > maxHeight) + (dists < -0.01))) + 0.1 -0.1
    vnp.addNumpyToVtk(polyData, diffShelf, 'diff_shelf')
    polyData = segmentation.thresholdPoints(polyData, 'diff_shelf', [1, 1])

    vis.updatePolyData(polyData, 'rest', parent='segmentation', visible=False)
    return polyData
Example #3
0
def labelNonFinitePoints(polyData, arrayName='Points'):
    '''
    adds is_nonfinite label to polyData.  non finite includes nan and +/- inf.
    '''
    pts = vnp.getNumpyFromVtk(polyData, arrayName)
    labels = np.logical_not(np.isfinite(pts)).any(axis=1)
    vnp.addNumpyToVtk(polyData, np.array(labels, dtype=np.int32), 'is_nonfinite')
Example #4
0
def labelNonFinitePoints(polyData, arrayName='Points'):
    '''
    adds is_nonfinite label to polyData.  non finite includes nan and +/- inf.
    '''
    pts = vnp.getNumpyFromVtk(polyData, arrayName)
    labels = np.logical_not(np.isfinite(pts)).any(axis=1)
    vnp.addNumpyToVtk(polyData, np.array(labels, dtype=np.int32),
                      'is_nonfinite')
Example #5
0
def removePlaneAndBeyond(polyData,
                         expectedNormal=[1, 0, 0],
                         filterRange=[-np.inf, -0.03],
                         whichAxis=1,
                         whichAxisLetter='y',
                         percentile=95):

    yvalues = vnp.getNumpyFromVtk(polyData, 'Points')[:, whichAxis]
    backY = np.percentile(yvalues, percentile)

    if (percentile > 50):
        searchRegion = segmentation.thresholdPoints(polyData, whichAxisLetter,
                                                    [backY - 0.1, np.inf])
    else:
        searchRegion = segmentation.thresholdPoints(polyData, whichAxisLetter,
                                                    [-np.inf, backY + 0.1])

    vis.updatePolyData(searchRegion,
                       'search region',
                       parent="segmentation",
                       colorByName=whichAxisLetter,
                       visible=False)

    # find the plane of the back wall, remove it and the points behind it:
    _, origin, normal = segmentation.applyPlaneFit(
        searchRegion,
        distanceThreshold=0.02,
        expectedNormal=expectedNormal,
        perpendicularAxis=expectedNormal,
        returnOrigin=True)

    points = vnp.getNumpyFromVtk(polyData, 'Points')
    dist = np.dot(points - origin, normal)
    vnp.addNumpyToVtk(polyData, dist, 'dist_to_plane')

    backFrame = transformUtils.getTransformFromOriginAndNormal(origin,
                                                               normal,
                                                               normalAxis=2)
    vis.updateFrame(backFrame,
                    'back frame',
                    parent='segmentation',
                    scale=0.15,
                    visible=False)
    vis.updatePolyData(polyData,
                       'dist to back',
                       parent='segmentation',
                       visible=False)

    polyData = segmentation.thresholdPoints(polyData, 'dist_to_plane',
                                            filterRange)
    vis.updatePolyData(polyData,
                       'back off and all',
                       parent='segmentation',
                       visible=False)

    return polyData
Example #6
0
def fitObjectsOnShelf(polyData, maxHeight=0.25):
    # find the shelf plane:
    polyDataWithoutFront, _ = segmentation.removeMajorPlane(
        polyData, distanceThreshold=0.02)
    polyDataPlaneFit, origin, normal = segmentation.applyPlaneFit(
        polyDataWithoutFront,
        expectedNormal=np.array([0.0, 0.0, 1.0]),
        perpendicularAxis=np.array([0.0, 0.0, 1.0]),
        returnOrigin=True)
    vis.updatePolyData(polyDataPlaneFit,
                       'polyDataPlaneFit',
                       parent='segmentation',
                       visible=False)

    shelfSurfacePoints = segmentation.thresholdPoints(polyDataPlaneFit,
                                                      'dist_to_plane',
                                                      [-0.01, 0.01])
    shelfCenter = segmentation.computeCentroid(shelfSurfacePoints)
    shelfFrame = transformUtils.getTransformFromOriginAndNormal(shelfCenter,
                                                                normal,
                                                                normalAxis=2)
    vis.showFrame(shelfFrame,
                  'shelfFrame',
                  parent='segmentation',
                  scale=0.15,
                  visible=False)

    # find the points near to the shelf plane and find objects on it:
    points = vnp.getNumpyFromVtk(polyData, 'Points')
    dist = np.dot(points - origin, normal)
    vnp.addNumpyToVtk(polyData, dist, 'dist_to_plane')
    shelfPoints = segmentation.thresholdPoints(polyData, 'dist_to_plane',
                                               [-0.01, maxHeight])
    vis.updatePolyData(shelfPoints,
                       'shelf',
                       parent='segmentation',
                       visible=False)

    data = segmentation.segmentTableScene(shelfPoints,
                                          shelfCenter,
                                          filterClustering=False)
    vis.showClusterObjects(data.clusters + [data.table], parent='segmentation')

    # remove the points that we considered from the orginal cloud
    dists = vnp.getNumpyFromVtk(polyData, 'dist_to_plane')
    diffShelf = (((dists > maxHeight) + (dists < -0.01))) + 0.1 - 0.1
    vnp.addNumpyToVtk(polyData, diffShelf, 'diff_shelf')
    polyData = segmentation.thresholdPoints(polyData, 'diff_shelf', [1, 1])

    vis.updatePolyData(polyData, 'rest', parent='segmentation', visible=False)
    return polyData
Example #7
0
    def getSphereGeometry(self, imageName):

        sphereObj = self.sphereObjects.get(imageName)
        if sphereObj:
            return sphereObj

        if not self.imageManager.getImage(imageName).GetDimensions()[0]:
            return None

        sphereResolution = 50
        sphereRadii = {
            'CAMERA_LEFT': 20,
            'CAMERACHEST_LEFT': 20,
            'CAMERACHEST_RIGHT': 20
        }

        geometry = makeSphere(sphereRadii[imageName], sphereResolution)
        self.imageManager.queue.computeTextureCoords(imageName, geometry)

        tcoordsArrayName = 'tcoords_%s' % imageName
        vtkNumpy.addNumpyToVtk(
            geometry,
            vtkNumpy.getNumpyFromVtk(geometry, tcoordsArrayName)[:, 0].copy(),
            'tcoords_U')
        vtkNumpy.addNumpyToVtk(
            geometry,
            vtkNumpy.getNumpyFromVtk(geometry, tcoordsArrayName)[:, 1].copy(),
            'tcoords_V')
        geometry = clipRange(geometry, 'tcoords_U', [0.0, 1.0])
        geometry = clipRange(geometry, 'tcoords_V', [0.0, 1.0])
        geometry.GetPointData().SetTCoords(
            geometry.GetPointData().GetArray(tcoordsArrayName))

        sphereObj = vis.showPolyData(geometry,
                                     imageName,
                                     view=self.view,
                                     parent='cameras')
        sphereObj.actor.SetTexture(self.imageManager.getTexture(imageName))
        sphereObj.actor.GetProperty().LightingOff()

        self.view.renderer().RemoveActor(sphereObj.actor)
        rendererId = 2 - self.sphereImages.index(imageName)
        self.renderers[rendererId].AddActor(sphereObj.actor)

        self.sphereObjects[imageName] = sphereObj
        return sphereObj
Example #8
0
    def getSphereGeometry(self, imageName):

        sphereObj = self.sphereObjects.get(imageName)
        if sphereObj:
            return sphereObj

        if not self.imageManager.getImage(imageName).GetDimensions()[0]:
            return None

        sphereResolution = 50
        sphereRadii = {
                'CAMERA_LEFT' : 20,
                'CAMERACHEST_LEFT' : 20,
                'CAMERACHEST_RIGHT' : 20
                }

        geometry = makeSphere(sphereRadii[imageName], sphereResolution)
        self.imageManager.queue.computeTextureCoords(imageName, geometry)

        tcoordsArrayName = 'tcoords_%s' % imageName
        vtkNumpy.addNumpyToVtk(geometry, vtkNumpy.getNumpyFromVtk(geometry, tcoordsArrayName)[:,0].copy(), 'tcoords_U')
        vtkNumpy.addNumpyToVtk(geometry, vtkNumpy.getNumpyFromVtk(geometry, tcoordsArrayName)[:,1].copy(), 'tcoords_V')
        geometry = clipRange(geometry, 'tcoords_U', [0.0, 1.0])
        geometry = clipRange(geometry, 'tcoords_V', [0.0, 1.0])
        geometry.GetPointData().SetTCoords(geometry.GetPointData().GetArray(tcoordsArrayName))

        sphereObj = vis.showPolyData(geometry, imageName, view=self.view, parent='cameras')
        sphereObj.actor.SetTexture(self.imageManager.getTexture(imageName))
        sphereObj.actor.GetProperty().LightingOff()

        self.view.renderer().RemoveActor(sphereObj.actor)
        rendererId = 2 - self.sphereImages.index(imageName)
        self.renderers[rendererId].AddActor(sphereObj.actor)

        self.sphereObjects[imageName] = sphereObj
        return sphereObj