Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AngleBasedSmoothing.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: AngleBasedSmoothing.C,v 1.4 2008/12/06 08:45:27 mtcampbe Exp $
24 
25 #include "FaceOffset_3.h"
26 #include "../Rocblas/include/Rocblas.h"
27 #include "../Rocsurf/include/Generic_element_2.h"
28 #include "../Rocsurf/include/Rocsurf.h"
29 
31 
32 void FaceOffset_3::
33 compute_angle_based_vertex_centers() {
34  COM_assertion_msg( COMMPI_Comm_size( _buf->get_communicator())==1,
35  "Angle-based smoothing supports only serial runs now");
36 
37  double zero = 0., eps = 1.e-100;
40 
41  // Loop through the panes and its real faces
42  std::vector< COM::Pane*>::iterator it = _panes.begin();
43  Manifold::PM_iterator pm_it=_surf->pm_begin();
44  for ( int i=0, local_npanes = _panes.size();
45  i<local_npanes; ++i, ++it, ++pm_it) {
46  COM::Pane *pane = *it;
47 
48  const Point_3 *pnts = reinterpret_cast<Point_3*>
49  (pane->attribute(COM_NC)->pointer());
50  const char *tranks = reinterpret_cast<const char*>
51  ( pane->attribute(_tangranks->id())->pointer());
52  const Vector_3 *es = reinterpret_cast<const Vector_3*>
53  ( pane->attribute(_eigvecs->id())->pointer());
54  const Vector_3 *vnrm = reinterpret_cast<const Vector_3*>
55  ( pane->attribute(_vnormals->id())->pointer());
56 
57  Vector_3 *vcnts = reinterpret_cast<Vector_3*>
58  ( pane->attribute(_vcenters->id())->pointer());
59  double *ws = reinterpret_cast<double*>
60  ( pane->attribute(_weights->id())->pointer());
61 
62  // Loop through real elements of the current pane
63  Element_node_enumerator ene( pane, 1);
64  for ( int j=0, nj=pane->size_of_real_elements(); j<nj; ++j, ene.next()) {
65  int ne = ene.size_of_edges();
66 
67  // Loop through all Halfedge of current face.
68  for ( int k=0; k<ne; ++k) {
69  Halfedge h( &*pm_it, Edge_ID( j+1,k), SURF::REAL_PANE);
70  int vindex=ene[k]-1; // Destination of the halfedge
71 
72  Vector_3 dirs[2] = { es[3*vindex+1], es[3*vindex+2] };
73  // Skip corners.
74  switch ( tranks[vindex]) {
75  case 0:
76  continue;
77  case 1:
78  // Special handling for ridges.
79  dirs[0] = Vector_3::cross_product(dirs[1], vnrm[vindex]);
80  default: {
81  Point_3 pv = h.origin().point();
82  Vector_3 ds[3] = { h.opposite().prev().origin().point()-pv,
83  h.destination().point() - pv,
84  h.next().destination().point() - pv};
85 
86  Vector_2 p0 = proj( ds[0], dirs[0], dirs[1]);
87  Vector_2 p1 = proj( ds[1], dirs[0], dirs[1]);
88  Vector_2 p2 = proj( ds[2], dirs[0], dirs[1]);
89 
90  Vector_2 d1 = (-p1).normalize();
91  Vector_2 d2 = (p2-p1).normalize();
92  Vector_2 d0 = (p0-p1).normalize();
93 
94  double alpha1 = std::acos( d1*d2);
95  double alpha2 = std::acos( d0*d1);
96  double w = 1/(alpha1+alpha2)/(alpha1+alpha2);
97 
98  ws[vindex] += w;
99 
100  double beta = 0.5*(alpha2-alpha1);
101  double cosb=std::cos(beta), sinb=std::sin(beta);
102  Vector_2 pnt( p1[0]-p1[0]*cosb+p1[1]*sinb,
103  p1[1]-p1[0]*sinb-p1[1]*cosb);
104 
105  vcnts[vindex] += w*(pnt[0]*dirs[0]+pnt[1]*dirs[1]);
106  }
107  }
108  }
109  }
110  }
111 
112  _surf->reduce_on_shared_nodes( _vcenters, Manifold::OP_SUM);
113  _surf->reduce_on_shared_nodes( _weights, Manifold::OP_SUM);
115 }
116 
118 
119 
120 
121 
122 
123 
COM::Window * _buf
An adaptor for enumerating node IDs of an element.
#define PROP_END_NAMESPACE
Definition: propbasic.h:29
j indices k indices k
Definition: Indexing.h:6
#define PROP_BEGIN_NAMESPACE
Definition: propbasic.h:28
#define COM_assertion_msg(EX, msg)
MAP::Facet_ID Edge_ID
Definition: Manifold_2.h:49
COM::Attribute * _vcenters
Definition: FaceOffset_3.h:415
NT p1
This class encapsulate a halfedge over a window manifold.
Definition: Manifold_2.h:446
COM::Attribute * _tangranks
Definition: FaceOffset_3.h:417
int COMMPI_Comm_size(MPI_Comm c)
Definition: commpi.h:165
std::vector< COM::Pane * > _panes
Point object that represents a single point.
Definition: datatypedef.h:68
COM::Attribute * _eigvecs
Definition: FaceOffset_3.h:407
NT p0
NT & sin
blockLoc i
Definition: read.cpp:79
Manifold * _surf
COM::Attribute * _weights
Definition: FaceOffset_3.h:425
static void div(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for division.
Definition: op3args.C:269
static Vector_3 cross_product(const Vector_3 &v, const Vector_3 &w)
Definition: mapbasic.h:104
static void copy_scalar(const void *x, Attribute *y)
Operation wrapper for copy (x is a scalar pointer).
Definition: op2args.C:583
j indices j
Definition: Indexing.h:6
COM::Attribute * _vnormals
Definition: FaceOffset_3.h:410
CImg< _cimg_Tfloat > acos(const CImg< T > &instance)
Definition: CImg.h:6051
void int * nj
Definition: read.cpp:74
Some basic geometric data types.
Definition: mapbasic.h:54
static Vector_2 proj(const Vector_3 &v, const Vector_3 &d1, const Vector_3 &d2)
Definition: FaceOffset_3.h:318
NT & cos