Exemple #1
0
// reg_proc = TRUE
int MultiFlowLevMar::LevMarAccumulateRegionDerivsForActiveBeadList (
  float *ival, float *sbg,
  reg_params &eval_rp,
  BkgFitMatrixPacker *reg_fit, unsigned int PartialDeriv_mask,
  int iter, float *fvdbg, float *BackgroundDebugTapA, float *BackgroundDebugTapB)
{
  int reg_wells = 0;
  int defend_against_infinity = 0;
  lm_state.advance_bd = true; // always true here

  lm_state.avg_resid = CalculateCurrentResidualForTestBeads (sbg); // execute on every bead once to get current avg residual // @TODO: execute on every bead we care about in this fit???

  //@TODO nuc_rise step computed here, applied to all beads individually
  for (int nbd=0; (nbd < lm_state.ActiveBeads) && (defend_against_infinity<lm_state.numLBeads);defend_against_infinity++)
  {
    // get the index to the next bead to fit in the data matricies
    int ibd = lm_state.fit_indicies[nbd];

    // if this iteration is a region-wide parameter fit, then only process beads
    // in the selection sub-group
    if (!lm_state.ValidBeadGroup (ibd) || !lm_state.well_region_fit[ibd])
    {
      nbd++;
      continue;
    }

    // get the current parameter values for this bead
    bead_params eval_params = bkg.my_beads.params_nn[ibd];
    // make custom emphasis vector for this well using pointers to the per-HP vectors
    DynamicEmphasis(eval_params);
    bkg.my_scratch.FillObserved (bkg.my_trace, eval_params.trace_ndx);
    // now we're set up, do the individual steps
    ComputePartialDerivatives (eval_params, eval_rp, PartialDeriv_mask,ival, sbg, (ibd == bkg.my_beads.DEBUG_BEAD)); //@TODO: make explicit: sets lm_state.residual[ibd]
    lm_state.residual[ibd] = bkg.my_scratch.CalculateFitError (NULL,NUMFB);

    if ( (ibd == bkg.my_beads.DEBUG_BEAD) && (bkg.my_debug.trace_dbg_file != NULL))
    {
      bkg.DebugBeadIteration (eval_params,eval_rp, iter, ibd);
      bkg.my_trace.GetShiftedBkg (bkg.my_regions.rp.tshift,BackgroundDebugTapA);
      //CalcXtalkFlux(ibd,BackgroundDebugTapB);
      memcpy (fvdbg,bkg.my_scratch.fval,sizeof (float) *bkg.my_scratch.bead_flow_t);
    }

    lm_state.reg_error += lm_state.residual[ibd];

    if (lm_state.WellBehavedBead (ibd)) // only use "well-behaved" wells at any iteration
    {
      // if  reg_wells>0, continue same matrix, otherwise start a new one
      BuildMatrix (reg_fit, (reg_wells>0), (ibd==bkg.my_beads.DEBUG_BEAD));
      reg_wells++;
    }

    // if we just removed a bead from the fitting process, don't advance since a
    // new bead is already in place at the current index (it was placed there in
    // place of the bead that was just removed)
    if (lm_state.advance_bd)
      nbd++;
  }
  return (reg_wells); // number of live wells fit for region
}
		void GLSparseShadowMapRenderer::Render() {
			SPADES_MARK_FUNCTION();
			
			IGLDevice::Integer lastFb = device->GetInteger(IGLDevice::FramebufferBinding);
			
			//client::SceneDefinition def = GetRenderer()->GetSceneDef();
			
			float nearDist = 0.f;
			float farDist = 150.f;
			
			BuildMatrix(nearDist, farDist);
			
			device->BindFramebuffer(IGLDevice::Framebuffer,
									framebuffer);
			device->Viewport(0, 0, textureSize, textureSize);
			device->ClearDepth(1.f);
			device->Clear(IGLDevice::DepthBufferBit);
			
			RenderShadowMapPass();
			
			device->BindFramebuffer(IGLDevice::Framebuffer,
									lastFb);
			
			device->Viewport(0, 0, device->ScreenWidth(), device->ScreenHeight());
			
		}
Exemple #3
0
int main (int argc, char *argv[]) {
	if (argc != 2) {
		printf("usage: ./tokenize tm_file\n");
		exit(1);
	} else if (argc == 2) {
		FILE *fp;
		fp = fopen ( argv[1], "r");
		if ( fp == NULL ) {
			// something went wrong
			perror( argv[1] );
			exit( 1 );
		}
		// build matrix
		TransMatrix transMatrix = BuildMatrix(fp);
		// print matrix
		displayMatrix(transMatrix);
		/* process stdin and print state transitions from start
		to accepting state until end of file	
		*/
		while(Scanner(transMatrix) != EOF);
		//Scanner(transMatrix);
		// close the stream
		fclose(fp);
		}
	return 0;
}
Exemple #4
0
void MultiFlowLevMar::LevMarBuildMatrixForBead ( int ibd,
    bool well_only_fit,
    reg_params &eval_rp, NucStep &cache_step,

    BkgFitMatrixPacker *well_fit,
    unsigned int PartialDeriv_mask,
    int iter )
{
  // get the current parameter values for this bead
  bead_params eval_params = bkg.region_data->my_beads.params_nn[ibd];
  // make custom emphasis vector for this well using pointers to the per-HP vectors
  DynamicEmphasis ( eval_params );
  lev_mar_scratch.FillObserved ( bkg.region_data->my_trace, eval_params.trace_ndx );
  // now we're set up, do the individual steps
  ComputePartialDerivatives ( eval_params, eval_rp, cache_step, PartialDeriv_mask );
  lm_state.residual[ibd] = lev_mar_scratch.CalculateFitError ( NULL,NUMFB );

  if ( ( ibd == bkg.region_data->my_beads.DEBUG_BEAD ) && ( bkg.my_debug.trace_dbg_file != NULL ) )
  {
    bkg.my_debug.DebugBeadIteration ( eval_params,eval_rp, iter, lm_state.residual[ibd],&bkg.region_data->my_regions );
  }

  // assemble jtj matrix and rhs matrix for per-well fitting
  // only the non-zero elements of computed
  // automatically start a new matrix
  BuildMatrix ( well_fit,false, ( ibd == bkg.region_data->my_beads.DEBUG_BEAD ) );
}
Exemple #5
0
// assumes use of the cached regional derivative steps & nuc_step precomputation
void MultiFlowLevMar::AccumulateRegionDerivForOneBead (
  int ibd, int &reg_wells,
  BkgFitMatrixPacker *reg_fit, unsigned int PartialDeriv_mask,
  int iter )
{
  // get the current parameter values for this bead
  bead_params eval_params = bkg.region_data->my_beads.params_nn[ibd];
  // make custom emphasis vector for this well using pointers to the per-HP vectors
  DynamicEmphasis ( eval_params );
  lev_mar_scratch.FillObserved ( bkg.region_data->my_trace, eval_params.trace_ndx );
  // now we're set up, do the individual steps
  ComputeCachedPartialDerivatives ( eval_params, PartialDeriv_mask );
  lm_state.residual[ibd] = lev_mar_scratch.CalculateFitError ( NULL,NUMFB );

  if ( ( ibd == bkg.region_data->my_beads.DEBUG_BEAD ) && ( bkg.my_debug.trace_dbg_file != NULL ) )
  {
    bkg.my_debug.DebugBeadIteration ( eval_params,step_rp[0], iter,lm_state.residual[ibd],&bkg.region_data->my_regions );
  }

  lm_state.reg_error += lm_state.residual[ibd];

  if ( lm_state.WellBehavedBead ( ibd ) ) // only use "well-behaved" wells at any iteration
  {
    // if  reg_wells>0, continue same matrix, otherwise start a new one
    BuildMatrix ( reg_fit, ( reg_wells>0 ), ( ibd==bkg.region_data->my_beads.DEBUG_BEAD ) );
    reg_wells++;
  }
}
Exemple #6
0
void MultiFlowLevMar::LevMarBuildMatrixForBead (int ibd,
    float *ival, float *sbg,
    bool well_only_fit,
    reg_params &eval_rp,
    BkgFitMatrixPacker *well_fit, unsigned int PartialDeriv_mask,
    int iter, float *fvdbg, float *BackgroundDebugTapA, float *BackgroundDebugTapB)
{
  // get the current parameter values for this bead
  bead_params eval_params = bkg.my_beads.params_nn[ibd];
  // make custom emphasis vector for this well using pointers to the per-HP vectors
  DynamicEmphasis(eval_params);
  bkg.my_scratch.FillObserved (bkg.my_trace, eval_params.trace_ndx);
  // now we're set up, do the individual steps
  ComputePartialDerivatives (eval_params, eval_rp, PartialDeriv_mask,ival, sbg, (ibd == bkg.my_beads.DEBUG_BEAD));  //@TODO: this has side effect of computing residual - make explicit???
  lm_state.residual[ibd] = bkg.my_scratch.CalculateFitError (NULL,NUMFB);

  if ( (ibd == bkg.my_beads.DEBUG_BEAD) && (bkg.my_debug.trace_dbg_file != NULL))
  {
    bkg.DebugBeadIteration (eval_params,eval_rp, iter, ibd);
    bkg.my_trace.GetShiftedBkg (bkg.my_regions.rp.tshift,BackgroundDebugTapA);
    //CalcXtalkFlux(ibd,BackgroundDebugTapB);
    memcpy (fvdbg,bkg.my_scratch.fval,sizeof (float) *bkg.my_scratch.bead_flow_t);
  }

  // assemble jtj matrix and rhs matrix for per-well fitting
  // only the non-zero elements of computed
  // automatically start a new matrix
  BuildMatrix (well_fit,false, (ibd == bkg.my_beads.DEBUG_BEAD));
}
// Update internal segment data
void CCPACSFuselagePositioning::Update(void)
{
    if (!invalidated) {
        return;
    }

    BuildMatrix();
    invalidated = false;
}
		void GLBasicShadowMapRenderer::Render() {
			SPADES_MARK_FUNCTION();

			IGLDevice::Integer lastFb = device->GetInteger(IGLDevice::FramebufferBinding);

			// client::SceneDefinition def = GetRenderer()->GetSceneDef();

			float nearDist = 0.f;

			for (int i = 0; i < NumSlices; i++) {

				GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Slice %d / %d", i + 1, (int)NumSlices);

				float farDist = 0.0;
				// TODO: variable far distance according to the scene definition
				//       (note that this needs uniform shader variable)
				switch (i) {
					case 0: farDist = 12.f; break;
					case 1: farDist = 40.f; break;
					case 2: farDist = 150.f; break;
				}

				BuildMatrix(nearDist, farDist);
				matrices[i] = matrix;
				/*
				printf("m[%d]=\n[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n",
				       i, matrix.m[0], matrix.m[4], matrix.m[8], matrix.m[12],
				       matrix.m[1], matrix.m[5], matrix.m[9], matrix.m[13],
				       matrix.m[2], matrix.m[6], matrix.m[10], matrix.m[14],
				       matrix.m[3], matrix.m[7], matrix.m[11], matrix.m[15]);*/
				/*
				matrix = Matrix4::Identity();
				matrix = Matrix4::Scale(1.f / 16.f);
				matrix = matrix * Matrix4::Rotate(MakeVector3(1, 0, 0), M_PI / 4.f);
				matrix = matrix * Matrix4::Translate(-def.viewOrigin);
				matrix = Matrix4::Scale(1,1,16.f / 70.f) * matrix;*/

				device->BindFramebuffer(IGLDevice::Framebuffer, framebuffer[i]);
				device->Viewport(0, 0, textureSize, textureSize);
				device->ClearDepth(1.f);
				device->Clear(IGLDevice::DepthBufferBit);

				RenderShadowMapPass();

				nearDist = farDist;
			}

			device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);

			device->Viewport(0, 0, device->ScreenWidth(), device->ScreenHeight());
		}
Exemple #9
0
bool wordBreak(string strtomatch, unordered_set<string> &myset) {
    unsigned strlength = strtomatch.length();

    BuildMatrix(&pmatrix,strlength,strlength);

    for(int i=0;i<strlength;++i){
        for(int j=i;j<strlength;++j){
            pmatrix[i][j] = false;
        }
    }

    for(unsigned i=0;i<strlength;++i){
        for(unsigned j=i;j<strlength;++j){
            string strdata;
            strdata.assign(strtomatch,i,j-i+1);
            if(myset.find(strdata)!=myset.end()){
                pmatrix[i][j] = true;
            }
        }
    }

    for(int i=strlength-1;i>=0;--i){
        bool isallfalse = true;
        for(int j = i;j<strlength;++j){
            if(pmatrix[i][j]){
                isallfalse = false;
                break;
            }
        }

        if(isallfalse&&(i-1>=0)){
            for(int j = 0;j<strlength;++j){
                pmatrix[j][i-1] = false;
            }
        }
    }

    bool ret = FindWord(strlength);

    ReleaseMatrix(&pmatrix,strtomatch.length());
    
    return ret;
}
Exemple #10
0
/*!
 */
void polynomial::Solve()
{
    int O;

    O = GlobalO;
    if (XYCount() <= O)
        O = XYCount() - 1;

    if (O >= 0)
    {
        BuildMatrix(O);

		GaussSolve(O);
		while (1 < O)
		{
			C[0] = 0.0f;
			O = O - 1;
			FinalizeMatrix(O);
		}
    }
}
/**********************Main Function*********************************************/
int main(int argc, char ** argv)
{
	int length, source, destination, myrank, nprocs, rem_values, rank, i, j, l, m, s, r;
	const int serverrank = 0;
	char* filename = argv[1];
/***********************Read in file*********************************************/	
	FILE *ifp;
	ifp = fopen(filename,"r");
	if (ifp == NULL)
	{
		printf("Error opening file! \n");
		exit(1);
	}

	// Read in the first value which will be the length
	fscanf(ifp,"%d", &length);
	double *x = malloc(length*sizeof(double));
	//printf("the length is: %d \n",length);

	// Read in the rest of the values to an array
	//printf("In main z is equal to: \n");
	for (i=0;i<length;i++)
	{
		fscanf(ifp,"%lf", &x[i]);
		//printf("%f \n", x[i]);
	}

	fclose(ifp);
/*************************Set up MPI********************************************/
	MPI_Status status;
	MPI_Request request;
	
	int tag = 0;
	int mpi_error_code;
	//length = 6;
	//double x[] = {0,-25,3.8,7,54.9999,12};
	//double *y = malloc(length*sizeof(double));
	double **matrix1, **matrix2, *C, *y, *A;
	int size_per_processor; 
	int solution_count = 0;
	l = solution_count;

	mpi_error_code = MPI_Init(&argc, &argv);
	mpi_error_code = MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
	mpi_error_code = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

	/********************************************************************************
	Steps: 
		   1. Break up the input array into smaller arrays depending on the number of 
			  processors.
		   2. Processors sort their arrays using merge sort.
		   3. The sorted arrays are then merged together on alternating processers
		   	  using merger.
		   4. Serverrank outputs the result to a file.
		   5. Serverrank prints results and time.

	********************************************************************************/
	startT = clock();
	/***************** 1. Break up the array *************************
	This initial array is broken up into smaller arrays depending 
	on the number of processors.
	*****************************************************************/
	/* Get the size of arrays per processor */
	size_per_processor = length/nprocs;
		
	/* Get the remainder values */
	rem_values = length % nprocs;
	if (myrank == serverrank) //Debugg
	{
		//printf("The remainder is: %d \n", rem_values);
		//printf("size_per_processor is equal to: %d \n", size_per_processor);
		//printf("The number of processors is: %d \n", nprocs);
	}
	/* Create two double matrices to store the arrays */
	matrix1 = BuildMatrix(nprocs - rem_values,size_per_processor);
	matrix2 = BuildMatrix(rem_values, size_per_processor+1);
	
	/* Fill matrix 1 */
	int count = 0;
	for (i=0; i<nprocs-rem_values; i++)
	{
		for (j=0; j<size_per_processor; j++)
		{
			matrix1[i][j] = x[count];
			count++;
		}
	}

	/* Fill matrix 2 (contains the remainder values) */
	for (i=0;i<rem_values;i++)
	{
		for (j=0; j<size_per_processor+1; j++)
		{
			matrix2[i][j] = x[count];
			count++;
		}
	}

	/*********Print for debugging************************/
	if (myrank == serverrank)
	{
	//printf("Filled Matrix 1 is: \n");
	for (i=0; i<nprocs-rem_values; i++)
	{
		for (j=0; j<size_per_processor; j++)
		{
			//printf("%f",matrix1[i][j]);
			if (j == size_per_processor-1)
			{
				//printf("\n");
			}
		}
	}
	//printf("Filled Matrix 2 is: \n");
	for (i=0; i<rem_values; i++)
	{
		for (j=0; j<size_per_processor+1; j++)
		{
			//printf("%f",matrix2[i][j]);
			if (j == size_per_processor)
			{
				//printf("\n");
			}
		}
	}
	}
	/************************************************************
		Step 2: Processors merge sort their arrays.

	*************************************************************/
	for (rank=0; rank<nprocs-rem_values;rank++)
	{
		if (myrank == rank)
		{
			A = calloc(size_per_processor, sizeof(double));
			//printf("Hello from rank: %d\n",myrank);
			for (i=0;i<size_per_processor;i++)
			{
				A[i] = matrix1[rank][i];
			}

			// Merge Sort A
			mergeSort(A, 0, size_per_processor-1);
		}
	}
	//B[size_per_processor+1] = matrix2[3][size_per_processor+1];

	for (rank=nprocs-rem_values; rank<nprocs; rank++)
	{
		if (myrank == rank)
		{
			size_per_processor = size_per_processor+1;
			A = calloc(size_per_processor, sizeof(double));
			for (i=0; i<size_per_processor;i++)
			{
				A[i] = matrix2[rank-(nprocs-rem_values)][i];	
			}
			
			// Merge sort B
			mergeSort(A, 0, size_per_processor-1);
		}
	}
	/*
	//Print for debugging
	for (rank=0; rank<nprocs;rank++)
	{
		if (myrank == rank)
		{
			printf("Size per processor is: %d on processor %d\n", size_per_processor,myrank);
			printf("A is equal to %f on processor %d\n", A[0],myrank);
		}
	}
	*/
	/***************************************************************
		Step 3: Merge all of the sorted arrays by alternating
				processors for each step one half as many processors
				are being used, The serverrank does the final merger.

	***************************************************************/
	//Starts here (Remove this and it will work with nprocs =2 )
		
	count = 1;
	while(count<nprocs)
	{
		if( myrank%(2*count)==0)
		{
			if (myrank+count<nprocs)
			{
				source = myrank+count;
				//receive size_per_processor first
				mpi_error_code = MPI_Recv(&s, 1, MPI_INT, source, 0, MPI_COMM_WORLD, &status);
				//allocate size of C
				C = (double *)malloc(s*sizeof(double));
				//receive A (call it C) from myrank+count
				mpi_error_code = MPI_Recv(C, s, MPI_DOUBLE, source, 0, MPI_COMM_WORLD, &status);

				A = merger(A,size_per_processor,C,s);
				
				//update size_per_processor
				size_per_processor=size_per_processor + s;
			}
		}
		else
		{
			//get destination
			int near = myrank-count;
			//send size_per_processor to near
			mpi_error_code = MPI_Send(&size_per_processor, 1, MPI_INT, near, 0, MPI_COMM_WORLD);
			//send A to near
			mpi_error_code = MPI_Send(A, size_per_processor, MPI_DOUBLE, near, 0, MPI_COMM_WORLD);
			//Break out of while loop
			break;
		}
		count = count*2;
	}
// Ends here
	stopT = clock();

	/***************************************************************
		Step 4: Server outputs results to a file, named "output"
	***************************************************************/
	if(myrank==0)
	{
		FILE * fout;

		// Display size, number of processors, and time
		printf("\n-------------------------------\n");
		printf("\n *MPI Results*\n Size of Array: %d;\n Processors   : %d;\n Time Elapsed : %f secs;\n",size_per_processor,nprocs,(stopT-startT)/CLOCKS_PER_SEC);
		printf("\n-------------------------------\n");
		fout = fopen("output","w");
		for(i=0;i<size_per_processor;i++)
			fprintf(fout,"%f\n",A[i]);
		fclose(fout);
	}

	//free memory
	//free (A);
	//free (B);
	free (matrix1);
	free (matrix2);

	mpi_error_code = MPI_Finalize();
}
void SFBerlekamp(vec_ZZ_pX& factors, const ZZ_pX& ff, long verbose)
{
   ZZ_pX f = ff;

   if (!IsOne(LeadCoeff(f)))
      Error("SFBerlekamp: bad args");

   if (deg(f) == 0) {
      factors.SetLength(0);
      return;
   }

   if (deg(f) == 1) {
      factors.SetLength(1);
      factors[0] = f;
      return;
   }

   double t;

   const ZZ& p = ZZ_p::modulus();

   long n = deg(f);

   ZZ_pXModulus F;

   build(F, f);

   ZZ_pX g, h;

   if (verbose) { cerr << "computing X^p..."; t = GetTime(); }
   PowerXMod(g, p, F);
   if (verbose) { cerr << (GetTime()-t) << "\n"; }

   vec_long D;
   long r;

   vec_ZZVec M;

   if (verbose) { cerr << "building matrix..."; t = GetTime(); }
   BuildMatrix(M, n, g, F, verbose);
   if (verbose) { cerr << (GetTime()-t) << "\n"; }

   if (verbose) { cerr << "diagonalizing..."; t = GetTime(); }
   NullSpace(r, D, M, verbose);
   if (verbose) { cerr << (GetTime()-t) << "\n"; }


   if (verbose) cerr << "number of factors = " << r << "\n";

   if (r == 1) {
      factors.SetLength(1);
      factors[0] = f;
      return;
   }

   if (verbose) { cerr << "factor extraction..."; t = GetTime(); }

   vec_ZZ_p roots;

   RandomBasisElt(g, D, M);
   MinPolyMod(h, g, F, r);
   if (deg(h) == r) M.kill();
   FindRoots(roots, h);
   FindFactors(factors, f, g, roots);

   ZZ_pX g1;
   vec_ZZ_pX S, S1;
   long i;

   while (factors.length() < r) {
      if (verbose) cerr << "+";
      RandomBasisElt(g, D, M);
      S.kill();
      for (i = 0; i < factors.length(); i++) {
         const ZZ_pX& f = factors[i];
         if (deg(f) == 1) {
            append(S, f);
            continue;
         }
         build(F, f);
         rem(g1, g, F);
         if (deg(g1) <= 0) {
            append(S, f);
            continue;
         }
         MinPolyMod(h, g1, F, min(deg(f), r-factors.length()+1));
         FindRoots(roots, h);
         S1.kill();
         FindFactors(S1, f, g1, roots);
         append(S, S1);
      }
      swap(factors, S);
   }

   if (verbose) { cerr << (GetTime()-t) << "\n"; }

   if (verbose) {
      cerr << "degrees:";
      long i;
      for (i = 0; i < factors.length(); i++)
         cerr << " " << deg(factors[i]);
      cerr << "\n";
   }
}
Exemple #13
0
void CKinematics::AddWallmark(const Fmatrix* parent_xform, const Fvector3& start, const Fvector3& dir, ref_shader shader, float size)
{
	Fvector S,D,normal		= {0,0,0};
	// transform ray from world to model
	Fmatrix P;	P.invert	(*parent_xform);
	P.transform_tiny		(S,start);
	P.transform_dir			(D,dir);
	// find pick point
	float dist				= flt_max;
	BOOL picked				= FALSE;

	DEFINE_VECTOR			(Fobb,OBBVec,OBBVecIt);
	OBBVec					cache_obb;
	cache_obb.resize		(LL_BoneCount());

	for (u16 k=0; k<LL_BoneCount(); k++){
		CBoneData& BD		= LL_GetData(k);
		if (LL_GetBoneVisible(k)&&!BD.shape.flags.is(SBoneShape::sfNoPickable)){
			Fobb& obb		= cache_obb[k];
			obb.transform	(BD.obb,LL_GetBoneInstance(k).mTransform);
			if (CDB::TestRayOBB(S,D, obb))
				for (u32 i=0; i<children.size(); i++)
					if (LL_GetChild(i)->PickBone(normal,dist,S,D,k)) picked=TRUE;
		}
	}
	if (!picked) return; 
 
	// calculate contact point
	Fvector cp;	cp.mad		(S,D,dist); 
 
	// collect collide boxes
	Fsphere test_sphere;
    test_sphere.set			(cp,size); 
	U16Vec					test_bones;
	test_bones.reserve		(LL_BoneCount());
	for (k=0; k<LL_BoneCount(); k++){
		CBoneData& BD		= LL_GetData(k);  
		if (LL_GetBoneVisible(k)&&!BD.shape.flags.is(SBoneShape::sfNoPickable)){
			Fobb& obb		= cache_obb[k];
			if (CDB::TestSphereOBB(test_sphere, obb))
				test_bones.push_back(k);
		}
	}

	// find similar wm
	for (u32 wm_idx=0; wm_idx<wallmarks.size(); wm_idx++){
		intrusive_ptr<CSkeletonWallmark>& wm = wallmarks[wm_idx];		
		if (wm->Similar(shader,cp,0.02f)){ 
			if (wm_idx<wallmarks.size()-1) 
				wm = wallmarks.back();
			wallmarks.pop_back();
			break;
		}
	}

	// ok. allocate wallmark
	intrusive_ptr<CSkeletonWallmark>		wm = xr_new<CSkeletonWallmark>(this,parent_xform,shader,cp,Device.fTimeGlobal);
	wm->m_LocalBounds.set		(cp,size*2.f);
	wm->XFORM()->transform_tiny	(wm->m_Bounds.P,cp);
	wm->m_Bounds.R				= wm->m_Bounds.R; 

	Fvector tmp; tmp.invert		(D);
	normal.add(tmp).normalize	();

	// build UV projection matrix
	Fmatrix						mView,mRot;
	BuildMatrix					(mView,1/(0.9f*size),normal,cp);
	mRot.rotateZ				(::Random.randF(deg2rad(-20.f),deg2rad(20.f)));
	mView.mulA_43				(mRot);

	// fill vertices
	for (u32 i=0; i<children.size(); i++){
		CSkeletonX* S		= LL_GetChild(i);
		for (U16It b_it=test_bones.begin(); b_it!=test_bones.end(); b_it++)
			S->FillVertices		(mView,*wm,normal,size,*b_it);
	}

	wallmarks.push_back		(wm);
}
Exemple #14
0
void LoadBalance3d(Mesh *mesh){

  int n,p,k,v,f;

  int nprocs = mesh->nprocs;
  int procid = mesh->procid;
  int **EToV = mesh->EToV;
  double **VX = mesh->GX;
  double **VY = mesh->GY;
  double **VZ = mesh->GZ;

  if(!procid) printf("Root: Entering LoadBalance\n");

  int Nverts = mesh->Nverts;
  
  int *Kprocs = BuildIntVector(nprocs);

  /* local number of elements */
  int Klocal = mesh->K;

  /* find number of elements on all processors */
  MPI_Allgather(&Klocal, 1, MPI_INT, Kprocs, 1, MPI_INT, MPI_COMM_WORLD);

  /* element distribution -- cumulative element count on processes */
  idxtype *elmdist = idxmalloc(nprocs+1, "elmdist");

  elmdist[0] = 0;
  for(p=0;p<nprocs;++p)
    elmdist[p+1] = elmdist[p] + Kprocs[p];

  /* list of element starts */
  idxtype *eptr = idxmalloc(Klocal+1, "eptr");

  eptr[0] = 0;
  for(k=0;k<Klocal;++k)
    eptr[k+1] = eptr[k] + Nverts;

  /* local element to vertex */
  idxtype *eind = idxmalloc(Nverts*Klocal, "eind");

  for(k=0;k<Klocal;++k)
    for(n=0;n<Nverts;++n)
      eind[k*Nverts+n] = EToV[k][n];

  /* weight per element */
  idxtype *elmwgt = idxmalloc(Klocal, "elmwgt");

  for(k=0;k<Klocal;++k)
    elmwgt[k] = 1.;
  
  /* weight flag */
  int wgtflag = 0;
  
  /* number flag (1=fortran, 0=c) */
  int numflag = 0;

  /* ncon = 1 */
  int ncon = 1;

  /* nodes on element face */
  int ncommonnodes = 3;
  
  /* number of partitions */
  int nparts = nprocs;

  /* tpwgts */
  float *tpwgts = (float*) calloc(Klocal, sizeof(float));
 
  for(k=0;k<Klocal;++k)
    tpwgts[k] = 1./(float)nprocs;

  float ubvec[MAXNCON];

  for (n=0; n<ncon; ++n)
    ubvec[n] = UNBALANCE_FRACTION;
  
  int options[10];
  
  options[0] = 1;
  options[PMV3_OPTION_DBGLVL] = 7;
  options[PMV3_OPTION_SEED] = 0;

  int edgecut;

  idxtype *part = idxmalloc(Klocal, "part");

  MPI_Comm comm;
  MPI_Comm_dup(MPI_COMM_WORLD, &comm);

  ParMETIS_V3_PartMeshKway
    (elmdist, 
     eptr, 
     eind, 
     elmwgt, 
     &wgtflag, 
     &numflag, 
     &ncon, 
     &ncommonnodes,
     &nparts, 
     tpwgts, 
     ubvec, 
     options, 
     &edgecut,
     part, 
     &comm);

  int **outlist = (int**) calloc(nprocs, sizeof(int*));
  double **xoutlist = (double**) calloc(nprocs, sizeof(double*));
  double **youtlist = (double**) calloc(nprocs, sizeof(double*));
  double **zoutlist = (double**) calloc(nprocs, sizeof(double*));

  int *outK = (int*) calloc(nprocs, sizeof(int));
  
  int *inK = (int*) calloc(nprocs, sizeof(int));

  MPI_Request *inrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));
  MPI_Request *outrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));
  MPI_Request *xinrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));
  MPI_Request *xoutrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));
  MPI_Request *yinrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));
  MPI_Request *youtrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));
  MPI_Request *zinrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));
  MPI_Request *zoutrequests = (MPI_Request*) calloc(nprocs, sizeof(MPI_Request));

  for(k=0;k<Klocal;++k)
    ++outK[part[k]];
  
  /* get count of incoming elements from each process */
  MPI_Alltoall(outK, 1, MPI_INT, 
	       inK,  1, MPI_INT, 
	       MPI_COMM_WORLD);

  /* count totals on each process */
  int *  newKprocs = BuildIntVector(nprocs);
  MPI_Allreduce(outK, newKprocs, nprocs, MPI_INT, MPI_SUM, MPI_COMM_WORLD);

  int totalinK = 0;
  for(p=0;p<nprocs;++p){
    totalinK += inK[p];
  }

  int **newEToV = BuildIntMatrix(totalinK, Nverts);
  double **newVX   = BuildMatrix(totalinK, Nverts);
  double **newVY   = BuildMatrix(totalinK, Nverts);
  double **newVZ   = BuildMatrix(totalinK, Nverts);
  
  int cnt = 0;
  for(p=0;p<nprocs;++p){
    MPI_Irecv(newEToV[cnt], Nverts*inK[p], MPI_INT, p, 666+p, MPI_COMM_WORLD,
	      inrequests+p);
    MPI_Irecv(newVX[cnt], Nverts*inK[p], MPI_DOUBLE, p, 1666+p, MPI_COMM_WORLD,
	      xinrequests+p);
    MPI_Irecv(newVY[cnt], Nverts*inK[p], MPI_DOUBLE, p, 2666+p, MPI_COMM_WORLD,
	      yinrequests+p);
    MPI_Irecv(newVZ[cnt], Nverts*inK[p], MPI_DOUBLE, p, 3666+p, MPI_COMM_WORLD,
	      zinrequests+p);
    cnt = cnt + inK[p];
  }

  for(p=0;p<nprocs;++p){
    int cnt = 0;
    outlist[p]  = BuildIntVector(Nverts*outK[p]);
    xoutlist[p]  = BuildVector(Nverts*outK[p]);
    youtlist[p]  = BuildVector(Nverts*outK[p]);
    zoutlist[p]  = BuildVector(Nverts*outK[p]);

    for(k=0;k<Klocal;++k)
      if(part[k]==p){
	for(v=0;v<Nverts;++v){
	  outlist[p][cnt] = EToV[k][v]; 
	  xoutlist[p][cnt] = VX[k][v];
	  youtlist[p][cnt] = VY[k][v];
	  zoutlist[p][cnt] = VZ[k][v];
	  ++cnt;
	}
      }
    
    MPI_Isend(outlist[p], Nverts*outK[p], MPI_INT, p, 666+procid, MPI_COMM_WORLD, 
	      outrequests+p);
    MPI_Isend(xoutlist[p], Nverts*outK[p], MPI_DOUBLE, p, 1666+procid, MPI_COMM_WORLD, 
	      xoutrequests+p);
    MPI_Isend(youtlist[p], Nverts*outK[p], MPI_DOUBLE, p, 2666+procid, MPI_COMM_WORLD, 
	      youtrequests+p);
    MPI_Isend(zoutlist[p], Nverts*outK[p], MPI_DOUBLE, p, 3666+procid, MPI_COMM_WORLD, 
	      zoutrequests+p);
  }

  MPI_Status *instatus = (MPI_Status*) calloc(nprocs, sizeof(MPI_Status));
  MPI_Status *outstatus = (MPI_Status*) calloc(nprocs, sizeof(MPI_Status));

  MPI_Waitall(nprocs,  inrequests, instatus);
  MPI_Waitall(nprocs, xinrequests, instatus);
  MPI_Waitall(nprocs, yinrequests, instatus);
  MPI_Waitall(nprocs, zinrequests, instatus);

  MPI_Waitall(nprocs,  outrequests, outstatus);
  MPI_Waitall(nprocs, xoutrequests, outstatus);
  MPI_Waitall(nprocs, youtrequests, outstatus);
  MPI_Waitall(nprocs, zoutrequests, outstatus);

  if(mesh->GX!=NULL){
    DestroyMatrix(mesh->GX);
    DestroyMatrix(mesh->GY);
    DestroyMatrix(mesh->GZ);
    DestroyIntMatrix(mesh->EToV);
  }

  mesh->GX = newVX;
  mesh->GY = newVY;
  mesh->GZ = newVZ;
  mesh->EToV = newEToV;
  mesh->K =  totalinK;

  for(p=0;p<nprocs;++p){
    if(outlist[p]){
      free(outlist[p]);
      free(xoutlist[p]);
      free(youtlist[p]);
      free(zoutlist[p]);
    }
  }

  free(outK);
  free(inK);
  
  free(inrequests);
  free(outrequests);

  free(xinrequests);
  free(xoutrequests);
  free(yinrequests);
  free(youtrequests);
  free(zinrequests);
  free(zoutrequests);
  free(instatus);
  free(outstatus);

}
Exemple #15
0
int 
CGenedocDoc::ProcessRecord( stcSearch *pSearch, GeneStor *pGeneStor, DWORD SeqLength, int Test )
{
    GeneStor *end, *begin;
    GeneStor *ptr;

    DWORD start;
    int found;
    int i;

	int length = BuildMatrix( pSearch->strSearch );

	// Test bad syntax
	if ( length == 0 ) return 0;

	end = pGeneStor + SeqLength;

    /* Signal Processing */
    begin = Csignal? end : pGeneStor;
    if( Nsignal ) end = begin+1;

    found = 0;

    for ( ptr=begin; ptr<end; ptr++ )
    {    
		char tChar = toupper(ptr->CharGene);
		if ( !(tChar >= 'A' && tChar <= 'Z' ) ) continue;
		if( !(i=LocateMotif(ptr,0,length, end)) ) continue;
		if ( Test ) return 1;

         start = ptr - pGeneStor;
//         if( found )
//         {
//			if( start > MotifStop )
//			{
//				MotifStop = start+i;
//				MotifStart = start;
//			} else 
//				 MotifStop = start+i;

//         } else {   

			MotifStop = start+i;
			MotifStart = start;
			found = 1;
//		}

		 // Color Here ..

		int shd = (int)(MotifStop - MotifStart);
		for ( int j=0; j<shd; ++j ) {
//			char tChar = toupper(pGeneStor[start+j].CharGene);
			char tChar = toupper(pGeneStor[MotifStart+j].CharGene);
			if ( tChar >= 'A' && tChar <= 'Z' ) {
				pGeneStor[MotifStart+j].TextColor = pSearch->rgbText;
				pGeneStor[MotifStart+j].BackColor = pSearch->rgbBack;
			} else {
				++shd;
			}
		}
	}

	return found;

}
Exemple #16
0
Mesh *ReadMesh3d(char *filename){

  int n;

  Mesh *mesh = (Mesh*) calloc(1, sizeof(Mesh));

  char buf[BUFSIZ];
  
  FILE *fp = fopen(filename, "r");

  /* assume modified Gambit neutral format */
  for(n=0;n<6;++n)
    fgets(buf, BUFSIZ, fp);

  fgets(buf, BUFSIZ, fp);
  sscanf(buf, "%d %d \n", &(mesh->Nv), &(mesh->K));
  mesh->Nverts = 4; /* assume tets */
  mesh->Nedges = 6; /* assume tets */
  mesh->Nfaces = 4; /* assume tets */

  fgets(buf, BUFSIZ, fp);
  fgets(buf, BUFSIZ, fp);

  /* read vertex coordinates */
  double *VX = BuildVector(mesh->Nv);
  double *VY = BuildVector(mesh->Nv);
  double *VZ = BuildVector(mesh->Nv);
  for(n=0;n<mesh->Nv;++n){
    fgets(buf, BUFSIZ, fp);
    sscanf(buf, "%*d %lf %lf %lf", VX+n, VY+n, VZ+n);
  }

  /* decide on parition */
  int procid, nprocs;

  MPI_Comm_rank(MPI_COMM_WORLD, &procid);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

  mesh->procid = procid;
  mesh->nprocs = nprocs;

  /* assume this proc owns a block of elements */

  int Klocal, Kstart;
  int *Kprocs = (int*) calloc(nprocs, sizeof(int));
  int p;
  
  int **newEToV, *newKprocs;
  double **newVX, **newVY;
  
  Klocal = (int) ( (double)(mesh->K)/(double)nprocs );
  
  for(p=0;p<nprocs-1;++p){
    Kprocs[p] = Klocal;
  }
  Kprocs[p] = Klocal + mesh->K - nprocs*Klocal;
  
  
  Kstart= 0;
  for(p=0;p<procid;++p)
    Kstart += Kprocs[p];
  
  Klocal = Kprocs[procid];

  /* read element to vertex connectivity */
  fgets(buf, BUFSIZ, fp);
  fgets(buf, BUFSIZ, fp);
  mesh->EToV = BuildIntMatrix(Klocal, mesh->Nverts);
  mesh->GX = BuildMatrix(Klocal, mesh->Nverts);
  mesh->GY = BuildMatrix(Klocal, mesh->Nverts);
  mesh->GZ = BuildMatrix(Klocal, mesh->Nverts);

  int sk = 0, v;
  for(n=0;n<mesh->K;++n){
    fgets(buf, BUFSIZ, fp);
    if(n>=Kstart && n<Kstart+Klocal){
      sscanf(buf, "%*d %*d %*d %d %d %d %d", 
	     mesh->EToV[sk]+0, mesh->EToV[sk]+1,
	     mesh->EToV[sk]+2, mesh->EToV[sk]+3);
      
      /* correct to 0-index */
      --(mesh->EToV[sk][0]);
      --(mesh->EToV[sk][1]);
      --(mesh->EToV[sk][2]);
      --(mesh->EToV[sk][3]);

      for(v=0;v<mesh->Nverts;++v){
	mesh->GX[sk][v] = VX[mesh->EToV[sk][v]];
	mesh->GY[sk][v] = VY[mesh->EToV[sk][v]];
	mesh->GZ[sk][v] = VZ[mesh->EToV[sk][v]];
      }

      ++sk;
    }
  }
  fgets(buf, BUFSIZ, fp);
  fgets(buf, BUFSIZ, fp);

  mesh->K = Klocal;

  fclose(fp);

  return mesh;
  
}
Exemple #17
0
int main(int argc, char* argv[])
{
/********Get Filenames***************/
	char* matrix_A = argv[1];
	char* matrix_B = argv[2];
	char* matrix_C = argv[3];
	double **A, **B, **C, **AB, **BC, **ABC, **ABplusC, **AplusBC, **ABminusC, **AminusBC;
if (matrix_A == NULL || matrix_B == NULL || matrix_C == NULL)
{
	printf("Error improper input arguments entered!!\n");
	exit(1);
}
/********Get Dimensions******************/
	//printf("Getting dimensions of A: %c \n", *matrix_A);
	int dimension_A[2], dimension_B[2], dimension_C[2], dimension_AB[2], dimension_BC[2], dimension_ABC[2];
	int d_a, d_b, d_c, i, j;
	double a,b,c;
	FILE *file_1;
	FILE *file_2;
	FILE *file_3;
	file_1 = fopen(matrix_A, "r");
	file_2 = fopen(matrix_B, "r");
	file_3 = fopen(matrix_C, "r");
if (file_1 == NULL || file_2 == NULL || file_3 == NULL)
{
	printf("Error opening files! \n");
	exit(1);
}
// Get dimensions
	fscanf(file_1, "%d", &d_a);
	fscanf(file_2, "%d", &d_b);
	fscanf(file_3, "%d", &d_c);
	dimension_A[0] = d_a;
	dimension_B[0] = d_b;
	dimension_C[0] = d_c;
	fscanf(file_1, "%d", &d_a);
	fscanf(file_2, "%d", &d_b);
	fscanf(file_3, "%d", &d_c);
	dimension_A[1] = d_a;
	dimension_B[1] = d_b;
	dimension_C[1] = d_c;
// Get dimensions of AB BC
	dimension_AB[0] = dimension_A[0];
	dimension_AB[1] = dimension_B[1];
	dimension_BC[0] = dimension_B[0];
	dimension_BC[1] = dimension_C[1];
// Get dimensions of solution matrices 
	dimension_ABC[0] = dimension_AB[0];
	dimension_ABC[1] = dimension_C[1];
// Print dimensions
	//printf("The dimensions of %c are %d by %d \n", *matrix_A, dimension_A[0], dimension_A[1]);
	//printf("The dimensions of %c are %d by %d \n", *matrix_B, dimension_B[0], dimension_B[1]);
	//printf("The dimensions of %c are %d by %d \n", *matrix_C, dimension_C[0], dimension_C[1]);
	//printf("The dimensions of %c%c are %d by %d \n", *matrix_A, *matrix_B, dimension_AB[0], dimension_AB[1]);
	//printf("The dimensions of %c%c are %d by %d \n", *matrix_B, *matrix_C, dimension_BC[0], dimension_BC[1]);
	//printf("The dimensions of %c%c%c are %d by %d \n", *matrix_A, *matrix_B, *matrix_C, dimension_ABC[0], dimension_ABC[1]);
fclose(file_1);
fclose(file_2);
fclose(file_3);
/********Conditionals to stop********/
/********Build Solution Matrices*****/
	AB = BuildMatrix(dimension_AB[0], dimension_AB[1]);
	BC = BuildMatrix(dimension_BC[0], dimension_BC[1]);
	ABC = BuildMatrix(dimension_ABC[0], dimension_ABC[1]);
	ABplusC = BuildMatrix(dimension_AB[0], dimension_AB[1]);
	AplusBC = BuildMatrix(dimension_A[0], dimension_A[1]);
	ABminusC = BuildMatrix(dimension_AB[0], dimension_AB[1]);
	AminusBC = BuildMatrix(dimension_A[0], dimension_A[1]);

/*********Read in File 1 and make copies*************/
	A = FillMatrix(matrix_A);
	AplusBC = FillMatrix(matrix_A);
	AminusBC = FillMatrix(matrix_A);

/********Read in File 2**************/
	B = FillMatrix(matrix_B);

/*******Read in File 3 and make copies***************/
	C = FillMatrix(matrix_C);
	ABplusC = FillMatrix(matrix_C);
	ABminusC = FillMatrix(matrix_C);

/*******Add conditionals to make sure operations make sense**************/
// Run Cblas_dgemm for AB
if (dimension_A[1] == dimension_B[0])
{
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,dimension_A[0],dimension_B[1],dimension_A[1],1.0,*A,dimension_A[1],*B,dimension_B[1],0.0,*AB,dimension_AB[1]);
}
else
{
	printf("Cannot compute AB, dimensions don't match! \n");
}
// Run Cblas_dgemm for BC ************************************************
if (dimension_A[1] == dimension_B[0])
{
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,dimension_B[0],dimension_C[1],dimension_B[1],1.0,*B,dimension_B[1],*C,dimension_C[1],0.0,*BC,dimension_BC[1]);
}
else
{
	printf("Cannot compute BC, dimensions don't match! \n");
}
// Run Cblas_dgemm for ABC ************************************************
if (dimension_AB[1] == dimension_C[0])
{
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,dimension_AB[0],dimension_C[1],dimension_AB[1],1.0,*AB,dimension_AB[1],*C,dimension_C[1],0.0,*ABC,dimension_ABC[1]);

	// Create file name
	char file_name1[ sizeof "AAAA_mult_BBBB_mult_CCCC"]; // Add extra values for longer file names
	sprintf(file_name1, "%s_mult_%s_mult_%s", matrix_A, matrix_B, matrix_C);

	// Write to a file
	write_to_file(file_name1, ABC, dimension_ABC[0], dimension_ABC[1]);
}
else
{
	printf("Cannot compute ABC, dimensions don't match! \n");
}
// Compute AB +- C *********************************************************
if (dimension_AB[0] == dimension_C[0] && dimension_AB[1] == dimension_C[1])
{
	//printf("Still need to code AB +- C! \n");
	// AB + C
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,dimension_A[0],dimension_B[1],dimension_A[1],1.0,*A,dimension_A[1],*B,dimension_B[1],1.0,*ABplusC,dimension_C[1]);
	// AB - C
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,dimension_A[0],dimension_B[1],dimension_A[1],1.0,*A,dimension_A[1],*B,dimension_B[1],-1.0,*ABminusC,dimension_C[1]);

	// Create file names
	char file_name2[ sizeof "AAAA_mult_BBBB_plus_CCCC"]; // Add extra values for longer file names
	sprintf(file_name2, "%s_mult_%s_plus_%s", matrix_A, matrix_B, matrix_C);

	char file_name3[ sizeof "AAAA_mult_BBBB_minus_CCCC"]; // Add extra values for longer file names
	sprintf(file_name3, "%s_mult_%s_minus_%s", matrix_A, matrix_B, matrix_C);

	// Write to a file
	write_to_file(file_name2, ABplusC, dimension_C[0], dimension_C[1]);
	write_to_file(file_name3, ABminusC, dimension_C[0], dimension_C[1]);

}
else
{
	printf("Cannot compute AB +- C, dimensions don't match! \n");
}
// Compute A +- BC ********************************************************
if (dimension_A[0] == dimension_BC[0] && dimension_A[1] == dimension_BC[1])
{
	//printf("Still need to code A +- BC! \n");
	// A + BC
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,dimension_B[0],dimension_C[1],dimension_B[1],1.0,*B,dimension_B[1],*C,dimension_C[1],1.0,*AplusBC,dimension_A[1]);
	
	// A - BC 
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,dimension_B[0],dimension_C[1],dimension_B[1],-1.0,*B,dimension_B[1],*C,dimension_C[1],1.0,*AminusBC,dimension_A[1]);
	
	// Create file names
	char file_name4[ sizeof "AAAA_mult_BBBB_plus_CCCC"]; // Add extra values for longer file names
	sprintf(file_name4, "%s_plus_%s_mult_%s", matrix_A, matrix_B, matrix_C);

	char file_name5[ sizeof "AAAA_minus_BBBB_mult_CCCC"]; // Add extra values for longer file names
	sprintf(file_name5, "%s_minus_%s_mult_%s", matrix_A, matrix_B, matrix_C);

	// Write to a file
	write_to_file(file_name4, AplusBC, dimension_A[0], dimension_A[1]);
	write_to_file(file_name5, AminusBC, dimension_A[0], dimension_A[1]);
}
else
{
	printf("Cannot compute A +- BC, dimensions don't match! \n");
}


/******Free memory*******************/
	free(A);
	free(B);
	free(C);
	free(AB);
	free(BC);
	free(ABC);
	free(ABplusC);
	free(AplusBC);
	free(ABminusC);
	free(AminusBC);
//return 0;
}
Exemple #18
0
void CWallmarksEngine::AddWallmark_internal	(CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hShader, float sz)
{
	// query for polygons in bounding box
	// calculate adjacency
	{
		Fbox				bb_query;
		Fvector				bbc,bbd;
		bb_query.set		(contact_point,contact_point);
		bb_query.grow		(sz*2.5f);
		bb_query.get_CD		(bbc,bbd);
		xrc.box_options		(CDB::OPT_FULL_TEST);
		xrc.box_query		(g_pGameLevel->ObjectSpace.GetStaticModel(),bbc,bbd);
		u32	triCount		= xrc.r_count	();
		if (0==triCount)	return;
		CDB::TRI* tris		= g_pGameLevel->ObjectSpace.GetStaticTris();
		sml_collector.clear	();
		sml_collector.add_face_packed_D	(pVerts[pTri->verts[0]],pVerts[pTri->verts[1]],pVerts[pTri->verts[2]],0);
		for (u32 t=0; t<triCount; t++)	{
			CDB::TRI*	T	= tris+xrc.r_begin()[t].id;
			if (T==pTri)	continue;
			sml_collector.add_face_packed_D		(pVerts[T->verts[0]],pVerts[T->verts[1]],pVerts[T->verts[2]],0);
		}
		sml_collector.calc_adjacency	(sml_adjacency);
	}

	// calc face normal
	Fvector	N;
	N.mknormal			(pVerts[pTri->verts[0]],pVerts[pTri->verts[1]],pVerts[pTri->verts[2]]);
	sml_normal.set		(N);

	// build 3D ortho-frustum
	Fmatrix				mView,mRot;
	BuildMatrix			(mView,1/sz,contact_point);
	mRot.rotateZ		(::Random.randF(deg2rad(-20.f),deg2rad(20.f)));
	mView.mulA_43		(mRot);
	sml_clipper.CreateFromMatrix	(mView,FRUSTUM_P_LRTB);

	// create wallmark
	static_wallmark* W	= static_wm_allocate();
	RecurseTri			(0,mView,*W);

	// calc sphere
	if (W->verts.size()<3) { static_wm_destroy(W); return; }
	else {
		Fbox bb;	bb.invalidate();

		FVF::LIT* I=&*W->verts.begin	();
		FVF::LIT* E=&*W->verts.end		();
		for (; I!=E; I++)	bb.modify	(I->p);
		bb.getsphere					(W->bounds.P,W->bounds.R);
	}

	if (W->bounds.R < 1.f)	
	{
		// search if similar wallmark exists
		wm_slot* slot			= FindSlot	(hShader);
		if (slot){
			StaticWMVecIt it	=	slot->static_items.begin	();
			StaticWMVecIt end	=	slot->static_items.end	();
			for (; it!=end; it++)	{
				static_wallmark* wm		=	*it;
				if (wm->bounds.P.similar(W->bounds.P,0.02f)){ // replace
					static_wm_destroy	(wm);
					*it					=	W;
					return;
				}
			}
		} else {
			slot		= AppendSlot(hShader);
		}

		// no similar - register _new_
		slot->static_items.push_back(W);
	}
}