From: Pablo Garzon Date: Thu, 11 May 2023 12:43:30 +0000 (+0200) Subject: #3504 Mesh Manager handle multiple meshes X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=4c66cb9b724ca030dfd569b546521f700baadacb;p=creaVtk.git #3504 Mesh Manager handle multiple meshes --- diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx index 79b9991..900de4e 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx @@ -169,6 +169,9 @@ void CreateMeshFromPoints::CloseContourSides(std::vector lstIndexs, bool uP { bool normalOrder = isPointingCorrectly(firstIndex, firstIndex+increment, centroid, contraryId); centroidId = points->InsertNextPoint(centroid[0], centroid[1], centroid[2]); + //vtkSmartPointer triangleStrip = vtkSmartPointer::New(); + //triangleStrip->GetPointIds()->SetNumberOfIds(numPointsFace*2 + (!isClosedCont?2:0)); + //int triangleIndex = 0; if( normalOrder ) { int initial = firstIndex; @@ -186,11 +189,21 @@ void CreateMeshFromPoints::CloseContourSides(std::vector lstIndexs, bool uP triangle->GetPointIds()->SetId(2, centroidId); cells->InsertNextCell(triangle); } + /* + triangleStrip->GetPointIds()->SetId(triangleIndex,index); + triangleStrip->GetPointIds()->SetId(triangleIndex+1,centroidId);//1 + if(index+increment >= end && !isClosedCont){ + triangleStrip->GetPointIds()->SetId(triangleIndex+2,initial);//2 + triangleStrip->GetPointIds()->SetId(triangleIndex+3,centroidId);//3 + } + triangleIndex+=2; + */ } + //cells->InsertNextCell(triangleStrip); } else { int initial = firstIndex-1; int triangleStripStart = end-1; - for(int index = triangleStripStart; index > initial; index-=increment){ + for(int index = triangleStripStart; index > initial; index-=increment){ if(index-increment <= initial && !isClosedCont){ vtkNew triangle; triangle->GetPointIds()->SetId(0, index); @@ -204,8 +217,17 @@ void CreateMeshFromPoints::CloseContourSides(std::vector lstIndexs, bool uP triangle->GetPointIds()->SetId(2, centroidId); cells->InsertNextCell(triangle); } + /**triangleStrip->GetPointIds()->SetId(triangleIndex,index); + triangleStrip->GetPointIds()->SetId(triangleIndex+1,centroidId); + if(index-increment <= initial && !isClosedCont){ + triangleStrip->GetPointIds()->SetId(triangleIndex+2,triangleStripStart); + triangleStrip->GetPointIds()->SetId(triangleIndex+3,centroidId); + } + triangleIndex+=2; + */ } - } + //cells->InsertNextCell(triangleStrip); + }//if normalOrder }//if validCentroid }//if numPointsFace }//for facesIdx diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.cxx index 25be322..3fa8d4b 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.cxx @@ -15,11 +15,14 @@ MeshManagerModel_Box::~MeshManagerModel_Box( ) { } -void MeshManagerModel_Box::RefreshOutputs( ) +void MeshManagerModel_Box::RefreshOutputs(bool signalBox) { mBox->bbSetOutputMeshBase( GetMeshBase() ); mBox->bbSetOutputMeshTemp( GetMeshTemp() ); - mBox->bbSignalOutputModification(); + mBox->bbSetOutputMeshNames( GetMeshNames() ); + if(signalBox==true){ + mBox->bbSignalOutputModification(); + } } @@ -47,8 +50,12 @@ void MeshManager::Process() if (meshManagerModel_Box==NULL) { meshManagerModel_Box = new MeshManagerModel_Box(this); - meshManagerModel_Box->SetMeshBase( bbGetInputMesh() ); - meshManagerModel_Box->RefreshOutputs(); + + meshManagerModel_Box->AddMeshes_( bbGetInputMeshVector() ); + + meshManagerModel_Box->AddMesh_( bbGetInputMesh() ); + //meshManagerModel_Box->SetMeshBase( bbGetInputMesh() ); + meshManagerModel_Box->RefreshOutputs(false); bbSetOutputMeshManagerModel( meshManagerModel_Box ); } // if meshManagerModel_Box } diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.h b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.h index e4e389a..3b544e3 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager.h @@ -24,8 +24,10 @@ class bbcreaVtk_EXPORT MeshManager // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== BBTK_DECLARE_INPUT(Mesh,vtkPolyData*); + BBTK_DECLARE_INPUT(MeshVector, std::vector); BBTK_DECLARE_OUTPUT(MeshBase,vtkPolyData*); BBTK_DECLARE_OUTPUT(MeshTemp,vtkPolyData*); + BBTK_DECLARE_OUTPUT(MeshNames,std::vector); BBTK_DECLARE_OUTPUT(MeshManagerModel,MeshManagerModel*); BBTK_PROCESS(Process); void Process(); @@ -41,7 +43,7 @@ class MeshManagerModel_Box : public MeshManagerModel public : MeshManagerModel_Box(MeshManager *box); ~MeshManagerModel_Box(); - virtual void RefreshOutputs(); + virtual void RefreshOutputs(bool signalBox); protected: private: MeshManager *mBox; @@ -56,8 +58,10 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(MeshManager,bbtk::AtomicBlackBox); BBTK_CATEGORY("empty"); BBTK_INPUT(MeshManager,Mesh,"Mesh",vtkPolyData*,""); + BBTK_INPUT(MeshManager,MeshVector,"Vector of Meshes",std::vector,""); BBTK_OUTPUT(MeshManager,MeshBase,"Mesh Base",vtkPolyData*,""); BBTK_OUTPUT(MeshManager,MeshTemp,"Mesh Temp",vtkPolyData*,""); + BBTK_OUTPUT(MeshManager,MeshNames,"Mesh Names",std::vector,""); BBTK_OUTPUT(MeshManager,MeshManagerModel,"Mesh manager model",MeshManagerModel*,""); BBTK_END_DESCRIBE_BLACK_BOX(MeshManager); diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx index d0f63ed..e39e25f 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx @@ -66,6 +66,31 @@ void MeshManager_tool::Process() bbGetInputMeshManagerModel()->ResetMeshTemp(); } // if Tool 40 Reset + if(bbGetInputTool() == 50) // Set Array of Meshes + { + if(bbGetInputMeshes().size() > 1) + { + if(bbGetInputMeshManagerModel()->GetNumberOfMeshes() == 1){ + bbGetInputMeshManagerModel()->DeleteAll(); + } + if(bbGetInputMeshManagerModel()->GetNumberOfMeshes() > 1) + { + bbGetInputMeshManagerModel()->DeleteCurrentMesh(); + } + bbGetInputMeshManagerModel()->InsertMeshesAtCurrent(bbGetInputMeshes()); + } + } + if(bbGetInputTool() == 60) // Select Mesh by Name + { + if(!bbGetInputStringParam().empty()) + { + bbGetInputMeshManagerModel()->SelectMeshByName(bbGetInputStringParam()); + } + } + if(bbGetInputTool() == 70) // Delete Current Mesh + { + bbGetInputMeshManagerModel()->DeleteCurrentMesh(); + } } else { printf("EED Warning! MeshManager_tool : MeshManagerModel not defined. \n"); }// if MeshManagerModel != NULL diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h index 3cf9b79..76ba719 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h @@ -24,6 +24,8 @@ class bbcreaVtk_EXPORT MeshManager_tool BBTK_DECLARE_INPUT(Tool,int); BBTK_DECLARE_INPUT(Mesh,vtkPolyData*); BBTK_DECLARE_INPUT(MeshManagerModel,MeshManagerModel*); + BBTK_DECLARE_INPUT(Meshes,std::vector); + BBTK_DECLARE_INPUT(StringParam, std::string); // BBTK_DECLARE_OUTPUT(Out,double); BBTK_PROCESS(Process); void Process(); @@ -38,8 +40,10 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(MeshManager_tool,bbtk::AtomicBlackBox); BBTK_DESCRIPTION("No Description."); BBTK_CATEGORY("empty"); - BBTK_INPUT(MeshManager_tool,Tool,"(default 0) 0:Nothing 10:Undo 20:ReDo 30:Set 32:Copy and Set 35:Set memory mode 40:ResetMeshTemp",int,""); + BBTK_INPUT(MeshManager_tool,Tool,"(default 0) 0:Nothing 10:Undo 20:ReDo 30:Set 32:Copy and Set 35:Set memory mode 40:ResetMeshTemp 50: Set Array of meshes 60:Select mesh by name 70:Delete current mesh",int,""); BBTK_INPUT(MeshManager_tool,Mesh,"Mesh",vtkPolyData*,""); + BBTK_INPUT(MeshManager_tool,Meshes,"Input meshes, required for tool 50",std::vector,""); + BBTK_INPUT(MeshManager_tool,StringParam,"String input",std::string,""); BBTK_INPUT(MeshManager_tool,MeshManagerModel,"Mesh Manager Model",MeshManagerModel*,""); // BBTK_OUTPUT(MeshManager_tool,Out,"First output",double,""); diff --git a/lib/creaVtk/MeshManagerModel.cpp b/lib/creaVtk/MeshManagerModel.cpp index cf0b3dd..677727c 100644 --- a/lib/creaVtk/MeshManagerModel.cpp +++ b/lib/creaVtk/MeshManagerModel.cpp @@ -27,17 +27,39 @@ #include "MeshManagerModel.h" -MeshManagerModel::MeshManagerModel() +//////////////////// +/////////////////////// MESH MODEL +//////////////////// + +MeshModel::MeshModel(int id) { - _meshBase = NULL; + _meshBase = NULL; _meshTemp = NULL; + _meshId = id; + _name = "mesh-" + std::to_string(id); } -MeshManagerModel::~MeshManagerModel() +MeshModel::MeshModel(vtkPolyData* mesh, int id) { + if(mesh != NULL){ + _meshBase = mesh; + _meshTemp = vtkPolyData::New(); + _meshTemp->DeepCopy(_meshBase); + _meshId = id; + _name = "mesh-" + std::to_string(id); + } } -void MeshManagerModel::ResetMeshTemp_() +MeshModel::~MeshModel(){ + if(_meshBase != NULL){ + _meshBase->Delete(); + } + if(_meshTemp != NULL){ + _meshTemp->Delete(); + } +} + +void MeshModel::ResetMeshTemp_() { if (_meshBase!=NULL) { @@ -52,29 +74,26 @@ void MeshManagerModel::ResetMeshTemp_() } } -void MeshManagerModel::SetMeshBase(vtkPolyData* mesh) +void MeshModel::SetMeshBase(vtkPolyData* mesh) { if (mesh!=NULL) { _meshBase = mesh; ResetMeshTemp_(); - RefreshOutputs(); } // if mesh } -void MeshManagerModel::SetMeshMemoryMode(vtkPolyData* mesh) +void MeshModel::SetMeshMemoryMode(vtkPolyData* mesh) { _meshBase = mesh; - RefreshOutputs(); } -void MeshManagerModel::ResetMeshTemp() +void MeshModel::ResetMeshTemp() { ResetMeshTemp_(); - RefreshOutputs(); } -void MeshManagerModel::CopySetMeshBase(vtkPolyData* mesh) +void MeshModel::CopySetMeshBase(vtkPolyData* mesh) { if (mesh!=NULL) { @@ -85,16 +104,291 @@ void MeshManagerModel::CopySetMeshBase(vtkPolyData* mesh) } -vtkPolyData* MeshManagerModel::GetMeshBase() +vtkPolyData* MeshModel::GetMeshBase() { return _meshBase; } -vtkPolyData* MeshManagerModel::GetMeshTemp() +vtkPolyData* MeshModel::GetMeshTemp() { return _meshTemp; } -void MeshManagerModel::RefreshOutputs() // virtula +int MeshModel::GetId() +{ + return _meshId; +} + +std::string MeshModel::GetName() +{ + return _name; +} + +//////////////////// +/////////////////////// MESH MANAGER +//////////////////// + +MeshManagerModel::MeshManagerModel() +{ + //MeshModel* firstMesh = new MeshModel(); + //_meshes.push_back(firstMesh); + currentMesh = 0; + meshId = 0; +} + +MeshManagerModel::~MeshManagerModel() +{ + DeleteAll(); +} + +void MeshManagerModel::RefreshOutputs(bool signalBox) // virtual +{ +} + +int MeshManagerModel::GetNumberOfMeshes(){ + return _meshes.size(); +} + +void MeshManagerModel::AddMesh_(vtkPolyData* mesh){ + if(mesh != NULL){ + MeshModel *meshModel = new MeshModel(mesh, meshId); + _meshes.push_back(meshModel); + meshId++; + } + else{ + printf("PG MeshManagerModel::AddMesh Mesh is null \n"); + } +} + +void MeshManagerModel::AddMesh(vtkPolyData* mesh){ + AddMesh_(mesh); + RefreshOutputs(true); +} + +void MeshManagerModel::AddMeshes_(std::vector meshList){ + if(!meshList.empty()) + { + MeshModel *meshModel; + for(int i = 0; i < meshList.size(); i++){ + meshModel = new MeshModel(meshList[i], meshId); + _meshes.push_back(meshModel); + meshId++; + } + }else{ + printf("PG MeshManagerModel::AddMeshes Empty list of meshes \n"); + } +} + +void MeshManagerModel::AddMeshes(std::vector meshList){ + AddMeshes_(meshList); + RefreshOutputs(true); +} + +void MeshManagerModel::AddEmptyMesh_(){ + MeshModel *meshModel = new MeshModel(meshId); + _meshes.push_back(meshModel); + meshId++; +} + +void MeshManagerModel::AddEmptyMesh(){ + AddEmptyMesh_(); + RefreshOutputs(true); +} + +void MeshManagerModel::InsertMeshesAtCurrent_(std::vector meshList) +{ + if(!meshList.empty()) + { + std::vector tmpVect; + MeshModel *meshModel; + for(int i = 0; i < meshList.size(); i++){ + meshModel = new MeshModel(meshList[i], meshId); + tmpVect.push_back(meshModel); + meshId++; + } + _meshes.insert(_meshes.begin() + currentMesh, tmpVect.begin(), tmpVect.end()); + }else{ + printf("PG MeshManagerModel::AddMeshes Empty list of meshes \n"); + } +} + +void MeshManagerModel::InsertMeshesAtCurrent(std::vector meshList) +{ + InsertMeshesAtCurrent_(meshList); + RefreshOutputs(true); +} + +void MeshManagerModel::SelectMesh(int i) { + if(i >= 0 && i < _meshes.size()){ + int prevCurrent = currentMesh; + currentMesh = i; + if(prevCurrent != i){ + RefreshOutputs(true); + } + } + else{ + printf("PG MeshManagerModel::SelectMesh index out of bounds \n"); + } +} + +void MeshManagerModel::SelectMeshByName(std::string meshName) { + if(!_meshes.empty()){ + bool found = false; + for(int i = 0; i < _meshes.size() && !found; i++){ + if(_meshes.at(i)->GetName() == meshName){ + found = true; + SelectMesh(i); + } + } + } +} + +void MeshManagerModel::DeleteMesh(int position){ + if(position >= 0 && position < _meshes.size()){ + delete _meshes.at(position); + _meshes.erase(_meshes.begin() + position); + currentMesh = currentMesh + (position <= currentMesh?-1:0); + if(currentMesh < 0){ + currentMesh = 0; + } + RefreshOutputs(true); + } +} + +void MeshManagerModel::DeleteMeshByName(std::string meshName){ + if(!_meshes.empty()){ + bool found = false; + for(int i = 0; i < _meshes.size() && !found; i++){ + if(_meshes.at(i)->GetName() == meshName){ + found = true; + delete _meshes.at(i); + _meshes.erase(_meshes.begin() + i); + currentMesh = currentMesh + (i <= currentMesh?-1:0); + if(currentMesh < 0){ + currentMesh = 0; + } + RefreshOutputs(true); + } + } + } +} + +void MeshManagerModel::DeleteCurrentMesh(){ + if(!_meshes.empty()){ + delete _meshes.at(currentMesh); + _meshes.erase(_meshes.begin() + currentMesh); + currentMesh--; + if(currentMesh < 0){ + currentMesh = 0; + } + RefreshOutputs(true); + } +} + +void MeshManagerModel::DeleteAll(){ + if(!_meshes.empty()){ + for (MeshModel* element : _meshes) + { + delete element; + } + _meshes.clear(); + RefreshOutputs(true); + } +} + +void MeshManagerModel::NextMesh(){ + currentMesh++; + if(currentMesh >= _meshes.size()){ + currentMesh = _meshes.size()-1; + } + RefreshOutputs(true); +} + +void MeshManagerModel::PreviousMesh(){ + currentMesh--; + if(currentMesh < 0){ + currentMesh = 0; + } + RefreshOutputs(true); +} + +MeshModel* MeshManagerModel::GetMeshModel(){ + return _meshes.at(currentMesh); +} + +vtkPolyData* MeshManagerModel::GetMeshBase() +{ + if(!_meshes.empty()){ + return _meshes.at(currentMesh)->GetMeshBase(); + } + else{ + return NULL; + } +} + +vtkPolyData* MeshManagerModel::GetMeshTemp() +{ + if(!_meshes.empty()){ + return _meshes.at(currentMesh)->GetMeshTemp(); + } + else{ + return NULL; + } +} + +void MeshManagerModel::SetMeshBase(vtkPolyData* mesh) +{ + if(!_meshes.empty()){ + _meshes.at(currentMesh)->SetMeshBase(mesh); + RefreshOutputs(true); + }else{ + printf("PG MeshManagerModel::SetMeshMemoryMode Mesh vector is empty \n"); + } +} + +void MeshManagerModel::SetMeshMemoryMode(vtkPolyData* mesh) +{ + //if(!_meshes.empty()){ + if(_meshes.size() > 1){ + DeleteAll(); + } + if(_meshes.size() == 0){ + AddEmptyMesh_(); + } + _meshes.at(currentMesh)->SetMeshMemoryMode(mesh); + RefreshOutputs(true); + //}else{ + // printf("PG MeshManagerModel::SetMeshMemoryMode Mesh vector is empty \n"); + //} +} + +void MeshManagerModel::ResetMeshTemp() +{ + if(!_meshes.empty()){ + _meshes.at(currentMesh)->ResetMeshTemp(); + RefreshOutputs(true); + }else{ + printf("PG MeshManagerModel::ResetMeshTemp Mesh vector is empty \n"); + } + +} + +void MeshManagerModel::CopySetMeshBase(vtkPolyData* mesh) +{ + if(!_meshes.empty()){ + _meshes.at(currentMesh)->CopySetMeshBase(mesh); + RefreshOutputs(true); + } + else{ + printf("PG MeshManagerModel::CopySetMeshBase Mesh vector is empty \n"); + } +} + +std::vector MeshManagerModel::GetMeshNames() { + std::vector names; + for(int i = 0; i < _meshes.size(); i++){ + names.push_back(_meshes.at(i)->GetName()); + } + return names; } diff --git a/lib/creaVtk/MeshManagerModel.h b/lib/creaVtk/MeshManagerModel.h index b2f5dc9..b679255 100644 --- a/lib/creaVtk/MeshManagerModel.h +++ b/lib/creaVtk/MeshManagerModel.h @@ -24,6 +24,33 @@ # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ +#include + +class MeshModel{ + +public: + MeshModel(int id); + MeshModel(vtkPolyData* mesh, int id); + ~MeshModel(); + + void SetMeshBase(vtkPolyData* mesh); + void SetMeshMemoryMode(vtkPolyData* mesh); + void CopySetMeshBase(vtkPolyData* mesh); + void ResetMeshTemp(); + void ResetMeshTemp_(); + vtkPolyData* GetMeshBase(); + vtkPolyData* GetMeshTemp(); + int GetId(); + std::string GetName(); + +protected: + +private: + vtkPolyData *_meshBase; + vtkPolyData *_meshTemp; + int _meshId; + std::string _name; +}; #ifndef _MESHMANAGERMODEL_H_ #define _MESHMANAGERMODEL_H_ @@ -33,8 +60,6 @@ // [classdescription] //--------------------------------------------- -#include - class MeshManagerModel { @@ -49,10 +74,36 @@ public : void SetMeshMemoryMode(vtkPolyData* mesh); void CopySetMeshBase(vtkPolyData* mesh); void ResetMeshTemp(); - void ResetMeshTemp_(); + //void ResetMeshTemp_(); vtkPolyData* GetMeshBase(); vtkPolyData* GetMeshTemp(); - virtual void RefreshOutputs(); + + virtual void RefreshOutputs(bool signalBox); + + MeshModel* GetMeshModel(); + int GetNumberOfMeshes(); + + void AddMesh_(vtkPolyData* mesh); + void AddMesh(vtkPolyData* mesh); + + void AddEmptyMesh_(); + void AddEmptyMesh(); + + void AddMeshes(std::vector meshList); + void AddMeshes_(std::vector meshList); + + void InsertMeshesAtCurrent_(std::vector meshList); + void InsertMeshesAtCurrent(std::vector meshList); + + void SelectMesh(int i); + void SelectMeshByName(std::string meshName); + void DeleteMesh(int position); + void DeleteMeshByName(std::string meshName); + void DeleteCurrentMesh(); + void DeleteAll(); + void NextMesh(); + void PreviousMesh(); + std::vector GetMeshNames(); //--Method template---------------------------- // void FunctionName(int& parameterA); @@ -67,8 +118,10 @@ protected: //Methods and attributes only visible by this class //--------------------------------------------- private: - vtkPolyData *_meshBase; - vtkPolyData *_meshTemp; + + std::vector _meshes; + int currentMesh; + int meshId; }; //-end of _MESHMANAGERMODEL_H_------------------------------------------------------