Пример #1
0
	void main1_3(void *arg)
	{
		color Kd = color(diffuse(), diffuse(), diffuse());

		normal Nf = faceforward(normalize(N()), I());
		vector V = -normalize(I());

		while (illuminance(P(), Nf, PI / 2.0f))
		{
			color C = 0.0f;
			SAMPLE_LIGHT_2(color, C, 0.0f,
				C += Cl() * (
					color_() * Kd * (normalize(L()) % Nf) 
					+ cosinePower() * specularColor() * specularbrdf(normalize(L()), Nf, V, 0.1f/*roughness()*/)
					)
				);

			Ci() += C;
		}

		if ( ! less_than( &transparency(), LIQ_SCALAR_ALMOST_ZERO ) )
		{//transparent
			Ci() = Ci() * ( 1.0f - transparency() ) + trace_transparent() * transparency();
		}//else{ opacity }
		setOutputForMaya();
	}
Пример #2
0
/** After the running shader on the complete grid return the compute Ci
 * \param x Integer Raster position.
 * \param y Integer Raster position.
 */
CqColor CqImagersource::Color( TqFloat x, TqFloat y )
{
	CqColor result = gColBlack;

	TqInt index = static_cast<TqInt>( ( y - m_uYOrigin ) * ( m_uGridRes + 1 ) + x - m_uXOrigin );

	if ( (TqInt)Ci() ->Size() >= index )
		Ci() ->GetColor( result, index );

	return result;
}
Пример #3
0
	void main1(void *arg)
	{
		color Kd = color(diffuse(), diffuse(), diffuse());

		normal Nf = faceforward(normalize(N()), I());
		vector V = -normalize(I());

		while (illuminance(P(), Nf, PI / 2.0f))
		{
			color	C = 0.0f;
			color	last = 0.0f;
			int		num_samples = 0;

			while (sample_light())
			{
				C += Cl() * (
					color_() * Kd * (normalize(L()) % Nf) 
					+ cosinePower() * specularColor() * specularbrdf(normalize(L()), Nf, V, 0.1f/*roughness()*/)
					);

				++ num_samples;

				if ((num_samples % 4) == 0)
				{
					color	current = C * (1.0f / (scalar)num_samples);

					if (converged(current, last)){
						break;
					}
					last = current;
				}
			}

			C *= (1.0f / (scalar)num_samples);
			Ci() += C;
		}

		if ( ! less_than( &transparency(), LIQ_SCALAR_ALMOST_ZERO ) )
		{//transparent
			Ci() = Ci() * ( 1.0f - transparency() ) + trace_transparent() * transparency();
		}//else{ opacity }
		setOutputForMaya();
	}
Пример #4
0
void SparseMatrixF :: ReadDiagonal(double *dv)
{
    for ( unsigned long j = 0; j < neq; j++ ) {
        for ( unsigned long ad = Adr(j); ad < Adr(j + 1); ad++ ) {
            unsigned long i = Ci(ad);
            if ( i == j ) {
                dv [ j ] = a [ ad ];
            }
        }
    }
}
Пример #5
0
void SparseMatrixF :: GetA12block(double *pA12, long c)
{
    for ( unsigned long j = neq - c; j < neq; j++ ) {
        for ( unsigned long ad = Adr(j); ad < Adr(j + 1); ad++ ) {
            unsigned long i = Ci(ad);
            if ( i < ( neq - c ) ) {
                pA12 [ i * c + ( j - ( neq - c ) ) ] = a [ ad ];
            }
        }
    }
}
Пример #6
0
void SparseMatrixF :: MulSymMatrixByVector(double *b, double *c)
{
    for ( unsigned long j = 0; j < neq; j++ ) {
        for ( unsigned long ad = Adr(j); ad < Adr(j + 1); ad++ ) {
            double A = a [ ad ];
            unsigned long i = Ci(ad);
            c [ i ] += A * b [ j ];
            if ( i != j ) {
                c [ j ] += A * b [ i ];
            }
        }
    }
}
Пример #7
0
bool Container::equalTree(Object const* o1, Object const * o2)
{
	Q_ASSERT(o1 && o2);
	if(o1==o2)
		return true;
	bool eq= o1->type()==o2->type();
	switch(o2->type()) {
		case Object::variable:
			eq = eq && Ci(o2)==Ci(o1);
			break;
		case Object::value:
			eq = eq && Cn(o2)==Cn(o1);
			break;
		case Object::container:
			eq = eq && Container(o2)==Container(o1);
			break;
		case Object::oper:
			eq = eq && Operator(o2)==Operator(o1);
			break;
		default:
			break;
	}
	return eq;
}
Пример #8
0
bool Foam::functionObjects::writeCellCentres::write()
{
    volVectorField C
    (
        IOobject
        (
            "C",
            time_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::NO_WRITE,
            false
        ),
        mesh_.C(),
        calculatedFvPatchScalarField::typeName
    );

    Log << "    Writing cell-centre field " << C.name()
        << " to " << time_.timeName() << endl;

    C.write();

    for (direction i=0; i<vector::nComponents; i++)
    {
        volScalarField Ci
        (
            IOobject
            (
                mesh_.C().name() + vector::componentNames[i],
                time_.timeName(),
                mesh_,
                IOobject::NO_READ,
                IOobject::NO_WRITE,
                false
            ),
            mesh_.C().component(i)
        );

        Log << "    Writing the "
            << vector::componentNames[i]
            << " component field of the cell-centres " << Ci.name()
            << " to " << time_.timeName() << endl;

        Ci.write();
    }

    return true;
}
Пример #9
0
void SparseMatrixF :: mxv_scr(double *b, double *c)
{
    unsigned long i, j, ii, lj, uj;
    double s, d;

    for ( i = 0; i < neq; i++ ) {
        lj = Adr(i);
        uj = Adr(i + 1);
        s = 0.0;
        d = b [ i ];
        for ( j = lj; j < uj; j++ ) {
            ii = Ci(j);
            s += a [ j ] * b [ ii ];
            c [ ii ] += a [ j ] * d;
        }

        c [ i ] = s;
    }
}
Пример #10
0
			RMMTree(stream_type & in, base_layer_type const & rB)
			: 
				B(rB),
				n(libmaus::util::NumberSerialisation::deserialiseNumber(in)),
				numlevels(libmaus::util::NumberSerialisation::deserialiseNumber(in)),
				I(libmaus::util::NumberSerialisation::deserialiseNumber(in)),
				C(libmaus::util::NumberSerialisation::deserialiseNumber(in)),
				S(in)
			{
				for ( uint64_t i = 0; i < I.size(); ++i )
				{
					libmaus::bitio::CompactArray::unique_ptr_type tIi(new libmaus::bitio::CompactArray(in));
					I[i] = UNIQUE_PTR_MOVE(tIi);
				}
				for ( uint64_t i = 0; i < C.size(); ++i )
				{
					C_ptr_type Ci(C_type::load(in));					
					C[i] = UNIQUE_PTR_MOVE(Ci);
				}
			}
Пример #11
0
//---------------------------------------------------------------------
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 */
	}
}
Пример #12
0
	static
	bool smoother_conjugate_gradient(
			double i_tvis,
			const PlaneData &i_rhs,
			PlaneData &io_x,
			double *i_domain_size,
			double i_error_threshold = 0.000001,
			int i_max_iters = 999999999,
			double i_omega = 0.1, //not needed in CG
			int i_verbosity = 0
	)
	{
		const PlaneData &b = i_rhs;
		PlaneData &x = io_x;

		double inv_helm_h[2];
		inv_helm_h[0] = (double)i_rhs.planeDataConfig->physical_data_size[0]/(double)i_domain_size[0];
		inv_helm_h[1] = (double)i_rhs.planeDataConfig->physical_data_size[1]/(double)i_domain_size[1];

		double scalar_Dx = 1.0*(inv_helm_h[0]*inv_helm_h[0]);
		double scalar_Dy = 1.0*(inv_helm_h[1]*inv_helm_h[1]);
		double scalar_C = -(2.0*(inv_helm_h[0]*inv_helm_h[0]) + 2.0*(inv_helm_h[1]*inv_helm_h[1]));
		const double res_kernel[9] = {
						 0,         scalar_Dy, 0,
						 scalar_Dx, scalar_C,  scalar_Dx,
						 0,         scalar_Dy, 0
				};

#define A(x)	(x - i_tvis*x.op_stencil_Re_3x3(res_kernel))

#if 0
		double foo = 1.0/std::sqrt(i_kappa.real() - i_gh0*scalar_C);
		double c_re = foo;
		double c_im = foo;

		c_re = 1;
		c_im = 1;

#	define Ci(x)	(x.multiply_real_imag(c_re, c_im))
#else
#	define Ci(x)	(x)
#endif


		PlaneData r = b - A(x);
		PlaneData w = Ci(r);
		PlaneData v = Ci(w);

		// TODO: should we maybe use the conjugate dot product?
		double alpha = (w*w).reduce_sum();

		if (i_verbosity > 3)
			std::cout << "RESIDUAL: " << r.reduce_rms() << std::endl;


		int i = 0;
		for (i = 0; i < i_max_iters; i++)
		{
//			if (v.reduce_rms() < i_error_threshold)
//				return true;

			PlaneData u = A(v);
			double t = alpha / (v*u).reduce_sum();

			x = x + t*v;
			r = r - t*u;
			w = Ci(r);
			double beta = (w*w).reduce_sum();

			if (std::abs(beta) < i_error_threshold)
			{
				if (r.reduce_rms() < i_error_threshold)
				{
					if (i_verbosity > 0)
						std::cout << "FIN RESIDUAL: " << (b-A(x)).reduce_rms() << " after " << i << " iterations" << std::endl;
					return true;
				}
			}

			//if (i_verbosity > 3)
			x.print_physicalArrayData();
			r.print_physicalArrayData();
				std::cout << "RESIDUAL: " << r.reduce_rms() << std::endl;

			double s = beta / alpha;
			v = Ci(w) + v*s;

			alpha = beta;
		}


#undef A
#undef Ci

		return false;
	}
Пример #13
0
/**
  * The optimal community structure is a subdivision of the network into
  * nonoverlapping groups of nodes in a way that maximizes the number of
  * within-group edges, and minimizes the number of between-group edges.
  * The modularity is a statistic that quantifies the degree to which the
  * network may be subdivided into such clearly delineated groups.
  *
  * The Louvain algorithm is a fast and accurate community detection
  * algorithm (as of writing). The algorithm may also be used to detect
  * hierarchical community structure.
  *
  *     Input:      W       undirected (weighted or binary) connection matrix.
  *                 gamma,  modularity resolution parameter (optional)
  *                             gamma>1     detects smaller modules
  *                             0<=gamma<1  detects larger modules
  *                             gamma=1     (default) classic modularity
  *
  *     Outputs:    Ci,     community structure
  *                 Q,      modularity

  * Note: Ci and Q may vary from run to run, due to heuristics in the
  * algorithm. Consequently, it may be worth to compare multiple runs.
  *
  * Reference: Blondel et al. (2008)  J. Stat. Mech. P10008.
  *           Reichardt and Bornholdt (2006) Phys Rev E 74:016110.
  */
urowvec Connectome::modularity_louvain(mat W, double *Qopt, double gamma)
{
    uint N = W.n_rows, h = 1, n = N, u =0, ma =0, mb =0;
    double s = accu(W), wm = 0, max_dQ = -1;
    uvec M, t;
    rowvec dQ;
    field<urowvec> Ci(20);
    Ci(0) = urowvec(); Ci(1) = linspace<urowvec>(0,n-1,n);
    rowvec Q = "-1,0";

    while (Q(h)-Q(h-1) > 1e-10) {
        rowvec K = sum(W,0), Km = K;
        mat Knm = W;

        M = linspace<uvec>(0,n-1,n);

        bool flag = true;

        while (flag) {
            flag = false;

            arma_rng::set_seed_random();
            t = shuffle(linspace<uvec>(0,n-1,n));
            for (uint i =0;i<n;++i) {
                u = t(i);
                ma = M(u);
                dQ = Knm.row(u) - Knm(u,ma)+W(u,u)-
                        gamma*K(u)*(Km-Km(ma)+K(u))/s;
                dQ(ma) = 0;
                max_dQ = dQ.max();
                mb = as_scalar(find(dQ == max_dQ,1));
                if (max_dQ > 1e-10) {
                    flag = true;
                    M(u) = mb;

                    Knm.col(mb) += W.col(u);
                    Knm.col(ma) -= W.col(u);
                    Km(mb) += K(u);
                    Km(ma) -= K(u);
                }
            }
        }
        Ci(++h) = zeros<urowvec>(1,N);
        M = matlabUnique(M);
        for (uint u=0;u<n;++u) {
            Ci(h)(find(Ci(h-1) == u)).fill(M(u));
        }
        n = M.max()+1;
        mat w = zeros(n,n);
        for (uint u =0;u<n;++u)
            for (uint v=u;v<n;++v) {
                wm = accu(W(find(M==u),find(M==v)));
                w(u,v) = wm;
                w(v,u) = wm;
            }
        W = w;
        Q.resize(h+1);
        Q(h) = trace(W)/s - gamma*accu((W*W)/(s*s));
    }
    *Qopt = Q(h);
    return Ci(h);
}
Пример #14
-1
void SparseMatrixF :: MulNonsymMatrixByVector(double *b, double *c)
{
    switch ( m_eSparseOrientation ) {
    case eCompressedColumns:
    {
        for ( unsigned long j = 0; j < neq; j++ ) {
            for ( unsigned long ad = Adr(j); ad < Adr(j + 1); ad++ ) {
                double A = a [ ad ];
                unsigned long i = Ci(ad);
                c [ i ] += A * b [ j ];
            }
        }
    }
    break;
    case eCompressedRows:
    {
        for ( unsigned long j = 0; j < neq; j++ ) {
            for ( unsigned long ad = Adr(j); ad < Adr(j + 1); ad++ ) {
                double A = a [ ad ];
                unsigned long i = Ci(ad);
                c [ j ] += A * b [ i ];
            }
        }
    }
    break;
    default:
        fprintf(stderr, "SparseMatrixF::MulNonsymMatrixByVector: unsupported m_eSparseOrientation value\n");
        abort();
    }
}