BOOL CDirTreeCtrl::DisplayProject(LPCTSTR proName, LPCTSTR proPath) { HTREEITEM root; SetItemHeight(20); SetTextColor(RGB(0X0,0X0,0XFF)); DeleteAllItems(); SetDirTreeStyle(); if ( !AttachImgList() ) return FALSE; m_RootName = proName; m_RootPath = proPath; root = InsertItem(proName); BuildTree(root, proPath); Expand( root, TVE_EXPAND ); return TRUE; }
int Jos2( int People, int Passes ) { OrderedSearchTree<int> T; BuildTree( T, 1, People ); int Rank = 1; while( People > 1 ) { if( ( Rank = ( Rank + Passes ) % People ) == 0 ) Rank = People; T.Remove( T.FindKth( Rank ) ); People--; } return T.FindKth( 1 ); }
void DecodeFile(FILE *infile,FILE *outfile){ int ch; huffman_node_t *huffmanLeaves[CHARCOUNT], *htree, *currentnode; huffman_code_t *huffmanCodes[CHARCOUNT]; buffered_bit_file_t *bufferedInFile; buffered_bit_file_t *bufferedOutFile=CreateBitOutFile(outfile); for(ch=0;ch<CHARCOUNT;ch++){ huffmanLeaves[ch]=CreateNode(ch); } huffmanLeaves[EOF_CHAR]->value=EOF_CHAR; huffmanLeaves[EOF_CHAR]->count=1; ReadFrequencyArray(infile, huffmanLeaves); htree=BuildTree(huffmanLeaves, CHARCOUNT); bufferedInFile=CreateBitInFile(infile); if(htree != huffmanLeaves[EOF_CHAR]){ for(int i=0;i<CHARCOUNT;i++){ huffmanCodes[i]=CreateCode(); } GenerateCodeList(huffmanCodes, htree); currentnode=htree; for(;;){ int bit=BitFileGetBit(bufferedInFile); if(bit != 0) currentnode=currentnode->left; else currentnode=currentnode->right; if(currentnode->value != COMBINE_NODE){ if(currentnode->value == EOF_CHAR){ BitFileFlush(bufferedOutFile); break; } BitFilePutChar(bufferedOutFile, currentnode->value); currentnode=htree; } } for(int i=0;i<CHARCOUNT;i++) free(huffmanCodes[i]); } FreeHuffmanTree(htree); free(bufferedInFile); free(bufferedOutFile); }
void EncodeFile(FILE *infile,FILE *outfile){ int ch; huffman_node_t *huffmanLeaves[CHARCOUNT], *htree; buffered_bit_file_t *bufferedOutFile=CreateBitOutFile(outfile); huffman_code_t *huffmanCodes[CHARCOUNT]; unsigned char *buffer; size_t buffersize=1000000, readcount; buffer=(unsigned char*)malloc(buffersize*sizeof(unsigned char)); for(ch=0;ch<CHARCOUNT;ch++){ huffmanLeaves[ch]=CreateNode(ch); } while ((readcount=fread(buffer, sizeof(unsigned char), buffersize, infile)) == buffersize) { for(int i=0;i<buffersize;i++) ++huffmanLeaves[buffer[i]]->count; } for(int i=0;i<readcount;i++) ++huffmanLeaves[buffer[i]]->count; huffmanLeaves[EOF_CHAR]->value=EOF_CHAR; huffmanLeaves[EOF_CHAR]->count=1; WriteFrequencyArray(bufferedOutFile, huffmanLeaves, CHARCOUNT); htree=BuildTree(huffmanLeaves, CHARCOUNT); for(int i=0;i<CHARCOUNT;i++){ huffmanCodes[i]=CreateCode(); } GenerateCodeList(huffmanCodes, htree); rewind(infile); while ((readcount=fread(buffer, sizeof(unsigned char), buffersize, infile)) == buffersize) { for(int i=0;i<buffersize;i++) BitFileWriteCode(bufferedOutFile, huffmanCodes[buffer[i]]); } for(int i=0;i<readcount;i++) BitFileWriteCode(bufferedOutFile, huffmanCodes[buffer[i]]); BitFileWriteCode(bufferedOutFile, huffmanCodes[EOF_CHAR]); BitFileFlush(bufferedOutFile); FreeHuffmanTree(htree); free(bufferedOutFile); free(buffer); for(int i=0;i<CHARCOUNT;i++) free(huffmanCodes[i]); }
void KDTree::Build() { // Compute bounds for kd-tree construction vector<BBox> primBounds; primBounds.reserve(m_uiNumPrimitives); primitives.reserve(m_uiNumPrimitives); for (unsigned int i = 0; i < m_uiNumPrimitives; ++i) { Point Vertex1(m_pPrimitives[i]->GetVertex(0)->Pos); Point Vertex2(m_pPrimitives[i]->GetVertex(1)->Pos); Point Vertex3(m_pPrimitives[i]->GetVertex(2)->Pos); BBox bbox = Union(BBox(Vertex1, Vertex2),Vertex3); bounds = Union(bounds, bbox); primBounds.push_back(bbox); primitives.push_back(KDTreePrimitiveInfo(i, bbox)); } // Allocate working memory for kd-tree construction BoundEdge *edges[3]; for (int i = 0; i < 3; ++i) edges[i] = new BoundEdge[2*primitives.size()]; uint32_t *prims0 = new uint32_t[primitives.size()]; uint32_t *prims1 = new uint32_t[(maxDepth+1) * primitives.size()]; // Initialize _primNums_ for kd-tree construction uint32_t *primNums = new uint32_t[primitives.size()]; for (uint32_t i = 0; i < primitives.size(); ++i) primNums[i] = i; // Start recursive construction of kd-tree BuildTree(0, bounds, primBounds, primNums, primitives.size(), maxDepth, edges, prims0, prims1); // Free working memory for kd-tree construction delete[] primNums; for (int i = 0; i < 3; ++i) delete[] edges[i]; delete[] prims0; delete[] prims1; }
void CSiteGroupsTree::OnSiteGroupMergeWithGroup() { ASSERT(m_actionGroup); MergeChooseGroupHook hook(*m_actionGroup); CChooseGroupDlg dlg(WebWatch::Store::Instance().GetRootGroup(), &hook, GetParent()); if (dlg.DoModal() != IDOK) return; WebWatch::SiteItemGroup *group = dlg.GetChosenGroup(); if (group == 0) return; group->MergeGroup(*m_actionGroup); BuildTree(); // The action group no longer exists, it was merged onto 'group' SelectGroup(*group, true); }
// BuildTreeFromMapPolys static void ProcessModel() { bsptree_t *tree; Message("Processing model...\n"); tree = BuildTree(); MarkEmptyLeafs(tree); BuildPortals(tree); BuildAreas(tree); #if 1 extern void BuildAreaModels(bsptree_t *tree); BuildAreaModels(tree); #endif WriteBinary(tree); }
void TileMap::BuildTree(TileNode &parentNode, unsigned int level) { level++; if(level == numLevels) return; for(unsigned int i=0; i<4; i++) { parentNode.childIndices[i] = ++nodeIndex; assert(nodeIndex < numNodes); TileNode ¤tNode = tileNodeList[parentNode.childIndices[i]]; unsigned int denominator = 1 << level; const float size = 1.0f/((float)denominator); Vector2 offsets[4] = { Vector2(-size, size), Vector2(-size, -size), Vector2(size, -size), Vector2(size, size) }; currentNode.position = parentNode.position+offsets[i]; currentNode.level = level; currentNode.minLevel = 0; BuildTree(currentNode, level); } }
void CSiteGroupsTree::OnLButtonUp(UINT flags, CPoint point) { CTreeCtrl::OnLButtonUp(flags, point); if (m_isDragging == false) return; // User is dropping an item m_isDragging = false; CImageList::DragLeave(this); CImageList::EndDrag(); ReleaseCapture(); m_dragImageList.reset(0); SelectDropTarget(0); // Determine whether dropping the item has an effect // Here we allow a group to be dropped on itself without any effect and without any // error message if ((m_draggedItem == m_droppedItem) || (m_droppedItem == 0)) return; if (IsDroppableItem(m_draggedItem) == false) return; WebWatch::SiteItemGroup & draggedGroup = GetGroupFromItem(m_draggedItem); WebWatch::SiteItemGroup & droppedGroup = GetGroupFromItem(m_droppedItem); if (WebWatch::IsChildOf(draggedGroup, droppedGroup) == true) { GetParent()->MessageBox("Cannot move a group into one of its child groups", "Error", MB_OK | MB_ICONERROR); return; } // Do the actual moving droppedGroup.MoveGroup(draggedGroup); BuildTree(); SelectGroup(draggedGroup, true); }
bool LoserTree::PlayNextGame() { if (!is_build_) { is_build_ = true; return BuildTree(); } if (inner_node_.empty()) { return false; } int winner_slot = inner_node_[0]; if (winner_slot == LOSER_TREE_SENTINEL || players_[winner_slot]->Value() == LOSER_TREE_MAX_VALUE) { return false; } players_[winner_slot]->Next(); BuildImpl(winner_slot); return players_[inner_node_[0]]->Value() != LOSER_TREE_MAX_VALUE; }
void PHPFileLayoutTree::Construct() { // Sanity if(!m_editor || !m_manager) return; wxString text = m_editor->GetTextRange(0, m_editor->GetLength()); PHPSourceFile source(text); source.SetParseFunctionBody(false); source.SetFilename(m_editor->GetFileName()); source.Parse(); DeleteAllItems(); wxTreeItemId root = AddRoot(wxT("Root")); wxImageList* images = new wxImageList(16, 16, true); images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/globals"))); // 0 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_private"))); // 1 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_protected"))); // 2 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_public"))); // 3 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_private"))); // 4 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_protected"))); // 5 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_public"))); // 6 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/namespace"))); // 7 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/class"))); // 8 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/enumerator"))); // 9 AssignImageList(images); // Build the tree view BuildTree(root, source.Namespace()); if(HasChildren(GetRootItem())) { wxTreeItemIdValue cookie; wxTreeItemId child = GetFirstChild(GetRootItem(), cookie); if(child.IsOk()) { SelectItem(child); ScrollTo(child); } ExpandAll(); } }
int main() { int i,maxa,mina; freopen("poj2823.txt","r",stdin); freopen("poj2823ans.txt","w",stdout); while (scanf("%d%d",&n,&k)!=EOF) { for (i=1;i<=n;i++) scanf("%d",&a[i]); BuildTree(1,n,1); for (i=1;i<=n-k+1;i++) { SegmentQuery(i,i+k-1,1,mina,maxa); minans[i]=mina; maxans[i]=maxa; } for (i=1;i<=n-k+1;i++) printf("%d ",minans[i]); printf("\n"); for (i=1;i<=n-k+1;i++) printf("%d ",maxans[i]); printf("\n"); } return 0; }
/** * @sa ProcessModels */ static void ProcessSubModel (int entityNum) { const entity_t* e; int start, end; tree_t* tree; bspbrush_t* list; AABB aabb; BeginModel(entityNum); e = &entities[entityNum]; #if 0 Com_Printf("Processing entity: %i into model %i (%s:%s)\n", entityNum, curTile->nummodels, e->epairs->key, e->epairs->value); #endif start = e->firstbrush; end = start + e->numbrushes; aabb.reset(); aabb.expand(MAX_WORLD_WIDTH); /* every level (-1) */ list = MakeBspBrushList(start, end, -1, aabb); if (!config.nocsg) list = ChopBrushes(list); tree = BuildTree(list, aabb.mins, aabb.maxs); assert(tree); assert(tree->headnode); if (tree->headnode->planenum == PLANENUM_LEAF) Sys_Error("No head node bmodel of %s (%i)\n", ValueForKey(e, "classname"), entityNum); MakeTreePortals(tree); MarkVisibleSides(tree, start, end); MakeFaces(tree->headnode); FixTjuncs(tree->headnode); curTile->models[curTile->nummodels].headnode = WriteBSP(tree->headnode); FreeTree(tree); EndModel(); }
void main() { NODE RootNode; int i; long StartTime; // Build a sample tree BuildTree(&RootNode, 14); // Walk the tree 1000 times and see how long it takes StartTime = time(NULL); for (i=0; i<1000; i++) { WalkTree(&RootNode); } printf("Seconds elapsed: %ld\n", time(NULL) - StartTime); getch(); }
int main() { int n,q; scanf("%d%d",&n,&q); BuildTree(n); for (int i=0;i<q;i++) { char c; int a,b,d; scanf("%*c%c",&c); if (c=='Q') { scanf("%d%d",&a,&b); printf("%I64d\n",Query(a,b,1,M,1)); } else { scanf("%d%d%d",&a,&b,&d); Update(a,b,d,1,M,1); } } return 0; }
void huffman(OCTET *in, int width, int height) { int frequencies[UniqueSymbols] = {0}; for (int i = 0; i < width * height; i++) { frequencies[in[i]]++; } INode* root = BuildTree(frequencies); HuffCodeMap codes; GenerateCodes(root, HuffCode(), codes); delete root; std::stack<bool> *vec = new std::stack<bool>(); for (int i = 0; i < width * height; i++) { HuffCode c = codes.find(in[i])->second; std::for_each(c.begin(), c.end(), [=](bool b) { vec->push(b); }); if(vec->size() > 8) { std::cout << toChar(vec); } } }
int main(int argc, char *argv[]) { // Build frequency table int frequencies[UniqueSymbols] = {0}; const char* ptr = SampleString; while (*ptr != '\0') ++frequencies[*ptr++]; INode* root = BuildTree(frequencies); HuffCodeMap codes; GenerateCodes(root, HuffCode(), codes); delete root; for (HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); ++it) { std::cout << it->first << " "; std::copy(it->second.begin(), it->second.end(), std::ostream_iterator<bool>(std::cout)); std::cout << std::endl; } return 0; }
bool GameUI::Create() { if (!LoadWindowFromXML("game-ui.xml", "gameui", this)) return false; bool err = false; UIUtilE::Assign(this, m_gameUITree, "gametreelist", &err); UIUtilW::Assign(this, m_gameTitleText, "title"); UIUtilW::Assign(this, m_gameSystemText, "system"); UIUtilW::Assign(this, m_gameYearText, "year"); UIUtilW::Assign(this, m_gameGenreText, "genre"); UIUtilW::Assign(this, m_gameFavouriteState, "favorite"); UIUtilW::Assign(this, m_gamePlotText, "description"); UIUtilW::Assign(this, m_gameImage, "screenshot"); UIUtilW::Assign(this, m_fanartImage, "fanart"); UIUtilW::Assign(this, m_boxImage, "coverart"); if (err) { LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'gameui'"); return false; } connect(m_gameUITree, SIGNAL(itemClicked(MythUIButtonListItem*)), this, SLOT(itemClicked(MythUIButtonListItem*))); connect(m_gameUITree, SIGNAL(nodeChanged(MythGenericTree*)), this, SLOT(nodeChanged(MythGenericTree*))); m_gameShowFileName = gCoreContext->GetSetting("GameShowFileNames").toInt(); BuildTree(); BuildFocusList(); return true; }
void PHPOutlineTree::BuildTree(const wxFileName& filename) { m_filename = filename; PHPSourceFile sourceFile(filename); sourceFile.SetParseFunctionBody(false); sourceFile.Parse(); wxWindowUpdateLocker locker(this); DeleteAllItems(); wxTreeItemId root = AddRoot(wxT("Root")); wxImageList* images = new wxImageList(16, 16, true); images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/globals"))); // 0 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_private"))); // 1 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_protected"))); // 2 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_public"))); // 3 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_private"))); // 4 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_protected"))); // 5 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_public"))); // 6 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/namespace"))); // 7 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/class"))); // 8 images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/enumerator"))); // 9 AssignImageList(images); // Build the tree view BuildTree(root, sourceFile.Namespace()); if(HasChildren(GetRootItem())) { wxTreeItemIdValue cookie; wxTreeItemId child = GetFirstChild(GetRootItem(), cookie); if(child.IsOk()) { SelectItem(child); ScrollTo(child); } ExpandAll(); } }
BOOL CSettingsSheet::OnInitDialog() { CSkinDialog::OnInitDialog(); SetWindowText( m_sCaption ); CRect rect; m_wndTree.Create( WS_CHILD|WS_TABSTOP|WS_VISIBLE|/*TVS_PRIVATEIMAGELISTS|*/ TVS_HASLINES|TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_NOHSCROLL, rect, this, IDC_SETTINGS_TREE ); m_wndOK.Create( _T("OK"), WS_CHILD|WS_TABSTOP|WS_VISIBLE|BS_DEFPUSHBUTTON, rect, this, IDOK ); m_wndOK.SetFont( &theApp.m_gdiFont ); m_wndCancel.Create( _T("Cancel"), WS_CHILD|WS_TABSTOP|WS_VISIBLE, rect, this, IDCANCEL ); m_wndCancel.SetFont( &theApp.m_gdiFont ); m_wndApply.Create( _T("Apply"), WS_CHILD|WS_TABSTOP|WS_VISIBLE, rect, this, IDRETRY ); m_wndApply.SetFont( &theApp.m_gdiFont ); if ( m_pFirst == NULL ) m_pFirst = GetPage( INT_PTR(0) ); SetActivePage( m_pFirst ); BuildTree(); return TRUE; }
/* ==================== NET_Init ==================== */ void NET_Init (int port) { WORD wVersionRequested; int r; #ifdef _DEBUG ZeroFreq(); #endif BuildTree(HuffFreq); wVersionRequested = MAKEWORD(1, 1); r = WSAStartup (MAKEWORD(1, 1), &winsockdata); if (r) Sys_Error ("Winsock initialization failed."); // // open the single socket to be used for all communications // net_socket = UDP_OpenSocket (port); // // init the message buffer // net_message.maxsize = sizeof(net_message_buffer); net_message.data = net_message_buffer; // // determine my name & address // NET_GetLocalAddress (); Con_Printf("UDP Initialized\n"); }
void CDialogTextures::OnCheckHideroot() { BuildTree(); }
/* ======================================================================================================================= ======================================================================================================================= */ void CDialogTextures::OnRefresh() { quickTree.Clear(); addModels( true ); if (mode == TEXTURES) { idStrList textures(1024); int count = declManager->GetNumDecls( DECL_MATERIAL ); int i; const idMaterial *mat; for (i = 0; i < count; i++) { mat = declManager->MaterialByIndex(i, false); if ( mat->IsValid() && mat->TestMaterialFlag(MF_EDITOR_VISIBLE) && !idStr::Icmpn( mat->GetName(), "textures/", 9 ) ) { textures.Append(mat->GetName()); } } declManager->Reload( false ); BuildTree(); count = textures.Num(); for (i = 0; i < count; i++) { mat = declManager->FindMaterial(textures[i].c_str()); if ( mat ) { mat->SetMaterialFlag(MF_EDITOR_VISIBLE); } } SelectCurrentItem(false, g_qeglobals.d_texturewin.texdef.name, CDialogTextures::TEXTURES); } else if (mode == MATERIALS) { idStrList textures(1024); int count = declManager->GetNumDecls( DECL_MATERIAL ); int i; const idMaterial *mat; for (i = 0; i < count; i++) { mat = declManager->MaterialByIndex(i, false); if ( mat->IsValid() && mat->TestMaterialFlag(MF_EDITOR_VISIBLE) && idStr::Icmpn( mat->GetName(), "textures/", 9 ) ) { textures.Append(mat->GetName()); } } declManager->Reload( false ); BuildTree(); count = textures.Num(); for (i = 0; i < count; i++) { mat = declManager->FindMaterial(textures[i].c_str()); if ( mat ) { mat->SetMaterialFlag(MF_EDITOR_VISIBLE); } } SelectCurrentItem(false, g_qeglobals.d_texturewin.texdef.name, CDialogTextures::MATERIALS); } else if (mode == SOUNDS || mode == SOUNDPARENT) { HTREEITEM root = m_treeTextures.GetRootItem(); HTREEITEM sib = m_treeTextures.GetNextItem(root, TVGN_ROOT); while (sib) { idStr str = m_treeTextures.GetItemText(sib); if (str.Icmp(TypeNames[SOUNDS]) == 0) { CWaitCursor cursor; m_treeTextures.DeleteItem(sib); declManager->Reload( false ); bool rootItems = m_chkHideRoot.GetCheck() == 0; addSounds(rootItems); return; } sib = m_treeTextures.GetNextSiblingItem(sib); } } }
void mtsQtCommandSelector::Refresh(void) { BuildTree(GlobalManager); }
TreeNode *sortedArrayToBST(vector<int> &num) { return BuildTree(num,0,num.size()-1); }
/** * @param inorder: A list of integers that inorder traversal of a tree * @param postorder: A list of integers that postorder traversal of a tree * @return: Root of a tree */ TreeNode * buildTree(vector<int> &inorder, vector<int> &postorder) { if (postorder.empty() || inorder.empty()) return NULL; int n = postorder.size(); return BuildTree(inorder, postorder, 0, n - 1, 0, n - 1); }
dgInt32 dgConvexHull4d::InitVertexArray(dgHullVector* const points, const dgBigVector* const vertexCloud, dgInt32 count, void* const memoryPool, dgInt32 maxMemSize) { for (dgInt32 i = 0; i < count; i ++) { points[i] = vertexCloud[i]; points[i].m_index = i; points[i].m_mark = 0; } dgSort(points, count, ConvexCompareVertex); dgInt32 indexCount = 0; for (int i = 1; i < count; i ++) { for (; i < count; i ++) { if (ConvexCompareVertex (&points[indexCount], &points[i], NULL)) { indexCount ++; points[indexCount] = points[i]; break; } } } count = indexCount + 1; if (count < 4) { m_count = 0; return count; } dgAABBPointTree4d* tree = BuildTree (NULL, points, count, 0, (dgInt8**) &memoryPool, maxMemSize); dgBigVector boxSize (tree->m_box[1] - tree->m_box[0]); boxSize.m_w = dgFloat64 (0.0f); m_diag = dgFloat32 (sqrt (boxSize.DotProduct4(boxSize).m_x)); m_points[4].m_x = dgFloat64 (0.0f); dgHullVector* const convexPoints = &m_points[0]; dgStack<dgBigVector> normalArrayPool (256); dgBigVector* const normalArray = &normalArrayPool[0]; dgInt32 normalCount = BuildNormalList (&normalArray[0]); dgInt32 index = SupportVertex (&tree, points, normalArray[0]); convexPoints[0] = points[index]; points[index].m_mark = 1; bool validTetrahedrum = false; dgBigVector e1 (dgFloat64 (0.0f), dgFloat64 (0.0f), dgFloat64 (0.0f), dgFloat64 (0.0f)) ; for (dgInt32 i = 1; i < normalCount; i ++) { dgInt32 index = SupportVertex (&tree, points, normalArray[i]); dgAssert (index >= 0); e1 = points[index] - convexPoints[0]; e1.m_w = dgFloat64 (0.0f); dgFloat64 error2 = e1.DotProduct4(e1).m_x; if (error2 > (dgFloat32 (1.0e-4f) * m_diag * m_diag)) { convexPoints[1] = points[index]; points[index].m_mark = 1; validTetrahedrum = true; break; } } if (!validTetrahedrum) { m_count = 0; return count; } dgInt32 bestIndex = -1; dgFloat64 bestValue = dgFloat64 (1.0f); validTetrahedrum = false; dgFloat64 lenght2 = e1.DotProduct4(e1).m_x; dgBigVector e2(dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));; for (dgInt32 i = 2; i < normalCount; i ++) { dgInt32 index = SupportVertex (&tree, points, normalArray[i]); dgAssert (index >= 0); dgAssert (index < count); e2 = points[index] - convexPoints[0]; e2.m_w = dgFloat64 (0.0f); dgFloat64 den = e2.DotProduct4(e2).m_x; if (fabs (den) > (dgFloat64 (1.0e-6f) * m_diag)) { den = sqrt (lenght2 * den); dgFloat64 num = e2.DotProduct4(e1).m_x; dgFloat64 cosAngle = fabs (num / den); if (cosAngle < bestValue) { bestValue = cosAngle; bestIndex = index; } if (cosAngle < 0.9f) { break; } } } if (bestValue < dgFloat64 (0.999f)) { convexPoints[2] = points[bestIndex]; points[bestIndex].m_mark = 1; validTetrahedrum = true; } if (!validTetrahedrum) { m_count = 0; return count; } validTetrahedrum = false; dgBigVector e3(dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));; for (dgInt32 i = 3; i < normalCount; i ++) { dgInt32 index = SupportVertex (&tree, points, normalArray[i]); dgAssert (index >= 0); dgAssert (index < count); e3 = points[index] - convexPoints[0]; e3.m_w = dgFloat64 (0.0f); dgFloat64 volume = (e1 * e2) % e3; if (fabs (volume) > (dgFloat64 (1.0e-4f) * m_diag * m_diag * m_diag)) { convexPoints[3] = points[index]; points[index].m_mark = 1; validTetrahedrum = true; break; } } m_count = 4; if (!validTetrahedrum) { m_count = 0; } return count; }
dgAABBPointTree4d* dgConvexHull4d::BuildTree (dgAABBPointTree4d* const parent, dgHullVector* const points, dgInt32 count, dgInt32 baseIndex, dgInt8** memoryPool, dgInt32& maxMemSize) const { dgAABBPointTree4d* tree = NULL; dgAssert (count); dgBigVector minP ( dgFloat32 (1.0e15f), dgFloat32 (1.0e15f), dgFloat32 (1.0e15f), dgFloat32 (1.0e15f)); dgBigVector maxP (-dgFloat32 (1.0e15f), -dgFloat32 (1.0e15f), -dgFloat32 (1.0e15f), -dgFloat32 (1.0e15f)); if (count <= DG_VERTEX_CLUMP_SIZE_4D) { dgAABBPointTree4dClump* const clump = new (*memoryPool) dgAABBPointTree4dClump; *memoryPool += sizeof (dgAABBPointTree4dClump); maxMemSize -= sizeof (dgAABBPointTree4dClump); dgAssert (maxMemSize >= 0); dgAssert (clump); clump->m_count = count; for (dgInt32 i = 0; i < count; i ++) { clump->m_indices[i] = i + baseIndex; const dgBigVector& p = points[i]; minP.m_x = dgMin (p.m_x, minP.m_x); minP.m_y = dgMin (p.m_y, minP.m_y); minP.m_z = dgMin (p.m_z, minP.m_z); minP.m_w = dgMin (p.m_w, minP.m_w); maxP.m_x = dgMax (p.m_x, maxP.m_x); maxP.m_y = dgMax (p.m_y, maxP.m_y); maxP.m_z = dgMax (p.m_z, maxP.m_z); maxP.m_w = dgMax (p.m_w, maxP.m_w); } clump->m_left = NULL; clump->m_right = NULL; tree = clump; } else { dgBigVector median (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f)); dgBigVector varian (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f)); for (dgInt32 i = 0; i < count; i ++) { const dgBigVector& p = points[i]; minP.m_x = dgMin (p.m_x, minP.m_x); minP.m_y = dgMin (p.m_y, minP.m_y); minP.m_z = dgMin (p.m_z, minP.m_z); minP.m_w = dgMin (p.m_w, minP.m_w); maxP.m_x = dgMax (p.m_x, maxP.m_x); maxP.m_y = dgMax (p.m_y, maxP.m_y); maxP.m_z = dgMax (p.m_z, maxP.m_z); maxP.m_w = dgMax (p.m_w, maxP.m_w); median = median + p; varian = varian + p.CompProduct4(p); } varian = varian.Scale4 (dgFloat32 (count)) - median.CompProduct4(median); dgInt32 index = 0; dgFloat64 maxVarian = dgFloat64 (-1.0e10f); for (dgInt32 i = 0; i < 4; i ++) { if (varian[i] > maxVarian) { index = i; maxVarian = varian[i]; } } dgBigVector center = median.Scale4 (dgFloat64 (1.0f) / dgFloat64 (count)); dgFloat64 test = center[index]; dgInt32 i0 = 0; dgInt32 i1 = count - 1; do { for (; i0 <= i1; i0 ++) { dgFloat64 val = points[i0][index]; if (val > test) { break; } } for (; i1 >= i0; i1 --) { dgFloat64 val = points[i1][index]; if (val < test) { break; } } if (i0 < i1) { dgSwap(points[i0], points[i1]); i0++; i1--; } } while (i0 <= i1); if (i0 == 0){ i0 = count / 2; } if (i0 >= (count - 1)){ i0 = count / 2; } tree = new (*memoryPool) dgAABBPointTree4d; *memoryPool += sizeof (dgAABBPointTree4d); maxMemSize -= sizeof (dgAABBPointTree4d); dgAssert (maxMemSize >= 0); dgAssert (i0); dgAssert (count - i0); tree->m_left = BuildTree (tree, points, i0, baseIndex, memoryPool, maxMemSize); tree->m_right = BuildTree (tree, &points[i0], count - i0, i0 + baseIndex, memoryPool, maxMemSize); } dgAssert (tree); tree->m_parent = parent; tree->m_box[0] = minP - dgBigVector (dgFloat64 (1.0e-3f), dgFloat64 (1.0e-3f), dgFloat64 (1.0e-3f), dgFloat64 (1.0e-3f)); tree->m_box[1] = maxP + dgBigVector (dgFloat64 (1.0e-3f), dgFloat64 (1.0e-3f), dgFloat64 (1.0e-3f), dgFloat64 (1.0e-3f)); return tree; }
void FNodeBuilder::BuildMini(bool makeGLNodes) { GLNodes = makeGLNodes; GroupSegPlanesSimple(); BuildTree(); }
void CPreviewDlg::OnBnClickedButtonReload() { BuildTree(); g_qeglobals.sw->StopAllSounds(); }