]> Creatis software - creaMaracasVisu.git/commitdiff
#3493 ShowNPoints_UndoRedo
authorEduardo DAVILA <davila@creatis.insa-lyon.fr>
Sat, 15 Oct 2022 06:16:03 +0000 (08:16 +0200)
committerEduardo DAVILA <davila@creatis.insa-lyon.fr>
Sat, 15 Oct 2022 06:16:03 +0000 (08:16 +0200)
bbtk/src/bbcreaMaracasVisuShowNPoints_Reset.cxx
bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h

index 33c0b574140bd5bcf57a16172a27f61fa22b6f3f..eaeb7519defee4086712a19e5670abeccb6f8cb2 100644 (file)
@@ -29,7 +29,7 @@ void ShowNPoints_Reset::Process()
 //    bbSetOutputOut( bbGetInputIn() );
 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
 
-       bbGetInputWidgetShowNPoints()->DeleteAllPoints();
+       bbGetInputWidgetShowNPoints()->DeleteAllPoints_();
        bbGetInputWidgetShowNPoints()->GetModelShowNPoints()->SetFirstTime(true);
 }
 //===== 
index f17105cd50db92f1f937080b7fa345f8caa20df8..5585788034e4379fe32dcd506e67e188dfe5b7e3 100644 (file)
@@ -32,6 +32,7 @@ void ShowNPoints_Tools::CreatePatch01()
          (wsp->GetModelShowNPoints()->GetLstPointsSize()==4) &&
          (bbGetInputMesh()!=NULL ) )
     {
+        std::vector<long int>   lstIdNormal;
         double                  spc[3];
                                 spc[0]          = bbGetInputSpacing()[0];
                                 spc[1]          = bbGetInputSpacing()[1];
@@ -60,38 +61,44 @@ void ShowNPoints_Tools::CreatePatch01()
         p[2] = lstZ[0] + dz*s;
         NearestPointToMesh(points, pointLocator, spc, p,pM);
         wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
+        lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) );
         s=s*2;
         p[0] = lstX[0] + dx*s;
         p[1] = lstY[0] + dy*s;
         p[2] = lstZ[0] + dz*s;
         NearestPointToMesh(points, pointLocator, spc, p,pM);
         wsp->InsertPoint(pM[0],pM[1], pM[2],"");
+        lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) );
 
         // --- Group 1 ---
-        wsp->OnInsertCollectionAfter_();
+        wsp->InsertCollectionAfter_();
           p[0] = (lstX[0]+lstX[3])/2;
           p[1] = (lstY[0]+lstY[3])/2;
           p[2] = (lstZ[0]+lstZ[3])/2;
           NearestPointToMesh(points, pointLocator, spc, p,pM);
           wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
+          lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) );
           p[0] = (lstX[1]+lstX[2])/2;
           p[1] = (lstY[1]+lstY[2])/2;
           p[2] = (lstZ[1]+lstZ[2])/2;
           NearestPointToMesh(points, pointLocator, spc, p,pM);
           wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
+          lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) );
           p[0] = (lstX[0]+lstX[1]+lstX[2]+lstX[3])/4;          p[1] = (lstY[0]+lstY[1]+lstY[2]+lstY[3])/4;          p[2] = (lstZ[0]+lstZ[1]+lstZ[2]+lstZ[3])/4;
           wsp->InsertPoint(p[0] ,p[1], p[2],"");
 
         // --- Group 2 ---
-        wsp->OnInsertCollectionAfter_();
+        wsp->InsertCollectionAfter_();
           p[0] = lstX[3];
           p[1] = lstY[3];
           p[2] = lstZ[3];
           wsp->InsertPoint(p[0] ,p[1], p[2],"");
+          lstIdNormal.push_back( pointLocator->FindClosestPoint(p) );
           p[0] = lstX[2];
           p[1] = lstY[2];
           p[2] = lstZ[2];
           wsp->InsertPoint(p[0] ,p[1], p[2],"");
+          lstIdNormal.push_back( pointLocator->FindClosestPoint(p) );
           dx = lstX[2]-lstX[3];
           dy = lstY[2]-lstY[3];
           dz = lstZ[2]-lstZ[3];
@@ -110,6 +117,17 @@ void ShowNPoints_Tools::CreatePatch01()
 
         wsp->SetOutputBox();
         pointLocator->Delete();
+        
+        
+        // Check normals
+        1. Recorrer las normales de lstIdNormals y calcular el promedio  -> V1
+        2. Calcular el promedio de 4 normales de la nueva superficie     -> V2
+        3. Calcular el angulo entre V1 y V2
+        4. Si el angulo es major de 90 Invertir las normales de la superficie actual
+        
+        
+        // --- Finish ---
+        wsp->UndoRedo_SaveCollection();
     } else {
             printf("EED ShowNPoints_Tools::CreatePatch01  Warning patch not apply. Need juste one group with four points\n");
     } // if
@@ -162,7 +180,7 @@ void ShowNPoints_Tools::Process()
         } // if Type
         if (bbGetInputType()==50)
         {
-            bbGetInputWidgetShowNPoints()->DeleteAllPoints();
+            bbGetInputWidgetShowNPoints()->OnDeleteAllPoints_();
         } // if Type
         if (bbGetInputType()==100)
         {
@@ -182,7 +200,7 @@ void ShowNPoints_Tools::Process()
         } // if Type
         if (bbGetInputType()==210)
         {
-            bbGetInputWidgetShowNPoints()->InvertLstPoints();
+            bbGetInputWidgetShowNPoints()->OnInvertLstPoints_();
         } // if Type
     } // if bbGetInputWidgetShowNPoints
 }
index f31e871b088f82225cd32e4b19b99bc515f0bdb5..ff7e6236bb7e63b093050d7705a38396fdeec159 100644 (file)
@@ -515,6 +515,7 @@ void WidgetShowNPoints::OnInsertPoint_()
     } else {//mpoint.size
         printf("creaMaracasVisu::ShowNPoints (not match point) \n");
     }
+    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
@@ -537,20 +538,19 @@ void WidgetShowNPoints::OnAddPoint_()
        } else {//mpoint.size
                printf("creaMaracasVisu::ShowNPoints (not match point) \n");
        }
+    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 {
     OnAddPoint_();
-    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
 {
     OnInsertPoint_();
-    UndoRedo_SaveCollection();
 }
 
 
@@ -671,13 +671,13 @@ void WidgetShowNPoints::OnSetPoint_()
         GetViewShowNPoints()->Render();
     } // if id
     SetOutputBox();
+    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
 {
     OnSetPoint_();
-    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
@@ -780,13 +780,13 @@ void WidgetShowNPoints::StopTrackPoint( )
         //renderer->GetRenderWindow()->Render();
         GetViewShowNPoints()->Render();
         StopTrackPoint();
+        UndoRedo_SaveCollection();
     }
 
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
        {
                OnErasePoint_();
-        UndoRedo_SaveCollection();
        }
 
 //------------------------------------------------------------------------
@@ -804,7 +804,7 @@ void WidgetShowNPoints::StopTrackPoint( )
        }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::DeleteAllPoints()
+void WidgetShowNPoints::DeleteAllPoints_()
 {
     // EED 2022-05-19
     //int id,size=lstActorsSphere.size();
@@ -815,14 +815,18 @@ void WidgetShowNPoints::DeleteAllPoints()
     }// for id
 }
 
+void WidgetShowNPoints::OnDeleteAllPoints_()
+{
+    DeleteAllPoints_();
+    UndoRedo_SaveCollection();
+}
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
 {
-       DeleteAllPoints();
+       OnDeleteAllPoints_();
     SetOutputBox();
     GetViewShowNPoints()->Render();
-    UndoRedo_SaveCollection();
 }
 
 //NTU: Method for updating points opacity and Radio
@@ -936,7 +940,7 @@ void WidgetShowNPoints::InsertCollection()
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
+void WidgetShowNPoints::InsertCollectionBefore_()
 {
     InsertCollection();
     RefreshCollectionText();
@@ -945,7 +949,22 @@ void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::OnInsertCollectionAfter_()
+void WidgetShowNPoints::OnInsertCollectionBefore_()
+{
+    InsertCollectionBefore_();
+    UndoRedo_SaveCollection();
+}
+
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
+{
+    OnInsertCollectionBefore_();
+}
+
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::InsertCollectionAfter_()
 {
     mActualCollection++;
     InsertCollection();
@@ -954,6 +973,13 @@ void WidgetShowNPoints::OnInsertCollectionAfter_()
     StopTrackPoint();
 }
 
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnInsertCollectionAfter_()
+{
+    InsertCollectionAfter_();
+    UndoRedo_SaveCollection();
+}
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
 {
@@ -965,7 +991,7 @@ void WidgetShowNPoints::DeleteCollection_()
 {
     if ( lstModelShowNPoints.size()>1 )
     {
-        DeleteAllPoints();  // Actual Collection
+        DeleteAllPoints_();  // Actual Collection
         lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
         lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
         if ( mActualCollection>=lstModelShowNPoints.size() )
@@ -973,7 +999,7 @@ void WidgetShowNPoints::DeleteCollection_()
             mActualCollection--;
         } // if
     } else {
-        DeleteAllPoints();  // Actual Collection
+        DeleteAllPoints_();  // Actual Collection
     } // if
 }
 
@@ -986,17 +1012,17 @@ void WidgetShowNPoints::OnDeleteCollection_()
     RefreshCollectionText();
     RefreshColourCollection();
     StopTrackPoint();
+    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
 {
     OnDeleteCollection_();
-    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::OnResetCollections_()
+void WidgetShowNPoints::ResetCollections_()
 {
     int i,size=lstModelShowNPoints.size();
     for (i=0;i<size;i++)
@@ -1009,11 +1035,19 @@ void WidgetShowNPoints::OnResetCollections_()
     StopTrackPoint();
 }
 
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnResetCollections_()
+{
+    ResetCollections_();
+    UndoRedo_SaveCollection();
+}
+
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnResetCollections(wxCommandEvent &event)
 {
     OnResetCollections_();
-    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
@@ -1347,7 +1381,7 @@ int WidgetShowNPoints::GetLstModelShowNPointsSize()
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::InvertLstPoints()
+void WidgetShowNPoints::InvertLstPoints_()
 {
     int i,size=lstModelShowNPoints.size();
     for (i=0 ;  i < size ; i++)
@@ -1357,6 +1391,13 @@ void WidgetShowNPoints::InvertLstPoints()
     SetOutputBox();
 }
 
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnInvertLstPoints_()
+{
+    InvertLstPoints_();
+    UndoRedo_SaveCollection();
+}
+
 
 //------------------------------------------------------------------------
 std::string WidgetShowNPoints::GetUndoRedoFileName()
@@ -1370,14 +1411,13 @@ std::string WidgetShowNPoints::GetUndoRedoFileName()
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnUndo(wxCommandEvent &event)
 {
-    OnResetCollections_();
+    ResetCollections_();
 //    if (idUndoRedo==maxUndoRedo+1)
 //    {
 //       idUndoRedo--;
 //    } // if idUndoRedo+1
     idUndoRedo--;
     idUndoRedo--;
-    printf("EED  WidgetShowNPoints::OnUndo %d  %d\n", idUndoRedo, maxUndoRedo);
     if (idUndoRedo<0)
     {
         idUndoRedo=-1;
@@ -1391,28 +1431,22 @@ void WidgetShowNPoints::OnUndo(wxCommandEvent &event)
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnRedo(wxCommandEvent &event)
 {
-    printf("EED  WidgetShowNPoints::OnRedo A  %d  %d\n", idUndoRedo, maxUndoRedo);
     if (idUndoRedo>maxUndoRedo)
     {
         idUndoRedo=maxUndoRedo+1;
     } else {
-        OnResetCollections_();
+        ResetCollections_();
         OnLoadCollections_( GetUndoRedoFileName() );
         idUndoRedo++;
     }// if idUndoRedo
-    
-    printf("EED  WidgetShowNPoints::OnRedo B  %d  %d\n", idUndoRedo, maxUndoRedo);
-
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::UndoRedo_SaveCollection()
 {
-    printf("EED  \n EED WidgetShowNPoints::UndoRedo_SaveCollection %d  %d\n", idUndoRedo, maxUndoRedo);
     OnSaveCollections_( GetUndoRedoFileName() );
     maxUndoRedo = idUndoRedo;
     idUndoRedo++;
-    printf("EED  WidgetShowNPoints::UndoRedo_SaveCollection %d  %d\n", idUndoRedo, maxUndoRedo);
 }
 
 
index a14001345daba7d93cd39c35d47f0d2807487d08..a9a646bf781f65074edb647c7a56232c9752cd5b 100644 (file)
@@ -33,8 +33,10 @@ class WidgetShowNPoints : public wxPanel
       void OnErasePoint_();
          void OnErasePoint(wxCommandEvent& event);
          void OnEraseLastPoint(wxCommandEvent &event); 
+      void DeleteAllPoints_();
+      void OnDeleteAllPoints_();
          void OnDeleteAllPoints(wxCommandEvent &event);
-    
+
          void OnSavePoints(wxCommandEvent &event);   
          void OnLoadPoints(wxCommandEvent &event);
 
@@ -42,7 +44,10 @@ class WidgetShowNPoints : public wxPanel
       void UpdatePoints_();
 
       void InsertCollection();
+      void InsertCollectionBefore_();
+      void OnInsertCollectionBefore_();
       void OnInsertCollectionBefore(wxCommandEvent &event);
+      void InsertCollectionAfter_();
       void OnInsertCollectionAfter_();
       void OnInsertCollectionAfter(wxCommandEvent &event);
       void OnDeleteCollection_();
@@ -54,9 +59,10 @@ class WidgetShowNPoints : public wxPanel
       void OnSaveCollections_( std::string filename );
       void OnLoadCollections(wxCommandEvent &event);
       void OnLoadCollections_( std::string filename );
-      void OnResetCollections(wxCommandEvent &event);
+      void ResetCollections_();
       void OnResetCollections_();
-    
+      void OnResetCollections(wxCommandEvent &event);
+
       void OnUndo(wxCommandEvent &event);
       void OnRedo(wxCommandEvent &event);
       void UndoRedo_SaveCollection();
@@ -65,8 +71,9 @@ class WidgetShowNPoints : public wxPanel
 
       void RefreshCollectionText();
       void RefreshColourCollection();
-      void InvertLstPoints();
-    
+      void InvertLstPoints_();
+      void OnInvertLstPoints_();
+
       // EED 2022-05-19
          //void RefreshPoint(int id);
       //void RefreshPoints();
@@ -82,29 +89,24 @@ class WidgetShowNPoints : public wxPanel
          void AddPoint(int x, int y, int z, std::string label);
       void OnInsertPoint_();
          void InsertPoint(int x, int y, int z, std::string label);//CFT
-         void DeleteAllPoints();
 
       int GetLstModelShowNPointsSize();
          ModelShowNPoints* GetModelShowNPoints();
       ViewShowNPoints* GetViewShowNPoints();
          void SetInitLstPoints( std::vector<int> initLstPointsX,  std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels );
 
-               void SetType(int type);
-               int  GetType();
-
-               double GetRadio();
-               double GetOpacity();
-
-    virtual void                      SetOutputBox();
-    void                              ErasePoint(int id);
-
-    
-    
-    std::vector<int> GetLstPointsX();
-    std::vector<int> GetLstPointsY();
-    std::vector<int> GetLstPointsZ();
-    std::vector<std::string> GetLstLabels();
-    std::vector<int> GetLstIndexs();
+      void          SetType(int type);
+      int           GetType();
+      double        GetRadio();
+      double        GetOpacity();
+      virtual void  SetOutputBox();
+      void          ErasePoint(int id);
+
+      std::vector<int> GetLstPointsX();
+      std::vector<int> GetLstPointsY();
+      std::vector<int> GetLstPointsZ();
+      std::vector<std::string> GetLstLabels();
+      std::vector<int> GetLstIndexs();