49 :
G4Surface(), bezier_list(0), smin(0.), smax(0.),
50 average_u(0.), average_v(0.), dir(0), u_knots(0), v_knots(0),
51 ctl_points(0), new_knots(0), ord(0), oslo_m(0), lower(0), upper(0),
52 u_min(0.), u_max(0.), v_min(0.), v_max(0.), old_points(0)
54 order[0]=0; order[1]=0;
81 :
G4Surface(), bezier_list(0), smin(0.), smax(0.),
82 average_u(0.), average_v(0.), dir(0), u_knots(0), v_knots(0),
83 ctl_points(0), new_knots(0), ord(0), oslo_m(0), lower(0), upper(0),
84 u_min(0.), u_max(0.), v_min(0.), v_max(0.), old_points(0)
86 order[0]=0; order[1]=0;
103 if(smin > 1.0 || smax < 0.0)
109 if((smax - smin) > 0.8)
115 LocalizeClipValues();
123 if(smin > 1.0 || smax < 0.0)
129 if((smax - smin) > 0.8)
135 LocalizeClipValues();
154 for(
register G4int a = ctl_points->
GetRows()-1; a>=0;a--)
155 for(
register G4int b = ctl_points->
GetCols()-1; b>=0;b--)
165 if((box_min.
x()) > (tmp.
x())) box_min.
setX(tmp.
x());
166 if((box_max.
x()) < (tmp.
x())) box_max.
setX(tmp.
x());
167 if((box_min.
y()) > (tmp.
y())) box_min.
setY(tmp.
y());
168 if((box_max.
y()) < (tmp.
y())) box_max.
setY(tmp.
y());
175void G4BezierSurface::CalcAverage()
178 average_u = (u_min + u_max)/2.0;
179 average_v = (v_min + v_max)/2.0;
183void G4BezierSurface::CalcDistance(
const G4Point3D& ray_start)
187 distance = ((((ray_start.
x() - average_pt.
x())*
188 (ray_start.
x() - average_pt.
x()))+
189 ((ray_start.
y() - average_pt.
y())*
190 (ray_start.
y() - average_pt.
y()))+
191 ((ray_start.
z() - average_pt.
z())*
192 (ray_start.
z() - average_pt.
z()))));
196void G4BezierSurface::SetValues()
214 G4int clip_regions = 0;
236 GetClippedRegionFromSurface();
251 if( (u_max - u_min) < (v_max - v_min) )
262 if( smin > 1.0 || smax < 0.0 )
269 if( (smax - smin) > 0.8)
287 LocalizeClipValues();
360 G4double norm = std::sqrt(v3.
x() * v3.
x() + v3.
y() * v3.
y());
363 G4cout <<
"\nNormal zero!";
364 G4cout <<
"\nLINE & DIR: " << line.
x() <<
" " << line.
y() <<
" " << dir;
368 line.
setX(-line.
x());
371 line.
setY(-line.
y());
374 G4cout <<
"\n RETURNING FROm CLIP..";
375 smin = 0; smax = 1;
delete ch_tmp;
379 G4cout <<
"\nCHANGED LINE & DIR: " << line.
x() <<
" "
380 << line.
y() <<
" " << dir;
384 line.
setX( v3.
y() / norm);
385 line.
setY(-v3.
x() / norm);
396 for(
G4int a = 0; a < col_size; a++)
398 ch_ptr =
new G4ConvexHull(a/(col_size - 1.0),1.0e8,-1.0e8);
401 ch_first=ch_ptr;
delete ch_tmp;
414 for(
G4int h = 0; h < row_size; h++)
416 for(
G4int k = 0; k < col_size; k++)
423 value = - ((coordstmp.
x() * line.
x() + coordstmp.
y() * line.
y()));
440 for(
G4int l = 0; l < col_size - 1; l++)
443 for(
G4int q = l+1; q < col_size; q++)
445 register G4double d, param1, param2;
451 d = Findzero( param1, param2, ch_ptr->
GetMax(), ch_tmp->
GetMax());
458 d = Findzero( param1, param2, ch_ptr->
GetMin(), ch_tmp->
GetMin());
471 if (smin <= 0.0) smin = 0.0;
472 if (smax >= 1.0) smax = 1.0;
475 && (Sign(ch_ptr->
GetMin()) != Sign(ch_ptr->
GetMax()))) smin = 0.0;
477 i = Sign(ch_tmp->
GetMin());
478 j = Sign(ch_tmp->
GetMax());
486 for(
G4int n = 0; n < row_size; n++)
488 ch_ptr =
new G4ConvexHull(n/(row_size - 1.0),1.0e8,-1.0e8);
491 ch_first=ch_ptr;
delete ch_tmp;
500 for(
G4int o = 0; o < col_size; o++)
502 for(
G4int p = 0; p < row_size; p++)
511 value = - ((coordstmp.
x() * line.
x() + coordstmp.
y() * line.
y()));
525 for(
G4int q = 0; q < row_size - 1; q++)
528 for(
G4int r = q+1; r < row_size; r++)
536 d = Findzero( param1, param2, ch_ptr->
GetMax(), ch_tmp->
GetMax());
543 d = Findzero( param1, param2, ch_ptr->
GetMin(), ch_tmp->
GetMin());
557 if (smin <= 0.0) smin = 0.0;
558 if (smax >= 1.0) smax = 1.0;
561 && (Sign(ch_ptr->
GetMin()) != Sign(ch_ptr->
GetMax()))) smin = 0.0;
565 i = Sign(ch_tmp->
GetMin());
566 j = Sign(ch_tmp->
GetMax());
586void G4BezierSurface::GetClippedRegionFromSurface()
616void G4BezierSurface::RefineSurface()
660void G4BezierSurface::CalcOsloMatrix()
671 register G4int mu, muprim;
672 register G4int vv, p;
673 register G4int iu, il, ih, n1;
681 n1 = new_knots->
GetSize() - ord;
691 tmp=oslo_m->
GetNextNode();
delete oslo_m; oslo_m=tmp;
706 for (j = 0; j < n1; j++)
729 for (vv = 0, p = 1; p < ord; p++)
737 ahi = AhIndex(0, ord - 1,ord);
740 for (p = 1; p <= vv; p++)
747 beta1 = AhIndex(p - 1, ord - muprim,ord);
748 beta1 = ((tj - old_knots->
GetKnot(0)) * beta1) /
755 iu = Amin (muprim, i);
757 for (i = il; i <= iu; i++)
762 d1 = tj - old_knots->
GetKnot(i);
763 d2 = old_knots->
GetKnot(i + p + ord - vv - 1) - tj;
765 beta = ah->
GetKnot(AhIndex(p - 1, i + ord - muprim - 1,ord)) /
769 ah->
PutKnot(AhIndex(p, i + ord - muprim - 2,ord), d2 * beta + beta1) ;
773 ah->
PutKnot(AhIndex(p, iu + ord - muprim - 1,ord), beta1);
780 kkk = old_knots->
GetKnot(n1 - 1 + ord);
781 ahv = AhIndex (p - 1, iu + ord - muprim,ord);
782 ah->
PutKnot(AhIndex(p, iu + ord - muprim - 1,ord),
783 beta1 + (kkk - tj) * ahv /
784 (kkk - old_knots->
GetKnot(iu + 1)));
814 oslo_m =
new G4OsloMatrix(vv+1, Amax(muprim - vv,0), vv);
816 for ( i = vv, p = 0; i >= 0; i--)
829void G4BezierSurface::MapSurface(
G4Surface*)
840 new_pts = ctl_points;
844 old_pts = old_points;
857 for(
G4int a=0; a<size;a++)
861 for ( i = 0, o_ptr = oslo_m;
872 for ( j = lower; j < upper; j++, o_ptr = o_ptr->GetNextNode())
885 o_scale = o_ptr->GetKnotVector()->GetKnot(0);
887 tempc.
setX(o_pts.
x() * o_scale);
888 tempc.
setY(o_pts.
x() * o_scale);
890 for ( i = 1; i <= o_ptr->GetSize(); i++)
892 o_scale = o_ptr->GetKnotVector()->GetKnot(i);
899 o_pts = old_pts->
Get3D(x, i+o_ptr->GetOffset());
900 tempc.
setX(tempc.
x() + o_scale * o_pts.
x());
901 tempc.
setY(tempc.
y() + o_scale * o_pts.
y());
905 c_ptr->
put(a,(j)%upper-lower,tempc);
910 for ( j = lower; j < upper; j++, o_ptr = o_ptr->GetNextNode())
923 o_scale = o_ptr->GetKnotVector()->GetKnot(0);
925 tempc.
setX(o_pts.
x() * o_scale);
926 tempc.
setY(o_pts.
y() * o_scale);
928 for ( i = 1; i <= o_ptr->GetSize(); i++)
930 o_scale = o_ptr->GetKnotVector()->GetKnot(i);
934 o_pts= old_pts->
Get3D(i+o_ptr->GetOffset(),a);
935 tempc.
setX(tempc.
x() + o_scale * o_pts.
x());
936 tempc.
setY(tempc.
y() + o_scale * o_pts.
y());
939 c_ptr->
put((j)%upper-lower,a,tempc);
946void G4BezierSurface::SplitNURBSurface()
955 register G4int k_index=0;
963 for( i = 0; i < u_knots->
GetSize(); i++)
964 if( value == u_knots->
GetKnot(i) )
990 delete srf1->ctl_points;
999 new_knots->
GetSize(), k_index);
1004 delete srf2->ctl_points;
1019 for( i = 0; i < v_knots->
GetSize(); i++)
1020 if( value == v_knots->
GetKnot(i))
1046 delete srf1->ctl_points;
1058 delete srf2->ctl_points;
HepGeom::Point3D< G4double > G4Point3D
const G4Point3D PINFINITY(kInfinity, kInfinity, kInfinity)
HepGeom::Vector3D< G4double > G4Vector3D
G4DLLIMPORT std::ostream G4cout
static G4double Tolerance
virtual G4Vector3D SurfaceNormal(const G4Point3D &Pt) const
G4SurfaceList * bezier_list
virtual ~G4BezierSurface()
G4int GetOrder(G4int direction) const
G4int BIntersect(G4SurfaceList &)
G4int GetTestResult() const
G4Point3D Get3D(G4int i, G4int j) const
void put(G4int i, G4int j, const G4Point3D &tmp)
G4ConvexHull * GetNextHull()
G4double GetParam() const
void SetNextHull(G4ConvexHull *n)
void ExtractKnotVector(G4KnotVector *kv, G4int upper, G4int lower)
G4double GetKnot(G4int knot_number) const
G4KnotVector * MultiplyKnotVector(G4int num, G4double value)
void PutKnot(G4int knot_number, G4double value)
G4OsloMatrix * GetNextNode()
void SetNextNode(G4OsloMatrix *)
G4KnotVector * GetKnotVector()
void AddSurface(G4Surface *srf)
void RemoveSurface(G4Surface *srf)