Select Git revision
Transform.cpp
Forked from
gmsh / gmsh
Source project has a limited visibility.
OctreeInternals.cpp 13.25 KiB
// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>.
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "GmshMessage.h"
#include "OctreeInternals.h"
int initializeOctantBuckets(double *_orig, double *_size, int _maxElem,
octantBucket **buckets_head, globalInfo **globalPara)
// Initialize the buckets
// Given by user: orig and size -- information about the domain
// maxElem -- maximum number of elements per bucket
// Return: buckets -- pointer to the begin of buckets
// globalPara -- some info about the buckets
// At last, 1 will be returned if succeed, otherwise, return 0
{
int i, j, k, tmp1;
int p = 1;
int initial_buckets_num; // which is a number of 8^p form for integer p
double tmp[3], error[3];
octantBucket *buckets;
for (i = 0; i < 3; i++)
error[i]= _size[i]*0.01;
initial_buckets_num = (int)pow(8., p); // it is actually 8
(*globalPara) = new globalInfo;
(*globalPara)->maxPrecision = 1;
(*globalPara)->maxElements = _maxElem;
(*globalPara)->ptrToPrevElement = NULL;
for (i = 0; i < 3; i++) {
(*globalPara)->origin[i] = _orig[i];
(*globalPara)->size[i] = _size[i];
}
(*globalPara)->numBuckets = initial_buckets_num;
*buckets_head = new octantBucket;
if (!(*buckets_head)) {
Msg::Error("initializeOctantBuckets could not allocate enough space");
return (0);
} // if could not allocate buckets
buckets = new octantBucket[8];
if (!buckets) {
Msg::Error("initializeOctantBuckets could not allocate enough space");
return (0);
}
(*buckets_head)->next = buckets;
(*buckets_head)->parent = NULL;
(*buckets_head)->numElements = 0;
(*buckets_head)->lhead = NULL;
(*buckets_head)->precision = 0;
for (i = 0; i< 3; i++) {
(*buckets_head)->minPt[i] = _orig[i]-error[i];
(*buckets_head)->maxPt[i] = _size[i]+_orig[i]+error[i];
}
for (i = 0; i < (*globalPara)->numBuckets; i++) {
buckets[i].numElements = 0;
buckets[i].lhead = NULL;
buckets[i].next = NULL;
buckets[i].parent = *buckets_head;