int main(){ char s0[] = "bananaaabbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbb"; char s1[] = "abc"; char s2[] = "banana"; cout<<lrs(s0)<<endl; cout<<strcmp(lrs(s1),"\0")<<endl; cout<<lrs(s2)<<endl; return 0; }
Spectrum MetropolisRenderer::PathL(const MLTSample &sample, const Scene *scene, MemoryArena &arena, const Camera *camera, const Distribution1D *lightDistribution, PathVertex *cameraPath, PathVertex *lightPath, RNG &rng) const { // Generate camera path from camera path samples PBRT_STARTED_GENERATING_CAMERA_RAY((CameraSample *)(&sample.cameraSample)); RayDifferential cameraRay; float cameraWt = camera->GenerateRayDifferential(sample.cameraSample, &cameraRay); cameraRay.ScaleDifferentials(1.f / sqrtf(nPixelSamples)); PBRT_FINISHED_GENERATING_CAMERA_RAY((CameraSample *)(&sample.cameraSample), &cameraRay, cameraWt); RayDifferential escapedRay; Spectrum escapedAlpha; uint32_t cameraLength = GeneratePath(cameraRay, cameraWt, scene, arena, sample.cameraPathSamples, cameraPath, &escapedRay, &escapedAlpha); if (!bidirectional) { // Compute radiance along path using path tracing return Lpath(scene, cameraPath, cameraLength, arena, sample.lightingSamples, rng, sample.cameraSample.time, lightDistribution, escapedRay, escapedAlpha); } else { // Sample light ray and apply bidirectional path tracing // Choose light and sample ray to start light path PBRT_MLT_STARTED_SAMPLE_LIGHT_FOR_BIDIR(); float lightPdf, lightRayPdf; uint32_t lightNum = lightDistribution->SampleDiscrete(sample.lightNumSample, &lightPdf); const Light *light = scene->lights[lightNum]; Ray lightRay; Normal Nl; LightSample lrs(sample.lightRaySamples[0], sample.lightRaySamples[1], sample.lightRaySamples[2]); Spectrum lightWt = light->Sample_L(scene, lrs, sample.lightRaySamples[3], sample.lightRaySamples[4], sample.cameraSample.time, &lightRay, &Nl, &lightRayPdf); PBRT_MLT_FINISHED_SAMPLE_LIGHT_FOR_BIDIR(); if (lightWt.IsBlack() || lightRayPdf == 0.f) { // Compute radiance along path using path tracing return Lpath(scene, cameraPath, cameraLength, arena, sample.lightingSamples, rng, sample.cameraSample.time, lightDistribution, escapedRay, escapedAlpha); } else { // Compute radiance along paths using bidirectional path tracing lightWt *= AbsDot(Normalize(Nl), lightRay.d) / (lightPdf * lightRayPdf); uint32_t lightLength = GeneratePath(RayDifferential(lightRay), lightWt, scene, arena, sample.lightPathSamples, lightPath, NULL, NULL); return Lbidir(scene, cameraPath, cameraLength, lightPath, lightLength, arena, sample.lightingSamples, rng, sample.cameraSample.time, lightDistribution, escapedRay, escapedAlpha); } } }
void MPointCreator::ProcessCurve(const SimpleLine& rCurve, const Interval<Instant> TimeInterval, double dCurveLength) { double dLength = dCurveLength < 0.0 ? MMUtil::CalcLengthCurve(&rCurve, m_dNetworkScale) : dCurveLength; if (AlmostEqual(dLength, 0.0)) { AttributePtr<UPoint> pUPoint(new UPoint(TimeInterval, rCurve.StartPoint(), rCurve.EndPoint())); m_pResMPoint->Add(*pUPoint); return; } DateTime Duration = TimeInterval.end - TimeInterval.start; Duration.Abs(); const bool bStartsSmaller = rCurve.GetStartSmaller(); Instant TimeStart(TimeInterval.start); const int nHalfSegments = rCurve.Size(); if (nHalfSegments <= 0) return; assert(nHalfSegments % 2 == 0); LRS lrs(bStartsSmaller ? 0.0 : rCurve.Length(), 0); int lrsPosAkt = 0; if (!const_cast<SimpleLine&>(rCurve).Get(lrs, lrsPosAkt)) { assert(false); return; } LRS lrsAkt; rCurve.Get(lrsPosAkt, lrsAkt); HalfSegment hs; rCurve.Get(lrsAkt.hsPos, hs); double dLengthHS = MMUtil::CalcDistance(hs.GetLeftPoint(), hs.GetRightPoint(), m_dNetworkScale); DateTime TimeEnd = TimeStart + DateTime(datetime::durationtype, (uint64_t)(((Duration.millisecondsToNull() / dLength) * dLengthHS) + .5)); Interval<Instant> TimeIntervalAkt(TimeStart, TimeEnd, true, TimeStart == TimeEnd); Point Pt1(false); Point Pt2(false); if (const_cast<SimpleLine&>(rCurve).StartsSmaller()) { Pt1 = hs.GetDomPoint(); Pt2 = hs.GetSecPoint(); } else { Pt1 = hs.GetSecPoint(); Pt2 = hs.GetDomPoint(); } AttributePtr<UPoint> pUPoint(new UPoint(TimeIntervalAkt, Pt1, Pt2)); m_pResMPoint->Add(*pUPoint); TimeStart = TimeEnd; if (bStartsSmaller) ++lrsPosAkt; else --lrsPosAkt; while (lrsPosAkt >= 0 && lrsPosAkt < nHalfSegments / 2) { rCurve.Get(lrsPosAkt, lrsAkt); rCurve.Get(lrsAkt.hsPos, hs); double dLengthHS = MMUtil::CalcDistance(hs.GetLeftPoint(), hs.GetRightPoint(), m_dNetworkScale); DateTime TimeEnd = TimeStart + DateTime(datetime::durationtype, (uint64_t)(((Duration.millisecondsToNull() / dLength) * dLengthHS) + .5)); Interval<Instant> TimeIntervalAkt(TimeStart, TimeEnd, true, TimeStart == TimeEnd); if (AlmostEqual(Pt2, hs.GetDomPoint())) { Pt1 = hs.GetDomPoint(); Pt2 = hs.GetSecPoint(); } else { Pt1 = hs.GetSecPoint(); Pt2 = hs.GetDomPoint(); } /*if (AlmostEqual(Pt2, rCurve.EndPoint())) TimeStart = TimeInterval.end;*/ AttributePtr<UPoint> pUPoint(new UPoint(TimeIntervalAkt, Pt1, Pt2)); m_pResMPoint->Add(*pUPoint); TimeStart = TimeEnd; if (bStartsSmaller) ++lrsPosAkt; else --lrsPosAkt; } }
void Tri2dFCBlockSolver::gradSetupQuadratic() { // form quadratic sub elements int nElemQ = 3*nElem; int nneQ = 6; //quadratic elements int nngQ = 4; //quadratic elements Array2D<int> elemQ(nElemQ,nneQ),gNode(nElemQ,nngQ); int m=0; for (int n=0; n<nElem; n++){ elemQ(m ,0) = elem(n,0); elemQ(m ,1) = elem(n,4); elemQ(m ,2) = elem(n,7); elemQ(m ,3) = elem(n,3); elemQ(m ,4) = elem(n,9); elemQ(m ,5) = elem(n,8); gNode(m ,0) = 0; gNode(m ,1) = 3; gNode(m ,2) = 4; gNode(m++,3) = 5; elemQ(m ,0) = elem(n,3); elemQ(m ,1) = elem(n,1); elemQ(m ,2) = elem(n,6); elemQ(m ,3) = elem(n,4); elemQ(m ,4) = elem(n,5); elemQ(m ,5) = elem(n,9); gNode(m ,0) = 1; gNode(m ,1) = 4; gNode(m ,2) = 5; gNode(m++,3) = 3; elemQ(m ,0) = elem(n,8); elemQ(m ,1) = elem(n,5); elemQ(m ,2) = elem(n,2); elemQ(m ,3) = elem(n,9); elemQ(m ,4) = elem(n,6); elemQ(m ,5) = elem(n,7); gNode(m ,0) = 2; gNode(m ,1) = 5; gNode(m ,2) = 3; gNode(m++,3) = 4; } /* for (int n=0; n<nElemQ; n++){ cout << n << " "; for (int j=0; j<nneQ; j++) cout << elemQ(n,j) << " "; cout << endl; } exit(0); */ // Jacobian terms Array2D <double> xr(nElemQ,nngQ),yr(nElemQ,nngQ),xs(nElemQ,nngQ), ys(nElemQ,nngQ),jac(nElemQ,nngQ),rs(nneQ,3),lc(nneQ,nneQ); xr.set(0.); yr.set(0.); xs.set(0.); ys.set(0.); jac.set(0.); int orderE=2; //quadratic elements solutionPoints(orderE, spacing, &rs(0,0)); bool test=true; lagrangePoly(test, orderE, &rs(0,0), &lc(0,0)); int j,km,lm; double lrm,lsm,ri,si; for (int n=0; n<nElemQ; n++){ // evaluate the Jacobian terms at the mesh points for (int i=0; i<nngQ; i++){ //ith mesh point ri = rs(gNode(n,i),0); si = rs(gNode(n,i),1); for (int m=0; m<nneQ; m++){ //mth Lagrange polynomial j = 0; lrm = 0.; lsm = 0.; for (int k=0; k<=orderE; k++) for (int l=0; l<=orderE-k; l++){ km = max(0,k-1); lm = max(0,l-1); lrm +=((double)k)*pow(ri,km)*pow(si,l )*lc(m,j ); lsm +=((double)l)*pow(ri,k )*pow(si,lm)*lc(m,j++); } xr(n,i) += lrm*x(elemQ(n,m),0); yr(n,i) += lrm*x(elemQ(n,m),1); xs(n,i) += lsm*x(elemQ(n,m),0); ys(n,i) += lsm*x(elemQ(n,m),1); } jac(n,i) = xr(n,i)*ys(n,i)-yr(n,i)*xs(n,i); }} // lr(i,j) = (dl_j/dr)_i (a row is all Lagrange polynomials (derivatives) // evaluated at a single mesh point i, same with the other derivatives) Array2D<double> lr(nneQ,nneQ),ls(nneQ,nneQ),lrr(nneQ,nneQ), lss(nneQ,nneQ),lrs(nneQ,nneQ); lr.set(0.); ls.set(0.); lrr.set(0.); lss.set(0.); lrs.set(0.); int kmm,lmm; for (int n=0; n<nneQ; n++) // nth Lagrange polynomial for (int i=0; i<nneQ; i++){ // ith mesh point j = 0; ri = rs(i,0); si = rs(i,1); for (int k=0; k<=orderE; k++) for (int l=0; l<=orderE-k; l++){ km = max(0,k-1); lm = max(0,l-1); kmm = max(0,k-2); lmm = max(0,l-2); lr (i,n) +=((double)k)*pow(ri,km)*pow(si,l )*lc(n,j); ls (i,n) +=((double)l)*pow(ri,k )*pow(si,lm)*lc(n,j); lrr(i,n) +=((double)(k*km))*pow(ri,kmm)*pow(si,l )*lc(n,j ); lss(i,n) +=((double)(l*lm))*pow(ri,k )*pow(si,lmm)*lc(n,j ); lrs(i,n) +=((double)(k*l ))*pow(ri,km )*pow(si,lm )*lc(n,j++); }} // compute averaged quadratic FEM gradient coefficients Array1D<double> sumj(nNode); sumj.set(0.); for (int n=0; n<nElemQ; n++) for (int i=0; i<nngQ; i++){ m = gNode(n,i); sumj(elemQ(n,m)) += jac(n,i); } for (int n=0; n<nNode; n++) sumj(n) = 1./sumj(n); int k1,k2; double xri,yri,xsi,ysi; Array2D<double> ax(nNode,2); ax.set(0.); gxQ.set(0.); for (int n=0; n<nElemQ; n++) for (int i=0; i<nngQ; i++){ m = gNode(n,i); k1 = elemQ(n,m); xri = xr(n,i); yri = yr(n,i); xsi = xs(n,i); ysi = ys(n,i); for (int j=0; j<nneQ; j++){ k2 = elemQ(n,j); ax(k2,0) = lr(m,j)*ysi-ls(m,j)*yri; ax(k2,1) =-lr(m,j)*xsi+ls(m,j)*xri; } for(int j=psp2(k1); j<psp2(k1+1); j++){ k2 = psp1(j); gxQ(j,0) += ax(k2,0); gxQ(j,1) += ax(k2,1); } for (int j=0; j<nneQ; j++){ k2 = elemQ(n,j); ax(k2,0) = 0.; ax(k2,1) = 0.; }} for (int n=0; n<nNode; n++) for (int i=psp2(n); i<psp2(n+1); i++){ gxQ(i,0) *= sumj(n); gxQ(i,1) *= sumj(n); } // deallocate work arrays elemQ.deallocate(); gNode.deallocate(); xr.deallocate(); yr.deallocate(); xs.deallocate(); ys.deallocate(); jac.deallocate(); rs.deallocate(); lc.deallocate(); lr.deallocate(); ls.deallocate(); lrr.deallocate(); lss.deallocate(); lrs.deallocate(); sumj.deallocate(); ax.deallocate(); }