RDCode: Feature.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories

# Feature.h

Go to the documentation of this file.

    00001 //
    00002 //  Copyright (C) 2004-2006 Rational Discovery LLC
    00003 //
    00004 //   @@ All Rights Reserved  @@
    00005 //
    00006 #ifndef __FEATURE_H_30112004_1121__
    00007 #define __FEATURE_H_30112004_1121__
    00008
    00009 #include <vector>
    00010 #include <Geometry/point.h>
    00011
    00012 namespace RDFeatures {
    00013   template <typename FAMILYMARKER, typename TYPEMARKER=FAMILYMARKER, typename LOCTYPE=RDGeom::Point3D>
    00014   class ExplicitFeature {
    00015   public:
    00016     ExplicitFeature() {};
    00017     explicit ExplicitFeature(const FAMILYMARKER &f,const TYPEMARKER &t) :
    00018       d_family(f), d_type(t) {};
    00019     ExplicitFeature(const FAMILYMARKER &f,const TYPEMARKER &t,const LOCTYPE &loc) :
    00020       d_family(f), d_type(t), d_loc(loc){};
    00021
    00022     const FAMILYMARKER &getFamily() const { return d_family; };
    00023     void setFamily(const FAMILYMARKER &f)  { d_family=f; };
    00024
    00025     const TYPEMARKER &getType() const { return d_type; };
    00026     void setType(const TYPEMARKER &t)  { d_type=t; };
    00027
    00028     const LOCTYPE &getLoc() const { return d_loc; };
    00029     void setLoc(const LOCTYPE &loc) { d_loc=loc; };
    00030
    00031     const std::vector<LOCTYPE> &getDirs() const { return d_dirs; };
    00032     std::vector<LOCTYPE> &getDirs() { return d_dirs; };
    00033
    00034   private:
    00035     FAMILYMARKER d_family;
    00036     TYPEMARKER d_type;
    00037     LOCTYPE d_loc;
    00038     std::vector<LOCTYPE> d_dirs;
    00039   };
    00040
    00041
    00042   template <typename FAMILYMARKER, typename TYPEMARKER=FAMILYMARKER, typename LOCTYPE=RDGeom::Point3D>
    00043   class ImplicitFeature {
    00044   public:
    00045     ImplicitFeature() : d_weightSum(0.0) {};
    00046     explicit ImplicitFeature(const FAMILYMARKER &f,const TYPEMARKER &t) :
    00047       d_weightSum(0.0), d_family(f), d_type(t) {};
    00048
    00049     const FAMILYMARKER &getFamily() const { return d_family; };
    00050     void setFamily(const FAMILYMARKER &f)  { d_family=f; };
    00051
    00052     const TYPEMARKER &getType() const { return d_type; };
    00053     void setType(const TYPEMARKER &t)  { d_type=t; };
    00054
    00055     LOCTYPE getLoc() const {
    00056       PRECONDITION(d_weights.size()==d_locs.size(),"weight/locs mismatch");
    00057       LOCTYPE accum;
    00058       for(unsigned int i=0;i<d_weights.size();i++){
    00059         LOCTYPE tmp=*d_locs[i];
    00060         tmp *= d_weights[i]/d_weightSum;
    00061         accum += tmp;
    00062       }
    00063       return accum;
    00064     };
    00065     void addPoint(const LOCTYPE *p,double weight=1.0){
    00066       d_locs.push_back(p);
    00067       d_weights.push_back(weight);
    00068       d_weightSum += weight;
    00069     }
    00070     void reset() {
    00071       d_locs.clear();
    00072       d_weights.clear();
    00073       d_weightSum=0.0;
    00074     }
    00075
    00076     const std::vector<LOCTYPE> &getDirs() const { return d_dirs; };
    00077     std::vector<LOCTYPE> &getDirs() { return d_dirs; };
    00078
    00079
    00080   private:
    00081     double d_weightSum;
    00082     FAMILYMARKER d_family;
    00083     TYPEMARKER d_type;
    00084     std::vector<double>  d_weights;
    00085     std::vector<const LOCTYPE *> d_locs;
    00086     // FIX: add something correct for directions
    00087     std::vector<LOCTYPE> d_dirs;
    00088   };
    00089 }
    00090 #endif