void Remove(edge *e) { point *u = Oi(e), *v = Dt(e); if (u->in == e) u->in = e->on; if (v->in == e) v->in = e->dn; if (Oi(e->on) == u) e->on->op = e->op; else e->on->dp = e->op; if (Oi(e->op) == u) e->op->on = e->on; else e->op->dn = e->on; if (Oi(e->dn) == v) e->dn->op = e->dp; else e->dn->dp = e->dp; if (Oi(e->dp) == v) e->dp->on = e->dn; else e->dp->dn = e->dn; elist[nfree++] = e; }
/** After the running shader on the complete grid return the compute Oi * \param x Integer Raster position. * \param y Integer Raster position. */ CqColor CqImagersource::Opacity( TqFloat x, TqFloat y ) { CqColor result = gColWhite; TqInt index = static_cast<TqInt>( ( y - m_uYOrigin ) * ( m_uGridRes + 1 ) + x - m_uXOrigin ); if ((TqInt) Oi() ->Size() >= index ) Oi() ->GetColor( result, index ); return result; }
edge *Join(edge *a, point *u, edge *b, point *v, int side) { edge *e = Make_edge(u, v); if (side == 1) { if (Oi(a) == u) Splice(Op(a), e, u); else Splice(Dp(a), e, u); Splice(b, e, v); } else { Splice(a, e, u); if (Oi(b) == v) Splice(Op(b), e, v); else Splice(Dp(b), e, v); } return e; }
void Divide(int s, int t, edge **L, edge **R) { edge *a, *b, *c, *ll, *lr, *rl, *rr, *tangent; int n = t - s + 1; if (n == 2) *L = *R = Make_edge(Q[s], Q[t]); else if (n == 3) { a = Make_edge(Q[s], Q[s + 1]), b = Make_edge(Q[s + 1], Q[t]); Splice(a, b, Q[s + 1]); double v = C3(Q[s], Q[s + 1], Q[t]); if (v > eps) c = Join(a, Q[s], b, Q[t], 0), *L = a, *R = b; else if (v < -eps) c = Join(a, Q[s], b, Q[t], 1), *L = c, *R = c; else *L = a, *R = b; } else if (n > 3) { int split = (s + t) / 2; Divide(s, split, &ll, &lr); Divide(split + 1, t, &rl, &rr); Merge(lr, Q[split], rl, Q[split + 1], &tangent); if (Oi(tangent) == Q[s]) ll = tangent; if (Dt(tangent) == Q[t]) rr = tangent; *L = ll; *R = rr; } }
//--------------------------------------------------------------------- void CqImagersource::Initialise( const CqRegion& DRegion, IqChannelBuffer* buffer ) { AQSIS_TIME_SCOPE(Imager_shading); // We use one less than the bucket width and height here, since these // resolutions really represent one less than the number of shaded points // in each direction. (Usually they describe the number of micropolygons // on a grid which is one less than the number of shaded vertices. This // concept has no real analogue in context of an imager shader.) TqInt uGridRes = DRegion.width()-1; TqInt vGridRes = DRegion.height()-1; TqInt x = DRegion.xMin(); TqInt y = DRegion.yMin(); m_uYOrigin = static_cast<TqInt>( y ); m_uXOrigin = static_cast<TqInt>( x ); m_uGridRes = uGridRes; m_vGridRes = vGridRes; TqInt mode = QGetRenderContext() ->poptCurrent()->GetIntegerOption( "System", "DisplayMode" ) [ 0 ]; TqFloat components; TqInt j, i; TqFloat shuttertime = QGetRenderContext() ->poptCurrent()->GetFloatOption( "System", "Shutter" ) [ 0 ]; components = mode & DMode_RGB ? 3 : 0; components += mode & DMode_A ? 1 : 0; components = mode & DMode_Z ? 1 : components; TqInt Uses = ( 1 << EnvVars_P ) | ( 1 << EnvVars_Ci ) | ( 1 << EnvVars_Oi | ( 1 << EnvVars_ncomps ) | ( 1 << EnvVars_time ) | ( 1 << EnvVars_alpha ) | ( 1 << EnvVars_s ) | ( 1 << EnvVars_t ) ); m_pShaderExecEnv->Initialise( uGridRes, vGridRes, uGridRes * vGridRes, (uGridRes+1)*(vGridRes+1), true, IqAttributesPtr(), IqTransformPtr(), m_pShader.get(), Uses ); // Initialise the geometric parameters in the shader exec env. TqInt numShadingPoints = (uGridRes+1) * (vGridRes+1); P() ->Initialise( numShadingPoints ); Ci() ->Initialise( numShadingPoints ); Oi() ->Initialise( numShadingPoints ); alpha() ->Initialise( numShadingPoints ); s() ->Initialise( numShadingPoints ); t() ->Initialise( numShadingPoints ); //TODO dtime is not initialised yet //dtime().Initialise(uGridRes, vGridRes, i); ncomps() ->SetFloat( components ); time() ->SetFloat( shuttertime ); m_pShader->Initialise( uGridRes, vGridRes, (uGridRes+1)*(vGridRes+1), m_pShaderExecEnv.get() ); TqUint CiIndex = buffer->getChannelIndex("Ci"); TqUint OiIndex = buffer->getChannelIndex("Oi"); TqUint coverageIndex = buffer->getChannelIndex("coverage"); for ( j = 0; j < vGridRes+1; j++ ) { for ( i = 0; i < uGridRes+1; i++ ) { TqInt off = j * ( uGridRes + 1 ) + i; P() ->SetPoint( CqVector3D( x + i, y + j, 0.0 ), off ); Ci() ->SetColor( CqColor((*buffer)(i, j, CiIndex)[0], (*buffer)(i, j, CiIndex)[1], (*buffer)(i, j, CiIndex)[2]), off ); CqColor opa((*buffer)(i, j, OiIndex)[0], (*buffer)(i, j, OiIndex)[1], (*buffer)(i, j, OiIndex)[2]); Oi() ->SetColor( opa, off ); TqFloat avopa = ( opa.r() + opa.g() + opa.b() ) /3.0f; alpha() ->SetFloat( (*buffer)(i, j, coverageIndex)[0] * avopa, off ); s() ->SetFloat( x + i + 0.5, off ); t() ->SetFloat( y + j + 0.5, off ); } } // Execute the Shader VM if ( m_pShader ) { m_pShader->Evaluate( m_pShaderExecEnv.get() ); alpha() ->SetFloat( 1.0f ); /* by default 3delight/bmrt set it to 1.0 */ } }
void Splice(edge *a, edge *b, point *v) { edge *next; if (Oi(a) == v) next = On(a), On(a) = b; else next = Dn(a), Dn(a) = b; if (Oi(next) == v) Op(next) = b; else Dp(next) = b; if (Oi(b) == v) On(b) = next, Op(b) = a; else Dn(b) = next, Dp(b) = a; }