X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2FCutModule%2Fkernel%2FCutModelManager.cxx;h=05e92d879559024a916ed787b3334c773ca60227;hb=f9901e756bb82bd333310b47607875331616bb29;hp=9cec5c6fefa0bd524b55ade0166508cae0e3265a;hpb=2a69bae264c4dc43a7189f16b53a66dcd3a774dc;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx b/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx index 9cec5c6..05e92d8 100644 --- a/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx +++ b/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx @@ -1,20 +1,47 @@ +/*# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ */ + /*========================================================================= - Program: wxMaracas - Module: $RCSfile: CutModelManager.cxx,v $ - Language: C++ - Date: $Date: 2010/02/08 15:20:22 $ - Version: $Revision: 1.6 $ +Program: wxMaracas +Module: $RCSfile: CutModelManager.cxx,v $ +Language: C++ +Date: $Date: 2012/11/15 14:15:48 $ +Version: $Revision: 1.11 $ - Copyright: (c) 2002, 2003 - License: +Copyright: (c) 2002, 2003 +License: - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notice for more information. +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "CutModelManager.h" + +//Machete #include "CutModelMainPanel.h" /** @@ -27,11 +54,11 @@ CutModelManager::CutModelManager(std::string path){ _interactor = NULL; _render = NULL; _currentaction=0; - + } CutModelManager::~CutModelManager(){ std::string files = _path; - files+="/infounrd_0_fig_0.info"; + files+="/infounrd_0_fig_0.info"; remove(files.c_str()); _vectordata.clear(); _img = NULL; @@ -41,6 +68,10 @@ CutModelManager::~CutModelManager(){ } +vtkImageData* CutModelManager::getImageData(){ + return _img2; +} + void CutModelManager::setImageData(vtkImageData* img){ int type = CutModelMainPanel::getInstance()->GetType(); if( type == 0) @@ -48,13 +79,17 @@ void CutModelManager::setImageData(vtkImageData* img){ _img = img; if(_img2!=NULL){ - _img2->Delete(); + _img2->Delete(); } _img2 = vtkImageData::New(); _img2->SetExtent(_img->GetExtent()); _img2->SetSpacing(_img->GetSpacing()); +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 _img2->AllocateScalars(); - +#else + //... +#endif _img2->DeepCopy(_img); } else @@ -67,7 +102,12 @@ void CutModelManager::setImageData(vtkImageData* img){ _img = vtkImageData::New(); _img->SetExtent(_img2->GetExtent()); _img->SetSpacing(_img2->GetSpacing()); +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 _img->AllocateScalars(); +#else + //... +#endif _img->DeepCopy(_img2); } @@ -84,7 +124,7 @@ void CutModelManager::setRenderer(vtkRenderer* renderer){ void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){ checkInvariant(); - + CutModelData* data = new CutModelData(id,_interactor, observer, _img); _vectordata.push_back(data); @@ -136,7 +176,9 @@ void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException) CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){ CutModelData* current = NULL; - for(int i= 0; i < _vectordata.size();i++){ + int i; + for(i= 0; i < (int)_vectordata.size();i++) + { CutModelData* temp = _vectordata[i]; std::cout<<"id in CutModelManager:: "<getId()<udapteActorDirection(); - + } void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){ @@ -167,29 +209,31 @@ void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutMo _render->Render(); } void CutModelManager::RemoveActor(int id)throw( CutModelException){ - - checkInvariant(); - - CutModelData* current = getCutModelData(id); - for(int i = 0; i < _vectordata.size()-1;i++){ - if(_vectordata[i]->getId()==id){ - for(int j = i; j < _vectordata.size()-1;j++){ - _vectordata[j]=_vectordata[j+1]; - } - i = _vectordata.size(); + + checkInvariant(); + + CutModelData* current = getCutModelData(id); + int i,j; + for(i = 0; i < (int)_vectordata.size()-1;i++) + { + if(_vectordata[i]->getId()==id){ + for(j = i; j < (int)_vectordata.size()-1;j++){ + _vectordata[j]=_vectordata[j+1]; } + i = _vectordata.size(); } - _render->RemoveViewProp(current->getActor()); - //_render->RemoveViewProp(current->get - delete current; - _vectordata.pop_back(); - _render->Render(); - + } + _render->RemoveViewProp(current->getActor()); + //_render->RemoveViewProp(current->get + delete current; + _vectordata.pop_back(); + _render->Render(); + } void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){ - checkInvariant(); - + checkInvariant(); + CutModelData* current = getCutModelData(id); current->ExecuteCut(range, isinside,_img2); @@ -204,12 +248,12 @@ void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( Cut } vtkImageData* CutModelManager::GetResultImage(){ - checkInvariant(); - return _img2; + checkInvariant(); + return _img2; } void CutModelManager::RefreshActor(int id){ - checkInvariant(); + checkInvariant(); CutModelData* current = getCutModelData(id); _render->RemoveActor(current->getActor()); _render->AddActor(current->getActor()); @@ -219,24 +263,24 @@ void CutModelManager::RefreshActor(int id){ void CutModelManager::SaveCutModelData(std::string filename)throw( CutModelException){ - + throw CutModelException("not implemented"); - - - - + + + + } void CutModelManager::LoadCutModelData(std::string filename)throw( CutModelException){ - + throw CutModelException("not implemented"); - + } CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){ - + for(int i = _undoredo.size()-1; i > _currentaction;i--){ delete _undoredo[i]; _undoredo.pop_back(); @@ -252,12 +296,12 @@ CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw _currentaction++;// = _undoredo.size(); //std::cout<<"current index "<<_currentaction; - + return cutmodel; } int CutModelManager::Undo() throw( CutModelException){ - //&& _currentaction < _undoredo.size() + //&& _currentaction < _undoredo.size() if(_currentaction > 0){ int tempaction = _currentaction-1; CutModelSaveBinInfo* currentundo = _undoredo[tempaction]; @@ -285,7 +329,7 @@ int CutModelManager::Undo() throw( CutModelException){ int CutModelManager::Redo() throw( CutModelException){ - if(_currentaction >= 0 && _currentaction < _undoredo.size()){ + if(_currentaction >= 0 && _currentaction < (int)_undoredo.size()){ CutModelSaveBinInfo* currentundo = _undoredo[_currentaction]; CutModelData* currentmodel; @@ -305,3 +349,108 @@ int CutModelManager::Redo() throw( CutModelException){ } return -1; } + +void CutModelManager::ParallelProjectionOn(){ + _render->GetActiveCamera()->ParallelProjectionOn(); +} + +void CutModelManager::ParallelProjectionOff(){ + _render->GetActiveCamera()->ParallelProjectionOff(); +} + + +//RaC +void CutModelManager::UpdatePolygon(bool mode) +{ + if(mode) + { + cutterstyle->Delete(); + cutterstyle = vtkInteractorStyleCutter::New(); + + cutterstyle->SetInteractor ( _interactor ); + _interactor ->SetInteractorStyle( cutterstyle ); + } + else + { + cutterstyle->VisibilityOff(); + + loop = vtkImplicitSelectionLoop::New(); + mapper = vtkPolyDataMapper::New(); + if(cutterstyle->Finished()) + { + if(actor3D != NULL) + { + _render->RemoveActor(actor3D); + } + + loop->SetLoop( cutterstyle->GetLoopPoints() ); + loop->SetNormal( cutterstyle->GetDirection()); + + + /// Printing Points + int numPoints = cutterstyle->GetLoopPoints()->GetNumberOfPoints(); + contourDirection = cutterstyle->GetDirection(); + + contourPoints = cutterstyle->GetLoopPoints(); + + _polygonCutter = new CutModelPolygon(); + + cout<<"RaC Printing points......"<GetLoopPoints()->GetPoint(t,point); + cout<<"Initial Point:"<SetImplicitFunction(loop); + sample->CappingOn(); + + contour = vtkContourFilter::New(); +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 + contour->SetInput((vtkDataObject *)sample->GetOutput()); +#else + contour->SetInputData((vtkDataObject *)sample->GetOutput()); +#endif + contour->SetValue(0,1); + + actor = contour->GetOutput(); + + actor3D = vtkActor::New(); +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 + mapper->SetInput(actor); +#else + mapper->SetInputData(actor); +#endif + mapper->SetScalarModeToUseCellData(); + actor3D->SetMapper( mapper); + _render->AddActor(actor3D); + } + + interactorstyle->SetInteractor ( _interactor ); + _interactor->SetInteractorStyle( interactorstyle ); + } + + _interactor->Render(); + _render->ResetCameraClippingRange(); +} +void CutModelManager::ExecuteCutPolygon(bool inOutCut){ + + _polygonCutter->setInImage(_img2); + _polygonCutter->setPoints(contourPoints); + _polygonCutter->setDirection(contourDirection); + _polygonCutter->processOutImage(inOutCut); +} + +void CutModelManager::InitializePolygonInteractorStyle(){ + + cutterstyle = vtkInteractorStyleCutter::New(); + interactorstyle = vtkInteractorStyleTrackballCamera ::New(); + interactorstyle->SetInteractor ( _interactor ); + _interactor->SetInteractorStyle( interactorstyle ); +}