コード例 #1
0
ファイル: TestThreshold.py プロジェクト: timkrentz/SunTracker
  def testThreshold(self):
    global args
    writefiles = "SaveData" in args

    renderer = vtk.vtkRenderer()
    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renwin)
    renwin.Render()

    if "GPURender" in args:
        vtk.vtkPistonMapper.InitCUDAGL(renwin)

    src = vtk.vtkImageMandelbrotSource()
    src.SetWholeExtent(0,10,0,10,0,10)

    #scale and bias until piston's threshold understands origin and spacing
    src.Update()
    inputdata = src.GetOutput()
    if "Normalize" in args:
         testdata1 = inputdata.NewInstance()
         testdata1.ShallowCopy(inputdata)
         testdata1.SetSpacing(1,1,1)
         testdata1.SetOrigin(0,0,0)
         inputdata = testdata1

    d2p = vtk.vtkDataSetToPiston()
    d2p.SetInputData(inputdata)
    #d2p.SetInputConnection(src.GetOutputPort())

    threshF = vtk.vtkPistonThreshold()
    threshF.SetInputConnection(d2p.GetOutputPort())
    threshF.SetMinValue(0)
    threshF.SetMaxValue(80)

    p2d = vtk.vtkPistonToDataSet()
    p2d.SetInputConnection(threshF.GetOutputPort())
    p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)

    if writefiles:
        writeFile(p2d, "piston_threshold.vtk")

    mapper = vtk.vtkPistonMapper()
    mapper.SetInputConnection(threshF.GetOutputPort())
    mapper.Update()

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    renderer.AddActor(actor)

    renderer.ResetCamera()
    renwin.Render()

    img_file = "TestThreshold.png"
    Testing.compareImage(renwin, Testing.getAbsImagePath(img_file))

    if Testing.isInteractive():
        iren.Start()
コード例 #2
0
    def testThreshold(self):
        global args
        writefiles = "SaveData" in args

        renderer = vtk.vtkRenderer()
        renwin = vtk.vtkRenderWindow()
        renwin.AddRenderer(renderer)
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renwin)
        renwin.Render()

        if "GPURender" in args:
            vtk.vtkPistonMapper.InitCUDAGL(renwin)

        src = vtk.vtkImageMandelbrotSource()
        src.SetWholeExtent(0, 10, 0, 10, 0, 10)

        #scale and bias until piston's threshold understands origin and spacing
        src.Update()
        inputdata = src.GetOutput()
        if "Normalize" in args:
            testdata1 = inputdata.NewInstance()
            testdata1.ShallowCopy(inputdata)
            testdata1.SetSpacing(1, 1, 1)
            testdata1.SetOrigin(0, 0, 0)
            inputdata = testdata1

        d2p = vtk.vtkDataSetToPiston()
        d2p.SetInputData(inputdata)
        #d2p.SetInputConnection(src.GetOutputPort())

        threshF = vtk.vtkPistonThreshold()
        threshF.SetInputConnection(d2p.GetOutputPort())
        threshF.SetMinValue(0)
        threshF.SetMaxValue(80)

        p2d = vtk.vtkPistonToDataSet()
        p2d.SetInputConnection(threshF.GetOutputPort())
        p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)

        if writefiles:
            writeFile(p2d, "piston_threshold.vtk")

        mapper = vtk.vtkPistonMapper()
        mapper.SetInputConnection(threshF.GetOutputPort())
        mapper.Update()

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        renderer.AddActor(actor)

        renderer.ResetCamera()
        renwin.Render()

        img_file = "TestThreshold.png"
        Testing.compareImage(renwin, Testing.getAbsImagePath(img_file))

        if Testing.isInteractive():
            iren.Start()
コード例 #3
0
    def testSlice(self):
        global plane, filter, args
        writefiles = "SaveData" in args

        renderer = vtk.vtkRenderer()
        renwin = vtk.vtkRenderWindow()
        renwin.AddRenderer(renderer)
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renwin)
        renwin.Render()

        if "GPURender" in args:
            vtk.vtkPistonMapper.InitCUDAGL(renwin)

        src = vtk.vtkImageMandelbrotSource()
        src.SetWholeExtent(0, 20, 0, 20, 0, 20)

        #scale and bias until piston understands origin and spacing
        src.Update()
        inputdata = src.GetOutput()
        if "Normalize" in args:
            testdata1 = inputdata.NewInstance()
            testdata1.ShallowCopy(inputdata)
            testdata1.SetSpacing(1, 1, 1)
            testdata1.SetOrigin(0, 0, 0)
            inputdata = testdata1

        bounds = inputdata.GetBounds()
        center = [(bounds[1] - bounds[0]) / 2 + bounds[0],
                  (bounds[3] - bounds[2]) / 2 + bounds[2],
                  (bounds[5] - bounds[4]) / 2 + bounds[4]]

        d2p = vtk.vtkDataSetToPiston()
        d2p.SetInputData(inputdata)
        #d2p.SetInputConnection(src.GetOutputPort())

        plane = vtk.vtkPlane()
        plane.SetOrigin(center)
        plane.SetNormal(0, 0, 1)

        filter = vtk.vtkPistonSlice()
        filter.SetInputConnection(d2p.GetOutputPort())
        filter.SetClippingPlane(plane)
        filter.SetOffset(0.0)

        p2d = vtk.vtkPistonToDataSet()
        p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)
        p2d.SetInputConnection(filter.GetOutputPort())
        if writefiles:
            writeFile(p2d, "piston_slice.vtk")

        mapper = vtk.vtkPistonMapper()
        mapper.SetInputConnection(filter.GetOutputPort())
        mapper.Update()  #TODO why is this necessary

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        renderer.AddActor(actor)

        widget = vtk.vtkImplicitPlaneWidget()
        widget.PlaceWidget(bounds)
        widget.SetOrigin([plane.GetOrigin()[x] for x in 0, 1, 2])
        widget.SetNormal([plane.GetNormal()[x] for x in 0, 1, 2])
        widget.SetInteractor(iren)
        widget.AddObserver("InteractionEvent", widgetCallBack)
        widget.SetEnabled(1)
        widget.DrawPlaneOff()

        renderer.ResetCamera()
        renwin.Render()

        img_file = "TestSlice.png"
        Testing.compareImage(renwin, Testing.getAbsImagePath(img_file))

        if Testing.isInteractive():
            widget.DrawPlaneOn()
            iren.Start()
コード例 #4
0
ファイル: TestSlice.py プロジェクト: 0004c/VTK
  def testSlice(self):
    global plane, filter, args
    writefiles = "SaveData" in args

    renderer = vtk.vtkRenderer()
    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renwin)
    renwin.Render()

    if "GPURender" in args:
        vtk.vtkPistonMapper.InitCUDAGL(renwin)

    src = vtk.vtkImageMandelbrotSource()
    src.SetWholeExtent(0,20,0,20,0,20)

    #scale and bias until piston understands origin and spacing
    src.Update()
    inputdata = src.GetOutput()
    if "Normalize" in args:
         testdata1 = inputdata.NewInstance()
         testdata1.ShallowCopy(inputdata)
         testdata1.SetSpacing(1,1,1)
         testdata1.SetOrigin(0,0,0)
         inputdata = testdata1

    bounds = inputdata.GetBounds()
    center = [(bounds[1]-bounds[0])/2+bounds[0],
              (bounds[3]-bounds[2])/2+bounds[2],
              (bounds[5]-bounds[4])/2+bounds[4]]

    d2p = vtk.vtkDataSetToPiston()
    d2p.SetInputData(inputdata)
    #d2p.SetInputConnection(src.GetOutputPort())

    plane = vtk.vtkPlane()
    plane.SetOrigin(center)
    plane.SetNormal(0,0,1)

    filter = vtk.vtkPistonSlice()
    filter.SetInputConnection(d2p.GetOutputPort())
    filter.SetClippingPlane(plane)
    filter.SetOffset(0.0)

    p2d = vtk.vtkPistonToDataSet()
    p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)
    p2d.SetInputConnection(filter.GetOutputPort())
    if writefiles:
        writeFile(p2d, "piston_slice.vtk")

    mapper = vtk.vtkPistonMapper()
    mapper.SetInputConnection(filter.GetOutputPort())
    mapper.Update() #TODO why is this necessary

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    renderer.AddActor(actor)

    widget = vtk.vtkImplicitPlaneWidget()
    widget.PlaceWidget(bounds)
    widget.SetOrigin([plane.GetOrigin()[x] for x in 0,1,2])
コード例 #5
0
    def testConversion(self):
        global args
        writefiles = "SaveData" in args

        src = vtk.vtkImageMandelbrotSource()
        src2 = vtk.vtkSphereSource()
        d2p = vtk.vtkDataSetToPiston()
        p2d = vtk.vtkPistonToDataSet()

        #test sending imagedata to the card and getting it back
        src.SetWholeExtent(0, 10, 0, 10, 0, 10)
        d2p.SetInputConnection(src.GetOutputPort())
        p2d.SetOutputDataSetType(vtk.VTK_IMAGE_DATA)
        p2d.SetInputConnection(d2p.GetOutputPort())
        p2d.Update()

        printDS("INPUT IMAGE DATA", src.GetOutput())
        printTDO("GPU VERSION", d2p.GetPistonDataObjectOutput(0))
        printDS("OUTPUT IMAGE DATA", p2d.GetDataSetOutput(0))

        if writefiles:
            writeFile(p2d, "piston_imagedata.vtk")
        inDS = src.GetOutput()
        outDS = p2d.GetDataSetOutput(0)
        if inDS.GetBounds() != outDS.GetBounds():
            self.fail("Problem: bounds were not preserved.")
        if inDS.GetNumberOfCells() != outDS.GetNumberOfCells():
            self.fail("Problem: cells were not preserved.")
        if inDS.GetPointData().GetArray(
                0).GetName() != outDS.GetPointData().GetArray(0).GetName():
            self.fail("Problem: arrays were not preserved.")

        #test sending polydata to the card and getting it back
        #test a pipeline that works on poly data

        #below doesn't work in vtk6, gets null output for p2d
        #since data type AND upstream pipeline changes
        #workaround until that is fixes
        #d2p.SetInputConnection(src2.GetOutputPort())
        #p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)
        #p2d.Update()
        #printDS("INPUT POLYDATA", src2.GetOutput())
        #printTDO("GPU VERSION", d2p.GetPistonDataObjectOutput(0))
        #printDS("OUTPUT POLYDATA", p2d.GetDataSetOutput(0))
        #if writefiles:
        #    writeFile(p2d, "piston_polydata.vtk")
        #
        #so use this instead
        d2p2 = vtk.vtkDataSetToPiston()
        p2d2 = vtk.vtkPistonToDataSet()
        d2p2.SetInputConnection(src2.GetOutputPort())
        p2d2.SetOutputDataSetType(vtk.VTK_POLY_DATA)
        p2d2.SetInputConnection(d2p2.GetOutputPort())
        p2d2.Update()
        printDS("INPUT POLYDATA", src2.GetOutput())
        printTDO("GPU VERSION", d2p2.GetPistonDataObjectOutput(0))
        printDS("OUTPUT POLYDATA", p2d2.GetDataSetOutput(0))
        if writefiles:
            writeFile(p2d2, "piston_polydata.vtk")

        inDS = src2.GetOutput()
        outDS = p2d2.GetDataSetOutput(0)
        if inDS.GetBounds() != outDS.GetBounds():
            self.fail("Problem: bounds were not preserved.")
        if inDS.GetNumberOfCells() != outDS.GetNumberOfCells():
            self.fail("Problem: cells were not preserved.")
        if inDS.GetPointData().GetArray(
                0).GetName() != outDS.GetPointData().GetArray(0).GetName():
            self.fail("Problem: arrays were not preserved.")
コード例 #6
0
  def testConversion(self):
    global args
    writefiles = "SaveData" in args

    src = vtk.vtkImageMandelbrotSource()
    src2 = vtk.vtkSphereSource()
    d2p = vtk.vtkDataSetToPiston()
    p2d = vtk.vtkPistonToDataSet()

    #test sending imagedata to the card and getting it back
    src.SetWholeExtent(0,10,0,10,0,10)
    d2p.SetInputConnection(src.GetOutputPort())
    p2d.SetOutputDataSetType(vtk.VTK_IMAGE_DATA)
    p2d.SetInputConnection(d2p.GetOutputPort())
    p2d.Update()

    printDS("INPUT IMAGE DATA", src.GetOutput())
    printTDO("GPU VERSION", d2p.GetPistonDataObjectOutput(0))
    printDS("OUTPUT IMAGE DATA", p2d.GetDataSetOutput(0))

    if writefiles:
        writeFile(p2d, "piston_imagedata.vtk")
    inDS = src.GetOutput()
    outDS = p2d.GetDataSetOutput(0)
    if inDS.GetBounds() != outDS.GetBounds():
        self.fail("Problem: bounds were not preserved.")
    if inDS.GetNumberOfCells() != outDS.GetNumberOfCells():
        self.fail("Problem: cells were not preserved.")
    if inDS.GetPointData().GetArray(0).GetName() != outDS.GetPointData().GetArray(0).GetName():
        self.fail("Problem: arrays were not preserved.")

    #test sending polydata to the card and getting it back
    #test a pipeline that works on poly data

    #below doesn't work in vtk6, gets null output for p2d
    #since data type AND upstream pipeline changes
    #workaround until that is fixes
    #d2p.SetInputConnection(src2.GetOutputPort())
    #p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)
    #p2d.Update()
    #printDS("INPUT POLYDATA", src2.GetOutput())
    #printTDO("GPU VERSION", d2p.GetPistonDataObjectOutput(0))
    #printDS("OUTPUT POLYDATA", p2d.GetDataSetOutput(0))
    #if writefiles:
    #    writeFile(p2d, "piston_polydata.vtk")
    #
    #so use this instead
    d2p2 = vtk.vtkDataSetToPiston()
    p2d2 = vtk.vtkPistonToDataSet()
    d2p2.SetInputConnection(src2.GetOutputPort())
    p2d2.SetOutputDataSetType(vtk.VTK_POLY_DATA)
    p2d2.SetInputConnection(d2p2.GetOutputPort())
    p2d2.Update()
    printDS("INPUT POLYDATA", src2.GetOutput())
    printTDO("GPU VERSION", d2p2.GetPistonDataObjectOutput(0))
    printDS("OUTPUT POLYDATA", p2d2.GetDataSetOutput(0))
    if writefiles:
        writeFile(p2d2, "piston_polydata.vtk")

    inDS = src2.GetOutput()
    outDS = p2d2.GetDataSetOutput(0)
    if inDS.GetBounds() != outDS.GetBounds():
        self.fail("Problem: bounds were not preserved.")
    if inDS.GetNumberOfCells() != outDS.GetNumberOfCells():
        self.fail("Problem: cells were not preserved.")
    if inDS.GetPointData().GetArray(0).GetName() != outDS.GetPointData().GetArray(0).GetName():
        self.fail("Problem: arrays were not preserved.")