示例#1
0
    def __init__(self, name, polyData, view):

        om.ObjectModelItem.__init__(self, name, om.Icons.Robot)

        self.views = []
        self.polyData = polyData
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInput(self.polyData)
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
        self.shadowActor = None
        self.scalarBarWidget = None
        self.extraViewRenderers = {}

        self.rangeMap = dict(PolyDataItem.defaultScalarRangeMap)

        self.addProperty('Color By', 0, attributes=om.PropertyAttributes(enumNames=['Solid Color']))
        self.addProperty('Visible', True)
        self.addProperty('Alpha', 1.0,
                         attributes=om.PropertyAttributes(decimals=2, minimum=0, maximum=1.0, singleStep=0.1, hidden=False))
        self.addProperty('Point Size', self.actor.GetProperty().GetPointSize(),
                         attributes=om.PropertyAttributes(decimals=0, minimum=1, maximum=20, singleStep=1, hidden=False))

        self.addProperty('Surface Mode', 0,
                         attributes=om.PropertyAttributes(enumNames=['Surface', 'Wireframe', 'Surface with edges', 'Points'], hidden=True))

        self.addProperty('Color', [1.0, 1.0, 1.0])
        self.addProperty('Show Scalar Bar', False)

        self._updateSurfaceProperty()
        self._updateColorByProperty()

        if view is not None:
            self.addToView(view)
示例#2
0
    def shadowOn(self):

        if self.shadowActor:
            return

        mat =  [[1, 0, -1,  0],
                [0, 1, -1,  0],
                [0, 0,  0,  0],
                [0, 0,  0,  1]]

        shadowT = transformUtils.getTransformFromNumpy(mat)

        baseTransform = self.actor.GetUserTransform()
        if baseTransform:
            shadowT.PreMultiply()
            shadowT.Concatenate(baseTransform)

        self.shadowActor = vtk.vtkActor()
        self.shadowActor.SetMapper(self.mapper)
        self.shadowActor.SetUserTransform(shadowT)
        self.shadowActor.GetProperty().LightingOff()
        self.shadowActor.GetProperty().SetColor(0, 0, 0)

        for view in self.views:
            view.renderer().AddActor(self.shadowActor)
示例#3
0
    def __init__(self, name, polyData, view):

        om.ObjectModelItem.__init__(self, name, om.Icons.Robot)

        self.views = []
        self.polyData = polyData
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputData(self.polyData)
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
        self.shadowActor = None
        self.scalarBarWidget = None
        self.extraViewRenderers = {}

        self.rangeMap = dict(PolyDataItem.defaultScalarRangeMap)

        self.addProperty(
            'Color By',
            0,
            attributes=om.PropertyAttributes(enumNames=['Solid Color']))
        self.addProperty('Visible', True)
        self.addProperty('Alpha',
                         1.0,
                         attributes=om.PropertyAttributes(decimals=2,
                                                          minimum=0,
                                                          maximum=1.0,
                                                          singleStep=0.1,
                                                          hidden=False))
        self.addProperty('Point Size',
                         self.actor.GetProperty().GetPointSize(),
                         attributes=om.PropertyAttributes(decimals=0,
                                                          minimum=1,
                                                          maximum=20,
                                                          singleStep=1,
                                                          hidden=False))

        self.addProperty('Line Width',
                         self.actor.GetProperty().GetLineWidth(),
                         attributes=om.PropertyAttributes(decimals=0,
                                                          minimum=1,
                                                          maximum=20,
                                                          singleStep=1,
                                                          hidden=False))

        self.addProperty('Surface Mode',
                         0,
                         attributes=om.PropertyAttributes(enumNames=[
                             'Surface', 'Wireframe', 'Surface with edges',
                             'Points'
                         ],
                                                          hidden=True))

        self.addProperty('Color', [1.0, 1.0, 1.0])
        self.addProperty('Show Scalar Bar', False)

        self._updateSurfaceProperty()
        self._updateColorByProperty()

        if view is not None:
            self.addToView(view)
示例#4
0
    def shadowOn(self):

        if self.shadowActor:
            return

        mat =  [[1, 0, -1,  0],
                [0, 1, -1,  0],
                [0, 0,  0,  0],
                [0, 0,  0,  1]]

        shadowT = transformUtils.getTransformFromNumpy(mat)

        baseTransform = self.actor.GetUserTransform()
        if baseTransform:
            shadowT.PreMultiply()
            shadowT.Concatenate(baseTransform)

        self.shadowActor = vtk.vtkActor()
        self.shadowActor.SetMapper(self.mapper)
        self.shadowActor.SetUserTransform(shadowT)
        self.shadowActor.GetProperty().LightingOff()
        self.shadowActor.GetProperty().SetColor(0, 0, 0)

        for view in self.views:
            view.renderer().AddActor(self.shadowActor)
    def __init__(self, name, polyData, view):

        om.ObjectModelItem.__init__(self, name, om.Icons.Robot)

        self.views = []
        self.polyData = polyData
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInput(self.polyData)
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
        self.shadowActor = None
        self.scalarBarWidget = None
        self.extraViewRenderers = {}

        self.rangeMap = {
            'intensity': (400, 4000),
            #'z' : (0.0, 2.0),
            #'distance' : (0.5, 4.0),
            'spindle_angle': (0, 360),
            'azimuth': (-2.5, 2.5),
            'scan_delta': (0.0, 0.3)
        }

        self.addProperty(
            'Color By',
            0,
            attributes=om.PropertyAttributes(enumNames=['Solid Color']))
        self.addProperty('Visible', True)
        self.addProperty('Alpha',
                         1.0,
                         attributes=om.PropertyAttributes(decimals=2,
                                                          minimum=0,
                                                          maximum=1.0,
                                                          singleStep=0.1,
                                                          hidden=False))
        self.addProperty('Point Size',
                         self.actor.GetProperty().GetPointSize(),
                         attributes=om.PropertyAttributes(decimals=0,
                                                          minimum=1,
                                                          maximum=20,
                                                          singleStep=1,
                                                          hidden=False))

        self.addProperty('Surface Mode',
                         0,
                         attributes=om.PropertyAttributes(enumNames=[
                             'Surface', 'Wireframe', 'Surface with edges',
                             'Points'
                         ],
                                                          hidden=True))

        self.addProperty('Color', [1.0, 1.0, 1.0])
        self.addProperty('Show Scalar Bar', False)

        self._updateSurfaceProperty()
        self._updateColorByProperty()

        if view is not None:
            self.addToView(view)
示例#6
0
def render_depth(renWin,
                 renderer,
                 camera,
                 data_dir,
                 data_dir_name,
                 num_im,
                 out_dir,
                 use_mesh,
                 object_dir,
                 mesh='meshed_scene.ply',
                 keyword=None):
    actor = vtk.vtkActor()
    filter1 = vtk.vtkWindowToImageFilter()
    imageWriter = vtk.vtkPNGWriter()
    scale = vtk.vtkImageShiftScale()

    if use_mesh:  #use meshed version of scene
        if not glob.glob(data_dir + "/" + mesh):
            out = None
            if glob.glob(data_dir + "/original_log.lcmlog.ply"):
                out = "original_log.lcmlog.ply"
            elif glob.glob(data_dir + "/trimmed_log.lcmlog.ply"):
                out = "trimmed_log.lcmlog.ply"
            elif glob.glob('*.ply'):
                out = glob.glob('*.ply')[0]
            else:
                return
            mesher = mesh_wrapper.Mesh(out_dir=data_dir)
            status = mesher.mesh_cloud(out)
            print status
            #blocks until done
        mapper = vtk.vtkPolyDataMapper()
        fileReader = vtk.vtkPLYReader()
        fileReader.SetFileName(data_dir + "/" + mesh)
        mapper.SetInputConnection(fileReader.GetOutputPort())
        actor.SetMapper(mapper)
        renderer.AddActor(actor)
    else:  #import just the objects
        objects = common.Objects(data_dir, object_dir)
        objects.loadObjectMeshes("/registration_result.yaml",
                                 renderer,
                                 keyword=keyword)

    #setup filters
    filter1.SetInput(renWin)
    filter1.SetMagnification(1)
    filter1.SetInputBufferTypeToZBuffer()
    windowToColorBuffer = vtk.vtkWindowToImageFilter()
    windowToColorBuffer.SetInput(renWin)
    windowToColorBuffer.SetInputBufferTypeToRGB()
    scale.SetOutputScalarTypeToUnsignedShort()
    scale.SetScale(1000)

    poses = common.CameraPoses(data_dir + "/posegraph.posegraph")
    for i in range(1, num_im + 1):
        try:
            utimeFile = open(
                data_dir + "/images/" + str(i).zfill(10) + "_utime.txt", 'r')
            utime = int(utimeFile.read())

            #update camera transform
            cameraToCameraStart = poses.getCameraPoseAtUTime(utime)
            t = cameraToCameraStart
            common.setCameraTransform(camera, t)
            renWin.Render()

            #update filters
            filter1.Modified()
            filter1.Update()
            windowToColorBuffer.Modified()
            windowToColorBuffer.Update()

            #extract depth image
            depthImage = vtk.vtkImageData()
            pts = vtk.vtkPoints()
            ptColors = vtk.vtkUnsignedCharArray()
            vtk.vtkDepthImageUtils.DepthBufferToDepthImage(
                filter1.GetOutput(), windowToColorBuffer.GetOutput(), camera,
                depthImage, pts, ptColors)
            scale.SetInputData(depthImage)
            scale.Update()

            #write out depth image
            imageWriter.SetFileName(out_dir + str(i).zfill(10) + "_" +
                                    data_dir_name + "_depth_ground_truth.png")
            imageWriter.SetInputConnection(scale.GetOutputPort())
            imageWriter.Write()
        except (IOError):
            break
    renderer.RemoveAllViewProps()
    renWin.Render()
示例#7
0
def render_normals(renWin,
                   renderer,
                   camera,
                   data_dir,
                   data_dir_name,
                   num_im,
                   out_dir,
                   use_mesh,
                   object_dir,
                   mesh='meshed_scene.ply',
                   keyword=None):
    #setup rendering enviornment
    actor = vtk.vtkActor()
    filter1 = vtk.vtkWindowToImageFilter()
    imageWriter = vtk.vtkPNGWriter()
    scale = vtk.vtkImageShiftScale()

    if use_mesh:  #use meshed version of scene
        if not glob.glob(data_dir + "/" + mesh):
            out = "original_log.lcmlog.ply" if glob.glob(
                data_dir +
                "/original_log.lcmlog.ply") else "trimmed_log.lcmlog.ply"
            mesher = mesh_wrapper.Mesh(out_dir=data_dir)
            status = mesher.mesh_cloud(out)
            print status
            #blocks until done
        mapper = vtk.vtkPolyDataMapper()
        #shading
        #set_material_prop(actor)
        set_shader_input(mapper)
        fileReader = vtk.vtkPLYReader()
        fileReader.SetFileName(data_dir + "/" + mesh)
        mapper.SetInputConnection(fileReader.GetOutputPort())
        actor.SetMapper(mapper)
        renderer.AddActor(actor)

    else:  #import just the objects
        objects = common.Objects(data_dir, object_dir)
        objects.loadObjectMeshes("/registration_result.yaml",
                                 renderer,
                                 keyword=keyword,
                                 shader=set_shader_input)

    #setup rendering enviornment
    windowToColorBuffer = vtk.vtkWindowToImageFilter()
    windowToColorBuffer.SetInput(renWin)
    windowToColorBuffer.SetInputBufferTypeToRGB()

    #setup camera calibration
    common.set_up_camera_params(camera)

    poses = common.CameraPoses(data_dir + "/posegraph.posegraph")
    for i in range(1, num_im + 1):
        try:
            utimeFile = open(
                data_dir + "/images/" + str(i).zfill(10) + "_utime.txt", 'r')
            utime = int(utimeFile.read())

            #update camera transform
            cameraToCameraStart = poses.getCameraPoseAtUTime(utime)
            t = cameraToCameraStart
            common.setCameraTransform(camera, t)
            renWin.Render()

            windowToColorBuffer.Modified()
            windowToColorBuffer.Update()

            #write out depth image
            imageWriter.SetFileName(out_dir + str(i).zfill(10) + "_" +
                                    data_dir_name + "_normal_ground_truth.png")
            imageWriter.SetInputConnection(windowToColorBuffer.GetOutputPort())
            imageWriter.Write()
        except (IOError):
            break
    renderer.RemoveAllViewProps()
    renWin.Render()
示例#8
0
            normal = np.array(pickPointFields.pickedNormal)
            image[i, j, :] = normal
        # add some rgb conversion step, maybe png writer does that???
    return image


if __name__ == '__main__':
    #setup
    view_height = 640
    view_width = 480
    data_dir = sys.argv[1]
    num_im = int(sys.argv[2])
    mesh = sys.argv[3]

    mapper = vtk.vtkPolyDataMapper()
    actor = vtk.vtkActor()
    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    interactor = vtk.vtkRenderWindowInteractor()
    fileReader = vtk.vtkPLYReader()
    filter1 = vtk.vtkWindowToImageFilter()
    imageWriter = vtk.vtkBMPWriter()
    scale = vtk.vtkImageShiftScale()
    fileReader.SetFileName(sys.argv[1] + "/" + sys.argv[3])
    renWin.SetSize(view_height, view_width)

    camera = vtk.vtkCamera()
    renderer.SetActiveCamera(camera)

    mapper.SetInputConnection(fileReader.GetOutputPort())
    actor.SetMapper(mapper)
示例#9
0
out_file = "/media/drc/DATA/chris_labelfusion/RGBDCNN/stats.yaml"
stats = {}
samples_per_run = 1

###run through scenes
for i, j in paths[1:50]:
    #set file names
    data_dir = path + i
    print data_dir
    data_dir_name = os.path.basename(os.path.normpath(data_dir))
    object_dir = "/media/drc/DATA/chris_labelfusion/object-meshes"
    mesh = 'meshed_scene.ply'

    #####set up mesh
    actor = vtk.vtkActor()
    mapper = vtk.vtkPolyDataMapper()
    #set_shader(mapper)
    fileReader = vtk.vtkPLYReader()
    fileReader.SetFileName(data_dir + "/" + mesh)
    mapper.SetInputConnection(fileReader.GetOutputPort())
    actor.SetMapper(mapper)
    renderer.AddActor(actor)

    #add objects
    objects = common.Objects(data_dir, object_dir)

    poses = common.CameraPoses(data_dir + "/posegraph.posegraph")
    for l in np.random.choice(range(1, 500), samples_per_run):
        new_data_dir = '/media/drc/DATA/chris_labelfusion/RGBDCNN/'
        utimeFile = open(