MapExtractorInterface.h

Go to the documentation of this file.
00001 #ifndef __MAPEXTRACTORINTERFACE_H
00002 #define __MAPEXTRACTORINTERFACE_H
00003 
00004 #include <QtGui/QComboBox>
00005 
00006 #if defined(JAMBUILD)
00007 #include <Mudbox/mudbox.h>
00008 #else
00009 #include "../../include/Mudbox/mudbox.h"
00010 #endif
00011 
00012 class TextureExtractionDialog;
00013 class Mapper;
00014 
00015 namespace mapextractionmodules
00016 {
00017 
00018 #ifndef COMPILING_MAPEXTRACTOR_DLL
00019 #define MEDLL MUDBOX_DLLIMPORT
00020 #else
00021 #define MEDLL MUDBOX_DLLEXPORT
00022 #endif
00023 
00063 class MEDLL MapExtractor : public mudbox::TreeNode
00064 {
00065     DECLARE_CLASS;
00066     
00068     virtual void SetTargetCount( int iTargetCount );
00070     virtual void SetTarget( 
00071         int iTargetIndex, 
00072         mudbox::SubdivisionLevel *pTarget 
00073         );
00074     
00076     virtual int TargetCount( void ) const;
00078     virtual mudbox::SubdivisionLevel *TargetMesh( int iMeshIndex ) const;
00080     virtual int CurrentTarget( void ) const;
00081     
00083     virtual unsigned int SourceCount( void ) const;
00085     virtual mudbox::SubdivisionLevel *Source( unsigned int iIndex ) const;
00087     virtual void SetSourceCount( unsigned int iMeshCount );
00089     virtual void SetSource( unsigned int iIndex, mudbox::SubdivisionLevel *pSource );
00090     
00092     virtual int ComponentCount( void ) const;
00094     virtual class Component *ComponentByIndex( int iIndex ) const;
00096     virtual class Component *ComponentByName( const QString &sComponentName ) const;
00098     virtual class Component *ComponentByClassName( const QString &sClassName ) const;
00099 
00101     virtual unsigned int LocationCount( void ) const;
00103     virtual void TargetLocation( unsigned int iIndex, class TargetLocation *pLocation ) const;
00105     virtual void SourceLocation( unsigned int iIndex, mudbox::SurfacePoint *pLocation ) const;
00106     
00108     virtual bool SourceSmoothing( void ) const;
00110     virtual bool TargetUVSmoothing( void ) const;
00112     virtual bool TargetSmoothing( void ) const;
00114     virtual void SetSmoothing( bool bTargetSmoothing, bool bSourceSmoothing, bool bTargetUVSmoothing = false );
00116     virtual bool SourceCreases( void ) const;
00118     virtual void SetSourceCreases( bool bOn );
00120     virtual void AddProgress( int iProgress );
00121     
00123     virtual void SetMapWidth( int iWidth );
00125     virtual void SetMapHeight( int iHeight );
00127     virtual class Layout *Layout() const;    
00129     virtual class Locator *GetLocator() const;
00130 
00133     virtual void SetTangentGenerator( mudbox::TangentGenerator *pGenerator );
00134     
00139     virtual void SetUtilizerType( const mudbox::ClassDesc *pUtilizerType );
00141     virtual void SetLocatorType( const mudbox::ClassDesc *pLocatorType );
00142     
00144     virtual bool Execute( 
00145         bool bInterface = true 
00146         );
00148     virtual bool SilentMode( void ) const;
00149 
00151     virtual void ValidityChanged( void );
00152 };
00153 
00154 //------------------------------------------------------------------------------
00158 class Data
00159 {
00160     private:
00161         union {
00162             int                     m_int[16];
00163             float                   m_float[16];
00164             double                  m_double[8];
00165             // we cant put classes with copy ctors or assignment operators in a union...
00166         };
00167 
00168     public:
00169         Data(int                       r) { m_int[0]    = r; } 
00170         Data(float                     r) { m_float[0]  = r; } 
00171         Data(double                    r) { m_double[0] = r; } 
00172         Data(const mudbox::Color      &r) { m_float[0]  = r.m_fRed;  m_float[1] = r.m_fGreen; 
00173                                             m_float[2]  = r.m_fBlue; m_float[3] = r.m_fAlpha; } 
00174         Data(const mudbox::Vector     &r) { m_float[0]  = r.x; m_float[1]  = r.y; m_float[2]  = r.z; m_float[3]  = 0; } 
00175         Data(const mudbox::DblVector  &r) { m_double[0] = r.x; m_double[1] = r.y; m_double[2] = r.z; m_double[3] = 0; }
00176         Data(const mudbox::Vector4    &r) { m_float[0]  = r.x; m_float[1]  = r.y; 
00177                                             m_float[2]  = r.z; m_float[3]  = r.w; } 
00178         Data(const mudbox::Quaternion &r) { memcpy(m_float, &r.m_fW, sizeof(float) * 4);    } 
00179         Data(const mudbox::Matrix     &r) { memcpy(m_float, r.m_fData, sizeof(float) * 16); } 
00180 
00181         int                    As_int        () const { return m_int[0];            }
00182         float                  As_float      () const { return m_float[0];          }
00183         double                 As_double     () const { return m_double[0];         }
00184         mudbox::Color          As_Color      () const { return mudbox::Color(m_float[0], m_float[1], m_float[2], m_float[3]);     }
00185         mudbox::Vector         As_Vector     () const { return mudbox::Vector(m_float[0], m_float[1], m_float[2]);                }
00186         mudbox::DblVector      As_DblVector  () const { return mudbox::DblVector(m_double[0], m_double[1], m_double[2]);          }
00187         mudbox::Vector4        As_Vector4    () const { return mudbox::Vector4(m_float[0], m_float[1], m_float[2], m_float[3]);   }
00188         mudbox::Quaternion     As_Quaternion () const { mudbox::Quaternion q; memcpy(&q.m_fW, m_float, sizeof(float) * 4); return q; }
00189         mudbox::Matrix         As_Matrix     () const { mudbox::Matrix m; memcpy(m.m_fData,  m_float, sizeof(float) * 16); return m; }
00190 };
00191 
00192 
00193 //------------------------------------------------------------------------------
00194 // This is the base class for locators, i.e. nodes which should find surface 
00195 // points on the source mesh to match surface points on the target mesh. The map 
00196 // extractor node always uses one instance of a locator during the extraction 
00197 // process
00198 class MEDLL Locator : public mudbox::Node
00199 {
00200     DECLARE_CLASS;
00201 public:
00202     Locator( void ) : m_pMapper( NULL ) {};
00203     ~Locator( void ) {};
00205     virtual void Prepare( void ) {};
00208     virtual bool LocateSurfacePoint( mudbox::SurfacePoint &pPoint, const class TargetLocation &vTarget );
00211     virtual QWidget *UserInterface( void );
00213     virtual void Serialize( mudbox::Stream &s );
00215     class MapExtractor *MapExtractor( void ) const;
00216 
00217     Mapper *m_pMapper;
00218 };
00219 
00230 class MEDLL ComponentUI : public QObject, public mudbox::Node
00231 {
00232     Q_OBJECT;
00233 protected:
00234     ComponentUI( class Component *pTarget );
00236     QWidget *CreateTargetWidget( 
00237         bool bSmoothing = true, 
00238         bool bUVSmoothing = true, 
00239         bool bDefaultToLowest = true, 
00240         bool bShowLevels = true 
00241         );
00243     QWidget *CreateSourceWidget( 
00244         bool bSmoothing = true 
00245         );
00248     QWidget *CreateLocatorWidget( void );
00252     QWidget *CreateLayoutWidget( void );
00255     QWidget *CreateOutputWidget( void );
00256 public:
00257     using mudbox::Node::Initialize;
00258     virtual void Initialize( void );
00259     virtual QWidget *RootWidget( void );
00260     virtual void UpdateValues( void );
00261 
00262     TextureExtractionDialog *m_pDialog;
00263     Mapper *m_pMapper;
00264     bool m_bValidData;
00265     bool m_bDefaultTargetToLowestLevel;
00266     class Component *m_pTarget;
00267     QLabel *SmallerLabel( const QString& text );
00268 private slots:
00269     void OnAddSelectedAsTarget( void );
00270     void OnAddAllAsTarget( void );
00271     void OnRemoveTarget( void );
00272     void OnTargetItemClicked( int row, int column );
00273     void OnSourceItemClicked( int row, int column );
00274     void OnSmoothTargetChanged( void );
00275     void OnSmoothTargetUVChanged( void );
00276     void OnPreserveCreasesAndHardEdgesChanged( void );
00277     void OnSmoothSourceChanged( void );
00278     void OnAddSelectedAsSource( void );
00279     void OnAddAllAsSource( void );
00280     void OnRemoveSource( void );
00281     void OnTargetReordered( int, int, int );
00282     void OnMapTypeChanged( const QString & );
00283 protected:
00284     QComboBox *m_pLocateMethod;
00285 };
00286 
00288 enum PhaseEventType
00289 {
00290     eventSectionStart,  
00291     eventSectionEnd,    
00292     eventQueueFlush,    
00293     eventQueueLocated,
00294 
00295     eventQueueProcessed
00296 };
00297 
00305 class MEDLL Layout : public mudbox::Node
00306 {
00307     DECLARE_CLASS;
00308 
00309     Layout( void ) : m_pMapExtractor( NULL ) {};
00311     void ProcessSurfacePoint( const TargetLocation &vLocation );
00314     void Flush( void );
00321     void BeginSection( void );
00323     void EndSection( void );
00325     virtual void CleanUp( void );
00326     void Serialize( mudbox::Stream & );
00327 
00329     virtual unsigned int Prepare( void );
00332     virtual void ProcessSurface( mudbox::SubdivisionLevel *pTarget );
00334     virtual QWidget *UserInterface( void );
00335 public:
00336     MapExtractor *m_pMapExtractor;
00337 };
00338 
00349 class MEDLL Component : public mudbox::Node
00350 {
00351     DECLARE_CLASS;
00352     enum Normalization
00353     {
00354         eNormNone,      
00355         eNormFull,      
00356         eNormKeepZero,
00357         eNormCustom 
00358     }; 
00359     enum Precision
00360     {
00361         ePrecByte,      
00362         ePrecFloat, 
00363         ePrecFloatOnly  
00364     };
00366     struct DataInfo
00367     {
00368         DataInfo() : m_eNormalization( eNormNone ), m_fLowerBound( 0 ), m_fUpperBound( 1 ), m_iChannelCount( 3 ), m_ePrecision( ePrecFloat ) {};
00369         Normalization m_eNormalization; 
00370         float m_fLowerBound;    
00371         float m_fUpperBound;    
00372         int m_iChannelCount;    
00373         Precision m_ePrecision; 
00374         QString m_sMaterialChannelName; 
00375 
00376         QString m_sDataName;    
00377 
00378     };
00379     Component( void );
00380     void Serialize( mudbox::Stream & );
00384     virtual int Prepare( void );
00386     virtual void CleanUp( void );
00387 
00390     virtual Data ProcessSurfacePoint( const TargetLocation &cTarget, const mudbox::SurfacePoint &cSource );
00392     virtual ComponentUI *UserInterface( void );
00400     virtual unsigned int ConfigurationCount( void ) const;
00402     virtual void SetConfiguration( unsigned int iConfiguration );
00405     virtual bool IsValid( void );
00407     virtual void SetupPaintLayer( mudbox::TexturePool *pPaintLayer ) const;
00409     virtual void OnPhaseEvent( PhaseEventType eType );
00413     virtual Data DefaultData( void ) const;
00416     virtual struct DataInfo DataInfo( void ) const;
00417 
00418 public:
00419     mudbox::abool m_bEnabled;
00420     Mapper *m_pMapper;
00421     class MapExtractor *m_pMapExtractor;
00422     class Utilizer *m_pUtilizer;
00423 };
00424 
00430 class MEDLL TargetLocation : public mudbox::SurfacePoint
00431 {
00432 public:
00436     float m_fDiameter;
00440     int m_aLayoutData[16];
00444     unsigned int m_iReferenceFaceIndex;
00448     float m_fReferenceFaceU, m_fReferenceFaceV;
00452     unsigned int m_iIndex;
00453     mudbox::Base m_bTangent;
00454     TargetLocation( void ) : m_iReferenceFaceIndex( 0xffffffff ) {};
00455     TargetLocation( class mudbox::Mesh *pMesh, unsigned int iVertexIndex, unsigned int iFaceIndex ) : SurfacePoint( pMesh, iVertexIndex, iFaceIndex ), m_iReferenceFaceIndex( 0xffffffff ) {};
00457     void Fill( 
00458         class mudbox::Mesh *pMesh, 
00459         unsigned int iFaceIndex, 
00460         float fFaceU, 
00461         float fFaceV, 
00462         float fDiameter = 1.0f 
00463         );
00467     void FillUsingUV( 
00468                      class mudbox::Mesh *pMesh, 
00469                      unsigned int iFaceIndex,           
00470                      float fU,                                  
00471                      float fV,                                  
00472                      mudbox::SurfaceSmoother *pSS = NULL,
00473                      float fDiameter = 1.0f             
00474                      );
00475 
00479     void FillNSided(
00480         class mudbox::Mesh *pMesh,  
00481         unsigned int iFaceIndex,            
00482         const mudbox::Vector &vPosition,
00483         float fDiameter = 1.0f              
00484         );
00485 
00486         mudbox::Base TangentBase( void ) const { return m_bTangent; };
00487 
00488 private:
00489     bool RefineFaceIndex( void );
00490     float RefineFaceCoordinates( const mudbox::SurfaceSmoother *pSS, float fTargetU, float fTargetV );
00491 };
00492 
00500 class MEDLL Utilizer : public mudbox::Node
00501 {
00502     DECLARE_CLASS;
00503     Utilizer( void ) : m_pComponent( NULL ), m_bEnabled( true ) {};
00505     virtual QString MapTypeName( void ) const;
00507     virtual void OnPhaseEvent( PhaseEventType eType );
00509     virtual bool IsValid( void );
00511     virtual void CleanUp( void );
00512     using mudbox::Node::Initialize;
00515     virtual void Initialize( Layout *pLayout, Component *pComponent );
00516     // This function is called every time when a new data is calculated by the associated component of the utilizer.  Usually the utilizer obtains additional data
00517     // from the cTarget objects, which is able to hold generic data from the layout (m_aLayoutData). The utilizer should know the current layout type, so it 
00518     // knows how to interpret the data stored in that area. This function must be thread safe.
00519     virtual void StoreData( 
00520         const Data &cData, 
00521         const TargetLocation &cTarget, 
00522         bool bHit 
00523         );
00525     virtual QWidget *UserInterface( void );
00529     virtual Layout *CreateLayout( void );
00530     virtual void Serialize( mudbox::Stream &s );
00531 
00532 public:
00533     Component *m_pComponent;
00534     bool m_bEnabled;
00535 };
00536 
00537 class MEDLL Mapping : public mudbox::TreeNode
00538 {
00539     DECLARE_CLASS;
00540     virtual mudbox::Mesh *Target( void ) const;
00541     virtual bool MapSurfacePoint( mudbox::SurfacePoint &pPoint, const class TargetLocation &vTarget );
00542 };
00543 
00544 };
00545 
00546 #endif
00547