}
/*
- * Destructor
+ * Destruct
*
*/
Intersector3D::~Intersector3D()
{
+ for (map<medGeometryElement, CELLMODEL*>::iterator it=_cellmodel_map.begin();
+ it!=_cellmodel_map.end();
+ it++)
+ delete it->second;
}
/*
{
// get cell model for the element
- CELLMODEL cellModel(type);
+ CELLMODEL* cellModel=retrieveCellModel(type);
- assert(cellModel.getDimension() == 3);
+ assert(cellModel->getDimension() == 3);
assert(element >= 1);
assert(element <= _srcMesh.getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS));
// try to avoid reallocations with push_back()
// 2 * the number of faces should be plenty
- triangles.reserve(2 * cellModel.getNumberOfConstituents(1));
+ triangles.reserve(2 * cellModel->getNumberOfConstituents(1));
// loop over faces
- double** transformedNodes = new double*[cellModel.getNumberOfNodes()];
+ double** transformedNodes = new double*[cellModel->getNumberOfNodes()];
bool isOutside[8] = {true, true, true, true, true, true, true, true};
bool isTargetOutside = false;
// calculate the coordinates of the nodes
- for(int i = 1; i <= cellModel.getNumberOfNodes() ; ++i)
+ for(int i = 1; i <= cellModel->getNumberOfNodes() ; ++i)
{
const double* node = getCoordsOfNode(i, element, _srcMesh);
transformedNodes[i-1] = new double[3];
if(!isTargetOutside)
{
- for(int i = 1 ; i <= cellModel.getNumberOfConstituents(1) ; ++i)
+ for(int i = 1 ; i <= cellModel->getNumberOfConstituents(1) ; ++i)
{
- const medGeometryElement faceType = cellModel.getConstituentType(1, i);
+ const medGeometryElement faceType = cellModel->getConstituentType(1, i);
CELLMODEL faceModel(faceType);
assert(faceModel.getDimension() == 2);
// get the nodes of the face
for(int j = 1; j <= faceModel.getNumberOfNodes(); ++j)
{
- nodes[j-1] = cellModel.getNodeConstituent(1, i, j) - 1;
+ nodes[j-1] = cellModel->getNodeConstituent(1, i, j) - 1;
assert(nodes[j-1] +1 >= 0);
- assert(nodes[j-1] +1 <= cellModel.getNumberOfNodes());
+ assert(nodes[j-1] +1 <= cellModel->getNumberOfNodes());
}
// std::cout << "here3 : " << nodes[0] << "," << nodes[1] << ", " << nodes[2] << std::endl;
// create transformed triangles from face
++filtered;
}
- for(int i = 0 ; i < cellModel.getNumberOfNodes() ; ++i)
+ for(int i = 0 ; i < cellModel->getNumberOfNodes() ; ++i)
{
delete[] transformedNodes[i];
}
void Intersector3D::triangulate(const medGeometryElement type, const int element, std::vector<TransformedTriangle>& triangles, const TetraAffineTransform& T) const
{
// get cell model for the element
- CELLMODEL cellModel(type);
+ CELLMODEL* cellModel=retrieveCellModel(type);
assert(element >= 1);
assert(element <= _srcMesh.getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS));
- assert(cellModel.getDimension() == 3);
+ assert(cellModel->getDimension() == 3);
// loop over faces
- for(int i = 1 ; i <= cellModel.getNumberOfConstituents(1) ; ++i)
+ for(int i = 1 ; i <= cellModel->getNumberOfConstituents(1) ; ++i)
{
- medGeometryElement faceType = cellModel.getConstituentType(1, i);
+ medGeometryElement faceType = cellModel->getConstituentType(1, i);
CELLMODEL faceModel(faceType);
assert(faceModel.getDimension() == 2);
for(int j = 1; j <= faceModel.getNumberOfNodes(); ++j)
{
// offset of node from cellIdx
- int localNodeNumber = cellModel.getNodeConstituent(1, i, j);
+ int localNodeNumber = cellModel->getNodeConstituent(1, i, j);
assert(localNodeNumber >= 1);
- assert(localNodeNumber <= cellModel.getNumberOfNodes());
+ assert(localNodeNumber <= cellModel->getNumberOfNodes());
const double* node = getCoordsOfNode(localNodeNumber, element, _srcMesh);
}
#endif
-
+CELLMODEL* retrieveCellModel(const medGeometryElement type)
+{
+ map<medGeometryElement, CELLMODEL*>::iterator it = _cellmodel_map.find(type);
+ if (it!=_cellmodel_map.end())
+ return iter->second;
+ else
+ {
+ CELLMODEL* cellmodel=new CELLMODEL(type);
+ _cellmodel_map.insert(make_pair(type,cellmodel));
+ return cellmodel;
+ }
+}
+}
};