00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #pragma push_macro("free")
00016 #undef free
00017 #include <valarray>
00018 #pragma pop_macro("free")
00019
00020 #include <set>
00021
00022 #include "nvsgcommon.h"
00023
00024 #include "nvsg/nvsg.h"
00025 #include "nvtraverser/Traverser.h"
00026
00027 namespace nvtraverser
00028 {
00029
00031
00032 class CondenseTraverser : public Traverser
00033 {
00034 public:
00036 NVSG_API CondenseTraverser(void);
00037
00039
00040 NVSG_API void setEpsilon(
00041 float epsilon
00042 );
00043
00044 protected:
00046 NVSG_API virtual ~CondenseTraverser(void);
00047
00049
00050 NVSG_API virtual void doApply( const nvsg::ViewState *pViewState
00051 , const nvsg::Scene *pScene
00052 );
00053
00055 NVSG_API virtual void handleGeoNode( const nvsg::GeoNode *p
00056 );
00057
00058 private:
00059 bool areSimilar( const std::valarray<float> &v0, const std::valarray<float> &v1, float eps );
00060 void condense( const nvsg::Quads *p );
00061 void condense( const nvsg::Triangles *p );
00062 size_t hash( const std::valarray<float> &vertex, const std::valarray<float> &base, float scale, size_t numVertices );
00063 void postRemapping( const nvsg::GeoSet *p, std::vector<std::valarray<float> > &valuesOut );
00064 void prepareRemapping( const nvsg::GeoSet *p, std::vector<std::valarray<float> > &valuesIn );
00065 bool remap( const nvsg::IndexSet &iIn, const std::vector<std::valarray<float> > &vIn,
00066 nvsg::IndexSet &iOut, std::vector<std::valarray<float> > &vOut, float epsilon );
00067
00068 private:
00069 float m_epsilon;
00070 float m_tolerance;
00071 std::set<const nvsg::Quads *> m_quads;
00072 std::set<const nvsg::Triangles *> m_triangles;
00073 };
00074
00075 inline void CondenseTraverser::setEpsilon( float epsilon )
00076 {
00077 m_epsilon = fabsf( epsilon );
00078 }
00079 }