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