@@ -48,6 +48,7 @@ FACSurface::~FACSurface()
4848{
4949 // got to clean some technical attributes used by ANN
5050 delete m_kd_tree;
51+ annDeallocPts (m_dataPts);
5152 annClose (); // done with ANN
5253}
5354/* ----------------------------------------------------------------------------*/
@@ -166,7 +167,10 @@ FACSurface::setMeshFaces(const std::vector<Face> &AFaces)
166167 m_mesh_faces[i] = AFaces[i].id ();
167168 }
168169
169- if (m_kd_tree != NULL ) delete m_kd_tree;
170+ if (m_kd_tree != nullptr ) {
171+ delete m_kd_tree;
172+ annDeallocPts (m_dataPts);
173+ }
170174
171175 buildANNTree ();
172176}
@@ -338,11 +342,11 @@ FACSurface::volumes()
338342void
339343FACSurface::buildANNTree ()
340344{
345+ if (m_kd_tree != nullptr ) throw GMDSException (" FACSurface Issue: the kd tree structure was previously initialized" );
341346
342347 int dim = 3 ; // dimension
343348 int maxPts = m_mesh_faces.size (); // maximum number of data points
344- ANNpointArray dataPts; // data points
345- dataPts = annAllocPts (maxPts, dim); // allocate data points
349+ m_dataPts = annAllocPts (maxPts, dim); // allocate data points
346350
347351 // ========================================================
348352 // (1) Fill in the ANN structure for storing points
@@ -353,16 +357,15 @@ FACSurface::buildANNTree()
353357
354358 while (nPts < maxPts) {
355359 math::Point p = m_support->get <Face>(m_mesh_faces[nPts]).center ();
356- dataPts [nPts][0 ] = p.X ();
357- dataPts [nPts][1 ] = p.Y ();
358- dataPts [nPts][2 ] = p.Z ();
360+ m_dataPts [nPts][0 ] = p.X ();
361+ m_dataPts [nPts][1 ] = p.Y ();
362+ m_dataPts [nPts][2 ] = p.Z ();
359363 nPts++;
360364 };
361365 // ========================================================
362366 // (2) Build the search structure
363367 // ========================================================
364- if (m_kd_tree != NULL ) throw GMDSException (" FACSurface Issue: the kd tree structure was previously initialized" );
365- m_kd_tree = new ANNkd_tree (dataPts, // the data points
368+ m_kd_tree = new ANNkd_tree (m_dataPts, // the data points
366369 nPts, // number of points
367370 dim); // dimension of space
368371}
@@ -388,6 +391,8 @@ FACSurface::getANNClosestTriangle(const math::Point &AP) const
388391 queryPt, // query point
389392 k, nnIdx, dists, 0.01 );
390393 int idx = nnIdx[0 ];
394+
395+ annDeallocPt (queryPt);
391396 delete[] nnIdx;
392397 delete[] dists;
393398
0 commit comments