Cleanup clusterfit.

This commit is contained in:
castano 2011-01-19 07:27:04 +00:00
parent 4f098c4ff9
commit 95b5e1decd
2 changed files with 418 additions and 526 deletions

View File

@ -48,57 +48,56 @@ void ClusterFit::setColourSet(const ColorSet * set)
#endif #endif
// cache some values // cache some values
count = set->count; m_count = set->count;
Vector3 values[16]; Vector3 values[16];
for (uint i = 0; i < count; i++) for (uint i = 0; i < m_count; i++)
{ {
values[i] = set->colors[i].xyz(); values[i] = set->colors[i].xyz();
} }
Vector3 principle = Fit::computePrincipalComponent(count, values, set->weights, metric); Vector3 principle = Fit::computePrincipalComponent(m_count, values, set->weights, metric);
// build the list of values // build the list of values
int order[16];
float dps[16]; float dps[16];
for (uint i = 0; i < count; ++i) for (uint i = 0; i < m_count; ++i)
{ {
dps[i] = dot(values[i], principle); dps[i] = dot(values[i], principle);
m_order[i] = i; order[i] = i;
} }
// stable sort // stable sort
for (uint i = 0; i < count; ++i) for (uint i = 0; i < m_count; ++i)
{ {
for (uint j = i; j > 0 && dps[j] < dps[j - 1]; --j) for (uint j = i; j > 0 && dps[j] < dps[j - 1]; --j)
{ {
swap( dps[j], dps[j - 1] ); swap(dps[j], dps[j - 1]);
swap( m_order[j], m_order[j - 1] ); swap(order[j], order[j - 1]);
} }
} }
// weight all the points // weight all the points
#if NVTT_USE_SIMD #if NVTT_USE_SIMD
SimdVector const* unweighted = set->GetPointsSimd();
SimdVector const* weights = set->GetWeightsSimd();
m_xxsum = SimdVector( 0.0f ); m_xxsum = SimdVector( 0.0f );
m_xsum = SimdVector( 0.0f ); m_xsum = SimdVector( 0.0f );
#else #else
Vector3 const* unweighted = values;
float const* weights = set->weights;
m_xxsum = Vector3(0.0f);
m_xsum = Vector3(0.0f); m_xsum = Vector3(0.0f);
m_wsum = 0.0f; m_wsum = 0.0f;
#endif #endif
for (uint i = 0; i < count; ++i) for (uint i = 0; i < m_count; ++i)
{ {
int p = m_order[i]; int p = order[i];
m_weighted[i] = weights[p] * unweighted[p]; #if NVTT_USE_SIMD
m_weighted[i] = SimdVector(Vector4(set->weights[p] * values[p], set->weights[p]));
m_xxsum += m_weighted[i] * m_weighted[i]; m_xxsum += m_weighted[i] * m_weighted[i];
m_xsum += m_weighted[i]; m_xsum += m_weighted[i];
#if !NVTT_USE_SIMD #else
m_weights[i] = weights[p]; m_weighted[i] = values[p];
m_xxsum += m_weighted[i] * m_weighted[i];
m_xsum += m_weighted[i];
m_weights[i] = set->weights[p];
m_wsum += m_weights[i]; m_wsum += m_weights[i];
#endif #endif
} }
@ -108,7 +107,7 @@ void ClusterFit::setColourSet(const ColorSet * set)
void ClusterFit::setMetric(Vector4::Arg w) void ClusterFit::setMetric(Vector4::Arg w)
{ {
#if NVTT_USE_SIMD #if NVTT_USE_SIMD
m_metric = SimdVector(w); m_metric = SimdVector(Vector4(w.xyz(), 1));
#else #else
m_metric = w.xyz(); m_metric = w.xyz();
#endif #endif
@ -131,7 +130,7 @@ float ClusterFit::bestError() const
bool ClusterFit::compress3( Vector3 * start, Vector3 * end ) bool ClusterFit::compress3( Vector3 * start, Vector3 * end )
{ {
int const count = m_colours->count; int const count = m_count;
SimdVector const one = SimdVector(1.0f); SimdVector const one = SimdVector(1.0f);
SimdVector const zero = SimdVector(0.0f); SimdVector const zero = SimdVector(0.0f);
SimdVector const half(0.5f, 0.5f, 0.5f, 0.25f); SimdVector const half(0.5f, 0.5f, 0.5f, 0.25f);
@ -211,30 +210,6 @@ bool ClusterFit::compress3( Vector3 * start, Vector3 * end )
// save the block if necessary // save the block if necessary
if( compareAnyLessThan( besterror, m_besterror ) ) if( compareAnyLessThan( besterror, m_besterror ) )
{ {
// compute indices from cluster sizes.
/*u8 bestindices[16];
{
int i = 0;
for(; i < b0; i++) {
bestindices[i] = 0;
}
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock3( beststart.toVector3(), bestend.toVector3(), bestindices, block );*/
*start = beststart.toVector3(); *start = beststart.toVector3();
*end = bestend.toVector3(); *end = bestend.toVector3();
@ -250,7 +225,7 @@ bool ClusterFit::compress3( Vector3 * start, Vector3 * end )
bool ClusterFit::compress4( Vector3 * start, Vector3 * end ) bool ClusterFit::compress4( Vector3 * start, Vector3 * end )
{ {
int const count = m_colours->count; int const count = m_count;
SimdVector const one = SimdVector(1.0f); SimdVector const one = SimdVector(1.0f);
SimdVector const zero = SimdVector(0.0f); SimdVector const zero = SimdVector(0.0f);
SimdVector const half = SimdVector(0.5f); SimdVector const half = SimdVector(0.5f);
@ -340,34 +315,6 @@ bool ClusterFit::compress4( Vector3 * start, Vector3 * end )
// save the block if necessary // save the block if necessary
if( compareAnyLessThan( besterror, m_besterror ) ) if( compareAnyLessThan( besterror, m_besterror ) )
{ {
/*// compute indices from cluster sizes.
u8 bestindices[16];
{
int i = 0;
for(; i < b0; i++) {
bestindices[i] = 0;
}
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < b0+b1+b2; i++) {
bestindices[i] = 3;
}
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock4( beststart.toVector3(), bestend.toVector3(), bestindices, block );*/
*start = beststart.toVector3(); *start = beststart.toVector3();
*end = bestend.toVector3(); *end = bestend.toVector3();
@ -384,6 +331,7 @@ bool ClusterFit::compress4( Vector3 * start, Vector3 * end )
bool ClusterFit::compress3(Vector3 * start, Vector3 * end) bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
{ {
int const count = m_count;
const Vector3 one( 1.0f ); const Vector3 one( 1.0f );
const Vector3 zero( 0.0f ); const Vector3 zero( 0.0f );
const Vector3 half( 0.5f ); const Vector3 half( 0.5f );
@ -455,30 +403,6 @@ bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
// save the block if necessary // save the block if necessary
if( besterror < m_besterror ) if( besterror < m_besterror )
{ {
/*// compute indices from cluster sizes.
u8 bestindices[16];
{
int i = 0;
for(; i < b0; i++) {
bestindices[i] = 0;
}
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock3( beststart, bestend, bestindices, block );*/
*start = beststart; *start = beststart;
*end = bestend; *end = bestend;
@ -494,6 +418,7 @@ bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
bool ClusterFit::compress4(Vector3 * start, Vector3 * end) bool ClusterFit::compress4(Vector3 * start, Vector3 * end)
{ {
int const count = m_count;
Vector3 const one( 1.0f ); Vector3 const one( 1.0f );
Vector3 const zero( 0.0f ); Vector3 const zero( 0.0f );
Vector3 const half( 0.5f ); Vector3 const half( 0.5f );
@ -573,34 +498,6 @@ bool ClusterFit::compress4(Vector3 * start, Vector3 * end)
// save the block if necessary // save the block if necessary
if( besterror < m_besterror ) if( besterror < m_besterror )
{ {
/*// compute indices from cluster sizes.
u8 bestindices[16];
{
int i = 0;
for(; i < b0; i++) {
bestindices[i] = 0;
}
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < b0+b1+b2; i++) {
bestindices[i] = 3;
}
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock4( beststart, bestend, bestindices, block );*/
*start = beststart; *start = beststart;
*end = bestend; *end = bestend;

View File

@ -51,18 +51,15 @@ namespace nv {
private: private:
uint count; uint m_count;
//ColorSet const* m_colours;
Vector3 m_principle;
#if NVTT_USE_SIMD #if NVTT_USE_SIMD
SimdVector m_weighted[16]; SimdVector m_weighted[16]; // color | weight
SimdVector m_metric; SimdVector m_metric; // vec3
SimdVector m_metricSqr; SimdVector m_metricSqr; // vec3
SimdVector m_xxsum; SimdVector m_xxsum; // color | weight
SimdVector m_xsum; SimdVector m_xsum; // color | weight (wsum)
SimdVector m_besterror; SimdVector m_besterror; // scalar
#else #else
Vector3 m_weighted[16]; Vector3 m_weighted[16];
float m_weights[16]; float m_weights[16];
@ -73,8 +70,6 @@ namespace nv {
float m_wsum; float m_wsum;
float m_besterror; float m_besterror;
#endif #endif
int m_order[16];
}; };
} // nv namespace } // nv namespace