@@ -14,6 +14,8 @@ function vtkTextActor(publicAPI, model) {
1414 // Set our className
1515 model . classHierarchy . push ( 'vtkTextActor' ) ;
1616
17+ const superClass = { ...publicAPI } ;
18+
1719 publicAPI . makeProperty = vtkTextProperty . newInstance ;
1820
1921 const texture = vtkTexture . newInstance ( {
@@ -38,7 +40,7 @@ function vtkTextActor(publicAPI, model) {
3840 const backgroundColor = publicAPI . getProperty ( ) . getBackgroundColor ( ) ;
3941
4042 const dpr = Math . max ( window . devicePixelRatio || 1 , 1 ) ;
41- const ctx = canvas . getContext ( '2d' ) ;
43+ const ctx = canvas . getContext ( '2d' , { willReadFrequently : true } ) ;
4244
4345 // Set the text properties to measure
4446 const textSize = fontSizeScale ( resolution ) * dpr ;
@@ -110,21 +112,39 @@ function vtkTextActor(publicAPI, model) {
110112 return ImageHelper . canvasToImageData ( canvas ) ;
111113 }
112114
115+ function updateTexture ( ) {
116+ const image = createImageData ( model . input ) ;
117+ texture . setInputData ( image , 0 ) ;
118+ model . textureBuildTime . modified ( ) ;
119+ }
120+
121+ function updateTextureIfNeeded ( ) {
122+ if ( model . input === undefined ) {
123+ return ;
124+ }
125+
126+ if (
127+ model . textureBuildTime . getMTime ( ) < model . mtime ||
128+ model . textureBuildTime . getMTime ( ) < publicAPI . getProperty ( ) . getMTime ( )
129+ ) {
130+ updateTexture ( ) ;
131+ }
132+ }
133+
113134 mapper . setInputConnection ( plane . getOutputPort ( ) ) ;
114135
115136 publicAPI . setMapper ( mapper ) ;
116137 publicAPI . addTexture ( texture ) ;
117138
118- model . _onInputChanged = ( _publicAPI , _model , value ) => {
119- const image = createImageData ( value ) ;
120- texture . setInputData ( image , 0 ) ;
139+ publicAPI . getTextures = ( ) => {
140+ updateTextureIfNeeded ( ) ;
141+ return superClass . getTextures ( ) ;
121142 } ;
122143}
123144
124145// Default property values
125146const DEFAULT_VALUES = {
126- mapper : null ,
127- property : null ,
147+ textureBuildTime : null ,
128148} ;
129149
130150export function extend ( publicAPI , model , initialValues = { } ) {
@@ -135,6 +155,8 @@ export function extend(publicAPI, model, initialValues = {}) {
135155
136156 // Build VTK API
137157 macro . setGet ( publicAPI , model , [ 'input' ] ) ;
158+ model . textureBuildTime = { } ;
159+ macro . obj ( model . textureBuildTime , { mtime : 0 } ) ;
138160
139161 // Object methods
140162 vtkTextActor ( publicAPI , model ) ;
0 commit comments