1313
1414#include "TextureProperties.h"
1515#include "IFEM.h"
16+ #include "Functions.h"
1617#include "HDF5Reader.h"
1718#include "ProcessAdm.h"
1819#include "Utilities.h"
@@ -33,8 +34,11 @@ void TextureProperties::parse(const TiXmlElement* elem)
3334 continue ;
3435 }
3536
36- std ::string textureFile ;
37+ std ::string textureFile , function ;
3738 utl ::getAttribute (child , "file" , textureFile );
39+ utl ::getAttribute (child , "function" , function );
40+ int comp = 1 ;
41+ utl ::getAttribute (child ,"comp" ,comp );
3842
3943 if (textureFile .find (".h5" ) != std ::string ::npos ||
4044 textureFile .find (".hdf5" ) != std ::string ::npos ) {
@@ -73,6 +77,17 @@ void TextureProperties::parse(const TiXmlElement* elem)
7377 }
7478
7579 properties [prop ].textureData .resize (nx ,ny ,nz );
80+ if (!function .empty ()) {
81+ properties [prop ].func_definition = function ;
82+ FunctionBase * func ;
83+ if (comp == 1 )
84+ func = utl ::parseRealFunc (function .c_str ());
85+ else
86+ func = utl ::parseVecFunc (function .c_str ());
87+
88+ properties [prop ].function .reset (func );
89+ }
90+
7691 const unsigned char * data = image ;
7792 for (int i = 1 ; i <= nx ; ++ i )
7893 for (int j = 1 ; j <= ny ; ++ j )
@@ -89,10 +104,13 @@ void TextureProperties::parse(const TiXmlElement* elem)
89104
90105void TextureProperties ::printLog () const
91106{
92- for (const auto& prop : properties )
107+ for (const auto& prop : properties ) {
93108 IFEM ::cout << "\n \t \tProperty with name " << prop.first
94109 << " (min = " << prop .second .min
95110 << ", max = " << prop .second .max << ")" ;
111+ if (!prop .second .func_definition .empty ())
112+ IFEM ::cout << "\n\t\t\tfunction = " << prop .second .func_definition ;
113+ }
96114}
97115
98116
@@ -104,19 +122,33 @@ bool TextureProperties::getProperty(const std::string& name,
104122 return false;
105123
106124 const Property & prop = it -> second ;
125+ val = this -> getValue (prop , X );
107126
108- const Vec4 * X4 = static_cast < const Vec4 * > (& X );
109- if (!X4 )
127+ if (prop .function ) {
128+ Vec3 f ;
129+ f .x = val ;
130+ val = prop .function -> getValue (f ).front ();
131+ }
132+
133+ return true;
134+ }
135+
136+ bool TextureProperties ::getProperty (const std ::string & name ,
137+ const Vec3 & X , Vec3 & val ) const
138+ {
139+ auto it = properties .find (name );
140+ if (it == properties .end ())
110141 return false;
111142
112- int i = std ::round (X4 -> u [0 ]* (prop .textureData .dim (1 )- 1 ));
113- int j = std ::round (X4 -> u [1 ]* (prop .textureData .dim (2 )- 1 ));
114- int k = std ::round (X4 -> u [2 ]* (prop .textureData .dim (3 )- 1 ));
143+ const Property & prop = it -> second ;
144+ double value = this -> getValue (prop , X );
115145
116- if (prop .prescaled )
117- val = prop .textureData (i + 1 ,j + 1 ,k + 1 );
118- else
119- val = prop .min + (prop .max - prop .min ) * prop .textureData (i + 1 ,j + 1 ,k + 1 );
146+ if (prop .function ) {
147+ Vec3 f ;
148+ f .x = value ;
149+ val = prop .function -> getValue (f );
150+ } else
151+ val = value ;
120152
121153 return true;
122154}
@@ -126,3 +158,21 @@ bool TextureProperties::hasProperty(const std::string& name) const
126158{
127159 return properties .find (name ) != properties .end ();
128160}
161+
162+
163+ double TextureProperties ::getValue (const Property & prop , const Vec3 & X ) const
164+ {
165+ const Vec4 * X4 = static_cast < const Vec4 * > (& X );
166+ if (!X4 )
167+ return false;
168+
169+ int i = std ::round (X4 -> u [0 ]* (prop .textureData .dim (1 )- 1 ));
170+ int j = std ::round (X4 -> u [1 ]* (prop .textureData .dim (2 )- 1 ));
171+ int k = std ::round (X4 -> u [2 ]* (prop .textureData .dim (3 )- 1 ));
172+
173+ if (prop .prescaled )
174+ return prop .textureData (i + 1 ,j + 1 ,k + 1 );
175+ else
176+ return prop .min + (prop .max - prop .min ) * prop .textureData (i + 1 ,j + 1 ,k + 1 );
177+
178+ }
0 commit comments