help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: structures, lvalues and handle graphics


From: Kai Habel
Subject: Re: structures, lvalues and handle graphics
Date: Sun, 03 Sep 2000 13:10:10 +0200

Nimrod Mesika wrote:
> 
> I'm trying to implement the following functionality (following jwe's
> suggestion):
> 
> h = line(...) % or whatever constructor you choose
> s = get(h);   % s is now some form of struct
> 
> s.Color='red';
> 
> The code I'm using looks like this:
> 
> octave_value Line::asStruct()
> {
>     Octave_map m;
>     m["Type"] = octave_value("line");
>     m["Color"] = octave_value(color);
>     octave_value v(new octave_struct(m));
>     return v;
> }
> 
> The real problem, of course, is that I need to check the values
> entered - make sure their type is correct, values are within range,
> etc. Once the value has been changed the figure must be updated
> accordingly.
> 
> Initially, I thought I'd subclass octave_value and create a few new
> types: handle_string, handle_vector, handle_scalar. The new types
> would carry a handle to the handle graphics object and their values
> would be validated when modified.
> 
> The problem with this approach is that, usually, structure fields
> are not modified but rather recreated with a new value. So unless
> the user writes "s.Color(1:3)='red'" no validation checks would be
> done and the object would not be updated.
> 
> Next, I tried creating a new handle_struct type. It is similar to
> octave_struct, except lvalues are initialized with a chg_fcn. This
> function is indeed called when one of the values is being modified
> (and yes, even when they are replaced with a new octave_value
> object).
> 
> BUT, the chg_fcn is called without any arguments. How do I get the
> value of the object being modified? Subclassing octave_lvalue to
> change the calls to chg_fcn is no good because no functions are
> declared virtual.
> 
> A third idea (which I haven't tried yet) is to create a new type
> which will work as a 'proxy' for the real value. This is similar to
> the way octave_value holds an octave_value representation and it may
> be possible to subclass octave_value to do just that.
> 
> Obviously, I'm not familiar enough with Octave so maybe I'm missing
> something obvious.
> 
> Any ideas? jwe? others?

Hello,
since I have started working on a octave_figure class, I would like to
share my ideas.

I would like to stay more closly to matlabs graphics/ui classes. I
wouldn't use a octave structure directly, it should be encapsulated in a
new class, to avoid direct acces to its members. The line contructor
should give back the line object, but should only print a unique id .
(well I don't know if this is possible)

The matlab classes are very good documented and available in the
graphics manual (refbook2.pdf) from matlabs site. 

                  Root
                    |
                  Figure
                    |
      --------------------------------------------
      |           |             |                |
    Axes     Uicontrol       Uimenu      Uicontextmenu
      |
      -----------------------------------------------------------------
      |           |         |       |          |             |        |
     Image      Light     Line    Patch    Rectangle     Surface    Text


A figure class would be something like this

class
ocatve_figure : octave_base_value {
  private:
    int id
    init_figure(void) {
      // set initial Property values
      id = a_global_static_id_value++;
    }
    PropType1 Property1
    PropType2 Property2
    ...
    PropTypen Propertyn
  public:
    octave_figure {
      // Constructor
      init_figure();
    }
    PropType getProperty(string PropKey) {
      if PropKey=='Property1name'
        retval = Property1
        ...
    }
    int setProperty(string Propertyname,Propertyn) {
      //check Propertyname and value
    }
......
};
The set/get pair would acces the public methods getProperty,setProperty.

I am not sure if it works this way, especially the derivation from
octave_base_value. 

The graphic classes are a importend piece of infrastructure. It is the
part independend of the graphic library. If this part is is fixed, we
can implement, the actual functions using the graphic library (VTK,...)

Since there was some discussion on the graphics library, I would like to
add that SGI has rereleased Open Inventor under LGPL. (see
http://oss.sgi.com) There exists even a SoGTK class (see
http://www.coin.org , now LGPL too)

On my homepage I have added a simple example for a surf function using
VTK. (see http://user.berlin.de/Šþkai.habel/demo/demo_vtkgraphics.html )

Bye Kai
-- 
Kai Habel
mailto:address@hidden



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]