MeshKit  1.0
AF2FreeZoneDefLCQualLim.cpp
Go to the documentation of this file.
00001 // MeshhKit
00002 #include "meshkit/AF2FreeZoneDefLCQualLim.hpp"
00003 #include "meshkit/Error.hpp"
00004 
00005 AF2FreeZoneDefLCQualLim::AF2FreeZoneDefLCQualLim(
00006         std::list<AF2Point2D> const & preferBndryPnts,
00007         std::list<const AF2PointTransform*> const & preferPntTrnsfrms,
00008         std::list<AF2Point2D> const & limitBndryPnts,
00009         std::list<const AF2PointTransform*> const & limitPntTrnsfrms)
00010 {
00011   // confirm that the lists are the same size
00012   if ((preferBndryPnts.size() != preferPntTrnsfrms.size()) ||
00013       (preferBndryPnts.size() != limitBndryPnts.size()) ||
00014       (preferBndryPnts.size() != limitPntTrnsfrms.size()))
00015   {
00016     MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00017     badArg.set_string(
00018         "The lists passed to the constructor are not all the same size");
00019     throw badArg;
00020   }
00021 
00022   numPoints = preferBndryPnts.size();
00023   prefBndryPoints = new AF2Point2D[numPoints];
00024   prefPointTransforms = new const AF2PointTransform*[numPoints];
00025   limBndryPoints = new AF2Point2D[numPoints];
00026   limPointTransforms = new const AF2PointTransform*[numPoints];
00027   int pIndx = 0;
00028   for (std::list<AF2Point2D>::const_iterator itr =
00029       preferBndryPnts.begin(); itr != preferBndryPnts.end(); ++itr)
00030   {
00031     prefBndryPoints[pIndx] = *itr;
00032     ++pIndx;
00033   }
00034 
00035   pIndx = 0;
00036   for (std::list<const AF2PointTransform*>::const_iterator itr =
00037       preferPntTrnsfrms.begin(); itr != preferPntTrnsfrms.end(); ++itr)
00038   {
00039     prefPointTransforms[pIndx] = (*itr)->clone();
00040     ++pIndx;
00041   }
00042 
00043   pIndx = 0;
00044   for (std::list<AF2Point2D>::const_iterator itr =
00045       limitBndryPnts.begin(); itr != limitBndryPnts.end(); ++itr)
00046   {
00047     limBndryPoints[pIndx] = *itr;
00048     ++pIndx;
00049   }
00050 
00051   pIndx = 0;
00052   for (std::list<const AF2PointTransform*>::const_iterator itr =
00053       limitPntTrnsfrms.begin(); itr != limitPntTrnsfrms.end(); ++itr)
00054   {
00055     limPointTransforms[pIndx] = (*itr)->clone();
00056     ++pIndx;
00057   }
00058 }
00059 
00060 AF2FreeZoneDefLCQualLim::~AF2FreeZoneDefLCQualLim()
00061 {
00062   delete[] prefBndryPoints;
00063   delete[] limBndryPoints;
00064   for (int pIndx = 0; pIndx < numPoints; ++pIndx)
00065   {
00066     delete prefPointTransforms[pIndx];
00067     delete limPointTransforms[pIndx];
00068   }
00069   delete[] prefPointTransforms;
00070   delete[] limPointTransforms;
00071 }
00072 
00073 AF2FreeZoneDefLCQualLim::AF2FreeZoneDefLCQualLim(
00074     const AF2FreeZoneDefLCQualLim & toCopy)
00075 {
00076   numPoints = toCopy.numPoints;
00077   prefBndryPoints = new AF2Point2D[numPoints];
00078   prefPointTransforms = new const AF2PointTransform*[numPoints];
00079   limBndryPoints = new AF2Point2D[numPoints];
00080   limPointTransforms = new const AF2PointTransform*[numPoints];
00081   for (int pIndx = 0; pIndx < numPoints; ++pIndx)
00082   {
00083     prefBndryPoints[pIndx] = toCopy.prefBndryPoints[pIndx];
00084     prefPointTransforms[pIndx] = toCopy.prefPointTransforms[pIndx]->clone();
00085     limBndryPoints[pIndx] = toCopy.limBndryPoints[pIndx];
00086     limPointTransforms[pIndx] = toCopy.limPointTransforms[pIndx]->clone();
00087   }
00088 }
00089 
00090 AF2FreeZoneDefLCQualLim& AF2FreeZoneDefLCQualLim::operator=(
00091     const AF2FreeZoneDefLCQualLim & rhs)
00092 {
00093   // copy constructor functionality,
00094   // but to other parts of memory, not yet to this
00095   AF2Point2D* otherPrefBndryPoints = new AF2Point2D[numPoints];
00096   const AF2PointTransform** otherPrefPointTransforms =
00097       new const AF2PointTransform*[numPoints];
00098   AF2Point2D* otherLimBndryPoints = new AF2Point2D[numPoints];
00099   const AF2PointTransform** otherLimPointTransforms =
00100       new const AF2PointTransform*[numPoints];
00101   for (int pIndx = 0; pIndx < numPoints; ++pIndx)
00102   {
00103     otherPrefBndryPoints[pIndx] = rhs.prefBndryPoints[pIndx];
00104     otherPrefPointTransforms[pIndx] = rhs.prefPointTransforms[pIndx]->clone();
00105     otherLimBndryPoints[pIndx] = rhs.limBndryPoints[pIndx];
00106     otherLimPointTransforms[pIndx] = rhs.limPointTransforms[pIndx]->clone();
00107   }
00108 
00109   // destructor functionality
00110   delete[] prefBndryPoints;
00111   delete[] limBndryPoints;
00112   for (int pIndx = 0; pIndx < numPoints; ++pIndx)
00113   {
00114     delete prefPointTransforms[pIndx];
00115     delete limPointTransforms[pIndx];
00116   }
00117   delete[] prefPointTransforms;
00118   delete[] limPointTransforms;
00119 
00120   // transfer ownership from other parts of memory to this object
00121   numPoints = rhs.numPoints;
00122   prefBndryPoints = otherPrefBndryPoints;
00123   otherPrefBndryPoints = NULL; // not necessary, but to be explicit
00124   prefPointTransforms = otherPrefPointTransforms;
00125   otherPrefPointTransforms = NULL; // not necessary, but to be explicit
00126   limBndryPoints = otherLimBndryPoints;
00127   otherLimBndryPoints = NULL; // not necessary, but to be explicit
00128   limPointTransforms = otherLimPointTransforms;
00129   otherLimPointTransforms = NULL; // not necessary, but to be explicit
00130 
00131   // return this
00132   return *this;
00133 }
00134 
00135 AF2FreeZoneDefLCQualLim* AF2FreeZoneDefLCQualLim::clone() const
00136 {
00137   return new AF2FreeZoneDefLCQualLim(*this);
00138 }
00139 
00140 AF2FreeZone* AF2FreeZoneDefLCQualLim::makeFreeZone(
00141     AF2Binding const & vertexBinding, unsigned int qualityClass) const
00142 {
00143   // Check that the quality class is greater than zero
00144   if (qualityClass == 0)
00145   {
00146     MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00147     badArg.set_string("The quality class is not greater than zero.");
00148     throw badArg;
00149   }
00150 
00151   // compute the coefficients to use in the linear combination
00152   double prefCoeff = 1.0/qualityClass;
00153   double limCoeff = 1.0 - prefCoeff;
00154 
00155   // compute the list of actual free zone boundary points
00156   std::list<AF2Point2D> freeZoneBndry;
00157   for (int pIndx = 0; pIndx < numPoints; ++pIndx)
00158   {
00159     AF2Point2D prefPnt = prefPointTransforms[pIndx]->transformPoint(
00160         prefBndryPoints[pIndx], vertexBinding);
00161     AF2Point2D limPnt = limPointTransforms[pIndx]->transformPoint(
00162         limBndryPoints[pIndx], vertexBinding);
00163     AF2Point2D fzBndryPnt(
00164         prefCoeff * prefPnt.getX()  +  limCoeff * limPnt.getX(),
00165         prefCoeff * prefPnt.getY()  +  limCoeff * limPnt.getY());
00166     freeZoneBndry.push_back(fzBndryPnt);
00167   }
00168 
00169   // construct and return the free zone
00170   AF2FreeZone* freeZone = new AF2FreeZone(freeZoneBndry);
00171   return freeZone;
00172 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines