1 /*=========================================================================
4 Module: $RCSfile: CutModelManager.cxx,v $
6 Date: $Date: 2009/09/01 14:01:36 $
7 Version: $Revision: 1.2 $
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(){
28 CutModelManager::~CutModelManager(){
32 void CutModelManager::setImageData(vtkImageData* img){
37 _copyimg = vtkImageData::New();
38 _copyimg->SetExtent(_img->GetExtent());
39 _copyimg->SetSpacing(_img->GetSpacing());
40 _copyimg->AllocateScalars();
42 _copyimg->DeepCopy(_img);
46 void CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){
47 _interactor = interactor;
50 void CutModelManager::setRenderer(vtkRenderer* renderer){
54 void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){
57 CutModelData* data = new CutModelData(id,_interactor, observer, _img);
58 _vectordata.push_back(data);
60 _render->AddActor(data->getActor());
62 //_render->UpdateCamera();
66 void CutModelManager::checkInvariant() throw( CutModelException){
68 throw CutModelException("The image is not set");
71 throw CutModelException("The image is not set");
73 if(_interactor==NULL){
74 throw CutModelException("Interactor not set");
77 throw CutModelException("Render not set");
81 double* CutModelManager::getImageRange()throw( CutModelException){
83 return _img->GetScalarRange();
86 void CutModelManager::changeOpacity(int id,int opacity)throw( CutModelException){
88 CutModelData* current = getCutModelData(id);
89 current->changeOpacity(opacity);
92 void CutModelManager::ShowViewBox(int id,bool check)throw( CutModelException){
94 CutModelData* current = getCutModelData(id);
95 current->ShowViewBox(check);
98 void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException){
100 CutModelData* current = getCutModelData(id);
101 current->ChangeShape(selection);
105 CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){
107 CutModelData* current = NULL;
108 for(int i= 0; i < _vectordata.size();i++){
109 std::cout<<"id in CutModelManager:: "<<id<<std::endl;
110 std::cout<<"vectordataid in CutModelManager:: "<<_vectordata[i]->getId()<<std::endl;
112 if(_vectordata[i]->getId()==id){
113 current = _vectordata[i];
118 throw CutModelException("Data not found");
123 void CutModelManager::updateActorDirection(int id)throw( CutModelException){
125 CutModelData* current = getCutModelData(id);
126 current->udapteActorDirection();
130 void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){
133 CutModelData* current = getCutModelData(id);
134 current->changeColor(r,g,b);
137 void CutModelManager::RemoveActor(int id)throw( CutModelException){
141 CutModelData* current = getCutModelData(id);
142 for(int i = 0; i < _vectordata.size()-1;i++){
143 if(_vectordata[i]->getId()==id){
144 for(int j = i; j < _vectordata.size()-1;j++){
145 _vectordata[j]=_vectordata[j+1];
147 i = _vectordata.size();
150 _render->RemoveActor(current->getActor());
152 _vectordata.pop_back();
157 void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
159 CutModelData* current = getCutModelData(id);
160 current->ExecuteCut(range, isinside,_copyimg);
164 vtkImageData* CutModelManager::GetResultImage(){
169 void CutModelManager::RefreshActor(int id){
171 CutModelData* current = getCutModelData(id);
172 _render->RemoveActor(current->getActor());
173 _render->AddActor(current->getActor());
174 current->RefreshViewBox();