00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __SEGMENTATION_H__
00019 #define __SEGMENTATION_H__
00020
00021 #include <fstream>
00022 #include <string>
00023 #include <exception>
00024 #include <vector>
00025 #include <map>
00026 #include <string>
00027
00028 #ifdef USE_QT4
00029 #include <QtCore/QtCore>
00030 #endif
00031 #include <boost/shared_ptr.hpp>
00032
00033 #include "../mesh/mesh_sequence.h"
00034 #include "cluster.h"
00035
00036 #ifndef USE_QT4
00037 #define Q_DECLARE_METATYPE(XXX)
00038 #endif
00039
00044 #define ISEGMENTATION(SEG) \
00045 inline boost::shared_ptr<SegmentationNS::Segmentation> \
00046 Make##SEG(MeshNS::MeshSequencePtr dm, int nbCluster) { return SegmentationNS::SegmentationPtr(new SegmentationNS::SEG(dm,nbCluster)); } \
00047 Q_DECLARE_METATYPE(SegmentationNS::SEG) \
00048 Q_DECLARE_METATYPE(boost::shared_ptr<SegmentationNS::SEG>) \
00049
00050
00051 #define QTVARIANTTYPE(SEG) \
00052 Q_DECLARE_METATYPE(SegmentationNS::SEG) \
00053 Q_DECLARE_METATYPE(boost::shared_ptr<SegmentationNS::SEG>)
00054
00060 #define REGISTERSEG(SEG, STRING, CLUSTER) \
00061 SegmentationNS::RegisterInstanciator<SegmentationNS::NewSegmentation>(STRING, Make##SEG); \
00062 SegmentationNS::RegisterSegmentation<std::string>(STRING, CLUSTER);
00063
00064
00065 namespace SegmentationNS {
00066
00081 class Segmentation {
00082
00083 public:
00084 enum SegType {
00085 TIME, GEOMETRIC, STABLE
00086 };
00087
00088 Segmentation(const std::string& name="", SegType segtype= STABLE, MeshNS::MeshSequencePtr mesh=MeshNS::MeshSequencePtr(),
00089 int nbCluster= -1) :
00090 _name(name), _segType(segtype), _dmesh(mesh), _nbClusters(nbCluster), _nbRequestedClusters(
00091 nbCluster) {
00092 }
00093
00094 void draw(MeshNS::RenderMode _renderMode, int frame) const;
00095
00096
00097 inline void setNbCluster(int nbClusters) {
00098 _nbClusters= _nbRequestedClusters= nbClusters;
00099 }
00100
00103 virtual void addCluster(const Cluster& cluster) {
00104 _clusters.push_back(cluster);
00105 }
00106
00107 virtual void push_back(const Cluster& cluster) {
00108 addCluster(cluster);
00109 }
00110
00114 virtual void segment() {
00115 }
00116
00117 inline int getNbCluster() const {
00118 return _clusters.size();
00119 }
00120
00121 inline int getNbRequestedCluster() const {
00122 return _nbRequestedClusters;
00123 }
00124
00125 inline int getClusterType() const {
00126 return _clusters[0]._type;
00127 }
00128
00129 inline MeshNS::MeshSequencePtr getMeshSequence() {
00130 return _dmesh;
00131 }
00132
00133 inline const MeshNS::MeshSequencePtr getMeshSequence() const {
00134 return _dmesh;
00135 }
00136
00137 Cluster& getCluster(int index) {
00138 return _clusters[index];
00139 }
00140
00141 const Cluster& getCluster(int index) const {
00142 return _clusters[index];
00143 }
00144
00145 std::vector<Cluster>& getClusters() {
00146 return _clusters;
00147 }
00148
00149 const std::vector<Cluster>& getClusters() const {
00150 return _clusters;
00151 }
00152
00153 void setMesh(MeshNS::MeshSequencePtr m) {
00154 _dmesh= m;
00155 for (unsigned int i= 0; i < _clusters.size(); ++i) {
00156 _clusters[i].setMesh(m);
00157 _clusters[i].close();
00158 }
00159 }
00160
00161 std::string getName() const {
00162 return _name;
00163 }
00164
00168 bool operator==(const Segmentation::Segmentation& seg) {
00169 if (_dmesh != seg._dmesh)
00170 return false;
00171 if (_clusters.size() != seg._clusters.size())
00172 return false;
00173 return true;
00174 }
00175
00176 virtual ~Segmentation() {
00177 }
00178
00179 SegType getSegmentationType() const {
00180 return _segType;
00181 }
00182
00183 protected:
00184 std::string _name;
00185 SegType _segType;
00186 MeshNS::MeshSequencePtr _dmesh;
00187 int _nbClusters;
00188 int _nbRequestedClusters;
00189 std::vector<Cluster> _clusters;
00190
00191 };
00192
00193 typedef boost::shared_ptr<Segmentation> SegmentationPtr;
00194 typedef std::map<std::string, Cluster::ClusterType> SegRegister;
00195 typedef SegmentationNS::SegmentationPtr (*NewSegmentation)(MeshNS::MeshSequencePtr dm, int nbCluster);
00196 template<class T> void RegisterSegmentation(const std::string &str,
00197 Cluster::ClusterType type);
00198 template<class T> SegRegister GetRegisteredSegmentation();
00199 template<class T> void RegisterInstanciator(const std::string& str,
00200 NewSegmentation create);
00201 template<class T> T GetRegisteredInstanciator(const std::string& str);
00202
00203 }
00204
00205 #ifdef USE_QT4
00206 Q_DECLARE_METATYPE(SegmentationNS::Segmentation)
00207 Q_DECLARE_METATYPE(boost::shared_ptr<SegmentationNS::Segmentation>)
00208 #endif
00209
00210 #endif