static int test_oriented_brick() { CubitVector center(1, 2, 4); CubitVector axes[3] = { CubitVector(0.707, 0.707, 0), CubitVector(-0.707, 0.707, 0), CubitVector(0, 0, 1) }; CubitVector extension(3, 5, 7); Body* brick = GeometryModifyTool::instance()->brick(center, axes, extension); if(!brick) { printf("failed to make brick\n"); return 1; } CubitBox comp_box(CubitVector(-4.656854, -3.656854, -3.), CubitVector(6.656854, 7.656854, 11.)); CubitBox bnd_box = brick->bounding_box(); bool identical = cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true); if (identical) return 0; if( bnd_box < comp_box || bnd_box > comp_box*1.09) { printf("boxes not identical\n"); return 1; } return 0; }
CubitVector SurfaceOverlapFacet::smallest_edge_midpoint() { CubitVector point1 = CubitVector( t.b.x, t.b.y, t.b.z ); CubitVector point2 = CubitVector( t.e0.x + t.b.x, t.e0.y + t.b.y, t.e0.z + t.b.z ); CubitVector point3 = CubitVector( t.e1.x + t.b.x, t.e1.y + t.b.y, t.e1.z + t.b.z ); double len_12 = point1.distance_between( point2 ); double len_23 = point2.distance_between( point3 ); double len_13 = point1.distance_between( point3 ); if( (len_12 < len_23) && (len_12 < len_13) ) { point1 += point2; point1 /= 2; return point1; } else if( len_23 < len_13 ) { point2 += point3; point2 /= 2; return point2; } else { point1 += point3; point1 /= 2; return point1; } }
//------------------------------------------------------------------------- // Purpose : Calculates the derivitives at a given parameter location. // //------------------------------------------------------------------------- CubitStatus OCCSurface::uv_derivitives( double u, double v, CubitVector &du, CubitVector &dv ) { BRepAdaptor_Surface asurface(*myTopoDSFace); gp_Pnt p; gp_Vec d1u, d1v; asurface.D1(u, v, p, d1u, d1v); du = CubitVector(d1u.X(), d1u.Y(), d1u.Z()); dv = CubitVector(d1v.X(), d1v.Y(), d1v.Z()); return CUBIT_SUCCESS; }
bool PST_Face::calculate_plane() { update_plane_ = 0; // Use Newell's method CubitVector dif, sum, ref(0.,0.,0.); CubitVector norm(0.,0.,0.); // For each coedge... PST_CoEdge* ce = coedge_; int count = 0; do { count++; const CubitVector& pt1 = ce->start_coord(); const CubitVector& pt2 = ce->end_coord(); dif = pt2 - pt1; sum = pt2 + pt1; ref += pt1; norm += CubitVector( dif.y()*sum.z(), dif.z()*sum.x(), dif.x()*sum.y() ); ce = ce->next(); assert( count < PST_MAX_LIST_LEN ); } while( ce != coedge_ ); // Degenerate? double len = norm.length(); if( len > CUBIT_RESABS ) { double d = (ref % norm) / (count * len); norm /= -len; //reverse and normalize plane_.normal( norm ); plane_.coefficient( d ); return true; } else { plane_.normal( CubitVector(0.,0.,0.) ); plane_.coefficient( 0. ); return false; } }
//------------------------------------------------------------------------- // Purpose : Computes the closest_point on the surface to the input // location. Optionally, it also computes and returns // the normal to the surface at closest_location and the // principal curvatures(1-min, 2-max) // //------------------------------------------------------------------------- CubitStatus OCCSurface::closest_point( CubitVector const& location, CubitVector* closest_location, CubitVector* unit_normal_ptr, CubitVector* curvature_1, CubitVector* curvature_2) { BRepAdaptor_Surface asurface(*myTopoDSFace); gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0); double minDist=0.0, u, v; int i; BRepLProp_SLProps SLP(asurface, 2, Precision::PConfusion()); Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); ext.Point(i).Parameter(u, v); SLP.SetParameters(u, v); } } if (closest_location != NULL) *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z()); if (unit_normal_ptr != NULL) { gp_Dir normal; //normal of a RefFace point to outside of the material if (SLP.IsNormalDefined()) { normal = SLP.Normal(); CubitSense sense = get_geometry_sense(); if(sense == CUBIT_REVERSED) normal.Reverse() ; *unit_normal_ptr = CubitVector(normal.X(), normal.Y(), normal.Z()); } } gp_Dir MaxD, MinD; if (SLP.IsCurvatureDefined()) { SLP.CurvatureDirections(MaxD, MinD); if (curvature_1 != NULL) *curvature_1 = CubitVector(MinD.X(), MinD.Y(), MinD.Z()); if (curvature_2 != NULL) *curvature_2 = CubitVector(MaxD.X(), MaxD.Y(), MaxD.Z()); } } return CUBIT_SUCCESS; }
void SurfaceOverlapFacet::draw( int color ) { CubitVector point1 = CubitVector( t.b.x, t.b.y, t.b.z ); CubitVector point2 = CubitVector( t.e0.x + t.b.x, t.e0.y + t.b.y, t.e0.z + t.b.z ); CubitVector point3 = CubitVector( t.e1.x + t.b.x, t.e1.y + t.b.y, t.e1.z + t.b.z ); GfxPreview::draw_line( point1, point2, color ); GfxPreview::draw_line( point2, point3, color ); GfxPreview::draw_line( point1, point3, color ); return; }
CubitStatus OCCSurface::principal_curvatures( CubitVector const& location, double& curvature_1, double& curvature_2, CubitVector* closest_location ) { BRepAdaptor_Surface asurface(*myTopoDSFace); gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0); double minDist=0.0, u, v; int i; BRepLProp_SLProps SLP(asurface, 2, Precision::PConfusion()); Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); ext.Point(i).Parameter(u, v); SLP.SetParameters(u, v); } } } if (closest_location != NULL) *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z()); if (SLP.IsCurvatureDefined()) { curvature_1 = SLP.MinCurvature(); curvature_2 = SLP.MaxCurvature(); } return CUBIT_SUCCESS; }
CubitVector SurfaceOverlapFacet::centroid() { CubitVector point1 = CubitVector( t.b.x, t.b.y, t.b.z ); CubitVector point2 = CubitVector( t.e0.x + t.b.x, t.e0.y + t.b.y, t.e0.z + t.b.z ); CubitVector point3 = CubitVector( t.e1.x + t.b.x, t.e1.y + t.b.y, t.e1.z + t.b.z ); point1 += point2; point1 += point3; point1 /= 3; return point1; }
//------------------------------------------------------------------------- // Purpose : Given values of the two parameters, get the position. // // Special Notes : // //------------------------------------------------------------------------- CubitVector FacetSurface::position_from_u_v (double u, double v) { if ( myEvaluator ) return myEvaluator->position_from_u_v( u, v ); PRINT_ERROR("Faceted geometry currently does not support u-v parameterization.\n"); return CubitVector (0,0,0); }
static int test_brick() { Body* brick = GeometryModifyTool::instance()->brick(1,2,4); if(!brick) { printf("failed to make brick\n"); return 1; } if(!cubit_box_identical(brick->bounding_box(), CubitBox(CubitVector(-0.5,-1,-2), CubitVector(0.5,1,2)), GEOMETRY_RESABS*2.0, true)) { printf("boxes not identical\n"); return 1; } return 0; }
static int test_sphere() { Body* sphere = GeometryModifyTool::instance()->sphere(1); if(!sphere) { printf("failed to make sphere\n"); return 1; } CubitBox comp_box( CubitVector(-1,-1,-1), CubitVector(1,1,1)); CubitBox bnd_box = sphere->bounding_box(); bool identical = cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true); if (identical) return 0; if( bnd_box < comp_box || bnd_box > comp_box*1.09) { printf("boxes not identical\n"); return 1; } return 0; }
static int test_torus() { printf("making torus\n"); Body* torus = GeometryModifyTool::instance()->torus(1, .2); if(!torus) { printf("failed to make torus\n"); return 1; } CubitBox comp_box(CubitVector(-1.2,-1.2,-0.2), CubitVector(1.2,1.2,0.2)); CubitBox bnd_box = torus->bounding_box(); bool identical = cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true); if (identical) return 0; if( bnd_box < comp_box || bnd_box > comp_box*1.09) { printf("boxes not identical\n"); return 1; } return 0; }
int main( int argc, char* argv[] ) { // Start up CGM CubitStatus result = InitCGMA::initialize_cgma(TEST_ENGINE); if (CUBIT_SUCCESS != result) return 1; // Create a brick Body* brick = GMI->brick(BS, BS, BS); assert(brick != 0); DLIList<Body *> bodies, single_body, all_bodies, neighbor_list, new_bodies; all_bodies.append(brick); for (int i = -1; i <= 1; i+= 2) { for (int j = -1; j <= 1; j+= 2) { for (int k = -1; k <= 1; k+= 2) { Body* sph = GMI->sphere(RAD); assert(brick != 0); GQI->translate(sph, CubitVector(i*.5*BS, j*.5*BS, k*.5*BS)); bodies.append(sph); } } } CubitStatus stat = GMI->unite(bodies, single_body); assert(CUBIT_SUCCESS == stat && single_body.size() == 1); stat = GMI->webcut_with_body(all_bodies, single_body.get(), new_bodies, neighbor_list); assert(CUBIT_SUCCESS == stat); std::cout << "Number of resulting bodies = " << new_bodies.size() << std::endl; DLIList<RefEntity*> re_list; for (int i = 0; i < new_bodies.size(); i++) re_list.append(new_bodies.get_and_step()); if(export_b == 1) { int num_exp; CubitString vers; ModelExportOptions opts; stat = GQI->export_solid_model (re_list, "spheres.sat", ACIS_SAT_TYPE, num_exp, vers, opts); } bodies.clean_out(); GQI->bodies(bodies); assert (bodies.size() == 10); //delete all entities GQI->delete_Body(bodies); DLIList<RefEntity*> free_entities; GQI->get_free_ref_entities(free_entities); assert(free_entities.size() ==0); return 0; }
//------------------------------------------------------------------------- // Purpose : Computes the closest_point on the trimmed surface to the // input location. // // Special Notes : //------------------------------------------------------------------------- void OCCSurface::closest_point_trimmed( CubitVector from_point, CubitVector& point_on_surface) { BRepAdaptor_Surface asurface(*myTopoDSFace); gp_Pnt p(from_point.x(), from_point.y(), from_point.z()), newP(0.0, 0.0, 0.0); double minDist=0.0; int i; Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); } } } point_on_surface = CubitVector(newP.X(), newP.Y(), newP.Z()); }
//------------------------------------------------------------------------- // Purpose : This function returns the {u, v} coordinates of the point // on the Surface closest to the input point (specified in // global space). The closest_location is also returned. // // Special Notes : // //------------------------------------------------------------------------- CubitStatus OCCSurface::u_v_from_position( CubitVector const& location, double& u, double& v, CubitVector* closest_location ) { BRepAdaptor_Surface asurface(*myTopoDSFace); Handle(Geom_Surface) surface = BRep_Tool::Surface(*myTopoDSFace); gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0); GeomAPI_ProjectPointOnSurf projection( p, surface); if(projection.NbPoints() > 0) { if(projection.LowerDistance() < Precision::Confusion() ) { projection.LowerDistanceParameters(u, v); return CUBIT_SUCCESS; } } double minDist=0.0; int i; Extrema_ExtPS ext(p, asurface, Precision::Confusion(), Precision::Confusion()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); ext.Point(i).Parameter(u, v); } } } if (closest_location != NULL) *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z()); if (ext.IsDone() && (ext.NbExt() > 0)) return CUBIT_SUCCESS; Handle(ShapeAnalysis_Surface) su = new ShapeAnalysis_Surface(surface); gp_Pnt2d suval = su->ValueOfUV(p, BRep_Tool::Tolerance(*myTopoDSFace)); suval.Coord(u, v); return CUBIT_SUCCESS; }
//------------------------------------------------------------------------- // Purpose : Given values of the two parameters, get the position. // // Special Notes : // //------------------------------------------------------------------------- CubitVector OCCSurface::position_from_u_v (double u, double v) { BRepAdaptor_Surface asurface(*myTopoDSFace, Standard_False); gp_Pnt p = asurface.Value(u, v); return CubitVector (p.X(), p.Y(), p.Z()); }
static inline CubitVector coordinates(GPoint* p) { return CubitVector( p->x, p->y, p->z ); }
static int test_arc() { RefVertex* pt1 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(0,0,0)); RefVertex* pt2 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(1,1,0)); RefVertex* pt3 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(2,0,0)); RefEdge* arc = GeometryModifyTool::instance()->create_arc_three(pt1, pt2, pt3, false); if(!arc) { printf("failed to make arc\n"); return 1; } CubitBox comp_box(CubitVector(0, 0, 0), CubitVector(2, 1, 0)); CubitBox bnd_box = arc->bounding_box(); bool identical = cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true); if (!identical) { if( bnd_box < comp_box || bnd_box > comp_box*1.09) { printf("boxes not identical\n"); return 1; } } // previously free curves at end points must be consumed DLIList<RefVertex*> all_verts; GeometryQueryTool::instance()->ref_vertices(all_verts); if(all_verts.size() != 3) { printf("vertices not consumed properly with curve creation\n"); return 1; } GeometryQueryTool::instance()->delete_RefVertex(pt2); RefVertex* pt4 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(1,-1,0)); RefEdge* arc2 = GeometryModifyTool::instance()->create_arc_three(pt1, pt4, pt3, true); CubitBox comp_box2(CubitVector(0, -1, 0), CubitVector(2, 1, 0)); bnd_box = arc2->bounding_box(); identical = cubit_box_identical(bnd_box, comp_box2, GEOMETRY_RESABS*2.0, true); if (identical) return 0; if( bnd_box < comp_box2 || bnd_box > comp_box2*1.09) { printf("boxes not identical\n"); return 1; } all_verts.clean_out(); GeometryQueryTool::instance()->ref_vertices(all_verts); if(all_verts.size() != 4) { printf("vertices not consumed properly with curve creation\n"); return 1; } return 0; }
static int test_planar_sheet() { CubitVector axes[2] = { CubitVector(1,0,0), CubitVector(.1,.9,0) }; Body* body = GeometryModifyTool::instance()->planar_sheet(CubitVector(1,1,1), axes, 2, 3); if(!body) { printf("failed to make planar sheet\n"); return 1; } CubitBox comp_box(CubitVector(-0.165647,-0.490826,1.0), CubitVector(2.165647,2.490826,1.0)); CubitBox bnd_box = body->bounding_box(); bool identical = cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true); if (identical) return 0; if( bnd_box < comp_box || bnd_box > comp_box*1.09) { printf("boxes not identical\n"); return 1; } body = GeometryModifyTool::instance()->planar_sheet( CubitVector(0,0,0), CubitVector(1,0,0), CubitVector(1,1,0), CubitVector(0,1,.2) ); if(body) { printf("should have failed to make planar sheet out of non-planar points\n"); return 1; } body = GeometryModifyTool::instance()->planar_sheet( CubitVector(0,0,0), CubitVector(0,0,0), CubitVector(1,1,0), CubitVector(0,1,0) ); if(body) { printf("should have failed to make planar sheet with coincident input points\n"); return 1; } return 0; }