*/
//================================================================================
-UnitTetraIntersectionBary::UnitTetraIntersectionBary()
+UnitTetraIntersectionBary::UnitTetraIntersectionBary():TransformedTriangle()
{
- init();
+ _intVolume = 0;
+ //init();
}
//================================================================================
/*!
void UnitTetraIntersectionBary::init()
{
- _volume = 0;
+ _intVolume = 0;
_faces.clear();
}
void UnitTetraIntersectionBary::addSide(const TransformedTriangle& triangle)
{
- _volume += triangle.getVolume();
+ _intVolume += triangle.getVolume();
double triNormal[3], polyNormal[3];
crossprod<3>( triangle.getCorner(P),triangle.getCorner(Q),triangle.getCorner(R), triNormal);
sortIntersectionPolygon(A, _barycenterA);
pPolygonA = & _polygonA;
}
- const vector<double*>& polygonA = *pPolygonA;
// check if polygon orientation is same as the one of triangle
- vector<double*>::const_iterator p = polygonA.begin(), pEnd = polygonA.end();
+ vector<double*>::const_iterator p = pPolygonA->begin(), pEnd = pPolygonA->end();
double* p1 = *p++;
double* p2 = *p;
while ( samePoint( p1, p2 ) && ++p != pEnd )
// store polygon
_faces.push_back( vector< double* > () );
vector< double* >& faceCorner = _faces.back();
- faceCorner.resize( polygonA.size()/* + 1*/ );
+ faceCorner.resize( pPolygonA->size()/* + 1*/ );
int i = 0;
if ( reverse ) {
- vector<double*>::const_reverse_iterator polyF = polygonA.rbegin(), polyEnd;
- for ( polyEnd = polygonA.rend(); polyF != polyEnd; ++i, ++polyF )
+ vector<double*>::const_reverse_iterator polyF = pPolygonA->rbegin(), polyEnd;
+ for ( polyEnd = pPolygonA->rend(); polyF != polyEnd; ++i, ++polyF )
if ( i==0 || !samePoint( *polyF, faceCorner[i-1] ))
copyVector3( *polyF, faceCorner[i] = new double[3] );
else
--i;
}
else {
- vector<double*>::const_iterator polyF = polygonA.begin(), polyEnd;
- for ( polyEnd = polygonA.end(); polyF != polyEnd; ++i, ++polyF )
+ vector<double*>::const_iterator polyF = pPolygonA->begin(), polyEnd;
+ for ( polyEnd = pPolygonA->end(); polyF != polyEnd; ++i, ++polyF )
if ( i==0 || !samePoint( *polyF, faceCorner[i-1] ))
copyVector3( *polyF, faceCorner[i] = new double[3] );
else
_faces.pop_back();
}
else {
- if ( i < polygonA.size() )
+ if ( i < pPolygonA->size() )
faceCorner.resize( i );
}
baryCenter[0] = baryCenter[1] = baryCenter[2] = -1.0;
if ( addSideFaces() < NB_TETRA_SIDES ) {
// tetra is not intersected
- if ( _volume != 0.0 ) {
+ if ( _intVolume != 0.0 ) {
// tetra is fully inside the other cell
baryCenter[0] = baryCenter[1] = baryCenter[2] = 0.25;
- _volume = 0.166667;
+ _intVolume = 0.166667;
return true;
}
return false;
baryCenter[1] += ( bary[1] * 0.75 + P[1] * 0.25 ) * vol;
baryCenter[2] += ( bary[2] * 0.75 + P[2] * 0.25 ) * vol;
}
- if ( _volume < 0. ) _volume = -_volume;
- baryCenter[0] /= _volume;
- baryCenter[1] /= _volume;
- baryCenter[2] /= _volume;
+ if ( _intVolume < 0. ) _intVolume = -_intVolume;
+ baryCenter[0] /= _intVolume;
+ baryCenter[1] /= _intVolume;
+ baryCenter[2] /= _intVolume;
return true;
}
}
}
// check if the segment p1-p2 is on the inclined side
- if ( epsilonEqual( p1[_X] + p1[_Y] + p1[_Z], 1.0 ) &&
+ if ( sideFaces[3] &&
+ epsilonEqual( p1[_X] + p1[_Y] + p1[_Z], 1.0 ) &&
epsilonEqual( p2[_X] + p2[_Y] + p2[_Z], 1.0 ))
{
sideFaces[3]->push_back( new double[3] );
void UnitTetraIntersectionBary::clearPolygons(bool andFaces)
{
for(vector<double*>::iterator it = _polygonA.begin() ; it != _polygonA.end() ; ++it)
- delete[] *it;
+ { delete[] *it; *it = 0; }
for(vector<double*>::iterator it = _polygonB.begin() ; it != _polygonB.end() ; ++it)
- delete[] *it;
+ { delete[] *it; *it = 0; }
_polygonA.clear();
_polygonB.clear();
if ( andFaces ) {
- list< vector< double* > >::iterator f = _faces.begin(), fEnd = _faces.end();
+ list< vector< double* > >::iterator f = this->_faces.begin(), fEnd = this->_faces.end();
for ( ; f != fEnd; ++f )
{
vector< double* >& polygon = *f;
for(vector<double*>::iterator it = polygon.begin() ; it != polygon.end() ; ++it)
- delete[] *it;
+ { delete[] *it; *it = 0; }
}
- _faces.clear();
+ this->_faces.clear();
}
}
+//================================================================================
+/*!
+ * \brief Destructor clears coordinates of faces
+ */
+//================================================================================
+
+UnitTetraIntersectionBary::~UnitTetraIntersectionBary()
+{
+ clearPolygons(/*andFaces=*/true );
+}
+
}