]> Creatis software - creaVtk.git/commitdiff
#3517 Adjustments Undo - Redo for deformation
authorPablo Garzon <gapablo2001@gmail.com>
Fri, 28 Jul 2023 09:14:11 +0000 (11:14 +0200)
committerPablo Garzon <gapablo2001@gmail.com>
Fri, 28 Jul 2023 09:14:11 +0000 (11:14 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx
lib/creaVtk/MeshManagerModel.cpp
lib/creaVtk/MeshManagerModel.h

index abee3e687157ae877e78500b7fd828b79558fd1b..2a4dd4402d441fb82b211c3fdc2511e9c45cb323 100644 (file)
@@ -151,11 +151,11 @@ void CreateMeshFromPoints::Process()
                                int lastId1 = lstIndexs[0]-1;
                                int lastId2 = sizeLstX - 1;
                                int firstId2 = sizeLstX - lstIndexs[sizeLstIdexes - 1];
-                               bool face1open = std::fabs(lstX[0] - lstX[lastId1]) > 0.0001 && std::fabs(lstY[0] - lstY[lastId1]) > 0.0001 && std::fabs(lstZ[0] - lstZ[lastId1]) > 0.0001;
-                               bool face2open = std::fabs(lstX[firstId2] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[firstId2] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[firstId2] - lstZ[lastId2]) > 0.0001;
+                               bool face1open = std::fabs(lstX[0] - lstX[lastId1]) > 0.0001 || std::fabs(lstY[0] - lstY[lastId1]) > 0.0001 || std::fabs(lstZ[0] - lstZ[lastId1]) > 0.0001;
+                               bool face2open = std::fabs(lstX[firstId2] - lstX[lastId2]) > 0.0001 || std::fabs(lstY[firstId2] - lstY[lastId2]) > 0.0001 || std::fabs(lstZ[firstId2] - lstZ[lastId2]) > 0.0001;
                                
-                               bool altFace1open = std::fabs(lstX[0] - lstX[firstId2]) > 0.0001 && std::fabs(lstY[0] - lstY[firstId2]) > 0.0001 && std::fabs(lstZ[0] - lstZ[firstId2]) > 0.0001;
-                               bool altFace2open = std::fabs(lstX[lastId1] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[lastId1] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[lastId1] - lstZ[lastId2]) > 0.0001;
+                               bool altFace1open = std::fabs(lstX[0] - lstX[firstId2]) > 0.0001 || std::fabs(lstY[0] - lstY[firstId2]) > 0.0001 || std::fabs(lstZ[0] - lstZ[firstId2]) > 0.0001;
+                               bool altFace2open = std::fabs(lstX[lastId1] - lstX[lastId2]) > 0.0001 || std::fabs(lstY[lastId1] - lstY[lastId2]) > 0.0001 || std::fabs(lstZ[lastId1] - lstZ[lastId2]) > 0.0001;
 
                                //false = Open Contour
                                //true = Closed Contour
index c089676c87390307eaadedb0acd7185219a57577..e1fc4ed5d161c846dd6e3b6dc92c651a86e0ff5c 100644 (file)
@@ -32,13 +32,19 @@ void MeshManager_tool::Process()
         if (bbGetInputTool()==10) // Undo
         {
                bbGetInputMeshManagerModel()->Undo();
-               bbSetOutputOut(bbGetInputMeshManagerModel()->GetReferencePoint());
+               std::vector<double> outData = bbGetInputMeshManagerModel()->GetReferencePoint();
+               std::vector<double> refNormal = bbGetInputMeshManagerModel()->GetReferenceNormal();
+               outData.insert(outData.end(), refNormal.begin(), refNormal.end());
+               bbSetOutputOut(outData);
         } // if Tool 10 Undo
         
         if (bbGetInputTool()==20) // Redo
         {
                bbGetInputMeshManagerModel()->Redo();
-               bbSetOutputOut(bbGetInputMeshManagerModel()->GetReferencePoint());
+               std::vector<double> outData = bbGetInputMeshManagerModel()->GetReferencePoint();
+               std::vector<double> refNormal = bbGetInputMeshManagerModel()->GetReferenceNormal();
+               outData.insert(outData.end(), refNormal.begin(), refNormal.end());
+               bbSetOutputOut(outData);
         } // if Tool 20 Redo
 
         if (bbGetInputTool()==30)  // Set
@@ -58,9 +64,11 @@ void MeshManager_tool::Process()
         } // if Tool 35 Set memory mode
                if(bbGetInputTool() == 37) // Save State Memory Mode
         {
-               if(bbGetInputDoubleParams().size() == 5){       
+               if(bbGetInputDoubleParams().size() == 8){       
                                std::vector<double> point = {bbGetInputDoubleParams()[0], bbGetInputDoubleParams()[1], bbGetInputDoubleParams()[2]};
                                bbGetInputMeshManagerModel()->SetReferencePoint(point);
+                               std::vector<double> normVect = {bbGetInputDoubleParams()[3], bbGetInputDoubleParams()[4], bbGetInputDoubleParams()[5]};
+                               bbGetInputMeshManagerModel()->SetReferenceNormal(normVect);
                        bbGetInputMeshManagerModel()->SaveMemoryMode();
                }
         }
index 2eb006a63623250122f804bc37c45c1dc20836fe..c666b5fd8cc048774732d1da2d827839755015f0 100644 (file)
@@ -45,7 +45,7 @@ void PlaneWidget_Base::Process()
     {
        bbGetInputIn()->SetNormalIn(bbGetInputParamVector());
        bbGetInputIn()->Process();
-        bbGetInputIn()->Execute();
+        //bbGetInputIn()->Execute();
     } // if Type == 2
     if((bbGetInputType()==3)  &&  (bbGetInputIn()!=NULL) && (bbGetInputParamVector().size() == 3))
     {
index 1f0ce15a3f5a61a7209e86574d9a5428a08b80ff..84713441479ad9dbe9fcfade3da2982d05596f8d 100644 (file)
@@ -330,6 +330,7 @@ MeshManagerModel::MeshManagerModel()
        lastModified = 0;
        memoryMode = false;
        referencePoint = {0, 0, 0};
+       referenceNormal = {0, 0, 1};
 }
 
 MeshManagerModel::~MeshManagerModel()
@@ -367,6 +368,16 @@ std::vector<double> MeshManagerModel::GetReferencePoint()
        return referencePoint;
 }
 
+void MeshManagerModel::SetReferenceNormal(std::vector<double> normal)
+{
+       referenceNormal = normal;
+}
+
+std::vector<double> MeshManagerModel::GetReferenceNormal()
+{
+       return referenceNormal;
+}
+
 int MeshManagerModel::GetNumberOfMeshes()
 {
        return _meshes.size();
@@ -701,7 +712,7 @@ void MeshManagerModel::Undo()
        if(history->UndoSize() > 0)
        {
                if(memoryMode == false){
-                       RestoreState(history->Undo(new ManagerState(_meshes, meshId, lastModified, referencePoint)));
+                       RestoreState(history->Undo(new ManagerState(_meshes, meshId, lastModified)));
                        RefreshOutputs(true);
                }
                else if(history->UndoSize() > 1){
@@ -715,7 +726,7 @@ void MeshManagerModel::Redo()
        if(history->RedoSize() > 0)
        {
                if(memoryMode == false){
-                       RestoreState(history->Redo(new ManagerState(_meshes, meshId, lastModified, referencePoint)));
+                       RestoreState(history->Redo(new ManagerState(_meshes, meshId, lastModified)));
                        RefreshOutputs(true);
                }
                else{
@@ -726,7 +737,7 @@ void MeshManagerModel::Redo()
 
 void MeshManagerModel::Save()
 {
-       history->Save(new ManagerState(_meshes, meshId, currentMesh, referencePoint));
+       history->Save(new ManagerState(_meshes, meshId, currentMesh));
 }
 
 void MeshManagerModel::SaveMemoryMode()
@@ -735,7 +746,7 @@ void MeshManagerModel::SaveMemoryMode()
        {
                std::vector<std::shared_ptr<MeshModel>> savedMesh;
                savedMesh.push_back(std::make_shared<MeshModel>(_meshes.at(0).get()));
-               history->Save(new ManagerState(savedMesh, meshId, 0, referencePoint));
+               history->Save(new ManagerState(savedMesh, meshId, 0, referencePoint, referenceNormal));
        }
        else{
                printf("PG MeshManagerModel::SaveMemoryMode WARNING Mesh vector has invalid size or memoryMode is not set \n");
@@ -766,6 +777,7 @@ void MeshManagerModel::RestoreStateMemoryMode(ManagerState* state){
                _meshes.at(0)->GetMeshBase()->GetPoints()->Modified();
         _meshes.at(0)->GetMeshBase()->Modified();
         referencePoint = state->GetReferencePoint();
+        referenceNormal = state->referenceNormal;
        }else{
                printf("PG MeshManagerModel::RestoreStateMemoryMode WARNING Mesh vector has invalid size or state is NULL\n");
        }
@@ -774,12 +786,20 @@ void MeshManagerModel::RestoreStateMemoryMode(ManagerState* state){
 //
 //Manager State
 //
-MeshManagerModel::ManagerState::ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedPos, std::vector<double> refPoint)
+MeshManagerModel::ManagerState::ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedPos)
+{
+       savedMeshes = meshesToSave;
+       savedId = meshId;
+       savedModifiedPos = modifiedPos;
+}
+
+MeshManagerModel::ManagerState::ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedPos, std::vector<double> refPoint, std::vector<double> refNormal)
 {
        savedMeshes = meshesToSave;
        savedId = meshId;
        savedModifiedPos = modifiedPos;
        referencePoint = refPoint;
+       referenceNormal = refNormal;
 }
 
 MeshManagerModel::ManagerState::~ManagerState()
index a32867f73ea399d2955302a46b64092c5b9a2b79..98f55063366cf46a758c13597fe790279a904ddc 100644 (file)
@@ -103,6 +103,8 @@ public :
        
        void SetReferencePoint(std::vector<double> point);
        std::vector<double> GetReferencePoint();
+       void SetReferenceNormal(std::vector<double> normal);
+       std::vector<double> GetReferenceNormal();
        
     void SetMeshBase(vtkPolyData* mesh);
     void SetMeshMemoryMode(vtkPolyData* mesh);
@@ -178,20 +180,23 @@ private:
     int                                                                                lastModified;
     bool                                                                       memoryMode;
     std::vector<double>                                                referencePoint;
+    std::vector<double>                                                referenceNormal;
     
     class ManagerState{
        public:
-               ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId, std::vector<double> refPoint);
+               ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId);
+               ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId, std::vector<double> refPoint, std::vector<double> refNormal);
                ~ManagerState();
                std::vector<std::shared_ptr<MeshModel>>& GetMeshes();
                int GetMeshId();
                int GetModifiedPos();
                std::vector<double>& GetReferencePoint();
-       private:
+
                std::vector<std::shared_ptr<MeshModel>> savedMeshes;
                int savedModifiedPos;
                int savedId;
                std::vector<double> referencePoint;
+               std::vector<double> referenceNormal;
     };
     
     void                                                       Save();