Branch data Line data Source code
1 : : #include "SmartLaplacianSmoother.hpp"
2 : : #include "PatchData.hpp"
3 : : #include "MsqVertex.hpp"
4 : : #include "MsqMeshEntity.hpp"
5 : :
6 : : namespace MBMesquite
7 : : {
8 : :
9 : 1458 : size_t SmartLaplacianSmoother::num_inverted( PatchData& pd, MsqError& err )
10 : : {
11 : 1458 : size_t result = 0;
12 : : int inverted, junk;
13 [ + - ][ + + ]: 13122 : for( size_t i = 0; i < pd.num_elements(); ++i )
14 : : {
15 [ + - ][ + - ]: 11664 : pd.element_by_index( i ).check_element_orientation( pd, inverted, junk, err );
16 [ + - ][ - + ]: 11664 : MSQ_ERRZERO( err );
[ # # ][ # # ]
[ - + ]
17 [ - + ]: 11664 : if( inverted ) ++result;
18 : : }
19 : 1458 : return result;
20 : : }
21 : :
22 : 0 : std::string SmartLaplacianSmoother::get_name() const
23 : : {
24 [ # # ]: 0 : return "SmartLaplacianSmoother";
25 : : }
26 : :
27 [ # # ]: 0 : SmartLaplacianSmoother::~SmartLaplacianSmoother() {}
28 : :
29 : 729 : void SmartLaplacianSmoother::optimize_vertex_positions( PatchData& pd, MsqError& err )
30 : : {
31 [ + - ][ - + ]: 729 : assert( pd.num_free_vertices() == 1 );
32 : 729 : const size_t center_vtx_index = 0;
33 [ + - ][ + - ]: 1458 : const size_t init_inverted = num_inverted( pd, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
34 : :
35 : 729 : adjVtxList.clear();
36 [ + - ][ + - ]: 729 : pd.get_adjacent_vertex_indices( center_vtx_index, adjVtxList, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
37 : :
38 [ - + ]: 729 : if( adjVtxList.empty() ) return;
39 : :
40 [ + - ]: 729 : const MsqVertex* verts = pd.get_vertex_array( err );
41 : 729 : const size_t n = adjVtxList.size();
42 : :
43 [ + - ]: 729 : const Vector3D orig_pos = verts[center_vtx_index];
44 [ + - ][ + - ]: 729 : Vector3D new_pos = verts[adjVtxList[0]];
45 [ + + ]: 4374 : for( size_t i = 1; i < n; ++i )
46 [ + - ][ + - ]: 3645 : new_pos += verts[adjVtxList[i]];
47 [ + - ]: 729 : new_pos *= 1.0 / n;
48 [ + - ]: 729 : pd.set_vertex_coordinates( new_pos, center_vtx_index, err );
49 [ + - ][ + - ]: 729 : pd.snap_vertex_to_domain( center_vtx_index, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
50 [ + - ][ + - ]: 729 : const size_t new_inverted = num_inverted( pd, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
51 [ - + ][ # # ]: 729 : if( new_inverted > init_inverted ) pd.set_vertex_coordinates( orig_pos, center_vtx_index, err );
52 : : }
53 : :
54 [ + - ][ + - ]: 4 : } // namespace MBMesquite
|