MeshKit  1.0
AF2PntTrnsfrmLnrV.cpp
Go to the documentation of this file.
00001 #include "meshkit/AF2PntTrnsfrmLnrV.hpp"
00002 
00003 // C++
00004 #include <cstddef>
00005 #include <sstream>
00006 
00007 // MeshKit
00008 #include "meshkit/Error.hpp"
00009 
00010 AF2PntTrnsfrmLnrV::AF2PntTrnsfrmLnrV(
00011     std::list<const AF2RuleExistVertex*> vertices,
00012     std::list<double> xDiffCoeff, std::list<double> yDiffCoeff) :
00013     refVertices(vertices.begin(), vertices.end()),
00014     xCoeff(xDiffCoeff.begin(), xDiffCoeff.end()),
00015     yCoeff(yDiffCoeff.begin(), yDiffCoeff.end())
00016 {
00017   if (xDiffCoeff.size() != 2 * vertices.size())
00018   {
00019     std::ostringstream errStringStream;
00020     errStringStream << "The list of x coefficients (size "
00021         << xDiffCoeff.size() << ") is not twice as long as the list of "
00022         << "vertices (size " << vertices.size() << ").";
00023     MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00024     badArg.set_string(errStringStream.str().c_str());
00025     throw badArg;
00026   }
00027   if (yDiffCoeff.size() != 2 * vertices.size())
00028   {
00029     std::ostringstream errStringStream;
00030     errStringStream << "The list of y coefficients (size "
00031         << yDiffCoeff.size() << ") is not twice as long as the list of "
00032         << "vertices (size " << vertices.size() << ").";
00033     MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00034     badArg.set_string(errStringStream.str().c_str());
00035     throw badArg;
00036   }
00037 }
00038 
00039 AF2PntTrnsfrmLnrV::AF2PntTrnsfrmLnrV(
00040     std::vector<const AF2RuleExistVertex*> vertices,
00041     std::vector<double> xDiffCoeff, std::vector<double> yDiffCoeff) :
00042     refVertices(vertices), xCoeff(xDiffCoeff), yCoeff(yDiffCoeff)
00043 {
00044   if (xDiffCoeff.size() != 2 * vertices.size())
00045   {
00046     std::ostringstream errStringStream;
00047     errStringStream << "The vector of x coefficients (size "
00048         << xDiffCoeff.size() << ") is not twice as long as the vector of "
00049         << "vertices (size " << vertices.size() << ").";
00050     MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00051     badArg.set_string(errStringStream.str().c_str());
00052     throw badArg;
00053   }
00054   if (yDiffCoeff.size() != 2 * vertices.size())
00055   {
00056     std::ostringstream errStringStream;
00057     errStringStream << "The vector of y coefficients (size "
00058         << yDiffCoeff.size() << ") is not twice as long as the vector of "
00059         << "vertices (size " << vertices.size() << ").";
00060     MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00061     badArg.set_string(errStringStream.str().c_str());
00062     throw badArg;
00063   }
00064 }
00065 
00066 AF2PntTrnsfrmLnrV* AF2PntTrnsfrmLnrV::clone() const
00067 {
00068   return new AF2PntTrnsfrmLnrV(refVertices, xCoeff, yCoeff);
00069 }
00070 
00071 AF2Point2D AF2PntTrnsfrmLnrV::transformPoint(AF2Point2D const & point,
00072     AF2Binding const & vBinding) const
00073 {
00074   double xOffset = 0.0;
00075   double yOffset = 0.0;
00076   for (unsigned int i = 0; i < refVertices.size(); ++i)
00077   {
00078     const AF2RuleExistVertex* refVertex = refVertices[i];
00079     const AF2Point2D* boundVal = vBinding.getBoundValue(refVertex);
00080     if (boundVal == NULL)
00081     {
00082       MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
00083       badArg.set_string("The binding does not have a bound value for all reference vertices.");
00084       throw badArg;
00085     }
00086     double xDiff = boundVal->getX() - refVertex->getX();
00087     double yDiff = boundVal->getY() - refVertex->getY();
00088     xOffset += xCoeff[2*i]*xDiff + xCoeff[2*i + 1]*yDiff;
00089     yOffset += yCoeff[2*i]*xDiff + yCoeff[2*i + 1]*yDiff;
00090   }
00091 
00092   AF2Point2D translated(point.getX() + xOffset, point.getY() + yOffset);
00093   return translated;
00094 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines