// Automatically sets the MXF file's metadata from the WAV parser info. ASDCP::Result_t ASDCP::PCM::MXFWriter::h__Writer::SetSourceStream(const AudioDescriptor& ADesc) { if ( ! m_State.Test_INIT() ) return RESULT_STATE; if ( ADesc.EditRate != EditRate_24 && ADesc.EditRate != EditRate_25 && ADesc.EditRate != EditRate_30 && ADesc.EditRate != EditRate_48 && ADesc.EditRate != EditRate_50 && ADesc.EditRate != EditRate_60 && ADesc.EditRate != EditRate_96 && ADesc.EditRate != EditRate_100 && ADesc.EditRate != EditRate_120 && ADesc.EditRate != EditRate_16 && ADesc.EditRate != EditRate_18 && ADesc.EditRate != EditRate_20 && ADesc.EditRate != EditRate_22 && ADesc.EditRate != EditRate_23_98 ) { DefaultLogSink().Error("AudioDescriptor.EditRate is not a supported value: %d/%d\n", ADesc.EditRate.Numerator, ADesc.EditRate.Denominator); return RESULT_RAW_FORMAT; } if ( ADesc.AudioSamplingRate != SampleRate_48k && ADesc.AudioSamplingRate != SampleRate_96k ) { DefaultLogSink().Error("AudioDescriptor.AudioSamplingRate is not 48000/1 or 96000/1: %d/%d\n", ADesc.AudioSamplingRate.Numerator, ADesc.AudioSamplingRate.Denominator); return RESULT_RAW_FORMAT; } assert(m_Dict); m_ADesc = ADesc; Result_t result = PCM_ADesc_to_MD(m_ADesc, (WaveAudioDescriptor*)m_EssenceDescriptor); if ( ASDCP_SUCCESS(result) ) { memcpy(m_EssenceUL, m_Dict->ul(MDD_WAVEssence), SMPTE_UL_LENGTH); m_EssenceUL[SMPTE_UL_LENGTH-1] = 1; // first (and only) essence container result = m_State.Goto_READY(); } if ( ASDCP_SUCCESS(result) ) { result = WriteASDCPHeader(PCM_PACKAGE_LABEL, UL(m_Dict->ul(MDD_WAVWrappingFrame)), SOUND_DEF_LABEL, UL(m_EssenceUL), UL(m_Dict->ul(MDD_SoundDataDef)), m_ADesc.EditRate, derive_timecode_rate_from_edit_rate(m_ADesc.EditRate), calc_CBR_frame_size(m_Info, m_ADesc)); } return result; }
static void __init omnia_II_fixup(struct machine_desc *desc, struct tag *tags, char **cmdline, struct meminfo *mi) { mi->nr_banks = 2; mi->bank[0].start = UL(0x50000000);//PHYS_OFFSET; mi->bank[0].size = (128 * 1024 * 1024); mi->bank[0].node = PHYS_TO_NID(0x50000000); mi->bank[1].start = UL(0x60000000); mi->bank[1].size = PHYS_UNRESERVED_SIZE; // mi->bank[1].size = (80 * 1024 * 1024); mi->bank[1].node = PHYS_TO_NID(0x60000000); }
void ASDCP::ATMOS::AtmosDescriptorDump(const AtmosDescriptor& ADesc, FILE* stream) { char str_buf[40]; char atmosID_buf[40]; if ( stream == 0 ) stream = stderr; fprintf(stream, "\ EditRate: %d/%d\n\ ContainerDuration: %u\n\ DataEssenceCoding: %s\n\ AtmosVersion: %u\n\ MaxChannelCount: %u\n\ MaxObjectCount: %u\n\ AtmosID: %s\n\ FirsFrame: %u\n", ADesc.EditRate.Numerator, ADesc.EditRate.Denominator, ADesc.ContainerDuration, UL(ADesc.DataEssenceCoding).EncodeString(str_buf, 40), ADesc.AtmosVersion, ADesc.MaxChannelCount, ADesc.MaxObjectCount, UUID(ADesc.AtmosID).EncodeString(atmosID_buf, 40), ADesc.FirstFrame); }
JNIEXPORT jlong JNICALL Java_jxtn_core_unix_NativeString_memmem(JNIEnv *env, jclass thisObj, jlong haystack, jlong haystacklen, jbyteArray needle) { if (haystack == 0L || needle == 0L) return SETERR(EFAULT); size_t needlelen = (size_t) (*env)->GetArrayLength(env, needle); return (jlong) memmem((void*) haystack, UL(haystacklen), resolveBA(needle), needlelen); }
JNIEXPORT jint JNICALL Java_jxtn_core_unix_NativeDirs_getdents64(JNIEnv *env, jclass thisObj, jint fd, jbyteArray dirp) { if (dirp == NULL) { return SETERR(EFAULT); } size_t count = UL((*env)->GetArrayLength(env, dirp)); return ERR((int) syscall(SYS_getdents64, fd, resolveBA(dirp), count)); }
int __init_malloc(void) { curr_brk = mem_ptr = orig_brk = (void*)ROUNDUP(UL(mbrk(0)), BYTES_PER_LONG); if (orig_brk + INITIAL_SIZE != mbrk(orig_brk + INITIAL_SIZE)) return -1; SET_SIZE(mem_ptr, INITIAL_SIZE); SET_UNUSED(mem_ptr); curr_brk = orig_brk + INITIAL_SIZE; return 0; }
std::ostream& ASDCP::ATMOS::operator << (std::ostream& strm, const AtmosDescriptor& ADesc) { char str_buf[40]; strm << " EditRate: " << ADesc.EditRate.Numerator << "/" << ADesc.EditRate.Denominator << std::endl; strm << " ContainerDuration: " << (unsigned) ADesc.ContainerDuration << std::endl; strm << " DataEssenceCoding: " << UL(ADesc.DataEssenceCoding).EncodeString(str_buf, 40) << std::endl; strm << " AtmosVersion: " << (unsigned) ADesc.AtmosVersion << std::endl; strm << " MaxChannelCount: " << (unsigned) ADesc.MaxChannelCount << std::endl; strm << " MaxObjectCount: " << (unsigned) ADesc.MaxObjectCount << std::endl; strm << " AtmosID: " << UUID(ADesc.AtmosID).EncodeString(str_buf, 40) << std::endl; strm << " FirstFrame: " << (unsigned) ADesc.FirstFrame << std::endl; return strm; }
void World::RenderGroup(SceneGroup *i, mat4 t) { int ii, time = 0; // sphere vars double r; MaterialInfo m; // light vars LightInfo l; // camera vars CameraInfo f; // if this is a terminal node if (i->getChildCount() == 0) { // if this node is a sphere if (i->computeSphere(r,m,time)) { _spheres.push_back(Sphere(vec4(0,0,0,1), r, m, t)); } else if (i->computeLight(l)) { if (l.type == LIGHT_POINT) { _lights[l.type].push_back(Light(vec3(t*vec4(0,0,0,1),VW),0, l)); }else if (l.type == LIGHT_DIRECTIONAL){ _lights[l.type].push_back(Light(0,vec3(t*vec4(0,0,-1,0),VW), l)); }else if (l.type == LIGHT_AMBIENT) _ambientLight = l.color; } else if (i->computeCamera(f)) { vec4 eye(0.0, 0.0, 0.0, 1.0); vec4 LL(f.sides[FRUS_LEFT], f.sides[FRUS_BOTTOM], -1*f.sides[FRUS_NEAR], 1.0); vec4 UL(f.sides[FRUS_LEFT], f.sides[FRUS_TOP], -1*f.sides[FRUS_NEAR], 1.0); vec4 LR(f.sides[FRUS_RIGHT], f.sides[FRUS_BOTTOM], -1*f.sides[FRUS_NEAR], 1.0); vec4 UR(f.sides[FRUS_RIGHT], f.sides[FRUS_TOP], -1*f.sides[FRUS_NEAR], 1.0); _view = Viewport(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT); } } else { // expand and traverse this node for(ii=0; ii<i->getChildCount();ii++) RenderInstance(i->getChild(ii), t); } }
bool wxGetDiskSpace(const wxString& WXUNUSED_IN_WINCE(path), wxDiskspaceSize_t *WXUNUSED_IN_WINCE(pTotal), wxDiskspaceSize_t *WXUNUSED_IN_WINCE(pFree)) { #ifdef __WXWINCE__ // TODO-CE return false; #else if ( path.empty() ) return false; ULARGE_INTEGER bytesFree, bytesTotal; // may pass the path as is, GetDiskFreeSpaceEx() is smart enough if ( !::GetDiskFreeSpaceEx(path.t_str(), &bytesFree, &bytesTotal, NULL) ) { wxLogLastError(wxT("GetDiskFreeSpaceEx")); return false; } // ULARGE_INTEGER is a union of a 64 bit value and a struct containing // two 32 bit fields which may be or may be not named - try to make it // compile in all cases #if defined(__BORLANDC__) && !defined(_ANONYMOUS_STRUCT) #define UL(ul) ul.u #else // anon union #define UL(ul) ul #endif if ( pTotal ) { #if wxUSE_LONGLONG *pTotal = wxDiskspaceSize_t(UL(bytesTotal).HighPart, UL(bytesTotal).LowPart); #else *pTotal = wxDiskspaceSize_t(UL(bytesTotal).LowPart); #endif } if ( pFree ) { #if wxUSE_LONGLONG *pFree = wxLongLong(UL(bytesFree).HighPart, UL(bytesFree).LowPart); #else *pFree = wxDiskspaceSize_t(UL(bytesFree).LowPart); #endif } return true; #endif // __WXWINCE__ }
/* This potentially could be optimized internally. However, the * current implementation does the dumb thing (allocate more * than needed to ensure alignment). We assume alignment is a power * of two. * * This function is provided more out of convenience since dput/dget * require memory to be aligned on a page boundary for copying. The * caller must keep track of the actual pointer that this library * knows about to free the memory. */ void *malloc_aligned(ssize_t size, uint32_t alignment, void **actual) { /*ssize_t s2ize = size; size = ROUNDUP(size, BYTES_PER_LONG); ssize_t off = (alignment - size % alignment) % alignment; void *v = malloc(size + off); if (!v) return NULL; *actual = v; iprintf("But actually (%08lx,%d)\n", ROUNDDOWN(UL(v),alignment),s2ize); return (void*)(ROUNDDOWN(UL(v), alignment));*/ void *v = malloc(size + alignment - 1); if (!v) return NULL; *actual = v; return (void*)ROUNDUP(UL(v), alignment); }
void QuasiNewton<dcomplex>::setupRestart(){ this->allocGuess(); ComplexCMMap UR(this->URMem,this->N_,this->nGuess_); (*this->guessR_) = UR; if(this->symmetrizedTrial_){ ComplexCMMap UL(this->ULMem,this->N_,this->nGuess_); (*this->guessL_) = UL; } // Zero out scratch space std::memset(this->SCR,0.0,this->LenScr*sizeof(dcomplex)); // Ensure that the the new guess vectors are orthonormal this->Orth(*this->guessR_); if(this->symmetrizedTrial_) this->Orth(*this->guessL_); /** DO NOT RESET doRestart_ here! next iteration needs to know that we restarted **/ } // setupRestart
int main() { std::mutex MX; std::condition_variable CV; auto F1 = [&] { std::cout << "Start F1" << std::endl; try { std::unique_lock<std::mutex> UL(MX); while (true) { interruptible_wait(CV, UL); } } catch (thread_interrupted& e) { std::cout << e.what() << std::endl; } std::cout << "Endof F1" << std::endl; }; interruptible_thread T1(F1); std::thread T2([&] { std::cout << "Start F2" << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(1000)); T1.interrupt(); //std::this_thread::sleep_for(std::chrono::milliseconds(10000)); //T1.interrupt(); std::cout << "Endof F2" << std::endl; }); T1.join(); T2.join(); return 0; }
char* ProcParse(const char* buffer, int length) { int i; int cur = 0; char* nametable = (char*)malloc(length + 1); memset(nametable, NULL, length + 1); for (i = 0; i < length + 1; i++) { if (buffer[i] == '\0') { nametable[cur] = 0x00; break; } else if (buffer[i] == '\n') { nametable[cur++] = 0x80; // 0x80は改行コードなので覚えよう } else if ((unsigned char)buffer[i] == 0x20) { nametable[cur++] = 0x40; // 0x40は例外的に空白記号にする } else if (UL(0x21,0x3f)) { nametable[cur++] = 0xff; i++; } else if (0x20 <= buffer[i] && buffer[i] <= 0x7d) { nametable[cur++] = buffer[i] - 0x20; /* アルファベット処理 */ } else if (0x81 <= (unsigned char)buffer[i] && (unsigned char)buffer[i] <= 0x83) { /* 2バイト文字の処理 */ nametable[cur] = MultiByteWord((unsigned char)buffer[i], (unsigned char)buffer[i+1], &nametable[cur+1]); if ((unsigned char)nametable[cur] == 0xc0) { printf("%02x\n", (unsigned char)buffer[i]); AssertionWord(i); } if (nametable[cur+1] != NULL) cur++; /* qualifyがNULLじゃなければ,濁点扱いでインクリ */ cur++; i += 1; } else { AssertionWord(i); } } return nametable; }
static ssize_t copyfile_sparse(int srcfd, int dstfd) { ssize_t srcend = lseek(srcfd, 0L, SEEK_END); if (srcend == -1L) { return -1L; } if (ftruncate(dstfd, srcend) == -1) { return -1L; } ssize_t num_total = 0L; ssize_t srcpos = 0L; while (srcpos < srcend) { ssize_t next_beg = srcpos = lseek(srcfd, srcpos, SEEK_DATA); if (next_beg == -1L) { return -1L; } ssize_t next_end = srcpos = lseek(srcfd, srcpos, SEEK_HOLE); if (next_end == -1L) { return -1L; } ssize_t next_len = next_end - next_beg; if (next_len > 0) { if (lseek(srcfd, next_beg, SEEK_SET) == -1L) { return -1L; } if (lseek(dstfd, next_beg, SEEK_SET) == -1L) { return -1L; } ssize_t num = sendfile(dstfd, srcfd, NULL, UL(next_len)); if (num == -1L) { return -1L; } num_total += num; } srcpos = next_end; } return num_total; }
Shader_T * ColorTextureLightShader_Create(const char * shader_name, GLuint shader_id) { ColorTextureLightShader_T * shader; shader = malloc(sizeof(ColorTextureLightShader_T)); Shader_Init(&shader->parent, shader_name, e_ST_Map, shader_id, ColorTextureLightShader_Destory, ColorTextureLightShader_Renderer); shader->uniform_world = UL("WMatrix"); shader->uniform_world_perspective = UL("PMatrix"); shader->uniform_texture = UL("CSampler"); shader->uniform_light_direction = UL("LightDirection"); shader->uniform_light_color = UL("LightColor"); shader->uniform_color = UL("Color"); return (Shader_T *)shader; }
JNIEXPORT jlong JNICALL Java_jxtn_core_unix_NativeMMap_mmap(JNIEnv *env, jclass thisObj, jlong addr, jlong length, jint prot, jint flags, jint fd, jlong offset) { return ERRVP(mmap((void*) addr, UL(length), prot, flags, fd, offset)); }
bool wxGetDiskSpace(const wxString& WXUNUSED_IN_WINCE(path), wxDiskspaceSize_t *WXUNUSED_IN_WINCE(pTotal), wxDiskspaceSize_t *WXUNUSED_IN_WINCE(pFree)) { #ifdef __WXWINCE__ // TODO-CE return false; #else if ( path.empty() ) return false; // old w32api don't have ULARGE_INTEGER #if defined(__WIN32__) && \ (!defined(__GNUWIN32__) || wxCHECK_W32API_VERSION( 0, 3 )) // GetDiskFreeSpaceEx() is not available under original Win95, check for // it typedef BOOL (WINAPI *GetDiskFreeSpaceEx_t)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER); GetDiskFreeSpaceEx_t pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress ( ::GetModuleHandle(_T("kernel32.dll")), #if wxUSE_UNICODE "GetDiskFreeSpaceExW" #else "GetDiskFreeSpaceExA" #endif ); if ( pGetDiskFreeSpaceEx ) { ULARGE_INTEGER bytesFree, bytesTotal; // may pass the path as is, GetDiskFreeSpaceEx() is smart enough if ( !pGetDiskFreeSpaceEx(path, &bytesFree, &bytesTotal, NULL) ) { wxLogLastError(_T("GetDiskFreeSpaceEx")); return false; } // ULARGE_INTEGER is a union of a 64 bit value and a struct containing // two 32 bit fields which may be or may be not named - try to make it // compile in all cases #if defined(__BORLANDC__) && !defined(_ANONYMOUS_STRUCT) #define UL(ul) ul.u #else // anon union #define UL(ul) ul #endif if ( pTotal ) { #if wxUSE_LONGLONG *pTotal = wxDiskspaceSize_t(UL(bytesTotal).HighPart, UL(bytesTotal).LowPart); #else *pTotal = wxDiskspaceSize_t(UL(bytesTotal).LowPart); #endif } if ( pFree ) { #if wxUSE_LONGLONG *pFree = wxLongLong(UL(bytesFree).HighPart, UL(bytesFree).LowPart); #else *pFree = wxDiskspaceSize_t(UL(bytesFree).LowPart); #endif } } else #endif // Win32 { // there's a problem with drives larger than 2GB, GetDiskFreeSpaceEx() // should be used instead - but if it's not available, fall back on // GetDiskFreeSpace() nevertheless... DWORD lSectorsPerCluster, lBytesPerSector, lNumberOfFreeClusters, lTotalNumberOfClusters; // FIXME: this is wrong, we should extract the root drive from path // instead, but this is the job for wxFileName... if ( !::GetDiskFreeSpace(path, &lSectorsPerCluster, &lBytesPerSector, &lNumberOfFreeClusters, &lTotalNumberOfClusters) ) { wxLogLastError(_T("GetDiskFreeSpace")); return false; } wxDiskspaceSize_t lBytesPerCluster = (wxDiskspaceSize_t) lSectorsPerCluster; lBytesPerCluster *= lBytesPerSector; if ( pTotal ) { *pTotal = lBytesPerCluster; *pTotal *= lTotalNumberOfClusters; } if ( pFree ) { *pFree = lBytesPerCluster; *pFree *= lNumberOfFreeClusters; } } return true; #endif // __WXWINCE__ }
void PM_dem::detect( Mat &img, float score_thresh, bool show_hints, bool show_img, string save_img ) { if( score_thresh==DEFAULT_THRESH ) model.threshing = model.thresh; else model.threshing = score_thresh; hints = show_hints; // 1. Feature pyramid <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< prag_start = yuGetCurrentTime('M'); if( hints ){ printf("Calculating feature pyramid ...\n"); start_clock = prag_start; } featpyramid2( img, model, pyra ); if( hints ){ end_clock = yuGetCurrentTime('M'); printf("Time for _featpyramid is %gs\n",(end_clock-start_clock)/1000.f); } // 2. Compute PCA projection of the feature pyramid <<<<<<<<<<<<<< if( hints ){ printf("Compute PCA projection of the feature pyramid ...\n"); start_clock = end_clock; } /*Mat Ctest = model.C2(Rect(0,155,32,1)); cout<<Ctest;*/ //project_pyramid( model, pyra ); if( hints ){ end_clock = yuGetCurrentTime('M'); printf("Time for _project_pyramid() is %gs\n",(end_clock-start_clock)/1000.f); } if (hints) { end_clock = start_clock; printf("QT\n"); } qtpyra(model,pyra); if (hints) { end_clock = yuGetCurrentTime('M'); printf("%gs\n",(end_clock-start_clock)/1000.f); } if( pyra.num_levels!=pyra.feat.size() ){ printf("pyra.num_levels!=pyra.feat.size()\n"); throw runtime_error(""); } // 3. Precompute location/scale scores <<<<<<<<<<<<<<<<<<<<<<< Mat loc_f = loc_feat( model, pyra.num_levels ); pyra.loc_scores.resize( model.numcomponents ); for( int c=0; c<model.numcomponents; c++ ){ Mat loc_w( 1, model.loc[c].w.size(), CV_32FC1, &(model.loc[c].w[0]) ); // loc_w = model.loc[c].w pyra.loc_scores[c] = loc_w * loc_f; } // 4. Gather PCA root filters for convolution <<<<<<<<<<<<<<<<<<< if( hints ){ printf("Gathering PCA root filters for convolution ...\n"); start_clock = end_clock; } if( rootscores[0].size()!=pyra.num_levels ){ vector<Mat> tmp_rootscores(pyra.num_levels); rootscores.assign(model.numcomponents,tmp_rootscores); } // ofstream f1("pj.txt"); int numrootlocs = 0; int s = 0; // will hold the amount of temp storage needed by cascade() for( int i=0; i<pyra.num_levels; i++ ){ s += pyra.feat[i].rows * pyra.feat[i].cols; if( i<model.interval ) continue; static vector<Mat> scores; //fconv( pyra.projfeat[i], rootfilters, 0, numrootfilters, scores ); fconv_root_qt(model, pyra.qtfeat[i], scores); for( int c=0; c<model.numcomponents; c++ ){ int u = model.components[c].rootindex; int v = model.components[c].offsetindex; float tmp = model.offsets[v].w + pyra.loc_scores[c].at<float>(i); rootscores[c][i] = scores[u] + Scalar(tmp); numrootlocs += scores[u].total(); } } cout<<numrootlocs<<endl; s = s * model.partfilters.size(); if( hints ){ end_clock = yuGetCurrentTime('M'); printf("Time for gathering PCA root filters is %gs\n",(end_clock-start_clock)/1000.f); } // 5. Cascade detection in action <<<<<<<<<<<<<<<<<<<<<<< if( hints ){ printf("Cascade detection in action ...\n"); start_clock = end_clock; } //Mat coords = cascade(model, pyra, rootscores, numrootlocs, s); Mat coords = cascade_qt(model, pyra, rootscores, numrootlocs, s); //cout<<coords; //cout<<"??"<<endl; if( hints ){ end_clock = yuGetCurrentTime('M'); printf("Time for _cascade() is %gs\n",(end_clock-start_clock)/1000.f); if( coords.empty() ){ printf("No Detection!\n"); return; } } // 6. Detection results <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Mat boxes = getboxes( model, img_color, coords ); Mat x1 = boxes.col(0); Mat y1 = boxes.col(1); Mat x2 = boxes.col(2); Mat y2 = boxes.col(3); Mat Score = boxes.col( boxes.cols-1 ); detections.resize( x1.rows ); for( int i=0; i<x1.rows; i++ ){ detections[i][0] = x1.at<float>(i); detections[i][1] = y1.at<float>(i); detections[i][2] = x2.at<float>(i); detections[i][3] = y2.at<float>(i); detections[i][4] = Score.at<float>(i); } if( hints ){ prag_end = yuGetCurrentTime('M'); printf("Total detection time is : %gs\n",(prag_end-prag_start)/1000.f); } // 6. Draw and show <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if( show_img || !save_img.empty() ){ //showboxes( img_color, boxes ); // const int fontFace = CV_FONT_HERSHEY_PLAIN; const double fontScale = 1; const Scalar drawColor = CV_RGB(255,0,0); const Scalar fontColor = CV_RGB(30,250,150); // for( int i=0; i!=detections.size(); i++ ){ float x1 = detections[i][0], y1 = detections[i][1], x2 = detections[i][2], y2 = detections[i][3]; float _score = detections[i][4]; // Point2f UL( x1, y1 ); Point2f BR( x2, y2 ); rectangle( img_color, UL, BR, drawColor, 2 ); printf("----------------------------\n"); printf("%g %g %g %g %g\n", x1, y1, x2, y2, _score ); // x1 = int(x1*10+0.5) / 10.f; // ½ö±£Áô1λСÊý y1 = int(y1*10+0.5) / 10.f; x2 = int(x2*10+0.5) / 10.f; y2 = int(y2*10+0.5) / 10.f; _score = int(_score*100+0.5) / 100.f; // char buf[50] = { 0 }; sprintf_s( buf, 50, "%d", i ); string text = buf; int baseline = 0; Size textSize = getTextSize( text, fontFace, fontScale, 1, &baseline ); Point2f textOrg2( x1, y1+textSize.height+2 ); putText( img_color, text, textOrg2, fontFace, fontScale, fontColor ); // sprintf_s( buf, 50, "%d %g %g %g %g %g", i, x1, y1, x2, y2, _score ); text = buf; textSize = getTextSize( text, fontFace, fontScale, 1, &baseline ); Point2f textOrg(5,(i+1)*(textSize.height+3)); putText( img_color, text, textOrg, fontFace, fontScale, fontColor ); } { char buf[30] = { 0 }; sprintf_s( buf, 30, "time : %gs", (prag_end-prag_start)/1000.f ); string time_text = buf; int baseline = 0; Size textSize = getTextSize( time_text, fontFace, fontScale, 1, &baseline ); Point2f time_orig(5,(detections.size()+1)*(textSize.height+3)); putText( img_color, time_text, time_orig, fontFace, fontScale, fontColor ); } if( show_img ) imshow( "OK", img_color ); if( !save_img.empty() ) imwrite( save_img, img_color ); } }
ASDCP::Result_t ASDCP::EssenceType(const std::string& filename, EssenceType_t& type) { const Dictionary* m_Dict = &DefaultCompositeDict(); InterchangeObject* md_object = 0; assert(m_Dict); Kumu::FileReader Reader; OP1aHeader TestHeader(m_Dict); Result_t result = Reader.OpenRead(filename); if ( ASDCP_SUCCESS(result) ) result = TestHeader.InitFromFile(Reader); // test UL and OP if ( ASDCP_SUCCESS(result) ) { type = ESS_UNKNOWN; if ( TestHeader.OperationalPattern == UL(m_Dict->ul(MDD_OPAtom)) || TestHeader.OperationalPattern == UL(m_Dict->ul(MDD_MXFInterop_OPAtom)) ) { if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(JPEG2000PictureSubDescriptor))) ) { if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(StereoscopicPictureSubDescriptor))) ) { type = ESS_JPEG_2000_S; } else { type = ESS_JPEG_2000; } } else if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(WaveAudioDescriptor), &md_object)) ) { assert(md_object); if ( static_cast<ASDCP::MXF::WaveAudioDescriptor*>(md_object)->AudioSamplingRate == SampleRate_96k ) { type = ESS_PCM_24b_96k; } else { type = ESS_PCM_24b_48k; } } else if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(MPEG2VideoDescriptor))) ) { type = ESS_MPEG2_VES; } else if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(TimedTextDescriptor))) ) { type = ESS_TIMED_TEXT; } else if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(DCDataDescriptor))) ) { if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(DolbyAtmosSubDescriptor))) ) { type = ESS_DCDATA_DOLBY_ATMOS; } else { type = ESS_DCDATA_UNKNOWN; } } } else if ( TestHeader.OperationalPattern == UL(m_Dict->ul(MDD_OP1a)) ) { if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(JPEG2000PictureSubDescriptor))) ) { type = ESS_AS02_JPEG_2000; } else if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(WaveAudioDescriptor), &md_object)) ) { assert(md_object); if ( static_cast<ASDCP::MXF::WaveAudioDescriptor*>(md_object)->AudioSamplingRate == SampleRate_96k ) { type = ESS_AS02_PCM_24b_96k; } else { type = ESS_AS02_PCM_24b_48k; } } else if ( ASDCP_SUCCESS(TestHeader.GetMDObjectByType(OBJ_TYPE_ARGS(TimedTextDescriptor))) ) { type = ESS_AS02_TIMED_TEXT; } } else { DefaultLogSink().Error("Unsupported MXF Operational Pattern.\n"); return RESULT_FORMAT; } } return result; }
JNIEXPORT jint JNICALL Java_jxtn_core_unix_NativeMMap_msync(JNIEnv *env, jclass thisObj, jlong addr, jlong length, jint flags) { return ERR(msync((void*) addr, UL(length), flags)); }
void overFace::rusanovFlux(void) { /* Different flux function to utilize interpolated corrected flux, but still * apply upwinding */ if (params->oversetMethod == 1) { for (int fpt=0; fpt<nFptsL; fpt++) { // Get primitive variables double rhoL = UL(fpt,0); double rhoR = UR(fpt,0); double uL = UL(fpt,1)/rhoL; double uR = UR(fpt,1)/rhoR; double vL = UL(fpt,2)/rhoL; double vR = UR(fpt,2)/rhoR; double wL, pL, vnL=0.; double wR, pR, vnR=0.; double vgn=0.; // Calculate pressure if (params->nDims==2) { pL = (params->gamma-1.0)*(UL(fpt,3)-0.5*rhoL*(uL*uL+vL*vL)); pR = (params->gamma-1.0)*(UR(fpt,3)-0.5*rhoR*(uR*uR+vR*vR)); } else { wL = UL(fpt,3)/rhoL; wR = UR(fpt,3)/rhoR; pL = (params->gamma-1.0)*(UL(fpt,4)-0.5*rhoL*(uL*uL+vL*vL+wL*wL)); pR = (params->gamma-1.0)*(UR(fpt,4)-0.5*rhoR*(uR*uR+vR*vR+wR*wR)); } // Get normal fluxes, normal velocities for (int dim=0; dim<params->nDims; dim++) { vnL += normL(fpt,dim)*UL(fpt,dim+1)/rhoL; vnR += normL(fpt,dim)*UR(fpt,dim+1)/rhoR; if (params->motion) vgn += normL(fpt,dim)*Vg(fpt,dim); } // Get maximum eigenvalue for diffusion coefficient double csqL = max(params->gamma*pL/rhoL,0.0); double csqR = max(params->gamma*pR/rhoR,0.0); double eigL = std::fabs(vnL) + sqrt(csqL); double eigR = std::fabs(vnR) + sqrt(csqR); double eig = max(eigL,eigR); /* Calculate Rusanov flux using corrected normal flux from donor grid * (copied to Fn) */ // Outflow - use internal state if (vnL - vgn > 0) { inviscidFlux(UL[fpt],tempFL,params); double tempFnL[5] = {0,0,0,0,0}; for (int k=0; k<nFields; k++) for (int dim=0; dim<nDims; dim++) tempFnL[k] += tempFL[dim][k]*normL(fpt,dim); for (int k=0; k<params->nFields; k++) { Fn(fpt,k) = tempFnL[k] - 0.5*eig*(UR(fpt,k)-UL(fpt,k)); } } // Inflow - use external state [previously copied into Fn] else { for (int k=0; k<params->nFields; k++) { Fn(fpt,k) = Fn(fpt,k) - 0.5*eig*(UR(fpt,k)-UL(fpt,k)); } } // Store wave speed for calculation of allowable dt if (params->motion) { eigL = std::fabs(vnL-vgn) + sqrt(csqL); eigR = std::fabs(vnR-vgn) + sqrt(csqR); } *waveSp[fpt] = max(eigL,eigR); } } // For other overset methods, just call normal Rusanov flux else { face::rusanovFlux(); } }
void Panama<B>::Iterate(size_t count, const word32 *p, word32 *z, const word32 *y) { word32 bstart = m_state[17]; word32 *const aPtr = m_state; word32 cPtr[17]; #define bPtr ((byte *)(aPtr+20)) // reorder the state for SSE2 // a and c: 4 8 12 16 | 3 7 11 15 | 2 6 10 14 | 1 5 9 13 | 0 // xmm0 xmm1 xmm2 xmm3 eax #define a(i) aPtr[((i)*13+16) % 17] // 13 is inverse of 4 mod 17 #define c(i) cPtr[((i)*13+16) % 17] // b: 0 4 | 1 5 | 2 6 | 3 7 #define b(i, j) b##i[(j)*2%8 + (j)/4] // output #define OA(i) z[i] = ConditionalByteReverse(B::ToEnum(), a(i+9)) #define OX(i) z[i] = y[i] ^ ConditionalByteReverse(B::ToEnum(), a(i+9)) // buffer update #define US(i) {word32 t=b(0,i); b(0,i)=ConditionalByteReverse(B::ToEnum(), p[i])^t; b(25,(i+6)%8)^=t;} #define UL(i) {word32 t=b(0,i); b(0,i)=a(i+1)^t; b(25,(i+6)%8)^=t;} // gamma and pi #define GP(i) c(5*i%17) = rotlFixed(a(i) ^ (a((i+1)%17) | ~a((i+2)%17)), ((5*i%17)*((5*i%17)+1)/2)%32) // theta and sigma #define T(i,x) a(i) = c(i) ^ c((i+1)%17) ^ c((i+4)%17) ^ x #define TS1S(i) T(i+1, ConditionalByteReverse(B::ToEnum(), p[i])) #define TS1L(i) T(i+1, b(4,i)) #define TS2(i) T(i+9, b(16,i)) while (count--) { if (z) { if (y) { OX(0); OX(1); OX(2); OX(3); OX(4); OX(5); OX(6); OX(7); y += 8; } else { OA(0); OA(1); OA(2); OA(3); OA(4); OA(5); OA(6); OA(7); } z += 8; } word32 *const b16 = (word32 *)(bPtr+((bstart+16*32) & 31*32)); word32 *const b4 = (word32 *)(bPtr+((bstart+(32-4)*32) & 31*32)); bstart += 32; word32 *const b0 = (word32 *)(bPtr+((bstart) & 31*32)); word32 *const b25 = (word32 *)(bPtr+((bstart+(32-25)*32) & 31*32)); if (p) { US(0); US(1); US(2); US(3); US(4); US(5); US(6); US(7); } else { UL(0); UL(1); UL(2); UL(3); UL(4); UL(5); UL(6); UL(7); } GP(0); GP(1); GP(2); GP(3); GP(4); GP(5); GP(6); GP(7); GP(8); GP(9); GP(10); GP(11); GP(12); GP(13); GP(14); GP(15); GP(16); T(0,1); if (p) { TS1S(0); TS1S(1); TS1S(2); TS1S(3); TS1S(4); TS1S(5); TS1S(6); TS1S(7); p += 8; } else { TS1L(0); TS1L(1); TS1L(2); TS1L(3); TS1L(4); TS1L(5); TS1L(6); TS1L(7); } TS2(0); TS2(1); TS2(2); TS2(3); TS2(4); TS2(5); TS2(6); TS2(7); } m_state[17] = bstart; }
void World::loadScene(string filename) { // for as4, you can optionally hard-code the scene. For as5 and as6 it must be loaded from a file. if (_FINAL_PROJ) { vec4 eye(0.0, 0.0, 0, 1.0); vec4 LL(-1.0, -1.0, -3.0, 1.0); vec4 UL(-1.0, 1.0, -3.0, 1.0); vec4 LR(1.0, -1.0, -3.0, 1.0); vec4 UR(1.0, 1.0, -3.0, 1.0); _view = Viewport(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT, 1); _lights[LIGHT_DIRECTIONAL].push_back( Light(0, vec3(0.5,0.5,-0.5), LightInfo(LIGHT_DIRECTIONAL, vec3(.4, .8, 1.2)))); _lights[LIGHT_POINT].push_back( Light(vec3(0.0,0.0,-14.0), vec3(0.5,0.5,-0.5), LightInfo(LIGHT_POINT, vec3(1.39, 0.2, 0.2)))); _ambientLight = vec3(.5,.2,.2); /* _spheres.push_back(Sphere(vec4(-2.5,-1.5,-17.0,1.0), 2.0, MaterialInfo(vec3(.4, .5, .9), .1, .5, .5, 150, 1.0))); _spheres.push_back(Sphere(vec4(0.0,4.0,-25.0,1.0), 2.5, MaterialInfo(vec3(.9, .4, .5), .4, .2, .5, 20, 0.0))); _spheres.push_back(Sphere(vec4(1.5,-1.5,-10.0,1.0), 1.0, MaterialInfo(vec3(.5, .9, .4), .5, .5, .3, 4, .5))); */ _cubes.push_back(Cube(vec4(-3.5,-3.5,-15.0,1.0), 1.5, MaterialInfo(vec3(.4, .5, .9), .1, .5, .5, 150, 1.0))); _cubes.push_back(Cube(vec4(2.0, 1.5, -10,1.0), 1.5, MaterialInfo(vec3(.9, .4, .5), .4, .2, .5, 20, 0.0))); _cubes.push_back(Cube(vec4(-3.5,4,-120.0,1.0), 3, MaterialInfo(vec3(.5, .9, .4), .5, .5, .3, 4, .5))); _cubes.push_back(Cube(vec4(3.5,-4,-250.0,1.0), 3.5, MaterialInfo(vec3(.5, .9, .4), .5, .5, .3, 4, .5))); ksmMod = kspMod = 1.0; } else if (_ASSIGNMENT >= 5) { scene = new Scene(filename); loadInstance(scene->getRoot()); if (_ASSIGNMENT >= 6) _bb = new BoundingBox(_spheres, 0); } if (_ASSIGNMENT <= 4) { //vec4 eye(0.0, 0.0, 0, 1.0); //vec4 LL(-1.0, -1.0, -3.0, 1.0); //vec4 UL(-1.0, 1.0, -3.0, 1.0); //vec4 LR(1.0, -1.0, -3.0, 1.0); //vec4 UR(1.0, 1.0, -3.0, 1.0); //_view = Viewport(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT); //_lights[LIGHT_DIRECTIONAL].push_back( // Light(0, vec3(0.5,0.5,-0.5), // LightInfo(LIGHT_DIRECTIONAL, vec3(.4, .8, 1.2)))); //_lights[LIGHT_POINT].push_back( // Light(vec3(0.0,0.0,-14.0), vec3(0.5,0.5,-0.5), // LightInfo(LIGHT_POINT, vec3(1.39, 0.2, 0.2)))); //_ambientLight = vec3(.5,.2,.2); //_spheres.push_back(Sphere(vec4(-2.5,-1.5,-17.0,1.0), 2.0, // MaterialInfo(vec3(.4, .5, .9), // .1, .5, .5, 150, 1.0))); //_spheres.push_back(Sphere(vec4(0.0,4.0,-25.0,1.0), 2.5, // MaterialInfo(vec3(.9, .4, .5), // .4, .2, .5, 20, 0.0))); //_spheres.push_back(Sphere(vec4(1.5,-1.5,-10.0,1.0), 1.0, // MaterialInfo(vec3(.5, .9, .4), // .5, .5, .3, 4, .5))); //ksmMod = kspMod = 1.0; } }
void World::loadInstance(SceneInstance *si) { // Compute transform information. Should add a mat4 even if there is no transform. mat4 mTransform; if (!si->computeTransform(mTransform)) { mTransform = identity3D(); // if there is no transform, push an identity matrix. } if (!transformStack.empty() && transformStack.top() != identity3D()) { mat4 mPreviousTransform = transformStack.top(); mTransform = mPreviousTransform * mTransform; } transformStack.push(mTransform); SceneGroup *sg = si->getChild(); // Get camera info, if any. CameraInfo camInfo; if (sg->computeCamera(camInfo)) { vec4 eye(0.0, 0.0, 0.0, 1.0); double left = camInfo.sides[FRUS_LEFT]; double right = camInfo.sides[FRUS_RIGHT]; double top = camInfo.sides[FRUS_TOP]; double bottom = camInfo.sides[FRUS_BOTTOM]; double depth = -1*camInfo.sides[FRUS_NEAR]; vec4 LL(left, bottom, depth, 1.0); vec4 UL(left, top, depth, 1.0); vec4 LR(right, bottom, depth, 1.0); vec4 UR(right, top, depth, 1.0); eye = mTransform * eye; LL = mTransform * LL; UL = mTransform * UL; LR = mTransform * LR; UR = mTransform * UR; _view = Viewport(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT, camInfo.perspective); } // Compute light info, if any. LightInfo li; if (sg->computeLight(li)) { vec3 direction, position; switch (li.type) { case LIGHT_DIRECTIONAL: case LIGHT_POINT: case LIGHT_SPOT: direction = vec3(-1*mTransform[0][2],-1*mTransform[1][2],-1*mTransform[2][2]); position = mTransform * vec3(0.0); _lights[li.type].push_back(Light(position, direction, li)); break; case LIGHT_AMBIENT: _ambientLight = li.color; break; } } // Computes sphere info, if any. double radius; MaterialInfo matInfo; if (sg->computeSphere(radius, matInfo, 0)) { _spheres.push_back(Sphere(vec4(0.0), radius, matInfo, mTransform)); } // Recursively parse scene. for (int i = 0; i < sg->getChildCount(); i++) { loadInstance(sg->getChild(i)); } // Pops the transformation matrix of this SceneGroup. This function should have added this matrix at the beginning. transformStack.pop(); }
int main( int argc, char *argv[] ) { /* input */ if( argc != 5 ) { std::cerr<<"Usage: "<<argv[0]<<" [input map] [lon step] [lat step] [output file]"<<std::endl; exit(-1); } /* open input map */ std::ifstream fin(argv[1]); if( ! fin ) { std::cerr<<"Cannot read from file "<<argv[1]<<std::endl; exit(0); } /* read in point data */ std::vector<PointData> Map; for( std::string line; std::getline(fin, line); ){ PointData pdtmp( line.c_str() ); Map.push_back(pdtmp); } fin.close(); if( Map.size() <= 0 ) { std::cerr<<"Empty map!"<<std::endl; exit(0); } /* search for boundaries */ float lonstep = atof(argv[2]), latstep = atof(argv[3]); if( lonstep<=0 || latstep<=0 ) { std::cerr<<"positive number expected for lon/lat steps!"<<std::endl; exit(0); } PointData UL( Map.at(0) ); // upper-left corner PointData LR( Map.at(0) ); // lower-right corner for( int i=0; i<Map.size(); i++ ) { PointData &pdcurrent = Map.at(i); if( pdcurrent.IsWestOf(UL) ) UL.lon = pdcurrent.lon; else if( LR.IsWestOf(pdcurrent) ) LR.lon = pdcurrent.lon; if( pdcurrent.IsNorthOf(UL) ) UL.lat = pdcurrent.lat; else if( LR.IsNorthOf(pdcurrent) ) LR.lat = pdcurrent.lat; } std::cout<<"Upper-left: "<<UL<<std::endl; std::cout<<"Lower-right: "<<LR<<std::endl; /* compute data average */ float mean = 0.; for( int i=0; i<Map.size(); i++ ) mean += Map.at(i).dat; mean /= Map.size(); std::cout<<"data mean = "<<mean<<std::endl; /* data matrix */ int npts_lon = (int)floor( (LR.lon - UL.lon)/lonstep + 0.5 ) + 1; int npts_lat = (int)floor( (UL.lat - LR.lat)/latstep + 0.5 ) + 1; std::vector<float> DataM; DataM.resize( npts_lon * npts_lat ); std::fill( DataM.begin(), DataM.end(), mean); for( int i=0; i<Map.size(); i++ ) { PointData &pdcurrent = Map.at(i); int idxlon = (int)floor( (pdcurrent.lon - UL.lon) / lonstep + 0.5 ); int idxlat = (int)floor( (UL.lat - pdcurrent.lat) / latstep + 0.5 ); DataM.at( idxlon * npts_lat + idxlat ) = pdcurrent.dat; //std::cerr<<idxlat<<" "<<idxlon<<" "<<pdcurrent<<std::endl; } /* output in the format required by fm2dss */ std::ofstream fout(argv[4]); if( ! fout ) { std::cerr<<"Cannot write to file "<<argv[3]<<std::endl; exit(0); } fout << npts_lat-2 << " " << npts_lon-2 << std::endl; // leave the outer boundary as 'cushion nodes' fout << UL.lat-latstep << " " << UL.lon+lonstep << std::endl; // computational grid starts from the second point on each direction fout << latstep << " " << lonstep << std::endl; for( int i=0; i<DataM.size(); i++ ) fout << DataM.at(i) << std::endl; fout.close(); return 0; }
void Panama<B>::Iterate(unsigned int count, const word32 *p, word32 *z, const word32 *y) { unsigned int bstart = m_bstart; word32 *const a = m_state; #define c (a+17) #define b ((Stage *)(a+34)) // output #define OA(i) z[i] = ConditionalByteReverse(B::ToEnum(), a[i+9]) #define OX(i) z[i] = y[i] ^ ConditionalByteReverse(B::ToEnum(), a[i+9]) // buffer update #define US(i) {word32 t=b0[i]; b0[i]=ConditionalByteReverse(B::ToEnum(), p[i])^t; b25[(i+6)%8]^=t;} #define UL(i) {word32 t=b0[i]; b0[i]=a[i+1]^t; b25[(i+6)%8]^=t;} // gamma and pi #define GP(i) c[5*i%17] = rotlFixed(a[i] ^ (a[(i+1)%17] | ~a[(i+2)%17]), ((5*i%17)*((5*i%17)+1)/2)%32) // theta and sigma #define T(i,x) a[i] = c[i] ^ c[(i+1)%17] ^ c[(i+4)%17] ^ x #define TS1S(i) T(i+1, ConditionalByteReverse(B::ToEnum(), p[i])) #define TS1L(i) T(i+1, b4[i]) #define TS2(i) T(i+9, b16[i]) while (count--) { if (z) { if (y) { OX(0); OX(1); OX(2); OX(3); OX(4); OX(5); OX(6); OX(7); y += 8; } else { OA(0); OA(1); OA(2); OA(3); OA(4); OA(5); OA(6); OA(7); } z += 8; } word32 *const b16 = b[(bstart+16) % STAGES]; word32 *const b4 = b[(bstart+4) % STAGES]; bstart = (bstart + STAGES - 1) % STAGES; word32 *const b0 = b[bstart]; word32 *const b25 = b[(bstart+25) % STAGES]; if (p) { US(0); US(1); US(2); US(3); US(4); US(5); US(6); US(7); } else { UL(0); UL(1); UL(2); UL(3); UL(4); UL(5); UL(6); UL(7); } GP(0); GP(1); GP(2); GP(3); GP(4); GP(5); GP(6); GP(7); GP(8); GP(9); GP(10); GP(11); GP(12); GP(13); GP(14); GP(15); GP(16); T(0,1); if (p) { TS1S(0); TS1S(1); TS1S(2); TS1S(3); TS1S(4); TS1S(5); TS1S(6); TS1S(7); p += 8; } else { TS1L(0); TS1L(1); TS1L(2); TS1L(3); TS1L(4); TS1L(5); TS1L(6); TS1L(7); } TS2(0); TS2(1); TS2(2); TS2(3); TS2(4); TS2(5); TS2(6); TS2(7); } m_bstart = bstart; }
/* This most closely resembles the actual brk syscall (the C spec's versions * interface to the brk syscall differently). */ static void *mbrk(void *new_brk) { return (void*)syscall1(__NR_brk, UL(new_brk)); }
JNIEXPORT jint JNICALL Java_jxtn_core_unix_NativeMMap_munmap(JNIEnv *env, jclass thisObj, jlong addr, jlong length) { return ERR(munmap((void*) addr, UL(length))); }
void UNavMeshRenderingComponent::GatherData(struct FNavMeshSceneProxyData* CurrentData) const { #if WITH_RECAST const ARecastNavMesh* NavMesh = Cast<ARecastNavMesh>(GetOwner()); CurrentData->Reset(); CurrentData->bEnableDrawing = NavMesh->bEnableDrawing; CurrentData->bNeedsNewData = false; if (CurrentData && NavMesh && NavMesh->bEnableDrawing) { FHitProxyId HitProxyId = FHitProxyId(); CurrentData->bDrawPathCollidingGeometry = NavMesh->bDrawPathCollidingGeometry; CurrentData->NavMeshDrawOffset.Z = NavMesh->DrawOffset; CurrentData->NavMeshGeometry.bGatherPolyEdges = NavMesh->bDrawPolyEdges; CurrentData->NavMeshGeometry.bGatherNavMeshEdges = NavMesh->bDrawNavMeshEdges; const FNavDataConfig& NavConfig = NavMesh->GetConfig(); CurrentData->NavMeshColors[RECAST_DEFAULT_AREA] = NavConfig.Color.DWColor() > 0 ? NavConfig.Color : NavMeshRenderColor_RecastMesh; for (uint8 i = 0; i < RECAST_DEFAULT_AREA; ++i) { CurrentData->NavMeshColors[i] = NavMesh->GetAreaIDColor(i); } // just a little trick to make sure navmeshes with different sized are not drawn with same offset CurrentData->NavMeshDrawOffset.Z += NavMesh->GetConfig().AgentRadius / 10.f; NavMesh->BeginBatchQuery(); if (NavMesh->bDrawOctree) { const UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(GetWorld()); const FNavigationOctree* NavOctree = NavSys ? NavSys->GetNavOctree() : NULL; if (NavOctree) { for (FNavigationOctree::TConstIterator<> NodeIt(*NavOctree); NodeIt.HasPendingNodes(); NodeIt.Advance()) { const FNavigationOctree::FNode& CurrentNode = NodeIt.GetCurrentNode(); const FOctreeNodeContext& CorrentContext = NodeIt.GetCurrentContext(); CurrentData->OctreeBounds.Add(CorrentContext.Bounds); FOREACH_OCTREE_CHILD_NODE(ChildRef) { if (CurrentNode.HasChild(ChildRef)) { NodeIt.PushChild(ChildRef); } } } } } NavMesh->GetDebugGeometry(CurrentData->NavMeshGeometry); const TArray<FVector>& MeshVerts = CurrentData->NavMeshGeometry.MeshVerts; // @fixme, this is going to double up on lots of interior lines if (NavMesh->bDrawTriangleEdges) { for (int32 AreaIdx = 0; AreaIdx < RECAST_MAX_AREAS; ++AreaIdx) { const TArray<int32>& MeshIndices = CurrentData->NavMeshGeometry.AreaIndices[AreaIdx]; for (int32 Idx=0; Idx<MeshIndices.Num(); Idx += 3) { CurrentData->ThickLineItems.Add(FNavMeshSceneProxyData::FDebugThickLine(MeshVerts[MeshIndices[Idx + 0]] + CurrentData->NavMeshDrawOffset, MeshVerts[MeshIndices[Idx + 1]] + CurrentData->NavMeshDrawOffset, NavMeshRenderColor_Recast_TriangleEdges, DefaultEdges_LineThickness)); CurrentData->ThickLineItems.Add(FNavMeshSceneProxyData::FDebugThickLine(MeshVerts[MeshIndices[Idx + 1]] + CurrentData->NavMeshDrawOffset, MeshVerts[MeshIndices[Idx + 2]] + CurrentData->NavMeshDrawOffset, NavMeshRenderColor_Recast_TriangleEdges, DefaultEdges_LineThickness)); CurrentData->ThickLineItems.Add(FNavMeshSceneProxyData::FDebugThickLine(MeshVerts[MeshIndices[Idx + 2]] + CurrentData->NavMeshDrawOffset, MeshVerts[MeshIndices[Idx + 0]] + CurrentData->NavMeshDrawOffset, NavMeshRenderColor_Recast_TriangleEdges, DefaultEdges_LineThickness)); } } } // make lines for tile edges if (NavMesh->bDrawPolyEdges) { const TArray<FVector>& TileEdgeVerts = CurrentData->NavMeshGeometry.PolyEdges; for (int32 Idx=0; Idx < TileEdgeVerts.Num(); Idx += 2) { CurrentData->TileEdgeLines.Add( FDebugRenderSceneProxy::FDebugLine(TileEdgeVerts[Idx] + CurrentData->NavMeshDrawOffset, TileEdgeVerts[Idx+1] + CurrentData->NavMeshDrawOffset, NavMeshRenderColor_Recast_TileEdges)); } } // make lines for navmesh edges if (NavMesh->bDrawNavMeshEdges) { const FColor EdgesColor = DarkenColor(CurrentData->NavMeshColors[RECAST_DEFAULT_AREA]); const TArray<FVector>& NavMeshEdgeVerts = CurrentData->NavMeshGeometry.NavMeshEdges; for (int32 Idx=0; Idx < NavMeshEdgeVerts.Num(); Idx += 2) { CurrentData->NavMeshEdgeLines.Add( FDebugRenderSceneProxy::FDebugLine(NavMeshEdgeVerts[Idx] + CurrentData->NavMeshDrawOffset, NavMeshEdgeVerts[Idx+1] + CurrentData->NavMeshDrawOffset, EdgesColor)); } } // offset all navigation-link positions if (!NavMesh->bDrawClusters) { for (int32 OffMeshLineIndex = 0; OffMeshLineIndex < CurrentData->NavMeshGeometry.OffMeshLinks.Num(); ++OffMeshLineIndex) { FRecastDebugGeometry::FOffMeshLink& Link = CurrentData->NavMeshGeometry.OffMeshLinks[OffMeshLineIndex]; const bool bLinkValid = (Link.ValidEnds & FRecastDebugGeometry::OMLE_Left) && (Link.ValidEnds & FRecastDebugGeometry::OMLE_Right); if (NavMesh->bDrawFailedNavLinks || (NavMesh->bDrawNavLinks && bLinkValid)) { const FVector V0 = Link.Left + CurrentData->NavMeshDrawOffset; const FVector V1 = Link.Right + CurrentData->NavMeshDrawOffset; const FColor LinkColor = ((Link.Direction && Link.ValidEnds) || (Link.ValidEnds & FRecastDebugGeometry::OMLE_Left)) ? DarkenColor(CurrentData->NavMeshColors[Link.AreaID]) : NavMeshRenderColor_OffMeshConnectionInvalid; CacheArc(CurrentData->NavLinkLines, V0, V1, 0.4f, 4, LinkColor, LinkLines_LineThickness); const FVector VOffset(0, 0, FVector::Dist(V0, V1) * 1.333f); CacheArrowHead(CurrentData->NavLinkLines, V1, V0+VOffset, 30.f, LinkColor, LinkLines_LineThickness); if (Link.Direction) { CacheArrowHead(CurrentData->NavLinkLines, V0, V1+VOffset, 30.f, LinkColor, LinkLines_LineThickness); } // if the connection as a whole is valid check if there are any of ends is invalid if (LinkColor != NavMeshRenderColor_OffMeshConnectionInvalid) { if (Link.Direction && (Link.ValidEnds & FRecastDebugGeometry::OMLE_Left) == 0) { // left end invalid - mark it DrawWireCylinder(CurrentData->NavLinkLines, V0, FVector(1,0,0), FVector(0,1,0), FVector(0,0,1), NavMeshRenderColor_OffMeshConnectionInvalid, Link.Radius, NavMesh->AgentMaxStepHeight, 16, 0, DefaultEdges_LineThickness); } if ((Link.ValidEnds & FRecastDebugGeometry::OMLE_Right) == 0) { DrawWireCylinder(CurrentData->NavLinkLines, V1, FVector(1,0,0), FVector(0,1,0), FVector(0,0,1), NavMeshRenderColor_OffMeshConnectionInvalid, Link.Radius, NavMesh->AgentMaxStepHeight, 16, 0, DefaultEdges_LineThickness); } } } } } if (NavMesh->bDrawTileLabels || NavMesh->bDrawPolygonLabels || NavMesh->bDrawDefaultPolygonCost || NavMesh->bDrawTileBounds) { // calculate appropriate points for displaying debug labels const int32 TilesCount = NavMesh->GetNavMeshTilesCount(); CurrentData->DebugLabels.Reserve(TilesCount); for (int32 TileIndex = 0; TileIndex < TilesCount; ++TileIndex) { int32 X, Y, Layer; if (NavMesh->GetNavMeshTileXY(TileIndex, X, Y, Layer)) { const FBox TileBoundingBox = NavMesh->GetNavMeshTileBounds(TileIndex); FVector TileLabelLocation = TileBoundingBox.GetCenter(); TileLabelLocation.Z = TileBoundingBox.Max.Z; FNavLocation NavLocation(TileLabelLocation); if (!NavMesh->ProjectPoint(TileLabelLocation, NavLocation, FVector(NavMesh->TileSizeUU/100, NavMesh->TileSizeUU/100, TileBoundingBox.Max.Z-TileBoundingBox.Min.Z))) { NavMesh->ProjectPoint(TileLabelLocation, NavLocation, FVector(NavMesh->TileSizeUU/2, NavMesh->TileSizeUU/2, TileBoundingBox.Max.Z-TileBoundingBox.Min.Z)); } if (NavMesh->bDrawTileLabels) { CurrentData->DebugLabels.Add(FNavMeshSceneProxyData::FDebugText( /*Location*/NavLocation.Location + CurrentData->NavMeshDrawOffset , /*Text*/FString::Printf(TEXT("(%d,%d:%d)"), X, Y, Layer) )); } if (NavMesh->bDrawPolygonLabels || NavMesh->bDrawDefaultPolygonCost) { TArray<FNavPoly> Polys; NavMesh->GetPolysInTile(TileIndex, Polys); if (NavMesh->bDrawDefaultPolygonCost) { float DefaultCosts[RECAST_MAX_AREAS]; float FixedCosts[RECAST_MAX_AREAS]; NavMesh->GetDefaultQueryFilter()->GetAllAreaCosts(DefaultCosts, FixedCosts, RECAST_MAX_AREAS); for(int k = 0; k < Polys.Num(); ++k) { uint32 AreaID = NavMesh->GetPolyAreaID(Polys[k].Ref); CurrentData->DebugLabels.Add(FNavMeshSceneProxyData::FDebugText( /*Location*/Polys[k].Center + CurrentData->NavMeshDrawOffset , /*Text*/FString::Printf(TEXT("\\%.3f; %.3f\\"), DefaultCosts[AreaID], FixedCosts[AreaID]) )); } } else { for(int k = 0; k < Polys.Num(); ++k) { uint32 NavPolyIndex = 0; uint32 NavTileIndex = 0; NavMesh->GetPolyTileIndex(Polys[k].Ref, NavPolyIndex, NavTileIndex); CurrentData->DebugLabels.Add(FNavMeshSceneProxyData::FDebugText( /*Location*/Polys[k].Center + CurrentData->NavMeshDrawOffset , /*Text*/FString::Printf(TEXT("[%X:%X]"), NavTileIndex, NavPolyIndex) )); } } } if (NavMesh->bDrawTileBounds) { FBox TileBox = NavMesh->GetNavMeshTileBounds(TileIndex); float DrawZ = (TileBox.Min.Z + TileBox.Max.Z) * 0.5f; // @hack average FVector LL(TileBox.Min.X, TileBox.Min.Y, DrawZ); FVector UR(TileBox.Max.X, TileBox.Max.Y, DrawZ); FVector UL(LL.X, UR.Y, DrawZ); FVector LR(UR.X, LL.Y, DrawZ); CurrentData->ThickLineItems.Add(FNavMeshSceneProxyData::FDebugThickLine(LL, UL, NavMeshRenderColor_TileBounds, DefaultEdges_LineThickness)); CurrentData->ThickLineItems.Add(FNavMeshSceneProxyData::FDebugThickLine(UL, UR, NavMeshRenderColor_TileBounds, DefaultEdges_LineThickness)); CurrentData->ThickLineItems.Add(FNavMeshSceneProxyData::FDebugThickLine(UR, LR, NavMeshRenderColor_TileBounds, DefaultEdges_LineThickness)); CurrentData->ThickLineItems.Add(FNavMeshSceneProxyData::FDebugThickLine(LR, LL, NavMeshRenderColor_TileBounds, DefaultEdges_LineThickness)); } } } } CurrentData->bSkipDistanceCheck = GIsEditor && (GEngine->GetDebugLocalPlayer() == NULL); CurrentData->bDrawClusters = NavMesh->bDrawClusters; NavMesh->FinishBatchQuery(); // Draw Mesh if (NavMesh->bDrawClusters) { for (int32 Idx = 0; Idx < CurrentData->NavMeshGeometry.Clusters.Num(); ++Idx) { const TArray<int32>& MeshIndices = CurrentData->NavMeshGeometry.Clusters[Idx].MeshIndices; if (MeshIndices.Num() == 0) { continue; } FNavMeshSceneProxyData::FDebugMeshData DebugMeshData; DebugMeshData.ClusterColor = GetClusterColor(Idx); for (int32 VertIdx=0; VertIdx < MeshVerts.Num(); ++VertIdx) { AddVertexHelper(DebugMeshData, MeshVerts[VertIdx] + CurrentData->NavMeshDrawOffset, DebugMeshData.ClusterColor); } for (int32 TriIdx=0; TriIdx < MeshIndices.Num(); TriIdx+=3) { AddTriangleHelper(DebugMeshData, MeshIndices[TriIdx], MeshIndices[TriIdx+1], MeshIndices[TriIdx+2]); } CurrentData->MeshBuilders.Add(DebugMeshData); } } else if (NavMesh->bDrawNavMesh) { for (int32 AreaType = 0; AreaType < RECAST_MAX_AREAS; ++AreaType) { const TArray<int32>& MeshIndices = CurrentData->NavMeshGeometry.AreaIndices[AreaType]; if (MeshIndices.Num() == 0) { continue; } FNavMeshSceneProxyData::FDebugMeshData DebugMeshData; for (int32 VertIdx=0; VertIdx < MeshVerts.Num(); ++VertIdx) { AddVertexHelper(DebugMeshData, MeshVerts[VertIdx] + CurrentData->NavMeshDrawOffset, CurrentData->NavMeshColors[AreaType]); } for (int32 TriIdx=0; TriIdx < MeshIndices.Num(); TriIdx+=3) { AddTriangleHelper(DebugMeshData, MeshIndices[TriIdx], MeshIndices[TriIdx+1], MeshIndices[TriIdx+2]); } DebugMeshData.ClusterColor = CurrentData->NavMeshColors[AreaType]; CurrentData->MeshBuilders.Add(DebugMeshData); } } if (NavMesh->bDrawPathCollidingGeometry) { // draw all geometry gathered in navoctree const FNavigationOctree* NavOctree = NavMesh->GetWorld()->GetNavigationSystem()->GetNavOctree(); TArray<FVector> PathCollidingGeomVerts; TArray <int32> PathCollidingGeomIndices; for (FNavigationOctree::TConstIterator<> It(*NavOctree); It.HasPendingNodes(); It.Advance()) { const FNavigationOctree::FNode& Node = It.GetCurrentNode(); for (FNavigationOctree::ElementConstIt ElementIt(Node.GetElementIt()); ElementIt; ElementIt++) { const FNavigationOctreeElement& Element = *ElementIt; if (Element.ShouldUseGeometry(&NavMesh->NavDataConfig) && Element.Data.CollisionData.Num()) { const FRecastGeometryCache CachedGeometry(Element.Data.CollisionData.GetData()); AppendGeometry(PathCollidingGeomVerts, PathCollidingGeomIndices, CachedGeometry.Verts, CachedGeometry.Header.NumVerts, CachedGeometry.Indices, CachedGeometry.Header.NumFaces); } } FOREACH_OCTREE_CHILD_NODE(ChildRef) { if (Node.HasChild(ChildRef)) { It.PushChild(ChildRef); } } } CurrentData->PathCollidingGeomIndices = PathCollidingGeomIndices; for (const auto& Vertex : PathCollidingGeomVerts) { CurrentData->PathCollidingGeomVerts.Add(FDynamicMeshVertex(Vertex)); } } if (CurrentData->NavMeshGeometry.BuiltMeshIndices.Num() > 0) { FNavMeshSceneProxyData::FDebugMeshData DebugMeshData; for (int32 VertIdx=0; VertIdx < MeshVerts.Num(); ++VertIdx) { AddVertexHelper(DebugMeshData, MeshVerts[VertIdx] + CurrentData->NavMeshDrawOffset, NavMeshRenderColor_RecastTileBeingRebuilt); } DebugMeshData.Indices.Append(CurrentData->NavMeshGeometry.BuiltMeshIndices); DebugMeshData.ClusterColor = NavMeshRenderColor_RecastTileBeingRebuilt; CurrentData->MeshBuilders.Add(DebugMeshData); // updates should be requested by FRecastNavMeshGenerator::TickAsyncBuild after tiles were refreshed } if (NavMesh->bDrawClusters) { for (int i = 0; i < CurrentData->NavMeshGeometry.ClusterLinks.Num(); i++) { const FRecastDebugGeometry::FClusterLink& CLink = CurrentData->NavMeshGeometry.ClusterLinks[i]; const FVector V0 = CLink.FromCluster + CurrentData->NavMeshDrawOffset; const FVector V1 = CLink.ToCluster + CurrentData->NavMeshDrawOffset + FVector(0,0,20.0f); CacheArc(CurrentData->ClusterLinkLines, V0, V1, 0.4f, 4, FColor::Black, ClusterLinkLines_LineThickness); const FVector VOffset(0, 0, FVector::Dist(V0, V1) * 1.333f); CacheArrowHead(CurrentData->ClusterLinkLines, V1, V0+VOffset, 30.f, FColor::Black, ClusterLinkLines_LineThickness); } } // cache segment links if (NavMesh->bDrawNavLinks) { for (int32 iArea = 0; iArea < RECAST_MAX_AREAS; iArea++) { const TArray<int32>& Indices = CurrentData->NavMeshGeometry.OffMeshSegmentAreas[iArea]; FNavMeshSceneProxyData::FDebugMeshData DebugMeshData; int32 VertBase = 0; for (int32 i = 0; i < Indices.Num(); i++) { FRecastDebugGeometry::FOffMeshSegment& SegInfo = CurrentData->NavMeshGeometry.OffMeshSegments[Indices[i]]; const FVector A0 = SegInfo.LeftStart + CurrentData->NavMeshDrawOffset; const FVector A1 = SegInfo.LeftEnd + CurrentData->NavMeshDrawOffset; const FVector B0 = SegInfo.RightStart + CurrentData->NavMeshDrawOffset; const FVector B1 = SegInfo.RightEnd + CurrentData->NavMeshDrawOffset; const FVector Edge0 = B0 - A0; const FVector Edge1 = B1 - A1; const float Len0 = Edge0.Size(); const float Len1 = Edge1.Size(); const FColor SegColor = DarkenColor(CurrentData->NavMeshColors[SegInfo.AreaID]); const FColor ColA = (SegInfo.ValidEnds & FRecastDebugGeometry::OMLE_Left) ? FColor::White : FColor::Black; const FColor ColB = (SegInfo.ValidEnds & FRecastDebugGeometry::OMLE_Right) ? FColor::White : FColor::Black; const int32 NumArcPoints = 8; const float ArcPtsScale = 1.0f / NumArcPoints; FVector Prev0 = EvalArc(A0, Edge0, Len0*0.25f, 0); FVector Prev1 = EvalArc(A1, Edge1, Len1*0.25f, 0); AddVertexHelper(DebugMeshData, Prev0, ColA); AddVertexHelper(DebugMeshData, Prev1, ColA); for (int32 j = 1; j <= NumArcPoints; j++) { const float u = j * ArcPtsScale; FVector Pt0 = EvalArc(A0, Edge0, Len0*0.25f, u); FVector Pt1 = EvalArc(A1, Edge1, Len1*0.25f, u); AddVertexHelper(DebugMeshData, Pt0, (j == NumArcPoints) ? ColB : FColor::White); AddVertexHelper(DebugMeshData, Pt1, (j == NumArcPoints) ? ColB : FColor::White); AddTriangleHelper(DebugMeshData, VertBase+0, VertBase+2, VertBase+1); AddTriangleHelper(DebugMeshData, VertBase+2, VertBase+3, VertBase+1); AddTriangleHelper(DebugMeshData, VertBase+0, VertBase+1, VertBase+2); AddTriangleHelper(DebugMeshData, VertBase+2, VertBase+1, VertBase+3); VertBase += 2; Prev0 = Pt0; Prev1 = Pt1; } VertBase += 2; DebugMeshData.ClusterColor = SegColor; } if (DebugMeshData.Indices.Num()) { CurrentData->MeshBuilders.Add(DebugMeshData); } } } CurrentData->NavMeshGeometry.PolyEdges.Empty(); CurrentData->NavMeshGeometry.NavMeshEdges.Empty(); }
void DumpArenaStats(JSGCArenaStats *stp, FILE *fp) { size_t sumArenas = 0, sumTotalArenas = 0, sumThings =0, sumMaxThings = 0; size_t sumThingSize = 0, sumTotalThingSize = 0, sumArenaCapacity = 0; size_t sumTotalArenaCapacity = 0, sumAlloc = 0, sumLocalAlloc = 0; for (int i = 0; i < (int) FINALIZE_LIMIT; i++) { JSGCArenaStats *st = &stp[i]; if (st->maxarenas == 0) continue; size_t thingSize = 0, thingsPerArena = 0; GetSizeAndThingsPerArena(i, thingSize, thingsPerArena); fprintf(fp, "%s arenas (thing size %lu, %lu things per arena):\n", GC_ARENA_NAMES[i], UL(thingSize), UL(thingsPerArena)); fprintf(fp, " arenas before GC: %lu\n", UL(st->narenas)); fprintf(fp, " arenas after GC: %lu (%.1f%%)\n", UL(st->livearenas), PERCENT(st->livearenas, st->narenas)); fprintf(fp, " max arenas: %lu\n", UL(st->maxarenas)); fprintf(fp, " things: %lu\n", UL(st->nthings)); fprintf(fp, " GC cell utilization: %.1f%%\n", PERCENT(st->nthings, thingsPerArena * st->narenas)); fprintf(fp, " average cell utilization: %.1f%%\n", PERCENT(st->totalthings, thingsPerArena * st->totalarenas)); fprintf(fp, " max things: %lu\n", UL(st->maxthings)); fprintf(fp, " alloc attempts: %lu\n", UL(st->alloc)); fprintf(fp, " alloc without locks: %lu (%.1f%%)\n", UL(st->localalloc), PERCENT(st->localalloc, st->alloc)); sumArenas += st->narenas; sumTotalArenas += st->totalarenas; sumThings += st->nthings; sumMaxThings += st->maxthings; sumThingSize += thingSize * st->nthings; sumTotalThingSize += size_t(thingSize * st->totalthings); sumArenaCapacity += thingSize * thingsPerArena * st->narenas; sumTotalArenaCapacity += thingSize * thingsPerArena * st->totalarenas; sumAlloc += st->alloc; sumLocalAlloc += st->localalloc; putc('\n', fp); } fputs("Never used arenas:\n", fp); for (int i = 0; i < (int) FINALIZE_LIMIT; i++) { JSGCArenaStats *st = &stp[i]; if (st->maxarenas != 0) continue; fprintf(fp, "%s\n", GC_ARENA_NAMES[i]); } fprintf(fp, "\nTOTAL STATS:\n"); fprintf(fp, " total GC arenas: %lu\n", UL(sumArenas)); fprintf(fp, " total GC things: %lu\n", UL(sumThings)); fprintf(fp, " max total GC things: %lu\n", UL(sumMaxThings)); fprintf(fp, " GC cell utilization: %.1f%%\n", PERCENT(sumThingSize, sumArenaCapacity)); fprintf(fp, " average cell utilization: %.1f%%\n", PERCENT(sumTotalThingSize, sumTotalArenaCapacity)); fprintf(fp, " alloc attempts: %lu\n", UL(sumAlloc)); fprintf(fp, " alloc without locks: %lu (%.1f%%)\n", UL(sumLocalAlloc), PERCENT(sumLocalAlloc, sumAlloc)); }