Branch data Line data Source code
1 : : //-------------------------------------------------------------------------
2 : : // Filename : AutoMidsurfaceTool.cpp
3 : : //
4 : : // Purpose :
5 : : // Create a midsurface of a body/volume given a thickness range. If no thickness range is given
6 : : // then make a educated guess at the thickness (using something like Volume/Surface Area).
7 : : //
8 : : // Create Midsurface Volume <id_list> auto [<min_thickness> <max_thickness>]
9 : : //
10 : : // Creator : Sam Showman
11 : : //
12 : : // Creation Date : 05/10/2008
13 : : //-------------------------------------------------------------------------
14 : : #include "AutoMidsurfaceTool.hpp"
15 : : #include "GeometryModifyEngine.hpp"
16 : : #include "GeometryQueryTool.hpp"
17 : : #include "BodySM.hpp"
18 : : #include "Body.hpp"
19 : : #include "GeometryModifyTool.hpp"
20 : : #include "RefFace.hpp"
21 : : #include "Surface.hpp"
22 : : #include "Curve.hpp"
23 : : #include "RefEntity.hpp"
24 : : #include "SurfaceOverlapTool.hpp"
25 : : #include "CubitPlane.hpp"
26 : : #include "GfxPreview.hpp"
27 : : #include "GfxDebug.hpp"
28 : : #include "RefVertex.hpp"
29 : : #include "ProgressTool.hpp"
30 : : #include "AppUtil.hpp"
31 : : #include "BoundingBoxTool.hpp"
32 : : #include "GeomMeasureTool.hpp"
33 : :
34 : : // Constructor - nothing going on here
35 : 0 : AutoMidsurfaceTool::AutoMidsurfaceTool()
36 : : {
37 : 0 : }
38 : :
39 : : // The main midsurface function
40 : : // lower_tol, upper_tol and preview are optional
41 : 0 : CubitStatus AutoMidsurfaceTool::midsurface(
42 : : DLIList<Body*> &body_list_in,
43 : : DLIList<BodySM*> &body_list_out,
44 : : DLIList<Body*> &old_bodies_midsurfaced,
45 : : DLIList<double> &thickness_out,
46 : : double lower_limit,
47 : : double upper_limit,
48 : : CubitBoolean delete_midsurfaced,
49 : : CubitBoolean preview)
50 : : {
51 [ # # ]: 0 : if(lower_limit == CUBIT_DBL_MAX)// no limit set
52 : 0 : lower_limit = -CUBIT_DBL_MAX;
53 : 0 : double lower_tol = CUBIT_DBL_MAX;
54 : 0 : double upper_tol = CUBIT_DBL_MAX;
55 : 0 : const double auto_thickness_margin = 0.05; // if the user wants to automatically find the search
56 : : // thickness then this var give the search margin around the
57 : : // guess
58 : 0 : ProgressTool* prog_tool = 0;
59 [ # # ][ # # ]: 0 : if(body_list_in.size()>5)
60 [ # # ][ # # ]: 0 : prog_tool = AppUtil::instance()->progress_tool();
61 : :
62 : : // At lease one body must be provided
63 [ # # ][ # # ]: 0 : if(body_list_in.size() < 1)
64 : : {
65 [ # # ][ # # ]: 0 : PRINT_ERROR( "No bodies given for midsurfacing\n" );
[ # # ][ # # ]
66 : 0 : return CUBIT_FAILURE;
67 : : }
68 : :
69 : : // The surfaceOverlapTool is persistent so we need to save the
70 : : // max_gap and such to restore them at the end or if we error out
71 : : // save current settings
72 [ # # ][ # # ]: 0 : double max_gap_save = SurfaceOverlapTool::instance()->get_gap_max();
73 [ # # ][ # # ]: 0 : double min_gap_save = SurfaceOverlapTool::instance()->get_gap_min();
74 [ # # ][ # # ]: 0 : int normal_type = SurfaceOverlapTool::instance()->get_normal_type();
75 [ # # ][ # # ]: 0 : CubitBoolean cubit_bool_save = SurfaceOverlapTool::instance()->get_check_within_bodies();
76 [ # # ][ # # ]: 0 : CubitBoolean skip_facing_surfaces = SurfaceOverlapTool::instance()->get_skip_facing_surfaces();
77 : :
78 : : // we want to only find overlap within a body
79 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_check_within_bodies(CUBIT_TRUE);
80 : : // 1=any, 2=opposite, 3=same - we want to find only the overlaps that normals
81 : : // pointing in the opposite directions
82 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_normal_type(2);
83 : : // Don't pickup surfaces that face each other
84 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_skip_facing_surfaces(CUBIT_TRUE);
85 : :
86 : : // list of bodies that fail to midsurface
87 [ # # ]: 0 : DLIList<Body*> failing_bodies;
88 : :
89 : 0 : GeometryModifyEngine* gme = 0;
90 : 0 : GeometryQueryEngine* gqe = 0;
91 : :
92 : : // loop over every body and try to create midsurface(s)
93 : 0 : int i = 0;
94 : 0 : CubitStatus return_status = CUBIT_FAILURE;
95 : :
96 [ # # ]: 0 : if(prog_tool)
97 [ # # ][ # # ]: 0 : prog_tool->start(0,body_list_in.size());
98 : :
99 [ # # ][ # # ]: 0 : for(i = body_list_in.size();i--;)
100 : : {
101 [ # # ]: 0 : if(prog_tool)
102 [ # # ]: 0 : prog_tool->step();
103 : :
104 [ # # ]: 0 : Body* cur_body = body_list_in[i];
105 [ # # ]: 0 : if(!cur_body)
106 : 0 : continue;
107 : :
108 [ # # ]: 0 : BodySM* body_sm = cur_body->get_body_sm_ptr();
109 [ # # ]: 0 : if(!body_sm)
110 : 0 : continue;
111 : :
112 [ # # ][ # # ]: 0 : if(cur_body->is_sheet_body())
113 : : {
114 [ # # ][ # # ]: 0 : PRINT_INFO("Body %d is a sheet body.\n",cur_body->id());
[ # # ][ # # ]
[ # # ]
115 : 0 : continue;
116 : : }
117 : :
118 : : // Grab the geometrymodify and geometryquery engines to use later
119 [ # # ]: 0 : gqe = cur_body->get_geometry_query_engine();
120 [ # # ][ # # ]: 0 : gme = GeometryModifyTool::instance()->get_engine(body_sm);
121 : :
122 [ # # ][ # # ]: 0 : if(!gqe || !gme)
123 : 0 : continue;
124 : :
125 : : // Here are the steps to finding/creating the midsurface
126 : : // 1. If the user did not give a thickness range to search then
127 : : // make an educated guess at the proper thickness range. The assumption
128 : : // is that the midsurface is a square and the thickness is constant.
129 : : // The resulting equation is a third order polynomial that is solved using
130 : : // a few newton iterations. The initial thickness guess is Volume/Area
131 : : // 2. Using the given search distances use the SurfaceOverlapTool to find
132 : : // surface pairs.
133 : : // 3. If there is only one surface pair then use the existing midsurface commands
134 : : // 4. Find if the surface pairs represent two surface patches
135 : : // 5. If there are only two surface patches try to offset one of the patches
136 : : // 6. (this step is commented out for now) - If 5 fails or there are more than
137 : : // two surface patches then try the following:
138 : : // - Use the manual midsurface creation function to create midsurfaces for each
139 : : // pair of surfaces.
140 : : // - Unite all of the created midsurfaces together
141 : : // - remove any surfaces that have a curve touching a surface pair
142 : : // - Regularize the resulting body
143 : : // 7. Done
144 : :
145 : : {
146 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("AUTOMATICALLY calculating search range\n");
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
147 [ # # ]: 0 : DLIList<RefVolume*> vol_list;
148 [ # # ]: 0 : cur_body->ref_volumes(vol_list);
149 : 0 : double total_vol = 0;
150 : 0 : double total_vol_bb = 0;
151 [ # # ][ # # ]: 0 : for(int vol_cnt = 0; vol_cnt < vol_list.size(); vol_cnt++)
152 : : {
153 [ # # ]: 0 : CubitVector cg;
154 : : double temp_volume;
155 [ # # ][ # # ]: 0 : vol_list[vol_cnt]->mass_properties(cg,temp_volume);
156 [ # # ][ # # ]: 0 : CubitBox vol_bb = vol_list[vol_cnt]->bounding_box();
157 : 0 : total_vol += temp_volume;
158 [ # # ][ # # ]: 0 : total_vol_bb += vol_bb.x_range()*vol_bb.y_range()*vol_bb.z_range();
[ # # ]
159 [ # # ]: 0 : }
160 : :
161 [ # # ][ # # ]: 0 : if(total_vol<0 || total_vol > total_vol_bb)
162 : : {
163 [ # # ][ # # ]: 0 : PRINT_INFO("Could not midsurface Body %d - try healing the body.\n",cur_body->id());
[ # # ][ # # ]
[ # # ]
164 [ # # ]: 0 : failing_bodies.append(cur_body);
165 : 0 : continue;
166 : : }
167 : :
168 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("Volume of %f\n",total_vol);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
169 : :
170 [ # # ][ # # ]: 0 : DLIList<RefFace*> face_list;
[ # # ][ # # ]
171 [ # # ]: 0 : cur_body->ref_faces(face_list);
172 : 0 : double total_surf = 0;
173 [ # # ][ # # ]: 0 : for(int surf_cnt = 0; surf_cnt < face_list.size(); surf_cnt++)
174 [ # # ][ # # ]: 0 : total_surf += face_list[surf_cnt]->area();
175 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("Area of %f\n",total_surf);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
176 : :
177 : 0 : double t_g = total_vol/(total_surf/2.0);
178 : 0 : double initial_guess = t_g;
179 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("Initial guess of thickness %f\n",t_g);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
180 : : // use a newton solver to get a more accurate estimate the thickness of the volume
181 [ # # ]: 0 : for(int n_i = 0;n_i<100;n_i++)
182 : : {
183 : 0 : double tol_newton = GEOMETRY_RESABS;
184 : 0 : double t_gn = t_g + tol_newton;
185 : 0 : double f_prime = ((2.0*total_vol + sqrt(total_vol*t_g*t_g*t_g)*4.0 - total_surf*t_g)
186 : 0 : -(2.0*total_vol + sqrt(total_vol*t_gn*t_gn*t_gn)*4.0 - total_surf*t_gn))/
187 : 0 : (t_g-t_gn);
188 : :
189 : : // avoid divide by zero
190 [ # # ]: 0 : if(fabs(f_prime)<tol_newton)
191 : 0 : break;
192 : :
193 : 0 : double t_old = t_g;
194 : 0 : t_g = t_g - (2.0*total_vol + sqrt(total_vol*t_g*t_g*t_g)*4.0 - total_surf*t_g)/f_prime;
195 : :
196 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("Guess %d Thickness %f\n",n_i,t_g);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
197 [ # # ]: 0 : if(fabs(t_g-t_old)<tol_newton)
198 : : {
199 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("Converged with thickness of %f in %d steps\n",t_g,n_i);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
200 : 0 : break;
201 : : }
202 [ # # ]: 0 : if(t_g<0.0)
203 : : {
204 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("thickness less than zero setting back to initial guess\n");
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
205 : 0 : t_g = fabs(initial_guess);
206 : 0 : break;
207 : : }
208 : : }
209 : 0 : upper_tol = t_g + t_g*auto_thickness_margin;
210 : 0 : lower_tol = t_g - t_g*auto_thickness_margin;
211 [ # # ]: 0 : upper_tol = upper_tol <= upper_limit?upper_tol:upper_limit;
212 [ # # ]: 0 : lower_tol = lower_tol >= lower_limit?lower_tol:lower_limit;
213 : :
214 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("Guessing a thickness of %f to %f\n",lower_tol,upper_tol);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
215 : : }
216 : :
217 : : // set the lower and upper search distances
218 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_gap_max(upper_tol);
219 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_gap_min(lower_tol);
220 : :
221 [ # # ][ # # ]: 0 : DLIList<RefFace*> ref_face_list,list1,list2;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
222 [ # # ][ # # ]: 0 : DLIList<RefEntity*> faces_to_draw;
[ # # ]
223 [ # # ]: 0 : cur_body->ref_faces(ref_face_list);
224 : : // find the surface pairs
225 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->find_overlapping_surfaces(ref_face_list,list1,list2,faces_to_draw);
226 : :
227 : 0 : int tweak_iters = 4;
228 [ # # ]: 0 : for(int tweak = 0;tweak<tweak_iters;tweak++)
229 : : {
230 : : // if we didn't find anything then the part may be long and selender so grow the search thickness
231 [ # # ][ # # ]: 0 : if(list1.size()==0 && list2.size() == 0)
[ # # ][ # # ]
[ # # ]
232 : : {
233 [ # # ][ # # ]: 0 : if(tweak == tweak_iters-1 && lower_limit != -CUBIT_DBL_MAX && upper_limit != CUBIT_DBL_MAX)
[ # # ]
234 : : {
235 : : // on the last try use the user defined limits
236 : 0 : lower_tol = lower_limit;
237 : 0 : upper_tol = upper_limit;
238 : : }
239 : : else
240 : : {
241 : 0 : lower_tol = (upper_tol + lower_tol)/2.0;
242 : 0 : upper_tol += lower_tol*auto_thickness_margin*2;
243 [ # # ]: 0 : upper_tol = upper_tol <= upper_limit?upper_tol:upper_limit;
244 [ # # ]: 0 : lower_tol = lower_tol >= lower_limit?lower_tol:lower_limit;
245 : : }
246 : :
247 [ # # ][ # # ]: 0 : PRINT_DEBUG_198("Guessing again with thickness of %f to %f\n",lower_tol,upper_tol);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
248 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_gap_max(upper_tol);
249 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_gap_min(lower_tol);
250 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->find_overlapping_surfaces(ref_face_list,list1,list2,faces_to_draw);
251 : : }
252 : :
253 [ # # ]: 0 : DLIList<RefFace*> check_list;
254 [ # # ]: 0 : check_list += list1;
255 [ # # ]: 0 : check_list += list2;
256 : :
257 [ # # ][ # # ]: 0 : if(check_list.size() == 0 )
258 : 0 : continue;
259 : :
260 : : // make sure the pairs will match the solid within 10% or so
261 [ # # ][ # # ]: 0 : if(!check_surf_pairs(lower_tol,upper_tol,check_list,cur_body))
[ # # ][ # # ]
262 : : {
263 [ # # ]: 0 : list1.clean_out();
264 [ # # ]: 0 : list2.clean_out();
265 : 0 : continue;
266 : : }
267 [ # # ][ # # ]: 0 : break;
268 : 0 : }
269 : :
270 [ # # ][ # # ]: 0 : if(list1.size() != list2.size())
[ # # ]
271 : : {
272 [ # # ][ # # ]: 0 : PRINT_INFO("Could not find workable surface pairs for Body %d - try using the Sheet Offset command. \n",cur_body->id());
[ # # ][ # # ]
[ # # ]
273 [ # # ]: 0 : failing_bodies.append(cur_body);
274 : 0 : continue;
275 : : }
276 [ # # ][ # # ]: 0 : else if(list1.size() == 0 || list2.size() == 0)
[ # # ][ # # ]
[ # # ]
277 : : {
278 [ # # ][ # # ]: 0 : PRINT_INFO("No surface pairs found for Body %d - try changing the search range\n",cur_body->id());
[ # # ][ # # ]
[ # # ]
279 [ # # ]: 0 : failing_bodies.append(cur_body);
280 : 0 : continue;
281 : : }
282 : :
283 : : // get the first pair and see if there are only two patches
284 [ # # ][ # # ]: 0 : DLIList<RefFace*> red_faces;
[ # # ]
285 [ # # ][ # # ]: 0 : red_faces.append(list1[0]);
286 [ # # ][ # # ]: 0 : DLIList<RefFace*> yellow_faces;
[ # # ]
287 [ # # ][ # # ]: 0 : yellow_faces.append(list2[0]);
288 [ # # ][ # # ]: 0 : DLIList<RefFace*> paired_faces;
[ # # ]
289 [ # # ]: 0 : paired_faces += list1;
290 [ # # ]: 0 : paired_faces += list2;
291 [ # # ]: 0 : paired_faces.uniquify_unordered();
292 : :
293 : : // red surfaces
294 : : while(1)
295 : : {
296 [ # # ]: 0 : int start_cnt = red_faces.size();
297 [ # # ]: 0 : DLIList<RefEdge*> red_edges;
298 : 0 : int j = 0;
299 [ # # ][ # # ]: 0 : for(j =0;j<red_faces.size();j++)
300 [ # # ][ # # ]: 0 : red_faces[j]->ref_edges(red_edges);
301 [ # # ]: 0 : red_edges.uniquify_unordered();
302 [ # # ][ # # ]: 0 : for(j =0;j<red_edges.size();j++)
303 [ # # ][ # # ]: 0 : red_edges[j]->ref_faces(red_faces);
304 [ # # ]: 0 : red_faces.uniquify_unordered();
305 [ # # ]: 0 : red_faces.intersect_unordered(paired_faces);
306 [ # # ][ # # ]: 0 : if(start_cnt == red_faces.size())
307 [ # # ][ # # ]: 0 : break;
308 : 0 : }
309 : :
310 : : // yellow surfaces
311 : : while(1)
312 : : {
313 [ # # ]: 0 : int start_cnt = yellow_faces.size();
314 [ # # ]: 0 : DLIList<RefEdge*> yellow_edges;
315 : 0 : int j = 0;
316 [ # # ][ # # ]: 0 : for(j =0;j<yellow_faces.size();j++)
317 [ # # ][ # # ]: 0 : yellow_faces[j]->ref_edges(yellow_edges);
318 [ # # ]: 0 : yellow_edges.uniquify_unordered();
319 [ # # ][ # # ]: 0 : for(j =0;j<yellow_edges.size();j++)
320 [ # # ][ # # ]: 0 : yellow_edges[j]->ref_faces(yellow_faces);
321 [ # # ]: 0 : yellow_faces.uniquify_unordered();
322 [ # # ]: 0 : yellow_faces.intersect_unordered(paired_faces);
323 [ # # ][ # # ]: 0 : if(start_cnt == yellow_faces.size())
324 [ # # ][ # # ]: 0 : break;
325 : 0 : }
326 : :
327 [ # # ][ # # ]: 0 : DLIList<BodySM*> results;
[ # # ]
328 : 0 : bool midsurface_done = false;
329 : :
330 [ # # ][ # # ]: 0 : if(DEBUG_FLAG(198))
[ # # ]
331 : : {
332 : 0 : int j = 0;
333 [ # # ][ # # ]: 0 : PRINT_INFO("Trying surface offset to create the mid_surface\n");
[ # # ][ # # ]
334 [ # # ][ # # ]: 0 : PRINT_INFO("Red surface ");
[ # # ][ # # ]
335 [ # # ][ # # ]: 0 : for(j = 0;j < red_faces.size();j++)
336 : : {
337 [ # # ][ # # ]: 0 : GfxDebug::draw_ref_face(red_faces[j],CUBIT_RED_INDEX);
338 [ # # ][ # # ]: 0 : PRINT_INFO("%d ",red_faces[j]->id());
[ # # ][ # # ]
[ # # ][ # # ]
339 : : }
340 : :
341 [ # # ][ # # ]: 0 : PRINT_INFO("\nYellow surface ");
[ # # ][ # # ]
342 [ # # ][ # # ]: 0 : for(j = 0;j < yellow_faces.size();j++)
343 : : {
344 [ # # ][ # # ]: 0 : GfxDebug::draw_ref_face(yellow_faces[j],CUBIT_YELLOW_INDEX);
345 [ # # ][ # # ]: 0 : PRINT_INFO("%d ",yellow_faces[j]->id());
[ # # ][ # # ]
[ # # ][ # # ]
346 : : }
347 : :
348 [ # # ][ # # ]: 0 : PRINT_INFO("\n");
[ # # ][ # # ]
349 : : }
350 : :
351 : : // first check to see if we can use the simple midsurface functions
352 [ # # ][ # # ]: 0 : if(red_faces.size() == 1 && yellow_faces.size() == 1 &&
[ # # ][ # # ]
[ # # ][ # # ]
353 [ # # ][ # # ]: 0 : paired_faces.size() == red_faces.size() + yellow_faces.size())
[ # # ]
354 : : {
355 [ # # ]: 0 : RefFace* face_1 = red_faces[0];
356 [ # # ]: 0 : RefFace* face_2 = yellow_faces[0];
357 : 0 : midsurface_done = false;
358 : :
359 [ # # ][ # # ]: 0 : if(face_1->geometry_type() == face_2->geometry_type())
[ # # ]
360 : : {
361 [ # # ]: 0 : Surface* surf_1 = face_1->get_surface_ptr();
362 [ # # ]: 0 : Surface* surf_2 = face_2->get_surface_ptr();
363 : : BodySM* result_body;
364 : : // grab the distance between surfaces
365 [ # # ]: 0 : CubitVector temp_vec0;
366 [ # # ]: 0 : CubitVector temp_vec1;
367 : 0 : double temp_dist = 0;
368 : : gqe->entity_entity_distance(
369 [ # # ]: 0 : face_1->get_surface_ptr(),
370 [ # # ]: 0 : face_2->get_surface_ptr(),
371 [ # # ]: 0 : temp_vec0,temp_vec1,temp_dist);
372 : :
373 [ # # ][ # # : 0 : switch(face_1->geometry_type())
# # # # ]
374 : : {
375 : : case CONE_SURFACE_TYPE:
376 [ # # ][ # # ]: 0 : if(gme->get_conic_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
377 : : {
378 : 0 : midsurface_done = true;
379 [ # # ]: 0 : results.append(result_body);
380 [ # # ]: 0 : thickness_out.append(fabs(temp_dist));
381 : : }
382 : 0 : break;
383 : : case PLANE_SURFACE_TYPE:
384 [ # # ][ # # ]: 0 : if(get_planar_mid_surface(face_1,face_2,body_sm,result_body,gme) == CUBIT_SUCCESS)
385 : : {
386 : 0 : midsurface_done = true;
387 [ # # ]: 0 : results.append(result_body);
388 [ # # ]: 0 : thickness_out.append(fabs(temp_dist));
389 : : }
390 : 0 : break;
391 : : case SPHERE_SURFACE_TYPE:
392 [ # # ][ # # ]: 0 : if(gme->get_spheric_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
393 : : {
394 : 0 : midsurface_done = true;
395 [ # # ]: 0 : results.append(result_body);
396 [ # # ]: 0 : thickness_out.append(fabs(temp_dist));
397 : : }
398 : 0 : break;
399 : : case TORUS_SURFACE_TYPE:
400 [ # # ][ # # ]: 0 : if(gme->get_toric_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
401 : : {
402 : 0 : midsurface_done = true;
403 [ # # ]: 0 : results.append(result_body);
404 [ # # ]: 0 : thickness_out.append(fabs(temp_dist));
405 : : }
406 : 0 : break;
407 : : case CYLINDER_SURFACE_TYPE:
408 [ # # ][ # # ]: 0 : if(gme->get_conic_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
409 : : {
410 : 0 : midsurface_done = true;
411 [ # # ]: 0 : results.append(result_body);
412 [ # # ]: 0 : thickness_out.append(fabs(temp_dist));
413 : : }
414 : 0 : break;
415 : : default:
416 : 0 : break;
417 : : }
418 : : }
419 : : }
420 : :
421 [ # # ][ # # ]: 0 : if(!midsurface_done &&
[ # # ]
422 [ # # ][ # # ]: 0 : paired_faces.size() == red_faces.size() + yellow_faces.size()) // just do the offset
[ # # ]
423 : : {
424 : 0 : int j = 0;
425 [ # # ]: 0 : DLIList<double> offset_distances;
426 [ # # ][ # # ]: 0 : for(j = 0;j<list1.size();j++)
427 : : {
428 [ # # ]: 0 : CubitVector temp_vec0;
429 [ # # ]: 0 : CubitVector temp_vec1;
430 : 0 : double temp_dist = 0;
431 [ # # ]: 0 : if(!gqe->entity_entity_distance(
432 [ # # ][ # # ]: 0 : list1[j]->get_surface_ptr(),
433 [ # # ][ # # ]: 0 : list2[j]->get_surface_ptr(),
434 [ # # ]: 0 : temp_vec0,temp_vec1,temp_dist))
435 : : {
436 : 0 : break;
437 : : }
438 [ # # ]: 0 : offset_distances.append(-temp_dist*.5);
439 : : }
440 : :
441 [ # # ][ # # ]: 0 : DLIList<Surface*> red_surfs;
442 [ # # ][ # # ]: 0 : for(j = 0;j<red_faces.size();j++)
443 [ # # ][ # # ]: 0 : red_surfs.append(red_faces[j]->get_surface_ptr());
[ # # ]
444 : :
445 [ # # ][ # # ]: 0 : DLIList<Surface*> yellow_surfs;
446 [ # # ][ # # ]: 0 : for(j = 0;j<yellow_faces.size();j++)
447 [ # # ][ # # ]: 0 : yellow_surfs.append(yellow_faces[j]->get_surface_ptr());
[ # # ]
448 : :
449 : : // all of the surfaces are offset the same distance
450 [ # # ]: 0 : double offset_distance = offset_distances[0];
451 [ # # ][ # # ]: 0 : bool old_error_flag = GET_ERROR_FLAG();
452 [ # # ][ # # ]: 0 : SET_ERROR_FLAG(false); // don't throw any gme errors
453 [ # # ]: 0 : if( gme->create_offset_sheet(red_surfs,offset_distance,
454 [ # # ]: 0 : NULL,NULL,results))
455 : : {
456 : 0 : midsurface_done = true;
457 [ # # ][ # # ]: 0 : for(j = 0;j<results.size();j++) // for every body add a thickness
458 [ # # ]: 0 : thickness_out.append(fabs(offset_distance*2.));
459 : : }
460 [ # # ]: 0 : else if( gme->create_offset_sheet(yellow_surfs,offset_distance,
461 [ # # ]: 0 : NULL,NULL,results)) // try the other direction
462 : : {
463 : 0 : midsurface_done = true;
464 [ # # ][ # # ]: 0 : for(j = 0;j<results.size();j++) // for every body add a thickness
465 [ # # ]: 0 : thickness_out.append(fabs(offset_distance*2.));
466 : : }
467 : : else
468 : : {
469 [ # # ][ # # ]: 0 : PRINT_INFO("Could not create midsurface for Body %d - try using the surface offset command\n",cur_body->id());
[ # # ][ # # ]
[ # # ]
470 [ # # ]: 0 : failing_bodies.append(cur_body);
471 : : }
472 [ # # ][ # # ]: 0 : SET_ERROR_FLAG(old_error_flag); // turn errors back on
[ # # ]
473 : : }
474 : :
475 [ # # ][ # # ]: 0 : if(!midsurface_done && paired_faces.size() != red_faces.size() + yellow_faces.size())
[ # # ][ # # ]
[ # # ][ # # ]
476 : : {
477 [ # # ][ # # ]: 0 : PRINT_INFO("Could not find workable surface pairs for Body %d - try changing the search range or \n"
[ # # ][ # # ]
478 [ # # ]: 0 : " using the Sheet Offset command.\n",cur_body->id());
479 : : }
480 : :
481 : : /*if(!midsurface_done)
482 : : {
483 : : if(DEBUG_FLAG(198))
484 : : PRINT_INFO("Trying the extend, unite, and trim method\n");
485 : :
486 : : // okay now remove duplicate pairs and unsupported pairs
487 : : DLIList<Surface*> surf_list1;
488 : : DLIList<Surface*> surf_list2;
489 : : bool delete_and_exit = false;
490 : : for(int j = 0;j<list1.size();j++)
491 : : {
492 : : RefFace* face_1 = list1[j];
493 : : RefFace* face_2 = list2[j];
494 : :
495 : : if(DEBUG_FLAG(198))
496 : : {
497 : : PRINT_INFO("Red surface ");
498 : : GfxDebug::draw_ref_face(face_1,CUBIT_RED_INDEX);
499 : : PRINT_INFO("%d ",face_1->id());
500 : :
501 : : PRINT_INFO("\nYellow surface ");
502 : : GfxDebug::draw_ref_face(face_2,CUBIT_YELLOW_INDEX);
503 : : PRINT_INFO("%d ",face_2->id());
504 : :
505 : : PRINT_INFO("\n");
506 : : }
507 : :
508 : : if(face_1->geometry_type() != face_2->geometry_type())
509 : : continue;
510 : :
511 : : Surface* surf_1 = face_1->get_surface_ptr();
512 : : surf_list1.append(surf_1);
513 : : Surface* surf_2 = face_2->get_surface_ptr();
514 : : surf_list2.append(surf_2);
515 : : BodySM* result_body;
516 : : switch(face_1->geometry_type())
517 : : {
518 : : case CONE_SURFACE_TYPE:
519 : : if(gme->get_conic_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
520 : : results.append(result_body);
521 : : else
522 : : delete_and_exit = true;
523 : : break;
524 : : case PLANE_SURFACE_TYPE:
525 : : if(get_planar_mid_surface(face_1,face_2,body_sm,result_body,gme) == CUBIT_SUCCESS)
526 : : results.append(result_body);
527 : : else
528 : : delete_and_exit = true;
529 : : break;
530 : : case SPHERE_SURFACE_TYPE:
531 : : if(gme->get_spheric_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
532 : : results.append(result_body);
533 : : else
534 : : delete_and_exit = true;
535 : : break;
536 : : case TORUS_SURFACE_TYPE:
537 : : if(gme->get_toric_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
538 : : results.append(result_body);
539 : : else
540 : : delete_and_exit = true;
541 : : break;
542 : : case CYLINDER_SURFACE_TYPE:
543 : : if(gme->get_conic_mid_surface(surf_1,surf_2,body_sm,result_body) == CUBIT_SUCCESS)
544 : : results.append(result_body);
545 : : else
546 : : delete_and_exit = true;
547 : : break;
548 : : default:
549 : : delete_and_exit = true;
550 : : break;
551 : : }
552 : :
553 : : if(delete_and_exit)
554 : : {
555 : : PRINT_WARNING("Failed to pair surface %d with surface %d\n",face_1->id(),face_2->id());
556 : : break;
557 : : }
558 : : }
559 : :
560 : : if(delete_and_exit)
561 : : {
562 : : failing_bodies.append(cur_body);
563 : : gqe->delete_solid_model_entities(results);
564 : : continue;
565 : : }
566 : :
567 : : DLIList<BodySM*> unite_results;
568 : : if(results.size()>1)
569 : : {
570 : : bool reg_result = GeometryModifyTool::instance()->boolean_regularize();
571 : : GeometryModifyTool::instance()->boolean_regularize(true);
572 : : if(gme->unite(results,unite_results)== CUBIT_SUCCESS)
573 : : {
574 : : // if the unite works just add them to the result list
575 : : results = unite_results;
576 : : }
577 : : else
578 : : {
579 : : // clean up the created surfaces and move on to the next
580 : : // body
581 : : failing_bodies.append(cur_body);
582 : : gqe->delete_solid_model_entities(results);
583 : : GeometryModifyTool::instance()->boolean_regularize(reg_result);
584 : : continue;
585 : : }
586 : :
587 : : GeometryModifyTool::instance()->boolean_regularize(reg_result);
588 : : }
589 : :
590 : : // trim the hanging surfaces
591 : : DLIList<Surface*> paired_surfs;
592 : : paired_surfs += surf_list1;
593 : : paired_surfs += surf_list2;
594 : :
595 : : DLIList<Curve*> all_curves;
596 : :
597 : : int k = 0;
598 : : for(k = 0;k<results.size();k++)
599 : : results[k]->curves(all_curves);
600 : :
601 : : all_curves.uniquify_unordered();
602 : :
603 : : DLIList<Surface*> remove_surfs;
604 : : for(k = 0;k<all_curves.size();k++)
605 : : for(int m = 0;m<paired_surfs.size();m++)
606 : : if(curve_in_surface(all_curves[k],paired_surfs[m]))
607 : : all_curves[k]->surfaces(remove_surfs);
608 : :
609 : : remove_surfs.uniquify_unordered();
610 : :
611 : : body_list_out += results;
612 : : DLIList<BodySM*> tweak_results;
613 : : if(gme->tweak_remove(remove_surfs,tweak_results,CUBIT_FALSE))
614 : : {
615 : : results = tweak_results;
616 : : }
617 : : else
618 : : {
619 : : // clean up the created surfaces and move on to the next
620 : : // body
621 : : failing_bodies.append(cur_body);
622 : : gqe->delete_solid_model_entities(results);
623 : : continue;
624 : : }
625 : :
626 : : DLIList<BodySM*> regularize_results;
627 : : // regularize the results
628 : : for(k = 0;k < results.size();k++)
629 : : {
630 : : BodySM* new_body = 0;
631 : : if(gme->regularize_body(results[k],new_body))
632 : : regularize_results.append(new_body);
633 : : else if(DEBUG_FLAG(198))
634 : : PRINT_INFO("Regularize failure\n");
635 : : }
636 : : results = regularize_results;
637 : : }*/
638 : :
639 [ # # ]: 0 : if(!midsurface_done)
640 : : {
641 [ # # ]: 0 : failing_bodies.append(cur_body);
642 : 0 : continue;
643 : : }
644 : :
645 [ # # ]: 0 : old_bodies_midsurfaced.append(cur_body);
646 : :
647 [ # # ][ # # ]: 0 : if(delete_midsurfaced && !preview)
648 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->delete_Body(cur_body);
649 : :
650 : 0 : return_status = CUBIT_SUCCESS;
651 [ # # ][ # # ]: 0 : body_list_out += results;
[ # # ]
652 : 0 : }
653 : :
654 [ # # ]: 0 : if(prog_tool)
655 [ # # ]: 0 : prog_tool->end();
656 : :
657 [ # # ][ # # ]: 0 : PRINT_INFO("Successfully midsurface %d of %d bodies\n",body_list_out.size(),body_list_in.size());
[ # # ][ # # ]
[ # # ][ # # ]
658 [ # # ]: 0 : if(preview)
659 : : {
660 [ # # ][ # # ]: 0 : for(int k = 0;k<body_list_out.size();k++)
661 : : {
662 [ # # ]: 0 : DLIList<Surface*> preview_surfaces;
663 [ # # ][ # # ]: 0 : body_list_out[k]->surfaces(preview_surfaces);
664 [ # # ][ # # ]: 0 : for(int p = 0;p<preview_surfaces.size();p++)
665 [ # # ][ # # ]: 0 : GfxPreview::draw_surface_facets_shaded(preview_surfaces[p],CUBIT_BLUE_INDEX);
666 [ # # ]: 0 : }
667 [ # # ]: 0 : GfxPreview::flush();
668 [ # # ]: 0 : if(gqe)
669 [ # # ]: 0 : gqe->delete_solid_model_entities(body_list_out);
670 [ # # ]: 0 : body_list_out.clean_out();
671 : : }
672 : :
673 [ # # ][ # # ]: 0 : if(failing_bodies.size() > 0)
674 : : {
675 [ # # ][ # # ]: 0 : PRINT_INFO("\n");
[ # # ][ # # ]
676 [ # # ][ # # ]: 0 : PRINT_INFO("Failed to midsurface Body ");
[ # # ][ # # ]
677 [ # # ][ # # ]: 0 : for(i = 0;i<failing_bodies.size();i++)
678 [ # # ][ # # ]: 0 : PRINT_INFO("%d ",failing_bodies[i]->id());
[ # # ][ # # ]
[ # # ][ # # ]
679 [ # # ][ # # ]: 0 : PRINT_INFO("\n");
[ # # ][ # # ]
680 : : }
681 : :
682 [ # # ][ # # ]: 0 : if(DEBUG_FLAG(198))
[ # # ]
683 [ # # ]: 0 : GfxDebug::flush();
684 : :
685 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_check_within_bodies(cubit_bool_save);
686 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_gap_max(max_gap_save);
687 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_normal_type(normal_type);
688 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_gap_min(min_gap_save);
689 [ # # ][ # # ]: 0 : SurfaceOverlapTool::instance()->set_skip_facing_surfaces(skip_facing_surfaces);
690 : :
691 [ # # ]: 0 : return return_status;
692 : : }
693 : :
694 : :
695 : 0 : CubitStatus AutoMidsurfaceTool::get_planar_mid_surface( RefFace* ref_face1,
696 : : RefFace* ref_face2,
697 : : BodySM* body_sm_to_trim_to,
698 : : BodySM*& midsurface_body_sm,
699 : : GeometryModifyEngine *gme_ptr )
700 : : {
701 [ # # ][ # # ]: 0 : CubitVector normal_1, normal_2, point_1, point_2, point_3;
[ # # ][ # # ]
[ # # ]
702 [ # # ][ # # ]: 0 : CubitPlane plane_1, plane_2;
703 [ # # ][ # # ]: 0 : CubitVector p_mid, n_mid;
704 : :
705 [ # # ][ # # ]: 0 : point_1 = ref_face1->center_point();
706 [ # # ][ # # ]: 0 : point_2 = ref_face2->center_point();
707 : :
708 [ # # ][ # # ]: 0 : normal_1 = ref_face1->normal_at(point_1);
709 [ # # ][ # # ]: 0 : normal_2 = ref_face2->normal_at(point_2);
710 : :
711 [ # # ][ # # ]: 0 : plane_1 = CubitPlane(normal_1,point_1);
712 [ # # ][ # # ]: 0 : plane_2 = CubitPlane(normal_2,point_2);
713 : :
714 [ # # ][ # # ]: 0 : if(point_1 == point_2)
715 : : {
716 [ # # ][ # # ]: 0 : PRINT_ERROR( "In GeometryModifyTool:: get_planar_mid_surface\n"
[ # # ]
717 [ # # ]: 0 : " Since both surfaces share the same point, the midsurface is not well-defined\n");
718 : 0 : return CUBIT_FAILURE;
719 : : }
720 : : else
721 : : {
722 [ # # ]: 0 : CubitVector temp1 = point_2;
723 [ # # ][ # # ]: 0 : temp1 = plane_1.project(temp1);
724 [ # # ]: 0 : temp1 -= point_2;
725 [ # # ][ # # ]: 0 : if ( temp1.length_squared() < GEOMETRY_RESABS*GEOMETRY_RESABS )
726 : : {
727 [ # # ][ # # ]: 0 : PRINT_ERROR("In GeometryModifyTool:: get_planar_mid_surface\n"
[ # # ]
728 [ # # ]: 0 : " Since both planes are the same, the midsurface is not well-defined.\n");
729 : 0 : return CUBIT_FAILURE;
730 : : }
731 : : }
732 : :
733 [ # # ][ # # ]: 0 : if ( ( normal_1.about_equal( normal_2 ) ) || ( (-normal_1).about_equal( normal_2 ) ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
734 : : {
735 [ # # ][ # # ]: 0 : p_mid = (point_1+point_2)/2;
[ # # ]
736 [ # # ][ # # ]: 0 : n_mid = plane_1.normal();
737 : : }
738 : : else
739 : : {
740 [ # # ]: 0 : CubitVector direction_of_line;
741 [ # # ]: 0 : plane_1.intersect(plane_2,p_mid,direction_of_line);
742 [ # # ]: 0 : direction_of_line.normalize();
743 : :
744 : : // Find if point_1 and point_2 are on the line of intersection
745 : : // If they are, then the mid-plane is not well-defined
746 [ # # ]: 0 : CubitVector p1 = point_1-p_mid;
747 [ # # ]: 0 : CubitVector p2 = point_2-p_mid;
748 [ # # ]: 0 : p1.normalize();
749 [ # # ]: 0 : p2.normalize();
750 : :
751 [ # # ][ # # ]: 0 : if(p1==direction_of_line || p1==-direction_of_line)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
752 : : {
753 [ # # ][ # # ]: 0 : PRINT_ERROR("In GeometryModifyTool:: get_planar_mid_surface\n"
[ # # ]
754 [ # # ]: 0 : " P1 is on the line of intersection.\n");
755 : 0 : return CUBIT_FAILURE;
756 : : }
757 : :
758 [ # # ][ # # ]: 0 : if(p2==direction_of_line || p2==-direction_of_line)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
759 : : {
760 [ # # ][ # # ]: 0 : PRINT_ERROR("In GeometryModifyTool:: get_planar_mid_surface\n"
[ # # ]
761 [ # # ]: 0 : " P2 is on the line of intersection.\n");
762 : 0 : return CUBIT_FAILURE;
763 : : }
764 : :
765 [ # # ][ # # ]: 0 : CubitVector v1 = p1 - (p1%direction_of_line)*direction_of_line;
[ # # ]
766 [ # # ]: 0 : v1.normalize();
767 : :
768 [ # # ][ # # ]: 0 : CubitVector v2 = p2 - (p2%direction_of_line)*direction_of_line;
[ # # ]
769 [ # # ]: 0 : v2.normalize();
770 : :
771 [ # # ][ # # ]: 0 : n_mid = v1 - v2;
772 [ # # ]: 0 : n_mid.normalize();
773 : : }
774 : :
775 [ # # ]: 0 : CubitPlane mid_plane(n_mid, p_mid);
776 [ # # ]: 0 : point_1 = p_mid;
777 : :
778 : : //find three points that will define the infinite plane from the
779 : : //mid plane.through the point in any direction just not along the
780 : : //normal direction
781 [ # # ][ # # ]: 0 : CubitVector Xdir(1,0,0), Ydir(0,1,0);
782 [ # # ]: 0 : CubitVector direction1;
783 : :
784 [ # # ][ # # ]: 0 : if ( ( ! n_mid.about_equal( Xdir ) ) && ( ! (-n_mid).about_equal( Xdir ) ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
785 [ # # ][ # # ]: 0 : direction1 = Xdir + n_mid;
786 : : else
787 [ # # ][ # # ]: 0 : direction1 = Ydir + n_mid;
788 : :
789 [ # # ][ # # ]: 0 : point_2 = p_mid + direction1;
790 [ # # ][ # # ]: 0 : point_2 = mid_plane.project(point_2);
791 : :
792 [ # # ][ # # ]: 0 : direction1 = point_2-point_1;
793 [ # # ]: 0 : CubitVector direction2 = direction1*n_mid;
794 [ # # ][ # # ]: 0 : point_3 = point_1 + direction2;
795 : :
796 : : CubitStatus ret = gme_ptr->get_mid_plane(point_1, point_2, point_3,
797 [ # # ]: 0 : body_sm_to_trim_to, midsurface_body_sm );
798 : 0 : return ret;
799 : : }
800 : :
801 : 0 : CubitBoolean AutoMidsurfaceTool::curve_in_surface(Curve *curve_in, Surface *surf_in)
802 : : {
803 [ # # ]: 0 : CubitVector loc_0;
804 [ # # ]: 0 : CubitVector loc_1;
805 [ # # ]: 0 : CubitVector loc_2;
806 : :
807 [ # # ]: 0 : curve_in->position_from_fraction(0.1,loc_0);
808 [ # # ]: 0 : curve_in->position_from_fraction(0.5,loc_1);
809 [ # # ]: 0 : curve_in->position_from_fraction(0.9,loc_2);
810 : :
811 [ # # ]: 0 : GeometryQueryEngine* gqe = surf_in->get_geometry_query_engine();
812 [ # # ]: 0 : double tol = gqe->get_sme_resabs_tolerance();
813 [ # # ]: 0 : CubitVector cl_pnt_0;
814 [ # # ]: 0 : CubitVector cl_pnt_1;
815 [ # # ]: 0 : CubitVector cl_pnt_2;
816 [ # # ]: 0 : surf_in->closest_point(loc_0,&cl_pnt_0);
817 [ # # ]: 0 : surf_in->closest_point(loc_1,&cl_pnt_1);
818 [ # # ]: 0 : surf_in->closest_point(loc_2,&cl_pnt_2);
819 : :
820 [ # # ][ # # ]: 0 : if(cl_pnt_0.distance_between(loc_0)<tol &&
[ # # ]
821 [ # # ][ # # ]: 0 : cl_pnt_1.distance_between(loc_1)<tol &&
[ # # ]
822 [ # # ]: 0 : cl_pnt_2.distance_between(loc_2)<tol)
823 : : {
824 : 0 : return CUBIT_TRUE;
825 : : }
826 : :
827 : 0 : return CUBIT_FALSE;
828 : : }
829 : :
830 : 0 : CubitStatus AutoMidsurfaceTool::find_offset_pair_patches(
831 : : DLIList<RefFace*> pairs_list_0,
832 : : DLIList<RefFace*> pairs_list_1,
833 : : DLIList<RefFace*>& red_faces,
834 : : DLIList<RefFace*>& yellow_faces,
835 : : DLIList<double>& offset_distances)
836 : : {
837 : 0 : return CUBIT_FAILURE;
838 : : }
839 : :
840 : 0 : CubitStatus AutoMidsurfaceTool::random_loc_on_surface( Surface* face_ptr, CubitVector &loc )
841 : : {
842 [ # # ]: 0 : GMem g_mem;
843 [ # # ]: 0 : GeometryQueryEngine* gqe = face_ptr->get_geometry_query_engine();
844 : 0 : unsigned short norm_tol = 10;
845 : 0 : double dist_tol = -1.0;
846 [ # # ]: 0 : gqe->get_graphics( face_ptr, &g_mem, norm_tol, dist_tol );
847 : :
848 [ # # ]: 0 : if(g_mem.fListCount < 1)
849 : : {
850 : : // Decrease tolerance and try again (we can get this for small features)
851 : 0 : norm_tol /= 2;
852 [ # # ]: 0 : gqe->get_graphics( face_ptr, &g_mem, norm_tol, dist_tol);
853 : : }
854 : :
855 [ # # ]: 0 : if(g_mem.fListCount < 1)
856 : : {
857 : : // Lets give up
858 [ # # ][ # # ]: 0 : PRINT_ERROR( "Unable to find location on a surface\n" );
[ # # ][ # # ]
859 : 0 : return CUBIT_FAILURE;
860 : : }
861 : :
862 : : // Use the first triangle
863 : : GPoint p[3];
864 [ # # ]: 0 : GPoint* plist = g_mem.point_list();
865 [ # # ]: 0 : int* facet_list = g_mem.facet_list();
866 : 0 : int c = 0;
867 : :
868 : 0 : p[0] = plist[facet_list[++c]];
869 : 0 : p[2] = plist[facet_list[++c]];
870 : 0 : p[1] = plist[facet_list[++c]];
871 : :
872 : : // Get centroid
873 [ # # ]: 0 : CubitVector p1( p[0].x, p[0].y, p[0].z );
874 [ # # ]: 0 : CubitVector p2( p[2].x, p[2].y, p[2].z );
875 [ # # ]: 0 : CubitVector p3( p[1].x, p[1].y, p[1].z );
876 : :
877 [ # # ][ # # ]: 0 : CubitVector center = (p1 + p2 + p3)/3.0;
[ # # ]
878 : :
879 [ # # ][ # # ]: 0 : face_ptr->closest_point_trimmed(center,loc);
880 : :
881 [ # # ]: 0 : return CUBIT_SUCCESS;
882 : : }
883 : :
884 : 0 : CubitBoolean AutoMidsurfaceTool::check_surf_pairs(double min_thick, double max_thick,
885 : : DLIList<RefFace*> check_list, Body* body_in )
886 : : {
887 : 0 : double total_area = 0.0;
888 [ # # ]: 0 : DLIList<RefVolume*> vol_list;
889 [ # # ]: 0 : body_in->ref_volumes(vol_list);
890 : 0 : double total_vol = 0;
891 [ # # ][ # # ]: 0 : for(int vol_cnt = 0; vol_cnt < vol_list.size(); vol_cnt++)
892 : : {
893 [ # # ]: 0 : CubitVector cg;
894 : : double temp_volume;
895 [ # # ][ # # ]: 0 : vol_list[vol_cnt]->mass_properties(cg,temp_volume);
896 : 0 : total_vol += temp_volume;
897 : : }
898 : :
899 [ # # ][ # # ]: 0 : for(int i = 0;i<check_list.size();i++)
900 [ # # ][ # # ]: 0 : total_area += check_list[i]->area();
901 : :
902 : 0 : total_area/=2.0;
903 : :
904 [ # # ][ # # ]: 0 : if(min_thick*total_area < total_vol && max_thick*total_area > total_vol)
905 : 0 : return CUBIT_TRUE;
906 : :
907 [ # # ]: 0 : return CUBIT_FALSE;
908 [ + - ][ + - ]: 6540 : }
|