mdsTriMesh.h

Go to the documentation of this file.
00001 //==============================================================================
00015 #ifndef MDS_TRIMESH_H
00016 #define MDS_TRIMESH_H
00017 
00018 #include "mdsDelaunayTri.h"
00019 #include "mdsTriFeatures.h"
00020 #include "mdsTriSimilarityMeasure.h"
00021 #include "mdsTriHomogeneityMeasure.h"
00022 
00023 // STL
00024 #include <vector>
00025 
00026 
00027 namespace mds
00028 {
00029 namespace seg
00030 {
00031 
00032 //==============================================================================
00036 class CTriMesh : public CDelaunayTri, public CTriBase
00037 {
00038 public:
00041     MDS_SHAREDPTR(CTriMesh);
00042 
00044     MDS_ENTITY_NAME("TriMesh");
00045 
00047     MDS_ENTITY_COMPRESSION(mds::mod::CC_RAW);
00048 
00050     MDS_ENTITY_BLOCK_SIZE(4096);
00051 
00053     typedef std::vector<CTriFeatures> tSegments;
00054 
00056     static const tSize DEFAULT_CELL;
00057     static const tSize DEFAULT_CELL_MARGIN;
00058     static const double DEFAULT_INIT_THRESHOLD;
00059     static const double DEFAULT_SPLITTING_THRESHOLD;
00060     static const double DEFAULT_DISTANCE_THRESHOLD;
00061 
00062 public:
00064     CTriMesh();
00065 
00067     CTriMesh(mds::img::CDImage *pEdgeImage);
00068 
00070     virtual ~CTriMesh();
00071 
00072 
00074     mds::img::CDImage *getImagePtr() { return m_spImage; }
00075 
00077     void setImage(mds::img::CDImage *pImage) { m_spImage = pImage; }
00078 
00080     mds::img::CDImage *getEdgeImagePtr() { return m_spEdgeImage; }
00081 
00083     void setEdgeImage(mds::img::CDImage *pEdgeImage) { m_spEdgeImage = pEdgeImage; }
00084 
00085 
00087     int getNumOfSegments() const { return m_iNumOfSegments; }
00088 
00090     void setNumOfSegments(int i) { m_iNumOfSegments = i; }
00091 
00093     tSegments& getSegments() { return m_Segments; }
00094 
00095 
00100     bool init(double dThreshold = DEFAULT_INIT_THRESHOLD,
00101               tSize CellSize = DEFAULT_CELL,
00102               tSize NumOfNodes = DEFAULT_NUMBER_OF_NODES,
00103               double dMinEdgeLength = DEFAULT_MIN_EDGE_LENGTH
00104               );
00105 
00108     bool evaluateFeatures(bool bSkipSmall = true);
00109 
00113     bool evaluateSegmentFeatures(bool bSkipSmall = true);
00114 
00118     bool edgeSplitting(double dMinLength = DEFAULT_MIN_EDGE_LENGTH,
00119                        double dOrientThreshold = DEFAULT_SPLITTING_THRESHOLD
00120                        );
00121 
00125     bool triangleSplitting(CTriHomogeneityMeasure& Measure,
00126                            double dMinLength = DEFAULT_MIN_EDGE_LENGTH
00127                            );
00128 
00133     bool regionGrowing(CTriSimilarityMeasure& Measure,
00134                        double dBThreshold = DEFAULT_DISTANCE_THRESHOLD
00135                        );
00136 
00140     bool regionMerging(CTriSimilarityMeasure& Measure,
00141                        double dBThreshold = DEFAULT_DISTANCE_THRESHOLD,
00142                        tSize NumOfRegions = -1
00143                        );
00144 
00148     bool classifyAdjacent(double dBThreshold = DEFAULT_DISTANCE_THRESHOLD);
00149 
00154     bool noiseReduction();
00155 
00158     void visualize(mds::img::CDImage *pImage);
00159 
00160 
00164     bool saveSTL(mds::mod::CChannel& Channel);
00165 
00169     bool saveVRML(mds::mod::CChannel& Channel);
00170 
00171 
00173     template <class S>
00174     void serialize(mds::mod::CChannelSerializer<S>& Writer)
00175     {
00176         // Serialize the Delaunay trianglation
00177         CDelaunayTri::serialize(Writer);
00178     }
00179 
00181     template <class S>
00182     void deserialize(mds::mod::CChannelSerializer<S>& Reader)
00183     {
00184         // Deserialize the Delaunay trianglation
00185         CDelaunayTri::deserialize(Reader);
00186 
00187         // Evaluate the number of regions
00188         int iMaxRegion = -1;
00189         vctl::MCTri *pTriangle = getFirstTriangle();
00190         for( ; pTriangle; pTriangle = pTriangle->GetNext() )
00191         {
00192             // Get triangle region
00193             int iRegion = getTriangleRegion(pTriangle);
00194             if( iRegion > iMaxRegion )
00195             {
00196                 iMaxRegion = iRegion;
00197             }
00198         }
00199 
00200         // Set the number of regions
00201         m_iNumOfSegments = iMaxRegion + 1;
00202     }
00203 
00204 protected:
00206     typedef std::vector<vctl::MCPoint3D> tPoints;
00207 
00208 protected:
00210     mds::img::CDImagePtr m_spImage;
00211 
00213     mds::img::CDImagePtr m_spEdgeImage;
00214 
00216     int m_iNumOfSegments;
00217 
00219     tSegments m_Segments;
00220 
00222     CTriHomogeneityMeasure *m_pHomogeneityMeasure;
00223 
00224 protected:
00225 //public:
00228     bool checkBoundaryEdge(vctl::MCEdge *pEdge,
00229                            double dThreshold = DEFAULT_DISTANCE_THRESHOLD
00230                            );
00231 
00234     void reassignRegions();
00235 
00238     bool splitEdge(vctl::MCEdge *pEdge,
00239                    double dMinLength,
00240                    double dThreshold,
00241                    tPoints& Points
00242                    );
00243 
00245     static void edgeSplittingInsertFunc(vctl::MCTri *pTriangle,
00246                                         CDelaunayTri *pMesh
00247                                         );
00248 
00251     bool splitTriangle(vctl::MCTri *pTriangle, double dMinLength);
00252 
00254     static void triangleSplittingInsertFunc(vctl::MCTri *pTriangle,
00255                                             CDelaunayTri *pMesh
00256                                             );
00257 
00259     static void triangleSplittingRemoveFunc(vctl::MCTri *pTriangle,
00260                                             CDelaunayTri *pMesh
00261                                             );
00262 };
00263 
00264 
00265 //=============================================================================
00266 /*
00267  * Basic template instances and type definitions.
00268  * - Using smart pointers.
00269  */
00270 
00272 typedef CTriMesh::tSmartPtr CTriMeshPtr;
00273 
00274 
00275 } // namespace seg
00276 } // namespace mds
00277 
00278 #endif // MDS_TRIMESH_H
00279 

Generated on Thu Mar 11 10:35:45 2010 for MDSTk Extension Libraries by  doxygen 1.4.6-NO