8 #define isNan(a) (a!=a)
34 for (
int ii = 0; ii <
values.size(); ii++ )
43 if ( db_access )
return load_db ( guid, db );
52 q <<
"get_noise_info" << id;
58 QByteArray contents = db->
value( 5 ).toString().toAscii();
60 QXmlStreamReader xml( contents );
68 QFile file( filename );
70 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
72 qDebug() <<
"Cannot open file for reading: " << filename;
76 QXmlStreamReader xml( &file );
84 QXmlStreamAttributes a;
85 bool read_next =
true;
88 while ( ! xml.atEnd() )
90 if ( read_next ) xml.readNext();
93 if ( xml.isStartElement() )
95 if ( xml.name() ==
"noise" )
99 typen = a.value(
"type" ).toString();
100 type = typen.compare(
"ti" ) == 0 ?
TI :
RI;
103 noiseGUID = a.value(
"noiseGUID" ).toString();
104 modelGUID = a.value(
"modelGUID" ).toString();
105 minradius = a.value(
"minradius" ).toString().toDouble();
106 maxradius = a.value(
"maxradius" ).toString().toDouble();
110 else if ( xml.name() ==
"d" )
112 a = xml.attributes();
114 values << a.value(
"v" ).toString().toDouble();
130 if ( db_access )
return write( db );
131 else return write( filename );
138 QByteArray temp_contents;
139 QXmlStreamWriter xml( &temp_contents );
146 QString typen = (
type ==
TI ) ?
"ti_noise" :
"ri_noise";
151 QString modelID = db->
value( 0 ).toString();
158 QString editID =
"0";
160 q <<
"get_model_desc" << invID;
164 if ( db->
value( 0 ).toString() == modelID )
166 editID = db->
value( 6 ).toString();
184 q <<
"new_noise" << noiseGUID << editID << modelID << modelGUID
186 message = QObject::tr(
"created" );
192 QString noiseID = db->
value( 0 ).toString();
193 q <<
"update_noise" << noiseID << noiseGUID << editID << modelID
195 message = QObject::tr(
"updated" );
208 QFile file( filename );
210 if ( ! file.open( QIODevice::WriteOnly | QIODevice::Text) )
213 QXmlStreamWriter xml( &file );
228 double applyf =
remove ? -1.0 : 1.0;
233 message = QObject::tr(
"No noise applied, since its count is zero" );
240 if (
count != rCount )
242 message = QObject::tr(
"Noise count does not equal data readings count" );
246 for ( jj = 0; jj < rCount; jj++ )
248 vnoise = (
values[ jj ] * applyf );
250 for ( ii = 0; ii < sCount; ii++ )
252 editdata.
scanData[ ii ].rvalues[ jj ] += vnoise;
260 if (
count != sCount )
262 message = QObject::tr(
"Noise count does not equal data scan count" );
266 for ( ii = 0; ii < sCount; ii++ )
268 vnoise = (
values[ ii ] * applyf );
270 for ( jj = 0; jj < rCount; jj++ )
272 editdata.
scanData[ ii ].rvalues[ jj ] += vnoise;
301 if ( ! dir.exists( path ) )
303 if ( ! dir.mkpath( path ) )
321 message = QObject::tr (
"Could not create noises directory" );
326 QStringList filter(
"N*.xml" );
327 QStringList names = f.entryList( filter, QDir::Files, QDir::Name );
331 for (
int ii = 0; ii < names.size(); ii++ )
333 filename = path +
"/" + names[ ii ];
334 QFile file( filename );
336 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
continue;
338 QXmlStreamReader xml( &file );
340 while ( ! xml.atEnd() )
344 if ( xml.isStartElement() )
346 if ( xml.name() ==
"noise" )
348 QXmlStreamAttributes a = xml.attributes();
350 if ( a.value(
"noiseGUID" ).toString() == guid ) found =
true;
358 if ( found )
return load( filename );
361 qDebug() <<
"Could not find noise GUID";
362 message = QObject::tr (
"Could not find noise guid" );
371 q <<
"get_noiseID" << guid;
377 QString
id = db->
value( 0 ).toString();
378 return load(
id, db );
384 QString typen(
"ti" );
387 typen = QString(
"ri" );
391 xml.setAutoFormatting(
true );
393 xml.writeStartDocument();
394 xml.writeDTD (
"<!DOCTYPE US_Noise>" );
395 xml.writeStartElement(
"NoiseData" );
396 xml.writeAttribute (
"version",
"1.0" );
398 xml.writeStartElement(
"noise" );
399 xml.writeAttribute (
"type", typen );
401 xml.writeAttribute (
"modelGUID",
modelGUID );
402 xml.writeAttribute (
"noiseGUID",
noiseGUID );
406 xml.writeAttribute (
"minradius", QString::number(
minradius ) );
407 xml.writeAttribute (
"maxradius", QString::number(
maxradius ) );
411 for (
int ii = 0; ii <
values.size(); ii++ )
413 xml.writeStartElement(
"d" );
415 xml.writeAttribute(
"v", QString::number(
values[ ii ] ) );
417 xml.writeEndElement();
420 xml.writeEndElement();
421 xml.writeEndElement();
422 xml.writeEndDocument();
429 QString typen(
"no" );
430 typen = (
type ==
RI ) ? QString(
"RI" ) : typen;
431 typen = (
type ==
TI ) ? QString(
"TI" ) : typen;
433 qDebug() <<
"type" << (int)
type << typen;
437 qDebug() <<
"values size" <<
values.size();
439 for (
int ii = 0; ii <
values.size(); ii++ )
441 qDebug() <<
" v[" << ii <<
"]" <<
values[ ii ];
459 (
type ==
TI && ( difflo > 0.0001 || diffhi > 0.0001 ) ) )
462 qDebug() <<
"SM-NOI: difflo diffhi" << difflo << diffhi;
468 for (
int ii = 0; ii <
values.size(); ii++ )
472 qDebug() <<
"SM-NOI: ii" << ii <<
"noi o i" <<
values[ii] << noise2.
values[ii];
476 else if ( always_sum )
483 for (
int ii = 0; ii < mcount; ii++ )
490 qDebug() <<
"SM-NOI: *NTRP* count count2" <<
count << noise2.
count
496 int limk2 = noise2.
count - 1;
497 double radin2 = ( noise2.
maxradius - radlo2 ) / (
double)( limk2 );
499 for (
int ii = 0; ii <
count; ii++ )
502 double xrad2 = ( radval - radlo2 ) / radin2;
506 double fac1 = (double)j2 - xrad2;
507 double fac2 = 1.0 - fac1;
508 double val1 = ( j1 < 0 ) ? noise2.
values[ 0 ] :
509 ( ( j1 > limk2 ) ? noise2.
values[ limk2 ] :
511 double val2 = ( j2 < 0 ) ? noise2.
values[ 0 ] :
512 ( ( j2 > limk2 ) ? noise2.
values[ limk2 ] :
515 values[ ii ] += ( val1 * fac1 + val2 * fac2 );
531 return noise1.
sum_noise( noise2, always_sum );