1 /*=========================================================================
4 Module: $RCSfile: CutModelManager.cxx,v $
6 Date: $Date: 2009/09/08 08:14:27 $
7 Version: $Revision: 1.3 $
9 Copyright: (c) 2002, 2003
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notice for more information.
16 =========================================================================*/
17 #include "CutModelManager.h"
20 ** Start of the manager class
22 CutModelManager::CutModelManager(std::string path){
30 CutModelManager::~CutModelManager(){
31 std::string files = _path;
32 files+="/infounrd_0_fig_0.info";
33 remove(files.c_str());
37 void CutModelManager::setImageData(vtkImageData* img){
42 _copyimg = vtkImageData::New();
43 _copyimg->SetExtent(_img->GetExtent());
44 _copyimg->SetSpacing(_img->GetSpacing());
45 _copyimg->AllocateScalars();
47 _copyimg->DeepCopy(_img);
51 void CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){
52 _interactor = interactor;
55 void CutModelManager::setRenderer(vtkRenderer* renderer){
59 void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){
62 CutModelData* data = new CutModelData(id,_interactor, observer, _img);
63 _vectordata.push_back(data);
65 _render->AddActor(data->getActor());
67 //_render->UpdateCamera();
71 void CutModelManager::checkInvariant() throw( CutModelException){
73 throw CutModelException("The image is not set");
76 throw CutModelException("The image is not set");
78 if(_interactor==NULL){
79 throw CutModelException("Interactor not set");
82 throw CutModelException("Render not set");
86 double* CutModelManager::getImageRange()throw( CutModelException){
88 return _img->GetScalarRange();
91 void CutModelManager::changeOpacity(int id,int opacity)throw( CutModelException){
93 CutModelData* current = getCutModelData(id);
94 current->changeOpacity(opacity);
97 void CutModelManager::ShowViewBox(int id,bool check)throw( CutModelException){
99 CutModelData* current = getCutModelData(id);
100 current->ShowViewBox(check);
103 void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException){
105 CutModelData* current = getCutModelData(id);
106 current->ChangeShape(selection);
110 CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){
112 CutModelData* current = NULL;
113 for(int i= 0; i < _vectordata.size();i++){
114 std::cout<<"id in CutModelManager:: "<<id<<std::endl;
115 std::cout<<"vectordataid in CutModelManager:: "<<_vectordata[i]->getId()<<std::endl;
117 if(_vectordata[i]->getId()==id){
118 current = _vectordata[i];
123 throw CutModelException("Data not found");
128 void CutModelManager::updateActorDirection(int id)throw( CutModelException){
130 CutModelData* current = getCutModelData(id);
131 current->udapteActorDirection();
135 void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){
138 CutModelData* current = getCutModelData(id);
139 current->changeColor(r,g,b);
142 void CutModelManager::RemoveActor(int id)throw( CutModelException){
146 CutModelData* current = getCutModelData(id);
147 for(int i = 0; i < _vectordata.size()-1;i++){
148 if(_vectordata[i]->getId()==id){
149 for(int j = i; j < _vectordata.size()-1;j++){
150 _vectordata[j]=_vectordata[j+1];
152 i = _vectordata.size();
155 _render->RemoveActor(current->getActor());
157 _vectordata.pop_back();
162 void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
165 CutModelData* current = getCutModelData(id);
166 current->ExecuteCut(range, isinside,_copyimg);
170 Setting extra information for the undo
172 CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
173 undoaction->setRange(range);
174 undoaction->setIsInside(isinside);
178 vtkImageData* CutModelManager::GetResultImage(){
183 void CutModelManager::RefreshActor(int id){
185 CutModelData* current = getCutModelData(id);
186 _render->RemoveActor(current->getActor());
187 _render->AddActor(current->getActor());
188 current->RefreshViewBox();
192 void CutModelManager::SaveCutModelData(std::string filename)throw( CutModelException){
195 throw CutModelException("not implemented");
204 void CutModelManager::LoadCutModelData(std::string filename)throw( CutModelException){
206 throw CutModelException("not implemented");
210 CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
212 for(int i = _undoredo.size()-1; i > _currentaction;i--){
214 _undoredo.pop_back();
217 CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
218 if(type == CUTMODEL_CUT){
219 cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
220 cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
223 _undoredo.push_back(cutmodel);
225 _currentaction++;// = _undoredo.size();
226 //std::cout<<"current index "<<_currentaction;
231 int CutModelManager::Undo() throw( CutModelException){
232 //&& _currentaction < _undoredo.size()
233 if(_currentaction > 0){
234 int tempaction = _currentaction-1;
235 CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
236 CutModelData* currentmodel;
238 if(currentundo->getActionType()==CUTMODEL_CUT){
240 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
242 currentmodel = getCutModelData(currentundo->getId());
244 currentmodel->setTransform(transform, _copyimg);
246 currentmodel->setCurrentShape(currentundo->getCurrentShape());
248 currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _copyimg);
258 int CutModelManager::Redo() throw( CutModelException){
260 if(_currentaction >= 0 && _currentaction < _undoredo.size()){
263 CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
264 CutModelData* currentmodel;
266 if(currentundo->getActionType()==CUTMODEL_CUT){
268 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
269 currentmodel = getCutModelData(currentundo->getId());
270 currentmodel->setTransform(transform, _copyimg);
271 currentmodel->setCurrentShape(currentundo->getCurrentShape());
272 currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);