Example #1
0
Vec3f CRSpline::GetInterpolatedSplinePoint(float t)
{
  // Find out in which interval we are on the spline
  int p = (int)(t / delta_t);
  // Compute local control point indices
#define BOUNDS(pp) { if (pp < 0) pp = 0; else if (pp >= (int)vp.size()-1) pp = (int)vp.size() - 1; }
  int p0 = p - 1;     BOUNDS(p0);
  int p1 = p;         BOUNDS(p1);
  int p2 = p + 1;     BOUNDS(p2);
  int p3 = p + 2;     BOUNDS(p3);
  // Relative (local) time 
  float lt = (t - delta_t*(float)p) / delta_t;
  // Interpolate
  return CRSpline::Eq(lt, vp[p0], vp[p1], vp[p2], vp[p3]);
}
Example #2
0
static int
get_range(Vector v, Int from, Int to, int *f, int *t)
{ int low  = valInt(getLowIndexVector(v));
  int high = valInt(getHighIndexVector(v));

  if ( low > high )
    fail;				/* empty vector */

  if ( isDefault(to) )
  { if ( isDefault(from) )
    { *f = low;
      *t = high;
    } else				/* from, @default */
    { int i = valInt(from);

      if ( i > high )
	fail;
      if ( i < low )
	i = low;
      *f = i;
      *t = high;
    }
  } else
  { if ( isDefault(from) )		/* @default, to */
    { int i = valInt(to);

      if ( low > i )
	fail;
      if ( i > high )
	i = high;
      *t = i;
      *f = low;
    } else				/* from, to */
    { int i = valInt(from);

      BOUNDS(i, low, high);
      *f = i;
      i = valInt(to);
      BOUNDS(i, low, high);
      *t = i;
    }
  }

  succeed;
}
Example #3
0
Vector3d Track::getPos(double t) const
{
    // Find out in which interval we are on the spline
    int p = (int)(t / delta_t);
    // Compute local control point indices
#define BOUNDS(pp) { if (pp < 0) pp = 0; else if (pp >= (int)pos.size()-1) pp = pos.size() - 1; }
    int p0 = p - 1;     BOUNDS(p0);
    int p1 = p;         BOUNDS(p1);
    int p2 = p + 1;     BOUNDS(p2);
    int p3 = p + 2;     BOUNDS(p3);
    
	// Relative (local) time 
	double lt = (t - delta_t*(double)p) / delta_t;
	
	// Interpolate
	//printf("lt: %f, p: %d, p0:%d, p1:%d, p2:%d, p3:%d \n", lt, p, p0, p1, p2, p3);
	return Track::Eq(lt, getControlPoint(p0), getControlPoint(p1), getControlPoint(p2), getControlPoint(p3));
}
Example #4
0
File: msgr.c Project: J2R5M3/MSGR
int main(int argc, char *argv[])
{


    char fileName[FILENAME_SIZE];
    char timeFile[FILENAME_SIZE] = {"timefile.msgr"};
    char outputFile[FILENAME_SIZE];
    int numEntries = 0;
    double totalTime = 0;
    int x;
    int y;
    int tTableXdim;
    int tTableYdim;

    FILE *fileOut;
    /*
        if ( argc != 3 )
        {
            printf("usage: %s filename", argv[0] );
            printf("usage: %s input File", argv[1] );
            printf("usage: %s output File", argv[2] );
        }
        else
        {
            strcpy(fileName, argv[1]);
            strcpy(outputFile, argv[2]);
        }
      */

    strcpy(fileName, "dtest.txt");
    strcpy(outputFile, "output.txt");

    tTableXdim = NumColumns(timeFile);
    tTableYdim = NumRows(timeFile);
    x = NumColumns(fileName);
    y = NumRows(fileName);


    Entry eTable[x][y];
    Entry tTable[tTableXdim][tTableYdim];

    int idInstances[y];
    int rowQuantity[y];
//    double clipLines[x][y];

    populateTable(eTable,x,y,fileName);
    populateTable(tTable,tTableXdim,tTableYdim,timeFile);

    calculateTimes(eTable,x,y,tTable,tTableXdim,tTableYdim,idInstances,rowQuantity,&numEntries, &totalTime, outputFile);

    fileOut = fopen(outputFile, "a");
    if(fileOut == 0)
    {
        perror("Could open output file\n");
        system("PAUSE");
        exit(-1);
    }
    else
    {
        fprintf(fileOut,"%s","Predicted Time For All Tiles: ");
        fprintf(fileOut,"%.2f", totalTime);
        fprintf(fileOut,"%s\n","min");
    }
    fclose(fileOut);
    printf("sizeof eTable = %u\n", (unsigned) sizeof eTable);

    printf("1st dimension = %u\n", (unsigned) BOUNDS(eTable));

    printf("2nd dimension = %u\n", (unsigned) BOUNDS(eTable[0]));

    printf("sizeof tTable = %u\n", (unsigned) sizeof tTable);

    printf("1st dimension = %u\n", (unsigned) BOUNDS(tTable));

    printf("2nd dimension = %u\n", (unsigned) BOUNDS(tTable[0]));

    system("PAUSE");
    return 0;
}
Example #5
0
void NeuralNode::SetParams(float vma, float vmb, float vp){
	ma = BOUNDS(vma,-1.,1.);
	mb = BOUNDS(vmb,-1.,1.);
	p	= BOUNDS(vp ,-1.,1.);
}
Example #6
0
void NeuralNet::Mutate(Random *rnd, float size, float div){
	if(rnd == NULL)rnd = &randomGenerator;
	for(unsigned int n = nodeCount; n-- > 1;){
		unsigned int r = rnd->Next()%n;
		unsigned int t = nodeRnd.at(n);
		nodeRnd.at(n) = nodeRnd.at(r);
		nodeRnd.at(r) = t;
	}

	unsigned int nodeCountEnd = nodeCount - 1, nodeCount2 = nodeCount*nodeCount, nodeCount3 = nodeCount*3;
	float sum = nodeCount3*size, sumW = nodeCount2*size;
	float max = 1., maxW = 1.;
	float min = 0., minW = 0.;
	float b1,b2;
	for(unsigned int n=0; n<nodeCount; n++){

		float n1, n2, n3, r;

		if(sum < max)max = sum;
		r = sum-nodeCount3+(n*3)+1;
		if(r > min)min = r;
		b1 = min+(size-min)*div; b2 = max+(size-max)*div;
		n1 = rnd->xrand(BOUNDS(b1,min,max),BOUNDS(b2,min,max));
		sum -= n1;

		if(sum < max)max = sum;
		r = sum-nodeCount3+(n*3)+2;
		if(r > min)min = r;
		b1 = min+(size-min)*div; b2 = max+(size-max)*div;
		n2 = rnd->xrand(BOUNDS(b1,min,max),BOUNDS(b2,min,max));
		sum -= n2;

		if(sum < max)max = sum;
		r = sum-nodeCount3+(n*3)+3;
		if(r > min)min = r;
		if(n == nodeCountEnd){
			n3 = sum;
		}else{
			b1 = min+(size-min)*div; b2 = max+(size-max)*div;
			n3 = rnd->xrand(BOUNDS(b1,min,max),BOUNDS(b2,min,max));
			sum -= n3;
		}

		unsigned int i1 = nodeRnd.at(n);
		unsigned int i2 = nodeRnd.at(i1);
		unsigned int i3 = nodeRnd.at(i2);

		nodes.at(i1).ma += rnd->xrand(-n1,n1);
		nodes.at(i2).mb += rnd->xrand(-n2,n2);
		nodes.at(i3).p += rnd->xrand(-n3,n3);

		nodes.at(i1).ma = BOUNDS(nodes.at(i1).ma,-1.,1.);
		nodes.at(i2).mb = BOUNDS(nodes.at(i2).mb,-1.,1.);
		nodes.at(i3).p = BOUNDS(nodes.at(i3).p,-1.,1.);

		for(unsigned int k=0; k<nodeCount; k++){
			if(sumW < maxW)maxW = sumW;
			float rW = sumW-nodeCount2+(n*k)+1;
			if(rW > minW)minW = rW;

			float num;
			if((k == nodeCountEnd) && (n == nodeCountEnd)){
				num = sumW;
			}else{
				b1 = minW+(size-minW)*div; b2 = maxW+(size-maxW)*div;
				num = rnd->xrand(BOUNDS(b1,minW,maxW),BOUNDS(b2,minW,maxW));
				sumW -= num;
			}

			unsigned int w1 = nodeCountEnd - i3;
			unsigned int w2 = nodeRnd.at(k);
			w1 += w2; if(w1 >= nodeCount)w1 -= nodeCount;
			w2 += w1; if(w2 >= nodeCount)w2 -= nodeCount;
			w1 = nodeRnd.at(w1);
			w2 = nodeRnd.at(w2);

			float wx1,wx2;
			if(num >= 0.5){
				wx1 = 0.;
				wx2 = 1.;
			}else{
				wx1 = weights.at(w1).at(w2) - num;
				wx2 = weights.at(w1).at(w2) + num;
				if(wx1 < 0.){ wx2 -= wx1; wx1 = 0.;}
				if(wx2 > 1.){ wx1 += wx2-1.; wx2 = 1.; }
			}
			weights.at(w1).at(w2) = rnd->xrand(wx1,wx2);
			//weights.at(w1).at(w2) += rnd->xrand(-num,num);
			weights.at(w1).at(w2) = BOUNDSWEIGHT(weights.at(w1).at(w2));
		}

	}

}
OP_ERROR SOP_FluidSolver2D::cookMySop(OP_Context &context) {

	oldf = f;

	double t = context.getTime();
	int f =	context.getFrame();
	UT_Interrupt	*boss;
	GU_PrimVolume	*volume;

	OP_Node::flags().timeDep = 1;
	fluidSolver->fps = OPgetDirector()->getChannelManager()->getSamplesPerSec();


	int newResX = RESX(t);
	int newResY = RESY(t);

	if ( newResX != fluidSolver->res.x || newResY != fluidSolver->res.y) {
		fluidSolver->changeFluidRes(newResX,newResY);

	}

	UT_Vector3 fluidPos(POSX(t), POSY(t), POSZ(t));
	UT_Vector3 fluidRot(ROTX(t), ROTY(t), ROTZ(t));
	fluidRot.degToRad();

	fluidSolver->fluidSize.x = FLUIDSIZEX(t);
	fluidSolver->fluidSize.y = FLUIDSIZEY(t);

	fluidSolver->borderNegX = BORDERNEGX(t);
	fluidSolver->borderPosX = BORDERPOSX(t);
	fluidSolver->borderNegY = BORDERNEGY(t);
	fluidSolver->borderPosY = BORDERPOSY(t);

	fluidSolver->preview = PREVIEW(t);
	fluidSolver->previewType = PREVIEWTYPE(t);
	fluidSolver->bounds = BOUNDS(t);

	fluidSolver->substeps = SUBSTEPS(t);
	fluidSolver->jacIter = JACITER(t);

	fluidSolver->densDis = DENSDIS(t);
	fluidSolver->densBuoyStrength = DENSBUOYSTRENGTH(t);
	float ddirX = DENSBUOYDIRX(t);
	float ddirY = DENSBUOYDIRY(t);
	fluidSolver->densBuoyDir = cu::make_float2(ddirX,ddirY);

	fluidSolver->velDamp = VELDAMP(t);
	fluidSolver->vortConf = VORTCONF(t);

	fluidSolver->noiseStr = NOISESTR(t);
	fluidSolver->noiseFreq = NOISEFREQ(t);
	fluidSolver->noiseOct = NOISEOCT(t);
	fluidSolver->noiseLacun = NOISELACUN(t);
	fluidSolver->noiseSpeed = NOISESPEED(t);
	fluidSolver->noiseAmp = NOISEAMP(t);

    if (error() < UT_ERROR_ABORT) {
			boss = UTgetInterrupt();

		gdp->clearAndDestroy();		

		// Start the interrupt server
		if (boss->opStart("Building Volume")){

			static float		 zero = 0.0;

#ifdef HOUDINI_11
			GB_AttributeRef fluidAtt = gdp->addAttrib("cudaFluidPreview", sizeof(int), GB_ATTRIB_INT, &zero);
			gdp->attribs().getElement().setValue<int>(fluidAtt, fluidSolver->preview);

			GB_AttributeRef solverIdAtt = gdp->addAttrib("solverId", sizeof(int), GB_ATTRIB_INT, &zero);
			gdp->attribs().getElement().setValue<int>(solverIdAtt, fluidSolver->id);
#else
			GA_WOAttributeRef fluidAtt = gdp->addIntTuple(GA_ATTRIB_DETAIL, "cudaFluidPreview", 1);
			gdp->element().setValue<int>(fluidAtt, fluidSolver->preview);

			GA_WOAttributeRef solverIdAtt = gdp->addIntTuple(GA_ATTRIB_DETAIL, "solverId", 1);
			gdp->element().setValue<int>(solverIdAtt, fluidSolver->id);
#endif


			UT_Matrix3              xform;
			const UT_XformOrder volXFormOrder;
			
			volume = (GU_PrimVolume *)GU_PrimVolume::build(gdp);

#ifdef HOUDINI_11
			volume->getVertex().getPt()->getPos() = fluidPos;
#else
			volume->getVertexElement(0).getPt()->setPos(fluidPos);
#endif

			xform.identity();
			xform.scale(fluidSolver->fluidSize.x*0.5, fluidSolver->fluidSize.y*0.5, 0.25);
			xform.rotate(fluidRot.x(), fluidRot.y(), fluidRot.z(), volXFormOrder);

			volume->setTransform(xform);
			

			xform.identity();
			xform.rotate(fluidRot.x(), fluidRot.y(), fluidRot.z(), volXFormOrder);
			xform.invert();

			if(lockInputs(context) >= UT_ERROR_ABORT)
				return error();

			if(getInput(0)){
				GU_Detail* emittersInput = (GU_Detail*)inputGeo(0, context);
				GEO_PointList emittersList = emittersInput->points();
				int numEmitters = emittersList.entries();

				if (numEmitters != fluidSolver->nEmit) {
					delete fluidSolver->emitters;
					fluidSolver->nEmit = numEmitters;
					fluidSolver->emitters = new FluidEmitter[numEmitters];
				}

				GEO_AttributeHandle radAh, amountAh;
				radAh = emittersInput->getPointAttribute("radius");
				amountAh = emittersInput->getPointAttribute("amount");

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

					UT_Vector4 emitPos = emittersList[i]->getPos();
					UT_Vector3 emitPos3(emitPos);

					emitPos3 -= fluidPos;
					emitPos3 = emitPos3*xform;

					fluidSolver->emitters[i].posX = emitPos3.x();
					fluidSolver->emitters[i].posY = emitPos3.y();

					radAh.setElement(emittersList[i]);
					amountAh.setElement(emittersList[i]);

					fluidSolver->emitters[i].radius = radAh.getF(0);
					fluidSolver->emitters[i].amount = amountAh.getF(0);
				}
			} else {

				fluidSolver->nEmit = 0;

			}
		

			if(getInput(1)) {
				GU_Detail* collidersInput = (GU_Detail*)inputGeo(1, context);
		
				GEO_PointList collidersList = collidersInput->points();
				int numColliders = collidersList.entries();

				if (numColliders != fluidSolver->nColliders) {
					delete fluidSolver->colliders;
					fluidSolver->nColliders = numColliders;
					fluidSolver->colliders = new Collider[numColliders];
				}

				GEO_AttributeHandle colRadAh;
				colRadAh = collidersInput->getPointAttribute("radius");

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

					UT_Vector4 colPos = collidersList[i]->getPos();
					UT_Vector3 colPos3(colPos);

					colPos3 -= fluidPos;
					colPos3 = colPos3*xform;

					if (f > STARTFRAME(t)) {
						fluidSolver->colliders[i].oldPosX = fluidSolver->colliders[i].posX;
						fluidSolver->colliders[i].oldPosY = fluidSolver->colliders[i].posY;
					} else {
						fluidSolver->colliders[i].oldPosX = colPos3.x();
						fluidSolver->colliders[i].oldPosY = colPos3.y();
					}

					fluidSolver->colliders[i].posX = colPos3.x();
					fluidSolver->colliders[i].posY = colPos3.y();

					colRadAh.setElement(collidersList[i]);

					fluidSolver->colliders[i].radius = colRadAh.getF(0);
				}

			} else {
				fluidSolver->nColliders = 0;
			}

			unlockInputs();

			if (f <= STARTFRAME(t)) {

				fluidSolver->resetFluid();

				if (fluidSolver->preview != 1) {
					{
						UT_VoxelArrayWriteHandleF	handle = volume->getVoxelWriteHandle();
						handle->constant(0);
					}
				}


			} else {

				if (f!=oldf) {

					fluidSolver->solveFluid();

				}

				if (fluidSolver->preview != 1) {
					
						cu::cudaMemcpy( fluidSolver->host_dens, fluidSolver->dev_dens,
						fluidSolver->res.x*fluidSolver->res.y*sizeof(float), cu::cudaMemcpyDeviceToHost );
				
					{
						UT_VoxelArrayWriteHandleF	handle = volume->getVoxelWriteHandle();

						handle->size(fluidSolver->res.x, fluidSolver->res.y, 1);

						for (int i = 0; i < fluidSolver->res.x; i++) {
							for (int j = 0; j < fluidSolver->res.y; j++) {
								handle->setValue(i, j, 0, fluidSolver->host_dens[(j*fluidSolver->res.x + i)]);
							}
						}
									

					}

				}
			}


		select(GU_SPrimitive);
		}

		// Tell the interrupt server that we've completed. Must do this
		// regardless of what opStart() returns.
		boss->opEnd();
    }

    gdp->notifyCache(GU_CACHE_ALL);
 
    return error();
}