Changeset 2895 for trunk


Ignore:
Timestamp:
02/19/14 20:41:19 (11 years ago)
Author:
WataruKawasaki
Message:

New Development: Yes

JIRA Issue: Yes CAS-6168

Ready for Test: Yes

Interface Changes:

What Interface Changed:

Test Programs:

Put in Release Notes: Yes

Module(s): sd.plotter2

Description: added methods to sd.plotter2 to enable changing the size and shape of the entire region to be plotted (which is referred to as 'viewsurface' in PGPLOT).


Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/plotter2.py

    r2861 r2895  
    55    def __init__(self):
    66        self._plotter = Plotter2()
     7        self.current_vs_unit = 'cm'
    78
    89    def set_output(self, filename=None, dev=None):
     
    3738        self._plotter.set_filename(expanduser(expandvars(filename)))
    3839        self._plotter.set_device(dev.strip())
    39 
     40        self.device = dev.strip()
     41
     42    def get_vs(self):
     43        """\
     44        returns viewsurface information as a dictionary.
     45        """
     46        width = self._plotter.get_viewsurface_width()
     47        unit = self.current_vs_unit
     48        if unit == 'cm':
     49            width = width * 2.54 # inch to centimeter
     50        elif unit == 'mm':
     51            width = width * 25.4 # inch to millimeter
     52        elif unit == 'pixel':
     53            width = width * 85.0 + 1.0 # inch to pixel (plus correction for 1pixel)
     54
     55        aspect = self._plotter.get_viewsurface_aspect()
     56
     57        return {'width': width, 'unit': unit, 'aspect': aspect}
     58
     59    def set_vs(self, width=None, unit=None, aspect=None):
     60        """\
     61        set size/shape of graphic window or output file. ('vs' comes from
     62        'view surface' defined by PGPLOT)
     63        Parameters:
     64            width:  width of graphic window or output file.
     65            unit:   unit of width. default value is 'cm'. 'mm', 'inch'
     66                    and 'pixel' are also available.
     67            aspect: aspect ratio (= height / width).
     68       
     69        Example:
     70            set_vs(width=10, unit='cm', aspect=1.0) -- set the output
     71                window/file as a square 10cm on a side.
     72            set_vs(width=400, unit='pixel', aspect=0.75) -- set the output
     73                window/file as a rectangle with 400 pixels in width and
     74                300 pixels in height.
     75
     76        Note:
     77            setting unit to 'cm', 'mm' or 'inch' results in the correct
     78            size when output device is X Window or PostScript, but not for
     79            the other cases (png). also, setting unit to 'pixel' works
     80            correctly only when output device is 'png'. this arises from
     81            the fixed size of pixel (=1/85 inch) defined in PGPLOT.
     82        """
     83        if width is None:
     84            width = self._plotter.get_viewsurface_width() # inch
     85            if self.current_vs_unit == 'cm':
     86                width = width * 2.54 # inch to centimeter
     87            elif self.current_vs_unit == 'mm':
     88                width = width * 25.4 # inch to millimeter
     89            elif self.current_vs_unit == 'pixel':
     90                width = width * 85.0 + 1.0 # inch to pixel (plus correction for 1pixel)
     91        if unit is None: unit = self.current_vs_unit
     92        if aspect is None: aspect = self._plotter.get_viewsurface_aspect()
     93       
     94        if not ((isinstance(width, int) or isinstance(width, float)) and (width > 0)):
     95            raise ValueError("Width must be positive float or integer.")
     96        if not (isinstance(aspect, int) or isinstance(aspect, float)):
     97            raise ValueError("Aspect must be positive float or integer.")
     98
     99        unit = unit.lower().strip()
     100        if unit == 'cm':
     101            width = width / 2.54 # centimeter to inch
     102        elif unit == 'mm':
     103            width = width / 25.4 # millimeter to inch
     104        elif unit == 'pixel':
     105            width = (width - 1.0) / 85.0 # pixel to inch (plus correction for 1pixel)
     106        elif unit != 'inch':
     107            raise ValueError("Unit must be 'cm', 'mm', 'inch' or 'pixel'.")
     108        self.current_vs_unit = unit
     109
     110        self._plotter.set_viewsurface(width, aspect)
     111       
    40112    def set_vp(self, xmin, xmax, ymin, ymax, id=None):
    41113        """\
  • trunk/src/Plotter2.cpp

    r2861 r2895  
    294294    hasDefaultViewport = true;
    295295    currentViewportId = 0;
     296
     297    width = 8.82796; // default viewsurface width seems to be this value.
     298    aspect = 0.75;   // default viewsurface aspect
    296299}
    297300
     
    320323    cpgopen((filename + "/" + device).c_str());
    321324    hasDevice = true;
     325}
     326
     327float Plotter2::getViewSurfaceWidth() {
     328    return width;
     329}
     330
     331float Plotter2::getViewSurfaceAspect() {
     332    return aspect;
     333}
     334
     335void Plotter2::setViewSurface(const float inWidth, const float inAspect) {
     336    width = inWidth;
     337    aspect = inAspect;
    322338}
    323339
     
    11271143    open();
    11281144
     1145    if ((width > 0.0) && (aspect > 0.0)) {
     1146        cpgpap(width, aspect);
     1147    }
     1148
    11291149    cpgscr(0, 1.0, 1.0, 1.0); // set background color white
    11301150    cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black
  • trunk/src/Plotter2.h

    r2861 r2895  
    162162    void setDevice(const std::string& inDevice);
    163163
     164    float getViewSurfaceWidth();
     165    float getViewSurfaceAspect();
     166    void setViewSurface(const float width, const float aspect);
    164167    int addViewport(const float xmin, const float xmax, const float ymin, const float ymax);
    165168    void setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id);
     
    208211    bool hasDefaultViewport;
    209212    int currentViewportId;
     213    float width;
     214    float aspect;
    210215    void open();
    211216    void close();
  • trunk/src/python_Plotter2.cpp

    r2830 r2895  
    4444         .def("get_device",&Plotter2::getDevice)
    4545         .def("set_device",&Plotter2::setDevice)
     46         .def("get_viewsurface_width",&Plotter2::getViewSurfaceWidth)
     47         .def("get_viewsurface_aspect",&Plotter2::getViewSurfaceAspect)
     48         .def("set_viewsurface",&Plotter2::setViewSurface)
    4649         .def("add_viewport",&Plotter2::addViewport)
    4750         .def("set_viewport",&Plotter2::setViewport)
Note: See TracChangeset for help on using the changeset viewer.