def segmentBlockByAnnotation(blockDimensions, p1, p2, p3):

    segmentationObj = om.findObjectByName('pointcloud snapshot')
    segmentationObj.mapper.ScalarVisibilityOff()
    segmentationObj.setProperty('Point Size', 2)
    segmentationObj.setProperty('Alpha', 0.8)

    # constraint z to lie in plane
    #p1[2] = p2[2] = p3[2] = max(p1[2], p2[2], p3[2])

    zedge = p2 - p1
    zaxis = zedge / np.linalg.norm(zedge)

    #xwidth = distanceToLine(p3, p1, p2)

    # expected dimensions
    xwidth, ywidth = blockDimensions

    zwidth = np.linalg.norm(zedge)

    yaxis = np.cross(p2 - p1, p3 - p1)
    yaxis = yaxis / np.linalg.norm(yaxis)

    xaxis = np.cross(yaxis, zaxis)

    # reorient axes
    viewPlaneNormal = getSegmentationView().camera().GetViewPlaneNormal()
    if np.dot(yaxis, viewPlaneNormal) < 0:
        yaxis *= -1

    if np.dot(xaxis, p3 - p1) < 0:
        xaxis *= -1

    # make right handed
    zaxis = np.cross(xaxis, yaxis)

    origin = ((p1 + p2) / 2.0) + xaxis*xwidth/2.0 + yaxis*ywidth/2.0

    d = DebugData()
    d.addSphere(origin, radius=0.01)
    d.addLine(origin - xaxis*xwidth/2.0, origin + xaxis*xwidth/2.0)
    d.addLine(origin - yaxis*ywidth/2.0, origin + yaxis*ywidth/2.0)
    d.addLine(origin - zaxis*zwidth/2.0, origin + zaxis*zwidth/2.0)
    obj = updatePolyData(d.getPolyData(), 'block axes')
    obj.setProperty('Color', QtGui.QColor(255, 255, 0))
    obj.setProperty('Visible', False)
    om.findObjectByName('annotation').setProperty('Visible', False)

    cube = vtk.vtkCubeSource()
    cube.SetXLength(xwidth)
    cube.SetYLength(ywidth)
    cube.SetZLength(zwidth)
    cube.Update()
    cube = shallowCopy(cube.GetOutput())

    t = getTransformFromAxes(xaxis, yaxis, zaxis)
    t.PostMultiply()
    t.Translate(origin)

    obj = updatePolyData(cube, 'block affordance', cls=BlockAffordanceItem, parent='affordances')
    obj.actor.SetUserTransform(t)

    obj.addToView(app.getDRCView())

    params = dict(origin=origin, xwidth=xwidth, ywidth=ywidth, zwidth=zwidth, xaxis=xaxis, yaxis=yaxis, zaxis=zaxis)
    obj.setAffordanceParams(params)
    obj.updateParamsFromActorTransform()



####
# debrs task ground frame
dataset/ETHPy150Open RobotLocomotion/director/src/python/director/segmentation.py/segmentBlockByAnnotation/original