/*
* Copyright (C) 2016 Daniel Haley
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "operator.h"
#include "common/basics.h"
//-- operation headers ---
#include "operators/cleanup.h"
#include "operators/cubicGen.h"
#include "operators/fccGen.h"
#include "operators/hcpGen.h"
#include "operators/randGen.h"
#include "operators/genericGen.h"
#include "operators/massOps.h"
#include "operators/pointConc.h"
#include "operators/composition.h"
#include "operators/mathTransform.h"
#include "operators/geomOps.h"
#include "operators/atomProbeOps.h"
#include "operators/dataOps.h"
#include "operators/format.h"
#include "operators/arraySplitter.h"
#include "operators/clusterOps.h"
#include "operators/clusterSweep.h"
#include "operators/noiseOps.h"
#include "operators/profile.h"
#include "operators/proxigram.h"
#include "operators/pointDensity.h"
#include "operators/isosurfaceOp.h"
//----------------------
#include <cstring>
RandNumGen *Operation::randomGen=0;
bool Operation::noProgress=false;
//Each possible operation that can be generated by the factory
// is given in this enum.
enum
{
FACTORY_CLEANOPS=0,
FACTORY_FCC,
FACTORY_HCP,
FACTORY_CUBIC,
FACTORY_SPATRAND,
FACTORY_GENERICRECT,
FACTORY_MASSCLIP,
FACTORY_POINTCONC,
FACTORY_COMPOSITION,
#if defined(HAVE_MATHTRANSFORM)
FACTORY_MATHTRANSFORM,
#endif
FACTORY_GEOTRANSFORM,
FACTORY_CLIP,
FACTORY_POSSET,
FACTORY_RANDRM,
FACTORY_RANDREPLACE,
FACTORY_SURFREMOVE,
FACTORY_EXTRACTFIELD,
FACTORY_RELABEL,
FACTORY_IVASIFY,
FACTORY_FILEFORMAT,
FACTORY_ARRAYSPLIT,
FACTORY_CLUSTER,
FACTORY_CLUSTERSWEEP,
FACTORY_NOISE,
FACTORY_PROFILE,
FACTORY_PROXIGRAM,
FACTORY_POINTDENSITY,
FACTORY_ISOSURFACE,
FACTORY_ENUM_END
};
std::map<string,unsigned int> OperationFactory::opNameToId;
void OperationFactory::init()
{
//Should not have run this before
ASSERT(opNameToId.empty());
for(unsigned int ui=0;ui<getNumOperations();ui++)
{
Operation *op;
op = createByID(ui);
//ID should exist, and tag should be non-empty
ASSERT(op && op->getTagName().size());
//Should not overwrite previous mappings (ie should be unique)
ASSERT(opNameToId.find(op->getTagName()) == opNameToId.end());
opNameToId.insert(make_pair(op->getTagName(), ui));
delete op;
}
}
Operation *OperationFactory::create(const char *strName)
{
//Must have populated map by calling init routines
ASSERT(opNameToId.size());
std::map<string,unsigned int>::const_iterator it;
//See if we can find this operation in our operation list
it = opNameToId.find(string(strName));
if(it!=opNameToId.end())
{
//Operation
Operation *op;
op=createByID(it->second);
ASSERT(op);
ASSERT(strName == op->getTagName());
return op;
}
return 0;
}
Operation *OperationFactory::createByID(unsigned int id)
{
#define FAC_RETURN(f,g) {case f: { return new g(); }}
switch(id)
{
FAC_RETURN(FACTORY_CLEANOPS,CleanOps);
FAC_RETURN(FACTORY_FCC, FCCGen);
FAC_RETURN(FACTORY_HCP, HCPGen);
FAC_RETURN(FACTORY_CUBIC, CubicGen);
FAC_RETURN(FACTORY_SPATRAND, RandGen);
FAC_RETURN(FACTORY_GENERICRECT, GenericRectGen);
FAC_RETURN(FACTORY_MASSCLIP, MassClip);
FAC_RETURN(FACTORY_POINTCONC, PointConc);
FAC_RETURN(FACTORY_COMPOSITION, CompositionOp);
#if defined(HAVE_MATHTRANSFORM)
FAC_RETURN(FACTORY_MATHTRANSFORM, MathTransform);
#endif
FAC_RETURN(FACTORY_GEOTRANSFORM, GeomOps);
FAC_RETURN(FACTORY_CLIP, ClipOps);
FAC_RETURN(FACTORY_POSSET, SetOp);
FAC_RETURN(FACTORY_RANDRM, RmOp);
FAC_RETURN(FACTORY_RANDREPLACE, RandReplaceOp);
FAC_RETURN(FACTORY_SURFREMOVE, SurfHullRemoveOp);
FAC_RETURN(FACTORY_EXTRACTFIELD, ExtractField);
FAC_RETURN(FACTORY_RELABEL, RelabelOp);
FAC_RETURN(FACTORY_IVASIFY, Ivasify);
FAC_RETURN(FACTORY_FILEFORMAT, FileFormat);
FAC_RETURN(FACTORY_ARRAYSPLIT, ArraySplitter);
FAC_RETURN(FACTORY_CLUSTER, ClusterOps);
FAC_RETURN(FACTORY_CLUSTERSWEEP, ClusterSweepOp);
FAC_RETURN(FACTORY_NOISE, NoiseOps);
FAC_RETURN(FACTORY_PROFILE, CompositionProfile);
FAC_RETURN(FACTORY_PROXIGRAM, ProxigramOp);
FAC_RETURN(FACTORY_POINTDENSITY, PointDensity);
FAC_RETURN(FACTORY_ISOSURFACE, IsosurfaceOp);
default:
ASSERT(false);
}
return 0;
}
unsigned int OperationFactory::getNumOperations()
{
return FACTORY_ENUM_END;
}