51 <<
"##ojc{NURBS}def[1.01.96.7] Just a magic. Could be added to /etc/magic"
52 <<
"\n# NURBS Definition File (human and computer readable format)"
53 <<
"\n# :" << in_kNurb.
Whoami()
54 <<
"\n# U order\tV order : "
70 otherKnots = knotI.
pick(&oneKnot);
71 inout_outStream <<
"\n\t\t" << oneKnot;
80 <<
"\n# Number of control points along U and V"
83 <<
"\n# Control Points (one by line, U increasing first)";
90 otherCPs = cpI.
pick(&oneCP);
100 inout_outStream <<
"\n# That's all!"
102 return inout_outStream;
111 if ( in_index <
m[in_dir].nbrKnots )
115 G4cerr <<
"\nERROR: G4NURBS::GetfloatKnot: index out of range\n"
116 <<
"\n\t in_dir : " <<
G4int(in_dir)
117 <<
", in_index : " <<
G4int(in_index)
119 return ((
G4float)
m[in_dir].pKnots[
m[in_dir].nbrKnots-1]);
126 if ( in_index <
m[in_dir].nbrKnots )
130 G4cerr <<
"\nERROR: G4NURBS::GetdoubleKnot: index out of range"
131 <<
"\n\t in_dir : " <<
G4int(in_dir)
132 <<
", in_index : " <<
G4int(in_index)
133 <<
"m[in_dir].nbrKnots : " <<
m[in_dir].
nbrKnots
146 G4cerr <<
"\nERROR: G4NURBS::GetfloatCtrlPt: index out of range"
147 <<
"\n\t in_onedimindex : " << in_onedimindex
156 if ( (in_Uindex <
m[
U].nbrCtrlPts) && (in_Vindex <
m[
V].nbrCtrlPts) )
160 G4cerr <<
"\nERROR: G4NURBS::GetfloatCtrlPt: index(s) out of range"
161 <<
"\n\t in_Uindex : " << in_Uindex
162 <<
" , in_Vindex : " << in_Vindex
176 G4cerr <<
"\nERROR: G4NURBS::getdoubleCtrlPts: index out of range"
177 <<
"\n\t in_onedimindex : " << in_onedimindex
186 if ( (in_Uindex <
m[
U].nbrCtrlPts) && (in_Vindex <
m[
V].nbrCtrlPts) )
190 G4cerr <<
"\nERROR: G4NURBS::GetdoubleCtrlPt: index(s) out of range"
191 <<
"\n\t in_Uindex : " << in_Uindex
192 <<
" , in_Vindex : " << in_Vindex
240 kmpMax(in_rNurb.m[kmdir].pKnots + in_rNurb.m[kmdir].nbrKnots)
246 G4cerr <<
"\nERROR: G4NURBS::KnotsIterator: in_startIndex out of range"
247 <<
"\n\tin_startIndex : " << in_startIndex
249 <<
"\n\t mp set to NULL, calls to picking functions will fail"
258 return (
G4bool)((++mp)<kmpMax);
263 (*inout_pFlt) = (
G4float)(*mp);
264 return (
G4bool)((++mp)<kmpMax);
275 G4cerr <<
"\nERROR: G4NURBS::CtrlPtsCoordsIterator: "
276 <<
"in_startCtrlPtIndex out of range"
277 <<
"\n\tin_startCtrlPtIndex : " << in_startCtrlPtIndex
279 <<
"\n\t mp set to NULL, calls to picking functions will fail"
288 return (
G4bool)((++mp)<kmpMax);
293 (*inout_pFlt) = (
G4float)((*mp));
294 return (
G4bool)((++mp)<kmpMax);
305 G4cerr <<
"\nERROR: G4NURBS::CtrlPtsIterator: in_startIndex out of range"
306 <<
"\n\tin_startIndex : " << in_startIndex
308 <<
"\n\t mp set to NULL, calls to picking functions will fail"
317 (*inout_pDblCtrlPt)[i] = (
G4double)((*mp)[i]);
318 return (
G4bool)((++mp)<kmpMax);
324 (*inout_pFltCtrlPt)[i] = (
G4float)((*mp)[i]);
325 return (
G4bool)((++mp)<kmpMax);
342 if ( (nbrCentralDistinctKnots % in_KVGFlag) == 0)
344 nbrCentralDistinctKnots /= in_KVGFlag;
352 t_Knot stepKnot = 1.0/(
t_Knot)(nbrCentralDistinctKnots+1);
353 t_Knot valKnot = stepKnot;
356 for (
t_indKnot j=0; j<nbrCentralDistinctKnots; valKnot+=stepKnot, j++)
359 io_d.
pKnots[indKnot] = valKnot;
377 default: io_ostr << (
G4int)in_f;
385void G4NURBS::Conscheck()
const
389 for (dummy=0; (dummy?(dir=
V):(dir=
U)),(dummy <
NofD); dummy++)
394 ed <<
"The order in the "
396 <<
" direction must be >= 1" <<
G4endl;
400 if (
m[dir].nbrCtrlPts<=0)
403 ed <<
"The number of control points "
405 <<
" direction must be >= 1" <<
G4endl;
432 ed <<
"A NURBS MUST HAVE CONTROL POINTS!\n"
433 <<
"\teven if they are defined later, the array must be allocated."
443 for (dummy=0; (dummy?(dir=
V):(dir=
U)),(dummy <
NofD); dummy++)
445 if ( !(
m[dir].pKnots = (dummy?in_pVKnots:in_pUKnots)) )
450 ed <<
"Unable to make a Regular knot vector along "
487 for (dummy=0; (dummy?(dir=
V):(dir=
U)),(dummy <
NofD); dummy++)
494 ed <<
"Unable to make knot vector along "
497 <<
" knots requested for a "
523 for (dummy=0; (dummy?(dir=
V):(dir=
U)),(dummy <
NofD); dummy++)
526 m[dir] = in_krNurb.
m[dir];
532 memcpy(
m[dir].pKnots, in_krNurb.
m[dir].
pKnots,
543 G4cerr <<
"\nWARNING: G4NURBS::G4NURBS(const G4NURBS &) used" <<
G4endl;
551 for (dummy=0; (dummy?(dir=
V):(dir=
U)),(dummy <
NofD); dummy++)
577 if (u == kv[np+1])
return np;
579 while ((u < kv[i]) && (i > 0)) i--;
602 for (r=2; r <= k; r++)
604 i = brkPoint - r + 1;
606 for (q=r-2; q >= 0; q--)
615 omega = (u - kv[i]) / (kv[i+r-1] - kv[i]);
617 bvals[q+1] = bvals[q+1] + (1.0-omega) * bvals[q];
618 bvals[q] = omega * bvals[q];
634 BasisFunctions(u, brkPoint, kv, k-1, dvals);
638 knotScale = kv[brkPoint+1] - kv[brkPoint];
640 i = brkPoint - k + 1;
641 for (q=k-2; q >= 0; q--)
644 omega = knotScale * ((
G4double)(k-1)) / (kv[i+k-1] - kv[i]);
645 dvals[q+1] += -omega * dvals[q];
669 G4int ubrkPoint, ufirst;
671 G4int vbrkPoint, vfirst;
673 Point4 r, rutan, rvtan;
675 r.x = 0.0; r.y = 0.0; r.z = 0.0; r.w = 0.0;
676 rutan = r; rvtan = r;
685 ubrkPoint = FindBreakPoint(u,
m[
U].pKnots, numU-1, orderU);
686 ufirst = ubrkPoint - orderU + 1;
687 BasisFunctions (u, ubrkPoint,
m[
U].pKnots, orderU, bu);
688 BasisDerivatives(u, ubrkPoint,
m[
U].pKnots, orderU, buprime);
690 vbrkPoint = FindBreakPoint(v,
m[
V].pKnots, numV-1, orderV);
691 vfirst = vbrkPoint - orderV + 1;
692 BasisFunctions (v, vbrkPoint,
m[
V].pKnots, orderV, bv);
693 BasisDerivatives(v, vbrkPoint,
m[
V].pKnots, orderV, bvprime);
701 for (i=0; i<orderV; i++)
703 for (j=0; j<orderU; j++)
708 tmp = bu[rj] * bv[ri];
722 tmp = buprime[rj] * bv[ri];
723 rutan.x += cp.x * tmp;
724 rutan.y += cp.y * tmp;
725 rutan.z += cp.z * tmp;
726 rutan.w += cp.w * tmp;
728 tmp = bu[rj] * bvprime[ri];
729 rvtan.x += cp.x * tmp;
730 rvtan.y += cp.y * tmp;
731 rvtan.z += cp.z * tmp;
732 rvtan.w += cp.w * tmp;
738 G4double wsqrdiv = 1.0 / (r.w * r.w);
740 utan.
setX((r.w * rutan.x - rutan.w * r.x) * wsqrdiv);
741 utan.
setY((r.w * rutan.y - rutan.w * r.y) * wsqrdiv);
742 utan.
setZ((r.w * rutan.z - rutan.w * r.z) * wsqrdiv);
744 vtan.
setX((r.w * rvtan.x - rvtan.w * r.x) * wsqrdiv);
745 vtan.
setY((r.w * rvtan.y - rvtan.w * r.y) * wsqrdiv);
746 vtan.
setZ((r.w * rvtan.z - rvtan.w * r.z) * wsqrdiv);
std::ostream & operator<<(std::ostream &inout_outStream, const G4NURBS &in_kNurb)
G4DLLIMPORT std::ostream G4cerr
CtrlPtsCoordsIterator(const G4NURBS &in_rNurb, t_indCtrlPt in_startCtrlPtIndex=0)
G4bool pick(G4double *inout_pDbl)
G4bool pick(t_doubleCtrlPt *inout_pDblCtrlPt)
CtrlPtsIterator(const G4NURBS &in_rNurb, t_indCtrlPt in_startIndex=0)
KnotsIterator(const G4NURBS &in_rNurb, t_direction in_dir, t_indKnot in_startIndex=0)
G4bool pick(G4double *inout_pDbl)
G4double * GetdoubleAllKnots(t_direction in_dir) const
t_floatCtrlPt * GetfloatCtrlPt(t_indCtrlPt in_onedimindex) const
G4double t_doubleCtrlPt[NofC]
static char Tochar(t_direction in_dir)
static G4bool MakeKnotVector(t_Dir &inout_dirdat, t_KnotVectorGenFlag in_KVGFlag)
t_indCtrlPt mtotnbrCtrlPts
G4int GetnbrKnots(t_direction in_dir) const
friend std::ostream & operator<<(std::ostream &inout_OutStream, t_KnotVectorGenFlag in_KVGFlag)
G4double * GetdoubleAllCtrlPts() const
G4float * GetfloatAllCtrlPts() const
static t_doubleCtrlPt * TodoubleCtrlPt(const t_CtrlPt &)
G4NURBS(t_order in_Uorder, t_order in_Vorder, t_inddCtrlPt in_UnbrCtrlPts, t_inddCtrlPt in_VnbrCtrlPts, t_CtrlPt *in_pCtrlPts, t_Knot *in_pUKnots=0, t_Knot *in_pVKnots=0, t_CheckFlag in_CheckFlag=check)
G4double GetdoubleKnot(t_direction in_dir, t_indKnot in_index) const
G4float t_floatCtrlPt[NofC]
G4float GetfloatKnot(t_direction in_dir, t_indKnot in_index) const
virtual const char * Whoami() const =0
t_doubleCtrlPt * GetdoubleCtrlPt(t_indCtrlPt in_onedimindex) const
G4int GetUnbrCtrlPts() const
G4int GetVnbrCtrlPts() const
static t_floatCtrlPt * TofloatCtrlPt(const t_CtrlPt &)
void CalcPoint(G4double u, G4double v, G4Point3D &p, G4Vector3D &utan, G4Vector3D &vtan) const
t_indCtrlPt To1d(t_inddCtrlPt in_Uindex, t_inddCtrlPt in_Vindex) const
G4float * GetfloatAllKnots(t_direction in_dir) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
std::ostringstream G4ExceptionDescription