MeshKit  1.0
AF2Neighborhood.cpp
Go to the documentation of this file.
00001 #include "meshkit/AF2Neighborhood.hpp"
00002 
00003 // MeshKit
00004 #include "meshkit/Error.hpp"
00005 
00006 // C++
00007 #include <set>
00008 
00009 AF2Neighborhood::AF2Neighborhood(const std::list<AF2Point3D*> & points,
00010     AF2Edge3D* baselineEdge,
00011     const std::list<const AF2Edge3D*> & otherEdges,
00012     const AF2LocalTransform* localTransformArg)
00013 {
00014   typedef std::list<AF2Point3D*>::const_iterator ConstPoint3DItr;
00015   typedef std::list<const AF2Edge3D*>::const_iterator ConstEdge3DItr;
00016   typedef std::map<AF2Point3D*, const AF2Point2D*>::const_iterator MapItr;
00017 
00018   std::set<AF2Point3D*> illegalPoints;
00019 
00020   baseEdge3D = baselineEdge;
00021   localTransform = localTransformArg;
00022 
00023   for (ConstPoint3DItr itr = points.begin(); itr != points.end(); ++itr)
00024   {
00025     bool legal = true;
00026     AF2Point2D* point2D = localTransform->transformFromSurface(**itr, legal);
00027     if (legal)
00028     {
00029       points2D.push_back(point2D);
00030       map2DTo3D[point2D] = *itr;
00031     }
00032     else
00033     {
00034       illegalPoints.insert(*itr);
00035     }
00036     map3DTo2D[*itr] = point2D;
00037   }
00038 
00039   MapItr baseStartItr = map3DTo2D.find(baselineEdge->getStart());
00040   MapItr baseEndItr = map3DTo2D.find(baselineEdge->getEnd());
00041   if (baseStartItr == map3DTo2D.end() || baseEndItr == map3DTo2D.end())
00042   {
00043     MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00044     badArg.set_string(
00045         "A baseline edge endpoint is not listed in the neighborhood points.");
00046     throw badArg;
00047   }
00048   baseEdge2D = new AF2Edge2D(baseStartItr->second, baseEndItr->second);
00049   edges2D.push_back(baseEdge2D);
00050 
00051   for (ConstEdge3DItr itr = otherEdges.begin();
00052       itr != otherEdges.end(); ++itr)
00053   {
00054     if (*itr == baselineEdge)
00055     {
00056       // the baseline edge should be listed only once (and listed first)
00057       // in the list of edges
00058       continue;
00059     }
00060     MapItr startItr = map3DTo2D.find((*itr)->getStart());
00061     MapItr endItr = map3DTo2D.find((*itr)->getEnd());
00062     if (startItr == map3DTo2D.end() || endItr == map3DTo2D.end())
00063     {
00064       MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00065       badArg.set_string(
00066           "An edge endpoint is not listed in the neighborhood points.");
00067       throw badArg;
00068     }
00069     if ((illegalPoints.find((*itr)->getStart()) != illegalPoints.end()) ||
00070         (illegalPoints.find((*itr)->getEnd()) != illegalPoints.end()))
00071     {
00072       // Don't create an edge if its endpoints are illegal
00073       // TODO: Decide whether there is something better to do if one endpoint
00074       // is legal and the other is not legal
00075       continue;
00076     }
00077     const AF2Edge2D* edge2D =
00078         new AF2Edge2D(startItr->second, endItr->second);
00079     edges2D.push_back(edge2D);
00080   }
00081 }
00082 
00083 AF2Neighborhood::~AF2Neighborhood()
00084 {
00085   typedef std::list<const AF2Point2D*>::const_iterator ConstPoint2DItr;
00086   typedef std::list<const AF2Edge2D*>::const_iterator ConstEdge2DItr;
00087 
00088   for (ConstEdge2DItr itr = edges2D.begin(); itr != edges2D.end(); ++itr)
00089   {
00090     delete *itr;
00091   }
00092   for (ConstPoint2DItr itr = points2D.begin(); itr != points2D.end(); ++itr)
00093   {
00094     delete *itr;
00095   }
00096   delete localTransform;
00097 }
00098 
00099 AF2Neighborhood::AF2Neighborhood(const AF2Neighborhood & toCopy)
00100 {
00101   MeshKit::Error notImpl(MeshKit::MK_NOT_IMPLEMENTED);
00102   notImpl.set_string("AF2Neighborhood copy construction is not supported.");
00103   throw notImpl;
00104 }
00105 
00106 AF2Neighborhood& AF2Neighborhood::operator=(const AF2Neighborhood & rhs)
00107 {
00108   MeshKit::Error notImpl(MeshKit::MK_NOT_IMPLEMENTED);
00109   notImpl.set_string("AF2Neighborhood assignment operator is not supported.");
00110   throw notImpl;
00111 }
00112 
00113 const AF2Edge2D* AF2Neighborhood::getBaselineEdge2D() const
00114 {
00115   return baseEdge2D;
00116 }
00117 
00118 AF2Edge3D* AF2Neighborhood::getBaselineEdge3D() const
00119 {
00120   return baseEdge3D;
00121 }
00122 
00123 AF2Point3D* AF2Neighborhood::getCorrespondingPoint(
00124     const AF2Point2D* const & ngbhdPoint2D) const
00125 {
00126   typedef std::map<const AF2Point2D*, AF2Point3D*>::const_iterator MapItr;
00127   MapItr ngbhdPntItr = map2DTo3D.find(ngbhdPoint2D);
00128   if (ngbhdPntItr == map2DTo3D.end())
00129   {
00130     return NULL;
00131   }
00132   return ngbhdPntItr->second;
00133 }
00134 
00135 const std::list<const AF2Edge2D*>* AF2Neighborhood::getEdges2D() const
00136 {
00137   return &edges2D;
00138 }
00139 
00140 const std::list<const AF2Point2D*>* AF2Neighborhood::getPoints2D() const
00141 {
00142   return &points2D;
00143 }
00144 
00145 AF2Point3D* AF2Neighborhood::transformPoint(
00146     const AF2Point2D* const & point2D, unsigned long const & pntId) const
00147 {
00148   return localTransform->transformToSurface(*point2D, pntId);
00149 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines