[Kst] extragear/graphics/kst/src/plugins/noise_addition

Adam Treat treat at kde.org
Thu Dec 7 22:33:35 CET 2006


SVN commit 611375 by treat:

* Convert another plugin...


 M  +8 -8      Makefile.am  
 A             kstobject_noise_addition.desktop  
 M  +89 -42    noise_addition.cpp  
 A             noise_addition.h   [License: GPL (v2+)]


--- trunk/extragear/graphics/kst/src/plugins/noise_addition/Makefile.am #611374:611375
@@ -1,12 +1,12 @@
-installdir=$(kde_moduledir)/kstplugins
-INCLUDES=-I$(srcdir)/../../../kst $(all_includes)
+INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstmath $(all_includes)
 
-install_LTLIBRARIES=noise_addition.la
+kde_module_LTLIBRARIES=kstobject_noise_addition.la
 
-noise_addition_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
-noise_addition_la_LIBADD = $(GSL_LIBS)
-noise_addition_la_SOURCES = noise_addition.cpp
+kstobject_noise_addition_la_LDFLAGS=$(all_libraries) -module -avoid-version
+kstobject_noise_addition_la_SOURCES=noise_addition.cpp
+kstobject_noise_addition_la_LIBADD = $(GSL_LIBS)
 
+services_DATA=kstobject_noise_addition.desktop
+servicesdir=$(kde_servicesdir)/kst
+
 METASOURCES=AUTO
-
-install_DATA=noise_addition.xml
--- trunk/extragear/graphics/kst/src/plugins/noise_addition/noise_addition.cpp #611374:611375
@@ -1,62 +1,109 @@
-/*
- *  Noise addition plugin for KST.
- *  Copyright 2003, The University of British Columbia
- *  Released under the terms of the GPL.
- *
- */
+/***************************************************************************
+                   noise_addition.cpp
+                             -------------------
+    begin                : 12/07/06
+    copyright            : (C) 2006 The University of Toronto
+    email                :
+ ***************************************************************************/
 
-#include <stdlib.h>
-#include <math.h>
-#include <string.h>
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#include "noise_addition.h"
+
 #include <gsl/gsl_rng.h>
 #include <gsl/gsl_randist.h>
 
-#define KST_UNUSED(x) if(x){};
+#include <kgenericfactory.h>
 
-extern "C" int noise_addition( 
-    const double *const inArrays[], const int inArrayLens[],
-		const double inScalars[],
-		double *outArrays[], int outArrayLens[],
-		double outScalars[] );
+static const QString& ARRAY = KGlobal::staticQString("Array");
+static const QString& SIGMA = KGlobal::staticQString("Sigma");
+static const QString& OUTPUT = KGlobal::staticQString("Output Array");
 
-int noise_addition( 
-    const double *const inArrays[], const int inArrayLens[],
-		const double inScalars[],
-		double *outArrays[], int outArrayLens[],
-		double outScalars[] )
-{
-  KST_UNUSED( outScalars )
-   
+KST_KEY_DATAOBJECT_PLUGIN( noise_addition )
+
+K_EXPORT_COMPONENT_FACTORY( kstobject_noise_addition,
+    KGenericFactory<NoiseAddition>( "kstobject_noise_addition" ) )
+
+NoiseAddition::NoiseAddition( QObject */*parent*/, const char */*name*/, const QStringList &/*args*/ )
+    : KstBasicPlugin() {
+}
+
+
+NoiseAddition::~NoiseAddition() {
+}
+
+
+bool NoiseAddition::algorithm() {
+
+  KstVectorPtr array    = inputVector(ARRAY);
+  KstScalarPtr sigma    = inputScalar(SIGMA);
+  KstVectorPtr output   = outputVector(OUTPUT);
+
   const gsl_rng_type* pGeneratorType;
   gsl_rng* pRandomNumberGenerator;
   double* pResult[1];
-  int iRetVal = -1;
-  int iLength = inArrayLens[0];
-  int i;
-  
-  if( iLength > 0 ) {   
-    if( outArrayLens[0] != iLength ) {
-      pResult[0] = (double*)realloc( outArrays[0], iLength * sizeof( double ) );
+  int iRetVal = false;
+  int iLength = array->length();
+
+  if (iLength > 0) {
+    if (output->length() != iLength) {
+      output->resize(iLength, false);
+      pResult[0] = (double*)realloc( output->value(), iLength * sizeof( double ) );
     } else {
-      pResult[0] = outArrays[0];
+      pResult[0] = output->value();
     }
   }
-  
+
   pGeneratorType = gsl_rng_default;
   pRandomNumberGenerator = gsl_rng_alloc( pGeneratorType );
-  if( pRandomNumberGenerator != NULL ) {
-    if( pResult[0] != NULL ) {	
-      outArrays[0] = pResult[0];
-      outArrayLens[0] = iLength;
-      
-      for( i=0; i<iLength; i++ ) {
-        outArrays[0][i] = inArrays[0][i] + gsl_ran_gaussian( pRandomNumberGenerator, inScalars[0] );
+  if (pRandomNumberGenerator != NULL) {
+    if (pResult[0] != NULL) {
+      for (int i=0; i<iLength; i++) {
+        output->value()[i] = array->value()[i] + gsl_ran_gaussian( pRandomNumberGenerator, sigma->value() );
       }
-            
-      iRetVal = 0;
+
+      iRetVal = true;
     }
     gsl_rng_free( pRandomNumberGenerator );
   }
-  
+
   return iRetVal;
 }
+
+
+QStringList NoiseAddition::inputVectorList() const {
+  return QStringList( ARRAY );
+}
+
+
+QStringList NoiseAddition::inputScalarList() const {
+  return QStringList( SIGMA );
+}
+
+
+QStringList NoiseAddition::inputStringList() const {
+  return QStringList();
+}
+
+
+QStringList NoiseAddition::outputVectorList() const {
+  return QStringList( OUTPUT );
+}
+
+
+QStringList NoiseAddition::outputScalarList() const {
+  return QStringList();
+}
+
+
+QStringList NoiseAddition::outputStringList() const {
+  return QStringList();
+}
+
+#include "noise_addition.moc"


More information about the Kst mailing list