Esempio n. 1
0
    def draw(self, gfxwindow, device):
        device.comment("Material Color")
        if config.dimension() == 2:
            themesh = self.who().resolve(gfxwindow)
            polygons = self.polygons(gfxwindow, themesh)
            # colorcache is a dictionary of colors keyed by Material.  It
            # prevents us from having to call material.fetchProperty for
            # each element.
            colorcache = {}
            for polygon, material in zip(polygons,
                                         self.materials(gfxwindow, themesh)):
                if material is not None:
                    try:
                        # If material has been seen already, retrieve its color.
                        color = colorcache[material]
                    except KeyError:
                        # This material hasn't been seen yet.
                        try:
                            colorprop = material.fetchProperty('Color')
                            color = colorprop.color()
                        except ooferror.ErrNoSuchProperty:
                            color = None
                        colorcache[material] = color
                    if color is not None:
                        device.set_fillColor(color)
                        device.fill_polygon(primitives.Polygon(polygon))
 
        elif config.dimension() == 3:
            # TODO 3D: clean up this code in general, perhaps the look
            # up table should be a member of the microstructure...
            themesh = self.who().resolve(gfxwindow).getObject()
            grid = themesh.skelgrid
            numCells = grid.GetNumberOfCells()
            # TODO 3D: will need to handle the creation and deletion of this array within canvas...
            materialdata = vtk.vtkIntArray()
            materialdata.SetNumberOfValues(numCells)
            grid.GetCellData().SetScalars(materialdata)
            lut = vtk.vtkLookupTable()
            colordict = {}
            for i in xrange(numCells):
                cat = themesh.elements[i].dominantPixel(themesh.MS)
                materialdata.SetValue(i,cat)
                mat = themesh.elements[i].material(themesh)
                if mat is not None:
                    try: 
                        color = colordict[cat]
                    except KeyError:
                        colorprop = mat.fetchProperty('Color')
                        color = colorprop.color()
                        colordict[cat] = color
            lut.SetNumberOfColors(max(colordict.keys())+1)
            lut.SetTableRange(min(colordict.keys()), max(colordict.keys()))
            for i in colordict:
                color = colordict[i]
                if color is not None:
                    lut.SetTableValue(i,color.getRed(),color.getGreen(),color.getBlue(),1)
                else:
                    lut.SetTableValue(i,0,0,0,0)
            device.draw_unstructuredgrid_with_lookuptable(grid, lut, mode="cell", scalarbar=False)
Esempio n. 2
0
 def getVtkLookupTable(self, numcolors):
     lut = vtkColorLUT.New()
     vtkColorLUT.SetNumberOfColors(lut, numcolors)
     delta = 1./(numcolors - 1)
     for i in xrange(numcolors):
         color = self.__call__(i*delta)
         vtkColorLUT.SetTableValue(
             lut, i, color.getRed(), color.getGreen(), color.getBlue(), 1)
     return lut
Esempio n. 3
0
 def add_glyphs(self, grid, source, color):
     glyph = vtk.vtkGlyph3D()
     glyph.SetInput(grid)
     glyph.SetSource(source.GetOutput())
     glyph.SetVectorModeToUseNormal()
     glyphmapper = vtk.vtkPolyDataMapper()
     glyphmapper.SetInput(glyph.GetOutput())
     self.glyphActor = vtk.vtkActor()
     self.glyphActor.SetMapper(glyphmapper)
     self.glyphActor.GetProperty().SetColor(color.getRed(),
                                            color.getGreen(),
                                            color.getBlue())
Esempio n. 4
0
 def add_glyphs(self, grid, source, color):
     glyph = vtk.vtkGlyph3D()
     glyph.SetInput(grid)
     glyph.SetSource(source.GetOutput())
     glyph.SetVectorModeToUseNormal()
     glyphmapper = vtk.vtkPolyDataMapper()
     glyphmapper.SetInput(glyph.GetOutput())
     self.glyphActor = vtk.vtkActor()
     self.glyphActor.SetMapper(glyphmapper)
     self.glyphActor.GetProperty().SetColor(color.getRed(),
                                            color.getGreen(),
                                            color.getBlue())
Esempio n. 5
0
 def getVtkLookupTable(self, numcolors, min, max):
     if max == min:
         max += 1.0
     lut = vtk.vtkLookupTable()
     lut.SetNumberOfColors(numcolors)
     lut.SetTableRange(min,max)
     delta = (max-min)/(numcolors-1)
     x = min
     for i in xrange(numcolors):
         color = self.__call__((x-min)/(max-min))
         x += delta
         lut.SetTableValue(i,color.getRed(),color.getGreen(),color.getBlue(),1)
     return lut
Esempio n. 6
0
 def getVtkLookupTable(self, numcolors, min, max):
     if max == min:
         max += 1.0
     lut = vtk.vtkLookupTable()
     lut.SetNumberOfColors(numcolors)
     lut.SetTableRange(min,max)
     delta = (max-min)/(numcolors-1)
     x = min
     for i in xrange(numcolors):
         color = self.__call__((x-min)/(max-min))
         x += delta
         lut.SetTableValue(i,color.getRed(),color.getGreen(),color.getBlue(),1)
     return lut
Esempio n. 7
0
    def draw(self, gfxwindow, device):
        device.comment("Material Color")
        if config.dimension() == 2:
            themesh = self.who().resolve(gfxwindow)
            polygons = self.polygons(gfxwindow, themesh)
            # colorcache is a dictionary of colors keyed by Material.  It
            # prevents us from having to call material.fetchProperty for
            # each element.
            colorcache = {}
            for polygon, material in zip(polygons,
                                         self.materials(gfxwindow, themesh)):
                if material is not None:
                    try:
                        # If material has been seen already, retrieve its color.
                        color = colorcache[material]
                    except KeyError:
                        # This material hasn't been seen yet.
                        try:
                            colorprop = material.fetchProperty('Color')
                            color = colorprop.color()
                        except ooferror.ErrNoSuchProperty:
                            color = None
                        colorcache[material] = color
                    if color is not None:
                        device.set_fillColor(color)
                        device.fill_polygon(primitives.Polygon(polygon))

        elif config.dimension() == 3:
            # TODO 3D: clean up this code in general, perhaps the look
            # up table should be a member of the microstructure...
            themesh = self.who().resolve(gfxwindow).getObject()
            grid = themesh.skelgrid
            numCells = grid.GetNumberOfCells()
            # TODO 3D: will need to handle the creation and deletion of this array within canvas...
            materialdata = vtk.vtkIntArray()
            materialdata.SetNumberOfValues(numCells)
            grid.GetCellData().SetScalars(materialdata)
            lut = vtk.vtkLookupTable()
            colordict = {}
            for i in xrange(numCells):
                cat = themesh.elements[i].dominantPixel(themesh.MS)
                materialdata.SetValue(i, cat)
                mat = themesh.elements[i].material(themesh)
                if mat is not None:
                    try:
                        color = colordict[cat]
                    except KeyError:
                        colorprop = mat.fetchProperty('Color')
                        color = colorprop.color()
                        colordict[cat] = color
            lut.SetNumberOfColors(max(colordict.keys()) + 1)
            lut.SetTableRange(min(colordict.keys()), max(colordict.keys()))
            for i in colordict:
                color = colordict[i]
                if color is not None:
                    lut.SetTableValue(i, color.getRed(), color.getGreen(),
                                      color.getBlue(), 1)
                else:
                    lut.SetTableValue(i, 0, 0, 0, 0)
            device.draw_unstructuredgrid_with_lookuptable(grid,
                                                          lut,
                                                          mode="cell",
                                                          scalarbar=False)
Esempio n. 8
0
 def set_contourmap_bgColor(self, color):
     if self._ContourRenderer is not None:
         self._ContourRenderer.SetBackground(color.getRed(),
                                             color.getGreen(),
                                             color.getBlue())
Esempio n. 9
0
 def set_bgColor(self, color):
     self._Renderer.SetBackground(color.getRed(), color.getGreen(),
                                  color.getBlue())
Esempio n. 10
0
 def set_contourmap_bgColor(self, color):
     if self._ContourRenderer is not None:
         self._ContourRenderer.SetBackground(color.getRed(), color.getGreen(), color.getBlue())
Esempio n. 11
0
 def set_bgColor(self, color):
     self._Renderer.SetBackground(color.getRed(), color.getGreen(), color.getBlue())