mdsTetraInfo.h

Go to the documentation of this file.
00001 //==============================================================================
00015 #ifndef MDS_TetraInfo_H
00016 #define MDS_TetraInfo_H
00017 
00018 #include "mdsTetraFeatures.h"
00019 #include "mdsTetraMesh.h"
00020 
00021 
00022 namespace mds
00023 {
00024 namespace seg
00025 {
00026 
00027 //==============================================================================
00031 class CWriteTetraInfo
00032 {
00033 public:
00035     enum EFlags
00036     {
00037         INFO                = 1,
00038         NEIGHBOURS          = 2,
00039         FEATURES            = 4,
00040         CHECK_EDGE_FACES    = 8,
00041         DEFAULT_FLAGS       = INFO | NEIGHBOURS | FEATURES,
00042     };
00043 
00044 public:
00046     CWriteTetraInfo(std::ostream& Stream, int Flags = DEFAULT_FLAGS)
00047         : m_Stream(Stream)
00048         , m_Flags(Flags)
00049     {}
00050 
00054     void setMesh(CTetraMesh *pMesh) { m_spMesh = pMesh; }
00055 
00057     void operator ()(vctl::MCTetra& Tetrahedron)
00058     {
00059         m_Stream << Tetrahedron.GetObject() << "\t";
00060 
00061         if( checkFlag(INFO) )
00062         {
00063             vctl::MCPoint3D Center;
00064             Tetrahedron.GetCenter(Center);
00065             m_Stream
00066                 << Center.GetX() << "\t" << Center.GetY() << "\t" << Center.GetZ() << "\t"
00067                 << Tetrahedron.GetVolume() << "\t";
00068         }
00069 
00070         if( checkFlag(NEIGHBOURS) )
00071         {
00072             vctl::MCVertex *pVertices[3];
00073             for( int i = 0; i < 4; ++i )
00074             {
00075                 if( !Tetrahedron.GetNeighbour(i) )
00076                 {
00077                     m_Stream << -1 << "\t";
00078                     continue;
00079                 }
00080 
00081                 Tetrahedron.GetTri(i, pVertices);
00082                 if( checkFlag(CHECK_EDGE_FACES) && m_spMesh.get() )
00083                 {
00084 //                    if( m_spMesh->checkBoundaryTriangle(pVertices[0], pVertices[1], pVertices[2], 0.1) )
00085                     if( m_spMesh->isBoundaryTriangle(pVertices[0], pVertices[1], pVertices[2]) )
00086                     {
00087                         m_Stream << -1 << "\t";
00088                         continue;
00089                     }
00090                 }
00091 
00092                 // Default output
00093                 m_Stream << Tetrahedron.GetNeighbour(i)->GetObject() << "\t";
00094             }
00095         }
00096 
00097         if( checkFlag(FEATURES) )
00098         {
00099             CTetraFeatures *pFeatures = getTetrahedronFeatures(&Tetrahedron);
00100 #ifdef USE_VARIANCE
00101             m_Stream
00102                 << pFeatures->getVoxelMean() << "\t"
00103                 << pFeatures->getVoxelVariance() << "\t"
00104                 << pFeatures->getNumOfVoxels();
00105 #else
00106             m_Stream
00107                 << pFeatures->getVoxelMean() << "\t"
00108                 << pFeatures->getNumOfVoxels();
00109 #endif // USE_VARIANCE
00110         }
00111       
00112         m_Stream << std::endl;
00113     }
00114 
00116     void writeHeading()
00117     {
00118         std::string Info("Id\t");
00119         
00120         if( checkFlag(INFO) )
00121         {
00122             Info += "CX\tCY\tCZ\tVolume\t";
00123         }
00124       
00125         if( checkFlag(NEIGHBOURS) )
00126         {
00127             Info += "N0\tN1\tN2\tN3\t";
00128         }
00129       
00130         if( checkFlag(FEATURES) )
00131         {
00132 #ifdef USE_VARIANCE
00133             Info += "Mean\tVariance\tCount";
00134 #else
00135             Info += "Mean\tCount";
00136 #endif // USE_VARIANCE
00137         }
00138       
00139         m_Stream << Info << std::endl;
00140     }
00141 
00143     bool checkFlag(int Flag) { return (m_Flags & Flag) == Flag; }
00144 
00145 protected:
00147     std::ostream& m_Stream;
00148 
00150     int m_Flags;
00151 
00153     CTetraMesh::tSmartPtr m_spMesh;
00154 };
00155 
00156 
00157 //==============================================================================
00161 class CAssignTetraIndex
00162 {
00163 public:
00165     CAssignTetraIndex(int StartValue = 0) : m_Counter(StartValue) {}
00166 
00168     void operator ()(vctl::MCTetra& Tetrahedron) { Tetrahedron.SetObject(m_Counter++); }
00169 
00170 protected:
00172     int m_Counter;
00173 };
00174 
00175 
00176 } // namespace seg
00177 } // namespace mds
00178 
00179 #endif // MDS_TetraInfo_H

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