void resetFireWork(){ Point fireWorkColor=randColor(); if(particals[0]){ delete particals[0]; } particals[0] = new ParticalRound(); for(int i=0; i<NUM_OF_PARTICALS; i++){ Point oo((((double) rand() / (RAND_MAX)) -0.5)/10.0, ((((double) rand() / (RAND_MAX)) -0.5)/10.0), ((((double) rand() / (RAND_MAX)) -0.5)/10.0)); if((oo[0]*oo[0] + oo[1]*oo[1] + oo[2]*oo[2]) < particals[0]->getRadius()*particals[0]->getRadius()){ if(particals[i]){ delete particals[i]; } particals[i] = new ParticalRound(oo[0], oo[1], oo[2]); particals[i]->setColor(fireWorkColor); }else{ i--; } additionalParticals.erase(additionalParticals.begin(), additionalParticals.end()); } fireWorkLocation=Point()+((double(rand()%100)/200.0)+2)*Physics::getRandomVector(Vector(0,1,0),30); fireWorkLocation[2]-=1.5; }
void ChessLegalityTest::test_castling() { ChessMove oo(Point(4, 7), Point(6, 7)); m_state->board().set(Point(6, 7), ChessPiece()); { ChessMove tmp(oo); CPPUNIT_ASSERT(!m_legality_check->pseudolegal(tmp)); } m_state->board().set(Point(5, 7), ChessPiece()); { ChessMove tmp(oo); CPPUNIT_ASSERT(m_legality_check->legal(tmp)); } m_state->board().set(Point(3, 6), ChessPiece(ChessPiece::BLACK, ChessPiece::PAWN)); { ChessMove tmp(oo); CPPUNIT_ASSERT(!m_legality_check->pseudolegal(tmp)); } m_state->board().set(Point(3, 6), ChessPiece()); m_state->board().set(Point(4, 6), ChessPiece(ChessPiece::BLACK, ChessPiece::PAWN)); { ChessMove tmp(oo); CPPUNIT_ASSERT(!m_legality_check->pseudolegal(tmp)); } }
/** * Aggregate 0 observations into adjacent smaller bin and compress +group tail. **/ void logistic_normal::aggregate_and_compress_arrays() { m_nB2.allocate(m_y1,m_y2); int i; for( i = m_y1; i <= m_y2; i++ ) { int n = m_b1-1; // index for maximum column each year for ragged objects for(int j = m_b1; j <= m_b2; j++ ) { double op = m_O(i,j)/sum(m_O(i)); if( op > m_dMinimumProportion ) { n ++; } } m_nB2(i) = n; } m_nAgeIndex.allocate(m_y1,m_y2,m_b1,m_nB2); m_Op.allocate(m_y1,m_y2,m_b1,m_nB2); m_Ep.allocate(m_y1,m_y2,m_b1,m_nB2); m_Op.initialize(); m_Ep.initialize(); for( i = m_y1; i <= m_y2; i++ ) { dvector oo = m_O(i) / sum(m_O(i)); dvar_vector ee = m_E(i) / sum(m_E(i)); int k=m_b1; for(int j = m_b1; j <= m_b2; j++ ) { if( oo(j) <= m_dMinimumProportion ) // Check this < gives -Inf need to compress left tails as well. { m_Op(i)(k) += oo(j); m_Ep(i)(k) += ee(j); } else { m_Op(i)(k) += oo(j); m_Ep(i)(k) += ee(j); if( k <=m_nB2(i) ) m_nAgeIndex(i,k) = k; if( k < m_nB2(i) ) k++; } } } }
static void _save(Request& r, MethodParams& params) { VXdoc& vdoc=GET_SELF(r, VXdoc); const String& file_spec=r.absolute(params.as_string(0, FILE_NAME_MUST_BE_STRING)); XDocOutputOptions oo(vdoc.output_options); oo.append(r, get_options(params, 1)); xdoc2buf(r, vdoc, oo, &file_spec); }
void ChessGameStateTest::test_queenside_castling() { ChessMove oo(Point(4, 7), Point(2, 7)); oo.setType(ChessMove::QUEEN_SIDE_CASTLING); m_state->move(oo); CPPUNIT_ASSERT(m_state->board().get(Point(2, 7)) == ChessPiece(ChessPiece::WHITE, ChessPiece::KING)); CPPUNIT_ASSERT(m_state->board().get(Point(3, 7)) == ChessPiece(ChessPiece::WHITE, ChessPiece::ROOK)); CPPUNIT_ASSERT(m_state->board().get(Point(0, 7)) == ChessPiece()); }
Double_t getShiftLL(const Double_t* thetaPhi) { Double_t chi2(1), c(0), oo(0); TVector3 norm; norm.SetMagThetaPhi(1.0, thetaPhi[0], thetaPhi[1]); for (Int_t ch=0; ch<NSnConstants::kNchans; ++ch) { for (Int_t xc=0; xc<ch; ++xc) { Double_t dtcor=0; for (Int_t i=(ch-xc); i>0; --i) { dtcor += dtCorrs[ch-i]; } const TVector3& posCh = getStnPos(ch); const TVector3& posXc = getStnPos(xc); const Double_t disCh = -(posCh.Dot(norm)); const Double_t disXc = -(posXc.Dot(norm)); // !!! check sign of delta(distance) and dtcor! Double_t dt = ( (disCh-disXc) * kNgTopFern / kC_m_ns ) // from m to ns + dtcor; // correct dt offset (ns) const Double_t odt = dt; Bool_t oob=kFALSE; if (dt<-maxdt) { dt = -maxdt; oob = kTRUE; } else if (dt>maxdt) { dt = maxdt; oob = kTRUE; } dt *= kSmpRate; c = getProbFromCorrCoef(gspl[ch][xc]->Eval(dt)); if (oob) { const Double_t wa = TMath::Abs(odt) - maxdt; oo += wa*wa; } /* if (TMath::Abs(dt)>maxdt) { // really don't like being out of bounds c = TMath::Exp(-dt*dt); } else { // get the correlation coefficient for this dt (in num samples) const Double_t corco = gspl[ch][xc]->Eval(dt); c = getProbFromCorrCoef(corco); } if (c>1.0) { Fatal("getShiftLL","Got ll term > 1 (%g)",c); } */ chi2 *= c; } } chi2 = -TMath::Log(chi2); chi2 += oo; return chi2; }
static void _string(Request& r, MethodParams& params) { VXdoc& vdoc=GET_SELF(r, VXdoc); XDocOutputOptions oo(vdoc.output_options); oo.append(r, get_options(params, 0)); String::C buf=xdoc2buf(r, vdoc, oo, 0/*file_name. not to file, to memory*/, true/*use source charset to render, client charset to put to header*/); // write out result r.write_no_lang(String(buf, String::L_AS_IS)); }
void addPerformance(const Int_t it) { if(!narr[it]){ narr[it] = (TObjArray*)arr->Clone(); narr[it]->SetOwner(); gDirectory->ls(); return; } TObject *oo(NULL); TH1 *h1(NULL), *H1(NULL); THnSparse *h(NULL), *H(NULL); Int_t nplots(plots[it]->GetEntries()); TString sname; for(Int_t ih(0); ih<nplots; ih++){ sname= ((TObjString*)(*plots[it])[ih])->String(); if(!mc && sname.EndsWith("MC")) continue; if(!(oo = (TObject*)arr->FindObject(sname.Data()))) { Warning("addPerformance", "Missing %s from \"%s\"", sname.Data(), file->GetName()); continue; } if(strstr(oo->IsA()->GetName(), "THnSparse")){ h = dynamic_cast<THnSparse*>(oo); if(!(H = (THnSparse*)narr[it]->FindObject(sname.Data()))) { Error("addPerformance", "Missing %s from Merging.", sname.Data()); return; } H->Add(h); if(kWrite) printf(" -> %s[%d]\n", sname.Data(), (Int_t)H->GetEntries()); } else if(strstr(oo->IsA()->GetName(), "TH")){ h1 = dynamic_cast<TH1*>(oo); if(!(H1 = (TH1*)narr[it]->FindObject(sname.Data()))) { Error("addPerformance", "Missing %s. from Merging.", sname.Data()); return; } H1->Add(h1); if(kWrite) printf(" -> %s[%d]\n", sname.Data(), (Int_t)H1->GetEntries()); } else{ Warning("addPerformance", "Object %s. from \"%s\" of unknown class %s", sname.Data(), file->GetName(), oo->IsA()->GetName()); continue; } } if(kWrite){ narr[it]->Write(taskName[it], /*TObject::kOverwrite|*/TObject::kSingleKey); narr[it]->Delete(); delete narr[it]; narr[it] = NULL; } }
main() { oo( D1, x ); oo( D1, y ); bo( D1, DE1 ); bo( D1, DE2 ); oo( D2, x ); oo( D2, y ); bo( D2, DE1 ); bo( D2, DE2 ); oo( D3, x ); oo( D3, y ); bo( D3, DE1 ); bo( D3, EE ); oo( D4, x ); oo( D4, y ); bo( D4, EE ); bo( D4, DE1 ); bo( D4, DE2 ); }
static void _file(Request& r, MethodParams& params) { VXdoc& vdoc=GET_SELF(r, VXdoc); XDocOutputOptions oo(vdoc.output_options); oo.append(r, get_options(params, 0), true/* $.name[filename] could be specified by user */); String::C buf=xdoc2buf(r, vdoc, oo, 0/*file_name. not to file, to memory*/); VFile& vfile=*new VFile; VHash& vhcontent_type=*new VHash; vhcontent_type.hash().put( value_name, new VString(*oo.mediaType)); vhcontent_type.hash().put( String::Body("charset"), new VString(*oo.encoding)); vfile.set_binary(false/*not tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length, oo.filename, &vhcontent_type); // write out result r.write_no_lang(vfile); }
// ###################################################################### int main() { std::cout << std::boolalpha << std::endl; { std::ofstream os("file.json"); cereal::JSONOutputArchive oar( os ); //auto f = std::make_shared<Fixture>(); //auto f2 = f; //oar( f ); //oar( f2 ); Stuff s; s.fillData(); oar( cereal::make_nvp("best data ever", s) ); } { std::ifstream is("file.json"); std::string str((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>()); std::cout << "---------------------" << std::endl << str << std::endl << "---------------------" << std::endl; } // playground { cereal::JSONOutputArchive archive( std::cout ); bool arr[] = {true, false}; std::vector<int> vec = {1, 2, 3, 4, 5}; archive( CEREAL_NVP(vec), arr ); auto f = std::make_shared<Fixture>(); auto f2 = f; archive( f ); archive( f2 ); } // test out of order std::stringstream oos; { cereal::JSONOutputArchive ar(oos); cereal::JSONOutputArchive ar2(std::cout, cereal::JSONOutputArchive::Options(2, cereal::JSONOutputArchive::Options::IndentChar::space, 2) ); ar( cereal::make_nvp( "1", 1 ), cereal::make_nvp( "2", 2 ), 3, 0, // unused cereal::make_nvp( "4", 4 ), cereal::make_nvp( "5", 5 ) ); int x = 33; ar.saveBinaryValue( &x, sizeof(int), "bla" ); ar2( cereal::make_nvp( "1", 1 ), cereal::make_nvp( "2", 2 ), 3, 0, // unused cereal::make_nvp( "4", 4 ), cereal::make_nvp( "5", 5 ) ); ar2.saveBinaryValue( &x, sizeof(int), "bla" ); OOJson oo( 1, 2, true, 4.2 ); ar( CEREAL_NVP(oo) ); ar2( CEREAL_NVP(oo) ); // boost stuff ar & cereal::make_nvp("usingop&", oo ) & 6; ar << 5 << 4 << 3; ar2 & cereal::make_nvp("usingop&", oo ) & 6; ar2 << 5 << 4 << 3; long double ld = std::numeric_limits<long double>::max(); long long ll = std::numeric_limits<long long>::max(); unsigned long long ull = std::numeric_limits<unsigned long long>::max(); ar( CEREAL_NVP(ld), CEREAL_NVP(ll), CEREAL_NVP(ull) ); ar2( CEREAL_NVP(ld), CEREAL_NVP(ll), CEREAL_NVP(ull) ); } { cereal::JSONInputArchive ar(oos); int i1, i2, i3, i4, i5, x; ar( i1 ); ar( cereal::make_nvp( "2", i2 ), i3 ); ar( cereal::make_nvp( "4", i4 ), i5 ); ar.loadBinaryValue( &x, sizeof(int) ); OOJson ii; ar( cereal::make_nvp("oo", ii) ); ar( cereal::make_nvp( "2", i2 ) ); std::cout << i1 << " " << i2 << " " << i3 << " " << i4 << " " << i5 << std::endl; std::cout << x << std::endl; std::cout << ii.a << " " << ii.b << " " << ii.c.first << " " << ii.c.second << " "; for( auto z : ii.d ) std::cout << z << " "; std::cout << std::endl; OOJson oo; ar >> cereal::make_nvp("usingop&", oo ); std::cout << oo.a << " " << oo.b << " " << oo.c.first << " " << oo.c.second << " "; for( auto z : oo.d ) std::cout << z << " "; int aa, a, b, c; ar & aa & a & b & c; std::cout << aa << " " << a << " " << b << " " << c << std::endl; long double ld; long long ll; unsigned long long ull; ar( CEREAL_NVP(ld), CEREAL_NVP(ll), CEREAL_NVP(ull) ); std::cout << (ld == std::numeric_limits<long double>::max()) << std::endl; std::cout << (ll == std::numeric_limits<long long>::max()) << std::endl; std::cout << (ull == std::numeric_limits<unsigned long long>::max()) << std::endl; } return 0; }
void LayerAsCentroid(const string &layerName) { OutputObject oo(vector_tile::Tile_GeomType_UNKNOWN, layerMap[layerName], osmID); outputs.push_back(oo); }
// Write this way/node to a vector tile's Layer // Called from Lua void Layer(const string &layerName, bool area) { OutputObject oo(isWay ? (area ? vector_tile::Tile_GeomType_POLYGON : vector_tile::Tile_GeomType_LINESTRING) : vector_tile::Tile_GeomType_POINT, layerMap[layerName], osmID); outputs.push_back(oo); }
MStatus anisotropicShaderNode::compute( const MPlug& plug, MDataBlock& block ) { if ((plug == aOutColor) || (plug.parent() == aOutColor)) { MFloatVector resultColor(0.0,0.0,0.0); MFloatVector diffuseColor( 0.0,0.0,0.0 ); MFloatVector specularColor( 0.0,0.0,0.0 ); MFloatVector ambientColor( 0.0,0.0,0.0 ); // get matrix MFloatMatrix& matrixOToW = block.inputValue( aMatrixOToW ).asFloatMatrix(); MFloatMatrix& matrixWToC = block.inputValue( aMatrixWToC ).asFloatMatrix(); // spin scratch around this vector (in object space ) MFloatVector& A = block.inputValue( aAxesVector ).asFloatVector(); A.normalize(); // spin scratch around this vector (in world space ) MFloatVector wa = A * matrixOToW; wa.normalize(); // spin scratch around this vector (in camera space ) MFloatVector ca = wa * matrixWToC; ca.normalize(); MFloatVector& surfacePoint = block.inputValue( aPointCamera ).asFloatVector(); // get sample surface shading parameters MFloatVector& N = block.inputValue( aNormalCamera ).asFloatVector(); MFloatVector& surfaceColor = block.inputValue( aColor ).asFloatVector(); float diffuseReflectivity = block.inputValue( aDiffuseReflectivity ).asFloat(); float specularCoeff = block.inputValue( aSpecularCoeff ).asFloat(); // get light list MArrayDataHandle lightData = block.inputArrayValue( aLightData ); int numLights = lightData.elementCount(); // iterate through light list and get ambient/diffuse values for( int count=0; count < numLights; count++ ) { MDataHandle currentLight = lightData.inputValue(); MFloatVector& lightIntensity = currentLight.child( aLightIntensity ).asFloatVector(); MFloatVector& lightDirection = currentLight.child( aLightDirection ).asFloatVector(); // find ambient component if( currentLight.child(aLightAmbient).asBool()) { ambientColor[0] += lightIntensity[0] * surfaceColor[0]; ambientColor[1] += lightIntensity[1] * surfaceColor[1]; ambientColor[2] += lightIntensity[2] * surfaceColor[2]; } float cosln = lightDirection * N; if( cosln > 0.0f ){ // illuminated! // find diffuse component if( currentLight.child(aLightDiffuse).asBool()) { float cosDif = cosln * diffuseReflectivity; diffuseColor[0] += lightIntensity[0] * cosDif * surfaceColor[0]; diffuseColor[1] += lightIntensity[1] * cosDif * surfaceColor[1]; diffuseColor[2] += lightIntensity[2] * cosDif * surfaceColor[2]; } // find specular component if( currentLight.child( aLightSpecular).asBool()){ MFloatVector& rayDirection = block.inputValue( aRayDirection ).asFloatVector(); MFloatVector viewDirection = -rayDirection; MFloatVector half = calcHalfVector( viewDirection, lightDirection ); // Beckmann function MFloatVector nA; if( fabs(1.0-fabs(N*ca)) <= 0.0001f ){ MFloatPoint oo( 0.0,0.0,0.0 ); MFloatPoint ow = oo * matrixOToW; MFloatPoint oc = ow * matrixWToC; MFloatVector origin( oc[0], oc[1], oc[2] ); nA = origin - surfacePoint; nA.normalize(); }else{ nA = ca; } MFloatVector x = N ^ nA; x.normalize(); MFloatVector y = N ^ x; y.normalize(); MFloatVector azimuthH = N ^ half; azimuthH = N ^ azimuthH; azimuthH.normalize(); float cos_phai = x * azimuthH; float sin_phai = 0.0; if( fabs(1 - cos_phai*cos_phai) < 0.0001 ){ sin_phai = 0.0; }else{ sin_phai = sqrtf( 1.0f - cos_phai*cos_phai ); } double co = pow( (half * N), 4.0f ); double t = tan( acos(half*N) ); t *= -t; float rough1 = block.inputValue( aRoughness1 ).asFloat(); float rough2 = block.inputValue( aRoughness2 ).asFloat(); double aaa = cos_phai / rough1; double bbb = sin_phai / rough2; t = t * ( aaa*aaa + bbb*bbb ); double D = pow( (1.0/((double)rough1*(double)rough2 * co)), t ); double aa = (2.0 * (N*half) * (N*viewDirection) ) / (viewDirection*half); double bb = (2.0 * (N*half) * (N*lightDirection) ) / (viewDirection*half); double cc = 1.0; double G = 0.0; G = MIN( aa, bb ); G = MIN( G, cc ); float s = (float) (D * G / (double)((N*lightDirection) * (N*viewDirection))); MFloatVector& specColor = block.inputValue( aSpecColor ).asFloatVector(); specularColor[0] += lightIntensity[0] * specColor[0] * s * specularCoeff; specularColor[1] += lightIntensity[1] * specColor[1] * s * specularCoeff; specularColor[2] += lightIntensity[2] * specColor[2] * s * specularCoeff; } } if( !lightData.next() ){ break; } } // result = specular + diffuse + ambient; resultColor = diffuseColor + specularColor + ambientColor; MFloatVector& transparency = block.inputValue( aInTransparency ).asFloatVector(); resultColor[0] *= ( 1.0f - transparency[0] ); resultColor[1] *= ( 1.0f - transparency[1] ); resultColor[2] *= ( 1.0f - transparency[2] ); // set ouput color attribute MDataHandle outColorHandle = block.outputValue( aOutColor ); MFloatVector& outColor = outColorHandle.asFloatVector(); outColor = resultColor; outColorHandle.setClean(); block.setClean( plug ); } else if ((plug == aOutTransparency) || (plug.parent() == aOutTransparency)) { MFloatVector& tr = block.inputValue( aInTransparency ).asFloatVector(); // set ouput color attribute MDataHandle outTransHandle = block.outputValue( aOutTransparency ); MFloatVector& outTrans = outTransHandle.asFloatVector(); outTrans = tr; block.setClean( plug ); } else return MS::kUnknownParameter; return MS::kSuccess; }
Double_t getDeltaTsLL(const Double_t* dts) { // dts must be indexed like so: // [0] = 1-0 // [1] = 2-1 // [2] = 3-2 // ... // // dt's are then calculated by: // 1-0 = dts[0] = dts[ch-(ch-xc)] = dts[1-(1-0)] // 2-1 = dts[1] = dts[2-(2-1)] // 3-0 = dts[3-(3-0)] + dts[3-(3-0-1)] + dts[3-(3-0-2)] // = dts[0] + dts[1] + dts[2] // = 1-0 + 2-1 + 3-2 = 3-0 Double_t chi2(1), c(0), oo(0); for (Int_t ch=1; ch<NSnConstants::kNchans; ++ch) { for (Int_t xc=0; xc<ch; ++xc) { Double_t dt=0; for (Int_t i=(ch-xc); i>0; --i) { dt += dts[ch-i]; } const Double_t odt = dt; Bool_t oob=kFALSE; if (dt<-maxdt) { dt = -maxdt; oob = kTRUE; } else if (dt>maxdt) { dt = maxdt; oob = kTRUE; } dt *= kSmpRate; // convert to samples c = getProbFromCorrCoef(gspl[ch][xc]->Eval(dt)); if (oob) { const Double_t wa = TMath::Abs(odt) - maxdt; oo += wa*wa; } /* if (TMath::Abs(dt)>maxdt) { // really don't like being out of bounds c = TMath::Power(dt, -2.0); } else { // how acceptable is this dt? const Double_t corco = gspl[ch][xc]->Eval(dt); c = getProbFromCorrCoef(corco); } */ if (isnan(c)) { Printf("d[%g, %g, %g], dt=%g, c=%g", dts[0], dts[1], dts[2], dt, c); Printf("ch=%d, xc=%d, gspl[ch][xc]=%p",ch,xc,gspl[ch][xc]); for (Int_t i=-63; i<63; ++i) { printf("(%d, %g), ", i, gspl[ch][xc]->Eval(i)); } printf("\n"); gspl[ch][xc]->Draw("apl"); if (gPad!=0) { gPad->Update(); gPad->WaitPrimitive(); } } chi2 *= c; } // xc } // ch chi2 = -TMath::Log(chi2); chi2 += oo; return chi2; }