1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
//- Class: PointGridSearch
//- Description:  The PointGridSearch class is used to maintain a "bucket sort" of
//-               all mesh points used for rapid high performance nearest
//-               neighbor searches.  The object contains a 3-dimensional
//-               array of point lists for each grid cell (i.e. box) containing
//-               points that lie within the grid cell.  appropriate calls that
//-               return point, edge, face, and hex lists that lie in the
//-               neighborhood of an input mesh entity are provided.
//- Owner: Jim Hipp
//- Checked by: 

#include <math.h>
#include <assert.h>

#include "PointGridSearch.hpp"
#include "MemoryManager.hpp"
#include "DLIList.hpp"
#include "CastTo.hpp"
#include "CubitVector.hpp"
#include "CubitPoint.hpp"
#include "CubitFacet.hpp"
#include "CpuTimer.hpp"
#include "CubitMessage.hpp"
#include "CubitBox.hpp"
#include "TDCellIndex.hpp"
#include "GeometryDefines.h"

const double GRID_EXTENSION   =  0.1;

//
// Constructor / Destructor ...................................................
//
PointGridSearch::PointGridSearch( DLIList<CubitPoint*> *point_list,
                                  DLIList<CubitFacet*> *facet_list,
                                  float grid_scale)
{
    // find the geometric bounding range mesh
  assert( point_list && point_list->size() );
  bounding_range( *point_list );

    //find an estimate of the cell size based on the average square distance
    //of the edges on the surface of the geometry

  double grid_cell_size = 1.;
  
    // edge lengths
  double sum = 0.0;
  int i;
  maxEdgeLength = CUBIT_DBL_MIN;
  assert( facet_list && facet_list->size());
  for ( i = 0; i < facet_list->size(); i++)
  {
    CubitPoint *p1, *p2;
    facet_list->next(i)->get_edge_1(p1, p2);
    CubitVector temp = p2->coordinates() - p1->coordinates();
    double tmp_lsqrd =  temp.length_squared();
    sum += tmp_lsqrd;
  }
  grid_cell_size = sqrt( sum / facet_list->size() );

  maxEdgeLength = grid_cell_size;
    // evaluate grid parameters
  CubitVector cell(1.0, 1.0, 1.0);
  double grid_cell_width = grid_scale * grid_cell_size;
  cell *= ( GRID_EXTENSION + 5.0 ) * grid_cell_width;
  gridRangeMinimum = boundingRangeMinimum - cell;
  gridRangeMaximum = boundingRangeMaximum + cell;
  
  CubitVector range_width = gridRangeMaximum - gridRangeMinimum;
  
  numberGridCellsX = (int) ceil(range_width.x() / grid_cell_width + 0.5);
  numberGridCellsY = (int) ceil(range_width.y() / grid_cell_width + 0.5);
  numberGridCellsZ = (int) ceil(range_width.z() / grid_cell_width + 0.5);
  numberGridCells  = numberGridCellsX * numberGridCellsY * numberGridCellsZ;
  
  gridCellWidth.x(range_width.x() / ((double) numberGridCellsX));
  gridCellWidth.y(range_width.y() / ((double) numberGridCellsY));
  gridCellWidth.z(range_width.z() / ((double) numberGridCellsZ));
  
  gridCellWidthInverse.x(1.0 / gridCellWidth.x());
  gridCellWidthInverse.y(1.0 / gridCellWidth.y());
  gridCellWidthInverse.z(1.0 / gridCellWidth.z());
  
    // allocate neighborhood list array
  neighborhoodList = new DLIList<CubitPoint*>* [numberGridCells];
  assert(neighborhoodList != NULL);
  for ( i = 0; i < numberGridCells; i++)
  {
    neighborhoodList[i] = NULL;
  }
}
PointGridSearch::PointGridSearch(DLIList <CubitPoint*> &point_list,
                                 double grid_cell_size,
                                 double grid_scale)
{
    // find the bounding range of the reference geometry
  bounding_range(point_list);
  if ( grid_cell_size < CUBIT_RESABS )
    grid_cell_size = 
      (boundingRangeMaximum - boundingRangeMinimum).length() / 5.;    
  
  CubitVector cell(1.0, 1.0, 1.0);
  double grid_cell_width = grid_scale * grid_cell_size;
  cell *= grid_cell_width;
  gridRangeMinimum = boundingRangeMinimum - cell;
  gridRangeMaximum = boundingRangeMaximum + cell;

  CubitVector range_width = gridRangeMaximum - gridRangeMinimum;

  numberGridCellsX = (int) ceil(range_width.x() / grid_cell_width + 0.5);
  numberGridCellsY = (int) ceil(range_width.y() / grid_cell_width + 0.5);
  numberGridCellsZ = (int) ceil(range_width.z() / grid_cell_width + 0.5);
  numberGridCells  = numberGridCellsX * numberGridCellsY * numberGridCellsZ;

  gridCellWidth.x(range_width.x() / ((double) numberGridCellsX));
  gridCellWidth.y(range_width.y() / ((double) numberGridCellsY));
  gridCellWidth.z(range_width.z() / ((double) numberGridCellsZ));

  gridCellWidthInverse.x(1.0 / gridCellWidth.x());
  gridCellWidthInverse.y(1.0 / gridCellWidth.y());
  gridCellWidthInverse.z(1.0 / gridCellWidth.z());

    // allocate neighborhood list array

  neighborhoodList = new DLIList<CubitPoint*>* [numberGridCells];
  assert(neighborhoodList != NULL);
  int i;
  for ( i = 0; i < numberGridCells; i++)
  {
    neighborhoodList[i] = NULL;
  }
}
PointGridSearch::~PointGridSearch()
{
    // delete each DLIList<CubitPoint*> and the array of pointers containing them

    // first, delete the tdcellindex for each point
  int i;
  for ( i = 0; i < numberGridCells; i++) {
    if (!neighborhoodList[i]) continue;
    for (int j = neighborhoodList[i]->size(); j > 0; j--)
      neighborhoodList[i]->get_and_step()->delete_TD(&TDCellIndex::is_cell_index);
  }

    for (i = 0; i < numberGridCells; i++)
      delete neighborhoodList[i];

    delete [] neighborhoodList;
}

//
// Private Member Functions ...................................................
//

void PointGridSearch::cell_from_range()
{
    // Evaluate boundingCellMin and Max from the boundingRangeMin and Max
    // parameters

    CubitVector range_vec = boundingRangeMinimum - gridRangeMinimum;
    boundingCellMinimumX  = (int) (range_vec.x() * gridCellWidthInverse.x());
    boundingCellMinimumY  = (int) (range_vec.y() * gridCellWidthInverse.y());
    boundingCellMinimumZ  = (int) (range_vec.z() * gridCellWidthInverse.z());

    if (boundingCellMinimumX < 0) boundingCellMinimumX = 0;
    if (boundingCellMinimumY < 0) boundingCellMinimumY = 0;
    if (boundingCellMinimumZ < 0) boundingCellMinimumZ = 0;

    range_vec = boundingRangeMaximum - gridRangeMinimum;
    boundingCellMaximumX  = (int) (range_vec.x() * gridCellWidthInverse.x());
    boundingCellMaximumY  = (int) (range_vec.y() * gridCellWidthInverse.y());
    boundingCellMaximumZ  = (int) (range_vec.z() * gridCellWidthInverse.z());

    if (boundingCellMaximumX >= numberGridCellsX)
        boundingCellMaximumX = numberGridCellsX - 1;
    if (boundingCellMaximumY >= numberGridCellsY)
        boundingCellMaximumY = numberGridCellsY - 1;
    if (boundingCellMaximumZ >= numberGridCellsZ)
        boundingCellMaximumZ = numberGridCellsZ - 1;
}

void PointGridSearch::bounding_range(DLIList<CubitPoint*>& point_list)
{

  if ( !point_list.size() )
    return;
  
    // initialize min and max range values to the first point coordinates
  boundingRangeMinimum = point_list.get()->coordinates();
  boundingRangeMaximum = point_list.get_and_step()->coordinates();
  
    // find the min and max coordinates that completely encloses the
    // point list
  
  for (int i = 1; i < point_list.size(); i++)
    bounding_range(point_list.get_and_step());

}
void PointGridSearch::bounding_range(DLIList<CubitFacet*>& facet_list)
{
  int i, j;
  DLIList<CubitPoint*> point_list;
  for ( i = 0; i < facet_list.size(); i++)
  {
    CubitFacet* facet = facet_list.get_and_step();
    
    DLIList<CubitPoint*> temp_point_list;
    facet->points(temp_point_list);
    for (j = 0; j < temp_point_list.size(); j++)
    {
      CubitPoint* point = temp_point_list.get_and_step();
      
      if (!point->marked())
      {
        point->marked(CUBIT_TRUE);
        point_list.append(point);
      }
    }
  }
    // unmark the found points
  
  for (i = 0; i < point_list.size(); i++)
  {
    point_list.get_and_step()->marked(CUBIT_FALSE);
  }
  if ( !point_list.size() )
    return;
  
    // initialize min and max range values to the first point coordinates
  boundingRangeMinimum = point_list.get()->coordinates();
  boundingRangeMaximum = point_list.get_and_step()->coordinates();
  
    // find the min and max coordinates that completely encloses the
    // point list
  
  for (i = 1; i < point_list.size(); i++)
    bounding_range(point_list.get_and_step());

}

//
// Public Member Functions ....................................................
//

void PointGridSearch::change_cell(CubitPoint* point)<--- The function 'change_cell' is never used.
{
  int old_cell, current_cell;
  // if cell index has changed then swap lists
  ToolData* td_temp = point->get_TD( &TDCellIndex::is_cell_index);
  TDCellIndex* td_index = CAST_TO(td_temp, TDCellIndex);
  if (td_temp == NULL) {
    td_index = new TDCellIndex;
    assert( td_index != NULL );
    point->add_TD(td_index);
  }
  old_cell = td_index->cell_index();
  
  current_cell = grid_cell_index(point);
  if (current_cell >= 0 && current_cell < numberGridCells)
  {
    if (current_cell != old_cell)
    {
      remove_point_from_cell(point, old_cell);
      add_point_to_cell(point, current_cell);
      td_index->cell_index(current_cell);
    }
  }
}

int PointGridSearch::in_grid(const CubitVector& position)<--- The function 'in_grid' is never used.
{
  CubitVector range_vec;
  int i, j, k, index;

  range_vec = position - gridRangeMinimum;
  i = (int) (range_vec.x() * gridCellWidthInverse.x());
  j = (int) (range_vec.y() * gridCellWidthInverse.y());
  k = (int) (range_vec.z() * gridCellWidthInverse.z());
  index = numberGridCellsX * (numberGridCellsY * k + j) + i;
  if(index >= 0 && index < numberGridCells)
  {
    return CUBIT_TRUE;
  }
  else
  {
    return CUBIT_FALSE;
  }
}

void PointGridSearch::add_point(CubitPoint* point)
{
    // append point to the appropriate list

    int i = grid_cell_index(point);
    if (i < 0 || i > numberGridCells){
      return;
    }

    ToolData* td_temp = point->get_TD(&TDCellIndex::is_cell_index);
    TDCellIndex* td_index;
    
    if(td_temp == NULL){
      td_index = new TDCellIndex;
      assert(td_index != NULL);
      point->add_TD(td_index);
      td_index->cell_index(i); 
      add_point_to_cell(point, i);
    }
    else{  // the tool data already exists, avoid multiple listings of point
      td_index = CAST_TO(td_temp, TDCellIndex);
      assert( td_index != NULL);
      int iold = td_index->cell_index();
      
      if(iold != i){
	remove_point_from_cell(point,iold);
	td_index->cell_index(i);
	add_point_to_cell(point, i);
      }
      else{  // iold==i, so check whether the point is already on the list
	if (neighborhoodList[i] && neighborhoodList[i]->move_to(point)) return;
	else add_point_to_cell(point, i);
      }
    }
}

void PointGridSearch::remove_point(CubitPoint* point)
{
    // remove point from the appropriate list
    int index = -1;
    ToolData* td_temp = point->get_TD(&TDCellIndex::is_cell_index);
    if (!td_temp)
      return;
    TDCellIndex* td_index = CAST_TO(td_temp, TDCellIndex);
    if( td_index ){
      index = td_index->cell_index();
      point->delete_TD( &TDCellIndex::is_cell_index );
    }
    remove_point_from_cell(point, index);
}

void PointGridSearch::set_neighborhood_bounds(CubitVector& vec)
{
    // set the range and cell min and max values for the vector

    boundingRangeMinimum = vec;
    boundingRangeMaximum = vec;

    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(const CubitVector& center,
                                              double size)
{
    // set the range and cell min and max values as a cube of breadth =
    // 2 * size centered at center

    CubitVector search_extent_box(size, size, size);
    boundingRangeMinimum = center - search_extent_box;
    boundingRangeMaximum = center + search_extent_box;

    cell_from_range();
}
void PointGridSearch::set_neighborhood_bounds_max_edge(const CubitVector& center,<--- The function 'set_neighborhood_bounds_max_edge' is never used.
                                                       double factor)
{
    // set the range and cell min and max values as a cube of breadth =
    // 2 * size centered at center

    CubitVector search_extent_box(maxEdgeLength*factor, 
                                  maxEdgeLength*factor, 
                                  maxEdgeLength*factor);
    boundingRangeMinimum = center - search_extent_box;
    boundingRangeMaximum = center + search_extent_box;

    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(CubitVector& center, double x,
					 double y, double z)
{
    // set the range and cell min and max values as a box of size 2x, 2y, and
    // 2z, centered at center

    CubitVector search_extent_box(x, y, z);
    boundingRangeMinimum = center - search_extent_box;
    boundingRangeMaximum = center + search_extent_box;

    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(CubitVector& vec_1,
					 CubitVector& vec_2)
{
    // initialize min and max range values to the first vectors coordinates
   
    boundingRangeMinimum = vec_1;
    boundingRangeMaximum = vec_1;

    // find the range and cell min and max values for the two vectors

    bounding_range(vec_2);
    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(CubitPoint* point, CubitVector& vec)
{
    // initialize min and max range values to the point coordinates

    boundingRangeMinimum = point->coordinates();
    boundingRangeMaximum = point->coordinates();

    // find the range and cell min and max values for the point and vector

    bounding_range(vec);
    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(CubitPoint* point)
{
    // initialize min and max range values to the point coordinates

    boundingRangeMinimum = point->coordinates();
    boundingRangeMaximum = point->coordinates();

    // find the cell min and max values

    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(CubitPoint* point_1, CubitPoint* point_2)
{
    // initialize min and max range values to the first point coordinates

    boundingRangeMinimum = point_1->coordinates();
    boundingRangeMaximum = point_1->coordinates();

    // find the range and cell min and max values for the two points

    bounding_range(point_2);
    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(DLIList<CubitPoint*>& point_list)
{
    // find the range and cell min and max values for the point list

    bounding_range(point_list);
    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(CubitFacet* facet)
{
    // find the points belonging to the face

    DLIList<CubitPoint*> point_list;
    facet->points(point_list);

    // find the bounding range and cell min and max values for the point list

    bounding_range(point_list);
    cell_from_range();
}

void PointGridSearch::set_neighborhood_bounds(DLIList<CubitFacet*>& facet_list)
{
    DLIList<CubitPoint*> point_list;

    // find all points belonging to the faces in face_list
    int i;
    for ( i = 0; i < facet_list.size(); i++)
    {
      CubitFacet* facet = facet_list.get_and_step();

      DLIList<CubitPoint*> temp_point_list;
      facet->points(temp_point_list);
      for (int j = 0; j < temp_point_list.size(); j++)
      {
	CubitPoint* point = temp_point_list.get_and_step();

	if (!point->marked())
	{
	  point->marked(CUBIT_TRUE);
	  point_list.append(point);
	}
      }
    }

    // unmark the found points

    for (i = 0; i < point_list.size(); i++)
    {
      point_list.get_and_step()->marked(CUBIT_FALSE);
    }

    // find the bounding range and cell min and max values for the point list

    bounding_range(point_list);
    cell_from_range();
}

void PointGridSearch::get_neighborhood_points( DLIList<CubitPoint*> &point_list )
{
  // retrieve points over the current bounding box range

  point_list.clean_out();

  for (int k = boundingCellMinimumZ; k <= boundingCellMaximumZ; k++)
  {
    int kn = numberGridCellsY * k;
    for (int j = boundingCellMinimumY; j <= boundingCellMaximumY; j++)
    {
      int jn = numberGridCellsX * (kn + j);
      for (int i = boundingCellMinimumX; i <= boundingCellMaximumX; i++)
      {
        int in = jn + i;
        assert( in >= 0 && in < numberGridCells );
        if (neighborhoodList[in])
        {
           point_list += *(neighborhoodList[in]);
        }
      }
    }
  }
}

template <typename X>
struct sort_by_second
{
  bool operator()(const X & a, const X & b)
  {
    return a.second < b.second;
  }
};

void PointGridSearch::get_neighborhood_points_sorted(<--- The function 'get_neighborhood_points_sorted' is never used.
  DLIList<CubitPoint*> &point_list,
  const CubitVector& center, double cut_off)
{
  point_list.clean_out();
  DLIList<CubitPoint*> temp_point_list;
  int i;

  for (int k = boundingCellMinimumZ; k <= boundingCellMaximumZ; k++)
  {
    int kn = numberGridCellsY * k;
    for (int j = boundingCellMinimumY; j <= boundingCellMaximumY; j++)
    {
      int jn = numberGridCellsX * (kn + j);
      for ( i = boundingCellMinimumX; i <= boundingCellMaximumX; i++)
      {
	int in = jn + i;
        if (neighborhoodList[in])
        {
          temp_point_list += *(neighborhoodList[in]);
        }
      }
    }
  }

  // evaluate point distance to center ... remove those larger than cut_off
  std::vector< std::pair<int, double> > sorted_index_list;
  CubitVector vec;
  cut_off *= cut_off;
  temp_point_list.reset();
  for ( i = 0; i < temp_point_list.size(); i++)
  {
    vec = center - temp_point_list.get_and_step()->coordinates();
    double distance = vec.length_squared();
    if (distance < cut_off)
    {
      sorted_index_list.push_back( std::make_pair( i, distance ) );
    }
  }

  std::sort(sorted_index_list.begin(), sorted_index_list.end(), sort_by_second<std::pair<int, double> >());
  temp_point_list.reset();
  for ( size_t j = 0; j < sorted_index_list.size(); j++ )
  {
    int index = sorted_index_list[j].first;
    point_list.append( temp_point_list.next( index ) );
  }
}

void PointGridSearch::get_neighborhood_facets( DLIList<CubitFacet*> &facet_list )<--- The function 'get_neighborhood_facets' is never used.
{
  // retrieve points over the current bounding box range

  facet_list.clean_out();
  DLIList<CubitPoint*> point_list;
  get_neighborhood_points( point_list );

  // retrieve all faces attached to the points in point_list

  for (int i = 0; i < point_list.size(); i++)
  {
    CubitPoint* point = point_list.get_and_step();

    DLIList<CubitFacet*> temp_facet_list;
    point->facets(temp_facet_list);

    for (int j = 0; j < temp_facet_list.size(); j++)
    {
      CubitFacet* facet = temp_facet_list.get_and_step();

      if (!facet->marked())
      {
        facet->marked(CUBIT_TRUE);
        facet_list.append(facet);
      }
    }
  }

  // unmark the found faces and return face_list

  for (int m = 0; m < facet_list.size(); m++)
  {
    facet_list.get_and_step()->marked(CUBIT_FALSE);
  }

}

double PointGridSearch::fraction_empty_cells()<--- The function 'fraction_empty_cells' is never used.
{
  int empty_cell = 0;

  for (int i = 0; i < numberGridCells; i++)
  {
    if (!neighborhoodList[i]) empty_cell++;
  }

  return ((double) (empty_cell) / (double) (numberGridCells));
}

double PointGridSearch::average_points_per_occupied_cell()<--- The function 'average_points_per_occupied_cell' is never used.
{
  int total_points    = 0;
  int occupied_cells = 0;

  for (int i = 0; i < numberGridCells; i++)
  {
    if (neighborhoodList[i])
    {
      total_points += neighborhoodList[i]->size();
      occupied_cells++;
    }
  }

  return ((double) (total_points) / (double) (occupied_cells));
}

int PointGridSearch::total_points_in_grid_cells()<--- The function 'total_points_in_grid_cells' is never used.
{
  int total_points = 0;

  for (int i = 0; i < numberGridCells; i++)
  {
    if (neighborhoodList[i])
    {
      total_points += neighborhoodList[i]->size();
    }
  }

  return total_points;
}


void PointGridSearch::add_point_to_cell(CubitPoint* point, int i)
{
  if (neighborhoodList[i])
  {
    neighborhoodList[i]->append(point);
  }
  else
  {
    neighborhoodList[i] = new DLIList<CubitPoint*>;
    neighborhoodList[i]->append(point);
  }
}
void PointGridSearch::remove_point_from_cell(CubitPoint* point, int i)
{
  if( i < 0 ) return;
  if (neighborhoodList[i])
  { 
    if (neighborhoodList[i]->move_to(point))
    {
      neighborhoodList[i]->extract();
    }
    if (!neighborhoodList[i]->size())
    {
      delete neighborhoodList[i];
      neighborhoodList[i] = NULL;
    }
  }
}