Cleanup clusterfit.
This commit is contained in:
parent
4f098c4ff9
commit
95b5e1decd
@ -48,57 +48,56 @@ void ClusterFit::setColourSet(const ColorSet * set)
|
||||
#endif
|
||||
|
||||
// cache some values
|
||||
count = set->count;
|
||||
m_count = set->count;
|
||||
|
||||
Vector3 values[16];
|
||||
for (uint i = 0; i < count; i++)
|
||||
for (uint i = 0; i < m_count; i++)
|
||||
{
|
||||
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
|
||||
int order[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);
|
||||
m_order[i] = i;
|
||||
order[i] = i;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
swap(dps[j], dps[j - 1]);
|
||||
swap( m_order[j], m_order[j - 1] );
|
||||
swap(order[j], order[j - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
// weight all the points
|
||||
#if NVTT_USE_SIMD
|
||||
SimdVector const* unweighted = set->GetPointsSimd();
|
||||
SimdVector const* weights = set->GetWeightsSimd();
|
||||
m_xxsum = SimdVector( 0.0f );
|
||||
m_xsum = SimdVector( 0.0f );
|
||||
#else
|
||||
Vector3 const* unweighted = values;
|
||||
float const* weights = set->weights;
|
||||
m_xxsum = Vector3(0.0f);
|
||||
m_xsum = Vector3(0.0f);
|
||||
m_wsum = 0.0f;
|
||||
#endif
|
||||
|
||||
for (uint i = 0; i < count; ++i)
|
||||
for (uint i = 0; i < m_count; ++i)
|
||||
{
|
||||
int p = m_order[i];
|
||||
m_weighted[i] = weights[p] * unweighted[p];
|
||||
int p = order[i];
|
||||
#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_xsum += m_weighted[i];
|
||||
#if !NVTT_USE_SIMD
|
||||
m_weights[i] = weights[p];
|
||||
#else
|
||||
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];
|
||||
#endif
|
||||
}
|
||||
@ -108,7 +107,7 @@ void ClusterFit::setColourSet(const ColorSet * set)
|
||||
void ClusterFit::setMetric(Vector4::Arg w)
|
||||
{
|
||||
#if NVTT_USE_SIMD
|
||||
m_metric = SimdVector(w);
|
||||
m_metric = SimdVector(Vector4(w.xyz(), 1));
|
||||
#else
|
||||
m_metric = w.xyz();
|
||||
#endif
|
||||
@ -131,7 +130,7 @@ float ClusterFit::bestError() const
|
||||
|
||||
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 zero = SimdVector(0.0f);
|
||||
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
|
||||
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();
|
||||
*end = bestend.toVector3();
|
||||
@ -250,7 +225,7 @@ bool ClusterFit::compress3( 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 zero = SimdVector(0.0f);
|
||||
SimdVector const half = SimdVector(0.5f);
|
||||
@ -340,34 +315,6 @@ bool ClusterFit::compress4( Vector3 * start, Vector3 * end )
|
||||
// save the block if necessary
|
||||
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();
|
||||
*end = bestend.toVector3();
|
||||
|
||||
@ -384,6 +331,7 @@ bool ClusterFit::compress4( Vector3 * start, Vector3 * end )
|
||||
|
||||
bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
|
||||
{
|
||||
int const count = m_count;
|
||||
const Vector3 one( 1.0f );
|
||||
const Vector3 zero( 0.0f );
|
||||
const Vector3 half( 0.5f );
|
||||
@ -455,30 +403,6 @@ bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
|
||||
// save the block if necessary
|
||||
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;
|
||||
*end = bestend;
|
||||
@ -494,6 +418,7 @@ bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
|
||||
|
||||
bool ClusterFit::compress4(Vector3 * start, Vector3 * end)
|
||||
{
|
||||
int const count = m_count;
|
||||
Vector3 const one( 1.0f );
|
||||
Vector3 const zero( 0.0f );
|
||||
Vector3 const half( 0.5f );
|
||||
@ -573,34 +498,6 @@ bool ClusterFit::compress4(Vector3 * start, Vector3 * end)
|
||||
// save the block if necessary
|
||||
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;
|
||||
*end = bestend;
|
||||
|
||||
|
@ -51,18 +51,15 @@ namespace nv {
|
||||
|
||||
private:
|
||||
|
||||
uint count;
|
||||
//ColorSet const* m_colours;
|
||||
|
||||
Vector3 m_principle;
|
||||
uint m_count;
|
||||
|
||||
#if NVTT_USE_SIMD
|
||||
SimdVector m_weighted[16];
|
||||
SimdVector m_metric;
|
||||
SimdVector m_metricSqr;
|
||||
SimdVector m_xxsum;
|
||||
SimdVector m_xsum;
|
||||
SimdVector m_besterror;
|
||||
SimdVector m_weighted[16]; // color | weight
|
||||
SimdVector m_metric; // vec3
|
||||
SimdVector m_metricSqr; // vec3
|
||||
SimdVector m_xxsum; // color | weight
|
||||
SimdVector m_xsum; // color | weight (wsum)
|
||||
SimdVector m_besterror; // scalar
|
||||
#else
|
||||
Vector3 m_weighted[16];
|
||||
float m_weights[16];
|
||||
@ -73,8 +70,6 @@ namespace nv {
|
||||
float m_wsum;
|
||||
float m_besterror;
|
||||
#endif
|
||||
|
||||
int m_order[16];
|
||||
};
|
||||
|
||||
} // nv namespace
|
||||
|
Loading…
Reference in New Issue
Block a user