#include <algorithm>
#include <iostream>
+#include <memory>
#include <limits>
#include <cmath>
_terminal=true;
}
- double* nodes=new double [nbelems];
- _elems.resize(nbelems);
- for (ConnType i=0; i<nbelems; i++)
- {
- ConnType elem;
- if (elems!=0)
- elem= elems[i];
- else
- elem=i;
+ double median = std::numeric_limits<double>::max();
+ {
+ std::unique_ptr<double[]> nodes( new double [nbelems] );
+ _elems.resize(nbelems);
+ for (ConnType i=0; i<nbelems; i++)
+ {
+ ConnType elem;
+ if (elems)
+ elem= elems[i];
+ else
+ elem=i;
- _elems[i]=elem;
- nodes[i]=bbs[elem*dim*2+(level%dim)*2];
- }
- if (_terminal) { delete[] nodes; return;}
+ _elems[i]=elem;
+ nodes[i]=bbs[elem*dim*2+(level%dim)*2];
+ }
+ if (_terminal) { return; }
- std::nth_element<double*>(nodes, nodes+nbelems/2, nodes+nbelems);
- double median = *(nodes+nbelems/2);
- delete[] nodes;
+ std::nth_element<double*>(nodes.get(), nodes.get()+nbelems/2, nodes.get()+nbelems);
+ median = *(nodes.get()+nbelems/2);
+ }
// std:: cout << *median <<std::endl;
std::vector<ConnType> new_elems_left;
*
*/
BoundingBox::BoundingBox(const double** pts, const unsigned numPts)
+ {
+ initializeWith(pts,numPts);
+ }
+
+ void BoundingBox::fillInXMinXmaxYminYmaxZminZmaxFormat(double data[6]) const
+ {
+ data[0] = this->getCoordinate(BoundingBox::XMIN);
+ data[1] = this->getCoordinate(BoundingBox::XMAX);
+ data[2] = this->getCoordinate(BoundingBox::YMIN);
+ data[3] = this->getCoordinate(BoundingBox::YMAX);
+ data[4] = this->getCoordinate(BoundingBox::ZMIN);
+ data[5] = this->getCoordinate(BoundingBox::ZMAX);
+ }
+
+ /**
+ * Constructor creating box from an array of the points corresponding
+ * to the vertices of the element.
+ * Each point is represented by an array of three doubles.
+ *
+ * @param pts array of points
+ * @param numPts number of vertices
+ *
+ */
+ void BoundingBox::initializeWith(const double** pts, const unsigned numPts)
{
// initialize with first two points
const double *pt0(pts[0]);
class INTERPKERNEL_EXPORT BoundingBox
{
public:
-
/// Enumeration representing the six coordinates that define the bounding box
enum BoxCoord { XMIN = 0, YMIN = 1, ZMIN = 2, XMAX = 3, YMAX = 4, ZMAX = 5 };
-
+
+ BoundingBox() { }
+
BoundingBox(const double** pts, const unsigned numPts);
BoundingBox(const BoundingBox& box1, const BoundingBox& box2);
~BoundingBox() { }
+
+ void fillInXMinXmaxYminYmaxZminZmaxFormat(double data[6]) const;
+
+ void initializeWith(const double** pts, const unsigned numPts);
bool isDisjointWith(const BoundingBox& box) const;
// create BBTree structure
// - get bounding boxes
std::vector<double> bboxes(2*SPACEDIM*numSrcElems);
- ConnType* srcElemIdx = new ConnType[numSrcElems];
for(ConnType i = 0; i < numSrcElems ; ++i)
{
// get source bboxes in right order
srcElems[i]->getBoundingBox()->toCompactData(bboxes.data()+6*i);
- srcElemIdx[i] = srcElems[i]->getIndex();
}
adjustBoundingBoxes(bboxes);
const double *bboxPtr(nullptr);
if(numSrcElems>0)
bboxPtr=&bboxes[0];
- BBTree<SPACEDIM,ConnType> tree(bboxPtr, srcElemIdx, 0, numSrcElems);
+ BBTree<SPACEDIM,ConnType> tree(bboxPtr, nullptr, 0, numSrcElems);
const ConnType *trgConnPtr(targetMesh.getConnectivityPtr()),*trgConnIPtr(targetMesh.getConnectivityIndexPtr());
const ConnType *srcConnPtr(srcMesh.getConnectivityPtr()),*srcConnIPtr(srcMesh.getConnectivityIndexPtr());
const double *trgCooPtr(targetMesh.getCoordinatesPtr()),*srcCooPtr(srcMesh.getCoordinatesPtr());
}
}
}
- delete [] srcElemIdx;
for(ConnType i = 0 ; i < numSrcElems ; ++i)
delete srcElems[i];
return srcMesh.getNumberOfNodes();
// create BBTree structure
// - get bounding boxes
std::vector<double> bboxes(6 * numSrcElems);
- ConnType* srcElemIdx = new ConnType[numSrcElems];
for(ConnType i = 0; i < numSrcElems ; ++i)
{
// get source bboxes in right order
const BoundingBox* box = srcElems[i]->getBoundingBox();
- bboxes[6*i+0] = box->getCoordinate(BoundingBox::XMIN);
- bboxes[6*i+1] = box->getCoordinate(BoundingBox::XMAX);
- bboxes[6*i+2] = box->getCoordinate(BoundingBox::YMIN);
- bboxes[6*i+3] = box->getCoordinate(BoundingBox::YMAX);
- bboxes[6*i+4] = box->getCoordinate(BoundingBox::ZMIN);
- bboxes[6*i+5] = box->getCoordinate(BoundingBox::ZMAX);
-
- // source indices have to begin with zero for BBox, I think
- srcElemIdx[i] = srcElems[i]->getIndex();
+ box->fillInXMinXmaxYminYmaxZminZmaxFormat(bboxes.data()+6*i);
}
// [ABN] Adjust 2D bounding box (those might be flat in the cases where the 2D surf are perfectly aligned with the axis)
performAdjustmentOfBB(intersector, bboxes);
- BBTree<3,ConnType> tree(bboxes.data(), srcElemIdx, 0, numSrcElems, 0.);
+ BBTree<3,ConnType> tree(bboxes.data(), nullptr, 0, numSrcElems, 0.);
// for each target element, get source elements with which to calculate intersection
// - calculate intersection by calling intersectCells
for(ConnType i = 0; i < numTargetElems; ++i)
{
const BoundingBox* box = targetElems[i]->getBoundingBox();
- const ConnType targetIdx = targetElems[i]->getIndex();
// get target bbox in right order
double targetBox[6];
- targetBox[0] = box->getCoordinate(BoundingBox::XMIN);
- targetBox[1] = box->getCoordinate(BoundingBox::XMAX);
- targetBox[2] = box->getCoordinate(BoundingBox::YMIN);
- targetBox[3] = box->getCoordinate(BoundingBox::YMAX);
- targetBox[4] = box->getCoordinate(BoundingBox::ZMIN);
- targetBox[5] = box->getCoordinate(BoundingBox::ZMAX);
+ box->fillInXMinXmaxYminYmaxZminZmaxFormat(targetBox);
std::vector<ConnType> intersectElems;
tree.getIntersectingElems(targetBox, intersectElems);
if ( !intersectElems.empty() )
- intersector->intersectCells(targetIdx, intersectElems, matrix);
+ intersector->intersectCells(i, intersectElems, matrix);
}
- delete [] srcElemIdx;
-
DuplicateFacesType::iterator iter;
for (iter = intersectFaces.begin(); iter != intersectFaces.end(); ++iter)
{
// create BBTree structure
// - get bounding boxes
std::unique_ptr<double[]> bboxes( new double[6 * numSrcElems] );
- std::unique_ptr<ConnType[]> srcElemIdx( new ConnType[numSrcElems] );
for(ConnType i = 0; i < numSrcElems ; ++i)
{
// get source bboxes in right order
- const BoundingBox* box = srcElems[i]->getBoundingBox();
- bboxes[6*i+0] = box->getCoordinate(BoundingBox::XMIN);
- bboxes[6*i+1] = box->getCoordinate(BoundingBox::XMAX);
- bboxes[6*i+2] = box->getCoordinate(BoundingBox::YMIN);
- bboxes[6*i+3] = box->getCoordinate(BoundingBox::YMAX);
- bboxes[6*i+4] = box->getCoordinate(BoundingBox::ZMIN);
- bboxes[6*i+5] = box->getCoordinate(BoundingBox::ZMAX);
-
- // source indices have to begin with zero for BBox, I think
- srcElemIdx[i] = srcElems[i]->getIndex();
+ const BoundingBox *box = srcElems[i]->getBoundingBox();
+ box->fillInXMinXmaxYminYmaxZminZmaxFormat(bboxes.get()+6*i);
}
- BBTree<3,ConnType> tree(bboxes.get(), srcElemIdx.get(), 0, numSrcElems);
+ BBTree<3,ConnType> tree(bboxes.get(), nullptr, 0, numSrcElems);
// for each target element, get source elements with which to calculate intersection
// - calculate intersection by calling intersectCells
for(ConnType i = 0; i < numTargetElems; ++i)
{
const BoundingBox* box = targetElems[i]->getBoundingBox();
- const ConnType targetIdx = targetElems[i]->getIndex();
// get target bbox in right order
double targetBox[6];
- targetBox[0] = box->getCoordinate(BoundingBox::XMIN);
- targetBox[1] = box->getCoordinate(BoundingBox::XMAX);
- targetBox[2] = box->getCoordinate(BoundingBox::YMIN);
- targetBox[3] = box->getCoordinate(BoundingBox::YMAX);
- targetBox[4] = box->getCoordinate(BoundingBox::ZMIN);
- targetBox[5] = box->getCoordinate(BoundingBox::ZMAX);
+ box->fillInXMinXmaxYminYmaxZminZmaxFormat(targetBox);
std::vector<ConnType> intersectElems;
tree.getIntersectingElems(targetBox, intersectElems);
if ( !intersectElems.empty() )
- intersector->intersectCells(targetIdx,intersectElems,result);
+ intersector->intersectCells(i,intersectElems,result);
}
#endif
// create BBTree structure
// - get bounding boxes
std::vector<double> bboxes(6*numSrcElems);
- std::unique_ptr<ConnType[]> srcElemIdx{ new ConnType[numSrcElems] };
for(ConnType i = 0; i < numSrcElems ; ++i)
{
// get source bboxes in right order
const BoundingBox* box = srcElems[i]->getBoundingBox();
- bboxes[6*i+0] = box->getCoordinate(BoundingBox::XMIN);
- bboxes[6*i+1] = box->getCoordinate(BoundingBox::XMAX);
- bboxes[6*i+2] = box->getCoordinate(BoundingBox::YMIN);
- bboxes[6*i+3] = box->getCoordinate(BoundingBox::YMAX);
- bboxes[6*i+4] = box->getCoordinate(BoundingBox::ZMIN);
- bboxes[6*i+5] = box->getCoordinate(BoundingBox::ZMAX);
-
- srcElemIdx[i] = srcElems[i]->getIndex();
+ box->fillInXMinXmaxYminYmaxZminZmaxFormat(bboxes.data()+6*i);
}
adjustBoundingBoxes(bboxes);
const double *bboxPtr = nullptr;
if(numSrcElems>0)
bboxPtr=bboxes.data();
- BBTree<3,ConnType> tree(bboxPtr, srcElemIdx.get(), 0, numSrcElems);
+ BBTree<3,ConnType> tree(bboxPtr, nullptr, 0, numSrcElems);
// for each target element, get source elements with which to calculate intersection
// - calculate intersection by calling intersectCells
for(ConnType i = 0; i < numTargetElems; ++i)
{
const BoundingBox* box = targetElems[i]->getBoundingBox();
- const ConnType targetIdx = targetElems[i]->getIndex();
-
// get target bbox in right order
double targetBox[6];
- targetBox[0] = box->getCoordinate(BoundingBox::XMIN);
- targetBox[1] = box->getCoordinate(BoundingBox::XMAX);
- targetBox[2] = box->getCoordinate(BoundingBox::YMIN);
- targetBox[3] = box->getCoordinate(BoundingBox::YMAX);
- targetBox[4] = box->getCoordinate(BoundingBox::ZMIN);
- targetBox[5] = box->getCoordinate(BoundingBox::ZMAX);
+ box->fillInXMinXmaxYminYmaxZminZmaxFormat(targetBox);
std::vector<ConnType> intersectElems;
tree.getIntersectingElems(targetBox, intersectElems);
if ( !intersectElems.empty() )
- intersector->intersectCells(targetIdx,intersectElems,result);
+ intersector->intersectCells(i,intersectElems,result);
}
return intersector->getNumberOfColsOfResMatrix();
}
template<class MyMeshType>
MeshElement(const ConnType index, const MyMeshType& mesh);
- ~MeshElement();
-
- ConnType getIndex() const { return _index; }
+ ~MeshElement() { }
nbnodesincelltype getNumberOfNodes() const { return _number; }
- const BoundingBox* getBoundingBox() const { return _box; }
+ const BoundingBox *getBoundingBox() const { return &_box; }
private:
/// disallow copying
/// disallow assignment
MeshElement& operator=(const MeshElement& elem);
- /// global number of the element
- const ConnType _index;
-
nbnodesincelltype _number;
/// bounding box of the element - does not change after having been initialised
- BoundingBox* _box;
+ BoundingBox _box;
};
/**
#include <assert.h>
#include <type_traits>
#include <limits>
+#include <memory>
namespace INTERP_KERNEL
{
template<class ConnType>
template<class MyMeshType>
MeshElement<ConnType>::MeshElement(const ConnType index, const MyMeshType& mesh)
- : _index(index), _number( 0 ), _box(nullptr)
+ : _number( 0 )
{
auto numberCore = mesh.getNumberOfNodesOfElement(OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index));
if(numberCore < std::numeric_limits<nbnodesincelltype>::max())
{
_number = static_cast< nbnodesincelltype >(numberCore);
- const double**vertices = new const double*[_number];
+ std::unique_ptr<const double*[]> vertices( new const double*[_number] );
for( nbnodesincelltype i = 0 ; i < _number ; ++i)
vertices[i] = getCoordsOfNode(i , OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index), mesh);
// create bounding box
- _box = new BoundingBox(vertices,_number);
- delete [] vertices;
+ _box.initializeWith(vertices.get(),_number);
}
else
{
- std::cerr << "ERROR at index " << index << " : exceeding capacity !" << std::endl;
+ THROW_IK_EXCEPTION("ERROR at index " << index << " : exceeding capacity !");
}
}
-
- /**
- * Destructor
- *
- */
- template<class ConnType>
- MeshElement<ConnType>::~MeshElement()
- {
- delete _box;
- }
/////////////////////////////////////////////////////////////////////
/// ElementBBoxOrder /////////////