-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsmall_mask.cpp
114 lines (111 loc) · 2.46 KB
/
small_mask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//****************************************************************************80
bool triangle_mask ( int dim_num, int triangle_order, int nodes[],
double coord[] )
//****************************************************************************80
//
// Purpose:
//
// TRIANGLE_MASK is a user routine which masks triangles.
//
// Discussion:
//
// The region to be considered is the [0,4]x[0,4] square.
//
// We want to remove the lower left triangular corner,
// and part of the upper right triangular corner.
//
// The following diagram of the 25 nodes indicates by "O" the
// nodes that should end up being deleted, although the deletion
// is actually done by triangles.
//
// Before masking:
//
// X - X - X - X - X
// | \ | \ | \ | \ |
// X - X - X - X - X
// | \ | \ | \ | \ |
// X - X - X - X - X
// | \ | \ | \ | \ |
// X - X - X - X - X
// | \ | \ | \ | \ |
// X - X - X - X - X
//
// After masking:
//
// X - X O O O
// | \ | \
// X - X - X O O
// | \ | \ | \
// X - X - X - X - X
// \ | \ | \ | \ |
// O X - X - X - X
// \ | \ | \ |
// O O X - X - X
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 14 January 2007
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int DIM_NUM, the spatial dimension.
//
// Input, int TRIANGLE_ORDER, the number of nodes in the triangle.
//
// Input, int NODES[TRIANGLE_ORDER], the indices of the nodes.
//
// Input, double COORD[DIM_NUM*TRIANGLE_ORDER], the coordinates
// of the nodes.
//
// Output, bool TRIANGLE_MASK, is TRUE if the triangle should be discarded,
// and FALSE if the triangle should be retained.
//
{
double centroid[2];
int dim;
bool mask;
int order;
//
// Compute the centroid.
//
for ( dim = 0; dim < 2; dim++ )
{
centroid[dim] = 0.0;
for ( order = 0; order < triangle_order; order++ )
{
centroid[dim] = centroid[dim] + coord[dim+order*dim_num];
}
centroid[dim] = centroid[dim] / ( double ) ( triangle_order );
}
//
// Remove the lower left corner
//
if ( centroid[0] + centroid[1] < 2.0 )
{
mask = true;
}
//
// Remove the upper right section.
//
else if ( 5.0 < centroid[0] + centroid[1] &&
2.0 < centroid[1] )
{
mask = true;
}
//
// Keep everything else.
//
else
{
mask = false;
}
return mask;
}