cgma
edgeFaceSense.cpp
Go to the documentation of this file.
00001 
00013 #include <cmath>
00014 #include <iostream>
00015 
00016 #include "BasicTopologyEntity.hpp"
00017 #include "Body.hpp"
00018 #include "CoEdge.hpp"
00019 #include "CubitBox.hpp"
00020 #include "GeometryModifyTool.hpp"
00021 #include "GroupingEntity.hpp"
00022 #include "InitCGMA.hpp"
00023 #include "RefEdge.hpp"
00024 #include "SenseEntity.hpp"
00025 
00026 bool testSense();
00027 
00028 int main (int argc, char **argv)
00029 {
00030   CubitStatus status = InitCGMA::initialize_cgma();
00031   if (CUBIT_SUCCESS != status)
00032   {
00033     return 1;
00034   }
00035 
00036   if (!testSense())
00037   {
00038     return 2;
00039   }
00040 
00041   return 0;
00042 }
00043 
00044 bool testSense()
00045 {
00046   GeometryModifyTool *modToolPtr = GeometryModifyTool::instance();
00047 
00048   double height = 10.0;
00049   double radius = 2.5;
00050   double tol = 4e-5;
00051   Body *cylBodyPtr = modToolPtr->cylinder(height, radius, radius, radius);
00052   // assumes that the body contains one covolume corresponding to one volume
00053   // and that the volume has one shell
00054   GroupingEntity *cylShellPtr = cylBodyPtr->get_first_sense_entity_ptr()->
00055       get_basic_topology_entity_ptr()->get_first_grouping_entity_ptr();
00056 
00057   BasicTopologyEntity *vertSurfPtr = NULL;
00058   double topZVal = 0.0;
00059   double bottomZVal = 0.0;
00060   SenseEntity* cylCoFacePtr = cylShellPtr->get_first_sense_entity_ptr();
00061   while (cylCoFacePtr != NULL)
00062   {
00063     CubitBox boundingBox =
00064         cylCoFacePtr->get_basic_topology_entity_ptr()->bounding_box();
00065     if (fabs(boundingBox.z_range() - height) < tol)
00066     {
00067       topZVal = boundingBox.max_z();
00068       bottomZVal = boundingBox.min_z();
00069       vertSurfPtr = cylCoFacePtr->get_basic_topology_entity_ptr();
00070       break;
00071     }
00072   }
00073 
00074   if (vertSurfPtr == NULL)
00075   {
00076     std::cout << "Failed to find vertical face." << std::endl;
00077     return false;
00078   }
00079 
00080   CoEdge *topCoEdgePtr = NULL;
00081   CoEdge *bottomCoEdgePtr = NULL;
00082   GroupingEntity *vsLoopPtr = vertSurfPtr->get_first_grouping_entity_ptr();
00083   while (vsLoopPtr != NULL &&
00084       (topCoEdgePtr == NULL || bottomCoEdgePtr == NULL))
00085   {
00086     SenseEntity *coEdgePtr = vsLoopPtr->get_first_sense_entity_ptr();
00087     while (coEdgePtr != NULL &&
00088         (topCoEdgePtr == NULL || bottomCoEdgePtr == NULL))
00089     {
00090       CubitBox edgeBoundBox =
00091           coEdgePtr->get_basic_topology_entity_ptr()->bounding_box();
00092       if (edgeBoundBox.z_range() < tol)
00093       {
00094         if (fabs(edgeBoundBox.max_z() - topZVal) < tol)
00095         {
00096           topCoEdgePtr = dynamic_cast<CoEdge*>(coEdgePtr);
00097         }
00098         else if (fabs(edgeBoundBox.max_z() - bottomZVal) < tol)
00099         {
00100           bottomCoEdgePtr = dynamic_cast<CoEdge*>(coEdgePtr);
00101         }
00102       }
00103       coEdgePtr = coEdgePtr->next();
00104     }
00105     vsLoopPtr = vsLoopPtr->next();
00106   }
00107 
00108   if (topCoEdgePtr == NULL || bottomCoEdgePtr == NULL)
00109   {
00110     std::cout << "Failed to find top and/or bottom coedge." << std::endl;
00111     return false;
00112   }
00113 
00114   // determine the orientation of the top edge from parametrization
00115   bool topRHCC = false; // top right-handed counterclockwise
00116   RefEdge* topEdgePtr = topCoEdgePtr->get_ref_edge_ptr();
00117   double startParam = topEdgePtr->start_param();
00118   double endParam = topEdgePtr->end_param();
00119   double startDeltaParam = (endParam - startParam) / 64;
00120   CubitVector startVec, startDeltaVec;
00121   topEdgePtr->position_from_u(startParam, startVec);
00122   topEdgePtr->position_from_u(startDeltaParam, startDeltaVec);
00123   CubitVector normal = startVec * startDeltaVec; // cross product
00124   if (normal.z() > 0)
00125   {
00126     std::cout << "Top edge is parametrized/oriented counterclockwise "
00127         << std::endl
00128         << "    around top face looking down from above." << std::endl;
00129     topRHCC = true;
00130   }
00131   else
00132   {
00133     std::cout << "Top edge is parametrized/oriented clockwise "
00134         << std::endl
00135         << "    around top face looking down from above." << std::endl;
00136   }
00137 
00138   // determine the orientation of the bottom edge from parametrization
00139   bool bottomLHCC = false; // bottom left-handed counterclockwise
00140   RefEdge* bottomEdgePtr = bottomCoEdgePtr->get_ref_edge_ptr();
00141   startParam = bottomEdgePtr->start_param();
00142   endParam = bottomEdgePtr->end_param();
00143   startDeltaParam = (endParam - startParam) / 64;
00144   bottomEdgePtr->position_from_u(startParam, startVec);
00145   bottomEdgePtr->position_from_u(startDeltaParam, startDeltaVec);
00146   normal = startVec * startDeltaVec; // cross product
00147   if (normal.z() > 0)
00148   {
00149     std::cout << "Bottom edge is parametrized/oriented clockwise "
00150         << std::endl
00151         << "    around bottom face looking up from below." << std::endl;
00152   }
00153   else
00154   {
00155     std::cout << "Bottom edge is parametrized/oriented counterclockwise "
00156         << std::endl
00157         << "    around bottom face looking up from below." << std::endl;
00158     bottomLHCC = true;
00159   }
00160 
00161   // report what is expected and what the result is
00162   bool expectSameSense = (topRHCC == bottomLHCC);
00163   std::cout << "The coedges of the vertical cylinder surface should have"
00164       << std::endl << "    " << (expectSameSense ? "the same sense." :
00165       "different senses.") << std::endl;
00166   if (topCoEdgePtr->get_sense() == bottomCoEdgePtr->get_sense())
00167   {
00168     std::cout << "The senses are the same." << std::endl;
00169   }
00170   else
00171   {
00172     std::cout << "The senses are different." << std::endl;
00173   }
00174 
00175   // fail the test if necessary
00176   if (expectSameSense &&
00177       topCoEdgePtr->get_sense() != bottomCoEdgePtr->get_sense())
00178   {
00179     std::cout << "FAILED TEST." << std::endl;
00180     return false;
00181   }
00182   else if (!expectSameSense &&
00183       topCoEdgePtr->get_sense() == bottomCoEdgePtr->get_sense())
00184   {
00185     std::cout << "FAILED TEST." << std::endl;
00186     return false;
00187   }
00188 
00189   // pass the test
00190   std::cout << "PASSED TEST." << std::endl;
00191   return true;
00192 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines