1 /*=========================================================================
4 Module: $RCSfile: CutModelManager.cxx,v $
6 Date: $Date: 2009/11/25 16:35:37 $
7 Version: $Revision: 1.4 $
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());
42 void CutModelManager::setImageData(vtkImageData* img){
47 _copyimg = vtkImageData::New();
48 _copyimg->SetExtent(_img->GetExtent());
49 _copyimg->SetSpacing(_img->GetSpacing());
50 _copyimg->AllocateScalars();
52 _copyimg->DeepCopy(_img);
56 void CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){
57 _interactor = interactor;
60 void CutModelManager::setRenderer(vtkRenderer* renderer){
64 void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){
67 CutModelData* data = new CutModelData(id,_interactor, observer, _img);
68 _vectordata.push_back(data);
70 _render->AddActor(data->getActor());
72 //_render->UpdateCamera();
76 void CutModelManager::checkInvariant() throw( CutModelException){
78 throw CutModelException("The image is not set");
81 throw CutModelException("The image is not set");
83 if(_interactor==NULL){
84 throw CutModelException("Interactor not set");
87 throw CutModelException("Render not set");
91 double* CutModelManager::getImageRange()throw( CutModelException){
93 return _img->GetScalarRange();
96 void CutModelManager::changeOpacity(int id,int opacity)throw( CutModelException){
98 CutModelData* current = getCutModelData(id);
99 current->changeOpacity(opacity);
102 void CutModelManager::ShowViewBox(int id,bool check)throw( CutModelException){
104 CutModelData* current = getCutModelData(id);
105 current->ShowViewBox(check);
108 void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException){
110 CutModelData* current = getCutModelData(id);
111 current->ChangeShape(selection);
115 CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){
117 CutModelData* current = NULL;
118 for(int i= 0; i < _vectordata.size();i++){
119 CutModelData* temp = _vectordata[i];
120 std::cout<<"id in CutModelManager:: "<<id<<std::endl;
121 std::cout<<"vectordataid in CutModelManager:: "<<temp->getId()<<std::endl;
123 if(temp->getId() == id){
129 throw CutModelException("Data not found");
134 void CutModelManager::updateActorDirection(int id)throw( CutModelException){
136 CutModelData* current = getCutModelData(id);
137 current->udapteActorDirection();
141 void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){
144 CutModelData* current = getCutModelData(id);
145 current->changeColor(r,g,b);
148 void CutModelManager::RemoveActor(int id)throw( CutModelException){
152 CutModelData* current = getCutModelData(id);
153 for(int i = 0; i < _vectordata.size()-1;i++){
154 if(_vectordata[i]->getId()==id){
155 for(int j = i; j < _vectordata.size()-1;j++){
156 _vectordata[j]=_vectordata[j+1];
158 i = _vectordata.size();
161 _render->RemoveViewProp(current->getActor());
162 //_render->RemoveViewProp(current->get
164 _vectordata.pop_back();
169 void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
172 CutModelData* current = getCutModelData(id);
173 current->ExecuteCut(range, isinside,_copyimg);
177 Setting extra information for the undo
179 CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
180 undoaction->setRange(range);
181 undoaction->setIsInside(isinside);
185 vtkImageData* CutModelManager::GetResultImage(){
190 void CutModelManager::RefreshActor(int id){
192 CutModelData* current = getCutModelData(id);
193 _render->RemoveActor(current->getActor());
194 _render->AddActor(current->getActor());
195 current->RefreshViewBox();
199 void CutModelManager::SaveCutModelData(std::string filename)throw( CutModelException){
202 throw CutModelException("not implemented");
211 void CutModelManager::LoadCutModelData(std::string filename)throw( CutModelException){
213 throw CutModelException("not implemented");
217 CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
219 for(int i = _undoredo.size()-1; i > _currentaction;i--){
221 _undoredo.pop_back();
224 CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
225 if(type == CUTMODEL_CUT){
226 cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
227 cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
230 _undoredo.push_back(cutmodel);
232 _currentaction++;// = _undoredo.size();
233 //std::cout<<"current index "<<_currentaction;
238 int CutModelManager::Undo() throw( CutModelException){
239 //&& _currentaction < _undoredo.size()
240 if(_currentaction > 0){
241 int tempaction = _currentaction-1;
242 CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
243 CutModelData* currentmodel;
245 if(currentundo->getActionType()==CUTMODEL_CUT){
247 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
249 currentmodel = getCutModelData(currentundo->getId());
251 currentmodel->setTransform(transform, _copyimg);
253 currentmodel->setCurrentShape(currentundo->getCurrentShape());
255 currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _copyimg);
265 int CutModelManager::Redo() throw( CutModelException){
267 if(_currentaction >= 0 && _currentaction < _undoredo.size()){
270 CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
271 CutModelData* currentmodel;
273 if(currentundo->getActionType()==CUTMODEL_CUT){
275 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
276 currentmodel = getCutModelData(currentundo->getId());
277 currentmodel->setTransform(transform, _copyimg);
278 currentmodel->setCurrentShape(currentundo->getCurrentShape());
279 currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);