From: Pablo Garzon Date: Fri, 28 Jul 2023 09:14:11 +0000 (+0200) Subject: #3517 Adjustments Undo - Redo for deformation X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=8480ddec6027339a7b6ca2291390eb51b755858d;p=creaVtk.git #3517 Adjustments Undo - Redo for deformation --- diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx index abee3e6..2a4dd44 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx @@ -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 diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx index c089676..e1fc4ed 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx @@ -32,13 +32,19 @@ void MeshManager_tool::Process() if (bbGetInputTool()==10) // Undo { bbGetInputMeshManagerModel()->Undo(); - bbSetOutputOut(bbGetInputMeshManagerModel()->GetReferencePoint()); + std::vector outData = bbGetInputMeshManagerModel()->GetReferencePoint(); + std::vector 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 outData = bbGetInputMeshManagerModel()->GetReferencePoint(); + std::vector 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 point = {bbGetInputDoubleParams()[0], bbGetInputDoubleParams()[1], bbGetInputDoubleParams()[2]}; bbGetInputMeshManagerModel()->SetReferencePoint(point); + std::vector normVect = {bbGetInputDoubleParams()[3], bbGetInputDoubleParams()[4], bbGetInputDoubleParams()[5]}; + bbGetInputMeshManagerModel()->SetReferenceNormal(normVect); bbGetInputMeshManagerModel()->SaveMemoryMode(); } } diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx index 2eb006a..c666b5f 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx @@ -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)) { diff --git a/lib/creaVtk/MeshManagerModel.cpp b/lib/creaVtk/MeshManagerModel.cpp index 1f0ce15..8471344 100644 --- a/lib/creaVtk/MeshManagerModel.cpp +++ b/lib/creaVtk/MeshManagerModel.cpp @@ -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 MeshManagerModel::GetReferencePoint() return referencePoint; } +void MeshManagerModel::SetReferenceNormal(std::vector normal) +{ + referenceNormal = normal; +} + +std::vector 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> savedMesh; savedMesh.push_back(std::make_shared(_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> meshesToSave, int meshId, int modifiedPos, std::vector refPoint) +MeshManagerModel::ManagerState::ManagerState(std::vector> meshesToSave, int meshId, int modifiedPos) +{ + savedMeshes = meshesToSave; + savedId = meshId; + savedModifiedPos = modifiedPos; +} + +MeshManagerModel::ManagerState::ManagerState(std::vector> meshesToSave, int meshId, int modifiedPos, std::vector refPoint, std::vector refNormal) { savedMeshes = meshesToSave; savedId = meshId; savedModifiedPos = modifiedPos; referencePoint = refPoint; + referenceNormal = refNormal; } MeshManagerModel::ManagerState::~ManagerState() diff --git a/lib/creaVtk/MeshManagerModel.h b/lib/creaVtk/MeshManagerModel.h index a32867f..98f5506 100644 --- a/lib/creaVtk/MeshManagerModel.h +++ b/lib/creaVtk/MeshManagerModel.h @@ -103,6 +103,8 @@ public : void SetReferencePoint(std::vector point); std::vector GetReferencePoint(); + void SetReferenceNormal(std::vector normal); + std::vector GetReferenceNormal(); void SetMeshBase(vtkPolyData* mesh); void SetMeshMemoryMode(vtkPolyData* mesh); @@ -178,20 +180,23 @@ private: int lastModified; bool memoryMode; std::vector referencePoint; + std::vector referenceNormal; class ManagerState{ public: - ManagerState(std::vector> meshesToSave, int meshId, int modifiedId, std::vector refPoint); + ManagerState(std::vector> meshesToSave, int meshId, int modifiedId); + ManagerState(std::vector> meshesToSave, int meshId, int modifiedId, std::vector refPoint, std::vector refNormal); ~ManagerState(); std::vector>& GetMeshes(); int GetMeshId(); int GetModifiedPos(); std::vector& GetReferencePoint(); - private: + std::vector> savedMeshes; int savedModifiedPos; int savedId; std::vector referencePoint; + std::vector referenceNormal; }; void Save();