MeshKit  1.0
dfltTriRules.cpp
Go to the documentation of this file.
00001 
00015 // C++
00016 #include <cstddef>
00017 #include <iostream>
00018 #include <string>
00019 #include <vector>
00020 
00021 // MeshKit
00022 #include "meshkit/AF2DfltTriangleRules.hpp"
00023 #include "meshkit/AF2Edge3D.hpp"
00024 #include "meshkit/AF2Neighborhood.hpp"
00025 #include "meshkit/AF2PlaneProjection.hpp"
00026 #include "meshkit/AF2Point3D.hpp"
00027 #include "meshkit/AF2Rule.hpp"
00028 #include "meshkit/AF2RuleAppVisitor.hpp"
00029 #include "meshkit/MKCore.hpp"
00030 #include "meshkit/ModelEnt.hpp"
00031 #include "meshkit/Matrix.hpp"
00032 
00033 // MeshKit testing
00034 #include "TestUtil.hpp"
00035 
00036 // define the geometry file extension depending on the geometry model
00037 #if HAVE_OCC
00038 #define FILE_EXT "stp"
00039 #else
00040 #define FILE_EXT "facet"
00041 #endif
00042 
00043 const AF2Rule* findRule(
00044     const AF2DfltTriangleRules & ruleSet, const std::string & ruleName);
00045 AF2LocalTransform* makePlaneProj();
00046 void test180DegreeRuleQ1();
00047 void test180DegreeRuleQ5();
00048 void test180DegreeRuleQ10();
00049 void test180DegreeRuleQ20();
00050 void test60DegreeAngleRightRule();
00051 void test60DegreeAngleLeftRule();
00052 void test120DegreeAngleRightRule();
00053 void test120DegreeAngleLeftRule();
00054 void test120DegreeAngleBothRule();
00055 void testFillTriangleRule();
00056 void testConnectVertexRule();
00057 void testConnectEdgeRule();
00058 
00059 class SaveLastVisitor : public AF2RuleAppVisitor
00060 {
00061   private:
00062     unsigned int count;
00063     AF2RuleApplication* lastRuleApp;
00064   public:
00065     SaveLastVisitor()
00066     {
00067       count = 0u;
00068       lastRuleApp = NULL;
00069     }
00070 
00071     ~SaveLastVisitor()
00072     {
00073       if (lastRuleApp != NULL)
00074       {
00075         delete lastRuleApp;
00076       }
00077     }
00078 
00079     void visit(AF2RuleApplication const & ruleApp)
00080     {
00081       ++count;
00082       if (lastRuleApp != NULL)
00083       {
00084         delete lastRuleApp;
00085       }
00086       lastRuleApp = new AF2RuleApplication(ruleApp);
00087     }
00088 
00089     AF2RuleApplication* getLast() const
00090     {
00091       return lastRuleApp;
00092     }
00093 
00094     unsigned int getVisitCount() const
00095     {
00096       return count;
00097     }
00098 };
00099 
00100 // This variable is at global scope because (1) calling deleteAll on
00101 // the MKCore geometry instance appears to cause memory inconsistencies
00102 // with later use of the geometry instance and (2) it is more efficient
00103 // to load the geometry model only once
00104 MeshKit::ModelEnt* square = NULL;
00105 
00106 int main(int argc, char **argv)
00107 {
00108   // This variable is defined and used in main because a new MKCore
00109   // instance cannot be easily constructed after another MKCore
00110   // instance is deleted; there are problems with a tag left behind in
00111   // iGeom.
00112   MeshKit::MKCore* mk = new MeshKit::MKCore();
00113 
00114   // load a square in plane z = 0.5 with -1.0 <= x <= 0 and -0.5 <= y <= 0.5
00115   std::string file_name = TestDir + "/squaresurf." + FILE_EXT;
00116   mk->load_geometry_mesh(file_name.c_str(), file_name.c_str());
00117   MeshKit::MEntVector surfs;
00118   mk->get_entities_by_dimension(2, surfs);
00119   square = *surfs.begin();
00120 
00121   // start up MK and load the geometry
00122   int num_fail = 0;
00123 
00124   num_fail += RUN_TEST(test180DegreeRuleQ1);
00125   num_fail += RUN_TEST(test180DegreeRuleQ5);
00126   num_fail += RUN_TEST(test180DegreeRuleQ10);
00127   num_fail += RUN_TEST(test180DegreeRuleQ20);
00128   num_fail += RUN_TEST(test60DegreeAngleRightRule);
00129   num_fail += RUN_TEST(test60DegreeAngleLeftRule);
00130   num_fail += RUN_TEST(test120DegreeAngleRightRule);
00131   num_fail += RUN_TEST(test120DegreeAngleLeftRule);
00132   num_fail += RUN_TEST(test120DegreeAngleBothRule);
00133   num_fail += RUN_TEST(testFillTriangleRule);
00134   num_fail += RUN_TEST(testConnectVertexRule);
00135   num_fail += RUN_TEST(testConnectEdgeRule);
00136 
00137   delete mk;
00138 
00139   return num_fail;
00140 }
00141 
00142 const AF2Rule* findRule(
00143     const AF2DfltTriangleRules & ruleSet, const std::string & ruleName)
00144 {
00145   typedef std::list<const AF2Rule*>::const_iterator RuleListItr;
00146 
00147   std::list<const AF2Rule*> ruleList = ruleSet.getRules();
00148   for (RuleListItr itr = ruleList.begin(); itr != ruleList.end(); ++itr)
00149   {
00150     if (ruleName == (*itr)->getName())
00151     {
00152       return *itr;
00153     }
00154   }
00155 
00156   return NULL;
00157 }
00158 
00159 AF2LocalTransform* makePlaneProj()
00160 {
00161   MeshKit::Vector<3> origin;
00162   origin[0] = -0.5;
00163   origin[1] = 0.0;
00164   origin[2] = 0.5;
00165   MeshKit::Vector<3> normal;
00166   normal[0] = 0.0;
00167   normal[1] = 0.0;
00168   normal[2] = 1.0;
00169   MeshKit::Vector<3> xDir;
00170   xDir[0] = 1.0;
00171   xDir[1] = 0.0;
00172   xDir[2] = 0.0;
00173 
00174   return new AF2PlaneProjection(square->igeom_instance(),
00175       square->geom_handle(), origin, normal, xDir, 0.125);
00176 }
00177 
00178 void test180DegreeRuleQ1()
00179 {
00180   AF2DfltTriangleRules triRules;
00181   const AF2Rule* rule180DegreeQ1 =
00182       findRule(triRules, "Triangle Off Line, Quality Level 1");
00183 
00184   CHECK(rule180DegreeQ1 != NULL);
00185 
00186   std::vector<AF2Point3D*> pointsVector;
00187   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
00188   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
00189   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
00190   pointsVector.push_back(new AF2Point3D(3, -0.25, 0.0, 0.5));
00191   pointsVector.push_back(new AF2Point3D(4, -0.3748, 0.0, 0.5));
00192   pointsVector.push_back(new AF2Point3D(5, -0.3123, 0.0876, 0.5));
00193   pointsVector.push_back(new AF2Point3D(6, -0.4375, 0.1877, 0.5));
00194   pointsVector.push_back(new AF2Point3D(7, -0.5627, 0.0876, 0.5));
00195   pointsVector.push_back(new AF2Point3D(8, -0.5002, 0.0, 0.5));
00196 
00197   std::list<AF2Point3D*> points;
00198 
00199   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00200   {
00201     points.push_back(pointsVector[pi]);
00202   }
00203 
00204   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
00205 
00206   std::list<const AF2Edge3D*> edges;
00207   // basic line
00208   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00209   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
00210   // lines bounding the expected free zone location
00211   edges.push_back(new AF2Edge3D(pointsVector[4], pointsVector[5]));
00212   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00213   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00214   edges.push_back(new AF2Edge3D(pointsVector[7], pointsVector[8]));
00215 
00216   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00217 
00218   SaveLastVisitor visitor;
00219   rule180DegreeQ1->applyRule(ngbhd, 1u, visitor);
00220 
00221   CHECK_EQUAL(1u, visitor.getVisitCount());
00222   std::cout << "Good: There is one way to apply the default triangle rule\n"
00223       << "  named \"" << rule180DegreeQ1->getName() << "\"" << std::endl;
00224   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
00225   CHECK_REAL_EQUAL(0.866, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
00226   std::cout << "Good: The new point is located near (0.5, 0.866)" << std::endl;
00227   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
00228   std::cout << "Good: There is one new face" << std::endl;
00229 
00230   SaveLastVisitor failVisitor;
00231   AF2Point3D failPointAlpha(9, -0.3752, 0.0001, 0.5);
00232   points.push_back(&failPointAlpha);
00233   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00234   rule180DegreeQ1->applyRule(failNgbhdAlpha, 1u, failVisitor);
00235   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00236   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00237       << "  has a point at (-0.3752, 0.0001, 0.5)" << std::endl;
00238   points.pop_back();
00239 
00240   AF2Point3D failPointBravo(10, -0.3127, 0.0874, 0.5);
00241   points.push_back(&failPointBravo);
00242   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00243   rule180DegreeQ1->applyRule(failNgbhdBravo, 1u, failVisitor);
00244   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00245   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00246       << "  has a point at (-0.3127, 0.0874, 0.5)" << std::endl;
00247   points.pop_back();
00248 
00249   AF2Point3D failPointCharlie(11, -0.4375, 0.1873, 0.5);
00250   points.push_back(&failPointCharlie);
00251   AF2Neighborhood failNgbhdCharlie(points,
00252       baselineEdge, edges, makePlaneProj());
00253   rule180DegreeQ1->applyRule(failNgbhdCharlie, 1u, failVisitor);
00254   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00255   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00256       << "  has a point at (-0.4375, 0.1873, 0.5)" << std::endl;
00257   points.pop_back();
00258 
00259   AF2Point3D failPointDelta(12, -0.5623, 0.0874, 0.5);
00260   points.push_back(&failPointDelta);
00261   AF2Neighborhood failNgbhdDelta(points,
00262       baselineEdge, edges, makePlaneProj());
00263   rule180DegreeQ1->applyRule(failNgbhdDelta, 1u, failVisitor);
00264   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00265   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00266       << "  has a point at (-0.5623, 0.0874, 0.5)" << std::endl;
00267   points.pop_back();
00268 
00269   AF2Point3D failPointEcho(13, -0.4998, 0.0001, 0.5);
00270   points.push_back(&failPointEcho);
00271   AF2Neighborhood failNgbhdEcho(points,
00272       baselineEdge, edges, makePlaneProj());
00273   rule180DegreeQ1->applyRule(failNgbhdEcho, 1u, failVisitor);
00274   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00275   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00276       << "  has a point at (-0.4998, 0.0001, 0.5)" << std::endl;
00277   points.pop_back();
00278 
00279 
00280   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
00281       itr != edges.end(); ++itr)
00282   {
00283     delete *itr;
00284   }
00285   delete baselineEdge;
00286   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00287   {
00288     delete pointsVector[pi];
00289   }
00290 
00291   std::cout << "PASS: The 180DegreeRuleQ1 passes the test." << std::endl;
00292 }
00293 
00294 void test180DegreeRuleQ5()
00295 {
00296   AF2DfltTriangleRules triRules;
00297   const AF2Rule* rule180DegreeQ5 =
00298       findRule(triRules, "Triangle Off Line, Quality Level 5");
00299 
00300   CHECK(rule180DegreeQ5 != NULL);
00301 
00302   std::vector<AF2Point3D*> pointsVector;
00303   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
00304   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
00305   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
00306   pointsVector.push_back(new AF2Point3D(3, -0.25, 0.0, 0.5));
00307   pointsVector.push_back(new AF2Point3D(4, -0.3748, 0.0, 0.5));
00308   pointsVector.push_back(new AF2Point3D(5, -0.4248, 0.0676, 0.5));
00309   pointsVector.push_back(new AF2Point3D(6, -0.4502, 0.0676, 0.5));
00310   pointsVector.push_back(new AF2Point3D(7, -0.5002, 0.0, 0.5));
00311 
00312   std::list<AF2Point3D*> points;
00313 
00314   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00315   {
00316     points.push_back(pointsVector[pi]);
00317   }
00318 
00319   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
00320 
00321   std::list<const AF2Edge3D*> edges;
00322   // basic line
00323   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00324   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
00325   // lines bounding the expected free zone location
00326   edges.push_back(new AF2Edge3D(pointsVector[4], pointsVector[5]));
00327   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00328   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00329 
00330   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00331 
00332   SaveLastVisitor visitor;
00333   rule180DegreeQ5->applyRule(ngbhd, 5u, visitor);
00334 
00335   CHECK_EQUAL(1u, visitor.getVisitCount());
00336   std::cout << "Good: There is one way to apply the default triangle rule\n"
00337       << "  named \"" << rule180DegreeQ5->getName() << "\"" << std::endl;
00338   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
00339   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
00340   std::cout << "Good: The new point is located near (0.5, 0.5)" << std::endl;
00341   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
00342   std::cout << "Good: There is one new face" << std::endl;
00343 
00344   SaveLastVisitor failVisitor;
00345   AF2Point3D failPointAlpha(8, -0.3752, 0.0001, 0.5);
00346   points.push_back(&failPointAlpha);
00347   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00348   rule180DegreeQ5->applyRule(failNgbhdAlpha, 5u, failVisitor);
00349   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00350   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00351       << "  has a point at (-0.3752, 0.0001, 0.5)" << std::endl;
00352   points.pop_back();
00353 
00354   AF2Point3D failPointBravo(9, -0.4252, 0.0674, 0.5);
00355   points.push_back(&failPointBravo);
00356   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00357   rule180DegreeQ5->applyRule(failNgbhdBravo, 5u, failVisitor);
00358   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00359   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00360       << "  has a point at (-0.4252, 0.0674, 0.5)" << std::endl;
00361   points.pop_back();
00362 
00363   AF2Point3D failPointCharlie(10, -0.4498, 0.0674, 0.5);
00364   points.push_back(&failPointCharlie);
00365   AF2Neighborhood failNgbhdCharlie(points,
00366       baselineEdge, edges, makePlaneProj());
00367   rule180DegreeQ5->applyRule(failNgbhdCharlie, 5u, failVisitor);
00368   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00369   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00370       << "  has a point at (-0.4498, 0.0674, 0.5)" << std::endl;
00371   points.pop_back();
00372 
00373   AF2Point3D failPointDelta(11, -0.4998, 0.0001, 0.5);
00374   points.push_back(&failPointDelta);
00375   AF2Neighborhood failNgbhdDelta(points,
00376       baselineEdge, edges, makePlaneProj());
00377   rule180DegreeQ5->applyRule(failNgbhdDelta, 5u, failVisitor);
00378   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00379   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00380       << "  has a point at (-0.4998, 0.0001, 0.5)" << std::endl;
00381   points.pop_back();
00382 
00383 
00384   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
00385       itr != edges.end(); ++itr)
00386   {
00387     delete *itr;
00388   }
00389   delete baselineEdge;
00390   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00391   {
00392     delete pointsVector[pi];
00393   }
00394 
00395   std::cout << "PASS: The 180DegreeRuleQ5 passes the test." << std::endl;
00396 }
00397 
00398 void test180DegreeRuleQ10()
00399 {
00400   AF2DfltTriangleRules triRules;
00401   const AF2Rule* rule180DegreeQ10 =
00402       findRule(triRules, "Triangle Off Line, Quality Level 10");
00403 
00404   CHECK(rule180DegreeQ10 != NULL);
00405 
00406   std::vector<AF2Point3D*> pointsVector;
00407   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
00408   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
00409   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
00410   pointsVector.push_back(new AF2Point3D(3, -0.25, 0.0, 0.5));
00411   pointsVector.push_back(new AF2Point3D(4, -0.3748, 0.0, 0.5));
00412   pointsVector.push_back(new AF2Point3D(5, -0.43105, 0.0401, 0.5));
00413   pointsVector.push_back(new AF2Point3D(6, -0.44395, 0.0401, 0.5));
00414   pointsVector.push_back(new AF2Point3D(7, -0.5002, 0.0, 0.5));
00415 
00416   std::list<AF2Point3D*> points;
00417 
00418   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00419   {
00420     points.push_back(pointsVector[pi]);
00421   }
00422 
00423   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
00424 
00425   std::list<const AF2Edge3D*> edges;
00426   // basic line
00427   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00428   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
00429   // lines bounding the expected free zone location
00430   edges.push_back(new AF2Edge3D(pointsVector[4], pointsVector[5]));
00431   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00432   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00433 
00434   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00435 
00436   SaveLastVisitor visitor;
00437   rule180DegreeQ10->applyRule(ngbhd, 10u, visitor);
00438 
00439   CHECK_EQUAL(1u, visitor.getVisitCount());
00440   std::cout << "Good: There is one way to apply the default triangle rule\n"
00441       << "  named \"" << rule180DegreeQ10->getName() << "\"" << std::endl;
00442   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
00443   CHECK_REAL_EQUAL(0.3, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
00444   std::cout << "Good: The new point is located near (0.5, 0.3)" << std::endl;
00445   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
00446   std::cout << "Good: There is one new face" << std::endl;
00447 
00448   SaveLastVisitor failVisitor;
00449   AF2Point3D failPointAlpha(8, -0.3752, 0.0001, 0.5);
00450   points.push_back(&failPointAlpha);
00451   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00452   rule180DegreeQ10->applyRule(failNgbhdAlpha, 10u, failVisitor);
00453   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00454   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00455       << "  has a point at (-0.3752, 0.0001, 0.5)" << std::endl;
00456   points.pop_back();
00457 
00458   AF2Point3D failPointBravo(9, -0.43145, 0.0399, 0.5);
00459   points.push_back(&failPointBravo);
00460   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00461   rule180DegreeQ10->applyRule(failNgbhdBravo, 10u, failVisitor);
00462   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00463   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00464       << "  has a point at (-0.43145, 0.0399, 0.5)" << std::endl;
00465   points.pop_back();
00466 
00467   AF2Point3D failPointCharlie(10, -0.44355, 0.0399, 0.5);
00468   points.push_back(&failPointCharlie);
00469   AF2Neighborhood failNgbhdCharlie(points,
00470       baselineEdge, edges, makePlaneProj());
00471   rule180DegreeQ10->applyRule(failNgbhdCharlie, 10u, failVisitor);
00472   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00473   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00474       << "  has a point at (-0.44355, 0.0399, 0.5)" << std::endl;
00475   points.pop_back();
00476 
00477   AF2Point3D failPointDelta(11, -0.4998, 0.0001, 0.5);
00478   points.push_back(&failPointDelta);
00479   AF2Neighborhood failNgbhdDelta(points,
00480       baselineEdge, edges, makePlaneProj());
00481   rule180DegreeQ10->applyRule(failNgbhdDelta, 10u, failVisitor);
00482   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00483   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00484       << "  has a point at (-0.4998, 0.0001, 0.5)" << std::endl;
00485   points.pop_back();
00486 
00487 
00488   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
00489       itr != edges.end(); ++itr)
00490   {
00491     delete *itr;
00492   }
00493   delete baselineEdge;
00494   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00495   {
00496     delete pointsVector[pi];
00497   }
00498 
00499   std::cout << "PASS: The 180DegreeRuleQ10 passes the test." << std::endl;
00500 }
00501 
00502 void test180DegreeRuleQ20()
00503 {
00504   AF2DfltTriangleRules triRules;
00505   const AF2Rule* rule180DegreeQ20 =
00506       findRule(triRules, "Triangle Off Line, Quality Level 20");
00507 
00508   CHECK(rule180DegreeQ20 != NULL);
00509 
00510   std::vector<AF2Point3D*> pointsVector;
00511   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
00512   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
00513   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
00514   pointsVector.push_back(new AF2Point3D(3, -0.25, 0.0, 0.5));
00515   pointsVector.push_back(new AF2Point3D(4, -0.3748, 0.0, 0.5));
00516   pointsVector.push_back(new AF2Point3D(5, -0.434175, 0.013225, 0.5));
00517   pointsVector.push_back(new AF2Point3D(6, -0.440825, 0.013225, 0.5));
00518   pointsVector.push_back(new AF2Point3D(7, -0.5002, 0.0, 0.5));
00519 
00520   std::list<AF2Point3D*> points;
00521 
00522   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00523   {
00524     points.push_back(pointsVector[pi]);
00525   }
00526 
00527   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
00528 
00529   std::list<const AF2Edge3D*> edges;
00530   // basic line
00531   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00532   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
00533   // lines bounding the expected free zone location
00534   edges.push_back(new AF2Edge3D(pointsVector[4], pointsVector[5]));
00535   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00536   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00537 
00538   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00539 
00540   SaveLastVisitor visitor;
00541   rule180DegreeQ20->applyRule(ngbhd, 20u, visitor);
00542 
00543   CHECK_EQUAL(1u, visitor.getVisitCount());
00544   std::cout << "Good: There is one way to apply the default triangle rule\n"
00545       << "  named \"" << rule180DegreeQ20->getName() << "\"" << std::endl;
00546   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
00547   CHECK_REAL_EQUAL(0.1, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
00548   std::cout << "Good: The new point is located near (0.5, 0.1)" << std::endl;
00549   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
00550   std::cout << "Good: There is one new face" << std::endl;
00551 
00552   SaveLastVisitor failVisitor;
00553   AF2Point3D failPointAlpha(8, -0.3756, 0.0001, 0.5);
00554   points.push_back(&failPointAlpha);
00555   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00556   rule180DegreeQ20->applyRule(failNgbhdAlpha, 20u, failVisitor);
00557   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00558   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00559       << "  has a point at (-0.3756, 0.0001, 0.5)" << std::endl;
00560   points.pop_back();
00561 
00562   AF2Point3D failPointBravo(9, -0.434575, 0.013025, 0.5);
00563   points.push_back(&failPointBravo);
00564   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00565   rule180DegreeQ20->applyRule(failNgbhdBravo, 20u, failVisitor);
00566   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00567   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00568       << "  has a point at (-0.434575, 0.013025, 0.5)" << std::endl;
00569   points.pop_back();
00570 
00571   AF2Point3D failPointCharlie(10, -0.440425, 0.013025, 0.5);
00572   points.push_back(&failPointCharlie);
00573   AF2Neighborhood failNgbhdCharlie(points,
00574       baselineEdge, edges, makePlaneProj());
00575   rule180DegreeQ20->applyRule(failNgbhdCharlie, 20u, failVisitor);
00576   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00577   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00578       << "  has a point at (-0.440425, 0.013025, 0.5)" << std::endl;
00579   points.pop_back();
00580 
00581   AF2Point3D failPointDelta(11, -0.4994, 0.0001, 0.5);
00582   points.push_back(&failPointDelta);
00583   AF2Neighborhood failNgbhdDelta(points,
00584       baselineEdge, edges, makePlaneProj());
00585   rule180DegreeQ20->applyRule(failNgbhdDelta, 20u, failVisitor);
00586   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00587   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00588       << "  has a point at (-0.4994, 0.0001, 0.5)" << std::endl;
00589   points.pop_back();
00590 
00591 
00592   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
00593       itr != edges.end(); ++itr)
00594   {
00595     delete *itr;
00596   }
00597   delete baselineEdge;
00598   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00599   {
00600     delete pointsVector[pi];
00601   }
00602 
00603   std::cout << "PASS: The 180DegreeRuleQ20 passes the test." << std::endl;
00604 }
00605 
00606 void test60DegreeAngleRightRule()
00607 {
00608   AF2DfltTriangleRules triRules;
00609   const AF2Rule* rule60DegreeRight =
00610       findRule(triRules, "Angle at Right Vertex of 60 Degrees");
00611 
00612   CHECK(rule60DegreeRight != NULL);
00613 
00614   std::vector<AF2Point3D*> pointsVector;
00615   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
00616   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
00617   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
00618   pointsVector.push_back(new AF2Point3D(3, -0.4375, 0.10825, 0.5));
00619   pointsVector.push_back(new AF2Point3D(4, -0.3125, 0.10825, 0.5));
00620   pointsVector.push_back(new AF2Point3D(5, -0.4375, 0.10845, 0.5));
00621   pointsVector.push_back(new AF2Point3D(6, -0.515725, 0.0812875, 0.5));
00622   pointsVector.push_back(new AF2Point3D(7, -0.5002, 0.0, 0.5));
00623 
00624   std::list<AF2Point3D*> points;
00625 
00626   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00627   {
00628     points.push_back(pointsVector[pi]);
00629   }
00630 
00631   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
00632 
00633   std::list<const AF2Edge3D*> edges;
00634   // basic neighborhood edges
00635   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00636   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
00637   edges.push_back(new AF2Edge3D(pointsVector[3], pointsVector[4]));
00638   // lines bounding the expected free zone location
00639   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00640   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00641 
00642   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00643 
00644   SaveLastVisitor visitor;
00645   rule60DegreeRight->applyRule(ngbhd, 1u, visitor);
00646 
00647   CHECK_EQUAL(1u, visitor.getVisitCount());
00648   std::cout << "Good: There is one way to apply the default triangle rule\n"
00649       << "  named \"" << rule60DegreeRight->getName() << "\"" << std::endl;
00650   CHECK_EQUAL(0u, visitor.getLast()->getNumNewPoints());
00651   std::cout << "Good: There are no new points" << std::endl;
00652   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
00653   std::cout << "Good: There is one new face" << std::endl;
00654 
00655   SaveLastVisitor failVisitor;
00656   AF2Point3D failPointAlpha(8, -0.4375, 0.10805, 0.5);
00657   points.push_back(&failPointAlpha);
00658   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00659   rule60DegreeRight->applyRule(failNgbhdAlpha, 1u, failVisitor);
00660   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00661   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00662       << "  has a point at (-0.4375, 0.10805, 0.5)" << std::endl;
00663   points.pop_back();
00664 
00665   AF2Point3D failPointBravo(9, -0.515525, 0.0810875, 0.5);
00666   points.push_back(&failPointBravo);
00667   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00668   rule60DegreeRight->applyRule(failNgbhdBravo, 1u, failVisitor);
00669   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00670   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00671       << "  has a point at (-0.515525, 0.0810875, 0.5)" << std::endl;
00672   points.pop_back();
00673 
00674   AF2Point3D failPointCharlie(10, -0.4998, 0.0001, 0.5);
00675   points.push_back(&failPointCharlie);
00676   AF2Neighborhood failNgbhdCharlie(points,
00677       baselineEdge, edges, makePlaneProj());
00678   rule60DegreeRight->applyRule(failNgbhdCharlie, 1u, failVisitor);
00679   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00680   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00681       << "  has a point at (-0.4998, 0.0001, 0.5)" << std::endl;
00682   points.pop_back();
00683 
00684 
00685   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
00686       itr != edges.end(); ++itr)
00687   {
00688     delete *itr;
00689   }
00690   delete baselineEdge;
00691   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00692   {
00693     delete pointsVector[pi];
00694   }
00695 
00696   std::cout << "PASS: The 60DegreeAngleRightRule passes the test." << std::endl;
00697 }
00698 
00699 void test60DegreeAngleLeftRule()
00700 {
00701   AF2DfltTriangleRules triRules;
00702   const AF2Rule* rule60DegreeLeft =
00703       findRule(triRules, "Angle at Left Vertex of 60 Degrees");
00704 
00705   CHECK(rule60DegreeLeft != NULL);
00706 
00707   std::vector<AF2Point3D*> pointsVector;
00708   pointsVector.push_back(new AF2Point3D(0, -0.5625, 0.10825, 0.5));
00709   pointsVector.push_back(new AF2Point3D(1, -0.4375, 0.10825, 0.5));
00710   pointsVector.push_back(new AF2Point3D(2, -0.5, 0.0, 0.5));
00711   pointsVector.push_back(new AF2Point3D(3, -0.375, 0.0, 0.5));
00712   pointsVector.push_back(new AF2Point3D(4, -0.25, 0.0, 0.5));
00713   pointsVector.push_back(new AF2Point3D(5, -0.3748, 0.0, 0.5));
00714   pointsVector.push_back(new AF2Point3D(6, -0.359275, 0.0812875, 0.5));
00715   pointsVector.push_back(new AF2Point3D(7, -0.4375, 0.10845, 0.5));
00716 
00717   std::list<AF2Point3D*> points;
00718 
00719   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00720   {
00721     points.push_back(pointsVector[pi]);
00722   }
00723 
00724   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[2], pointsVector[3]);
00725 
00726   std::list<const AF2Edge3D*> edges;
00727   // basic neighborhood edges
00728   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00729   edges.push_back(new AF2Edge3D(pointsVector[1], pointsVector[2]));
00730   edges.push_back(new AF2Edge3D(pointsVector[3], pointsVector[4]));
00731   // lines bounding the expected free zone location
00732   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00733   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00734 
00735   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00736 
00737   SaveLastVisitor visitor;
00738   rule60DegreeLeft->applyRule(ngbhd, 1u, visitor);
00739 
00740   CHECK_EQUAL(1u, visitor.getVisitCount());
00741   std::cout << "Good: There is one way to apply the default triangle rule\n"
00742       << "  named \"" << rule60DegreeLeft->getName() << "\"" << std::endl;
00743   CHECK_EQUAL(0u, visitor.getLast()->getNumNewPoints());
00744   std::cout << "Good: There are no new points" << std::endl;
00745   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
00746   std::cout << "Good: There is one new face" << std::endl;
00747 
00748   SaveLastVisitor failVisitor;
00749   AF2Point3D failPointAlpha(8, -0.3752, 0.0001, 0.5);
00750   points.push_back(&failPointAlpha);
00751   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00752   rule60DegreeLeft->applyRule(failNgbhdAlpha, 1u, failVisitor);
00753   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00754   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00755       << "  has a point at (-0.3752, 0.0001, 0.5)" << std::endl;
00756   points.pop_back();
00757 
00758   AF2Point3D failPointBravo(9, -0.359475, 0.0810875, 0.5);
00759   points.push_back(&failPointBravo);
00760   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00761   rule60DegreeLeft->applyRule(failNgbhdBravo, 1u, failVisitor);
00762   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00763   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00764       << "  has a point at (-0.359475, 0.0810875, 0.5)" << std::endl;
00765   points.pop_back();
00766 
00767   AF2Point3D failPointCharlie(10, -0.4375, 0.10805, 0.5);
00768   points.push_back(&failPointCharlie);
00769   AF2Neighborhood failNgbhdCharlie(points,
00770       baselineEdge, edges, makePlaneProj());
00771   rule60DegreeLeft->applyRule(failNgbhdCharlie, 1u, failVisitor);
00772   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00773   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00774       << "  has a point at (-0.4375, 0.10805, 0.5)" << std::endl;
00775   points.pop_back();
00776 
00777 
00778   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
00779       itr != edges.end(); ++itr)
00780   {
00781     delete *itr;
00782   }
00783   delete baselineEdge;
00784   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00785   {
00786     delete pointsVector[pi];
00787   }
00788 
00789   std::cout << "PASS: The 60DegreeAngleLeftRule passes the test." << std::endl;
00790 }
00791 
00792 void test120DegreeAngleRightRule()
00793 {
00794   AF2DfltTriangleRules triRules;
00795   const AF2Rule* rule120DegreeRight =
00796       findRule(triRules, "Angle at Right Vertex of 120 Degrees");
00797 
00798   CHECK(rule120DegreeRight != NULL);
00799 
00800   std::vector<AF2Point3D*> pointsVector;
00801   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
00802   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
00803   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
00804   pointsVector.push_back(new AF2Point3D(3, -0.3125, 0.10825, 0.5));
00805   pointsVector.push_back(new AF2Point3D(4, -0.1875, 0.10825, 0.5));
00806   pointsVector.push_back(new AF2Point3D(5, -0.3124, 0.10835, 0.5));
00807   pointsVector.push_back(new AF2Point3D(6, -0.375, 0.2167, 0.5));
00808   pointsVector.push_back(new AF2Point3D(7, -0.5, 0.2167, 0.5));
00809   pointsVector.push_back(new AF2Point3D(8, -0.5626, 0.10835, 0.5));
00810   pointsVector.push_back(new AF2Point3D(9, -0.5002, 0.0, 0.5));
00811 
00812   std::list<AF2Point3D*> points;
00813 
00814   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00815   {
00816     points.push_back(pointsVector[pi]);
00817   }
00818 
00819   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
00820 
00821   std::list<const AF2Edge3D*> edges;
00822   // basic neighborhood edges
00823   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00824   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
00825   edges.push_back(new AF2Edge3D(pointsVector[3], pointsVector[4]));
00826   // lines bounding the expected free zone location
00827   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00828   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00829   edges.push_back(new AF2Edge3D(pointsVector[7], pointsVector[8]));
00830   edges.push_back(new AF2Edge3D(pointsVector[8], pointsVector[9]));
00831 
00832   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00833 
00834   SaveLastVisitor visitor;
00835   rule120DegreeRight->applyRule(ngbhd, 1u, visitor);
00836 
00837   CHECK_EQUAL(1u, visitor.getVisitCount());
00838   std::cout << "Good: There is one way to apply the default triangle rule\n"
00839       << "  named \"" << rule120DegreeRight->getName() << "\"" << std::endl;
00840   CHECK_EQUAL(1u, visitor.getLast()->getNumNewPoints());
00841   std::cout << "Good: There is one new point" << std::endl;
00842   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
00843   CHECK_REAL_EQUAL(0.866, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
00844   std::cout << "Good: The new point is located near (0.5, 0.866)" << std::endl;
00845   CHECK_EQUAL(2u, visitor.getLast()->getNumNewFaces());
00846   std::cout << "Good: There are two new faces" << std::endl;
00847 
00848   SaveLastVisitor failVisitor;
00849   AF2Point3D failPointAlpha(10, -0.3126, 0.10815, 0.5);
00850   points.push_back(&failPointAlpha);
00851   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00852   rule120DegreeRight->applyRule(failNgbhdAlpha, 1u, failVisitor);
00853   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00854   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00855       << "  has a point at (-0.3126, 0.10815, 0.5)" << std::endl;
00856   points.pop_back();
00857 
00858   AF2Point3D failPointBravo(11, -0.375, 0.2163, 0.5);
00859   points.push_back(&failPointBravo);
00860   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00861   rule120DegreeRight->applyRule(failNgbhdBravo, 1u, failVisitor);
00862   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00863   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00864       << "  has a point at (-0.375, 0.2163, 0.5)" << std::endl;
00865   points.pop_back();
00866 
00867   AF2Point3D failPointCharlie(12, -0.5, 0.2163, 0.5);
00868   points.push_back(&failPointCharlie);
00869   AF2Neighborhood failNgbhdCharlie(points,
00870       baselineEdge, edges, makePlaneProj());
00871   rule120DegreeRight->applyRule(failNgbhdCharlie, 1u, failVisitor);
00872   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00873   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00874       << "  has a point at (-0.5, 0.2163, 0.5)" << std::endl;
00875   points.pop_back();
00876 
00877   AF2Point3D failPointDelta(13, -0.5624, 0.10815, 0.5);
00878   points.push_back(&failPointDelta);
00879   AF2Neighborhood failNgbhdDelta(points,
00880       baselineEdge, edges, makePlaneProj());
00881   rule120DegreeRight->applyRule(failNgbhdDelta, 1u, failVisitor);
00882   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00883   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00884       << "  has a point at (-0.5624, 0.10815, 0.5)" << std::endl;
00885   points.pop_back();
00886 
00887   AF2Point3D failPointEcho(14, -0.4998, 0.0001, 0.5);
00888   points.push_back(&failPointEcho);
00889   AF2Neighborhood failNgbhdEcho(points,
00890       baselineEdge, edges, makePlaneProj());
00891   rule120DegreeRight->applyRule(failNgbhdEcho, 1u, failVisitor);
00892   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00893   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00894       << "  has a point at (-0.4998, 0.0001, 0.5)" << std::endl;
00895   points.pop_back();
00896 
00897 
00898   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
00899       itr != edges.end(); ++itr)
00900   {
00901     delete *itr;
00902   }
00903   delete baselineEdge;
00904   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00905   {
00906     delete pointsVector[pi];
00907   }
00908 
00909   std::cout << "PASS: The 120DegreeAngleRightRule passes the test."
00910       << std::endl;
00911 }
00912 
00913 void test120DegreeAngleLeftRule()
00914 {
00915   AF2DfltTriangleRules triRules;
00916   const AF2Rule* rule120DegreeLeft =
00917       findRule(triRules, "Angle at Left Vertex of 120 Degrees");
00918 
00919   CHECK(rule120DegreeLeft != NULL);
00920 
00921   std::vector<AF2Point3D*> pointsVector;
00922   pointsVector.push_back(new AF2Point3D(0, -0.6875, 0.10825, 0.5));
00923   pointsVector.push_back(new AF2Point3D(1, -0.5625, 0.10825, 0.5));
00924   pointsVector.push_back(new AF2Point3D(2, -0.5, 0.0, 0.5));
00925   pointsVector.push_back(new AF2Point3D(3, -0.375, 0.0, 0.5));
00926   pointsVector.push_back(new AF2Point3D(4, -0.25, 0.0, 0.5));
00927   pointsVector.push_back(new AF2Point3D(5, -0.3748, 0.0, 0.5));
00928   pointsVector.push_back(new AF2Point3D(6, -0.3124, 0.10835, 0.5));
00929   pointsVector.push_back(new AF2Point3D(7, -0.375, 0.2167, 0.5));
00930   pointsVector.push_back(new AF2Point3D(8, -0.5, 0.2167, 0.5));
00931   pointsVector.push_back(new AF2Point3D(9, -0.5626, 0.10835, 0.5));
00932 
00933   std::list<AF2Point3D*> points;
00934 
00935   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
00936   {
00937     points.push_back(pointsVector[pi]);
00938   }
00939 
00940   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[2], pointsVector[3]);
00941 
00942   std::list<const AF2Edge3D*> edges;
00943   // basic neighborhood edges
00944   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
00945   edges.push_back(new AF2Edge3D(pointsVector[1], pointsVector[2]));
00946   edges.push_back(new AF2Edge3D(pointsVector[3], pointsVector[4]));
00947   // lines bounding the expected free zone location
00948   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
00949   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
00950   edges.push_back(new AF2Edge3D(pointsVector[7], pointsVector[8]));
00951   edges.push_back(new AF2Edge3D(pointsVector[8], pointsVector[9]));
00952 
00953   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
00954 
00955   SaveLastVisitor visitor;
00956   rule120DegreeLeft->applyRule(ngbhd, 1u, visitor);
00957 
00958   CHECK_EQUAL(1u, visitor.getVisitCount());
00959   std::cout << "Good: There is one way to apply the default triangle rule\n"
00960       << "  named \"" << rule120DegreeLeft->getName() << "\"" << std::endl;
00961   CHECK_EQUAL(1u, visitor.getLast()->getNumNewPoints());
00962   std::cout << "Good: There is one new point" << std::endl;
00963   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
00964   CHECK_REAL_EQUAL(0.866, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
00965   std::cout << "Good: The new point is located near (0.5, 0.866)" << std::endl;
00966   CHECK_EQUAL(2u, visitor.getLast()->getNumNewFaces());
00967   std::cout << "Good: There are two new faces" << std::endl;
00968 
00969   SaveLastVisitor failVisitor;
00970   AF2Point3D failPointAlpha(10, -0.3752, 0.0001, 0.5);
00971   points.push_back(&failPointAlpha);
00972   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
00973   rule120DegreeLeft->applyRule(failNgbhdAlpha, 1u, failVisitor);
00974   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00975   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00976       << "  has a point at (-0.3752, 0.0001, 0.5)" << std::endl;
00977   points.pop_back();
00978 
00979   AF2Point3D failPointBravo(11, -0.3126, 0.10815, 0.5);
00980   points.push_back(&failPointBravo);
00981   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
00982   rule120DegreeLeft->applyRule(failNgbhdBravo, 1u, failVisitor);
00983   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00984   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00985       << "  has a point at (-0.3126, 0.10815, 0.5)" << std::endl;
00986   points.pop_back();
00987 
00988   AF2Point3D failPointCharlie(12, -0.375, 0.2163, 0.5);
00989   points.push_back(&failPointCharlie);
00990   AF2Neighborhood failNgbhdCharlie(points,
00991       baselineEdge, edges, makePlaneProj());
00992   rule120DegreeLeft->applyRule(failNgbhdCharlie, 1u, failVisitor);
00993   CHECK_EQUAL(0u, failVisitor.getVisitCount());
00994   std::cout << "Good: The rule fails to apply when the neighborhood\n"
00995       << "  has a point at (-0.375, 0.2163, 0.5)" << std::endl;
00996   points.pop_back();
00997 
00998   AF2Point3D failPointDelta(13, -0.5, 0.2163, 0.5);
00999   points.push_back(&failPointDelta);
01000   AF2Neighborhood failNgbhdDelta(points,
01001       baselineEdge, edges, makePlaneProj());
01002   rule120DegreeLeft->applyRule(failNgbhdDelta, 1u, failVisitor);
01003   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01004   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01005       << "  has a point at (-0.5, 0.2163, 0.5)" << std::endl;
01006   points.pop_back();
01007 
01008   AF2Point3D failPointEcho(14, -0.5624, 0.10815, 0.5);
01009   points.push_back(&failPointEcho);
01010   AF2Neighborhood failNgbhdEcho(points,
01011       baselineEdge, edges, makePlaneProj());
01012   rule120DegreeLeft->applyRule(failNgbhdEcho, 1u, failVisitor);
01013   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01014   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01015       << "  has a point at (-0.5624, 0.10815, 0.5)" << std::endl;
01016   points.pop_back();
01017 
01018 
01019   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
01020       itr != edges.end(); ++itr)
01021   {
01022     delete *itr;
01023   }
01024   delete baselineEdge;
01025   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01026   {
01027     delete pointsVector[pi];
01028   }
01029 
01030   std::cout << "PASS: The 120DegreeAngleLeftRule passes the test."
01031       << std::endl;
01032 }
01033 
01034 void test120DegreeAngleBothRule()
01035 {
01036   AF2DfltTriangleRules triRules;
01037   const AF2Rule* rule120DegreeBoth =
01038       findRule(triRules, "Angles at Both Vertices of 120 Degrees");
01039 
01040   CHECK(rule120DegreeBoth != NULL);
01041 
01042   std::vector<AF2Point3D*> pointsVector;
01043   pointsVector.push_back(new AF2Point3D(0, -0.6875, 0.10825, 0.5));
01044   pointsVector.push_back(new AF2Point3D(1, -0.5625, 0.10825, 0.5));
01045   pointsVector.push_back(new AF2Point3D(2, -0.5, 0.0, 0.5));
01046   pointsVector.push_back(new AF2Point3D(3, -0.375, 0.0, 0.5));
01047   pointsVector.push_back(new AF2Point3D(4, -0.3125, 0.10825, 0.5));
01048   pointsVector.push_back(new AF2Point3D(5, -0.1875, 0.10825, 0.5));
01049   pointsVector.push_back(new AF2Point3D(6, -0.3124, 0.10835, 0.5));
01050   pointsVector.push_back(new AF2Point3D(7, -0.375, 0.162575, 0.5));
01051   pointsVector.push_back(new AF2Point3D(8, -0.5, 0.162575, 0.5));
01052   pointsVector.push_back(new AF2Point3D(9, -0.5626, 0.10835, 0.5));
01053 
01054   std::list<AF2Point3D*> points;
01055 
01056   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01057   {
01058     points.push_back(pointsVector[pi]);
01059   }
01060 
01061   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[2], pointsVector[3]);
01062 
01063   std::list<const AF2Edge3D*> edges;
01064   // basic neighborhood edges
01065   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
01066   edges.push_back(new AF2Edge3D(pointsVector[1], pointsVector[2]));
01067   edges.push_back(new AF2Edge3D(pointsVector[3], pointsVector[4]));
01068   edges.push_back(new AF2Edge3D(pointsVector[4], pointsVector[5]));
01069   // lines bounding the expected free zone location
01070   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
01071   edges.push_back(new AF2Edge3D(pointsVector[7], pointsVector[8]));
01072   edges.push_back(new AF2Edge3D(pointsVector[8], pointsVector[9]));
01073 
01074   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
01075 
01076   SaveLastVisitor visitor;
01077   rule120DegreeBoth->applyRule(ngbhd, 1u, visitor);
01078 
01079   CHECK_EQUAL(1u, visitor.getVisitCount());
01080   std::cout << "Good: There is one way to apply the default triangle rule\n"
01081       << "  named \"" << rule120DegreeBoth->getName() << "\"" << std::endl;
01082   CHECK_EQUAL(1u, visitor.getLast()->getNumNewPoints());
01083   std::cout << "Good: There is one new point" << std::endl;
01084   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
01085   CHECK_REAL_EQUAL(0.866, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
01086   std::cout << "Good: The new point is located near (0.5, 0.866)" << std::endl;
01087   CHECK_EQUAL(3u, visitor.getLast()->getNumNewFaces());
01088   std::cout << "Good: There are three new faces" << std::endl;
01089 
01090   SaveLastVisitor failVisitor;
01091   AF2Point3D failPointAlpha(10, -0.3126, 0.10815, 0.5);
01092   points.push_back(&failPointAlpha);
01093   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
01094   rule120DegreeBoth->applyRule(failNgbhdAlpha, 1u, failVisitor);
01095   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01096   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01097       << "  has a point at (-0.3126, 0.10815, 0.5)" << std::endl;
01098   points.pop_back();
01099 
01100   AF2Point3D failPointBravo(11, -0.375, 0.162175, 0.5);
01101   points.push_back(&failPointBravo);
01102   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
01103   rule120DegreeBoth->applyRule(failNgbhdBravo, 1u, failVisitor);
01104   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01105   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01106       << "  has a point at (-0.375, 0.162175, 0.5)" << std::endl;
01107   points.pop_back();
01108 
01109   AF2Point3D failPointCharlie(12, -0.5, 0.162175, 0.5);
01110   points.push_back(&failPointCharlie);
01111   AF2Neighborhood failNgbhdCharlie(points,
01112       baselineEdge, edges, makePlaneProj());
01113   rule120DegreeBoth->applyRule(failNgbhdCharlie, 1u, failVisitor);
01114   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01115   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01116       << "  has a point at (-0.5, 0.162175, 0.5)" << std::endl;
01117   points.pop_back();
01118 
01119   AF2Point3D failPointDelta(13, -0.5624, 0.10815, 0.5);
01120   points.push_back(&failPointDelta);
01121   AF2Neighborhood failNgbhdDelta(points,
01122       baselineEdge, edges, makePlaneProj());
01123   rule120DegreeBoth->applyRule(failNgbhdDelta, 1u, failVisitor);
01124   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01125   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01126       << "  has a point at (-0.5624, 0.10815, 0.5)" << std::endl;
01127   points.pop_back();
01128 
01129   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
01130       itr != edges.end(); ++itr)
01131   {
01132     delete *itr;
01133   }
01134   delete baselineEdge;
01135   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01136   {
01137     delete pointsVector[pi];
01138   }
01139 
01140   std::cout << "PASS: The 120DegreeAngleBothRule passes the test."
01141       << std::endl;
01142 }
01143 
01144 void testFillTriangleRule()
01145 {
01146   AF2DfltTriangleRules triRules;
01147   const AF2Rule* fillTriangleRule =
01148       findRule(triRules, "Fill Triangle");
01149 
01150   CHECK(fillTriangleRule != NULL);
01151 
01152   std::vector<AF2Point3D*> pointsVector;
01153   pointsVector.push_back(new AF2Point3D(0, -0.5, 0.0, 0.5));
01154   pointsVector.push_back(new AF2Point3D(1, -0.375, 0.0, 0.5));
01155   pointsVector.push_back(new AF2Point3D(2, -0.4375, 0.10825, 0.5));
01156 
01157   std::list<AF2Point3D*> points;
01158 
01159   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01160   {
01161     points.push_back(pointsVector[pi]);
01162   }
01163 
01164   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[0], pointsVector[1]);
01165 
01166   std::list<const AF2Edge3D*> edges;
01167   // basic neighborhood edges
01168   edges.push_back(new AF2Edge3D(pointsVector[1], pointsVector[2]));
01169   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[0]));
01170 
01171   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
01172 
01173   SaveLastVisitor visitor;
01174   fillTriangleRule->applyRule(ngbhd, 1u, visitor);
01175 
01176   CHECK_EQUAL(1u, visitor.getVisitCount());
01177   std::cout << "Good: There is one way to apply the default triangle rule\n"
01178       << "  named \"" << fillTriangleRule->getName() << "\"" << std::endl;
01179   CHECK_EQUAL(0u, visitor.getLast()->getNumNewPoints());
01180   std::cout << "Good: There are no new points" << std::endl;
01181   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
01182   std::cout << "Good: There is one new face" << std::endl;
01183 
01184   SaveLastVisitor failVisitor;
01185   AF2Point3D failPointAlpha(3, -0.4375, 0.10815, 0.5);
01186   points.push_back(&failPointAlpha);
01187   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
01188   fillTriangleRule->applyRule(failNgbhdAlpha, 1u, failVisitor);
01189   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01190   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01191       << "  has a point at (-0.4375, 0.10815, 0.5)" << std::endl;
01192   points.pop_back();
01193 
01194   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
01195       itr != edges.end(); ++itr)
01196   {
01197     delete *itr;
01198   }
01199   delete baselineEdge;
01200   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01201   {
01202     delete pointsVector[pi];
01203   }
01204 
01205   std::cout << "PASS: The fillTriangleRule passes the test."
01206       << std::endl;
01207 }
01208 
01209 void testConnectVertexRule()
01210 {
01211   AF2DfltTriangleRules triRules;
01212   const AF2Rule* connectVertexRule =
01213       findRule(triRules, "Connect to Opposite Vertex");
01214 
01215   CHECK(connectVertexRule != NULL);
01216 
01217   std::vector<AF2Point3D*> pointsVector;
01218   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
01219   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
01220   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
01221   pointsVector.push_back(new AF2Point3D(3, -0.25, 0.0, 0.5));
01222   pointsVector.push_back(new AF2Point3D(4, -0.4375, 0.10825, 0.5));
01223   pointsVector.push_back(new AF2Point3D(5, -0.3748, 0.0, 0.5));
01224   pointsVector.push_back(new AF2Point3D(6, -0.3499, 0.086725, 0.5));
01225   pointsVector.push_back(new AF2Point3D(7, -0.4375, 0.10845, 0.5));
01226   pointsVector.push_back(new AF2Point3D(8, -0.5251, 0.086725, 0.5));
01227   pointsVector.push_back(new AF2Point3D(9, -0.5002, 0.0, 0.5));
01228 
01229   std::list<AF2Point3D*> points;
01230 
01231   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01232   {
01233     points.push_back(pointsVector[pi]);
01234   }
01235 
01236   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
01237 
01238   std::list<const AF2Edge3D*> edges;
01239   // basic neighborhood edges
01240   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
01241   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
01242   // lines bounding the expected free zone location
01243   edges.push_back(new AF2Edge3D(pointsVector[5], pointsVector[6]));
01244   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
01245   edges.push_back(new AF2Edge3D(pointsVector[7], pointsVector[8]));
01246   edges.push_back(new AF2Edge3D(pointsVector[8], pointsVector[9]));
01247 
01248   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
01249 
01250   SaveLastVisitor visitor;
01251   connectVertexRule->applyRule(ngbhd, 1u, visitor);
01252 
01253   CHECK_EQUAL(1u, visitor.getVisitCount());
01254   std::cout << "Good: There is one way to apply the default triangle rule\n"
01255       << "  named \"" << connectVertexRule->getName() << "\"" << std::endl;
01256   CHECK_EQUAL(0u, visitor.getLast()->getNumNewPoints());
01257   std::cout << "Good: There are no new points" << std::endl;
01258   CHECK_EQUAL(1u, visitor.getLast()->getNumNewFaces());
01259   std::cout << "Good: There is one new face" << std::endl;
01260 
01261   SaveLastVisitor failVisitor;
01262   AF2Point3D failPointAlpha(10, -0.3752, 0.0001, 0.5);
01263   points.push_back(&failPointAlpha);
01264   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
01265   connectVertexRule->applyRule(failNgbhdAlpha, 1u, failVisitor);
01266   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01267   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01268       << "  has a point at (-0.3752, 0.0001, 0.5)" << std::endl;
01269   points.pop_back();
01270 
01271   AF2Point3D failPointBravo(11, -0.3501, 0.086525, 0.5);
01272   points.push_back(&failPointBravo);
01273   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
01274   connectVertexRule->applyRule(failNgbhdBravo, 1u, failVisitor);
01275   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01276   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01277       << "  has a point at (-0.3501, 0.086525, 0.5)" << std::endl;
01278   points.pop_back();
01279 
01280   AF2Point3D failPointCharlie(12, -0.5249, 0.086525, 0.5);
01281   points.push_back(&failPointCharlie);
01282   AF2Neighborhood failNgbhdCharlie(points,
01283       baselineEdge, edges, makePlaneProj());
01284   connectVertexRule->applyRule(failNgbhdCharlie, 1u, failVisitor);
01285   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01286   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01287       << "  has a point at (-0.5249, 0.086525, 0.5)" << std::endl;
01288   points.pop_back();
01289 
01290   AF2Point3D failPointDelta(13, -0.4998, 0.0001, 0.5);
01291   points.push_back(&failPointDelta);
01292   AF2Neighborhood failNgbhdDelta(points,
01293       baselineEdge, edges, makePlaneProj());
01294   connectVertexRule->applyRule(failNgbhdDelta, 1u, failVisitor);
01295   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01296   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01297       << "  has a point at (-0.4998, 0.0001, 0.5)" << std::endl;
01298   points.pop_back();
01299 
01300   // This vertex of the free zone cannot be tested by adding a point at
01301   //   (-0.4375, 0.10805) because the rule will just choose the vertex at
01302   //   (-0.4375, 0.10805) as the one it should connect to
01303   pointsVector.push_back(new AF2Point3D(14, -0.125, 0.10805, 0.5));
01304   pointsVector.push_back(new AF2Point3D(15, -0.875, 0.10805, 0.5));
01305   points.push_back(pointsVector[10]);
01306   points.push_back(pointsVector[11]);
01307   edges.push_back(new AF2Edge3D(pointsVector[10], pointsVector[11]));
01308   AF2Neighborhood failNgbhdEcho(points,
01309       baselineEdge, edges, makePlaneProj());
01310   connectVertexRule->applyRule(failNgbhdEcho, 1u, failVisitor);
01311   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01312   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01313       << "  has an edge from (-0.125, 0.10805) to (-0.875, 0.10805, 0.5)"
01314       << std::endl;
01315   points.pop_back();
01316 
01317   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
01318       itr != edges.end(); ++itr)
01319   {
01320     delete *itr;
01321   }
01322   delete baselineEdge;
01323   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01324   {
01325     delete pointsVector[pi];
01326   }
01327 
01328   std::cout << "PASS: The connectVertexRule passes the test." << std::endl;
01329 }
01330 
01331 void testConnectEdgeRule()
01332 {
01333   AF2DfltTriangleRules triRules;
01334   const AF2Rule* connectEdgeRule =
01335       findRule(triRules, "Connect to Opposite Edge");
01336 
01337   CHECK(connectEdgeRule != NULL);
01338 
01339   std::vector<AF2Point3D*> pointsVector;
01340   pointsVector.push_back(new AF2Point3D(0, -0.625, 0.0, 0.5));
01341   pointsVector.push_back(new AF2Point3D(1, -0.5, 0.0, 0.5));
01342   pointsVector.push_back(new AF2Point3D(2, -0.375, 0.0, 0.5));
01343   pointsVector.push_back(new AF2Point3D(3, -0.25, 0.0, 0.5));
01344   pointsVector.push_back(new AF2Point3D(4, -0.375, 0.2165, 0.5));
01345   pointsVector.push_back(new AF2Point3D(5, -0.5, 0.2165, 0.5));
01346   pointsVector.push_back(new AF2Point3D(6, -0.3748, 0.0, 0.5));
01347   pointsVector.push_back(new AF2Point3D(7, -0.3123, 0.10825, 0.5));
01348   pointsVector.push_back(new AF2Point3D(8, -0.3748, 0.2165, 0.5));
01349   pointsVector.push_back(new AF2Point3D(9, -0.5002, 0.2165, 0.5));
01350   pointsVector.push_back(new AF2Point3D(10, -0.5627, 0.10825, 0.5));
01351   pointsVector.push_back(new AF2Point3D(11, -0.5002, 0.0, 0.5));
01352 
01353   std::list<AF2Point3D*> points;
01354 
01355   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01356   {
01357     points.push_back(pointsVector[pi]);
01358   }
01359 
01360   AF2Edge3D* baselineEdge = new AF2Edge3D(pointsVector[1], pointsVector[2]);
01361 
01362   std::list<const AF2Edge3D*> edges;
01363   // basic neighborhood edges
01364   edges.push_back(new AF2Edge3D(pointsVector[0], pointsVector[1]));
01365   edges.push_back(new AF2Edge3D(pointsVector[2], pointsVector[3]));
01366   edges.push_back(new AF2Edge3D(pointsVector[4], pointsVector[5]));
01367   // lines bounding the expected free zone location
01368   edges.push_back(new AF2Edge3D(pointsVector[6], pointsVector[7]));
01369   edges.push_back(new AF2Edge3D(pointsVector[7], pointsVector[8]));
01370   edges.push_back(new AF2Edge3D(pointsVector[9], pointsVector[10]));
01371   edges.push_back(new AF2Edge3D(pointsVector[10], pointsVector[11]));
01372 
01373   AF2Neighborhood ngbhd(points, baselineEdge, edges, makePlaneProj());
01374 
01375   SaveLastVisitor visitor;
01376   connectEdgeRule->applyRule(ngbhd, 3u, visitor);
01377 
01378   CHECK_EQUAL(1u, visitor.getVisitCount());
01379   std::cout << "Good: There is one way to apply the default triangle rule\n"
01380       << "  named \"" << connectEdgeRule->getName() << "\"" << std::endl;
01381   CHECK_EQUAL(1u, visitor.getLast()->getNumNewPoints());
01382   std::cout << "Good: There is one new point" << std::endl;
01383   CHECK_REAL_EQUAL(0.5, visitor.getLast()->getNewPoint(0u)->getX(), 1e-14);
01384   CHECK_REAL_EQUAL(0.866, visitor.getLast()->getNewPoint(0u)->getY(), 1e-14);
01385   std::cout << "Good: The new point is located near (0.5, 0.866)" << std::endl;
01386   CHECK_EQUAL(2u, visitor.getLast()->getNumNewFaces());
01387   std::cout << "Good: There are two new faces" << std::endl;
01388 
01389   SaveLastVisitor failVisitor;
01390   AF2Point3D failPointAlpha(12, -0.3752, 0.0001, 0.5);
01391   points.push_back(&failPointAlpha);
01392   AF2Neighborhood failNgbhdAlpha(points, baselineEdge, edges, makePlaneProj());
01393   connectEdgeRule->applyRule(failNgbhdAlpha, 3u, failVisitor);
01394   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01395   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01396       << "  has a point at (-0.3752, 0.0001, 0.5)" << std::endl;
01397   points.pop_back();
01398 
01399   AF2Point3D failPointBravo(13, -0.3127, 0.10825, 0.5);
01400   points.push_back(&failPointBravo);
01401   AF2Neighborhood failNgbhdBravo(points, baselineEdge, edges, makePlaneProj());
01402   connectEdgeRule->applyRule(failNgbhdBravo, 3u, failVisitor);
01403   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01404   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01405       << "  has a point at (-0.3127, 0.10825, 0.5)" << std::endl;
01406   points.pop_back();
01407 
01408   AF2Point3D failPointCharlie(14, -0.3752, 0.2164, 0.5);
01409   points.push_back(&failPointCharlie);
01410   AF2Neighborhood failNgbhdCharlie(points,
01411       baselineEdge, edges, makePlaneProj());
01412   connectEdgeRule->applyRule(failNgbhdCharlie, 3u, failVisitor);
01413   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01414   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01415       << "  has a point at (-0.3752, 0.2164, 0.5)" << std::endl;
01416   points.pop_back();
01417 
01418   AF2Point3D failPointDelta(15, -0.4998, 0.2164, 0.5);
01419   points.push_back(&failPointDelta);
01420   AF2Neighborhood failNgbhdDelta(points,
01421       baselineEdge, edges, makePlaneProj());
01422   connectEdgeRule->applyRule(failNgbhdDelta, 3u, failVisitor);
01423   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01424   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01425       << "  has a point at (-0.4998, 0.2164, 0.5)" << std::endl;
01426   points.pop_back();
01427 
01428   AF2Point3D failPointEcho(16, -0.5623, 0.10825, 0.5);
01429   points.push_back(&failPointEcho);
01430   AF2Neighborhood failNgbhdEcho(points,
01431       baselineEdge, edges, makePlaneProj());
01432   connectEdgeRule->applyRule(failNgbhdEcho, 3u, failVisitor);
01433   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01434   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01435       << "  has a point at (-0.5623, 0.10825, 0.5)" << std::endl;
01436   points.pop_back();
01437 
01438   AF2Point3D failPointFoxtrot(17, -0.4998, 0.0001, 0.5);
01439   points.push_back(&failPointFoxtrot);
01440   AF2Neighborhood failNgbhdFoxtrot(points,
01441       baselineEdge, edges, makePlaneProj());
01442   connectEdgeRule->applyRule(failNgbhdFoxtrot, 3u, failVisitor);
01443   CHECK_EQUAL(0u, failVisitor.getVisitCount());
01444   std::cout << "Good: The rule fails to apply when the neighborhood\n"
01445       << "  has a point at (-0.4998, 0.0001, 0.5)" << std::endl;
01446   points.pop_back();
01447 
01448   for (std::list<const AF2Edge3D*>::iterator itr = edges.begin();
01449       itr != edges.end(); ++itr)
01450   {
01451     delete *itr;
01452   }
01453   delete baselineEdge;
01454   for (unsigned int pi = 0; pi < pointsVector.size(); ++pi)
01455   {
01456     delete pointsVector[pi];
01457   }
01458 
01459   std::cout << "PASS: The connectEdgeRule passes the test." << std::endl;
01460 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines