/** read matrix */ struct fclib_matrix* read_matrix (hid_t id) { struct fclib_matrix *mat; MM (mat = malloc (sizeof (struct fclib_matrix))); IO (H5LTread_dataset_int (id, "nzmax", &mat->nzmax)); IO (H5LTread_dataset_int (id, "m", &mat->m)); IO (H5LTread_dataset_int (id, "n", &mat->n)); IO (H5LTread_dataset_int (id, "nz", &mat->nz)); if (mat->nz >= 0) /* triplet */ { MM (mat->p = malloc (sizeof (int [mat->nz]))); MM (mat->i = malloc (sizeof (int [mat->nz]))); IO (H5LTread_dataset_int (id, "p", mat->p)); IO (H5LTread_dataset_int (id, "i", mat->i)); } else if (mat->nz == -1) /* csc */ { MM (mat->p = malloc (sizeof (int [mat->n+1]))); MM (mat->i = malloc (sizeof (int [mat->nzmax]))); IO (H5LTread_dataset_int (id, "p", mat->p)); IO (H5LTread_dataset_int (id, "i", mat->i)); } else if (mat->nz == -2) /* csr */ { MM (mat->p = malloc (sizeof (int [mat->m+1]))); MM (mat->i = malloc (sizeof (int [mat->nzmax]))); IO (H5LTread_dataset_int (id, "p", mat->p)); IO (H5LTread_dataset_int (id, "i", mat->i)); } else ASSERT (0, "ERROR: unkown sparse matrix type => fclib_matrix->nz = %d\n", mat->nz); MM (mat->x = malloc (sizeof (double [mat->nzmax]))); IO (H5LTread_dataset_double (id, "x", mat->x)); if (H5LTfind_dataset (id, "conditioning")) { H5T_class_t class_id; hsize_t dim; size_t size; MM (mat->info = malloc (sizeof (struct fclib_matrix_info))); if (H5LTfind_dataset (id, "comment")) { IO (H5LTget_dataset_info (id, "comment", &dim, &class_id, &size)); MM (mat->info->comment = malloc (sizeof (char [size]))); IO (H5LTread_dataset_string (id, "comment", mat->info->comment)); } else mat->info->comment = NULL; IO (H5LTread_dataset_double (id, "conditioning", &mat->info->conditioning)); IO (H5LTread_dataset_double (id, "determinant", &mat->info->determinant)); IO (H5LTread_dataset_int (id, "rank", &mat->info->rank)); } else { mat->info = NULL; } return mat; }
void ProxyArray::Release(ArrayData*ad) { decRefRef(asProxyArray(ad)->m_ref); MM().objFree(ad, sizeof(ProxyArray)); }
static bool HHVM_FUNCTION(hphp_memory_stop_interval) { return MM().stopStatsInterval(); }
void* smart_malloc(size_t nbytes) { auto& mm = MM(); auto const size = mm.debugAddExtra(std::max(nbytes, size_t(1))); return mm.debugPostAllocate(mm.smartMalloc(size), 0, 0); }
//_____________________________________________________________________________// void study(int type, bool wBkg){ string slep="_ee"; string SLEP="_EE_"; if(type==1){ slep = "_mm"; SLEP = "_MM_"; } if(type==2){ slep = "_em"; SLEP = "_EM_"; } TCut EE("llType==0"); TCut MM("llType==1"); TCut EM("llType==2"); // //start modif // bool logy=false;//true; TCut SJ("j_isC20 || j_isB20 || j_isF30"); TCut SEL("nSJets>=0 "); //TCut SEL("nSJets>0 && metrel>60 "); //TCut SEL(SJ && "nSJets==1 && (mll>100 & mll<110) && l_pt[0]>30 "); //TCut SEL("nSJets==1 && metrel>40 && (mll>100 & mll<110) "); //TCut SEL("nSJets==1 && met>40 && l_pt[0]>30"); //TCut SEL("nSJets==1 && metrel>40"); //TCut SEL("nSJets==1 && metrel>40 && l_pt[0]>30"); //TCut SEL(SJ && "nSJets==1 && metrel>40 && l_pt[0]>30 && (mll>100 & mll<110)"); //TCut SEL(SJ && "nSJets==1 && l_pt[0]>30 && (mll>100 & mll<110)"); //TCut SEL("nSJets==1 && metrel>40 && mll>90 & mll<120 && l_pt[0]"); //TCut SEL("nSJets<2 && metrel>40 "); //string var = "l_pt[1]"; //string var = "l_q[0]+l_q[1]"; //string var = "sqrt(2*l_pt[0]*met * (1- cos(acos(cos(l_phi[0]-met_phi)))))"; // string var = "mll"; //string var = "pTll"; //string var = "met"; string var = "metrel"; //string var = "met_refEle"; //string var = "met_refMuo"; //string var = "met_refJet"; //string var = "met_cellout"; // string var = "acos(cos(l_phi[1]-met_phi))"; //string var = "nSJets"; //string var = "j_pt"; //string var = "j_eta"; //string var = "j_jvf"; string sName = "CR2LepSS_noCut"+ SLEP + var; //string sName = "CR2LepSS_VR1SS"+ SLEP + var; //string sName = "CR2LepSS_Jveto"+ SLEP + var; //string sName = "CR2LepSS_ge1SJ_metrel70"+ SLEP + var; //string sName = "CR2LepSS_1Jptl030Mll100-110"+ SLEP + var; //string sName = "CR2LepSS_1JMetrel40"+ SLEP + var; //string sName = "CR2LepSS_Metrel40Mll100-110"+ SLEP + var; //string sName = "CR2LepSS_1JMet40ptl030"+ SLEP + var; // string sName = "CR2LepSS_1JMetrel40"+ SLEP + var; //string sName = "CR2LepSS_1JMetrel40ptl030"+ SLEP + var; //string sName = "CR2LepSS_LE1JMetrel40"+ SLEP + var; //string sName = "CR2LepSS_1JMetrel40Mll90-120"+ SLEP + var; // string sName = "CR2LepSS_1JMetrel40ptl030mll102-106"+ SLEP + var; //string sName = "CR2LepSS_1JMetrel40ptl030mll100-110"+ SLEP + var; //string sName = "CR2LepSS_1Jptl030IN"+ SLEP + var; //string sName = "CR2LepSS_1JMetrel40ptl030IN"+ SLEP + var; //string sName = "CR2LepSS_1JMetrel40ptl030OUT"+ SLEP + var; // //end modif // //No changes needed below string hName ="hdata"+slep; TH1F* hdata = bookHist(var,hName); if(hdata==NULL) abort(); TCut CEE( (SEL && EE ) * "w"); TCut CMM( (SEL && MM ) * "w"); TCut CEM( (SEL && EM ) * "w"); if(wBkg){ TH1F* hFake = (TH1F*) hdata->Clone(); hFake->SetTitle(string("hFake"+slep).c_str()); hFake->SetName(string("hFake"+slep).c_str()); TH1F* hWW = (TH1F*) hdata->Clone(); hWW->SetTitle(string("hWW"+slep).c_str()); hWW->SetName(string("hWW"+slep).c_str()); TH1F* hWZ = (TH1F*) hdata->Clone(); hWZ->SetTitle(string("hWZ"+slep).c_str()); hWZ->SetName(string("hWZ"+slep).c_str()); TH1F* hZZ = (TH1F*) hdata->Clone(); hZZ->SetTitle(string("hZZ"+slep).c_str()); hZZ->SetName(string("hZZ"+slep).c_str()); TH1F* hTOP = (TH1F*) hdata->Clone(); hTOP->SetTitle(string("hTOP"+slep).c_str()); hTOP->SetName(string("hTOP"+slep).c_str()); TH1F* hZJET = (TH1F*) hdata->Clone(); hZJET->SetTitle(string("hZJET"+slep).c_str()); hZJET->SetName(string("hZJET"+slep).c_str()); } //Fill histo if(type==0){ string cmd1 = var + ">>hdata_ee"; c_data->Draw(cmd1.c_str(),CEE,"goff"); if(wBkg){ cmd1 = var + ">>hFake_ee"; c_fake->Draw(cmd1.c_str(),CEE,"goff"); cmd1 = var + ">>hWW_ee"; c_WW->Draw(cmd1.c_str(),CEE,"goff"); cmd1 = var + ">>hWZ_ee"; c_WZ->Draw(cmd1.c_str(),CEE,"goff"); cmd1 = var + ">>hZZ_ee"; c_ZZ->Draw(cmd1.c_str(),CEE,"goff"); cmd1 = var + ">>hTOP_ee"; c_TOP->Draw(cmd1.c_str(),CEE,"goff"); cmd1 = var + ">>hZJET_ee"; c_ZJET->Draw(cmd1.c_str(),CEE,"goff"); } } else if (type==1) { string cmd1 = var + ">>hdata_mm"; c_data->Draw(cmd1.c_str(),CMM,"goff"); if(wBkg){ cmd1 = var + ">>hFake_mm"; c_fake->Draw(cmd1.c_str(),CMM,"goff"); cmd1 = var + ">>hWW_mm"; c_WW->Draw(cmd1.c_str(),CMM,"goff"); cmd1 = var + ">>hWZ_mm"; c_WZ->Draw(cmd1.c_str(),CMM,"goff"); cmd1 = var + ">>hZZ_mm"; c_ZZ->Draw(cmd1.c_str(),CMM,"goff"); cmd1 = var + ">>hTOP_mm"; c_TOP->Draw(cmd1.c_str(),CMM,"goff"); cmd1 = var + ">>hZJET_mm"; c_ZJET->Draw(cmd1.c_str(),CMM,"goff"); } } else if (type==2) { string cmd1 = var + ">>hdata_em"; c_data->Draw(cmd1.c_str(),CEM,"goff"); if(wBkg){ cmd1 = var + ">>hFake_em"; c_fake->Draw(cmd1.c_str(),CEM,"goff"); cmd1 = var + ">>hWW_em"; c_WW->Draw(cmd1.c_str(),CEM,"goff"); cmd1 = var + ">>hWZ_em"; c_WZ->Draw(cmd1.c_str(),CEM,"goff"); cmd1 = var + ">>hZZ_em"; c_ZZ->Draw(cmd1.c_str(),CEM,"goff"); cmd1 = var + ">>hTOP_em"; c_TOP->Draw(cmd1.c_str(),CEM,"goff"); cmd1 = var + ">>hZJET_em"; c_ZJET->Draw(cmd1.c_str(),CEM,"goff"); } } if(wBkg) plot(hdata,hFake,hWW,hWZ,hZZ,hTOP,hZJET, sName,logy); else plot(hdata,sName,logy); }
// ============================================================================ // GLOctree::computePolygons( Node * ) int GLOctree::computePolygons(Node * tree) { //glEnable(GL_DEPTH_TEST); setColor((*psv)[tree->obj].vps->col); // set the color glColor4ub(mycolor.red(), mycolor.green(), mycolor.blue(),store_options->texture_alpha_color); float uv[4][2] = { {0.0, 1.0-v_max}, {0.0, 1.0},{u_max, 1.0}, {u_max, 1.0-v_max} }; static int modulo=0; float rot=0.0; // Get Frustum //frustum.getFC(); int visible=0; int index=tree->index; float x=p_data->pos[index*3 ]+store_options->xtrans, y=p_data->pos[index*3+1]+store_options->ytrans, z=p_data->pos[index*3+2]+store_options->ztrans; //w=1.0; // compute point coordinates according to model via matrix float mx = MM(0,0)*x + MM(0,1)*y + MM(0,2)*z + MM(0,3);//*w; float my = MM(1,0)*x + MM(1,1)*y + MM(1,2)*z + MM(1,3);//*w; float mz= MM(2,0)*x + MM(2,1)*y + MM(2,2)*z + MM(2,3);//*w; modulo += (modulo%4); rot++; if (1) { // frustum.isPointInside(mx,my,mz)) { float new_texture_size=store_options->texture_size; visible++; glPushMatrix(); glTranslatef(mx,my,mz); // move to the transform particles glRotatef(rot,0.0,0.0,1.0); // rotate triangles around z axis glBegin(GL_TRIANGLES); // 1st triangle glTexCoord2f(uv[modulo][0], uv[modulo][1]); modulo = (modulo+1)%4; glVertex3f(-new_texture_size , new_texture_size ,0. ); glTexCoord2f(uv[modulo][0], uv[modulo][1]); modulo = (modulo+1)%4; glVertex3f(-new_texture_size , -new_texture_size ,0. ); glTexCoord2f(uv[modulo][0], uv[modulo][1]); glVertex3f(new_texture_size , -new_texture_size ,0. ); // second triangle modulo = (modulo+2)%4; glTexCoord2f(uv[modulo][0], uv[modulo][1]); glVertex3f(-new_texture_size , new_texture_size ,0. ); modulo = (modulo+2)%4; glTexCoord2f(uv[modulo][0], uv[modulo][1]); glVertex3f(+new_texture_size , -new_texture_size ,0. ); modulo = (modulo+1)%4; glTexCoord2f(uv[modulo][0], uv[modulo][1]); glVertex3f(new_texture_size , new_texture_size ,0. ); glEnd(); glPopMatrix(); } return 1; //std::cerr << "visible = " << visible << "\n"; }
void* smart_malloc(size_t nbytes) { auto& mm = MM(); auto const size = std::max(nbytes, size_t(1)); return mm.smartMalloc(size); }
static void HHVM_FUNCTION(gc_check_heap) { MM().checkHeap("gc_check_heap"); }
bool SparseMatrixTest(const size_t & size, const C_FLOAT64 & sparseness, const unsigned C_INT32 & seed, const bool & RMP, const bool & dgemmFlag, const bool & SMP, const bool & CCMP) { size_t i, j, l, loop = 1; CRandom * pRandom = CRandom::createGenerator(CRandom::mt19937, seed); // If the sparseness is not specified we expect 4 metabolites per reaction C_FLOAT64 Sparseness = sparseness; if (Sparseness == 0.0) Sparseness = 4.0 / size; CMatrix< C_FLOAT64 > M(size - 3, size); CSparseMatrix S(size - 3, size); CMatrix< C_FLOAT64 > MM(size, size + 3); CSparseMatrix Ss(size, size + 3); C_FLOAT64 tmp; for (i = 0; i < size - 3; i++) for (j = 0; j < size; j++) { if (pRandom->getRandomCC() < Sparseness) S(i, j) = (pRandom->getRandomCC() - 0.5) * 100.0; } for (i = 0; i < size; i++) for (j = 0; j < size + 3; j++) { if (pRandom->getRandomCC() < Sparseness) Ss(i, j) = (pRandom->getRandomCC() - 0.5) * 100.0; } M = S; MM = Ss; CCompressedColumnFormat C(S); CCompressedColumnFormat CC(Ss); std::cout << "Memory requirements for sparseness:\t" << Sparseness << std::endl; tmp = (C_FLOAT64) sizeof(CMatrix< C_FLOAT64 >) + size * size * sizeof(C_FLOAT64); std::cout << "Matrix(" << size << "x" << size << "):\t" << tmp << std::endl; C_FLOAT64 tmp2 = (C_FLOAT64) sizeof(CSparseMatrix) + 2 * size * sizeof(std::vector<CSparseMatrixElement *>) + 2 * size * sizeof(C_FLOAT64) + S.numNonZeros() * sizeof(CSparseMatrixElement); std::cout << "Sparse(" << size << "x" << size << "):\t" << tmp2 << std::endl; std::cout << "Sparse/Matrix:\t" << tmp2 / tmp << std::endl; tmp2 = (C_FLOAT64) sizeof(CCompressedColumnFormat) + 2 * C.numNonZeros() * sizeof(C_FLOAT64) + (size + 1) * sizeof(C_FLOAT64); std::cout << "CompressedColumnFormat(" << size << "x" << size << "):\t" << tmp2 << std::endl; std::cout << "CompressedColumnFormat/Matrix:\t" << tmp2 / tmp << std::endl << std::endl; CCopasiTimer CPU(CCopasiTimer::PROCESS); CCopasiTimer WALL(CCopasiTimer::WALL); if (RMP) { // Regular Matrix Product CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CMatrix< C_FLOAT64 > MR(M.numRows(), MM.numCols()); const C_FLOAT64 *pTmp1, *pTmp2, *pTmp4, *pTmp5; const C_FLOAT64 *pEnd1, *pEnd2, *pEnd4; C_FLOAT64 *pTmp3; size_t LDA = M.numCols(); size_t LDB = MM.numCols(); pTmp1 = M.array(); pEnd1 = pTmp1 + M.numRows() * LDA; pEnd2 = MM.array() + LDB; pTmp3 = MR.array(); for (; pTmp1 < pEnd1; pTmp1 += LDA) for (pTmp2 = MM.array(); pTmp2 < pEnd2; pTmp2++, pTmp3++) { *pTmp3 = 0.0; for (pTmp4 = pTmp1, pTmp5 = pTmp2, pEnd4 = pTmp4 + LDA; pTmp4 < pEnd4; pTmp4++, pTmp5 += LDB) * pTmp3 += *pTmp4 * *pTmp5; } } CPU.refresh(); WALL.refresh(); std::cout << "Matrix * Matrix:\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; } if (dgemmFlag) { CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CMatrix< C_FLOAT64 > dgemmR(M.numRows(), MM.numCols()); char T = 'N'; C_INT m = (C_INT) MM.numCols(); /* LDA, LDC */ C_INT n = (C_INT) M.numRows(); C_INT k = (C_INT) M.numCols(); /* LDB */ C_FLOAT64 Alpha = 1.0; C_FLOAT64 Beta = 0.0; dgemm_(&T, &T, &m, &n, &k, &Alpha, MM.array(), &m, M.array(), &k, &Beta, dgemmR.array(), &m); } /* for (i = 0; i < MR.numRows(); i++) for (j = 0; j < MR.numCols(); j++) assert(fabs(MR(i, j) - dgemmR(i, j)) <= 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(MR(i, j))); */ CPU.refresh(); WALL.refresh(); std::cout << "dgemm(Matrix, Matrix):\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; } // Sparse Matrix Product if (SMP) { CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CSparseMatrix SR(S.numRows(), Ss.numCols()); C_FLOAT64 Tmp; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator itRow; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator endRow; std::vector< CSparseMatrixElement * >::const_iterator itRowElement; std::vector< CSparseMatrixElement * >::const_iterator endRowElement; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator itCol; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator endCol; std::vector< CSparseMatrixElement * >::const_iterator itColElement; std::vector< CSparseMatrixElement * >::const_iterator endColElement; for (itRow = S.getRows().begin(), endRow = S.getRows().end(); itRow != endRow; ++itRow) { endRowElement = itRow->end(); for (itCol = Ss.getColumns().begin(), endCol = Ss.getColumns().end(); itCol != endCol; ++itCol) { Tmp = 0; itRowElement = itRow->begin(); itColElement = itCol->begin(); endColElement = itCol->end(); while (itRowElement != endRowElement && itColElement != endColElement) { while (itRowElement != endRowElement && (*itRowElement)->col() < (*itColElement)->row()) ++itRowElement; if (itRowElement == endRowElement) break; while (itColElement != endColElement && (*itColElement)->row() < (*itRowElement)->col()) ++itColElement; if (itColElement == endColElement) break; if ((*itRowElement)->col() != (*itColElement)->row()) continue; Tmp += **itRowElement * **itColElement; ++itRowElement; ++itColElement; } if (fabs(Tmp) < SR.getTreshold()) continue; SR.insert((*itRow->begin())->row(), (*itCol->begin())->col(), Tmp); } } } CPU.refresh(); WALL.refresh(); std::cout << "Sparse * Sparse:\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; /* for (i = 0; i < MR.numRows(); i++) for (j = 0; j < MR.numCols(); j++) assert(fabs(MR(i, j) - SR(i, j)) < SR.getTreshold()); */ } // Compressed Column Format Product if (CCMP) { CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CSparseMatrix TmpR(C.numRows(), CC.numCols()); CCompressedColumnFormat CR(C.numRows(), CC.numCols(), 0); C_FLOAT64 Tmp; size_t imax = CR.numRows(); size_t jmax = CR.numCols(); C_FLOAT64 * pColElement, * pEndColElement; size_t * pColElementRow, * pEndColElementRow; size_t * pColStart; CCompressedColumnFormat::const_row_iterator itRowElement; CCompressedColumnFormat::const_row_iterator endRowElement = C.endRow(0); for (j = 0, pColStart = CC.getColumnStart(); j < jmax; j++, pColStart++) { for (i = 0; i < imax; i++) { Tmp = 0; itRowElement = C.beginRow(i); pColElement = CC.getValues() + *pColStart; pEndColElement = CC.getValues() + *(pColStart + 1); pColElementRow = CC.getRowIndex() + *pColStart; pEndColElementRow = CC.getRowIndex() + *(pColStart + 1); while (itRowElement != endRowElement && pColElement != pEndColElement) { while (itRowElement != endRowElement && itRowElement.getColumnIndex() < *pColElementRow) ++itRowElement; if (!(itRowElement != endRowElement)) break; while (pColElement != pEndColElement && *pColElementRow < itRowElement.getColumnIndex()) { ++pColElement; ++pColElementRow; } if (pColElement == pEndColElement) break; if (itRowElement.getColumnIndex() != *pColElementRow) continue; Tmp += *itRowElement * *pColElement; ++itRowElement; ++pColElement; ++pColElementRow; } if (fabs(Tmp) < TmpR.getTreshold()) continue; TmpR.insert(i, j, Tmp); } } CR = TmpR; } CPU.refresh(); WALL.refresh(); std::cout << "Compressed * Compressed:\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; /* for (i = 0; i < MR.numRows(); i++) for (j = 0; j < MR.numCols(); j++) assert(fabs(MR(i, j) - TmpR(i, j)) < SR.getTreshold()); */ } std::cout << std::endl; std::cout << std::endl; return true; }
void delete_AwaitAllWaitHandle(ObjectData* od, const Class*) { auto const waitHandle = static_cast<c_AwaitAllWaitHandle*>(od); auto bytes = waitHandle->heapSize(); waitHandle->~c_AwaitAllWaitHandle(); MM().objFreeLogged(waitHandle, bytes); }
static int64_t HHVM_FUNCTION(gc_collect_cycles) { MM().collect("gc_collect_cycles"); return 0; // seriously, count cycles? }
c_AwaitAllWaitHandle* c_AwaitAllWaitHandle::Alloc(int32_t cnt) { auto size = c_AwaitAllWaitHandle::heapSize(cnt); auto mem = MM().objMallocLogged(size); return new (mem) c_AwaitAllWaitHandle(cnt); }
TEST(MemoryManager, RootMaps) { { ASSERT_EQ(MM().lookupRoot<DummyResource>(0), nullptr); auto dummy = makeSmartPtr<DummyResource>(); auto id = MM().addRoot(dummy); ASSERT_EQ(MM().lookupRoot<DummyResource>(id), dummy); auto removed = MM().removeRoot<DummyResource>(id); ASSERT_EQ(removed, dummy); ASSERT_EQ(MM().lookupRoot<DummyResource>(id), nullptr); ASSERT_FALSE(MM().removeRoot<DummyResource>(id)); MM().addRoot(dummy); ASSERT_TRUE(MM().removeRoot(dummy)); } { ASSERT_EQ(MM().lookupRoot<c_Vector>(0), nullptr); auto vec = makeSmartPtr<c_Vector>(); auto id = MM().addRoot(vec); ASSERT_EQ(MM().lookupRoot<c_Vector>(id), vec); auto removed = MM().removeRoot<c_Vector>(id); ASSERT_EQ(removed, vec); ASSERT_EQ(MM().lookupRoot<c_Vector>(id), nullptr); ASSERT_FALSE(MM().removeRoot<c_Vector>(id)); MM().addRoot(vec); ASSERT_TRUE(MM().removeRoot(vec)); } }
// ============================================================================ // DrawBox::draw() // convert particles from 3D space to 2D screen coordinates // compute blending values for particles and texture void DrawBox::draw( GLBox * glbox, const ParticlesData * part_data, const ParticlesSelectVector * _psv, const GlobalOptions * _store_options, QString shot_name) { const double * mProj = glbox->getProjMatrix(); double * mMod = const_cast<double*> (glbox->getModelMatrix()); // get data pointers viewport = glbox->getViewPort(); store_options = _store_options; psv = _psv; #define MP(row,col) mProj[col*4+row] #define MM(row,col) mMod[col*4+row] // get windows size width = viewport[2]; height= viewport[3]; // set windows size setGeometry(viewport[0],viewport[1],viewport[2],viewport[3]); //QPainter paint(this); //paint.eraseRect(viewport[0],viewport[1],viewport[2],viewport[3]); clearBuffer(); if (psv->size()) { // Zoom is located in ModelView matrix at coordinates MM(2,3) // loop on all object for (int i=0; i< (int ) psv->size(); i++ ) { // loop on all visible object selected particles //std::cerr << "----------\n"; if ((*psv)[i].vps->is_visible ) { for (int j = 0; j < (*psv)[i].vps->ni_index; j ++) { int jndex= (*psv)[i].vps->index_tab[j]; float x=part_data->pos[jndex*3 ], y=part_data->pos[jndex*3+1], z=part_data->pos[jndex*3+2], w=1; // do the product Mmodel X point = mxyzw float myzw0 = MM(0,1)*y + MM(0,2)*z + MM(0,3)*w; float mx = MM(0,0)*x + myzw0; float mx1= mx + store_options->texture_size/2.; // move X from half a texture float myzw1 = MM(1,1)*y + MM(1,2)*z + MM(1,3)*w; float my = MM(1,0)*x + myzw1; float MmzG = MM(2,1)*y + MM(2,2)*z; float Mmz = MM(2,0)*x + MmzG; float mz = Mmz + MM(2,3)*w; float mwG= MM(3,1)*y + MM(3,2)*z + MM(3,3)*w; float mw = MM(3,0)*x + mwG; // do the product Mproj X mxyzw = pxyzw float Ppx = MP(0,0)*mx + MP(0,1)*my + MP(0,3)*mw; float px = Ppx + MP(0,2)*mz; float px1 = MP(0,0)*mx1 + MP(0,1)*my + MP(0,3)*mw + MP(0,2)*mz; float Ppy= MP(1,0)*mx + MP(1,1)*my + MP(1,3)*mw; float py = Ppy + MP(1,2)*mz; float Ppz= MP(2,0)*mx + MP(2,1)*my + MP(2,3)*mw; float pz = Ppz + MP(2,2)*mz; float Ppw= MP(3,0)*mx + MP(3,1)*my + MP(3,3)*mw; float pw = Ppw + MP(3,2)*mz; float pw1 = MP(3,0)*mx1 + MP(3,1)*my + MP(3,3)*mw + MP(3,2)*mz; // normalyze //std::cerr << px << " " << py << " " << pz << "\n"; px /= pw; px1/= pw1; py /= pw; pz /= pw; //std::cerr << px << " " << py << " " << pz << "\n"; // compute screen coordinates float winx =viewport[0] + (1 + px) * viewport[2] / 2; float winx1=viewport[0] + (1 + px1) * viewport[2] / 2; float winy =viewport[1] + (1 + py) * viewport[3] / 2; // paint particles //paint.setPen(red); //paint.drawPoint((int) (winx), viewport[3]-(int) (winy)); #define MMAX(A,B) ((A)>(B)?(A):(B)) #define MMIN(A,B) ((A)<(B)?(A):(B)) //if (winx >= 0. && winy >= 0 && winx < 1024 && winy < 1024) { if (winx >= 0. && winy >= 0 && winx < width && winy < height && pz<1.0) { float size_texture = (int) fabs(winx1-winx); //std::cerr << "x=" << winx << " x1=" << winx1 << " size="<<size_texture<< "\n"; //color_rgba[(int) (winx)][(int) (winy)].blend(psv[i].vps->col,(float) (alpha)/255.); if (store_options->show_part) { //color_rgba[(int) (winx)][viewport[3]-1-(int) (winy)].blend((*psv)[i].vps->col, //(float) (store_options->particles_alpha)/255.); filterPoint( winx,winy,(*psv)[i].vps->col,(float) (store_options->particles_alpha)/255.); } //paint.drawPoint((int) (winx), (int) (winy)); if (store_options->show_poly) { float s4 = size_texture*4.; float ratio_texture = s4 - floor(s4); float ceil_texture = ceil(s4); texture->draw(this,psv,i,winx,winy,(int)(ceil_texture), ratio_texture); } } } } } } paintBuffer(shot_name); }
int64_t f_memory_get_peak_usage(bool real_usage /* = false */) { auto const& stats = MM().getStats(); return real_usage ? stats.peakUsage : stats.peakAlloc; }
StructArray* StructArray::createNoCopy(Shape* shape, size_t length) { auto ptr = MM().objMalloc(bytesForCapacity(shape->capacity())); return new (NotNull{}, ptr) StructArray(length, 0, shape); }
// ============================================================================ // GLOctree::hackTreePolygons int GLOctree::hackTreePolygons(Node * tree, float * rmid, int level, bool check_tree) { #define MM(row,col) mModel[col*4+row] float vv[8][3]; // 8 vertex to store //std::cerr << "hi\n"; float new_rmid[8][3]; if ( !tree ) { // free node return 0; } else if (tree->type == 1) { // a leaf if (level >= store_options->octree_level) { // selected particles (*psv)[tree->obj].vps->addIndexTab(tree->index); //computePolygons( tree ); } return 1; } else { // a node // Build float square_minus1=(float ) size_max/(1<<(level-1)); float square=(float ) size_max/(1<<level); int fac[2] = { -1,1 }; for (int i=0;i<2;i++) { for (int j=0;j<2;j++) { for (int k=0;k<2;k++) { int octant=(i<<2)+(j<<1)+k; // new middle coordinates new_rmid[octant][0]=fac[i]*square+rmid[0]; new_rmid[octant][1]=fac[j]*square+rmid[1]; new_rmid[octant][2]=fac[k]*square+rmid[2]; if (check_tree) { // vertex's octant coordinates vv[octant][0]=fac[i]*square_minus1+rmid[0];//+fac[i]*textureX2; vv[octant][1]=fac[j]*square_minus1+rmid[1];//+fac[j]*textureX2; vv[octant][2]=fac[k]*square_minus1+rmid[2];//+fac[k]*textureX2; // } assert(octant<8); //hackTreePolygons(tree->node[octant],new_rmid,level+1,true); } //k } //j } //i bool inside=true; // true if octant inside FC // must check_tree if not all the vertex of the octant // are not in the frustum if (check_tree) { int np_inside=0; // check out octant in FC? for (int i=0; i<8; i++) { float x=vv[i][0]+store_options->xtrans; float y=vv[i][1]+store_options->ytrans; float z=vv[i][2]+store_options->ztrans; #if 0 // compute point coordinates according to model via matrix float mx = MM(0,0)*x + MM(0,1)*y + MM(0,2)*z + MM(0,3);//*w; float my = MM(1,0)*x + MM(1,1)*y + MM(1,2)*z + MM(1,3);//*w; float mz= MM(2,0)*x + MM(2,1)*y + MM(2,2)*z + MM(2,3);//*w; #endif if (frustum.isPointInside(x,y,z)) { //!!mx,my,mz)) { np_inside++; } } // check if center of octant is inside if (np_inside == 0) { float x=rmid[0]+store_options->xtrans; float y=rmid[1]+store_options->ytrans; float z=rmid[2]+store_options->ztrans; #if 0 // compute point coordinates according to model via matrix float mx = MM(0,0)*x + MM(0,1)*y + MM(0,2)*z + MM(0,3);//*w; float my = MM(1,0)*x + MM(1,1)*y + MM(1,2)*z + MM(1,3);//*w; float mz= MM(2,0)*x + MM(2,1)*y + MM(2,2)*z + MM(2,3);//*w; #endif if (frustum.isPointInside(x,y,z)) { //!!mx,my,mz)) { np_inside++; } } if (np_inside==0) { // the whole octant inside = false; // is out of the FC } else if (np_inside==8) { // the whole octant is in the FC check_tree = false; // no need to keep compute the FC } } if (inside) { // octant inside FC for (int i=0; i<8; i++) { // check out sub octants hackTreePolygons(tree->node[i],new_rmid[i],level+1,check_tree); } } } return 1; }
/* * mm_put_header - Generate the header of a block and return the data section. */ inline void *mm_put_header(void *ptr, size_t size) { MM(ptr)->size = size; return ptr + MM_HEADER_SIZE; }
void APCLocalArray::Release(ArrayData* ad) { auto const smap = asSharedArray(ad); smap->~APCLocalArray(); MM().smartFreeSize(smap, sizeof(APCLocalArray)); }
/* * mm_malloc - Allocate a block. * Always allocate a block whose size is a multiple of the alignment. */ void *mm_malloc(size_t size) { #ifdef MM_CHECK if (!size) return; #endif void *now = mm_first_free(); void *best = NULL; size_t now_size = 0; size_t best_size = SIZE_T_MAX; size_t need_size = MM_HEADER_SIZE + ALIGN(size); // historical data total_alloc += need_size; if (MM_SEARCH()) { // scan the block list // if the best one is not found, keep best == NULL // if the last one is used, let now_size == 0 while ((now - 1) != mem_heap_hi()) { now_size = MM(now)->size; if (SIGN_CHECK(now_size)) { // current block is not used now_size = SIGN_MARK(now_size); // try to merge useable blocks while (now_size < need_size && mm_merge(now, &now_size)); // check if this block is useable and useful if (now_size >= need_size && now_size < best_size) { best = now; best_size = now_size; if (MM_FIT(need_size, now_size)) break; } // visit the next block now += now_size; } else { // current block is used // visit the next block now += now_size; // reset now_size now_size = 0; } } if (best) { // there is useable block and splitting is possible return mm_split(best, best_size, need_size); } else { // there is no useable block and sbrk is needed return mm_break(now - now_size, now_size, need_size); } } else { // force sbrk return mm_break(mem_heap_hi() + 1, 0, need_size); } }
void smart_free(void* ptr) { if (ptr) MM().smartFree(ptr); }
HOT_FUNC void SharedArray::Release(ArrayData* ad) { auto const smap = asSharedArray(ad); smap->~SharedArray(); MM().smartFreeSize(smap, sizeof(SharedArray)); }
void smart_free(void* ptr) { if (!ptr) return; auto& mm = MM(); mm.smartFree(mm.debugPreFree(ptr, 0, 0)); }
void dynamicLagrangian<BasicTurbulenceModel>::correct() { if (!this->turbulence_) { return; } // Local references const surfaceScalarField& phi = this->phi_; const volVectorField& U = this->U_; LESeddyViscosity<BasicTurbulenceModel>::correct(); tmp<volTensorField> tgradU(fvc::grad(U)); const volTensorField& gradU = tgradU(); volSymmTensorField S(dev(symm(gradU))); volScalarField magS(mag(S)); volVectorField Uf(filter_(U)); volSymmTensorField Sf(dev(symm(fvc::grad(Uf)))); volScalarField magSf(mag(Sf)); volSymmTensorField L(dev(filter_(sqr(U)) - (sqr(filter_(U))))); volSymmTensorField M ( 2.0*sqr(this->delta())*(filter_(magS*S) - 4.0*magSf*Sf) ); volScalarField invT ( (1.0/(theta_.value()*this->delta()))*pow(flm_*fmm_, 1.0/8.0) ); volScalarField LM(L && M); fvScalarMatrix flmEqn ( fvm::ddt(flm_) + fvm::div(phi, flm_) == invT*LM - fvm::Sp(invT, flm_) ); flmEqn.relax(); flmEqn.solve(); bound(flm_, flm0_); volScalarField MM(M && M); fvScalarMatrix fmmEqn ( fvm::ddt(fmm_) + fvm::div(phi, fmm_) == invT*MM - fvm::Sp(invT, fmm_) ); fmmEqn.relax(); fmmEqn.solve(); bound(fmm_, fmm0_); correctNut(gradU); }
void APCLocalArray::Release(ArrayData* ad) { assert(ad->hasExactlyOneRef()); auto const a = asApcArray(ad); a->~APCLocalArray(); MM().freeSmallSize(a, sizeof(APCLocalArray)); }
void RequestInjectionData::threadInit() { // phpinfo { auto setAndGetWall = IniSetting::SetAndGet<int64_t>( [this](const int64_t &limit) { setTimeout(limit); return true; }, [this] { return getTimeout(); } ); auto setAndGetCPU = IniSetting::SetAndGet<int64_t>( [this](const int64_t &limit) { setCPUTimeout(limit); return true; }, [this] { return getCPUTimeout(); } ); auto setAndGet = RuntimeOption::TimeoutsUseWallTime ? setAndGetWall : setAndGetCPU; IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "max_execution_time", setAndGet); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "maximum_execution_time", setAndGet); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "hhvm.max_wall_time", setAndGetWall); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "hhvm.max_cpu_time", setAndGetCPU); } // Resource Limits IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "memory_limit", IniSetting::SetAndGet<std::string>( [this](const std::string& value) { int64_t newInt = strtoll(value.c_str(), nullptr, 10); if (newInt <= 0) { newInt = std::numeric_limits<int64_t>::max(); m_maxMemory = std::to_string(newInt); } else { m_maxMemory = value; newInt = convert_bytes_to_long(value); if (newInt <= 0) { newInt = std::numeric_limits<int64_t>::max(); } } MM().getStatsNoRefresh().maxBytes = newInt; return true; }, nullptr ), &m_maxMemory); // Data Handling IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "arg_separator.output", "&", &m_argSeparatorOutput); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "arg_separator.input", "&", &m_argSeparatorInput); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "variables_order", "EGPCS", &m_variablesOrder); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "request_order", "", &m_requestOrder); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "default_charset", RuntimeOption::DefaultCharsetName.c_str(), &m_defaultCharset); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "default_mimetype", "text/html", &m_defaultMimeType); // Paths and Directories IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "include_path", getDefaultIncludePath().c_str(), IniSetting::SetAndGet<std::string>( [this](const std::string& value) { m_include_paths.clear(); int pos = value.find(':'); if (pos < 0) { m_include_paths.push_back(value); } else { int pos0 = 0; do { // Check for stream wrapper if (value.length() > pos + 2 && value[pos + 1] == '/' && value[pos + 2] == '/') { // .:// or ..:// is not stream wrapper if (((pos - pos0) >= 1 && value[pos - 1] != '.') || ((pos - pos0) >= 2 && value[pos - 2] != '.') || (pos - pos0) > 2) { pos += 3; continue; } } m_include_paths.push_back( value.substr(pos0, pos - pos0)); pos++; pos0 = pos; } while ((pos = value.find(':', pos)) >= 0); if (pos0 <= value.length()) { m_include_paths.push_back( value.substr(pos0)); } } return true; }, [this]() { std::string ret; bool first = true; for (auto &path : m_include_paths) { if (first) { first = false; } else { ret += ":"; } ret += path; } return ret; } )); // Paths and Directories m_allowedDirectories = RuntimeOption::AllowedDirectories; m_safeFileAccess = RuntimeOption::SafeFileAccess; IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "open_basedir", IniSetting::SetAndGet<std::string>( [this](const std::string& value) { auto boom = HHVM_FN(explode)(";", value).toCArrRef(); std::vector<std::string> directories; directories.reserve(boom.size()); for (ArrayIter iter(boom); iter; ++iter) { const auto& path = iter.second().toString(); // Canonicalise the path if (!path.empty() && File::TranslatePathKeepRelative(path).empty()) { return false; } if (path.equal(s_dot)) { auto cwd = g_context->getCwd().toCppString(); directories.push_back(cwd); } else { directories.push_back(path.toCppString()); } } m_allowedDirectories = directories; m_safeFileAccess = !boom.empty(); return true; }, [this]() -> std::string { if (!hasSafeFileAccess()) { return ""; } std::string out; for (auto& directory: getAllowedDirectories()) { if (!directory.empty()) { out += directory + ";"; } } // Remove the trailing ; if (!out.empty()) { out.erase(std::end(out) - 1, std::end(out)); } return out; } )); // Errors and Logging Configuration Options IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "error_reporting", std::to_string(RuntimeOption::RuntimeErrorReportingLevel) .c_str(), &m_errorReportingLevel); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "track_errors", "0", &m_trackErrors); IniSetting::Bind( IniSetting::CORE, IniSetting::PHP_INI_ALL, "html_errors", IniSetting::SetAndGet<bool>( [&] (const bool& on) { m_htmlErrors = on; return true; }, [&] () { return m_htmlErrors; } ), &m_htmlErrors ); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "log_errors", IniSetting::SetAndGet<bool>( [this](const bool& on) { if (m_logErrors != on) { if (on) { if (!m_errorLog.empty()) { FILE *output = fopen(m_errorLog.data(), "a"); if (output) { Logger::SetNewOutput(output); } } } else { Logger::SetNewOutput(nullptr); } } return true; }, nullptr ), &m_logErrors); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "error_log", IniSetting::SetAndGet<std::string>( [this](const std::string& value) { if (m_logErrors && !m_errorLog.empty()) { FILE *output = fopen(m_errorLog.data(), "a"); if (output) { Logger::SetNewOutput(output); } } return true; }, nullptr ), &m_errorLog); // Filesystem and Streams Configuration Options IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "user_agent", "", &m_userAgent); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "default_socket_timeout", std::to_string(RuntimeOption::SocketDefaultTimeout).c_str(), &m_socketDefaultTimeout); // Response handling. // TODO(T5601927): output_compression supports int values where the value // represents the output buffer size. Also need to add a // zlib.output_handler ini setting as well. // http://docs.hhvm.com/zlib.configuration.php IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "zlib.output_compression", &m_gzipCompression); IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_ALL, "zlib.output_compression_level", &m_gzipCompressionLevel); }
static int64_t HHVM_FUNCTION(memory_get_allocation) { auto const& stats = MM().getStats(); int64_t ret = stats.totalAlloc; assert(ret >= 0); return ret; }
int64_t f_memory_get_allocation() { auto const& stats = MM().getStats(); int64_t ret = stats.totalAlloc; assert(ret >= 0); return ret; }
void assemble_cortical(const Geometry& geo, Matrix& mat, const Head2EEGMat& M, const std::string& domain_name, const unsigned gauss_order, double alpha, double beta, const std::string &filename) { // Following the article: M. Clerc, J. Kybic "Cortical mapping by Laplace–Cauchy transmission using a boundary element method". // Assumptions: // - domain_name: the domain containing the sources is an innermost domain (defined as the interior of only one interface (called Cortex) // - Cortex interface is composed of one mesh only (no shared vertices) const Domain& SourceDomain = geo.domain(domain_name); const Interface& Cortex = SourceDomain.begin()->interface(); const Mesh& cortex = Cortex.begin()->mesh(); om_error(SourceDomain.size()==1); om_error(Cortex.size()==1); // shape of the new matrix: unsigned Nl = geo.size()-geo.outermost_interface().nb_triangles()-Cortex.nb_vertices()-Cortex.nb_triangles(); unsigned Nc = geo.size()-geo.outermost_interface().nb_triangles(); std::fstream f(filename.c_str()); Matrix P; if ( !f ) { // build the HeadMat: // The following is the same as assemble_HM except N_11, D_11 and S_11 are not computed. SymMatrix mat_temp(Nc); mat_temp.set(0.0); double K = 1.0 / (4.0 * M_PI); // We iterate over the meshes (or pair of domains) to fill the lower half of the HeadMat (since its symmetry) for ( Geometry::const_iterator mit1 = geo.begin(); mit1 != geo.end(); ++mit1) { for ( Geometry::const_iterator mit2 = geo.begin(); (mit2 != (mit1+1)); ++mit2) { // if mit1 and mit2 communicate, i.e they are used for the definition of a common domain const int orientation = geo.oriented(*mit1, *mit2); // equals 0, if they don't have any domains in common // equals 1, if they are both oriented toward the same domain // equals -1, if they are not if ( orientation != 0) { double Scoeff = orientation * geo.sigma_inv(*mit1, *mit2) * K; double Dcoeff = - orientation * geo.indicator(*mit1, *mit2) * K; double Ncoeff; if ( !(mit1->outermost() || mit2->outermost()) && ( (*mit1 != *mit2)||( *mit1 != cortex) ) ) { // Computing S block first because it's needed for the corresponding N block operatorS(*mit1, *mit2, mat_temp, Scoeff, gauss_order); Ncoeff = geo.sigma(*mit1, *mit2)/geo.sigma_inv(*mit1, *mit2); } else { Ncoeff = orientation * geo.sigma(*mit1, *mit2) * K; } if ( !mit1->outermost() && (( (*mit1 != *mit2)||( *mit1 != cortex) )) ) { // Computing D block operatorD(*mit1, *mit2, mat_temp, Dcoeff, gauss_order,false); } if ( ( *mit1 != *mit2 ) && ( !mit2->outermost() ) ) { // Computing D* block operatorD(*mit1, *mit2, mat_temp, Dcoeff, gauss_order, true); } // Computing N block if ( (*mit1 != *mit2)||( *mit1 != cortex) ) { operatorN(*mit1, *mit2, mat_temp, Ncoeff, gauss_order); } } } } // Deflate the diagonal block (N33) of 'mat' : (in order to have a zero-mean potential for the outermost interface) const Interface interface = geo.outermost_interface(); unsigned i_first = (*interface.begin()->mesh().vertex_begin())->index(); deflat(mat_temp, interface, mat_temp(i_first, i_first) / (geo.outermost_interface().nb_vertices())); mat = Matrix(Nl, Nc); mat.set(0.0); // copy mat_temp into mat except the lines for cortex vertices [i_vb_c, i_ve_c] and cortex triangles [i_tb_c, i_te_c]. unsigned iNl = 0; for ( Geometry::const_iterator mit = geo.begin(); mit != geo.end(); ++mit) { if ( *mit != cortex ) { for ( Mesh::const_vertex_iterator vit = mit->vertex_begin(); vit != mit->vertex_end(); ++vit) { mat.setlin(iNl, mat_temp.getlin((*vit)->index())); ++iNl; } if ( !mit->outermost() ) { for ( Mesh::const_iterator tit = mit->begin(); tit != mit->end(); ++tit) { mat.setlin(iNl, mat_temp.getlin(tit->index())); ++iNl; } } } } // ** Construct P: the null-space projector ** Matrix W; { Matrix U, s; mat.svd(U, s, W); } SparseMatrix S(Nc,Nc); // we set S to 0 everywhere, except in the last part of the diag: for ( unsigned i = Nl; i < Nc; ++i) { S(i, i) = 1.0; } P = (W * S) * W.transpose(); // P is a projector: P^2 = P and mat*P*X = 0 if ( filename.length() != 0 ) { std::cout << "Saving projector P (" << filename << ")." << std::endl; P.save(filename); } } else { std::cout << "Loading projector P (" << filename << ")." << std::endl; P.load(filename); } // ** Get the gradient of P1&P0 elements on the meshes ** Matrix MM(M.transpose() * M); SymMatrix RR(Nc, Nc); RR.set(0.); for ( Geometry::const_iterator mit = geo.begin(); mit != geo.end(); ++mit) { mit->gradient_norm2(RR); } // ** Choose Regularization parameter ** SparseMatrix alphas(Nc,Nc); // diagonal matrix Matrix Z; if ( alpha < 0 ) { // try an automatic method... TODO find better estimation double nRR_v = RR.submat(0, geo.nb_vertices(), 0, geo.nb_vertices()).frobenius_norm(); alphas.set(0.); alpha = MM.frobenius_norm() / (1.e3*nRR_v); beta = alpha * 50000.; for ( Vertices::const_iterator vit = geo.vertex_begin(); vit != geo.vertex_end(); ++vit) { alphas(vit->index(), vit->index()) = alpha; } for ( Meshes::const_iterator mit = geo.begin(); mit != geo.end(); ++mit) { if ( !mit->outermost() ) { for ( Mesh::const_iterator tit = mit->begin(); tit != mit->end(); ++tit) { alphas(tit->index(), tit->index()) = beta; } } } std::cout << "AUTOMATIC alphas = " << alpha << "\tbeta = " << beta << std::endl; } else { for ( Vertices::const_iterator vit = geo.vertex_begin(); vit != geo.vertex_end(); ++vit) { alphas(vit->index(), vit->index()) = alpha; } for ( Meshes::const_iterator mit = geo.begin(); mit != geo.end(); ++mit) { if ( !mit->outermost() ) { for ( Mesh::const_iterator tit = mit->begin(); tit != mit->end(); ++tit) { alphas(tit->index(), tit->index()) = beta; } } } std::cout << "alphas = " << alpha << "\tbeta = " << beta << std::endl; } Z = P.transpose() * (MM + alphas*RR) * P; // ** PseudoInverse and return ** // X = P * { (M*P)' * (M*P) + (R*P)' * (R*P) }¡(-1) * (M*P)'m // X = P * { P'*M'*M*P + P'*R'*R*P }¡(-1) * P'*M'm // X = P * { P'*(MM + a*RR)*P }¡(-1) * P'*M'm // X = P * Z¡(-1) * P' * M'm Matrix rhs = P.transpose() * M.transpose(); mat = P * Z.pinverse() * rhs; }
void SceneManager::Update() { RenderLayerManager & renderManager = RenderLayerManager::GetRenderLayerManager(); const PVRTVec3 center = renderManager.GetCenter(); float occlusionRadius = renderManager.GetOcclusionRadius(); PVRTVec4 vecA( mLookMtx->f[12], 0.0f, mLookMtx->f[14], 1); PVRTVec4 vecB( GLOBAL_SCALE * FRUSTUM_W, 0.0f, GLOBAL_SCALE * FRUSTUM_D, 1); PVRTVec4 vecC( GLOBAL_SCALE * -FRUSTUM_W, 0.0f, GLOBAL_SCALE * FRUSTUM_D, 1); vecB = *mLookMtx * vecB; vecC = *mLookMtx * vecC; PVRTVec2 A(vecA.x, vecA.z); PVRTVec2 B(vecB.x, vecB.z); PVRTVec2 C(vecC.x, vecC.z); mToApplyCount = 0; if (mQuadTree) { static QuadNode * quadNodes[256]={0}; int quadNodeCount = 0; //mQuadTree->GetQuads(center.x, center.z, occlusionRadius, quadNodes, quadNodeCount); mQuadTree->GetQuadsCameraFrustum(quadNodes, quadNodeCount, mLookMtx); quadNodeCount--; bool useFrustumCulling = true; //!!!!!!!!!!!!!!!!!!!!! for (int quad = quadNodeCount ; quad >=0 ; quad--) { QuadNode * pQuadNode = quadNodes[quad]; List & dataList = pQuadNode->GetDataList(); ListIterator listIter(dataList); while( Node * pRootNode = (Node*)listIter.GetPtr() ) { if (!pRootNode->IsVisible()) continue; //pRootNode->UpdateWithoutChildren(); bool useOcclusionRadius = pRootNode->GetUseOcclusionCulling(); PVRTVec3 worldPos = pRootNode->GetWorldTranslation(); if (!useFrustumCulling && useOcclusionRadius) { PVRTVec3 distVec = worldPos - center; if ( distVec.lenSqr() < MM(occlusionRadius) ) { pRootNode->SetInFrustum(true); pRootNode->Update(); mToApply[mToApplyCount] = pRootNode; mToApplyCount++; } else { pRootNode->SetInFrustum(false); } } else if (useFrustumCulling) { PVRTVec2 P(worldPos.x, worldPos.z); PVRTVec2 v0 = C - A; PVRTVec2 v1 = B - A; PVRTVec2 v2 = P - A; // Compute dot products float dot00 = v0.dot(v0); float dot01 = v0.dot(v1); float dot02 = v0.dot(v2); float dot11 = v1.dot(v1); float dot12 = v1.dot(v2); // Compute barycentric coordinates float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01); float u = (dot11 * dot02 - dot01 * dot12) * invDenom; float v = (dot00 * dot12 - dot01 * dot02) * invDenom; bool addToList = false; // Check if point is in triangle //PVRTVec3 distVec = worldPos - center; //if ( distVec.lenSqr() < MM(occlusionRadius) ) { if ( (u > 0) && (v > 0) && (u + v < 1)) { addToList = true; } else if ( Collision::CircleTriangleEdgeIntersection(A,B,P, pRootNode->GetRadius() ) ) { addToList = true; } else if ( Collision::CircleTriangleEdgeIntersection(A,C,P, pRootNode->GetRadius() )) { addToList = true; } if (addToList) { pRootNode->SetInFrustum(true); //pRootNode->Update(); mToApply[mToApplyCount] = pRootNode; mToApplyCount++; } else { pRootNode->SetInFrustum(false); } } //else //{ // pRootNode->SetInFrustum(false); //} } else { pRootNode->SetInFrustum(true); //pRootNode->Update(); mToApply[mToApplyCount] = pRootNode; mToApplyCount++; } } } } for (int n=0;n<mNodeCount;n++) { Node * pRootNode = mRootNodes[n]; if (!pRootNode->IsVisible()) continue; pRootNode->UpdateWithoutChildren(); bool useOcclusionRadius = pRootNode->GetUseOcclusionCulling(); PVRTVec3 worldPos = pRootNode->GetWorldTranslation(); PVRTVec3 distVec = worldPos - center; if (useOcclusionRadius) { if ( distVec.lenSqr() < MM(occlusionRadius) ) { PVRTVec2 P(worldPos.x, worldPos.z); PVRTVec2 v0 = C - A; PVRTVec2 v1 = B - A; PVRTVec2 v2 = P - A; // Compute dot products float dot00 = v0.dot(v0); float dot01 = v0.dot(v1); float dot02 = v0.dot(v2); float dot11 = v1.dot(v1); float dot12 = v1.dot(v2); // Compute barycentric coordinates float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01); float u = (dot11 * dot02 - dot01 * dot12) * invDenom; float v = (dot00 * dot12 - dot01 * dot02) * invDenom; bool addToList = false; // Check if point is in triangle //PVRTVec3 distVec = worldPos - center; //if ( distVec.lenSqr() < MM(occlusionRadius) ) { if ( (u > 0) && (v > 0) && (u + v < 1)) { addToList = true; } else if ( Collision::CircleTriangleEdgeIntersection(A,B,P, pRootNode->GetRadius() ) ) { addToList = true; } else if ( Collision::CircleTriangleEdgeIntersection(A,C,P, pRootNode->GetRadius() )) { addToList = true; } if (addToList) { pRootNode->SetInFrustum(true); pRootNode->Update(); mToApply[mToApplyCount] = pRootNode; mToApplyCount++; } else { pRootNode->SetInFrustum(false); } } /* pRootNode->SetInFrustum(true); pRootNode->Update(); mToApply[mToApplyCount] = pRootNode; mToApplyCount++; */ } else { pRootNode->SetInFrustum(false); } } else { pRootNode->SetInFrustum(true); pRootNode->Update(); mToApply[mToApplyCount] = pRootNode; mToApplyCount++; } /* PVRTVec3 worldPos = pRootNode->GetWorldTranslation(); PVRTVec3 distVec = worldPos - center; if (!pRootNode->GetUseOcclusionCulling()) { pRootNode->SetInFrustum(true); } else if ( distVec.lenSqr() < occlusionRadius ) { pRootNode->SetInFrustum(true); } else { pRootNode->SetInFrustum(false); } */ } }