@@ -12,28 +12,136 @@ namespace MMVII
1212template <const int DimM,const int DimE> class cManifold
1313{
1414 public :
15- static const int DimC = DimE - DimM,
15+ static const int DimC = DimE - DimM;
1616
1717 typedef cPtxd<tREAL8,DimM> tPtM;
1818 typedef cPtxd<tREAL8,DimE> tPtE;
19- typedef std::array <tPtE,DimC> tTgSp;
19+ typedef std::vector <tPtE> tTgSp;
2020
21+
22+ cManifold (int aNbMap=1 ,const tREAL8 aEpsDeriv = 1e-4 );
23+
24+ // / return the num map of a point, defaults assume mNbMap==1
25+ virtual int GetNumMap (const tPtE &) const ;
2126 // / Retun a point of manifold in embedding space kowning a parameter, default error
22- virtual tPtE PtOfParam (const tPtM &) const ;
27+ virtual tPtE PtOfParam (const tPtM &, int aNumMap ) const ;
2328 // / "Inverse" of PtOfParam, Assuming tPtE is on manifold
24- virtual tPtM ParamOfPt (const tPtE &) const ;
29+ virtual std::pair< int , tPtM> ParamOfPt (const tPtE &) const ;
2530
2631 // / return TgSpace
27- virtual tTgSp TgSpace (const tPtE &) const ;
32+ virtual tTgSp TgSpace (const tPtE &) const ;
33+ // / Given a point, gives an approximate value of the projection
34+ virtual tPtE ApproxProj (const tPtE &) const ;
35+ // /
36+ virtual tPtE Proj (const tPtE &) const ;
2837 private :
38+ int mNbMap ;
39+ tREAL8 mEpsDeriv ;
2940};
3041
42+ template <const int DimM,const int DimE>
43+ cManifold<DimM,DimE>::cManifold(int aNbMap,const tREAL8 aEpsDeriv) :
44+ mNbMap (aNbMap),
45+ mEpsDeriv (aEpsDeriv)
46+ {
47+ }
48+
49+ template <const int DimM,const int DimE> int cManifold<DimM,DimE>::GetNumMap(const tPtE &) const
50+ {
51+ MMVII_INTERNAL_ASSERT_tiny (mNbMap ==1 ," cCurveFromMapping->aNumMap" );
52+ return 0 ;
53+ }
54+
55+ template <const int DimM,const int DimE> cPtxd<tREAL8,DimE> cManifold<DimM,DimE>::PtOfParam(const tPtM&,int ) const
56+ {
57+ MMVII_INTERNAL_ERROR (" No def cManifold<DimM,DimE>::PtOfParam" );
58+ return tPtE ();
59+ }
60+
61+ template <const int DimM,const int DimE> std::pair<int ,cPtxd<tREAL8,DimM>> cManifold<DimM,DimE>::ParamOfPt(const tPtE&) const
62+ {
63+ MMVII_INTERNAL_ERROR (" No def cManifold<DimM,DimE>::ParamOfPt" );
64+ return std::pair<int ,tPtM>(0 ,tPtM ());
65+ }
3166
3267
68+ template <const int DimM,const int DimE>
69+ typename cManifold<DimM,DimE>::tTgSp cManifold<DimM,DimE>::TgSpace(const tPtE & aPE)const
70+ {
71+ tTgSp aRes;
72+ auto [aNum,aPParam] = ParamOfPt (aPE);
73+
74+ for (int aKM=0 ; aKM<DimM ; aKM++)
75+ {
76+ tPtM aDelta = tPtM::P1Coord (aKM,mEpsDeriv );
77+ tPtE aPPlus = PtOfParam (aPParam+aDelta,aNum);
78+ tPtE aPMinus = PtOfParam (aPParam-aDelta,aNum);
79+ tPtE aTgt = (aPPlus-aPMinus) / (2 *mEpsDeriv ) ;
80+
81+ // make some "on the fly" orthogonalization
82+ for (const auto & aPrec : aRes)
83+ {
84+ aTgt = aTgt - aPrec* Scal (aPrec,aTgt);
85+ }
86+
87+ aRes.push_back (VUnit (aTgt));
88+ }
89+
90+ return aRes;
91+ }
92+
3393template class cManifold <1 ,2 >; // curve 2d
3494template class cManifold <1 ,3 >; // curve 3d
3595
3696
97+ template <int DimE> class cCurveFromMapping : public cManifold <1 ,DimE>
98+ {
99+ public :
100+ // virtual tPtE PtOfParam(const tPtM &,int aNumMap) const ;
101+ static const int DimM = 1 ;
102+ static const int DimC = DimE - DimM;
103+
104+ typedef cPtxd<tREAL8,DimM> tPtM;
105+ typedef cPtxd<tREAL8,DimE> tPtE;
106+ typedef cSegmentCompiled<tREAL8,DimE> tSeg;
107+ typedef cDataInvertibleMapping<tREAL8,DimE> tMap;
108+
109+ tPtE PtOfParam (const tPtM &,int aNumMap) const override ;
110+ std::pair<int ,tPtM> ParamOfPt (const tPtE &) const override ;
111+ tPtE ApproxProj (const tPtE &) const override ;
112+ private :
113+ tSeg mSeg ;
114+ tMap *mMap ;
37115
38116};
39117
118+ template <int DimE> cPtxd<tREAL8,DimE> cCurveFromMapping<DimE>::PtOfParam(const tPtM & aP1,int aNumMap) const
119+ {
120+ MMVII_INTERNAL_ASSERT_tiny (aNumMap==0 ," cCurveFromMapping->aNumMap" );
121+
122+ tPtE aPtOnSeg = mSeg .PtOfAbscissa (aP1.x ());
123+
124+ return mMap ->Value (aPtOnSeg);
125+ }
126+
127+ template <int DimE> std::pair<int ,cPtxd<tREAL8,1 >> cCurveFromMapping<DimE>::ParamOfPt(const tPtE & aPE) const
128+ {
129+ tPtE aPOnSeg = mMap ->Inverse (aPE);
130+ return std::pair<int ,tPtM>(0 ,tPtM (mSeg .Abscissa (aPOnSeg)));
131+ }
132+
133+
134+ template <int DimE> cPtxd<tREAL8,DimE> cCurveFromMapping<DimE>::ApproxProj(const tPtE & aP1) const
135+ {
136+ tPtE aP2 = mMap ->Value (aP1);
137+ tPtE aP3 = mSeg .Proj (aP2);
138+ return mMap ->Inverse (aP3);
139+ }
140+
141+
142+ template class cCurveFromMapping <2 >; // curve 2d
143+ template class cCurveFromMapping <3 >; // curve 2d
144+ };
145+
146+
147+
0 commit comments