MeshKit  1.0
basicAlg2D.cpp
Go to the documentation of this file.
00001 
00009 // C++
00010 #include <cmath>
00011 #include <iostream>
00012 #include <vector>
00013 
00014 // MeshKit
00015 #include "meshkit/AF2Algorithm.hpp"
00016 #include "meshkit/AF2DfltPlaneProjMaker.hpp"
00017 #include "meshkit/AF2DfltTriangleRules.hpp"
00018 #include "meshkit/AF2FreeZoneDefSimple.hpp"
00019 #include "meshkit/AF2Point2D.hpp"
00020 #include "meshkit/AF2PointTransformNone.hpp"
00021 #include "meshkit/AF2Rule.hpp"
00022 #include "meshkit/AF2RuleNewTriangle.hpp"
00023 #include "meshkit/MKCore.hpp"
00024 #include "meshkit/ModelEnt.hpp"
00025 #include "meshkit/SizingFunction.hpp"
00026 
00027 // MeshKit testing
00028 #include "TestUtil.hpp"
00029 
00030 // define the geometry file extension depending on the geometry model
00031 #if HAVE_OCC
00032 #define FILE_EXT "stp"
00033 #else
00034 #define FILE_EXT "facet"
00035 #endif
00036 
00037 // These variables are at global scope because (1) calling deleteAll on
00038 // the MKCore geometry instance appears to cause memory inconsistencies
00039 // with later use of the geometry instance and (2) it is more efficient
00040 // to load the geometry model only once
00041 MeshKit::MKCore* mk = NULL;
00042 MeshKit::ModelEnt* square = NULL;
00043 
00044 AF2Rule* makeAddPeakVertexRule();
00045 AF2Rule* makeConnectToVertexRule();
00046 AF2Rule* makeCloseTriangleRule();
00047 AF2Rule* makeFillTriangleRule();
00048 void testAlgorithmFail();
00049 void testAlgorithmSucceed();
00050 void testAlgorithmSucceedIsoPoint();
00051 void testAlgorithmSucceedAddPoint();
00052 void testAlgorithmDefaultRulesSquare();
00053 
00054 int main(int argc, char **argv)
00055 {
00056   // This variable is defined and used in main because a new MKCore
00057   // instance cannot be easily constructed after another MKCore
00058   // instance is deleted; there are problems with a tag left behind in
00059   // iGeom.
00060   mk = new MeshKit::MKCore();
00061 
00062   // load a square in plane z = 0.5 with -1.0 <= x <= 0 and -0.5 <= y <= 0.5
00063   std::string file_name = TestDir + "/squaresurf." + FILE_EXT;
00064   mk->load_geometry_mesh(file_name.c_str(), file_name.c_str());
00065   MeshKit::MEntVector surfs;
00066   mk->get_entities_by_dimension(2, surfs);
00067   square = *surfs.begin();
00068 
00069   int num_fail = 0;
00070 
00071   num_fail += RUN_TEST(testAlgorithmFail);
00072   num_fail += RUN_TEST(testAlgorithmSucceed);
00073   num_fail += RUN_TEST(testAlgorithmSucceedIsoPoint);
00074   num_fail += RUN_TEST(testAlgorithmSucceedAddPoint);
00075   num_fail += RUN_TEST(testAlgorithmDefaultRulesSquare);
00076 
00077   delete mk;
00078 
00079   return num_fail;
00080 }
00081 
00082 AF2Rule* makeFillTriangleRule()
00083 {
00084   // existing vertices
00085   std::list<const AF2RuleExistVertex*> exVertices;
00086   AF2RuleExistVertex* originVertexPtr = new AF2RuleExistVertex(0, 0);
00087   exVertices.push_back(originVertexPtr);
00088   AF2RuleExistVertex* baseVertexPtr = new AF2RuleExistVertex(1, 0);
00089   exVertices.push_back(baseVertexPtr);
00090   AF2RuleExistVertex* peakVertexPtr =
00091       new AF2RuleExistVertex(0.5, sqrt(3.0)/2.0);
00092   exVertices.push_back(peakVertexPtr);
00093 
00094   // existing edges
00095   AF2RuleExistEdge* baseEdgePtr =
00096       new AF2RuleExistEdge(originVertexPtr, baseVertexPtr);
00097   std::list<const AF2RuleExistEdge*> exEdges;
00098   exEdges.push_back(new AF2RuleExistEdge(baseVertexPtr, peakVertexPtr));
00099   exEdges.push_back(new AF2RuleExistEdge(peakVertexPtr, originVertexPtr));
00100 
00101   // free zone definition
00102   // free zone definition lists
00103   std::list<AF2Point2D> bndryPnts;
00104   std::list<const AF2PointTransform*> bndryPntTransforms;
00105 
00106   // first element free zone definition lists
00107   AF2Point2D alpha(0, 0);
00108   AF2PointTransform* alphaTransform = new AF2PointTransformNone();
00109   bndryPnts.push_back(alpha);
00110   bndryPntTransforms.push_back(alphaTransform);
00111 
00112   // second element free zone definition lists
00113   AF2Point2D bravo(1, 0);
00114   AF2PointTransform* bravoTransform = new AF2PointTransformNone();
00115   bndryPnts.push_back(bravo);
00116   bndryPntTransforms.push_back(bravoTransform);
00117 
00118   // third element free zone definition lists
00119   AF2Point2D charlie(0.5, sqrt(3.0)/2.0);
00120   AF2PointTransform* charlieTransform = new AF2PointTransformNone();
00121   bndryPnts.push_back(charlie);
00122   bndryPntTransforms.push_back(charlieTransform);
00123 
00124   AF2FreeZoneDef* freeZoneDef = new AF2FreeZoneDefSimple(
00125       bndryPnts, bndryPntTransforms);
00126   delete alphaTransform;
00127   delete bravoTransform;
00128   delete charlieTransform;
00129 
00130   // no new vertices
00131   std::list<const AF2RuleNewVertex*> newVertices;
00132 
00133   // no new edges
00134   std::list<const AF2RuleNewEdge*> newEdges;
00135 
00136   // new face
00137   std::list<const AF2RuleNewFace*> newFaces;
00138   AF2RuleNewFace* newFacePtr = new AF2RuleNewTriangle(0, 1, 2);
00139   newFaces.push_back(newFacePtr);
00140 
00141   AF2Rule* rulePtr = new AF2Rule("Fill Triangle", 1u, exVertices,
00142       baseEdgePtr, exEdges, freeZoneDef, newVertices, newEdges, newFaces);
00143 
00144   return rulePtr;
00145 }
00146 
00147 AF2Rule* makeCloseTriangleRule()
00148 {
00149   // existing vertices
00150   std::list<const AF2RuleExistVertex*> exVertices;
00151   AF2RuleExistVertex* originVertexPtr = new AF2RuleExistVertex(0, 0);
00152   exVertices.push_back(originVertexPtr);
00153   AF2RuleExistVertex* baseVertexPtr = new AF2RuleExistVertex(1, 0);
00154   exVertices.push_back(baseVertexPtr);
00155   AF2RuleExistVertex* peakVertexPtr =
00156       new AF2RuleExistVertex(0.5, sqrt(3.0)/2.0);
00157   exVertices.push_back(peakVertexPtr);
00158 
00159   // existing edges
00160   AF2RuleExistEdge* baseEdgePtr =
00161       new AF2RuleExistEdge(originVertexPtr, baseVertexPtr);
00162   std::list<const AF2RuleExistEdge*> exEdges;
00163   exEdges.push_back(new AF2RuleExistEdge(peakVertexPtr, originVertexPtr));
00164 
00165   // free zone definition
00166   // free zone definition lists
00167   std::list<AF2Point2D> bndryPnts;
00168   std::list<const AF2PointTransform*> bndryPntTransforms;
00169 
00170   // first element free zone definition lists
00171   AF2Point2D alpha(0, 0);
00172   AF2PointTransform* alphaTransform = new AF2PointTransformNone();
00173   bndryPnts.push_back(alpha);
00174   bndryPntTransforms.push_back(alphaTransform);
00175 
00176   // second element free zone definition lists
00177   AF2Point2D bravo(1, 0);
00178   AF2PointTransform* bravoTransform = new AF2PointTransformNone();
00179   bndryPnts.push_back(bravo);
00180   bndryPntTransforms.push_back(bravoTransform);
00181 
00182   // third element free zone definition lists
00183   AF2Point2D charlie(0.5, sqrt(3.0)/2.0);
00184   AF2PointTransform* charlieTransform = new AF2PointTransformNone();
00185   bndryPnts.push_back(charlie);
00186   bndryPntTransforms.push_back(charlieTransform);
00187 
00188   AF2FreeZoneDef* freeZoneDef = new AF2FreeZoneDefSimple(
00189       bndryPnts, bndryPntTransforms);
00190   delete alphaTransform;
00191   delete bravoTransform;
00192   delete charlieTransform;
00193 
00194   // no new vertices
00195   std::list<const AF2RuleNewVertex*> newVertices;
00196 
00197   // new edge
00198   std::list<const AF2RuleNewEdge*> newEdges;
00199   AF2RuleNewEdge* newEdgePtr = new AF2RuleNewEdge(2, 1);
00200   newEdges.push_back(newEdgePtr);
00201 
00202   // new face
00203   std::list<const AF2RuleNewFace*> newFaces;
00204   AF2RuleNewFace* newFacePtr = new AF2RuleNewTriangle(0, 1, 2);
00205   newFaces.push_back(newFacePtr);
00206 
00207   AF2Rule* rulePtr = new AF2Rule("Close Triangle", 1u, exVertices,
00208       baseEdgePtr, exEdges, freeZoneDef, newVertices, newEdges, newFaces);
00209 
00210   return rulePtr;
00211 }
00212 
00213 AF2Rule* makeConnectToVertexRule()
00214 {
00215   // existing vertices
00216   std::list<const AF2RuleExistVertex*> exVertices;
00217   AF2RuleExistVertex* originVertexPtr = new AF2RuleExistVertex(0, 0);
00218   exVertices.push_back(originVertexPtr);
00219   AF2RuleExistVertex* baseVertexPtr = new AF2RuleExistVertex(1, 0);
00220   exVertices.push_back(baseVertexPtr);
00221   AF2RuleExistVertex* peakVertexPtr =
00222       new AF2RuleExistVertex(0.5, sqrt(3.0)/2.0);
00223   exVertices.push_back(peakVertexPtr);
00224 
00225   // existing edges
00226   AF2RuleExistEdge* baseEdgePtr =
00227       new AF2RuleExistEdge(originVertexPtr, baseVertexPtr);
00228   std::list<const AF2RuleExistEdge*> exEdges;
00229 
00230   // free zone definition
00231   // free zone definition lists
00232   std::list<AF2Point2D> bndryPnts;
00233   std::list<const AF2PointTransform*> bndryPntTransforms;
00234 
00235   // first element free zone definition lists
00236   AF2Point2D alpha(0, 0);
00237   AF2PointTransform* alphaTransform = new AF2PointTransformNone();
00238   bndryPnts.push_back(alpha);
00239   bndryPntTransforms.push_back(alphaTransform);
00240 
00241   // second element free zone definition lists
00242   AF2Point2D bravo(1, 0);
00243   AF2PointTransform* bravoTransform = new AF2PointTransformNone();
00244   bndryPnts.push_back(bravo);
00245   bndryPntTransforms.push_back(bravoTransform);
00246 
00247   // third element free zone definition lists
00248   AF2Point2D charlie(1.4, 0.75);
00249   AF2PointTransform* charlieTransform = new AF2PointTransformNone();
00250   bndryPnts.push_back(charlie);
00251   bndryPntTransforms.push_back(charlieTransform);
00252 
00253   // fourth element free zone definition lists
00254   AF2Point2D delta(0.5, sqrt(3.0)/2.0);
00255   AF2PointTransform* deltaTransform = new AF2PointTransformNone();
00256   bndryPnts.push_back(delta);
00257   bndryPntTransforms.push_back(deltaTransform);
00258 
00259   // fifth element free zone definition lists
00260   AF2Point2D echo(-0.4, 0.75);
00261   AF2PointTransform* echoTransform = new AF2PointTransformNone();
00262   bndryPnts.push_back(echo);
00263   bndryPntTransforms.push_back(echoTransform);
00264 
00265   AF2FreeZoneDef* freeZoneDef = new AF2FreeZoneDefSimple(
00266       bndryPnts, bndryPntTransforms);
00267   delete alphaTransform;
00268   delete bravoTransform;
00269   delete charlieTransform;
00270   delete deltaTransform;
00271   delete echoTransform;
00272 
00273   // no new vertices
00274   std::list<const AF2RuleNewVertex*> newVertices;
00275 
00276   // new edges
00277   std::list<const AF2RuleNewEdge*> newEdges;
00278   AF2RuleNewEdge* newEdgePtr = new AF2RuleNewEdge(0, 2);
00279   newEdges.push_back(newEdgePtr);
00280   newEdgePtr = new AF2RuleNewEdge(2, 1);
00281   newEdges.push_back(newEdgePtr);
00282 
00283   // new face
00284   std::list<const AF2RuleNewFace*> newFaces;
00285   AF2RuleNewFace* newFacePtr = new AF2RuleNewTriangle(0, 1, 2);
00286   newFaces.push_back(newFacePtr);
00287 
00288   AF2Rule* rulePtr = new AF2Rule("Connect To Vertex", 1u, exVertices,
00289       baseEdgePtr, exEdges, freeZoneDef, newVertices, newEdges, newFaces);
00290 
00291   return rulePtr;
00292 }
00293 
00294 AF2Rule* makeAddPeakVertexRule()
00295 {
00296   // existing vertices
00297   std::list<const AF2RuleExistVertex*> exVertices;
00298   AF2RuleExistVertex* originVertexPtr = new AF2RuleExistVertex(0, 0);
00299   exVertices.push_back(originVertexPtr);
00300   AF2RuleExistVertex* baseVertexPtr = new AF2RuleExistVertex(1, 0);
00301   exVertices.push_back(baseVertexPtr);
00302 
00303   // existing edges
00304   AF2RuleExistEdge* baseEdgePtr =
00305       new AF2RuleExistEdge(originVertexPtr, baseVertexPtr);
00306   std::list<const AF2RuleExistEdge*> exEdges;
00307 
00308   // free zone definition
00309   // free zone definition lists
00310   std::list<AF2Point2D> bndryPnts;
00311   std::list<const AF2PointTransform*> bndryPntTransforms;
00312 
00313   // first element free zone definition lists
00314   AF2Point2D alpha(0, 0);
00315   AF2PointTransform* alphaTransform = new AF2PointTransformNone();
00316   bndryPnts.push_back(alpha);
00317   bndryPntTransforms.push_back(alphaTransform);
00318 
00319   // second element free zone definition lists
00320   AF2Point2D bravo(1, 0);
00321   AF2PointTransform* bravoTransform = new AF2PointTransformNone();
00322   bndryPnts.push_back(bravo);
00323   bndryPntTransforms.push_back(bravoTransform);
00324 
00325   // third element free zone definition lists
00326   AF2Point2D charlie(1.4, 0.75);
00327   AF2PointTransform* charlieTransform = new AF2PointTransformNone();
00328   bndryPnts.push_back(charlie);
00329   bndryPntTransforms.push_back(charlieTransform);
00330 
00331   // fourth element free zone definition lists
00332   AF2Point2D delta(0.5, 1.25);
00333   AF2PointTransform* deltaTransform = new AF2PointTransformNone();
00334   bndryPnts.push_back(delta);
00335   bndryPntTransforms.push_back(deltaTransform);
00336 
00337   // fifth element free zone definition lists
00338   AF2Point2D echo(-0.4, 0.75);
00339   AF2PointTransform* echoTransform = new AF2PointTransformNone();
00340   bndryPnts.push_back(echo);
00341   bndryPntTransforms.push_back(echoTransform);
00342 
00343   AF2FreeZoneDef* freeZoneDef = new AF2FreeZoneDefSimple(
00344       bndryPnts, bndryPntTransforms);
00345   delete alphaTransform;
00346   delete bravoTransform;
00347   delete charlieTransform;
00348   delete deltaTransform;
00349   delete echoTransform;
00350 
00351   // new vertex
00352   std::list<const AF2RuleNewVertex*> newVertices;
00353   AF2Point2D newVertexLoc(0.5, sqrt(3.0)/2.0);
00354   AF2PointTransform* newVertexTransform = new AF2PointTransformNone();
00355   AF2RuleNewVertex* newVertex =
00356       new AF2RuleNewVertex(newVertexLoc, newVertexTransform);
00357   delete newVertexTransform;
00358   newVertices.push_back(newVertex);
00359 
00360   // new edges
00361   std::list<const AF2RuleNewEdge*> newEdges;
00362   AF2RuleNewEdge* newEdgePtr = new AF2RuleNewEdge(0, 2);
00363   newEdges.push_back(newEdgePtr);
00364   newEdgePtr = new AF2RuleNewEdge(2, 1);
00365   newEdges.push_back(newEdgePtr);
00366 
00367   // new face
00368   std::list<const AF2RuleNewFace*> newFaces;
00369   AF2RuleNewFace* newFacePtr = new AF2RuleNewTriangle(0, 1, 2);
00370   newFaces.push_back(newFacePtr);
00371 
00372   AF2Rule* rulePtr = new AF2Rule("Add Peak Vertex", 1u, exVertices,
00373       baseEdgePtr, exEdges, freeZoneDef, newVertices, newEdges, newFaces);
00374 
00375   return rulePtr;
00376 }
00377 
00378 void testAlgorithmFail()
00379 {
00380   AF2Rule* closeTriRule = makeCloseTriangleRule();
00381   AF2Rule* fillTriRule = makeFillTriangleRule();
00382   AF2LocalTransformMaker* transformMaker = new AF2DfltPlaneProjMaker(
00383       square->igeom_instance(), square->geom_handle());
00384   std::list<const AF2Rule*> ruleList;
00385   ruleList.push_back(closeTriRule);
00386   ruleList.push_back(fillTriRule);
00387 
00388   AF2Algorithm alg(ruleList);
00389 
00390   // coordinates of a regular hexagon with side length 0.1
00391   std::vector<double> coordinates;
00392   coordinates.push_back(-0.5);
00393   coordinates.push_back(0.0);
00394   coordinates.push_back(-0.5);
00395   coordinates.push_back(-0.4);
00396   coordinates.push_back(0.0);
00397   coordinates.push_back(-0.5);
00398   coordinates.push_back(-0.35);
00399   coordinates.push_back(sqrt(3)/20.0);
00400   coordinates.push_back(-0.5);
00401   coordinates.push_back(-0.4);
00402   coordinates.push_back(sqrt(3)/10.0);
00403   coordinates.push_back(-0.5);
00404   coordinates.push_back(-0.5);
00405   coordinates.push_back(sqrt(3)/10.0);
00406   coordinates.push_back(-0.5);
00407   coordinates.push_back(-0.55);
00408   coordinates.push_back(sqrt(3)/20.0);
00409   coordinates.push_back(-0.5);
00410 
00411   // edges of the regular hexagon
00412   std::vector<unsigned int> edges;
00413   edges.push_back(0u);
00414   edges.push_back(1u);
00415   edges.push_back(1u);
00416   edges.push_back(2u);
00417   edges.push_back(2u);
00418   edges.push_back(3u);
00419   edges.push_back(3u);
00420   edges.push_back(4u);
00421   edges.push_back(4u);
00422   edges.push_back(5u);
00423   edges.push_back(5u);
00424   edges.push_back(0u);
00425 
00426   unsigned int numPoints = coordinates.size() / 3;
00427   unsigned int numEdges = edges.size() / 2;
00428   AF2AlgorithmResult* result = alg.execute(
00429       transformMaker, &(coordinates[0]), numPoints, &(edges[0]), numEdges);
00430 
00431   CHECK(!result->isSuccessful());
00432   std::cout << "Good: Algorithm result is not successful." << std::endl;
00433 
00434   ruleList.clear();
00435   delete result;
00436   delete transformMaker;
00437   delete fillTriRule;
00438   delete closeTriRule;
00439 
00440   std::cout << "PASS: The algorithm appears to run properly on a hexagon\n"
00441       << "  with no rules that allow adding points and no free zones that\n"
00442       << "  have point transforms."  << std::endl;
00443 }
00444 
00445 void testAlgorithmSucceed()
00446 {
00447   AF2Rule* closeTriRule = makeCloseTriangleRule();
00448   AF2Rule* fillTriRule = makeFillTriangleRule();
00449   AF2LocalTransformMaker* transformMaker = new AF2DfltPlaneProjMaker(
00450       square->igeom_instance(), square->geom_handle());
00451   std::list<const AF2Rule*> ruleList;
00452   ruleList.push_back(closeTriRule);
00453   ruleList.push_back(fillTriRule);
00454 
00455   AF2Algorithm alg(ruleList);
00456 
00457   // coordinates of a regular hexagon with side length 0.1
00458   // plus the coordinates of a central vertex
00459   std::vector<double> coordinates;
00460   coordinates.push_back(-0.5);
00461   coordinates.push_back(0.0);
00462   coordinates.push_back(-0.5);
00463   coordinates.push_back(-0.4);
00464   coordinates.push_back(0.0);
00465   coordinates.push_back(-0.5);
00466   coordinates.push_back(-0.35);
00467   coordinates.push_back(sqrt(3)/20.0);
00468   coordinates.push_back(-0.5);
00469   coordinates.push_back(-0.4);
00470   coordinates.push_back(sqrt(3)/10.0);
00471   coordinates.push_back(-0.5);
00472   coordinates.push_back(-0.5);
00473   coordinates.push_back(sqrt(3)/10.0);
00474   coordinates.push_back(-0.5);
00475   coordinates.push_back(-0.55);
00476   coordinates.push_back(sqrt(3)/20.0);
00477   coordinates.push_back(-0.5);
00478   coordinates.push_back(-0.45);
00479   coordinates.push_back(sqrt(3)/20.0);
00480   coordinates.push_back(-0.5);
00481 
00482   // edges of the regular hexagon, plus a hanging edge to the central vertex
00483   std::vector<unsigned int> edges;
00484   edges.push_back(0u);
00485   edges.push_back(6u);
00486   edges.push_back(6u);
00487   edges.push_back(0u);
00488   edges.push_back(0u);
00489   edges.push_back(1u);
00490   edges.push_back(1u);
00491   edges.push_back(2u);
00492   edges.push_back(2u);
00493   edges.push_back(3u);
00494   edges.push_back(3u);
00495   edges.push_back(4u);
00496   edges.push_back(4u);
00497   edges.push_back(5u);
00498   edges.push_back(5u);
00499   edges.push_back(0u);
00500 
00501   unsigned int numPoints = coordinates.size() / 3;
00502   unsigned int numEdges = edges.size() / 2;
00503   AF2AlgorithmResult* result = alg.execute(
00504       transformMaker, &(coordinates[0]), numPoints, &(edges[0]), numEdges);
00505 
00506   CHECK(result->isSuccessful());
00507   std::cout << "Good: Algorithm result is successful." << std::endl;
00508   std::list<AF2Point3D*>::size_type sizeSeven(7u);
00509   CHECK_EQUAL(sizeSeven, result->getPoints()->size());
00510   std::cout << "Good: Algorithm result has seven points." << std::endl;
00511   std::list<const AF2Polygon3D*>::size_type sizeSix(6u);
00512   CHECK_EQUAL(sizeSix, result->getFaces()->size());
00513   std::cout << "Good: Algorithm result has six faces." << std::endl;
00514 
00515   ruleList.clear();
00516   delete result;
00517   delete transformMaker;
00518   delete fillTriRule;
00519   delete closeTriRule;
00520 
00521   std::cout << "PASS: The algorithm appears to run properly on a hexagon\n"
00522       << "  with a hanging edge." << std::endl;
00523 }
00524 
00525 void testAlgorithmSucceedIsoPoint()
00526 {
00527   AF2Rule* closeTriRule = makeCloseTriangleRule();
00528   AF2Rule* fillTriRule = makeFillTriangleRule();
00529   AF2Rule* connectToVertexRule = makeConnectToVertexRule();
00530   AF2LocalTransformMaker* transformMaker = new AF2DfltPlaneProjMaker(
00531       square->igeom_instance(), square->geom_handle());
00532   std::list<const AF2Rule*> ruleList;
00533   ruleList.push_back(closeTriRule);
00534   ruleList.push_back(fillTriRule);
00535   ruleList.push_back(connectToVertexRule);
00536 
00537   AF2Algorithm alg(ruleList);
00538 
00539   // coordinates of a regular hexagon with side length 0.1
00540   // plus the coordinates of a central vertex
00541   std::vector<double> coordinates;
00542   coordinates.push_back(-0.5);
00543   coordinates.push_back(0.0);
00544   coordinates.push_back(-0.5);
00545   coordinates.push_back(-0.4);
00546   coordinates.push_back(0.0);
00547   coordinates.push_back(-0.5);
00548   coordinates.push_back(-0.35);
00549   coordinates.push_back(sqrt(3)/20.0);
00550   coordinates.push_back(-0.5);
00551   coordinates.push_back(-0.4);
00552   coordinates.push_back(sqrt(3)/10.0);
00553   coordinates.push_back(-0.5);
00554   coordinates.push_back(-0.5);
00555   coordinates.push_back(sqrt(3)/10.0);
00556   coordinates.push_back(-0.5);
00557   coordinates.push_back(-0.55);
00558   coordinates.push_back(sqrt(3)/20.0);
00559   coordinates.push_back(-0.5);
00560   coordinates.push_back(-0.45);
00561   coordinates.push_back(sqrt(3)/20.0);
00562   coordinates.push_back(-0.5);
00563 
00564   // edges of the regular hexagon
00565   std::vector<unsigned int> edges;
00566   edges.push_back(0u);
00567   edges.push_back(1u);
00568   edges.push_back(1u);
00569   edges.push_back(2u);
00570   edges.push_back(2u);
00571   edges.push_back(3u);
00572   edges.push_back(3u);
00573   edges.push_back(4u);
00574   edges.push_back(4u);
00575   edges.push_back(5u);
00576   edges.push_back(5u);
00577   edges.push_back(0u);
00578 
00579   unsigned int numPoints = coordinates.size() / 3;
00580   unsigned int numEdges = edges.size() / 2;
00581   AF2AlgorithmResult* result = alg.execute(
00582       transformMaker, &(coordinates[0]), numPoints, &(edges[0]), numEdges);
00583 
00584   CHECK(result->isSuccessful());
00585   std::cout << "Good: Algorithm result is successful." << std::endl;
00586   std::list<AF2Point3D*>::size_type sizeSeven(7u);
00587   CHECK_EQUAL(sizeSeven, result->getPoints()->size());
00588   std::cout << "Good: Algorithm result has seven points." << std::endl;
00589   std::list<const AF2Polygon3D*>::size_type sizeSix(6u);
00590   CHECK_EQUAL(sizeSix, result->getFaces()->size());
00591   std::cout << "Good: Algorithm result has six faces." << std::endl;
00592 
00593   ruleList.clear();
00594   delete result;
00595   delete transformMaker;
00596   delete connectToVertexRule;
00597   delete fillTriRule;
00598   delete closeTriRule;
00599 
00600   std::cout << "PASS: The algorithm appears to run properly on a hexagon\n"
00601       << "  with an isolated central vertex." << std::endl;
00602 }
00603 
00604 void testAlgorithmSucceedAddPoint()
00605 {
00606   AF2Rule* closeTriRule = makeCloseTriangleRule();
00607   AF2Rule* fillTriRule = makeFillTriangleRule();
00608   AF2Rule* connectToVertexRule = makeConnectToVertexRule();
00609   AF2Rule* addPeakVertexRule = makeAddPeakVertexRule();
00610   AF2LocalTransformMaker* transformMaker = new AF2DfltPlaneProjMaker(
00611       square->igeom_instance(), square->geom_handle());
00612   std::list<const AF2Rule*> ruleList;
00613   ruleList.push_back(closeTriRule);
00614   ruleList.push_back(fillTriRule);
00615   ruleList.push_back(connectToVertexRule);
00616   ruleList.push_back(addPeakVertexRule);
00617 
00618   AF2Algorithm alg(ruleList);
00619 
00620   // coordinates of a regular hexagon with side length 0.1
00621   std::vector<double> coordinates;
00622   coordinates.push_back(-0.5);
00623   coordinates.push_back(0.0);
00624   coordinates.push_back(-0.5);
00625   coordinates.push_back(-0.4);
00626   coordinates.push_back(0.0);
00627   coordinates.push_back(-0.5);
00628   coordinates.push_back(-0.35);
00629   coordinates.push_back(sqrt(3)/20.0);
00630   coordinates.push_back(-0.5);
00631   coordinates.push_back(-0.4);
00632   coordinates.push_back(sqrt(3)/10.0);
00633   coordinates.push_back(-0.5);
00634   coordinates.push_back(-0.5);
00635   coordinates.push_back(sqrt(3)/10.0);
00636   coordinates.push_back(-0.5);
00637   coordinates.push_back(-0.55);
00638   coordinates.push_back(sqrt(3)/20.0);
00639   coordinates.push_back(-0.5);
00640 
00641   // edges of the regular hexagon
00642   std::vector<unsigned int> edges;
00643   edges.push_back(0u);
00644   edges.push_back(1u);
00645   edges.push_back(1u);
00646   edges.push_back(2u);
00647   edges.push_back(2u);
00648   edges.push_back(3u);
00649   edges.push_back(3u);
00650   edges.push_back(4u);
00651   edges.push_back(4u);
00652   edges.push_back(5u);
00653   edges.push_back(5u);
00654   edges.push_back(0u);
00655 
00656   unsigned int numPoints = coordinates.size() / 3;
00657   unsigned int numEdges = edges.size() / 2;
00658   AF2AlgorithmResult* result = alg.execute(
00659       transformMaker, &(coordinates[0]), numPoints, &(edges[0]), numEdges);
00660 
00661   CHECK(result->isSuccessful());
00662   std::cout << "Good: Algorithm result is successful." << std::endl;
00663   std::list<AF2Point3D*>::size_type sizeSeven(7u);
00664   CHECK_EQUAL(sizeSeven, result->getPoints()->size());
00665   std::cout << "Good: Algorithm result has seven points." << std::endl;
00666   std::list<const AF2Polygon3D*>::size_type sizeSix(6u);
00667   CHECK_EQUAL(sizeSix, result->getFaces()->size());
00668   std::cout << "Good: Algorithm result has six faces." << std::endl;
00669 
00670   ruleList.clear();
00671   delete result;
00672   delete transformMaker;
00673   delete addPeakVertexRule;
00674   delete connectToVertexRule;
00675   delete fillTriRule;
00676   delete closeTriRule;
00677 
00678   std::cout << "PASS: The algorithm appears to run properly on a hexagon\n"
00679       << "  when it can add a central vertex." << std::endl;
00680 }
00681 
00682 void testAlgorithmDefaultRulesSquare()
00683 {
00684   MeshKit::SizingFunction szFunc(mk, -1, 0.1);
00685   AF2LocalTransformMaker* transformMaker = new AF2DfltPlaneProjMaker(
00686       square->igeom_instance(), square->geom_handle(), &szFunc);
00687 
00688   AF2DfltTriangleRules defaultTriRules;
00689   AF2Algorithm alg(defaultTriRules.getRules());
00690 
00691   // coordinates along the boundary of the 1.0 x 1.0 square, spacing
00692   //   coordinates to be distance 0.1 between each consecutive pair
00693   std::vector<double> coordinates;
00694   for (int i = 0; i < 10; ++i)
00695   {
00696     coordinates.push_back(-1.0 + 0.1 * i);
00697     coordinates.push_back(-0.5);
00698     coordinates.push_back(0.5);
00699   }
00700   for (int i = 0; i < 10; ++i)
00701   {
00702     coordinates.push_back(0.0);
00703     coordinates.push_back(-0.5 + 0.1 * i);
00704     coordinates.push_back(0.5);
00705   }
00706   for (int i = 0; i < 10; ++i)
00707   {
00708     coordinates.push_back(0.0 - 0.1 * i);
00709     coordinates.push_back(0.5);
00710     coordinates.push_back(0.5);
00711   }
00712   for (int i = 0; i < 10; ++i)
00713   {
00714     coordinates.push_back(-1.0);
00715     coordinates.push_back(0.5 - 0.1 * i);
00716     coordinates.push_back(0.5);
00717   }
00718 
00719   // add edges
00720   std::vector<unsigned int> edges;
00721   for (unsigned int i = 0u; i < 39u; ++i)
00722   {
00723     edges.push_back(i);
00724     edges.push_back(i + 1u);
00725   }
00726   edges.push_back(39u);
00727   edges.push_back(0u);
00728 
00729   unsigned int numPoints = coordinates.size() / 3;
00730   unsigned int numEdges = edges.size() / 2;
00731   AF2AlgorithmResult* result = alg.execute(
00732       transformMaker, &(coordinates[0]), numPoints, &(edges[0]), numEdges);
00733 
00734   CHECK(result->isSuccessful());
00735   std::cout << "Good: Algorithm result is successful." << std::endl;
00736 
00737   delete result;
00738   delete transformMaker;
00739 
00740   std::cout << "PASS: The algorithm successfully meshes a square with\n"
00741       << "  the default triangle rules." << std::endl;
00742 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines