void TestMatrixExtras::test_mult_SS3() {
    // testing with C : DENSE

    size_t repetitions = 300;

    for (size_t r = 0; r < repetitions; r++) {
        size_t n = 10;
        size_t k = 8;
        size_t m = 9;
        Matrix A = MatrixFactory::MakeRandomSparse(n, k, std::ceil(n * k / 2), 2.0, 1.0);
        Matrix B = MatrixFactory::MakeRandomSparse(k, m, std::ceil(m * k / 2), 2.0, 1.0);
        Matrix C = MatrixFactory::MakeRandomMatrix(n, m, 2.0, 1.0);

        double alpha = -2.0 + 2.0 * static_cast<double> (std::rand()) / static_cast<double> (RAND_MAX);
        double gamma = -2.0 + 3.0 * static_cast<double> (std::rand()) / static_cast<double> (RAND_MAX);


        Matrix aAB = A*B;
        aAB *= alpha; /*     aAB = a * A * B          */

        Matrix gC(C);
        gC *= gamma; /*     gC  = g * C              */

        Matrix R = aAB + gC;

        Matrix C_copy(C);
        int status = Matrix::mult(C_copy, alpha, A, B, gamma);
        _ASSERT_EQ(ForBESUtils::STATUS_OK, status);

        _ASSERT_EQ(R, C_copy);
    }
}
// identifierar alla mesharna i scenen och extraherar data fr�n dem
bool Exporter::IdentifyAndExtractMeshes()
{
	UINT index = 0;
	scene_.meshes.clear();

	//itererar �ver DG:n och lagrar rgba-v�rden och texturnamn i ett tempor�rt material
	material tempmaterial;
	MItDependencyNodes matIt(MFn::kLambert);
	MString aC("ambientColor"), dC("color"), sC("specularColor"), gC("incandescence"), tC("transparency");
	while (!matIt.isDone()){
		if (matIt.item().hasFn(MFn::kPhong))
		{
			MFnPhongShader tempphong(matIt.item());
			tempmaterial.type = PHONG;
			extractColor(tempmaterial.ambient, tempphong, aC);
			extractColor(tempmaterial.diffuse, tempphong, dC);
			extractColor(tempmaterial.specular, tempphong, sC);
			extractColor(tempmaterial.glow, tempphong, gC);
			extractColor(tempmaterial.transparency, tempphong, tC);
		}
		else if (matIt.thisNode().hasFn(MFn::kBlinn))
		{
			MFnBlinnShader tempblinn(matIt.item());
			tempmaterial.type = BLINN;
			extractColor(tempmaterial.ambient, tempblinn, aC);
			extractColor(tempmaterial.diffuse, tempblinn, dC);
			extractColor(tempmaterial.specular, tempblinn, sC);
			extractColor(tempmaterial.glow, tempblinn, gC);
			extractColor(tempmaterial.transparency, tempblinn, tC);
		}
		else if (matIt.item().hasFn(MFn::kLambert))
		{
			MFnLambertShader templamb(matIt.item());
			tempmaterial.type = LAMBERT;
			extractColor(tempmaterial.ambient, templamb, aC);
			extractColor(tempmaterial.diffuse, templamb, dC);
			extractColor(tempmaterial.specular, templamb, sC);
			extractColor(tempmaterial.glow, templamb, gC);
			extractColor(tempmaterial.transparency, templamb, tC);
		}
		else
			printf("No material found\n");
		scene_.materials.push_back(tempmaterial);
		matIt.next();
	}

	//Turn off or on Blendshapes
	matIt.reset(MFn::kBlendShape);
	while (!matIt.isDone())
	{
		MFnBlendShapeDeformer bs(matIt.item());

		//Get the envelope attribute plug
		MPlug pl = bs.findPlug("en");

		//Set the 0 to disable FFD effect, enable by setting it to 1:
		pl.setValue(1.0f);

		matIt.next();
	}

	//Get Actual Blendshapes
	matIt.reset(MFn::kBlendShape);
	while (!matIt.isDone())
	{
		MFnBlendShapeDeformer bs(matIt.item());

		MObjectArray base_objects;

		//print blend shape name
		cout << "Blendshape " << bs.name().asChar() << endl;

		//Get a list of objects that this blend shape deforms
		bs.getBaseObjects(base_objects);

		cout << "NumBaseOBjects " << base_objects.length() << endl;

		//loop through each blendshaped object
		for (int i = 0; i < base_objects.length(); ++i)
		{
			//Get the base shape
			MObject Base = base_objects[i];

			//Output all of the target shapes and weights
			OutputBlendShapes(bs, Base);
		}
		//Get next blend shapes
		matIt.next();
	}

	MDagPath dag_path;
	MItDag dag_iter(MItDag::kBreadthFirst, MFn::kMesh);

	while (!dag_iter.isDone())
	{
		if (dag_iter.getPath(dag_path))
		{
			MFnDagNode dag_node = dag_path.node();

			// vill endast ha "icke-history"-f�rem�l
			if (!dag_node.isIntermediateObject())
			{
				// triangulera meshen innan man h�mtar punkterna
				MFnMesh mesh(dag_path);
				ExtractMeshData(mesh, index);
				index++;
			}
		}

		dag_iter.next();
	}

	MItDependencyNodes it(MFn::kSkinClusterFilter);
	for (; !it.isDone(); it.next()) {


		MObject object = it.item();


		OutputSkinCluster(object);

	}

	//Hitta kamera data
	dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kCamera);
	while (!dag_iter.isDone())
	{

		extractCamera(dag_iter.item());
		dag_iter.next();
	}

	//itererar dag och s�ker data f�r tillg�ngliga ljus
	//om ej ljus finns i scenen ignoreras denna iteration f�r sagda scen.
	dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kLight);
	while (!dag_iter.isDone())
	{
		//funktion till v�r iterator
		MFnLight func(dag_iter.item());

		//namn:
		export_stream_ << "Light: " << func.name().asChar() << std::endl;

		//kalla p�EextractLight function
		extractLight(dag_iter.item());

		//vidare till n�sta ljus i dag'en
		dag_iter.next();


		/*
		if (dag_iter.getPath(dag_path))
		{
		auto test = dag_path.fullPathName();
		export_stream_ << "light: " << test << std::endl;
		}
		dag_iter.next();
		*/
	}

	dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kJoint);
	while (!dag_iter.isDone())
	{
		if (dag_iter.getPath(dag_path))
		{
			MFnDagNode dag_node = dag_path.node();

			if (!dag_node.isIntermediateObject())
			{
				extractJointData(dag_path);
			}
		}
		dag_iter.next();
	}
	int breadth=0;
	dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kTransform);
	while (!dag_iter.isDone())
	{
		int depth = dag_iter.depth();
		if (depth > 1)
			break;
		if (dag_iter.getPath(dag_path))
		{
			createSceneGraph(MFnDagNode(dag_path),-1);
		}
		breadth++;
		dag_iter.next();
	}
	/*
	//general purpose iterator, sista argument �r filtret
		dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kLight);
		while (!dag_iter.isDone())
		{
		if (dag_iter.getPath(dag_path))
		{

		}
		dag_iter.next();
		}
		*/


	return true;
}
Exemple #3
0
I rk(I f,A r,A a,A w)
{
  A z=0,*p=0;
  if(w)ND2 else ND1;
  {
    XA;
    C *pp=0,*ap,*wp;
    I wt=0,wr=0,wn=0,*wd=0;
    I n=0,t=0,i,j,k,d[9],rw,ra,ri,ir,iw=0,ia=0,ii=0,
    e=!w&&f==MP(9),h=QP(f)&&f!=MP(71)&&!e;
    Q(!QA(r),9);
    Q(r->t,6);
    Q(r->n<1||r->n>3,8);
    ar-=ra=raw(ar,*r->p);
    if(!w) mv(d,ad,ra),ir=tr(ra,ad),ad+=ra;
    else 
    {
      wt=w->t,wr=w->r,wd=w->d;
      wr-=rw=raw(wr,r->p[r->n>1]),ri=r->n>2?r->p[2]:9;
      Q(ri<0,9);
      if(ri>ra)ri=ra;
      if(ri>rw)ri=rw;
      mv(d,ad,ra-=ri);
      ia=tr(ra,ad),mv(d+ra,wd,rw),iw=tr(rw-=ri,wd);
      Q(cm(ad+=ra,wd+=rw,ri),11);
      ii=tr(ri,ad),ra+=rw+ri,ir=ia*iw*ii,wn=tr(wr,wd+=ri),ad+=ri;
      if(h&&ir>iw&&(f==MP(21)||f==MP(25)||f==MP(26)||f==MP(32)||f==MP(33)))
	h=0;
    } 
    an=tr(ar,ad);
    if(h)
    {
      g=0;
      aw_c[0]=a->c;
      aw_c[1]=w&&w->c;
      r=(A)fa(f,gC(at,ar,an,ad,a->n?a->p:0),w?gC(wt,wr,wn,wd,w->n?w->p:0):0);
      aw_c[0]=aw_c[1]=1;
      if(!r)R 0;
      r=un(&r);
      mv(d+ra,r->d,j=r->r);
      if((j+=ra)>MAXR)R q=13,(I)r;
      n=r->n;t=r->t;
      if(ir<2) R mv(r->d,d,r->r=j),r->n*=ir,(I)r;
      dc(r);
      if(g==(I (*)())rsh) R rsh(w?w:a,j,d);
      if(!g){h=0;}
      else
      {
	if(at=atOnExit,w) wt=wtOnExit;
	if(at!=a->t&&!(a=at?ep_cf(1):ci(1))) R 0;
	if(w&&wt!=w->t&&!(w=wt?ep_cf(2):ci(2))) R 0;
	OF(i,ir,n);
	W(ga(t,j,i,d));
	pp=(C*)z->p;
      }
    }
    if(!h) 
    {
      W(ga(Et,ra,ir,d));
      *--Y=zr(z),p=(A*)z->p;
    }
    if(!w)
    {
      for(ap=(C*)a->p;ir--;ap+=Tt(at,an))
	if(h) (*(I(*)(C*,C*,I))g)(pp,ap,an),pp+=Tt(t,n);
	else a=gc(at,ar,an,ad,(I*)ap),*p++=e?a:(A)fa(f,(I)a,0);
    } 
    else
    {
      for(i=0;i<ia;++i)for(j=0;j<iw;++j)
	for(k=0;k<ii;++k){
	  ap=(C*)a->p+Tt(at,(i*ii+k)*an);
	  wp=(C*)w->p+Tt(wt,(j*ii+k)*wn);
	  if(h)
	  {
	    (*(I(*)(C*,C*,C*,I))g)(pp,ap,wp,n),pp+=Tt(t,n);
	    if(q==1)*--Y=(I)z,aplus_err(q,(A)Y[1]),++Y;
	  } 
	  else
	  { 
	    *p++=(A)fa(f,(I)gc(at,ar,an,ad,(I*)ap),(I)gc(wt,wr,wn,wd,(I*)wp));
	  }
	}
    }
    if(h)R(I)z;
    if(!e)z=(A)dis(r=z),dc(r);
    R ++Y,(I)z;
  }
}