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

Barth Netterfield netterfield at astro.utoronto.ca
Wed Nov 29 22:04:20 CET 2006


You forgot bin.h


On Wednesday 29 November 2006 14:45, Adam Treat wrote:
> SVN commit 609208 by treat:
>
> Convert Bin plugin to C++ basic plugin
>
>
>  M  +10 -10    Makefile.am
>  M  +94 -39    bin.cpp
>  D             bin.xml
>  A             kstobject_bin.desktop
>
>
> --- trunk/extragear/graphics/kst/src/plugins/bin/Makefile.am #609207:609208
> @@ -1,11 +1,11 @@
> -installdir=$(kde_moduledir)/kstplugins
> -INCLUDES=-I$(srcdir)/../../kst $(all_includes)
> -
> -install_LTLIBRARIES = bin.la
> -
> -bin_la_LDFLAGS = -module $(KDE_PLUGIN)
> -bin_la_SOURCES = bin.cpp
> -
> +INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/libkst
> -I$(top_srcdir)/kst/src/libkstmath $(all_includes) +
> +kde_module_LTLIBRARIES=kstobject_bin.la
> +
> +kstobject_bin_la_LDFLAGS=$(all_libraries) -module -avoid-version
> +kstobject_bin_la_SOURCES=bin.cpp
> +
> +services_DATA=kstobject_bin.desktop
> +servicesdir=$(kde_servicesdir)/kst
> +
>  METASOURCES=AUTO
> -
> -install_DATA=bin.xml
> --- trunk/extragear/graphics/kst/src/plugins/bin/bin.cpp #609207:609208
> @@ -1,50 +1,105 @@
> -/*
> - *  Bin plugin for KST.
> - *  Copyright 2004, The University of British Columbia
> - *  Released under the terms of the GPL.
> - */
> +/*************************************************************************
>** +                   bin.cpp
> +                             -------------------
> +    begin                : 11/28/06
> +    copyright            : (C) 2006 The University of Toronto
> +    email                :
> +
> ***************************************************************************
>/
>
> -#include <stdlib.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 "bin.h"
>
> -extern "C" int bin(const double *const inArrays[], const int
> inArrayLens[], -                const double is[],
> -                double *outArrays[], int outArrayLens[],
> -                double outScalars[]);
> +#include <kgenericfactory.h>
>
> -int bin(const double *const inArrays[], const int inArrayLens[],
> -                const double is[],
> -                double *outArrays[], int outArrayLens[],
> -                double outScalars[])
> +//in
> +static const QString& INPUT = KGlobal::staticQString("Input Vector");
> +static const QString& SIZE = KGlobal::staticQString("Bin Size");
> +
> +//out
> +static const QString& BINS = KGlobal::staticQString("Bins");
> +
> +KST_KEY_DATAOBJECT_PLUGIN( bin )
> +
> +K_EXPORT_COMPONENT_FACTORY( kstobject_bin,
> +    KGenericFactory<Bin>( "kstobject_bin" ) )
> +
> +Bin::Bin( QObject */*parent*/, const char */*name*/, const QStringList
> &/*args*/ ) +    : KstBasicPlugin() {
> +}
> +
> +
> +Bin::~Bin() {
> +}
> +
> +
>  //Bin the elements into the given size bins, additional elements at the
> end of the //input vector are ignored.
>  //Returns -1 on error, 0 on success.
> -{
> -	//Cast the binsize to an integer if it is not one
> -	int binsize=(int)is[0];
> +bool Bin::algorithm() {
>
> -	//Make sure there is at least 1 element in the input vector
> -	//Make sure the bin size is at least 1
> -	if (inArrayLens[0] < 1 || binsize < 1) {
> -		return -1;
> -	}
> +  KstVectorPtr input    = inputVector(INPUT);
> +  KstScalarPtr size     = inputScalar(SIZE);
> +  KstVectorPtr bins     = outputVector(BINS);
>
> -	//now set the outputs
> -	outArrayLens[0]=(int) (inArrayLens[0] / binsize);
> +  //Make sure there is at least 1 element in the input vector
> +  //Make sure the bin size is at least 1
> +  if (input->length() < 1 || size->value() < 1) {
> +    return -1;
> +  }
>
> -	//resize the output array
> -	outArrays[0]=(double*)realloc(outArrays[0],
> outArrayLens[0]*sizeof(double)); +  // allocate the lengths
> +  bins->resize(int(input->length() / size->value()), false);
>
> -	//now bin the data
> -	for (int i=0; i<outArrayLens[0]; i++)
> -	{
> -		outArrays[0][i]=0;
> -		//add up the elements for this bin
> -		for (int j=0; j<binsize; j++)
> -		{
> -			outArrays[0][i]+=inArrays[0][i*binsize+j];
> -		}
> -		//find the mean
> -		outArrays[0][i]/=binsize;
> -	}
> -	return 0;
> +  //now bin the data
> +  for (int i=0; i<bins->length(); i++)
> +  {
> +      bins->value()[i]=0;
> +      //add up the elements for this bin
> +      for (int j=0; j<size->value(); j++)
> +      {
> +          bins->value()[i]+=input->value()[int(i*size->value()+j)];
> +      }
> +      //find the mean
> +      bins->value()[i]/=size->value();
> +  }
> +  return true;
>  }
> +
> +
> +QStringList Bin::inputVectorList() const {
> +  return QStringList( INPUT );
> +}
> +
> +
> +QStringList Bin::inputScalarList() const {
> +  return QStringList( SIZE );
> +}
> +
> +
> +QStringList Bin::inputStringList() const {
> +  return QStringList();
> +}
> +
> +
> +QStringList Bin::outputVectorList() const {
> +  return QStringList( BINS );
> +}
> +
> +
> +QStringList Bin::outputScalarList() const {
> +  return QStringList();
> +}
> +
> +
> +QStringList Bin::outputStringList() const {
> +  return QStringList();
> +}
> +
> +#include "bin.moc"
> _______________________________________________
> Kst mailing list
> Kst at kde.org
> https://mail.kde.org/mailman/listinfo/kst


More information about the Kst mailing list