def loadObjFile(filename, scaleFactor=0.001):

        baseName = os.path.basename(filename)
        folder = om.getOrCreateContainer(baseName)
        meshes, actors = ioUtils.readObjMtl(filename)

        print 'loaded %d meshes from file: %s' % (len(meshes), filename)
        for i, mesh, actor in zip(xrange(len(meshes)), meshes, actors):

            mesh = filterUtils.cleanPolyData(mesh)
            mesh = filterUtils.computeNormals(mesh)

            obj = vis.showPolyData(mesh, baseName + ' piece %d'%i, parent=folder)
            obj.setProperty('Color', actor.GetProperty().GetColor())
            obj.actor.SetTexture(actor.GetTexture())

            pts = vnp.getNumpyFromVtk(obj.polyData, 'Points')
            pts *= scaleFactor

            print '  mesh %d, num points %d' % (i, obj.polyData.GetNumberOfPoints())

            #if actor.GetTexture():
            #    showImage(actor.GetTexture().GetInput())

        polyData = filterUtils.appendPolyData([obj.polyData for obj in folder.children()])
        vis.showPolyData(polyData, baseName + ' merged', parent=folder, visible=False)

        print '  total points:', polyData.GetNumberOfPoints()

        # compute centroid and subtract from points to move the mesh to the origin
        origin = np.array(filterUtils.computeCentroid(polyData))
        t = transformUtils.frameFromPositionAndRPY(-origin, [0.0, 0.0, 0.0])
        for obj in folder.children():
            obj.setPolyData(filterUtils.transformPolyData(obj.polyData, t))

        return folder.children()[-1].polyData
 def addNormals(polyData):
     hasNormals = polyData.GetPointData().GetNormals() is not None
     return polyData if hasNormals else filterUtils.computeNormals(
         polyData)
 def addNormals(polyData):
     hasNormals = polyData.GetPointData().GetNormals() is not None
     return polyData if hasNormals else filterUtils.computeNormals(polyData)
Example #4
0
    useVoxelGrid = True
    reorientNormals = False
    testNormals = False
    showGlyphs = False
    testPlaneSegmentation = True

else:
    removeGround = False
    useVoxelGrid = False
    reorientNormals = True
    testNormals = False
    showGlyphs = False
    testPlaneSegmentation = True

if reorientNormals:
    polyData = filterUtils.computeNormals(polyData)

if removeGround:
    groundPoints, scenePoints = segmentation.removeGround(polyData)
    vis.showPolyData(groundPoints, 'ground', visible=False)
    polyData = scenePoints

if useVoxelGrid:
    polyData = segmentation.applyVoxelGrid(polyData, leafSize=0.02)

if testNormals:

    print 'computing normals...'
    f = vtk.vtkRobustNormalEstimator()
    f.SetInput(polyData)
    f.SetMaxIterations(100)
Example #5
0
 def computeNormals(polyDataList):
     return [filterUtils.computeNormals(polyData) for polyData in polyDataList]
    reorientNormals = False
    testNormals = False
    showGlyphs = False
    testPlaneSegmentation = True

else:
    removeGround = False
    useVoxelGrid = False
    reorientNormals = True
    testNormals = False
    showGlyphs = False
    testPlaneSegmentation = True


if reorientNormals:
    polyData = filterUtils.computeNormals(polyData)


if removeGround:
    groundPoints, scenePoints =  segmentation.removeGround(polyData)
    vis.showPolyData(groundPoints, 'ground', visible=False)
    polyData = scenePoints


if useVoxelGrid:
    polyData = segmentation.applyVoxelGrid(polyData, leafSize=0.02)

if testNormals:

    print 'computing normals...'
    f = vtk.vtkRobustNormalEstimator()