Exemplo n.º 1
1
    def __draw_sample_as_cylinder(self,sample,color,warning_color):
        a = self.__cylinder_actors.get(sample)
        if a is not None:
            a.SetVisibility(1)
            return
        p1 = sample.coil_center
        p2 = sample.sphere_intersection
        p3 = p1+(p2-p1)*1.2  # an extra 20% to guarantee it goes into the sphere
        #height = self.COIL_HEIGHT*1.2
        height = self.COIL_HEIGHT*500
        source = vtk.vtkCylinderSource()
        source.SetCenter(0,0,0)
        #source.SetRadius(self.SAMPLE_RADIUS)
        source.SetRadius(2)
        source.SetHeight(height)
        source.SetResolution(8)

        trans = vtk.vtkTransform()
        trans.Identity()

        v1 = p1-p2
        v1 /= np.linalg.norm(v1)

        v2 = (0,1,0)
        vp = np.cross(v2,v1)
        angle = np.arcsin(np.linalg.norm(vp))
        angle_deg = 180*angle/np.pi

        trans.Translate(p3)
        trans.RotateWXYZ(angle_deg,vp)
        trans.Translate((0,height/2,0))

        trans_filter = vtk.vtkTransformPolyDataFilter()
        trans_filter.SetInputConnection(source.GetOutputPort())
        trans_filter.SetTransform(trans)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(trans_filter.GetOutputPort())

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

        self.ren.AddActor(actor)
        self.__cylinder_actors[sample]=actor

        prop = actor.GetProperty()
        if sample.timing_error > 1:
            if warning_color is None:
                warning_color = self.SAMPLE_CYLINDER_WARNING_COLOR
            prop.SetColor(warning_color)
        else:
            if color is None:
                color = self.SAMPLE_CYLINDER_COLOR
            prop.SetColor(color)
        info = vtk.vtkInformation()
        info.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
        info.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
        #prop.SetAmbient(0.8)
        actor.SetPropertyKeys(info)
Exemplo n.º 2
0
def vis_bw(ax, a, facecolor='r'):
    # verts, faces, normals, values = measure.marching_cubes_lewiner(a, 0)
    # print(verts)
    # mesh = Poly3DCollection(verts[faces], alpha=0.5)
    # mesh.set_facecolor(facecolor)
    # ax.add_collection3d(mesh)

    # v_a = numpy_support.numpy_to_vtk(num_array=a.ravel(), deep=True, array_type=vtk.VTK_STRUCTURED_POINTS)
    # v_a = vtk.vtkDataObject()
    # v_a.SetInformation(v_bit_a)

    # n2vtk = vtk.vtkImageImport()  # Converter
    # n2vtk.SetArr
    #
    # contour = vtk.vtkDiscreteMarchingCubes()
    # contour.SetInputData(v_a)
    # contour.SetValue(0, .5)
    # contour.Update()

    # writer = vtk.vtkPolyDataWriter()
    # writer.SetInputData(contour)
    # writer.SetFileName('contour.vtk')
    # writer.Update()
    # mc = vtk.vtkMarchingCubes(v_a)
    # print(v_a)

    n_a = np.ravel(sitk.GetArrayFromImage(a), order='C')

    v_a = vtk.vtkImageData()
    v_a.SetSpacing(a.GetSpacing())
    v_a.SetOrigin(a.GetOrigin())
    v_a.SetDimensions(a.GetSize())
    print(a.GetPixelID())
    v_a.SetScalarType(convertTypeITKtoVTK(sitk.sitkInt8), vtk.vtkInformation())
    v_a.SetNumberOfScalarComponents(a.GetNumberOfComponentsPerPixel(),
                                    vtk.vtkInformation())

    print('a')
    v_a_to_VTK = numpy_to_vtk(n_a,
                              deep=True,
                              array_type=convertTypeITKtoVTK(a.GetPixelID()))
    print('b')
    v_a.GetPointData().SetScalars(v_a_to_VTK)

    fow = vtk.vtkFileOutputWindow()
    fow.SetFileName('ow.txt')

    ow = vtk.vtkOutputWindow()
    ow.SetInstance(fow)

    contour = vtk.vtkDiscreteMarchingCubes()
    contour.SetInputData(v_a)
    contour.SetValue(0, .5)
    contour.Update()

    writer = vtk.vtkPolyDataWriter()
    writer.SetInputData(contour.GetOutput())
    writer.SetFileName('contour.vtk')
    writer.Update()
Exemplo n.º 3
0
    def testIgnoreBTX(self):
        """Try to call a method that is BTX'd, to ensure VTK_IGNORE_BTX=ON
        """

        stringArray = vtk.vtkStringArray()
        information = vtk.vtkInformation()
        stringArray.CopyInformation(information, 0)
Exemplo n.º 4
0
    def __draw_sphere(self,radius,center,color,resolution=20):
        source = vtk.vtkSphereSource()
        source.SetCenter(*center)
        source.SetRadius(radius)
        source.SetPhiResolution(resolution)
        source.SetThetaResolution(resolution)

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputConnection(source.GetOutputPort())

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(normals.GetOutputPort())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        prop = actor.GetProperty()
        prop.SetColor(color)
        #prop.SetInterpolationToPhong()
        brightness = np.max(color)
        specular_color = np.array(color)/brightness
        prop.SetSpecularColor(specular_color)
        prop.SetSpecular(0.1)
        prop.SetDiffuse(1)
        prop.SetAmbient(0)

        info = vtk.vtkInformation()
        info.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
        info.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
        actor.SetPropertyKeys(info)

        self.ren.AddActor(actor)
Exemplo n.º 5
0
    def testIgnoreBTX(self):
        """Try to call a method that is BTX'd, to ensure VTK_IGNORE_BTX=ON
        """

        stringArray = vtk.vtkStringArray()
        information = vtk.vtkInformation()
        stringArray.CopyInformation(information, 0)
Exemplo n.º 6
0
Arquivo: test.py Projeto: Mapoet/u3d
def set_name_for_actor(name, actor):
    """
    Sets the name in the PropertyKeys of a vtkActor
    """
    key = StringKey.MakeKey("MeshName", "root")
    i = vtk.vtkInformation()
    i.Set(key, name)
    actor.SetPropertyKeys(i)
Exemplo n.º 7
0
def surf_fill_vtk(vertices, polys, mat, shape):

    import vtk
    from vtk.util import numpy_support

    voxverts = nb.affines.apply_affine(np.linalg.inv(mat), vertices)
    points = vtk.vtkPoints()
    points.SetNumberOfPoints(len(voxverts))
    for i, pt in enumerate(voxverts):
        points.InsertPoint(i, pt)

    tris = vtk.vtkCellArray()
    for vert in polys:
        tris.InsertNextCell(len(vert))
        for v in vert:
            tris.InsertCellPoint(v)

    pd = vtk.vtkPolyData()
    pd.SetPoints(points)
    pd.SetPolys(tris)
    del points, tris

    whiteimg = vtk.vtkImageData()
    whiteimg.SetDimensions(shape)
    if vtk.VTK_MAJOR_VERSION <= 5:
        whiteimg.SetScalarType(vtk.VTK_UNSIGNED_CHAR)
    else:
        info = vtk.vtkInformation()
        whiteimg.SetPointDataActiveScalarInfo(info, vtk.VTK_UNSIGNED_CHAR, 1)

    ones = np.ones(np.prod(shape), dtype=np.uint8)
    whiteimg.GetPointData().SetScalars(numpy_support.numpy_to_vtk(ones))

    pdtis = vtk.vtkPolyDataToImageStencil()
    if vtk.VTK_MAJOR_VERSION <= 5:
        pdtis.SetInput(pd)
    else:
        pdtis.SetInputData(pd)

    pdtis.SetOutputWholeExtent(whiteimg.GetExtent())
    pdtis.Update()

    imgstenc = vtk.vtkImageStencil()
    if vtk.VTK_MAJOR_VERSION <= 5:
        imgstenc.SetInput(whiteimg)
        imgstenc.SetStencil(pdtis.GetOutput())
    else:
        imgstenc.SetInputData(whiteimg)
        imgstenc.SetStencilConnection(pdtis.GetOutputPort())
    imgstenc.SetBackgroundValue(0)

    imgstenc.Update()

    data = numpy_support.vtk_to_numpy(
        imgstenc.GetOutput().GetPointData().GetScalars()).reshape(
            shape).transpose(2, 1, 0)
    del pd, voxverts, whiteimg, pdtis, imgstenc
    return data
Exemplo n.º 8
0
def surf_fill_vtk(vertices, polys, mat, shape):

    import vtk
    from vtk.util import numpy_support

    voxverts = nb.affines.apply_affine(np.linalg.inv(mat), vertices)
    points = vtk.vtkPoints()
    points.SetNumberOfPoints(len(voxverts))
    for i, pt in enumerate(voxverts):
        points.InsertPoint(i, pt)

    tris = vtk.vtkCellArray()
    for vert in polys:
        tris.InsertNextCell(len(vert))
        for v in vert:
            tris.InsertCellPoint(v)

    pd = vtk.vtkPolyData()
    pd.SetPoints(points)
    pd.SetPolys(tris)
    del points, tris

    whiteimg = vtk.vtkImageData()
    whiteimg.SetDimensions(shape)
    if vtk.VTK_MAJOR_VERSION <= 5:
        whiteimg.SetScalarType(vtk.VTK_UNSIGNED_CHAR)
    else:
        info = vtk.vtkInformation()
        whiteimg.SetPointDataActiveScalarInfo(info, vtk.VTK_UNSIGNED_CHAR, 1)

    ones = np.ones(np.prod(shape), dtype=np.uint8)
    whiteimg.GetPointData().SetScalars(numpy_support.numpy_to_vtk(ones))

    pdtis = vtk.vtkPolyDataToImageStencil()
    if vtk.VTK_MAJOR_VERSION <= 5:
        pdtis.SetInput(pd)
    else:
        pdtis.SetInputData(pd)

    pdtis.SetOutputWholeExtent(whiteimg.GetExtent())
    pdtis.Update()

    imgstenc = vtk.vtkImageStencil()
    if vtk.VTK_MAJOR_VERSION <= 5:
        imgstenc.SetInput(whiteimg)
        imgstenc.SetStencil(pdtis.GetOutput())
    else:
        imgstenc.SetInputData(whiteimg)
        imgstenc.SetStencilConnection(pdtis.GetOutputPort())
    imgstenc.SetBackgroundValue(0)

    imgstenc.Update()

    data = (
        numpy_support.vtk_to_numpy(imgstenc.GetOutput().GetPointData().GetScalars()).reshape(shape).transpose(2, 1, 0)
    )
    del pd, voxverts, whiteimg, pdtis, imgstenc
    return data
Exemplo n.º 9
0
 def testObjectPointer(self):
     a = vtk.vtkInformation()
     ptr = a.__this__
     # check the format _0123456789abcdef_p_vtkInformation
     self.assertEqual(ptr[0:1], "_")
     self.assertEqual(ptr[-17:], "_p_vtkInformation")
     address = int(ptr[1:-17], 16)
     # create a VTK object from the swig pointer
     b = vtk.vtkObject(ptr)
     self.assertEqual(b.GetClassName(), a.GetClassName())
     self.assertEqual(a.__this__, b.__this__)
     self.assertEqual(a, b)
Exemplo n.º 10
0
 def testObjectPointer(self):
     a = vtk.vtkInformation()
     ptr = a.__this__
     # check the format _0123456789abcdef_p_vtkInformation
     self.assertEqual(ptr[0:1], "_")
     self.assertEqual(ptr[-17:], "_p_vtkInformation")
     address = int(ptr[1:-17], 16)
     # create a VTK object from the swig pointer
     b = vtk.vtkObject(ptr)
     self.assertEqual(b.GetClassName(), a.GetClassName())
     self.assertEqual(a.__this__, b.__this__)
     self.assertEqual(a, b)
Exemplo n.º 11
0
    def draw_block(self,block,color=None):
        a = self.__cone_actors.get(block)
        if a is not None:
            a.SetVisibility(1)
            source = self.__cone_sources[block]
        else:
            source = vtk.vtkConeSource()

        ctr = block.mean_coil_center
        tip = block.mean_intersection
        #r = block.circle_radius
        #r = block.circle_radius
        r = 5

        source.SetCenter(tip-((tip-ctr)/np.linalg.norm(tip-ctr))*0.5*self.COIL_HEIGHT)
        source.SetHeight(self.COIL_HEIGHT*1000)
        source.SetRadius(r)
        source.SetDirection(tip-ctr)
        source.SetResolution(20)

        if a is not None:
            return

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputConnection(source.GetOutputPort())

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(normals.GetOutputPort())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        self.__cone_actors[block]=actor
        self.__cone_sources[block] = source
        self.ren.AddActor(actor)

        prop = actor.GetProperty()
        if color is None:
            color = self.BLOCK_COLOR
        prop.SetColor(color)
        info = vtk.vtkInformation()
        info.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
        info.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
        actor.SetPropertyKeys(info)
Exemplo n.º 12
0
    def FringeSimulator(self, file_name, file_output):
        
 
        reader = vtk.vtkPLYReader()
        reader.SetFileName(file_name)
        reader.Update()

        smooth = vtk.vtkWindowedSincPolyDataFilter()   
        smooth.SetInput(reader.GetOutput())
        smooth.Update()
  
        normals = vtk.vtkPolyDataNormals()
        normals.SetInput(smooth.GetOutput())
        normals.SetComputePointNormals(1)
        normals.SetComputeCellNormals(1)
        normals.Update()

        mapper=vtk.vtkDataSetMapper()
        mapper.SetInput(smooth.GetOutput())
        mapper.SetScalarVisibility(1)

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

        self.renderer.AddActor(actor)

        key_properties = vtk.vtkInformation()
        key_properties.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
        key_properties.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.

        actor.SetPropertyKeys(key_properties)
        actor.SetVisibility(1)

        self.renderer.ResetCamera()
        cam = self.renderer.GetActiveCamera()

        cam_pos = cam.GetPosition()
        cam_f =  cam.GetFocalPoint()

        vcam_pos = numpy.array([float(cam_pos[0]), float(cam_pos[1]), float(cam_pos[2])])
        vcam_f = numpy.array([float(cam_f[0]),float(cam_f[1]),float(cam_f[2])])

        v = vcam_f - vcam_pos 
        d = numpy.linalg.norm(v)
        vn = v/d

        ap = vtk.vtkAppendPolyData()
        dist_fringes = cam_pos - vn * -250

        for x in xrange(-220, 220):
            cube_source= vtk.vtkCubeSource()
            cube_source.SetXLength(0.20)
            cube_source.SetYLength(80)
            cube_source.SetZLength(0.1)

            xfm = vtk.vtkTransform()
            xfm.Translate(float(x) * 0.40, 0, 0) 

            xfmPd = vtk.vtkTransformPolyDataFilter()
            xfmPd.SetInput(cube_source.GetOutput())
            xfmPd.SetTransform(xfm)

            ap.AddInput(xfmPd.GetOutput())

        ap.Update()


        xfm = vtk.vtkTransform()
        xfm.Translate(200, dist_fringes[1], dist_fringes[2])

        xfmPd = vtk.vtkTransformPolyDataFilter()
        xfmPd.SetInput(ap.GetOutput())
        xfmPd.SetTransform(xfm)

        cube_mapper=vtk.vtkPolyDataMapper()
        cube_mapper.SetInput(xfmPd.GetOutput())


        fringes_actor = vtk.vtkActor()
        fringes_actor.SetMapper(cube_mapper)
        fringes_actor.GetProperty().SetColor(1,0,0)

        fringesKeyProperties=vtk.vtkInformation()
        fringesKeyProperties.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
        fringesKeyProperties.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.
        fringes_actor.SetPropertyKeys(fringesKeyProperties)

        self.renderer.AddActor(fringes_actor)
        
        self.renderer.LightFollowCameraOff()
        self.renderer.AutomaticLightCreationOff()
        self.renderer.RemoveAllLights()
        self.renderer.UpdateLights()

        l = vtk.vtkLight()
        l.SetLightTypeToSceneLight()

        dist_light = cam_pos - vn * 6

        l.SetFocalPoint(vcam_f[0], vcam_f[1], vcam_f[2])
        l.SetPosition(220, dist_light[1], dist_light[2])
        l.PositionalOn()
        self.renderer.AddLight(l)
    
        self.renderer.Render()

        wf = vtk.vtkWindowToImageFilter()
        wf.SetInput(self.ren_win)
        wf.Update()

        png = vtk.vtkPNGWriter()
        png.SetFileName(file_output + ".png")
        png.SetInput(wf.GetOutput())
        png.Write()
Exemplo n.º 13
0
    def __draw_nose(self,calib_points,center):
        source = vtk.vtkCubeSource()

        width = np.linalg.norm(calib_points["left"]-calib_points["right"])/5
        source.SetXLength(width)
        height = np.linalg.norm(calib_points["nasion"]-calib_points["vertex"])/3
        source.SetYLength(height)
        source.SetZLength(height)

        #make it straight (y facing vertex)
        v3 = calib_points["vertex"]-center
        v3 /= np.linalg.norm(v3)
        v4 = np.array((0,1,0))
        perp2 = np.cross(v3,v4)
        angle2 = np.arcsin(np.linalg.norm(perp2))
        angle_deg2 = angle2*180/np.pi

        #make it straight (z facing front)
        front = calib_points["nasion"]-center
        front2 = front - np.dot(front,v3)*v3
        front2/= np.linalg.norm(front2)
        front_o = np.array((0,0,1))
        front_o2 = front_o-np.dot(front_o,v3)*v3
        front_o2/= np.linalg.norm(front_o2)
        angle3 = np.arcsin(np.linalg.norm(np.cross(front2,front_o2)))
        angle_deg3 = angle3*180/np.pi

        transform = vtk.vtkTransform()
        transform.Translate(-1*front2*height/2)
        transform.Translate(calib_points["nasion"])
        transform.RotateWXYZ(angle_deg3,v3)
        transform.RotateWXYZ(-1*angle_deg2,perp2)

        transform_filter = vtk.vtkTransformPolyDataFilter()
        transform_filter.SetInputConnection(source.GetOutputPort())
        transform_filter.SetTransform(transform)

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputConnection(transform_filter.GetOutputPort())

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(normals.GetOutputPort())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        self.ren.AddActor(actor)

        color = self.SKULL_COLOR
        prop = actor.GetProperty()
        prop.SetColor(color)
        prop.SetDiffuseColor(color)
        brightness = np.max(color)
        specular_color = np.array(color)/brightness
        prop.SetSpecularColor(specular_color)
        prop.SetInterpolationToFlat()
        prop.SetSpecular(0.0)
        prop.SetDiffuse(0.8)
        info = vtk.vtkInformation()
        info.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
        info.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
        actor.SetPropertyKeys(info)
cameraP.SetDelegatePass(seq)

renderer.SetPass(cameraP)

rectangleSource = vtk.vtkPlaneSource()
rectangleSource.SetOrigin(-5.0,0.0,5.0)
rectangleSource.SetPoint1(5.0,0.0,5.0)
rectangleSource.SetPoint2(-5.0,0.0,-5.0)
rectangleSource.SetResolution(100,100)

rectMapper = vtk.vtkPolyDataMapper()
rectMapper.SetInputData(rectangleSource.GetOutput())
rectMapper.SetScalarVisibility(0)

rectActor = vtk.vtkActor()
rectKeyProperty = vtk.vtkInformation()
rectKeyProperty.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
rectKeyProperty.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
rectActor.SetPropertyKeys(rectKeyProperty)

rectActor.SetMapper(rectMapper)
rectActor.SetVisibility(1);
rectActor.GetProperty().SetColor(1,1,1);

boxSource = vtk.vtkCubeSource()
boxSource.SetXLength(2)

boxNormals = vtk.vtkPolyDataNormals()
boxNormals.SetInputData(boxSource.GetOutput())
boxNormals.SetComputePointNormals(0)
boxNormals.SetComputeCellNormals(0)
Exemplo n.º 15
0
def compute(whole, split):

# prepare
  controller = vtk.vtkMPIController()
  vtk.vtkMultiProcessController.SetGlobalController(controller)
  rank = controller.GetLocalProcessId()
  nprocs = controller.GetNumberOfProcesses()
  #  print('rank={0}'.format(rank))
  #  print('nprocs={0}'.format(nprocs))

  # whole
  (wholeDataset, bounds, dimension) = readDataset(whole)
  if pow(2,dimension) != nprocs:
    print 'the number of procs must be 2^dimension'
    sys.exit()

  # coarse
  coarseData = vtk.vtkImageData()
  coarseData.CopyStructure(wholeDataset)
  coarseData.SetSpacing(0.1,0.1,0.1)
  if dimension == 2:
    coarseData.SetDimensions(11,11,1)
  else:
    coarseData.SetDimensions(11,11,11)
  #  print data
  #  print coarseData

  # compute moments
  momentsFilter = vtk.vtkComputeMoments()
  momentsFilter.SetFieldData(wholeDataset)
  momentsFilter.SetGridData(coarseData)
  momentsFilter.SetNameOfPointData(nameOfPointData)
  momentsFilter.SetUseFFT(0)
  momentsFilter.SetNumberOfIntegrationSteps(numberOfIntegrationSteps)
  momentsFilter.SetOrder(order)
  momentsFilter.SetRadiiArray([radius,0,0,0,0,0,0,0,0,0])
  momentsFilter.Update()
  #  if rank ==0: print momentsFilter



  # this is to make sure each proc only loads their piece
  ids_to_read = [rank]
  reqs = vtk.vtkInformation()
  reqs.Set(vtk.vtkCompositeDataPipeline.UPDATE_COMPOSITE_INDICES(), ids_to_read, 1)

  reader = vtk.vtkXMLMultiBlockDataReader()
  reader.SetFileName(split)
  reader.Update(reqs)
  #    print('reader={0}'.format(reader.GetOutput()))

  multiblock = vtk.vtkMultiBlockDataSet.SafeDownCast(reader.GetOutput())
  #    print('multiblock={0}'.format(multiblock))

  multipiece = vtk.vtkMultiPieceDataSet.SafeDownCast(multiblock.GetBlock(0))
  #    print('multipiece={0}'.format(multipiece))

  data = vtk.vtkImageData.SafeDownCast(multipiece.GetPiece(rank))
#  print('data={0}'.format(data))

  # coarse
  coarseData = vtk.vtkImageData()
  coarseData.CopyStructure(data)
  coarseData.SetSpacing(0.1,0.1,0.1)
  if dimension == 2:
    coarseData.SetDimensions(6,6,1)
  else:
    coarseData.SetDimensions(6,6,6)
  #  print data
  #  coarseData

  # parallel
  pMomentsFilter = vtk.vtkPComputeMoments()
  pMomentsFilter.SetFieldData(data)
  pMomentsFilter.SetGridData(coarseData)
  pMomentsFilter.SetNameOfPointData(nameOfPointData)
  pMomentsFilter.SetNumberOfIntegrationSteps(numberOfIntegrationSteps)
  pMomentsFilter.SetRadiiArray([radius, 0, 0, 0, 0, 0, 0, 0, 0, 0 ])
  pMomentsFilter.Update(reqs)
#  if rank ==0: print pMomentsFilter




  # check for difference except for the global boundary (the probe and parallel probe filters behave differently there. So, there is a difference if numberOfIntegrationSteps > 0 )
  diff = 0
  for i in xrange(pMomentsFilter.GetOutput().GetPointData().GetNumberOfArrays()):
    diffArray = vtk.vtkDoubleArray()
    diffArray.SetName( pMomentsFilter.GetOutput().GetPointData().GetArrayName(i) )
    diffArray.SetNumberOfComponents( 1 )
    diffArray.SetNumberOfTuples( pMomentsFilter.GetOutput().GetNumberOfPoints() )
    diffArray.Fill( 0.0 )

    momentsArray = momentsFilter.GetOutput().GetPointData().GetArray(i)
    pMomentsArray = pMomentsFilter.GetOutput().GetPointData().GetArray(i)

    for j in xrange(pMomentsFilter.GetOutput().GetNumberOfPoints()):
      diffArray.SetTuple1(j, abs(momentsArray.GetTuple1(momentsFilter.GetOutput().FindPoint(pMomentsFilter.GetOutput().GetPoint(j))) - pMomentsArray.GetTuple1(j)))
      if (dimension == 2 and pMomentsFilter.GetOutput().GetPoint(j)[0] > 0 and pMomentsFilter.GetOutput().GetPoint(j)[0] < 1 and pMomentsFilter.GetOutput().GetPoint(j)[1] > 0 and pMomentsFilter.GetOutput().GetPoint(j)[1] < 1) or (dimension == 3 and pMomentsFilter.GetOutput().GetPoint(j)[0] > 0 and pMomentsFilter.GetOutput().GetPoint(j)[0] < 1 and pMomentsFilter.GetOutput().GetPoint(j)[1] > 0 and pMomentsFilter.GetOutput().GetPoint(j)[1] < 1 and  pMomentsFilter.GetOutput().GetPoint(j)[2] > 0 and pMomentsFilter.GetOutput().GetPoint(j)[2] < 1):
#        if diffArray.GetTuple1(j) > 1e-10:
#          print rank, i, j, pMomentsFilter.GetOutput().GetPoint(j), diffArray.GetTuple(j)
        diff = max(diff, diffArray.GetTuple1(j))
  if diff > 1e-10:
    print "test failed, maxdiff =", diff
  else:
    print "test successful"



  if rank == 0:
    print 'all done!'
cameraP.SetDelegatePass(seq)

renderer.SetPass(cameraP)

rectangleSource = vtk.vtkPlaneSource()
rectangleSource.SetOrigin(-5.0,0.0,5.0)
rectangleSource.SetPoint1(5.0,0.0,5.0)
rectangleSource.SetPoint2(-5.0,0.0,-5.0)
rectangleSource.SetResolution(100,100)

rectMapper = vtk.vtkPolyDataMapper()
rectMapper.SetInputData(rectangleSource.GetOutput())
rectMapper.SetScalarVisibility(0)

rectActor = vtk.vtkActor()
rectKeyProperty = vtk.vtkInformation()
rectKeyProperty.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
rectKeyProperty.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
rectActor.SetPropertyKeys(rectKeyProperty)

rectActor.SetMapper(rectMapper)
rectActor.SetVisibility(1);
rectActor.GetProperty().SetColor(1,1,1);

boxSource = vtk.vtkCubeSource()
boxSource.SetXLength(2)

boxNormals = vtk.vtkPolyDataNormals()
boxNormals.SetInputData(boxSource.GetOutput())
boxNormals.SetComputePointNormals(0)
boxNormals.SetComputeCellNormals(0)
Exemplo n.º 17
0
 def isosurface(self, cubeobject, isovalue):
     me = Mesh.New()
     me2 = Mesh.New()
     faces = []
     vertices = []
     scalars = vtk.vtkFloatArray()
     for k in range(cubeobject.nz):
         for j in range(cubeobject.ny):
             for i in range(cubeobject.nx):
                 scalars.InsertNextValue(cubeobject.data3d[k][j][i])
     grid = vtk.vtkStructuredPoints()
     info = vtk.vtkInformation()
     grid.SetOrigin(cubeobject.origin[0], cubeobject.origin[1],
                    cubeobject.origin[2])
     grid.SetDimensions(cubeobject.nx, cubeobject.ny, cubeobject.nz)
     grid.SetSpacing(cubeobject.dx, cubeobject.dy, cubeobject.dz)
     grid.SetNumberOfScalarComponents(
         cubeobject.nx * cubeobject.ny * cubeobject.nz, info)
     grid.GetPointData().SetScalars(scalars)
     Marching = vtk.vtkContourFilter()
     Marching.SetInputData(grid)
     Marching.SetValue(0, isovalue)
     Marching.Update()
     contoursurface = Marching.GetOutput()
     for i in range(contoursurface.GetNumberOfPoints()):
         point = contoursurface.GetPoint(i)
         vertices.append([
             point[0] + self.cursorXYZ[0], point[1] + self.cursorXYZ[1],
             point[2] + self.cursorXYZ[2]
         ])
     me.verts.extend(vertices)
     me.materials = [materials["positivelobe"]]
     for i in range(contoursurface.GetNumberOfCells()):
         cell = contoursurface.GetCell(i)
         n1 = cell.GetPointId(0)
         n2 = cell.GetPointId(1)
         n3 = cell.GetPointId(2)
         faces.append([me.verts[n1], me.verts[n2], me.verts[n3]])
     me.faces.extend(faces)
     for face in me.faces:
         face.smooth = True
     ob = self.scene.objects.new(me, 'Positive Lobe')
     Marching.SetValue(0, -isovalue)
     Marching.Update()
     contoursurface = Marching.GetOutput()
     vertices = []
     for i in range(contoursurface.GetNumberOfPoints()):
         point = contoursurface.GetPoint(i)
         vertices.append([
             point[0] + self.cursorXYZ[0], point[1] + self.cursorXYZ[1],
             point[2] + self.cursorXYZ[2]
         ])
     me2.verts.extend(vertices)
     faces = []
     for i in range(contoursurface.GetNumberOfCells()):
         cell = contoursurface.GetCell(i)
         n1 = cell.GetPointId(0)
         n2 = cell.GetPointId(1)
         n3 = cell.GetPointId(2)
         faces.append([me2.verts[n1], me2.verts[n2], me2.verts[n3]])
     me2.faces.extend(faces)
     me2.materials = [materials["negativelobe"]]
     for face in me2.faces:
         face.smooth = True
     ob = self.scene.objects.new(me2, 'Negative Lobe')
Exemplo n.º 18
0
import vtk
from vtk.util import keys

import vtk
from vtk.util import keys

key = keys.MakeKey(keys.ObjectBaseKey, "a new key", "some class")
print("key:\n", key)

info = vtk.vtkInformation()
print("info:\n", info)

key.Set(info, vtk.vtkObject())
# Same as
#info.Set(key, vtk.vtkObject())

print("info after set:\n", info)

# Storing an integer in an information object
key = keys.MakeKey(keys.IntegerKey, "another key", "some class")

key.Set(info, 12)
print(info)

# vtkInformation is not aware of all types, hence the Set belongs to key

# For custom types, you will need to use key.Set(information, value)

info = vtk.vtkInformation()
info.Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER(), 1)