@@ -134,15 +134,37 @@ void EllipticMorph::execute()
134134
135135 markLockedCells ();
136136
137- std::vector<Node> nodes_int;
138- std::vector<Node> nodes_ext;
137+ std::vector<TCellID> modified_nodes;
138+
139+ if (m_ext_lock.empty ()){
140+ modified_nodes = noExteriorLock ();
141+ }else {
142+ modified_nodes = withExteriorLock ();
143+ }
144+
145+ for (auto n : modified_nodes){
146+
147+ math::Vector3d vec (m_vecs[n]);
148+ Node node = m_mesh->get <Node>(n);
149+ double y = node.Y ();
150+ double z = node.Z ();
151+
152+ node.setY (y+vec.Y ());
153+ node.setZ (z+vec.Z ());
154+ }
155+
156+ finalize ();
157+
158+ std::cout<<" ============================== Elliptic Morphing Finished ==============================" <<std::endl;
159+ }
160+ /* ----------------------------------------------------------------------------*/
161+ std::vector<TCellID> EllipticMorph::withExteriorLock (){
139162
140163 FastLocalize fl_int (m_lockedIn);
141164 FastLocalize fl_ext (m_lockedOut);
142165 FastLocalize fl_morphed (m_morphed);
143166
144- std::map<TCellID, math::Vector3d> vecs;
145- std::set<TCellID> modified_nodes;
167+ std::set<TCellID> internal_modified_nodes;
146168
147169 for (int i = 0 ; i < m_ellipses.size ()-1 ; i++) {
148170
@@ -193,8 +215,8 @@ void EllipticMorph::execute()
193215
194216 math::Vector3d vec;
195217 vec.setXYZ (0 , newY - p.Y (), newZ - p.Z ());
196- vecs [n.id ()] = vec;
197- modified_nodes .insert (n.id ());
218+ m_vecs [n.id ()] = vec;
219+ internal_modified_nodes .insert (n.id ());
198220 }
199221 }
200222
@@ -215,7 +237,7 @@ void EllipticMorph::execute()
215237 }
216238
217239 for (const auto & n : execution) {
218- modified_nodes .insert (n.id ());
240+ internal_modified_nodes .insert (n.id ());
219241
220242 math::Point p = n.point ();
221243
@@ -249,27 +271,135 @@ void EllipticMorph::execute()
249271 }
250272
251273 math::Vector3d vec;
252- vec = vecs [nearest_morphed.id ()];
274+ vec = m_vecs [nearest_morphed.id ()];
253275 vec *= omega;
254276
255- vecs [n.id ()] = vec;
277+ m_vecs [n.id ()] = vec;
256278 }
257279 }
258280
259- for ( auto n : modified_nodes){
281+ std::vector<TCellID> node_list (internal_modified_nodes. begin (),internal_modified_nodes. end ());
260282
261- math::Vector3d vec (vecs[n]) ;
262- Node node = m_mesh-> get <Node>(n);
263- double y = node. Y ();
264- double z = node. Z ();
283+ return node_list ;
284+ }
285+ /* ---------------------------------------------------------------------------- */
286+ std::vector<TCellID> EllipticMorph::noExteriorLock (){
265287
266- node.setY (y+vec.Y ());
267- node.setZ (z+vec.Z ());
288+ FastLocalize fl_int (m_lockedIn);
289+ FastLocalize fl_morphed (m_morphed);
290+
291+ std::set<TCellID> internal_modified_nodes;
292+
293+ for (int i = 0 ; i < m_ellipses.size ()-1 ; i++) {
294+
295+ double Xmin = m_ellipses[i][0 ];
296+ double Xmax = m_ellipses[i + 1 ][0 ];
297+
298+ std::vector<Node> interval_morphed;
299+
300+ for (auto n : m_morphed) {
301+ if (n.X () >= Xmin && n.X () < Xmax) {
302+ interval_morphed.push_back (n);
303+ }
304+ }
305+
306+ double coefa_min = m_ellipses[i][1 ];
307+ double coefb_min = m_ellipses[i][2 ];
308+ double coefc_min = m_ellipses[i][3 ];
309+
310+ double coefa_max = m_ellipses[i + 1 ][1 ];
311+ double coefb_max = m_ellipses[i + 1 ][2 ];
312+ double coefc_max = m_ellipses[i + 1 ][3 ];
313+
314+ for (auto n : interval_morphed) {
315+ math::Point p = n.point ();
316+
317+ math::Point p_int = m_mesh->get <Node>(fl_int.find (p)).point ();
318+
319+ double distXmin = p.X () - Xmin;
320+ double distXmax = Xmax - Xmin;
321+ double w = distXmin / distXmax;
322+
323+ double coefy_min = p.Y () >= 0 ? coefa_min : coefc_min;
324+ double coefy_max = p.Y () >= 0 ? coefa_max : coefc_max;
325+
326+ double coefy_test = coefy_min * (3 * pow (1 - w, 2 ) - 2 * pow (1 - w, 3 )) + coefy_max * (3 * pow (w, 2 ) - 2 * pow (w, 3 ));
327+ double coefz_test = coefb_min * (3 * pow (1 - w, 2 ) - 2 * pow (1 - w, 3 )) + coefb_max * (3 * pow (w, 2 ) - 2 * pow (w, 3 ));
328+
329+ double theta = atan (n.Y () / n.Z ());
330+ if (theta < 0 ) {
331+ theta *= -1 ;
332+ }
333+
334+ double sinus = sin (theta);
335+ double cosinus = cos (theta);
336+
337+ double newY = (p.Y () * ((coefy_test * sinus) + coefz_test * (1 - sinus)));
338+ double newZ = (p.Z () * ((coefz_test * cosinus) + coefy_test * (1 - cosinus)));
339+
340+ math::Vector3d vec;
341+ vec.setXYZ (0 , newY - p.Y (), newZ - p.Z ());
342+ m_vecs[n.id ()] = vec;
343+ internal_modified_nodes.insert (n.id ());
344+ }
268345 }
269346
270- finalize ();
347+ for ( int i = 0 ; i < m_ellipses. size ()- 1 ; i++) {
271348
272- std::cout<<" ============================== Elliptic Morphing Finished ==============================" <<std::endl;
349+ double Xmin = m_ellipses[i][0 ];
350+ double Xmax = m_ellipses[i+1 ][0 ];
351+
352+ std::vector<Node> execution;
353+
354+ for (auto n : m_mesh->nodes ()){
355+
356+ Node node = m_mesh->get <Node>(n);
357+
358+ if (node.X () >= Xmin && node.X () < Xmax && !m_mesh->isMarked <Node>(n, m_locked)) {
359+ execution.push_back (node);
360+ }
361+ }
362+
363+ for (const auto & n : execution) {
364+ internal_modified_nodes.insert (n.id ());
365+
366+ math::Point p = n.point ();
367+
368+ Node nearest_morphed = m_mesh->get <Node>(fl_morphed.find (p));
369+
370+ math::Point p_int = m_mesh->get <Node>(fl_int.find (p)).point ();
371+ math::Point p_m = nearest_morphed.point ();
372+ math::Point p_axe (p.X (), 0 , 0 );
373+
374+ math::Point p_origin = p.distance (p_int) < p.distance (p_axe) ? p_int : p_axe;
375+
376+ double dist_p = p.distance (p_axe);
377+ double dist_pm = p_m.distance (p_axe);
378+
379+ double dist1;
380+ double dist2;
381+ double omega;
382+
383+
384+ if (dist_p < dist_pm){
385+ dist1 = p.distance (p_origin);
386+ dist2 = p_m.distance (p_origin);
387+ omega = dist1 / dist2;
388+ }else {
389+ std::cout<<" error where is p ?" <<std::endl;
390+ }
391+
392+ math::Vector3d vec;
393+ vec = m_vecs[nearest_morphed.id ()];
394+ vec *= omega;
395+
396+ m_vecs[n.id ()] = vec;
397+ }
398+ }
399+
400+ std::vector<TCellID> node_list (internal_modified_nodes.begin (),internal_modified_nodes.end ());
401+
402+ return node_list;
273403}
274404/* ----------------------------------------------------------------------------*/
275405void EllipticMorph::markLockedCells ()
0 commit comments