void testCopy() { DataKeyDimension dim(*m_dim1); CPPUNIT_ASSERT(dim==*m_dim1); }
double & band_matrix::saved_diag(int i) { assert( (i>=0) && (i<dim()) ); return m_lower[0][i]; }
const SpdMatrix & IMMGS::Sigma() const { sigma_scratch_.resize(dim()); sigma_scratch_.diag() = unscaled_variance_diagonal(); sigma_scratch_.diag() *= sigsq(); return sigma_scratch_; }
int main(int argc, char** argv){// 1000G.marker.gz -> rs pos A1 A2 op = (char*)calloc(100, sizeof(char)); if(argc==1){fprintf(stderr,"tabix tbxfile CHR | ./ase 1000G.marker.gz [-printFrag] [-overlap] > output\n"); return -1;} int i; char* buf; buf = (char*)calloc(1000,sizeof(char)); long printFrag=0; long overlap=0; //long ascount; for(i=0; i<argc; i++){if(strcmp(argv[i],"-printFrag")==0){printFrag=1;}} for(i=0; i<argc; i++){if(strcmp(argv[i],"-overlap")==0){overlap=1;}} //for(i=0; i<argc; i++){if(strcmp(argv[i],"-ascount")==0){ascount=1;}} long N=0; gzFile fmarker; if((fmarker = gzopen(argv[1], "rb6f"))==NULL){fprintf(stderr, "gzread failed. no file!\n"); return -1;} long P=0; //N = getLine(fmarker); dim(fmarker, &buf, 1000*sizeof(char), &N, &P, 0); fprintf(stderr,"N of markers: %ld %ld\n", N, P); char** rs; long* pos; char* cpos; char* A1; char* A2; long* Y; double* ds; rs = (char**)calloc(N,sizeof(char*)); for(i=0;i<N;i++){ rs[i]=(char*)calloc(100,sizeof(char)); } cpos = (char*)calloc(100,sizeof(char)); pos = (long*)calloc(N,sizeof(long)); ds = (double*)calloc(N,sizeof(double)); A1 = (char*)calloc(N,sizeof(char)); A2 = (char*)calloc(N,sizeof(char)); Y = (long*)calloc(N*3,sizeof(long)); for(i=0; i<N; i++){ds[i]=0.0;} for(i=0; i<N*3; i++){Y[i]=0;} int ret; //char* buf; int l=0,cl=0,ncol=0; //buf = (char*)calloc(1000,sizeof(char)); while((ret = gzread(fmarker, buf, sizeof(buf))) != 0 && ret!=-1){ for(i=0;i<ret/sizeof(char);i++){ if(buf[i]=='\n'){ l++; ncol=cl=0; }else if(buf[i]==' ' || buf[i]=='\t' || buf[i]=='\n'){ if(ncol==2){rs[l][cl]='\0';}else if(ncol==1){cpos[cl]='\0'; pos[l]=atoi(cpos);} if(buf[i]=='\n'){l++; ncol=cl=0;}else{cl=0; ncol++;} }else{ if(ncol==2){ rs[l][cl++]=buf[i]; }else if(ncol==1){ cpos[cl++]=buf[i]; }else if(ncol==3){ if(cl==0){A1[l]=buf[i];}else{A1[l]='0';} cl++; }else if(ncol==4){ if(cl==0){ A2[l]=buf[i]; if(A2[l]=='-'){A2[l]='1';A1[l]='0';} }else{// allele length > 1 A2[l]='1';A1[l]='0'; } cl++; } } } } fprintf(stderr, "marker position: [%ld..%ld]\n",pos[0],pos[N-1]); //fprintf(stderr, "marker position: [%c %c %c %c..%c %c %c %c]\n",A1[0],A1[1],A1[2],A1[3],A1[N-4],A1[N-3],A1[N-2],A1[N-1]); //fprintf(stderr, "marker position: [%c %c %c %c..%c %c %c %c]\n",A2[0],A2[1],A2[2],A2[3],A2[N-4],A2[N-3],A2[N-2],A2[N-1]); char* chr; char* c1; char* seq; char* num; chr = (char*)calloc(100, sizeof(char)); seq = (char*)calloc(1000, sizeof(char)); c1 = (char*)calloc(1000, sizeof(char)); num = (char*)calloc(100, sizeof(char)); if(num==NULL || c1==NULL || seq==NULL || chr==NULL){fprintf(stderr, "memory allocation error!\n"); return 0;} long left, right; long* at; at = (long*)calloc(100, sizeof(long)); long j,j0=0; long l0=0, l1=0; while(scanf("%s\t%ld\t%ld\t%s\t%s", chr, &left, &right, c1, seq)!=EOF){ l=0; int flag=0; //fprintf(stderr, "%s\t%ld\t%ld\t%s\t%s\n", chr, left, right, c1, seq); for(j=j0; j<N; j++){ if(pos[j]>right){break;} if(pos[j]>=left){l++;}else{j0=j+1;} } if(l>0){ // flag: number of snps existing in the fragment flag=parseCigarPoint(left, c1, seq, pos+j0, l, A1+j0, A2+j0, Y+3*j0, num); parseCigarPoint2(left, c1, seq, pos+j0, l, A1+j0, ds+j0, num, flag); } if(printFrag==1){// tabix out put if( (overlap==1&&flag>0) || (overlap==0&&flag==0) ){ printf("%s\t%ld\t%ld\t%s\t%s\n", chr, left, right, c1, seq); } } if(flag==0){// no snp l1++; } // //printf("%s\t%ld\t%ld\t%s\t%s\n", chr, left, right, c1, seq); //}else{// more than one snp | flag captures the number of snps // printf("%d\n", flag); //} l0++; } if(printFrag==0){ for(j=0; j<N; j++){ printf("%s\t%ld\t%c\t%c\t%ld\t%ld\t%ld\t%lf\n", rs[j], pos[j], A1[j], A2[j], Y[j*3], Y[j*3+1], Y[j*3+2], ds[j]); } } //FILE* fcount; //fcount=fopen("count.bin","wb"); //fwrite(Y,sizeof(long),N*3,fcount); //fclose(fcount); fprintf(stderr, "%ld out of %ld fragments overlapped with SNPs\n", l0-l1, l0); return 0; }
/** * For that test you would need to luanch camera * so it would punch a hole for you. */ int main(int, char**) { LOGE("%s start", LOG_TAG); overlay2::GenericPipe<ovutils::FB0> pipe; overlay2::RotatorBase* r = new overlay2::NullRotator(); LOGE("Using null rotator"); bool ret = pipe.open(r); OVASSERT(ret, "Failed to open pipe"); LOGE("start ..."); ovutils::Whf whf(1024, 600, HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED); /* since we are using camera apk for punching a hole for us * we need ZOERDER_1 here so it will be on top of camera */ ovutils::eMdpFlags flags = ovutils::OV_MDP_FLAGS_NONE; ovutils::PipeArgs args(flags, ovutils::OVERLAY_TRANSFORM_0, whf, ovutils::WAIT, ovutils::ZORDER_1, ovutils::IS_FG_OFF, ovutils::ROT_FLAG_DISABLED, ovutils::PMEM_SRC_SMI, ovutils::RECONFIG_OFF); ret = pipe.start(args); OVASSERT(ret, "Failed to start pipe"); // let's try openning /dev/zero and mmap it. LOGE("Open /dev/pmem_adsp"); overlay2::OvMem m; uint32_t bfsz = 1024*600*4; ret = m.open(ovutils::PMEM_SRC_ADSP, 1, // one buf bfsz); //size OVASSERT(ret, "Failed to open /dev/pmem_adsp pipe"); m.dump(); ::memset(m.addr(), 0, bfsz); pipe.setMemoryId(m.getFD()); ovutils::Dim dim(0, 0, 1024, 600); // x,y,w,h ret = pipe.setPosition(dim); OVASSERT(ret, "Failed to setPosition"); LOGE("Before play ..."); pipe.dump(); enum { NUM_PLAY = 10 }; for (uint32_t i=0; i < NUM_PLAY; ++i) { ret = pipe.queueBuffer(0); // offset 0 OVASSERT(ret, "Failed to queueBuffer"); sleep(1); } ret = r->close(); OVASSERT(ret, "Error in rotator close"); ret = pipe.close(); OVASSERT(ret, "Error in pipe close"); ret = m.close(); delete r; r=0; LOGE("%s end", LOG_TAG); return 0; }
int SD_HW_GetMaxBusWidth(int iSlotIndex) { int iIndex = SD_HW_Convert_SlotIndex_To_HwSlotInfoIndex(iSlotIndex); SD_ASSERT( iIndex < (int)dim(sSdHwSlotInfo) ); return sSdHwSlotInfo[iIndex].iMaxBusWidth; }
} pKbdEventRmpCurr->uiVk = pvkMap->uiVkGenerated; } } } return cRmpKbdEvents; } static DEVICE_LAYOUT dlMatrixEngUs = { sizeof(DEVICE_LAYOUT), MATRIX_PDD, rgscvkMatrixEngUSTables, dim(rgscvkMatrixEngUSTables), MatrixUsRemapVKey, }; extern "C" BOOL Matrix( PDEVICE_LAYOUT pDeviceLayout ) { SETFNAME(_T("Matrix")); BOOL fRet = FALSE; if (pDeviceLayout == NULL) {
// second diag (used in LU decomposition), saved in m_lower double CBandMatrix::saved_diag(int i) const { assert( (i>=0) && (i<dim()) ); return m_lower[0][i]; }
void Action_AtomicCorr::Print() { int idx, idx3, vec1size; Vec3 V1, V2; mprintf(" ATOMICCORR: Calculating correlations between %s vectors:\n", ModeString[acorr_mode_]); if (atom_vectors_.empty()) { mprinterr("Error: No vectors calculated.\n"); return; } DataSet_MatrixFlt* tmatrix = static_cast<DataSet_MatrixFlt*>( dset_ ); tmatrix->AllocateTriangle( atom_vectors_.size() ); // Calculate correlation coefficient of each atomic vector to each other ACvector::iterator av_end = atom_vectors_.end(); ACvector::iterator av_end1 = av_end - 1; ProgressBar progress( tmatrix->Size() ); int iprogress = 0; for (ACvector::const_iterator vec1 = atom_vectors_.begin(); vec1 != av_end1; ++vec1) { for (ACvector::const_iterator vec2 = vec1 + 1; vec2 != av_end; ++vec2) { double corr_coeff = 0.0; progress.Update( iprogress++ ); // If vectors are too close, skip. vec2 always > vec1 if ( (*vec2) - (*vec1) > min_ ) { // Make sure same # of frames in each and not empty if ( vec1->empty() || vec2->empty() ) { mprintf("Warning: A vector is empty: Vec%zu=%zu, Vec%zu=%zu\n", vec1 - atom_vectors_.begin(), vec1->size(), vec2 - atom_vectors_.begin(), vec2->size()); } else if ( vec1->size() != vec2->size() ) { mprintf("Warning: Vec %zu and Vec %zu do not have same # of frames.\n", vec1 - atom_vectors_.begin(), vec2 - atom_vectors_.begin()); } else { vec1size = (int)(vec1->size() / 3); #ifdef _OPENMP #pragma omp parallel private(idx, idx3, V1, V2) reduction(+: corr_coeff) { #pragma omp for #endif for (idx = 0; idx < vec1size; ++idx) { idx3 = idx * 3; V1 = vec1->VXYZ(idx3); V2 = vec2->VXYZ(idx3); V1.Normalize(); V2.Normalize(); corr_coeff += (V1 * V2); } #ifdef _OPENMP } // END pragma omp parallel #endif corr_coeff /= (double)vec1size; if (fabs(corr_coeff) <= cut_) corr_coeff = 0.0; } } tmatrix->AddElement( corr_coeff ); } // END inner loop } // END outer loop if (acorr_mode_ == ATOM) { Dimension dim(1.0, 1.0, "Atom"); dset_->SetDim(Dimension::X, dim); dset_->SetDim(Dimension::Y, dim); } else { Dimension dim(1.0, 1.0, "Residue"); dset_->SetDim(Dimension::X, dim); dset_->SetDim(Dimension::Y, dim); } std::string labels; for (ACvector::const_iterator atom = atom_vectors_.begin(); atom != atom_vectors_.end(); ++atom) labels += ( atom->Label() + "," ); if (outfile_ != 0) outfile_->ProcessArgs( "xlabels " + labels + " ylabels " + labels ); }
separation find_wheel_minor(matroid_permuted <MatroidType>& permuted_matroid, matrix_permuted <MatrixType>& permuted_matrix, matroid_element_set& extra_elements) { assert (permuted_matrix.size1() >= 3 && permuted_matroid.size2() >= 3); /// Permute 1's in first row to the left. matroid_reorder_columns(permuted_matroid, permuted_matrix, 0, 1, 0, permuted_matroid.size2(), std::greater <int>()); size_t count_first_row_ones = matrix_count_property_column_series(permuted_matrix, 0, 1, 0, permuted_matrix.size2(), is_non_zero()); /// Trivial 1-separation if (count_first_row_ones == 0) { return separation(std::make_pair(1, 0)); } matroid_reorder_rows(permuted_matroid, permuted_matrix, 1, permuted_matroid.size1(), 0, 1, std::greater <int>()); size_t count_first_column_ones = matrix_count_property_row_series(permuted_matrix, 0, permuted_matroid.size1(), 0, 1, is_non_zero()); /// 1- or 2-separation if (count_first_row_ones == 1) { if (count_first_column_ones == 0) { return separation(std::make_pair(1, 1)); } else { return separation(std::make_pair(1, 1), std::make_pair(1, 0)); } } else if (count_first_column_ones == 1) { return separation(std::make_pair(1, 1), std::make_pair(0, 1)); } assert ((permuted_matrix(0,0) == 1) && (permuted_matrix(1,0) == 1) && (permuted_matrix(0,1) == 1)); /// Ensure we have a 2x2 block of ones if (permuted_matrix(1, 1) != 1) { matroid_binary_pivot(permuted_matroid, permuted_matrix, 0, 0); extra_elements.insert(permuted_matroid.name1(0)); extra_elements.insert(permuted_matroid.name2(0)); } assert ((permuted_matrix(0,0) == 1) && (permuted_matrix(1,0) == 1) && (permuted_matrix(0,1) == 1) && (permuted_matrix(1,1) == 1)); /// Grow the block to a set-maximal one. matroid_reorder_columns(permuted_matroid, permuted_matrix, 0, 2, 2, permuted_matroid.size2(), std::greater <int>()); size_t block_width = 2 + matrix_count_property_column_series(permuted_matrix, 0, 2, 2, permuted_matrix.size2(), is_all_ones()); matroid_reorder_rows(permuted_matroid, permuted_matrix, 2, permuted_matroid.size1(), 0, block_width, std::greater <int>()); size_t block_height = 2 + matrix_count_property_row_series(permuted_matrix, 2, permuted_matrix.size1(), 0, block_width, is_all_ones()); /// Search for a path in BFS graph zero_block_matrix_modifier modifier(block_height, block_width); matrix_modified <matrix_permuted <MatrixType> , zero_block_matrix_modifier> modified_matrix(permuted_matrix, modifier); bipartite_graph_dimensions dim(permuted_matrix.size1(), permuted_matrix.size2()); std::vector <bipartite_graph_dimensions::index_type> start_nodes(block_height); for (size_t i = 0; i < block_height; i++) start_nodes[i] = dim.row_to_index(i); std::vector <bipartite_graph_dimensions::index_type> end_nodes(block_width); for (size_t i = 0; i < block_width; i++) end_nodes[i] = dim.column_to_index(i); std::vector <bipartite_graph_bfs_node> bfs_result; bool found_path = bipartite_graph_bfs(modified_matrix, dim, start_nodes, end_nodes, false, bfs_result); /// There must be a 2-separation. if (!found_path) { std::pair <size_t, size_t> split(0, 0); /// Swap unreachable rows to top std::vector <int> reachable(permuted_matrix.size1()); for (size_t i = 0; i < permuted_matrix.size1(); ++i) { const bipartite_graph_bfs_node& node = bfs_result[dim.row_to_index(i)]; int value = (node.is_reachable() ? (node.distance > 0 ? 2 : 1) : 0); reachable[permuted_matrix.perm1()(i)] = value; if (value == 0) split.first++; } vector_less <int, std::less <int> > less(reachable, std::less <int>()); sort(permuted_matrix.perm1(), less); permuted_matroid.perm1() = permuted_matrix.perm1(); /// Swap unreachable columns to left reachable.resize(permuted_matrix.size2()); for (size_t i = 0; i < permuted_matrix.size2(); ++i) { const bipartite_graph_bfs_node& node = bfs_result[dim.column_to_index(i)]; int value = (node.is_reachable() ? 2 : (node.distance == -2 ? 1 : 0)); reachable[permuted_matrix.perm2()(i)] = value; if (value < 2) split.second++; } sort(permuted_matrix.perm2(), less); permuted_matroid.perm2() = permuted_matrix.perm2(); return separation(split, std::make_pair(split.first, split.second - 1)); } /// Go back along the path to find the nearest endpoint. bipartite_graph_dimensions::index_type nearest_end = 0; for (std::vector <bipartite_graph_dimensions::index_type>::const_iterator iter = end_nodes.begin(); iter != end_nodes.end(); ++iter) { if (bfs_result[*iter].is_reachable()) nearest_end = *iter; } assert (bfs_result[nearest_end].is_reachable()); size_t w3_one_column = dim.index_to_column(nearest_end); size_t nearest_distance = bfs_result[nearest_end].distance + 1; assert (nearest_distance % 2 == 0); size_t last_index = nearest_end; size_t current_index = bfs_result[last_index].predecessor; /// Find indices for basic W3-parts. size_t w3_one_row = 0; size_t w3_path_column = 0; size_t w3_path_row = dim.index_to_row(current_index); size_t w3_zero_column = 0; while (permuted_matrix(w3_path_row, w3_zero_column) != 0) { w3_zero_column++; assert (w3_zero_column < block_width); } /// Apply path shortening technique. while (last_index != current_index) { std::pair <size_t, size_t> coords = dim.indexes_to_coordinates(current_index, last_index); if ((bfs_result[current_index].distance % 2 == 0) && (bfs_result[current_index].distance >= 2) && (bfs_result[current_index].distance + 2 < (int) nearest_distance)) { matroid_binary_pivot(permuted_matroid, permuted_matrix, coords.first, coords.second); extra_elements.insert(permuted_matroid.name1(coords.first)); extra_elements.insert(permuted_matroid.name2(coords.second)); } if (bfs_result[current_index].distance == 1) { assert (dim.is_column(current_index)); w3_path_column = dim.index_to_column(current_index); } else if (bfs_result[current_index].distance == 0) { assert (dim.is_row(current_index)); w3_one_row = dim.index_to_row(current_index); } last_index = current_index; current_index = bfs_result[current_index].predecessor; } /// Collect more W3-indices. size_t w3_zero_row = 0; while (permuted_matrix(w3_zero_row, w3_path_column) != 0) { w3_zero_row++; assert (w3_zero_row< block_height); } assert (permuted_matrix (w3_one_row, w3_one_column) == 1); assert (permuted_matrix (w3_one_row, w3_zero_column) == 1); assert (permuted_matrix (w3_one_row, w3_path_column) == 1); assert (permuted_matrix (w3_zero_row, w3_one_column) == 1); assert (permuted_matrix (w3_zero_row, w3_zero_column) == 1); assert (permuted_matrix (w3_zero_row, w3_path_column) == 0); assert (permuted_matrix (w3_path_row, w3_one_column) == 1); assert (permuted_matrix (w3_path_row, w3_zero_column) == 0); assert (permuted_matrix (w3_path_row, w3_path_column) == 1); /// Some normalization if (w3_zero_row > w3_one_row) { matroid_permute1(permuted_matroid, permuted_matrix, w3_one_row, w3_zero_row); std::swap(w3_one_row, w3_zero_row); } if (w3_one_row > w3_path_row) { matroid_permute1(permuted_matroid, permuted_matrix, w3_path_row, w3_one_row); std::swap(w3_path_row, w3_one_row); } if (w3_zero_column > w3_one_column) { matroid_permute2(permuted_matroid, permuted_matrix, w3_one_column, w3_zero_column); std::swap(w3_one_column, w3_zero_column); } if (w3_one_column > w3_path_column) { matroid_permute2(permuted_matroid, permuted_matrix, w3_path_column, w3_one_column); std::swap(w3_path_column, w3_one_column); } matroid_permute1(permuted_matroid, permuted_matrix, 0, w3_zero_row); matroid_permute1(permuted_matroid, permuted_matrix, 1, w3_one_row); matroid_permute1(permuted_matroid, permuted_matrix, 2, w3_path_row); matroid_permute2(permuted_matroid, permuted_matrix, 0, w3_zero_column); matroid_permute2(permuted_matroid, permuted_matrix, 1, w3_one_column); matroid_permute2(permuted_matroid, permuted_matrix, 2, w3_path_column); return separation(); }
/*-------------------------------------------------------------------------------- Function : InventoryScreen::refresh Description : draws the InventoryScreen to the game window Inputs : None Outputs : updated InventoryScreen Return : void --------------------------------------------------------------------------------*/ void InventoryScreen::refresh() { Point dim(screen.getWidth(), screen.getHeight()); // set the colorscheme of the selected line TCODConsole::setColorControl(TCOD_COLCTRL_1, TCODColor::white, TCODColor::blue); // create a vector of the different item symbols vector< pair<int, TCODColor> > tabChars; tabChars.push_back(pair<int, TCODColor>('\\', UI_FORE_COLOR)); tabChars.push_back(pair<int, TCODColor>('[', UI_FORE_COLOR)); tabChars.push_back(pair<int, TCODColor>('!', UI_FORE_COLOR)); tabChars.push_back(pair<int, TCODColor>('*', UI_FORE_COLOR)); // draw interface int x=0, y=2; //screen.printEx(dim.X()/2, 0, TCOD_BKGND_SET, TCOD_CENTER, // (client->personalStats.name() + string("'s Inventory")).c_str()); screen.printEx(dim.X()/2, 0, TCOD_BKGND_SET, TCOD_CENTER, "Inventory"); // 'start' is the point at which the folder contents are drawn Point start = drawFolders(x, y, dim, tabChars); // draw the information line x = start.X(); y = start.Y(); screen.print(x+1, y++, "Qt. Item"); screen.hline(x, y++, dim.X()-3); // update start position to where items will be drawn start.setY(y); linesPerPage = dim.Y()-y; currentPage = (selectedLine==0) ? 0 : selectedLine / (linesPerPage-1); int numItems = client->inventory.getIndexSize(selectedTab); if(numItems <= 0) return; drawScrollBar(Point(dim.X()-2, y), linesPerPage, currentPage, (numItems/linesPerPage)+1); // determine at what line should be highlighted int hlOffset = selectedLine % ((currentPage==0) ? linesPerPage : linesPerPage-1); // set an iterator to the lowest spot that will show the selected line vector<ItemPtr>::const_iterator it; it = client->inventory.getIndexBegin(selectedTab) + (currentPage*linesPerPage) - currentPage; for(; it!=client->inventory.getIndexEnd(selectedTab); ++it, ++y) { // ignore lines that are off the display area if(y >= start.Y()+linesPerPage-1) break; // construct the display string // three spaces are allocated to the item count number. The buffer string // ensures that this number is right aligned in this space. string buffer = ""; unsigned int c = (*it)->getCount(); while(c<100) { buffer += " "; c *= 10;} string disp = buffer + boost::lexical_cast<string>((*it)->getCount()) + " " + (*it)->getName(); // if this is the selected line on the current page, highlight it if(y == (hlOffset) + start.Y()) { disp = "%c" + disp + "%c"; screen.printEx(start.X(), y, TCOD_BKGND_SET, TCOD_LEFT, disp.c_str(), TCOD_COLCTRL_1, TCOD_COLCTRL_STOP); } else // display the line normally { screen.printEx(start.X(), y, TCOD_BKGND_SET, TCOD_LEFT, disp.c_str()); } } }
/// \brief Sets the matrix to the \p nrows x \p ncols zero matrix. void matrix::zero(int nrows, int ncols) { dim(nrows, ncols); for(int i=0;i<nf*nc;i++) p[i]=0; }
int main(int, char**) { LOGE("OverlayCtrlTest start"); overlay2::Ctrl ctrl; overlay2::RotatorBase* rot = new overlay2::NullRotator(); // open rot here bool ret = rot->open(); OVASSERT(ret, "Rotator failed to open"); ovutils::PipeArgs args(ovutils::OV_MDP_FLAGS_NONE,//flags PIPE SHARED ovutils::OVERLAY_TRANSFORM_0, ovutils::Whf(), ovutils::WAIT, ovutils::ZORDER_0, ovutils::IS_FG_OFF, ovutils::ROT_FLAG_ENABLED, ovutils::PMEM_SRC_ADSP, ovutils::RECONFIG_OFF); ret = rot->remap(ROT_NUM_BUF, args); OVASSERT(ret, "Rotator failed to remap"); ret = ctrl.open(ovutils::FB0, rot); OVASSERT(ret, "Ctrl failed to open"); ovutils::Whf whf(100, 200, HAL_PIXEL_FORMAT_RGBA_8888); ovutils::eMdpFlags flags = ovutils::OV_MDP_FLAGS_NONE; ret = ctrl.start(args); OVASSERT(ret, "Ctrl failed to start"); ctrl.dump(); LOGE("setPosition ..."); ovutils::Dim dim(0, 0, 50, 100); ret = ctrl.setPosition(dim); OVASSERT(ret, "Ctrl failed to setPosition"); ctrl.dump(); LOGE("setParameter ..."); ovutils::Params p ( ovutils::OVERLAY_DITHER, 0 ); ret = ctrl.setParameter(p); OVASSERT(ret, "Ctrl failed to setParameter"); ctrl.dump(); LOGE("setSource ..."); ovutils::PipeArgs args1(flags, ovutils::OVERLAY_TRANSFORM_0, ovutils::Whf(75, 150, HAL_PIXEL_FORMAT_RGBA_8888), ovutils::WAIT, ovutils::ZORDER_0, ovutils::IS_FG_OFF, ovutils::ROT_FLAG_DISABLED, ovutils::PMEM_SRC_SMI, ovutils::RECONFIG_OFF); ret = ctrl.setSource(args1); OVASSERT(ret, "Ctrl failed to setSource"); ctrl.commit(); ctrl.dump(); ctrl.close(); rot->close(); delete rot; LOGE("OverlayCtrlTest end"); return 0; }
void SPxSolver::qualRedCostViolation(Real& maxviol, Real& sumviol) const { maxviol = 0.0; sumviol = 0.0; int i; // TODO: y = c_B * B^-1 => coSolve(y, c_B) // redcost = c_N - yA_N // solve system "x = e_i^T * B^-1" to get i'th row of B^-1 // DVector y( nRows() ); // basis().coSolve( x, spx->unitVector( i ) ); // DVector rdcost( nCols() ); #if 0 // un-const if (lastUpdate() > 0) factorize(); computePvec(); if (type() == ENTER) computeTest(); #endif if (type() == ENTER) { for(i = 0; i < dim(); ++i) { Real x = coTest()[i]; if (x < 0.0) { sumviol -= x; if (x < maxviol) maxviol = x; } } for(i = 0; i < coDim(); ++i) { Real x = test()[i]; if (x < 0.0) { sumviol -= x; if (x < maxviol) maxviol = x; } } } else { assert(type() == LEAVE); for(i = 0; i < dim(); ++i) { Real x = fTest()[i]; if (x < 0.0) { sumviol -= x; if (x < maxviol) maxviol = x; } } } maxviol *= -1; }
void RandomPCA::pca(MatrixXd &X, int method, bool transpose, unsigned int ndim, unsigned int nextra, unsigned int maxiter, double tol, long seed, int kernel, double sigma, bool rbf_center, unsigned int rbf_sample, bool save_kernel, bool do_orth, bool do_loadings) { unsigned int N; if(kernel != KERNEL_LINEAR) { transpose = false; verbose && std::cout << timestamp() << " Kernel not linear, can't transpose" << std::endl; } verbose && std::cout << timestamp() << " Transpose: " << (transpose ? "yes" : "no") << std::endl; if(transpose) { if(stand_method != STANDARDIZE_NONE) X_meansd = standardize_transpose(X, stand_method, verbose); N = X.cols(); } else { if(stand_method != STANDARDIZE_NONE) X_meansd = standardize(X, stand_method, verbose); N = X.rows(); } unsigned int total_dim = ndim + nextra; MatrixXd R = make_gaussian(X.cols(), total_dim, seed); MatrixXd Y = X * R; verbose && std::cout << timestamp() << " dim(Y): " << dim(Y) << std::endl; normalize(Y); MatrixXd Yn; verbose && std::cout << timestamp() << " dim(X): " << dim(X) << std::endl; MatrixXd K; if(kernel == KERNEL_RBF) { if(sigma == 0) { unsigned int med_samples = fminl(rbf_sample, N); double med = median_dist(X, med_samples, seed, verbose); sigma = sqrt(med); } verbose && std::cout << timestamp() << " Using RBF kernel with sigma=" << sigma << std::endl; K.noalias() = rbf_kernel(X, sigma, rbf_center, verbose); } else { verbose && std::cout << timestamp() << " Using linear kernel" << std::endl; K.noalias() = X * X.transpose() / (N - 1); } //trace = K.diagonal().array().sum() / (N - 1); trace = K.diagonal().array().sum(); verbose && std::cout << timestamp() << " Trace(K): " << trace << " (N: " << N << ")" << std::endl; verbose && std::cout << timestamp() << " dim(K): " << dim(K) << std::endl; if(save_kernel) { verbose && std::cout << timestamp() << " saving K" << std::endl; save_text("kernel.txt", K); } for(unsigned int iter = 0 ; iter < maxiter ; iter++) { verbose && std::cout << timestamp() << " iter " << iter; Yn.noalias() = K * Y; if(do_orth) { verbose && std::cout << " (orthogonalising)"; ColPivHouseholderQR<MatrixXd> qr(Yn); MatrixXd I = MatrixXd::Identity(Yn.rows(), Yn.cols()); Yn = qr.householderQ() * I; Yn.conservativeResize(NoChange, Yn.cols()); } else normalize(Yn); double diff = (Y - Yn).array().square().sum() / Y.size(); verbose && std::cout << " " << diff << std::endl; Y.noalias() = Yn; if(diff < tol) break; } verbose && std::cout << timestamp() << " QR begin" << std::endl; ColPivHouseholderQR<MatrixXd> qr(Y); MatrixXd Q = MatrixXd::Identity(Y.rows(), Y.cols()); Q = qr.householderQ() * Q; Q.conservativeResize(NoChange, Y.cols()); verbose && std::cout << timestamp() << " dim(Q): " << dim(Q) << std::endl; verbose && std::cout << timestamp() << " QR done" << std::endl; MatrixXd B = Q.transpose() * X; verbose && std::cout << timestamp() << " dim(B): " << dim(B) << std::endl; MatrixXd Et; pca_small(B, method, Et, d, verbose); verbose && std::cout << timestamp() << " dim(Et): " << dim(Et) << std::endl; d = d.array() / (N - 1); if(transpose) { V.noalias() = Q * Et; // We divide P by sqrt(N - 1) since X has not been divided // by it (but B has) P.noalias() = X.transpose() * V; VectorXd s = 1 / (d.array().sqrt() * sqrt(N - 1)); MatrixXd Dinv = s.asDiagonal(); U = P * Dinv; } else { // P = U D = X V U.noalias() = Q * Et; P.noalias() = U * d.asDiagonal(); if(do_loadings) { VectorXd s = 1 / (d.array().sqrt() * sqrt(N - 1)); MatrixXd Dinv = s.asDiagonal(); V = X.transpose() * U * Dinv; } } P.conservativeResize(NoChange, ndim); U.conservativeResize(NoChange, ndim); V.conservativeResize(NoChange, ndim); d.conservativeResize(ndim); pve = d.array() / trace; }
//! constructor CGUIMessageBox::CGUIMessageBox(IGUIEnvironment* environment, const wchar_t* caption, const wchar_t* text, s32 flags, IGUIElement* parent, s32 id, core::rect<s32> rectangle) : CGUIWindow(environment, parent, id, rectangle), StaticText(0), OkButton(0), YesButton(0), NoButton(0), CancelButton(0) { #ifdef _DEBUG setDebugName("CGUIMessageBox"); #endif // remove focus Environment->setFocus(0); // remove buttons getMaximizeButton()->remove(); getMinimizeButton()->remove(); if (caption) setText(caption); IGUISkin* skin = Environment->getSkin(); s32 buttonHeight = skin->getSize(EGDS_BUTTON_HEIGHT); s32 buttonWidth = skin->getSize(EGDS_BUTTON_WIDTH); s32 titleHeight = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH)+2; s32 buttonDistance = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH); // add static multiline text core::dimension2d<s32> dim(AbsoluteClippingRect.getWidth() - buttonWidth, AbsoluteClippingRect.getHeight() - (buttonHeight * 3)); core::position2d<s32> pos((AbsoluteClippingRect.getWidth() - dim.Width) / 2, buttonHeight / 2 + titleHeight); StaticText = Environment->addStaticText(text, core::rect<s32>(pos, dim), false, false, this); StaticText->setWordWrap(true); StaticText->grab(); // adjust static text height s32 textHeight = StaticText->getTextHeight(); core::rect<s32> tmp = StaticText->getRelativePosition(); tmp.LowerRightCorner.Y = tmp.UpperLeftCorner.Y + textHeight; StaticText->setRelativePosition(tmp); dim.Height = textHeight; // adjust message box height tmp = getRelativePosition(); s32 msgBoxHeight = textHeight + (s32)(2.5f * buttonHeight) + titleHeight; // adjust message box position tmp.UpperLeftCorner.Y = (parent->getAbsolutePosition().getHeight() - msgBoxHeight) / 2; tmp.LowerRightCorner.Y = tmp.UpperLeftCorner.Y + msgBoxHeight; setRelativePosition(tmp); // add buttons s32 countButtons = 0; if (flags & EMBF_OK) ++countButtons; if (flags & EMBF_CANCEL) ++countButtons; if (flags & EMBF_YES) ++countButtons; if (flags & EMBF_NO) ++countButtons; core::rect<s32> btnRect; btnRect.UpperLeftCorner.Y = pos.Y + dim.Height + buttonHeight / 2; btnRect.LowerRightCorner.Y = btnRect.UpperLeftCorner.Y + buttonHeight; btnRect.UpperLeftCorner.X = (AbsoluteClippingRect.getWidth() - ((buttonWidth + buttonDistance)*countButtons)) / 2; btnRect.LowerRightCorner.X = btnRect.UpperLeftCorner.X + buttonWidth; // add ok button if (flags & EMBF_OK) { OkButton = Environment->addButton(btnRect, this); OkButton->setText(skin->getDefaultText(EGDT_MSG_BOX_OK)); OkButton->grab(); btnRect.LowerRightCorner.X += buttonWidth + buttonDistance; btnRect.UpperLeftCorner.X += buttonWidth + buttonDistance; Environment->setFocus(OkButton); } // add yes button if (flags & EMBF_YES) { YesButton = Environment->addButton(btnRect, this); YesButton->setText(skin->getDefaultText(EGDT_MSG_BOX_YES)); YesButton->grab(); btnRect.LowerRightCorner.X += buttonWidth + buttonDistance; btnRect.UpperLeftCorner.X += buttonWidth + buttonDistance; } // add no button if (flags & EMBF_NO) { NoButton = Environment->addButton(btnRect, this); NoButton->setText(skin->getDefaultText(EGDT_MSG_BOX_NO)); NoButton->grab(); btnRect.LowerRightCorner.X += buttonWidth + buttonDistance; btnRect.UpperLeftCorner.X += buttonWidth + buttonDistance; } // add cancel button if (flags & EMBF_CANCEL) { CancelButton = Environment->addButton(btnRect, this); CancelButton->setText(skin->getDefaultText(EGDT_MSG_BOX_CANCEL)); CancelButton->grab(); btnRect.LowerRightCorner.X += buttonWidth + buttonDistance; btnRect.UpperLeftCorner.X += buttonWidth + buttonDistance; } }
// ---------------------------------------------------------------------- int Dense3d::setup(map<string,string>&) { iA(_srcPos!=NULL && _srcNor!=NULL && _trgPos!=NULL); iA((*_srcPos).m()==dim() && (*_trgPos).m()==dim()); //nothing to do return 0; }
bool Foam::chemPointISAT<CompType, ThermoType>::inEOA(const scalarField& phiq) { scalarField dphi(phiq-phi()); bool isMechRedActive = chemistry_.mechRed()->active(); label dim(0); if (isMechRedActive) { dim = nActiveSpecies_; } else { dim = completeSpaceSize() - nAdditionalEqns_; } scalar epsTemp = 0; List<scalar> propEps(completeSpaceSize(), scalar(0)); for (label i=0; i<completeSpaceSize()-nAdditionalEqns_; i++) { scalar temp = 0; // When mechanism reduction is inactive OR on active species multiply L // by dphi to get the distance in the active species direction else (for // inactive species), just multiply the diagonal element and dphi if ( !(isMechRedActive) ||(isMechRedActive && completeToSimplifiedIndex_[i] != -1) ) { label si=(isMechRedActive) ? completeToSimplifiedIndex_[i] : i; for (label j=si; j<dim; j++)// LT is upper triangular { label sj=(isMechRedActive) ? simplifiedToCompleteIndex_[j] : j; temp += LT_(si, j)*dphi[sj]; } temp += LT_(si, dim)*dphi[idT_]; temp += LT_(si, dim+1)*dphi[idp_]; if (variableTimeStep()) { temp += LT_(si, dim+2)*dphi[iddeltaT_]; } } else { temp = dphi[i]/(tolerance_*scaleFactor_[i]); } epsTemp += sqr(temp); if (printProportion_) { propEps[i] = temp; } } // Temperature if (variableTimeStep()) { epsTemp += sqr ( LT_(dim, dim)*dphi[idT_] +LT_(dim, dim+1)*dphi[idp_] +LT_(dim, dim+2)*dphi[iddeltaT_] ); } else { epsTemp += sqr ( LT_(dim, dim)*dphi[idT_] +LT_(dim, dim+1)*dphi[idp_] ); } // Pressure if (variableTimeStep()) { epsTemp += sqr ( LT_(dim+1, dim+1)*dphi[idp_] +LT_(dim+1, dim+2)*dphi[iddeltaT_] ); } else { epsTemp += sqr(LT_(dim+1, dim+1)*dphi[idp_]); } if (variableTimeStep()) { epsTemp += sqr(LT_[dim+2][dim+2]*dphi[iddeltaT_]); } if (printProportion_) { propEps[idT_] = sqr ( LT_(dim, dim)*dphi[idT_] + LT_(dim, dim+1)*dphi[idp_] ); propEps[idp_] = sqr(LT_(dim+1, dim+1)*dphi[idp_]); if (variableTimeStep()) { propEps[iddeltaT_] = sqr(LT_[dim+2][dim+2]*dphi[iddeltaT_]); } } if (sqrt(epsTemp) > 1 + tolerance_) { if (printProportion_) { scalar max = -1; label maxIndex = -1; for (label i=0; i<completeSpaceSize(); i++) { if(max < propEps[i]) { max = propEps[i]; maxIndex = i; } } word propName; if (maxIndex >= completeSpaceSize() - nAdditionalEqns_) { if (maxIndex == idT_) { propName = "T"; } else if (maxIndex == idp_) { propName = "p"; } else if (maxIndex == iddeltaT_) { propName = "deltaT"; } } else { propName = chemistry_.Y()[maxIndex].member(); } Info<< "Direction maximum impact to error in ellipsoid: " << propName << endl; Info<< "Proportion to the total error on the retrieve: " << max/(epsTemp+small) << endl; } return false; } else { return true; } }
HashGrid3<Vector3> Docking::createHashGrid(){ float min_x = 1000; float min_y = 1000; float min_z = 1000; float max_x = -1000; float max_y = -1000; float max_z = -1000; //iterate over all atoms of protein A to calc dimesion (s. calcSASSurface) for (vector<Vector3>::iterator a_it = positionsA.begin(); a_it != positionsA.end(); a_it++){ Vector3 vec = *a_it; if (vec.x > max_x){ max_x = vec.x; } if (vec.x < min_x){ min_x = vec.x; } if (vec.y > max_y){ max_y = vec.y; } if (vec.y < min_y){ min_y = vec.y; } if (vec.z > max_z){ max_z = vec.z; } if (vec.z < min_z){ min_z = vec.z; } } float x = max_x - min_x; float y = max_y - min_y; float z = max_z - min_z; x = ceil(x); y = ceil(y); z = ceil(z); Vector3 dim(x, y, z); Vector3 origin(min_x, min_y, min_z); HashGrid3<Vector3> pointGrid(origin,dim, 4.0); Vector3 vec2; for (vector<Vector3>::iterator A_it= positionsA.begin(); A_it != positionsA.end(); ++A_it){ vec2 = *A_it; pointGrid.insert(vec2,vec2); } return pointGrid; }
void CameraTestTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { m_dragged = true; CleanupParameters *cp = CleanupSettingsModel::instance()->getCurrentParameters(); TPointD dp(pos - m_lastPos); if (m_scaling != eNoScale) { TDimensionD dim(cp->m_camera.getSize()); TPointD delta; // Mid-edge cases if (m_scaling == e1M) delta = TPointD(dp.x / Stage::inch, 0); else if (m_scaling == e0M) delta = TPointD(-dp.x / Stage::inch, 0); else if (m_scaling == eM1) delta = TPointD(0, dp.y / Stage::inch); else if (m_scaling == eM0) delta = TPointD(0, -dp.y / Stage::inch); else { // Corner cases if (e.isShiftPressed()) { // Free adjust if (m_scaling == e11) delta = TPointD(dp.x / Stage::inch, dp.y / Stage::inch); else if (m_scaling == e00) delta = TPointD(-dp.x / Stage::inch, -dp.y / Stage::inch); else if (m_scaling == e10) delta = TPointD(dp.x / Stage::inch, -dp.y / Stage::inch); else if (m_scaling == e01) delta = TPointD(-dp.x / Stage::inch, dp.y / Stage::inch); } else { // A/R conservative bool xMaximalDp = (fabs(dp.x) > fabs(dp.y)); if (m_scaling == e11) delta.x = (xMaximalDp ? dp.x : dp.y) / Stage::inch; else if (m_scaling == e00) delta.x = (xMaximalDp ? -dp.x : -dp.y) / Stage::inch; else if (m_scaling == e10) delta.x = (xMaximalDp ? dp.x : -dp.y) / Stage::inch; else if (m_scaling == e01) delta.x = (xMaximalDp ? -dp.x : dp.y) / Stage::inch; // Keep A/R delta.y = delta.x * dim.ly / dim.lx; } } TDimensionD newDim(dim.lx + 2.0 * delta.x, dim.ly + 2.0 * delta.y); if (newDim.lx < 2.0 || newDim.ly < 2.0) return; cp->m_camera.setSize(newDim, true, // Preserve DPI false); // A/R imposed above in corner cases } else { if (e.isShiftPressed()) { TPointD delta = pos - m_firstPos; cp->m_offx = m_firstCameraOffset.x; cp->m_offy = m_firstCameraOffset.y; if (fabs(delta.x) > fabs(delta.y)) { if (!cp->m_offx_lock) cp->m_offx += -delta.x * (2.0 / Stage::inch); } else { if (!cp->m_offy_lock) cp->m_offy += -delta.y * (2.0 / Stage::inch); } } else { if (!cp->m_offx_lock) cp->m_offx += -dp.x * (2.0 / Stage::inch); if (!cp->m_offy_lock) cp->m_offy += -dp.y * (2.0 / Stage::inch); } } m_lastPos = pos; CleanupSettingsModel::instance()->commitChanges(); invalidate(); }
// Remapping function for the matrix keyboard static UINT WINAPI MatrixUsRemapVKey( const KEYBD_EVENT *pKbdEvents, UINT cKbdEvents, KEYBD_EVENT *pRmpKbdEvents, UINT cMaxRmpKbdEvents ) { SETFNAME(_T("MatrixUsRemapVKey")); static BOOL fFnDown = FALSE; UINT cRmpKbdEvents = 0; UINT ui; if (pRmpKbdEvents == NULL) { // 1 to 1 mapping if (cMaxRmpKbdEvents != 0) { DEBUGMSG(ZONE_ERROR, (_T("%s: cMaxRmpKbdEvents error!\r\n"), pszFname)); } return cKbdEvents; } if (pKbdEvents == NULL) { DEBUGMSG(ZONE_ERROR, (_T("%s: pKbdEvents error!\r\n"), pszFname)); } if (cMaxRmpKbdEvents < cKbdEvents) { DEBUGMSG(ZONE_ERROR, (_T("%s: Buffer is not large enough!\r\n"), pszFname)); return 0; } for (ui = 0; ui < cKbdEvents; ++ui) { const KEYBD_EVENT *pKbdEventCurr = &pKbdEvents[ui]; KEYBD_EVENT *pKbdEventRmpCurr = &pRmpKbdEvents[cRmpKbdEvents]; // Copy the input key event to our remapped list pKbdEventRmpCurr->uiVk = pKbdEventCurr->uiVk; pKbdEventRmpCurr->uiSc = pKbdEventCurr->uiSc; pKbdEventRmpCurr->KeyStateFlags = pKbdEventCurr->KeyStateFlags; const VirtualKeyMapping *pvkMap = NULL; BOOL fKeyDown = (pKbdEventCurr->KeyStateFlags & KeyStateDownFlag) != 0; UINT32 uiVkCurr = pKbdEventCurr->uiVk; if (uiVkCurr == VK_MATRIX_FN) { fFnDown = fKeyDown; // Fn virtual key does not get sent to the system so // do not increment cRmpKbdEvents. DEBUGMSG(ZONE_DEVICELAYOUT, (_T("%s: Fn key is now %s\r\n"), pszFname, (fFnDown ? _T("DOWN") : _T("UP")))); } else { // We have one key event ++cRmpKbdEvents; if (fKeyDown) { // Handle key down if (fFnDown) { // Fn key is on if (IS_NUMLOCK_ON(pKbdEventCurr->KeyStateFlags)) { pvkMap = FindRemappedKey(uiVkCurr, g_rgvkMapNumLock, dim(g_rgvkMapNumLock)); } if (pvkMap == NULL) { // NumLock did not effect this key. See if the // Fn key by itself does. pvkMap = FindRemappedKey(uiVkCurr, g_rgvkMapFn, dim(g_rgvkMapFn)); } } } else { // Handle key up if (fFnDown) { // Fn key is on if (IS_NUMLOCK_ON(pKbdEventCurr->KeyStateFlags)) { pvkMap = FindRemappedKey(uiVkCurr, g_rgvkMapNumLock, dim(g_rgvkMapNumLock)); } if (pvkMap == NULL) { // NumLock did not effect this key. See if the // Fn key by itself does. pvkMap = FindRemappedKey(uiVkCurr, g_rgvkMapFn, dim(g_rgvkMapFn)); } } } if (pvkMap != NULL) { // This combination generates a different virtual key if (pvkMap->uiVkGenerated == NULL) { DEBUGMSG(ZONE_ERROR, (_T("%s: pvkMap->uiVkGenerated error!\r\n"), pszFname)); } pKbdEventRmpCurr->uiVk = pvkMap->uiVkGenerated; } } } return cRmpKbdEvents; }
void set_children( unsigned int left ) { index = dim() | (left << 2); }
void RandomObstacles::spawn(OType type , SType subtype){ OdeHandle handle2 = odeHandle; OsgHandle osgHandle2; double density=((double)rand()/RAND_MAX)*(conf.maxDensity - conf.minDensity) + conf.minDensity; if(subtype == SRandom){ subtype = (SType)(rand()%4); } switch (subtype){ case Metal: handle2.substance.toMetal(1); osgHandle2 = osgHandle.changeColor(Color(0.5,0.5,0.5)); density = conf.maxDensity; break; case Plastic: handle2.substance.toPlastic(1); osgHandle2 = osgHandle.changeColor(Color(1,1,1)); break; case Rubber: handle2.substance.toRubber(10); osgHandle2 = osgHandle.changeColor(Color(0.2,0.2,0.2)); break; case Foam: default: handle2.substance.toFoam(15); osgHandle2 = osgHandle.changeColor(Color(1,1,0)); density = conf.minDensity; break; } Pos dim((double)rand() / RAND_MAX, (double)rand() / RAND_MAX, (double)rand() / RAND_MAX); dim = (dim & (conf.maxSize - conf.minSize)) + conf.minSize; if(type == ORandom) { int l = conf.boxRelFreq + conf.sphereRelFreq + conf.capRelFreq; int r = rand()%l; if(r<conf.boxRelFreq) type = RandomObstacles::Box; else if (r<conf.boxRelFreq + conf.sphereRelFreq) type = RandomObstacles::Sphere; else type = RandomObstacles::Caps; } Primitive* o; switch (type){ case RandomObstacles::Box: o = new lpzrobots::Box(dim.x(), dim.y(), dim.z()); o->init(handle2, dim.x()* dim.y()* dim.z() * density, osgHandle2); break; case RandomObstacles::Sphere: o = new lpzrobots::Sphere(dim.x()/2.0); o->init(handle2, 2.0/3.0*M_PI*pow(dim.x(),3)*density , osgHandle2); break; case RandomObstacles::Caps: default: o = new lpzrobots::Capsule(dim.x()/2.0, dim.z()/2.0); o->init(handle2, M_PI*sqr(dim.x())*dim.z()/8*density, osgHandle2); break; } Pos pos(random_minusone_to_one(0), random_minusone_to_one(0), 1); pos = (pos) & conf.area; pos.z() += (index%3) * conf.area.z()/2; index++; o->setPosition(pos * pose); obst.push_back(o); };
LIBSBML_CPP_NAMESPACE_USE int main(int argc, char** argv) { // // Creates an SBMLNamespaces object with the given SBML level, version // package name. // SBMLNamespaces sbmlns(2, 3); sbmlns.addNamespace(LayoutExtension::getXmlnsL2(), "layout"); // (NOTES) The above code creating an SBMLNamespaces object can be replaced // with the following other style. // // (2) Creates a LayoutPkgNamespaces object (SBMLNamespace derived class // for layout package. The class is basically used for createing an // SBase derived objects belonging to the layout package) with the // given SBML level, version. (Package version is not required by // Layout extension of SBML Level 2) // // LayoutPkgNamespaces sbmlns(2, 3); // // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); // create the Model Model* model = document->createModel(); model->setId("TestModel_with_modifiers"); document->setModel(model); // create the Layout LayoutPkgNamespaces layoutns(2, 3); LayoutModelPlugin* mplugin = static_cast<LayoutModelPlugin*>(model->getPlugin("layout")); Layout* layout = mplugin->createLayout(); layout->setId("Layout_1"); Dimensions dim(&layoutns, 400.0, 230.0); layout->setDimensions(&dim); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("Yeast"); // create the CompartmentGlyph CompartmentGlyph* compartmentGlyph = layout->createCompartmentGlyph(); compartmentGlyph->setId("CompartmentGlyph_1"); compartmentGlyph->setCompartmentId(compartment->getId()); BoundingBox bb(&layoutns, "bb1", 5, 5, 390, 220); compartmentGlyph->setBoundingBox(&bb); // create the Species, SpeciesGlyphs and associated TextGlyphs // Glucose Species* species_Gluc = model->createSpecies(); species_Gluc->setId("Glucose"); species_Gluc->setCompartment(compartment->getId()); SpeciesGlyph* glyph_Gluc = layout->createSpeciesGlyph(); glyph_Gluc->setId("SpeciesGlyph_Glucose"); glyph_Gluc->setSpeciesId(species_Gluc->getId()); bb = BoundingBox(&layoutns, "bb2", 105, 20, 130, 20); glyph_Gluc->setBoundingBox(&bb); TextGlyph* tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_Glucose"); bb = BoundingBox(&layoutns, "bbA", 115, 20, 110, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_Gluc->getId()); tGlyph->setGraphicalObjectId(glyph_Gluc->getId()); // Glucose-6-phosphate Species* species_G6P = model->createSpecies(); species_G6P->setId("Glucose_hyphen_6_hyphen_phosphate"); species_G6P->setCompartment(compartment->getId()); SpeciesGlyph* glyph_G6P = layout->createSpeciesGlyph(); glyph_G6P->setId("SpeciesGlyph_G6P"); glyph_G6P->setSpeciesId(species_G6P->getId()); bb = BoundingBox(&layoutns, "bb5", 50, 190, 270, 20); glyph_G6P->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_G6P"); bb = BoundingBox(&layoutns, "bbD", 60, 190, 250, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_G6P->getId()); tGlyph->setGraphicalObjectId(glyph_G6P->getId()); // ATP Species* species_ATP = model->createSpecies(); species_ATP->setId("ATP"); species_ATP->setCompartment(compartment->getId()); SpeciesGlyph* glyph_ATP = layout->createSpeciesGlyph(); glyph_ATP->setId("SpeciesGlyph_ATP"); glyph_ATP->setSpeciesId(species_ATP->getId()); bb = BoundingBox(&layoutns, "bb3", 270, 70, 80, 20); glyph_ATP->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_ATP"); bb = BoundingBox(&layoutns, "bbB", 280, 70, 60, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_ATP->getId()); tGlyph->setGraphicalObjectId(glyph_ATP->getId()); // ADP Species* species_ADP = model->createSpecies(); species_ADP->setId("ADP"); species_ADP->setCompartment(compartment->getId()); SpeciesGlyph* glyph_ADP = layout->createSpeciesGlyph(); glyph_ADP->setId("glyph_ADP"); glyph_ADP->setSpeciesId(species_ADP->getId()); bb = BoundingBox(&layoutns, "bb4", 270, 140, 80, 20); glyph_ADP->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_ADP"); bb = BoundingBox(&layoutns, "bbC", 280, 140, 60, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_ADP->getId()); tGlyph->setGraphicalObjectId(glyph_ADP->getId()); // Phosphate Species* species_Pi = model->createSpecies(); species_Pi->setId("Pi"); species_Pi->setCompartment(compartment->getId()); SpeciesGlyph* glyph_Pi = layout->createSpeciesGlyph(); glyph_Pi->setId("SpeciesGlyph_Pi"); glyph_Pi->setSpeciesId(species_Pi->getId()); bb = BoundingBox(&layoutns, "bb6", 50, 100, 60, 20); glyph_Pi->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_PI"); bb = BoundingBox(&layoutns, "bbE", 60, 100, 40, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_Pi->getId()); tGlyph->setGraphicalObjectId(glyph_Pi->getId()); // create the Reaction Reaction* reaction_Hexokinase = model->createReaction(); reaction_Hexokinase->setId("Hexokinase"); reaction_Hexokinase->setReversible(false); ReactionGlyph* glyph_Hexokinase = layout->createReactionGlyph(); glyph_Hexokinase->setId("glyph_Hexokinase"); glyph_Hexokinase->setReactionId(reaction_Hexokinase->getId()); Curve* curve_Hexokinase = glyph_Hexokinase->getCurve(); LineSegment* ls = curve_Hexokinase->createLineSegment(); Point p(&layoutns, 170, 100); ls->setStart(&p); p = Point(&layoutns, 170, 130); ls->setEnd(&p); // create the species reference for glucose SpeciesReference* reference_Gluc = reaction_Hexokinase->createReactant(); reference_Gluc->setSpecies(species_Gluc->getId()); reference_Gluc->setId("SpeciesReference_Glucose"); // create species reference glyph for glucose SpeciesReferenceGlyph* speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_Glucose"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_Gluc->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_Gluc->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_SUBSTRATE); ls = speciesReferenceGlyph->createLineSegment(); p = Point(&layoutns, 170, 100); ls->setStart(&p); p = Point(&layoutns, 170, 50); ls->setEnd(&p); // create species reference for ATP SpeciesReference* reference_ATP = reaction_Hexokinase->createReactant(); reference_ATP->setSpecies(species_ATP->getId()); reference_ATP->setId("SpeciesReference_ATP"); // create the species reference glyph for ATP speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_ATP"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_ATP->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_ATP->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_SIDESUBSTRATE); CubicBezier* cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 170, 100); cb->setStart(&p); p = Point(&layoutns, 170, 80); cb->setBasePoint1(&p); p = Point(&layoutns, 170, 80); cb->setBasePoint2(&p); p = Point(&layoutns, 260, 80); cb->setEnd(&p); // create species reference for G6P SpeciesReference* reference_G6P = reaction_Hexokinase->createProduct(); reference_G6P->setSpecies(species_G6P->getId()); reference_G6P->setId("SpeciesReference_G6P"); // create species reference for G6P as product speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_G6P_1"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_G6P->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_G6P->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_PRODUCT); ls = speciesReferenceGlyph->createLineSegment(); p = Point(&layoutns, 170, 130); ls->setStart(&p); p = Point(&layoutns, 170, 180); ls->setEnd(&p); // create species reference for ADP SpeciesReference* reference_ADP = reaction_Hexokinase->createProduct(); reference_ADP->setSpecies(species_ADP->getId()); reference_ADP->setId("SpeciesReference_ADP"); // create the species reference glyph for ADP speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_ADP"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_ADP->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_ADP->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_SIDEPRODUCT); cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 170, 130); cb->setStart(&p); p = Point(&layoutns, 170, 150); cb->setBasePoint1(&p); p = Point(&layoutns, 170, 150); cb->setBasePoint2(&p); p = Point(&layoutns, 260, 150); cb->setEnd(&p); // create modifier species reference for glucose-6-phosphate ModifierSpeciesReference* reference_G6P_2 = reaction_Hexokinase->createModifier(); reference_G6P_2->setSpecies(species_G6P->getId()); reference_G6P_2->setId("ModifierSpeciesReference_G6P"); reaction_Hexokinase->addModifier(reference_G6P_2); // create species reference glyph for G6P as a modifier speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_G6P_2"); speciesReferenceGlyph->setSpeciesReferenceId(reference_G6P_2->getId()); speciesReferenceGlyph->setSpeciesGlyphId(glyph_G6P->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_INHIBITOR); cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 45, 200); cb->setStart(&p); p = Point(&layoutns, 0, 200); cb->setBasePoint1(&p); p = Point(&layoutns, 0, 120); cb->setBasePoint2(&p); p = Point(&layoutns, 165, 120); cb->setEnd(&p); // create modifier species reference for phosphate ModifierSpeciesReference* reference_Pi = reaction_Hexokinase->createModifier(); reference_Pi->setSpecies(species_Pi->getId()); reference_Pi->setId("ModifierSpeciesReference_Pi"); reaction_Hexokinase->addModifier(reference_Pi); // create the species reference glyph for Phosphate speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_PI"); speciesReferenceGlyph->setSpeciesReferenceId(reference_Pi->getId()); speciesReferenceGlyph->setSpeciesGlyphId(glyph_Pi->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_ACTIVATOR); cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 115, 110); cb->setStart(&p); p = Point(&layoutns, 140, 110); cb->setBasePoint1(&p); p = Point(&layoutns, 140, 110); cb->setBasePoint2(&p); p = Point(&layoutns, 165, 110); cb->setEnd(&p); // write model to file writeSBML(document, "layout_example3_L2.xml"); delete document; }
SD_API_STATUS CSDHCBase::SlotOptionHandler( DWORD dwSlot, SD_SLOT_OPTION_CODE sdOption, PVOID pData, DWORD cbData ) { SD_API_STATUS status = SD_API_STATUS_SUCCESS; BOOL fCallSlotsHandler = TRUE; Lock(); Validate(); PCSDHCSlotBase pSlot = GetSlot(dwSlot); DEBUGCHK(sdOption < dim(sc_rgpszOptions)); DEBUGCHK(sc_rgpszOptions[sdOption] != NULL); DEBUGMSG(SDCARD_ZONE_INFO, (_T("CSDHCBase::SlotOptionHandler(%u, %s)\n"), dwSlot, sc_rgpszOptions[sdOption])); switch (sdOption) { case SDHCDSetSlotPower: { if (cbData != sizeof(DWORD)) { status = SD_API_STATUS_INVALID_PARAMETER; } break; } case SDHCDSetSlotInterface: { if (cbData != sizeof(SD_CARD_INTERFACE)) { status = SD_API_STATUS_INVALID_PARAMETER; } break; } case SDHCDEnableSDIOInterrupts: case SDHCDDisableSDIOInterrupts: case SDHCDAckSDIOInterrupt: if (pData || cbData != 0) { status = SD_API_STATUS_INVALID_PARAMETER; } break; case SDHCDGetWriteProtectStatus: { if (cbData != sizeof(SD_CARD_INTERFACE)) { status = SD_API_STATUS_INVALID_PARAMETER; } break; } case SDHCDQueryBlockCapability: { if (cbData != sizeof(SD_HOST_BLOCK_CAPABILITY)) { status = SD_API_STATUS_INVALID_PARAMETER; } break; } case SDHCDSetSlotPowerState: { if (cbData != sizeof(CEDEVICE_POWER_STATE)) { status = SD_API_STATUS_INVALID_PARAMETER; } PCEDEVICE_POWER_STATE pcps = (PCEDEVICE_POWER_STATE) pData; if (*pcps < m_cpsCurrent) { // Move controller to higher power state initially since // it will need to be powered for the slot to access // registers. SetControllerPowerState(*pcps); } status = pSlot->SlotOptionHandler(sdOption, pData, cbData); // Set the power state based on current conditions. Note that // the slot may have gone to a state different from what was // requested. CEDEVICE_POWER_STATE cps = DetermineRequiredControllerPowerState(); SetControllerPowerState(cps); fCallSlotsHandler = FALSE; break; } case SDHCDGetSlotPowerState: { if (cbData != sizeof(CEDEVICE_POWER_STATE)) { status = SD_API_STATUS_INVALID_PARAMETER; } break; } case SDHCDWakeOnSDIOInterrupts: { if (cbData != sizeof(BOOL)) { status = SD_API_STATUS_INVALID_PARAMETER; } break; } case SDHCDGetSlotInfo: { if (cbData != sizeof(SDCARD_HC_SLOT_INFO)) { status = SD_API_STATUS_INVALID_PARAMETER; } break; } default: break; } if (SD_API_SUCCESS(status) && fCallSlotsHandler) { // Call the slots handler to do the real work. status = pSlot->SlotOptionHandler(sdOption, pData, cbData); } Unlock(); return status; }
// This routine reads the registry to determine what type of device interfaces // we will be monitoring. The default PM GUID is ignored if present in the // registry and is always added last (so it's first in the list). BOOL DeviceListsInit(VOID) { BOOL fOk = TRUE; PDEVICE_LIST pdl; DWORD dwStatus; HKEY hk; TCHAR szBuf[MAX_PATH]; #ifndef SHIP_BUILD SETFNAME(_T("DeviceListsInit")); #endif // enumerate all the device classes StringCchPrintf(szBuf,_countof(szBuf), _T("%s\\Interfaces"), PWRMGR_REG_KEY); dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0, 0, &hk); if(dwStatus == ERROR_SUCCESS) { DWORD dwIndex = 0; do { DWORD cbValueName = dim(szBuf), dwType; GUID idInterface; dwStatus = RegEnumValue(hk, dwIndex, szBuf, &cbValueName, NULL, &dwType, NULL, NULL); if(dwStatus == ERROR_SUCCESS) { if(dwType != REG_SZ) { PMLOGMSG(ZONE_WARN, (_T("%s: invalid type for value '%s'\r\n"), pszFname, szBuf)); } else if(!ConvertStringToGuid(szBuf, &idInterface)) { PMLOGMSG(ZONE_WARN, (_T("%s: can't convert '%s' to GUID\r\n"), pszFname, szBuf)); } else if(idInterface == idGenericPMDeviceClass) { PMLOGMSG(ZONE_INIT, (_T("%s: default GUID found in registry as expected\r\n"), pszFname)); } else if((pdl = DeviceListCreate(&idInterface)) == NULL) { PMLOGMSG(ZONE_WARN, (_T("%s: DeviceListCreate() failed\r\n"), pszFname)); } else if(PlatformDeviceListInit(pdl) == FALSE) { PMLOGMSG(ZONE_WARN, (_T("%s: PlatformDeviceListInit() failed\r\n"), pszFname)); DeviceListDestroy(pdl); } else { // add the new entry to the list pdl->pNext = gpDeviceLists; gpDeviceLists = pdl; } // update the index dwIndex++; } } while(dwStatus == ERROR_SUCCESS); // check for abnormal termination of the loop if(dwStatus != ERROR_NO_MORE_ITEMS) { fOk = FALSE; } // close the registry handle RegCloseKey(hk); } // add the default list last if(fOk) { fOk = FALSE; pdl = DeviceListCreate(&idGenericPMDeviceClass); if(pdl != NULL) { if(PlatformDeviceListInit(pdl) == FALSE) { PMLOGMSG(ZONE_INIT || ZONE_WARN, (_T("%s: PlatformDeviceListInit() failed for default class\r\n"), pszFname)); DeviceListDestroy(pdl); } else { pdl->pNext = gpDeviceLists; gpDeviceLists = pdl; fOk = TRUE; } } } // clean up if necessary if(!fOk) { PMLOGMSG(ZONE_WARN, (_T("%s: error during list initialization\r\n"), pszFname)); while(gpDeviceLists != NULL) { pdl = gpDeviceLists; gpDeviceLists = pdl->pNext; pdl->pNext = NULL; DeviceListDestroy(pdl); } } return fOk; }
void gsMapper::drawMap(v3s16 position) { // width and height in nodes (these don't really need to be exact) s16 nwidth = floor(d_width / d_scale); s16 nheight = floor(d_height / d_scale); bool hasChanged = false; // check if position is outside the center if (d_valid) { if ( (position.X - d_border) < d_origin.X || (position.Z - d_border) < d_origin.Z || (position.X + d_border) > (d_origin.X + nwidth) || (position.Z + d_border) > (d_origin.Z + nheight) ) d_valid = false; } // recalculate the origin if (!d_valid || d_tracking) { d_origin.X = floor(position.X - (nwidth / 2)); d_origin.Y = d_surface; d_origin.Z = floor(position.Z - (nheight / 2)); d_valid = true; hasChanged = true; } // rescan next division of the map Map &map = d_client->getEnv().getMap(); v3s16 p; s16 x = 0; s16 y = 0; s16 z = 0; while (z < (nheight / 8) && (z + d_scanZ) < nheight) { p.Z = d_origin.Z + z + d_scanZ; x = 0; while (x < (nwidth / 8) && (x + d_scanX) < nwidth) { p.X = d_origin.X + x + d_scanX; bool b = true; // "above" mode: surface = mid-point for scanning if (d_above) { p.Y = d_surface + (d_scan / 2); for (y = 0; y < d_scan; y++) { if (b) { MapNode n = map.getNodeNoEx(p); p.Y--; if (n.param0 != CONTENT_IGNORE && n.param0 != CONTENT_AIR) { b = false; p.Y = d_surface; // check to see if this node is different from the map std::map<v3s16, u16>::iterator i2 = d_map.find(p); if ( i2 == d_map.end() || (i2 != d_map.end() && n.param0 != d_map[p]) ) { hasChanged = true; d_map[p] = n.param0; // change it } } } } // not "above" = use the radar for mapping } else { p.Y = position.Y + 1; MapNode n = map.getNodeNoEx(p); bool w = (n.param0 != CONTENT_IGNORE && n.param0 != CONTENT_AIR); int count = 0; u16 id = CONTENT_AIR; while (b) { if (w) // wall = scan up for air { p.Y++; n = map.getNodeNoEx(p); if (n.param0 == CONTENT_AIR) b = false; else id = n.param0; } else { // not wall = scan down for non-air p.Y--; n = map.getNodeNoEx(p); if (n.param0 != CONTENT_IGNORE && n.param0 != CONTENT_AIR) { id = n.param0; b = false; } } if (b && count++ >= (d_scan / 8)) { b = false; id = CONTENT_AIR; } } p.Y = d_surface; // the data is always flat std::map<v3s16, u16>::iterator i5 = d_radar.find(p); if ( i5 == d_radar.end() || (i5 != d_radar.end() && id != d_radar[p]) ) { hasChanged = true; d_radar[p] = id; // change it } } x++; } z++; } // move the scan block d_scanX += (nwidth / 8); if (d_scanX >= nwidth) { d_scanX = 0; d_scanZ += (nheight / 8); if (d_scanZ >= nheight) d_scanZ = 0; } video::IVideoDriver *driver = d_device->getVideoDriver(); if (hasChanged || !d_hastex) { // set up the image core::dimension2d<u32> dim(nwidth, nheight); video::IImage *image = driver->createImage(video::ECF_A8R8G8B8, dim); assert(image); bool psum = false; for (z = 0; z < nheight; z++) { for (x = 0; x < nwidth; x++) { p.X = d_origin.X + x; p.Y = d_surface; p.Z = d_origin.Z + z; u16 i = CONTENT_IGNORE; if (d_above) { std::map<v3s16, u16>::iterator i3 = d_map.find(p); if (i3 != d_map.end()) i = d_map[p]; } else { std::map<v3s16, u16>::iterator i6 = d_radar.find(p); if (i6 != d_radar.end()) i = d_radar[p]; } video::SColor c = getColorFromId(i); c.setAlpha(d_alpha); image->setPixel(x, nheight - z - 1, c); if (i != CONTENT_IGNORE) psum = true; } } // image -> texture if (psum && d_cooldown2 == 0) { if (d_hastex) { driver->removeTexture(d_texture); d_hastex = false; } std::string f = "gsmapper__" + itos(d_device->getTimer()->getRealTime()); d_texture = driver->addTexture(f.c_str(), image); assert(d_texture); d_hastex = true; d_cooldown2 = 5; // don't generate too many textures all at once } else { d_cooldown2--; if (d_cooldown2 < 0) d_cooldown2 = 0; } image->drop(); } // draw map texture if (d_hastex) { driver->draw2DImage( d_texture, core::rect<s32>(d_posx, d_posy, d_posx+d_width, d_posy+d_height), core::rect<s32>(0, 0, nwidth, nheight), 0, 0, true ); } // draw local player marker if (d_tsrc->isKnownSourceImage("player_marker0.png")) { v3s16 p = floatToInt(d_player->getPosition(), BS); if ( p.X >= d_origin.X && p.X <= (d_origin.X + nwidth) && p.Z >= d_origin.Z && p.Z <= (d_origin.Z + nheight) ) { f32 y = floor(360 - wrapDegrees_0_360(d_player->getYaw())); if (y < 0) y = 0; int r = floor(y / 90.0); int a = floor(fmod(y, 90.0) / 10.0); std::string f = "player_marker" + itos(a) + ".png"; video::ITexture *pmarker = d_tsrc->getTexture(f); assert(pmarker); v2u32 size = pmarker->getOriginalSize(); if (r > 0) { core::dimension2d<u32> dim(size.X, size.Y); video::IImage *image1 = driver->createImage(pmarker, core::position2d<s32>(0, 0), dim); assert(image1); // rotate image video::IImage *image2 = driver->createImage(video::ECF_A8R8G8B8, dim); assert(image2); for (u32 y = 0; y < size.Y; y++) for (u32 x = 0; x < size.X; x++) { video::SColor c; if (r == 1) { c = image1->getPixel(y, (size.X - x - 1)); } else if (r == 2) { c = image1->getPixel((size.X - x - 1), (size.Y - y - 1)); } else { c = image1->getPixel((size.Y - y - 1), x); } image2->setPixel(x, y, c); } image1->drop(); if (d_hasptex) { driver->removeTexture(d_pmarker); d_hasptex = false; } d_pmarker = driver->addTexture("playermarker__temp__", image2); assert(d_pmarker); pmarker = d_pmarker; d_hasptex = true; image2->drop(); } s32 sx = d_posx + floor((p.X - d_origin.X) * d_scale) - (size.X / 2); s32 sy = d_posy + floor((nheight - (p.Z - d_origin.Z)) * d_scale) - (size.Y / 2); driver->draw2DImage( pmarker, core::rect<s32>(sx, sy, sx+size.X, sy+size.Y), core::rect<s32>(0, 0, size.X, size.Y), 0, 0, true ); } } }
// This routine initializes the power manager and notifies the system that // its api set is ready to be used. It returns TRUE if successful and FALSE // if there's a problem. EXTERN_C BOOL WINAPI PmInit(VOID) { BOOL fOk = TRUE; HANDLE hevPnPReady = NULL, hevResumeReady = NULL, hevSystemReady = NULL; HANDLE hevActivityTimersReady = NULL, hevDummy = NULL; #ifndef SHIP_BUILD SETFNAME(_T("PmInit")); #endif PMLOGMSG(ZONE_INIT || ZONE_API, (_T("+%s\r\n"), pszFname)); // set up globals InitializeCriticalSection(&gcsPowerManager); InitializeCriticalSection(&gcsDeviceUpdateAPIs); gpFloorDx = NULL; gpCeilingDx = NULL; gpPowerNotifications = NULL; gpSystemPowerState = NULL; ghPmHeap = GetProcessHeap(); gpDeviceLists = NULL; gppActivityTimers = NULL; ghevPowerManagerReady = NULL; ghevResume = NULL; ghevTimerResume = NULL; ghtPnP = NULL; ghtResume = NULL; ghtActivityTimers = NULL; ghtSystem = NULL; // cleanup event (hopefully never used) ghevPmShutdown = CreateEvent(NULL, TRUE, FALSE, NULL); if(ghevPmShutdown == NULL) { PMLOGMSG(ZONE_ERROR, (_T("%s: CreateEvent() failed for shutdown event\r\n"), pszFname)); fOk = FALSE; } // validate the power management registry settings. OEM code should use this // routine to make sure that registry settings are present for all the power // states they expect to support. If the registry is not configured, the OEM // code can treat it as a fatal error or perform its own initialization. if(fOk) { DWORD dwStatus = PlatformValidatePMRegistry(); if(dwStatus != ERROR_SUCCESS) { PMLOGMSG(ZONE_ERROR, (_T("%s: PlatformValidatePMRegistry() failed %d\r\n"), pszFname, dwStatus)); fOk = FALSE; } else { // read the list of interface types we will monitor fOk = DeviceListsInit(); } } // create events if(fOk) { ghevPowerManagerReady = CreateEvent(NULL, TRUE, FALSE, _T("SYSTEM/PowerManagerReady")); ghevResume = CreateEvent(NULL, FALSE, FALSE, NULL); ghevTimerResume = CreateEvent(NULL, FALSE, FALSE, NULL); hevPnPReady = CreateEvent(NULL, FALSE, FALSE, NULL); hevResumeReady = CreateEvent(NULL, FALSE, FALSE, NULL); hevSystemReady = CreateEvent(NULL, FALSE, FALSE, NULL); hevActivityTimersReady = CreateEvent(NULL, FALSE, FALSE, NULL); hevDummy = CreateEvent(NULL, FALSE, FALSE, NULL); // check everything if(hevPnPReady == NULL || hevResumeReady == NULL || hevSystemReady == NULL || hevActivityTimersReady == NULL || hevDummy == NULL || ghevPowerManagerReady == NULL || ghevTimerResume == NULL || ghevResume == NULL) { PMLOGMSG(ZONE_ERROR, (_T("%s: event creation failure\r\n"), pszFname)); fOk = FALSE; } } // start threads if(fOk) { ghtPnP = CreateThread(NULL, 0, PnpThreadProc, (LPVOID) hevPnPReady, 0, NULL); ghtResume = CreateThread(NULL, 0, ResumeThreadProc, (LPVOID) hevResumeReady, 0, NULL); ghtActivityTimers = CreateThread(NULL, 0, ActivityTimersThreadProc, (LPVOID) hevActivityTimersReady, 0, NULL); // check everything if(ghtPnP == NULL || ghtResume == NULL || ghtActivityTimers == NULL) { PMLOGMSG(ZONE_ERROR, (_T("%s: thread creation failure\r\n"), pszFname)); fOk = FALSE; } } // wait for threads to initialize (or fail to initialize) #define NUM_OF_READY_EXIT_PAIR 3 HANDLE hEvents[] = { hevPnPReady, hevResumeReady, hevActivityTimersReady, ghtPnP, ghtResume, ghtActivityTimers }; int iReady = 0; while( iReady < NUM_OF_READY_EXIT_PAIR && fOk) { DWORD dwStatus = WaitForMultipleObjects(dim(hEvents), hEvents, FALSE, INFINITE); switch(dwStatus) { // thread ready events case (WAIT_OBJECT_0 + 0): // pnp ready case (WAIT_OBJECT_0 + 1): // resume ready case (WAIT_OBJECT_0 + 2): // activity timers ready // don't watch for the thread exiting now -- some may do // so if they don't have work to do. hEvents[dwStatus - WAIT_OBJECT_0 + NUM_OF_READY_EXIT_PAIR] = hevDummy; iReady++; break; // thread exiting events case (WAIT_OBJECT_0 + 3): // pnp exited case (WAIT_OBJECT_0 + 4): // resume exited case (WAIT_OBJECT_0 + 5): // activity timers exited PMLOGMSG(ZONE_ERROR, (_T("%s: thread initialization failure\r\n"), pszFname)); fOk = FALSE; break; default: PMLOGMSG(ZONE_ERROR, (_T("%s: WaitForMultipleObjects() returnd %d, status is %d\r\n"), pszFname, GetLastError())); fOk = FALSE; break; } } // load PMExt DLL, call init if (fOk) { TCHAR DevDll[DEVDLL_LEN]; DWORD cbData; DWORD Flags; HKEY hKey; gpPMExtInit = NULL; gpPMExtDeinit = NULL;; // Note: TEXT("\\Omap") is appended to the PMExt_Registry_Root because this is the only PMExt that we support if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, PMExt_Registry_Root TEXT("\\Omap"), 0, 0, &hKey)) { cbData = sizeof(DevDll); if (ERROR_SUCCESS == RegQueryValueEx(hKey, DEVLOAD_DLLNAME_VALNAME, NULL, NULL, (LPBYTE) DevDll, &cbData)) { cbData = sizeof(Flags); if (ERROR_SUCCESS != RegQueryValueEx(hKey, DEVLOAD_FLAGS_VALNAME, NULL, NULL, (LPBYTE) &Flags, &cbData)) { Flags = DEVFLAGS_NONE; } ghPMExtLib = (Flags & DEVFLAGS_LOADLIBRARY) ? LoadLibrary(DevDll) : LoadDriver(DevDll); if (!ghPMExtLib) { PMLOGMSG(ZONE_ERROR, (_T("%s: couldn't load PMExt \"%s\" -- error %d\r\n"), pszFname, DevDll, GetLastError())); } else { gpPMExtInit = (PFN_PMExt_Init) GetProcAddress(ghPMExtLib, PMExt_Init_NAME); if (!gpPMExtInit) PMLOGMSG(ZONE_ERROR, (_T("%s: \"%s\" can't GetProcAddress\r\n"), pszFname, PMExt_Init_NAME)); gpPMExtDeinit = (PFN_PMExt_DeInit) GetProcAddress(ghPMExtLib, PMExt_DeInit_NAME); } } else { PMLOGMSG(ZONE_INIT, (_T("%s: can't get value \"%s\" in key \"%s\"\r\n"), pszFname, DEVLOAD_DLLNAME_VALNAME, PMExt_Registry_Root TEXT("\\Omap"))); } if (gpPMExtInit && gpPMExtDeinit) { #ifdef DEBUG gdwPMExtContext = gpPMExtInit(HKEY_LOCAL_MACHINE, PMExt_Registry_Root TEXT("\\Omap")); #else __try { gdwPMExtContext = gpPMExtInit(HKEY_LOCAL_MACHINE, PMExt_Registry_Root TEXT("\\Omap")); } __except(EXCEPTION_EXECUTE_HANDLER) { gdwPMExtContext = 0; } #endif if (!gdwPMExtContext) PMLOGMSG(ZONE_ERROR, (_T("%s: \"%s\" failed\r\n"), pszFname, PMExt_Init_NAME)); else PMLOGMSG(ZONE_INIT, (_T("%s: \"%s\" success\r\n"), pszFname, PMExt_Init_NAME)); } RegCloseKey(hKey); }
const SpdMatrix & IMMGS::siginv() const { sigma_scratch_.resize(dim()); sigma_scratch_.diag() = 1.0 / unscaled_variance_diagonal(); sigma_scratch_.diag() /= sigsq(); return sigma_scratch_; }
static constexpr int size() { return Sequence::size() / (1 << dim()); }