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

Adam Treat treat at kde.org
Wed Nov 29 22:25:04 CET 2006


SVN commit 609242 by treat:

Convert chop plugin to C++ basic plugin


 M  +7 -7      Makefile.am  
 M  +101 -63   chop.cpp  
 A             chop.h   [License: GPL (v2+)]
 D             chop.xml  
 A             kstobject_chop.desktop  


--- trunk/extragear/graphics/kst/src/plugins/chop/Makefile.am #609241:609242
@@ -1,11 +1,11 @@
-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=chop.la
+kde_module_LTLIBRARIES=kstobject_chop.la
 
-chop_la_LDFLAGS=-module $(KDE_PLUGIN) $(all_libraries)
-chop_la_SOURCES=chop.cpp
+kstobject_chop_la_LDFLAGS=$(all_libraries) -module -avoid-version
+kstobject_chop_la_SOURCES=chop.cpp
 
+services_DATA=kstobject_chop.desktop
+servicesdir=$(kde_servicesdir)/kst
+
 METASOURCES=AUTO
-
-install_DATA=chop.xml
--- trunk/extragear/graphics/kst/src/plugins/chop/chop.cpp #609241:609242
@@ -1,68 +1,106 @@
-/*
- *  Phase plugin for KST.
- *  Copyright 2003, The University of British Columbia
- *  Released under the terms of the GPL.
- *
- */
+/***************************************************************************
+                   chop.cpp
+                             -------------------
+    begin                : 11/29/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 "chop.h"
 
-#define KST_UNUSED(x) if(x){};
+#include <kgenericfactory.h>
 
-extern "C" int chop( 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& ODD = KGlobal::staticQString("Odd Array");
+static const QString& EVEN = KGlobal::staticQString("Even Array");
+static const QString& DIFF = KGlobal::staticQString("Difference Array");
+static const QString& INDEX = KGlobal::staticQString("Index Array");
 
-int chop( const double *const inArrays[], const int inArrayLens[],
-		const double inScalars[],
-		double *outArrays[], int outArrayLens[],
-		double outScalars[] )
-{
-    KST_UNUSED( inScalars )
-    KST_UNUSED( outScalars )
-    
-    double* pResult[4];
-    int iRetVal = -1;
-    int iLength = inArrayLens[0];
-    int iLengthNew = iLength / 2;
-    int i;
-    
-    if( iLength > 1 )
-    {   
-        for( i=0; i<4; i++ )
-        {
-            if( outArrayLens[i] != iLengthNew )
-            {
-                pResult[i] = (double*)realloc( outArrays[i], iLengthNew * sizeof( double ) );
-            }
-            else
-            {
-                pResult[i] = outArrays[i];
-            }
-        }
-        
-        if( pResult[0] != NULL && pResult[1] != NULL && pResult[2] != NULL && pResult[3] != NULL )
-        {	
-            for( i=0; i<4; i++ )
-            {
-                outArrays[i] = pResult[i];
-                outArrayLens[i] = iLengthNew;
-            }
-            
-            for( i=0; i<iLength; i+=2 )
-            {
-                outArrays[0][i/2] = inArrays[0][i+0];
-                outArrays[1][i/2] = inArrays[0][i+1];
-                outArrays[2][i/2] = inArrays[0][i+0] - inArrays[0][i+1];
-                outArrays[3][i/2] = i/2;
-            }
-            
-            iRetVal = 0;
-        }
-    }   
-    
-    return iRetVal;
+KST_KEY_DATAOBJECT_PLUGIN( chop )
+
+K_EXPORT_COMPONENT_FACTORY( kstobject_chop,
+    KGenericFactory<Chop>( "kstobject_chop" ) )
+
+Chop::Chop( QObject */*parent*/, const char */*name*/, const QStringList &/*args*/ )
+    : KstBasicPlugin() {
 }
+
+
+Chop::~Chop() {
+}
+
+
+bool Chop::algorithm() {
+
+  KstVectorPtr array  = inputVector(ARRAY);
+
+  KstVectorPtr odd    = outputVector(ODD);
+  KstVectorPtr even   = outputVector(EVEN);
+  KstVectorPtr diff   = outputVector(DIFF);
+  KstVectorPtr index  = outputVector(INDEX);
+
+  QValueList<KstVectorPtr> outputs;
+  outputs << odd << even << diff << index;
+
+  int iLength = array->length();
+  int iLengthNew = (int)ceil(iLength / 2.0);
+
+  if (iLength > 1) {
+
+    QValueList<KstVectorPtr>::iterator it = outputs.begin();
+    for(; it != outputs.end(); ++it) {
+      if ((*it)->length() != iLengthNew) {
+        (*it)->resize(iLengthNew, false);
+      }
+    }
+
+    for (int i = 0; i < iLength; i+=2) {
+      odd->value()[i/2] = array->value()[i];
+      even->value()[i/2] = array->value()[i+1];
+      diff->value()[i/2] = array->value()[i] - array->value()[i+1];
+      index->value()[i/2] = i/2;
+    }
+  }
+
+  return true;
+}
+
+
+QStringList Chop::inputVectorList() const {
+  return QStringList( ARRAY );
+}
+
+
+QStringList Chop::inputScalarList() const {
+  return QStringList();
+}
+
+
+QStringList Chop::inputStringList() const {
+  return QStringList();
+}
+
+
+QStringList Chop::outputVectorList() const {
+  return QStringList( ODD ) << EVEN << DIFF << INDEX;
+}
+
+
+QStringList Chop::outputScalarList() const {
+  return QStringList();
+}
+
+
+QStringList Chop::outputStringList() const {
+  return QStringList();
+}
+
+#include "chop.moc"


More information about the Kst mailing list