forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opennurbs_brep_v2valid.cpp
221 lines (196 loc) · 5.92 KB
/
opennurbs_brep_v2valid.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
#if !defined(ON_COMPILING_OPENNURBS)
// This check is included in all opennurbs source .c and .cpp files to insure
// ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
// and the opennurbs .h files alter what is declared and how it is declared.
#error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
#endif
bool ON_Brep::IsValidForV2( const ON_BrepTrim& trim ) const
{
int ti = trim.m_trim_index;
if ( ti < 0 || ti >= m_T.Count() )
return false;
if ( &trim != &m_T[ti] )
return false;
if ( trim.ProxyCurveIsReversed() )
return false;
if ( trim.Domain() != trim.ProxyCurveDomain() )
return false;
const ON_Curve * curve = trim.TrimCurveOf();
if ( curve != trim.ProxyCurve() )
return false;
const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(curve);
if ( 0 == nurbs_curve )
return false;
if ( !nurbs_curve->IsClamped(2) )
return false;
if ( nurbs_curve->m_dim != 2 )
return false;
if ( nurbs_curve->m_is_rat )
{
// 2 June 2003 Dale Lear - RR 8809 fix
// V2 likes end weights to be 1.0
if ( nurbs_curve->m_cv[2] != 1.0 || nurbs_curve->CV(nurbs_curve->m_cv_count-1)[2] != 1.0 )
{
return false;
}
}
if ( nurbs_curve->m_cv_count >= 4
&& 0 == ON_ComparePoint( nurbs_curve->m_dim, nurbs_curve->m_is_rat, nurbs_curve->m_cv, nurbs_curve->CV(nurbs_curve->m_cv_count-1) )
)
{
// 14 April 2003 Dale Lear
// RR 8843 - V2 wants ends of this trim farther apart
if ( trim.m_vi[0] != trim.m_vi[1] )
{
const ON_BrepLoop* loop = Loop(trim.m_li);
if ( 0 != loop && loop->m_ti.Count() > 1 )
return false;
}
}
if ( curve->Domain() != trim.Domain() )
return false;
return true;
}
bool ON_Brep::IsValidForV2( const ON_BrepEdge& edge ) const
{
int ei = edge.m_edge_index;
if ( ei < 0 || ei >= m_E.Count() )
return false;
if ( &edge != &m_E[ei] )
return false;
if ( edge.ProxyCurveIsReversed() )
return false;
if ( edge.Domain() != edge.ProxyCurveDomain() )
return false;
const ON_Curve * curve = edge.EdgeCurveOf();
if ( curve != edge.ProxyCurve() )
return false;
const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(curve);
if ( 0 == nurbs_curve )
return false;
if ( !nurbs_curve->IsClamped(2) )
return false;
if ( nurbs_curve->m_dim != 3 )
return false;
if ( nurbs_curve->m_is_rat )
{
// 2 June 2003 Dale Lear - RR 8809 fix
// V2 likes end weights to be 1.0
if ( nurbs_curve->m_cv[3] != 1.0 || nurbs_curve->CV(nurbs_curve->m_cv_count-1)[3] != 1.0 )
{
return false;
}
}
if ( curve->Domain() != edge.Domain() )
return false;
// 14 April 2003 Dale Lear
// RR 8808 - V2 requires edges to be strictly closed/open
if ( nurbs_curve->m_cv_count >= 4
&& 0 == ON_ComparePoint( nurbs_curve->m_dim, nurbs_curve->m_is_rat, nurbs_curve->m_cv, nurbs_curve->CV(nurbs_curve->m_cv_count-1) )
)
{
if ( edge.m_vi[0] != edge.m_vi[1] )
return false;
}
else if (edge.m_vi[0] == edge.m_vi[1] )
{
return false;
}
return true;
}
bool ON_Brep::IsValidForV2() const
{
bool rc = IsValidTopology()?true:false;
if ( rc )
{
int c2i, c3i, si, ti, li, ei, vi, fi, next_ti, lti, next_lti, loop_trim_count;
ON_3dPoint P0, P1;
const int c2_count = m_C2.Count();
const int c3_count = m_C3.Count();
const int s_count = m_S.Count();
const int vertex_count = m_V.Count();
const int edge_count = m_E.Count();
const int face_count = m_F.Count();
const int loop_count = m_L.Count();
const int trim_count = m_T.Count();
for ( c2i = 0; c2i < c2_count; c2i++ )
{
// v2 3dm files expect NURBS curves
if ( !ON_NurbsCurve::Cast(m_C2[c2i]) )
return false;
}
for ( c3i = 0; c3i < c3_count; c3i++ )
{
// v2 3dm files expect NURBS curves
if ( !ON_NurbsCurve::Cast(m_C3[c3i]) )
return false;
}
for ( si = 0; si < s_count; si++ )
{
// v2 3dm files expect NURBS surfaces
if ( !ON_NurbsSurface::Cast(m_S[si]) )
return false;
}
for ( vi = 0; vi < vertex_count; vi++ )
{
const ON_BrepVertex& vertex = m_V[vi];
if ( vertex.m_vertex_index != vi )
return false;
}
for ( fi = 0; fi < face_count; fi++ )
{
const ON_BrepFace& face = m_F[fi];
if ( face.m_face_index != fi )
return false;
}
for ( ti = 0; ti < trim_count; ti++ )
{
if ( !IsValidForV2( m_T[ti] ) )
return false;
}
for ( ei = 0; ei < edge_count; ei++ )
{
if ( !IsValidForV2(m_E[ei]) )
return false;
}
for ( li = 0; li < loop_count; li++ )
{
const ON_BrepLoop& loop = m_L[li];
if ( loop.m_loop_index == -1 )
return false;
loop_trim_count = loop.m_ti.Count();
for ( lti = 0; lti < loop_trim_count; lti++ )
{
next_lti = (lti+1)%loop_trim_count;
ti = loop.m_ti[lti];
next_ti = loop.m_ti[next_lti];
if ( ti < 0 || ti >= trim_count )
return false;
if ( next_ti < 0 || next_ti >= trim_count )
return false;
P0 = m_T[ti].PointAtEnd();
P1 = m_T[next_ti].PointAtStart();
if ( P0.DistanceTo(P1) > ON_ZERO_TOLERANCE )
return false;
}
}
}
return rc;
}