casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CachingDisplayData.h
Go to the documentation of this file.
1 //# CachingDisplayData.h: base class for auto-caching DisplayData objects
2 //# Copyright (C) 1999,2000,2001,2002,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TRIALDISPLAY_CACHINGDISPLAYDATA_H
29 #define TRIALDISPLAY_CACHINGDISPLAYDATA_H
30 
31 #include <casa/aips.h>
32 #include <list>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37  class WorldCanvas;
38  class WorldCanvasHolder;
39  class AttributeBuffer;
40  class CachingDisplayMethod;
41 
42 // <summary>
43 // Base class for auto-caching DisplayData objects.
44 // </summary>
45 
46 // <use visibility=export>
47 
48 // <reviewed reviewer="" data="" tests="" demos="">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class=DisplayData> DisplayData </linkto>
53 // </prerequisite>
54 
55 // <etymology>
56 // "CachingDisplayData" is an implementation of a <linkto
57 // class=DisplayData> DisplayData </linkto> which provides automatic
58 // caching of individual depictions of the data.
59 // </etymology>
60 
61 // <synopsis>
62 // This class adds to the interface defined in <linkto
63 // class=DisplayData>DisplayData </linkto>. It adds an "automagic"
64 // caching system, which takes care of managing a set of individual
65 // drawings made by the DisplayData, and using previously generated
66 // drawing commands where applicable. For example, the user might be
67 // playing a movie of several frames in a DisplayData. The automagic
68 // caching will ensure that after one complete loop, while parameters
69 // affecting the display of the data do not change, all subsequent
70 // drawings will be made from a cache of drawing commands.
71 // Furthermore, provided the cache is large enough, the user may alter
72 // parameters, view some more frames, then return the parameters to
73 // their original state, and there may still be older cached drawings
74 // which can be used.
75 //
76 // The automagic caching also handles the case where a single
77 // DisplayData is registered on more than one <linkto
78 // class=WorldCanvasHolder>WorldCanvasHolder </linkto>. Thus a
79 // miniature view of the data could be shown in one window, and an
80 // expanded view in another, with full automagic caching available on
81 // both.
82 //
83 // This is a base class. Derived classes must implement the
84 // <src>newDisplayMethod</src> method, which is called to construct a
85 // new <linkto class=CachingDisplayMethod> CachingDisplayMethod
86 // </linkto> when the cache cannot satisfy the current drawing
87 // request. The method <src>optionsAsAttributes</src> should also be
88 // implemented: when a new CachingDisplayMethod is constructed, the
89 // return value of this method will be used to tag the parameters used
90 // in the drawing itself. Finally, the method
91 // <src>cachingAttributes</src> can be over-ridden, and should
92 // return any additional <linkto class=Attribute> Attributes </linkto>
93 // which should be considered in searches of the cache.
94 // </synopsis>
95 
96 // <motivation>
97 // Most DisplayData classes will offer more than one view of the data.
98 // Caching is therefore desirable to improve display speed for
99 // re-display of individual views of the data. It is nice to keep the
100 // caching in one place, hence this class.
101 // </motivation>
102 
104 
105  public:
106 
107  // Constructor.
109 
110  // Destructor.
111  virtual ~CachingDisplayData();
112 
113  // Install the default options for this DisplayData.
114  virtual void setDefaultOptions();
115 
116  // Apply options stored in <src>rec</src> to the DisplayData. A
117  // return value of <src>true</src> means a refresh is needed.
118  // <src>recOut</src> contains any fields which were implicitly
119  // changed as a result of the call to this function. The options
120  // handled by this class are:
121  // <li> <src>cachesize</src>: an integer specifying the maximum
122  // number of views which can be stored in the cache. The default
123  // value can be specified by the <src>display.cachesize</src>
124  // variable in the user's <src>.aipsrc</src> file, and in lieu
125  // of that, will be 256. If <src>cachesize</src> is lowered by
126  // a call to this method, the cache will be shrunk in size, with
127  // the oldest drawings being removed first. </li>
129 
130  // Retrieve the current and default options and parameter types.
131  virtual casacore::Record getOptions( bool scrub=false ) const;
132 
133  // Refresh event handler which is called indirectly by the
134  // WorldCanvas, via the WorldCanvasHolder. This function will take
135  // care of calling <src>newDisplayMethod</src> when necessary, and
136  // otherwise using an existing (previously cached) draw list.
137  virtual void refreshEH(const WCRefreshEvent &ev);
138 
139  // <group>
140  virtual void notifyRegister(WorldCanvasHolder *wcHolder) ;
141  virtual void notifyUnregister(WorldCanvasHolder& wcHolder,
142  casacore::Bool ignoreRefresh = false) ;
143  // </group>
144 
145  // Purges cache, to avoid reusing images with the
146  // wrong colormap, then calls base class version.
147  virtual void setColormap(Colormap *cmap, casacore::Float weight);
148 
149  // Empty cache completely.
150  virtual void purgeCache();
151 
152  // Empty cache of all DMs for a given WCH.
153  virtual void purgeCache(const WorldCanvasHolder& wch);
154 
155 
156 
157  protected:
158 
159  // Create a new (Caching)DisplayMethod for drawing on the given
160  // WorldCanvas when the AttributeBuffers are suitably matched to the
161  // current state of this DisplayData and of the WorldCanvas/Holder.
162  virtual CachingDisplayMethod *newDisplayMethod(WorldCanvas *worldCanvas,
163  AttributeBuffer *wchAttributes,
164  AttributeBuffer *ddAttributes,
165  CachingDisplayData *dd) = 0;
166 
167  // Return the current options of this DisplayData as an
168  // AttributeBuffer. The caller must delete the returned buffer.
170 
171  // Return any additional Attributes to consider when searching the
172  // cache. I guess I might put things like Colormap setup in here,
173  // since we need a way to handle the Colormap size being altered,
174  // and later returned to its original size/location in the
175  // PCColorTable, etc.
176  /*
177  virtual AttributeBuffer cachingAttributes();
178  */
179 
180  // Turn caching on/off.
181  virtual void setCaching(const casacore::Bool caching);
182 
183  // (Required) copy constructor.
185 
186  // (Required) copy assignment.
187  void operator=(const CachingDisplayData &other);
188 
189 
190  // The default is false. Derived DDs (such as WedgeDD) can set it true
191  // so that the colormap on the PixelCanvas before the DD draws is
192  // restored to it afterward. The 'colormap fiddling' mouse tools can
193  // (unfortunately) only operate on the PC's current colormap; this
194  // kludge is an attempt to assure that the 'right' one is left there.
196 
197  private:
198 
199  // Caching state.
201 
202  // Default and actual maximum length of element list.
204 
205  // casacore::List containing the CachingDisplayMethods for this
206  // CachingDisplayData.
207  std::list<void *> itsElementList;
208 
209  // Clear out cache entries beyond end of list.
210  void trimCache();
211 
212  // Install the default options for this DisplayData.
213  void installDefaultOptions();
214 
215  };
216 
217 
218 } //# NAMESPACE CASA - END
219 
220 #endif
221 
virtual void setColormap(Colormap *cmap, casacore::Float weight)
Purges cache, to avoid reusing images with the wrong colormap, then calls base class version...
virtual void notifyUnregister(WorldCanvasHolder &wcHolder, casacore::Bool ignoreRefresh=false)
ignoreRefresh tells the DD not to refresh just to clean up DMs
int Int
Definition: aipstype.h:50
Assistance class for auto-caching of DisplayData objects.
virtual casacore::Record getOptions(bool scrub=false) const
Retrieve the current and default options and parameter types.
Class which stores WorldCanvas refresh event information.
virtual void setDefaultOptions()
Install the default options for this DisplayData.
Buffer for storing Attributes.
virtual void notifyRegister(WorldCanvasHolder *wcHolder)
virtual void refreshEH(const WCRefreshEvent &ev)
Refresh event handler which is called indirectly by the WorldCanvas, via the WorldCanvasHolder.
virtual ~CachingDisplayData()
Destructor.
void trimCache()
Clear out cache entries beyond end of list.
virtual CachingDisplayMethod * newDisplayMethod(WorldCanvas *worldCanvas, AttributeBuffer *wchAttributes, AttributeBuffer *ddAttributes, CachingDisplayData *dd)=0
Create a new (Caching)DisplayMethod for drawing on the given WorldCanvas when the AttributeBuffers ar...
Base class for auto-caching DisplayData objects.
casacore::Int itsOptionsMaximumCacheSize
void operator=(const CachingDisplayData &other)
(Required) copy assignment.
casacore::Bool restorePCColormap_
The default is false.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
std::list< void * > itsElementList
casacore::List containing the CachingDisplayMethods for this CachingDisplayData.
float Float
Definition: aipstype.h:54
casacore::Int itsDefaultMaximumCacheSize
Default and actual maximum length of element list.
Describes a method of generating a table of colors.
Definition: Colormap.h:104
A holder to interface between DisplayDatas and a WorldCanvas.
Implementation of drawing in world coordinates on top of a PixelCanvas.
Definition: WorldCanvas.h:204
CachingDisplayData()
Constructor.
void installDefaultOptions()
Install the default options for this DisplayData.
virtual casacore::Bool setOptions(casacore::Record &rec, casacore::Record &recOut)
Apply options stored in rec to the DisplayData.
Base class for display objects.
Definition: DisplayData.h:317
virtual AttributeBuffer optionsAsAttributes()
Return the current options of this DisplayData as an AttributeBuffer.
virtual void purgeCache()
Empty cache completely.
virtual void setCaching(const casacore::Bool caching)
Return any additional Attributes to consider when searching the cache.
casacore::Bool itsCachingState
Caching state.