int PressureIndependMultiYield::getResponse (int responseID, Information &matInfo)
{
  switch (responseID) {
  case -1:
    return -1;
  case 1:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getCommittedStress();
    return 0;
  case 2:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getCommittedStrain();
    return 0;
  case 3:
    if (matInfo.theMatrix != 0)
      *(matInfo.theMatrix) = getTangent();
    return 0;
  case 4:
    if (matInfo.theMatrix != 0)
      getBackbone(*(matInfo.theMatrix));
    return 0;
  default:
    return -1;
  }
}
예제 #2
0
파일: path.cpp 프로젝트: thabz/RayGay
/**
 * @param num Number of tangents to calculate
 * @param out The result is written here
 */
void Path::getTangents(int num, Vector* out) const {
    assert(num > 1);
    double t;
    for (int i = 0; i < num; i++) {
	t = double(i) / (double(num));
	out[i] = getTangent(t);
    }
}
const Vector & PressureIndependMultiYield::getStress (void)
{
  int loadStage = loadStagex[matN];
  int numOfSurfaces = numOfSurfacesx[matN];
  int ndm = ndmx[matN];
  if (ndmx[matN] == 0) ndm = 3;

  int i;
  if (loadStage == 1 && e2p == 0) elast2Plast();

  if (loadStage!=1) {  //linear elastic
    //trialStrain.setData(currentStrain.t2Vector() + strainRate.t2Vector());
    getTangent();
    static Vector a(6);
    a = currentStress.t2Vector();
	a.addMatrixVector(1.0, theTangent, strainRate.t2Vector(1), 1.0);
    trialStress.setData(a);
  }

  else {
    for (i=1; i<=numOfSurfaces; i++) theSurfaces[i] = committedSurfaces[i];
    activeSurfaceNum = committedActiveSurf;
    subStrainRate = strainRate;
    setTrialStress(currentStress);
    if (isLoadReversal()) {
      updateInnerSurface();
      activeSurfaceNum = 0;
    }
    int numSubIncre = setSubStrainRate();

    for (i=0; i<numSubIncre; i++) {
      if (i==0)
	setTrialStress(currentStress);
      else
	setTrialStress(trialStress);
      if (activeSurfaceNum==0 && !isCrossingNextSurface()) continue;
      if (activeSurfaceNum==0) activeSurfaceNum++;
      stressCorrection(0);
      updateActiveSurface();
    }
    //volume stress change
    double volum = refBulkModulus*(strainRate.volume()*3.);
    volum += currentStress.volume();
     //if (volum > 0) volum = 0.;
    trialStress.setData(trialStress.deviator(),volum);
  }

  if (ndm==3)
    return trialStress.t2Vector();
  else {
    static Vector workV(3);
    workV[0] = trialStress.t2Vector()[0];
    workV[1] = trialStress.t2Vector()[1];
    workV[2] = trialStress.t2Vector()[3];
    return workV;
  }
}
예제 #4
0
  iSpline3D* otPolyLineSpline3::getDerivative()
  {
    unsigned int count = getPointList().getCount();
    otPolyLineSpline3* tangent=new otPolyLineSpline3(count);

    for(unsigned int i=0;i<count-1;i++)
    {
      tangent->setPoint(points[i].x,getTangent(points[i].x));
    }
    return tangent;
  }
예제 #5
0
double AnalyticSignal::calculate(const TimeSeries& ts, int modeNo, const string& prefix) {
	const vector<double>& xs = ts.getXs();
	const vector<double>& realSignal = ts.getYs();
	unsigned n = realSignal.size();
	double 	xStep = xs[1] - xs[0]; // Assuming even sampling
    fftw_complex* conjugatedSignal = (fftw_complex*) malloc(sizeof(fftw_complex) * n);
    for (unsigned i = 0; i < n; i++) {
    	conjugatedSignal[i][0] = realSignal[i];
    	conjugatedSignal[i][1] = 0;
    }
	fft(true, realSignal.size(), conjugatedSignal, 0);
	fft(false, realSignal.size(), conjugatedSignal, M_PI_2);
	//double* amplitude = (double*) malloc(sizeof(double) * n);
	//double* phase = (double*) malloc(sizeof(double) * n);
	//double* frequency = (double*) malloc(sizeof(double) * (n - 2));
	ofstream imfStream(prefix + "_imf_" + to_string(modeNo) + ".csv");
	ofstream ampStream(prefix + "_amp_" + to_string(modeNo) + ".csv");
	ofstream freqStream(prefix + "_freq_" + to_string(modeNo) + ".csv");
	ofstream perStream(prefix + "_per_" + to_string(modeNo) + ".csv");
	double totalEnergy = 0;
	double prevZeroCross = xs[0];
	for (unsigned i = 0; i < n; i++) {
		double x = xs[i];
		double u = realSignal[i];
		double v = conjugatedSignal[i][0] / n; // the fft is unnormalized
		double u2v2 = u * u + v * v;
		double amplitude = sqrt(u2v2);
		totalEnergy += u2v2;
		//double phase = atan(v / u);
		imfStream << x << " " << u << endl;
		ampStream << x << " " << amplitude << endl;
		if (i > 0 && i < n - 1) {
			double frequency = (getRealTangent(i, conjugatedSignal) * u / n - getTangent(i, realSignal) * v) / u2v2 / xStep;
			freqStream << x << " " << frequency << endl;
		}
		// Calculating average period based on zero-crossings (not part of Analytic signal calculation actually)
		if (i > 0) {
			if ((u > 0 && realSignal[i - 1] < 0) || (u < 0 && realSignal[i - 1] > 0)) {
				double zeroCross = (x + xs[i - 1]) / 2;
				if (prevZeroCross > xs[0]) {
					perStream << (zeroCross + prevZeroCross) / 2 << " " << 2 * (zeroCross - prevZeroCross) << endl;
				}
				prevZeroCross = zeroCross;
			}
		}
	}
	imfStream.close();
	ampStream.close();
	freqStream.close();
	perStream.close();
	return totalEnergy / n;
}
int PressureIndependMultiYield::getResponse (int responseID, Information &matInfo)
{
  switch (responseID) {
  case -1:
    return -1;
  case 1:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getCommittedStress();
    return 0;
  case 2:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getCommittedStrain();
    return 0;
  case 3:
    if (matInfo.theMatrix != 0)
      *(matInfo.theMatrix) = getTangent();
    return 0;
  case 4:
    if (matInfo.theMatrix != 0)
      getBackbone(*(matInfo.theMatrix));
    return 0;
	// begin change by Alborz Ghofrani UW --- get 6 components of stress
  case 5:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getStressToRecord(3);
    return 0;
  case 6:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getStressToRecord(4);
    return 0;
  case 7:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getStressToRecord(5);
    return 0;
  case 8:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getStressToRecord(6);
    return 0;
  case 9:
    if (matInfo.theVector != 0)
      *(matInfo.theVector) = getStressToRecord(7);
    return 0;
	// end change by Alborz Ghofrani UW
  default:
    return -1;
  }
}
예제 #7
0
파일: Model.cpp 프로젝트: Dwarfius/GP2
void Model::processMeshNormals(FbxMesh *mesh, Vertex *verts, int count)
{
	int polCount = mesh->GetPolygonCount();
	for (int polInd = 0; polInd < polCount; polInd++)
	{
		for (int vertInd = 0; vertInd < 3; vertInd++)
		{
			int cornerIndex = mesh->GetPolygonVertex(polInd, vertInd);
			FbxVector4 normal;
			mesh->GetPolygonVertexNormal(polInd, vertInd, normal);
			normal.Normalize();
			verts[cornerIndex].normal.x = normal[0];
			verts[cornerIndex].normal.y = normal[1];
			verts[cornerIndex].normal.z = normal[2];
			verts[cornerIndex].tangent = getTangent(verts[cornerIndex].normal);
			verts[cornerIndex].binormal = getBinormal(verts[cornerIndex].normal, verts[cornerIndex].tangent);
		}
	}
}
Vec3f CylinderDistribution3D::generate(void) const
{
    Vec3f Result;

    switch(getSurfaceOrVolume())
    {
    case SURFACE:
        {
            std::vector<Real32> Areas;
            //Min Cap
            Areas.push_back(0.5*osgAbs(getMaxTheta() - getMinTheta())*(getOuterRadius()*getOuterRadius() - getInnerRadius()*getInnerRadius()));
            //Max Cap
            Areas.push_back(Areas.back() + 0.5*osgAbs(getMaxTheta() - getMinTheta())*(getOuterRadius()*getOuterRadius() - getInnerRadius()*getInnerRadius()));
            //Inner Tube
            Areas.push_back(Areas.back() + getInnerRadius()*osgAbs(getMaxTheta() - getMinTheta()) * getHeight());
            //Outer Tube
            Areas.push_back(Areas.back() + getOuterRadius()*osgAbs(getMaxTheta() - getMinTheta()) * getHeight());

            bool HasTubeSides(osgAbs(getMaxTheta() - getMinTheta()) - 6.283185 < -0.000001);
            if(HasTubeSides)
            {
                //MinTheta Tube Side
                Areas.push_back(Areas.back() + (getOuterRadius() - getInnerRadius()) * getHeight());

                //MaxTheta Tube Side
                Areas.push_back(Areas.back() + (getOuterRadius() - getInnerRadius()) * getHeight());
            }

            Real32 PickEdge(RandomPoolManager::getRandomReal32(0.0,1.0));
            if(PickEdge < Areas[0]/Areas.back())
            {
                //Max Cap
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Result = getCenter().subZero()
                    + (Radius*osgSin(Theta))*getTangent()
                    + (Radius*osgCos(Theta))*getBinormal()
                    + (getHeight()/static_cast<Real32>(2.0))*getNormal();
            }
            else if(PickEdge < Areas[1]/Areas.back())
            {
                //Min Cap
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Result = getCenter().subZero()
                    + (Radius*osgSin(Theta))*getTangent()
                    + (Radius*osgCos(Theta))*getBinormal()
                    + (-getHeight()/static_cast<Real32>(2.0))*getNormal();
            }
            else if(PickEdge < Areas[2]/Areas.back())
            {
                //Inner Tube
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result =  getCenter().subZero()
                    + getInnerRadius()*osgSin(Theta)*getTangent()
                    + getInnerRadius()*osgCos(Theta)*getBinormal()
                    + Height*getNormal();
            }
            else if(PickEdge < Areas[3]/Areas.back())
            {
                //Outer Tube
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result =  getCenter().subZero()
                    + getOuterRadius()*osgSin(Theta)*getTangent()
                    + getOuterRadius()*osgCos(Theta)*getBinormal()
                    + Height*getNormal();
            }
            else if(HasTubeSides && PickEdge < Areas[4]/Areas.back())
            {
                //MinTheta Tube Side
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result = getCenter().subZero()
                    + (Radius*osgSin(getMinTheta()))*getTangent()
                    + (Radius*osgCos(getMinTheta()))*getBinormal()
                    + Height*getNormal();
            }
            else if(HasTubeSides && PickEdge < Areas[5]/Areas.back())
            {
                //MaxTheta Tube Side
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result = getCenter().subZero()
                    + (Radius*osgSin(getMaxTheta()))*getTangent()
                    + (Radius*osgCos(getMaxTheta()))*getBinormal()
                    + Height*getNormal();
            }
            else
            {
                assert(false && "Should never reach this point");
            }
            break;
        }
    case VOLUME:
    default:
        {
            //To get a uniform distribution across the disc get a uniformly distributed allong 0.0 - 1.0
            //Then Take the square root of that.  This gives a square root distribution from 0.0 - 1.0
            //This square root distribution is used for the random radius because the area of a disc is 
            //dependant on the square of the radius, i.e it is a quadratic function
            Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
            Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
            Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
            Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
            Result = getCenter().subZero()
                   + (Radius*osgSin(Theta))*getTangent()
                   + (Radius*osgCos(Theta))*getBinormal()
                   + Height*getNormal();
            break;
        }
    }

    return Result;
}
void TownDashboardRenderer::draw()
{
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    //type
    _typeLayerFbo.begin();
    
    ofClear(0, 0, 0, 0);
    ofBackground(0, 0, 0, 0);
    
    searchingStringImage.draw(0, 0);
    ofPushMatrix();

    ofSetColor(0,255,255);
    int maxVisibleCharacters = 14;
    string subString = _townName.length() > maxVisibleCharacters ? _townName.substr(0, maxVisibleCharacters) : _townName;
    if (_townName.length() <= (maxVisibleCharacters))
    {
        int insertWs = maxVisibleCharacters - _townName.length() - 1;
        for(int i = 0; i<insertWs; i++)
        {
            subString.push_back('p');
        }
    }
    else{
        subString += "...";
        _townName = subString;// + "...";
    }
    ofRectangle fullRect = font.getStringBoundingBox(subString, 0, 0);
    int p = 0;//running count
    ofRectangle runningStringDimensions;
    
    float debugXPos = 2600.0f;
    
    for(char &c : _townName)
    {
        int nVal = min(p + 1, (int)subString.length());
        
        string runningString = subString.substr(0, nVal);
        runningStringDimensions = font.getStringBoundingBox(runningString, 0, 0);
        string thisCharString = ofToString(c);
        ofRectangle thisCharDimensions = font.getStringBoundingBox(thisCharString, 0, 0);
        
        float diff = runningStringDimensions.width - thisCharDimensions.width;
        float debugWidth = fullRect.width;
        float dPos = diff / fullRect.width;
        ofVec2f positionOnCurve = spline2D.sampleAt(dPos);
        ofVec2f tangent = getTangent(dPos, spline2D);
        float rot = atan2(tangent.y, tangent.x) * RAD_TO_DEG;
        
        ofPushMatrix();
        
        ofTranslate(positionOnCurve.x, positionOnCurve.y);
        ofRotate(rot, 0, 0, 1);
        font.drawString(thisCharString, 0, 0);
        
        ofPopMatrix();
        
        if(_debugMode)
        {
            //debug stuff off screen
            ofSetColor(255, 0, 255);
            ofDrawRectangle(debugXPos, p * 100, runningStringDimensions.width, runningStringDimensions.height);
            ofSetColor(0, 255, 0);
            ofDrawRectangle(debugXPos + diff, runningStringDimensions.height + (p * 100), thisCharDimensions.width, 3000);
            ofSetColor(0, 0, 0);
            font.drawString(runningString, debugXPos, 50 + (p * 100));
        }
        
        ofPopMatrix();
        ++p;
        
    }
    ofSetColor(255);
    searchingStringImage.draw(0, 0);
    _typeLayerFbo.end();
    
    //drawn the type
    //black pass
    _blackPassFbo.begin();
    ofClear(0, 0, 0, 255);
    ofBackground(0, 0, 0, 255);
    
    _typeLayerFbo.draw(0, 0);
    
    _blackPassFbo.end();
    
    //glow
    glow.clear();
    glow << _blackPassFbo;
    
    
    
    _glowPassFbo.begin();
    ofClear(0, 0, 0);
    ofBackground(0, 0, 0);
    ofRectangle r = ofRectangle(0, 0, PRINT_DIMENSIONS_WIDTH, PRINT_DIMENSIONS_HEIGHT);
    glow.ofxFXObject::draw(r);
    _glowPassFbo.end();
    
    //final render
    _exportFbo.begin();
    
    ofClear(0, 0, 0);
    ofBackground(0, 0, 0);
//    backgroundImage.draw(0, 0);
    blendImage.draw(0, 0);
    _typeLayerFbo.draw(0, 0);

    ofEnableBlendMode(OF_BLENDMODE_ADD);

    _glowPassFbo.draw(0, 0);
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    
    _exportFbo.end();
    
}