gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Octree.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <vector>
9 #include "Octree.h"
10 
11 Octree *Octree_Create(int maxElements, double origin[3], double size[3],
12  void (*BB)(void *, double *, double *),
13  void (*Centroid)(void *, double *),
14  int (*InEle)(void *, double *))
15 {
16  Octree *myOctree = new Octree;
17  initializeOctantBuckets(origin, size, maxElements, &(myOctree->root),
18  &(myOctree->info));
19  myOctree->function_BB = BB;
20  myOctree->function_centroid = Centroid;
21  myOctree->function_inElement = InEle;
22  return myOctree;
23 }
24 
26 {
27  int i, numBuck = 8;
28  ELink ptr1, ptr2;
29 
30  if(bucket->next == nullptr) {
31  ptr1 = bucket->lhead;
32  while(ptr1 != nullptr) {
33  ptr2 = ptr1;
34  ptr1 = ptr1->next;
35  delete ptr2;
36  }
37  bucket->listBB.clear();
38  return;
39  }
40 
41  for(i = numBuck - 1; i >= 0; i--) free_buckets((bucket->next) + i);
42  delete[] bucket->next;
43  return;
44 }
45 
46 void Octree_Delete(Octree *myOctree)
47 {
48  if(!myOctree) return;
49  delete myOctree->info;
50  free_buckets(myOctree->root);
51  delete myOctree->root;
52  delete myOctree;
53 }
54 
55 void Octree_Insert(void *element, Octree *myOctree)
56 {
57  if(!myOctree) return;
58  double minBB[3], maxBB[3], centroid[3];
60  (*(myOctree->function_BB))(element, minBB, maxBB);
61  (*(myOctree->function_centroid))(element, centroid);
62  bucket = findElementBucket(myOctree->root, centroid);
63  if(bucket)
64  addElement2Bucket(bucket, element, minBB, maxBB, centroid, myOctree->info);
65 }
66 
67 void Octree_Arrange(Octree *myOctree)
68 {
69  if(!myOctree) return;
70  // std::list<void *>::iterator iter;
71  std::vector<void *>::iterator iter;
72  double minPt[3], maxPt[3];
73  for(iter = myOctree->info->listAllElements.begin();
74  iter != myOctree->info->listAllElements.end(); iter++) {
75  (*(myOctree->function_BB))(*iter, minPt, maxPt);
76  insertOneBB(*iter, minPt, maxPt, myOctree->root);
77  }
78  myOctree->info->listAllElements.clear();
79 }
80 
81 void *Octree_Search(double *pt, Octree *myOctree)
82 {
83  if(!myOctree) return nullptr;
84  return searchElement(myOctree->root, pt, myOctree->info,
85  myOctree->function_BB, myOctree->function_inElement);
86 }
87 
88 void Octree_SearchAll(double *pt, Octree *myOctree, std::vector<void *> *output)
89 {
90  if(!myOctree) return;
91  searchAllElements(myOctree->root, pt, myOctree->info, myOctree->function_BB,
92  myOctree->function_inElement, output);
93 }
Octree::function_inElement
InEleFunction function_inElement
Definition: OctreeInternals.h:56
elem::next
struct elem * next
Definition: OctreeInternals.h:22
Octree.h
bucket
Definition: OctreeInternals.h:27
initializeOctantBuckets
int initializeOctantBuckets(double *_orig, double *_size, int _maxElem, octantBucket **buckets_head, globalInfo **globalPara)
Definition: OctreeInternals.cpp:13
Octree_Insert
void Octree_Insert(void *element, Octree *myOctree)
Definition: Octree.cpp:55
Octree_Delete
void Octree_Delete(Octree *myOctree)
Definition: Octree.cpp:46
Octree_SearchAll
void Octree_SearchAll(double *pt, Octree *myOctree, std::vector< void * > *output)
Definition: Octree.cpp:88
centroid
static void centroid(int n, double *X, double *Y, double *Z, double *c)
Definition: OctreePost.cpp:61
addElement2Bucket
int addElement2Bucket(octantBucket *_bucket, void *_element, double *_minBB, double *_maxBB, double *_ele_centroid, globalInfo *_globalPara)
Definition: OctreeInternals.cpp:111
findElementBucket
octantBucket * findElementBucket(octantBucket *_buckets_head, double *_pt)
Definition: OctreeInternals.cpp:204
Octree_Search
void * Octree_Search(double *pt, Octree *myOctree)
Definition: Octree.cpp:81
Octree_Arrange
void Octree_Arrange(Octree *myOctree)
Definition: Octree.cpp:67
Octree::function_BB
BBFunction function_BB
Definition: OctreeInternals.h:55
Octree::info
globalInfo * info
Definition: OctreeInternals.h:53
bucket::lhead
ELink lhead
Definition: OctreeInternals.h:32
Octree_Create
Octree * Octree_Create(int maxElements, double origin[3], double size[3], void(*BB)(void *, double *, double *), void(*Centroid)(void *, double *), int(*InEle)(void *, double *))
Definition: Octree.cpp:11
bucket::next
struct bucket * next
Definition: OctreeInternals.h:34
Octree::root
octantBucket * root
Definition: OctreeInternals.h:54
Octree::function_centroid
CentroidFunction function_centroid
Definition: OctreeInternals.h:57
element
Definition: shapeFunctions.h:12
Octree
Definition: OctreeInternals.h:51
searchElement
void * searchElement(octantBucket *_buckets_head, double *_pt, globalInfo *_globalPara, BBFunction BBElement, InEleFunction xyzInElement)
Definition: OctreeInternals.cpp:290
bucket::listBB
std::vector< void * > listBB
Definition: OctreeInternals.h:33
output
static void output(code_int code)
Definition: gl2gif.cpp:743
searchAllElements
void * searchAllElements(octantBucket *_buckets_head, double *_pt, globalInfo *_globalPara, BBFunction BBElement, InEleFunction xyzInElement, std::vector< void * > *_elements)
Definition: OctreeInternals.cpp:396
free_buckets
void free_buckets(octantBucket *bucket)
Definition: Octree.cpp:25
insertOneBB
void insertOneBB(void *_region, double *_minPt, double *_maxPt, octantBucket *_bucket)
Definition: OctreeInternals.cpp:371
elem
Definition: OctreeInternals.h:17
global::listAllElements
std::vector< void * > listAllElements
Definition: OctreeInternals.h:47