PlaneDirectionManager.cxx
Go to the documentation of this file.00001
00002 #include "PlaneDirectionManager.h"
00003
00004
00005
00006
00007
00008 PlaneDirectionManager::PlaneDirectionManager(int radio, double colour[3] , int opacity){
00009 _radio = radio;
00010 _colour = colour;
00011 _opacity = opacity;
00012 }
00013
00014
00015 PlaneDirectionManager::~PlaneDirectionManager(){
00016 RemoveAllActorsFromIndex();
00017 }
00018
00019 void PlaneDirectionManager::SetRenderer(vtkRenderer* render){
00020 _render = render;
00021 }
00022 void PlaneDirectionManager::SetVectors( std::vector<double> lstPointsx, std::vector<double> lstPointsy, std::vector<double> lstPointsz){
00023
00024 _lstPointsx = lstPointsx;
00025 _lstPointsy = lstPointsy;
00026 _lstPointsz = lstPointsz;
00027 }
00028
00029 void PlaneDirectionManager::UpdateDirections() throw (std::exception){
00030 UpdateVectors();
00031 UpdateActors();
00032 AddActors();
00033
00034 }
00035 void PlaneDirectionManager::AddActors(){
00036 for(int i = 0; i < _vectdata.size();i++){
00037 _render->AddViewProp (_vectdata[i]->GetActor());
00038 }
00039 }
00040 void PlaneDirectionManager::RemoveAllActorsFromIndex(int n)throw (std::exception){
00041
00042
00043 if(_render==NULL){
00044 throw std::exception();
00045 }
00046 for(int i = _vectdata.size()-1; i >= n;i--){
00047 _render->RemoveViewProp(_vectdata[i]->GetActor());
00048 delete _vectdata[i];
00049 _vectdata.pop_back();
00050 }
00051 }
00052 void PlaneDirectionManager::UpdateVectors()throw (std::exception){
00053 PlaneDirectionManagerData* temp;
00054 bool deletelast = false;
00055 int currentdata = 0;
00056 for(int i = 0; i < _lstPointsx.size();i++){
00057 if(i % 3 == 0){
00058 if(_vectdata.size()>currentdata){
00059 temp = _vectdata[currentdata];
00060 }else{
00061 temp = new PlaneDirectionManagerData(_radio, _colour, _opacity);
00062 _vectdata.push_back(temp);
00063 }
00064 temp->setPoint0(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);
00065 deletelast = true;
00066 }else if(i % 3 == 1){
00067 temp->setPoint1(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);
00068 }else if(i % 3 == 2){
00069 temp->setPoint2(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);
00070 currentdata++;
00071 deletelast = false;
00072 }
00073 }
00074 RemoveAllActorsFromIndex(currentdata);
00075 }
00076
00077 void PlaneDirectionManager::UpdateActors(){
00078 for(int i = 0; i < _vectdata.size();i++){
00079 _vectdata[i]->UpdateActor();
00080 }
00081 }
00082
00083 void PlaneDirectionManager::addRemoveActor(int index, bool addremove){
00084
00085 if(index < _vectdata.size()){
00086 if(addremove){
00087 _render->AddViewProp (_vectdata[index]->GetActor());
00088 }else{
00089 _render->RemoveViewProp (_vectdata[index]->GetActor());
00090 }
00091 }
00092 }
00093
00094 void PlaneDirectionManager::changeColor(int index,double r,double g,double b)
00095 {
00096 GetPlaneDirectionManagerData(index)->ChangeColour(r,g,b);
00097 }
00098
00099 PlaneDirectionManagerData* PlaneDirectionManager::GetPlaneDirectionManagerData(int id)
00100 {
00101 return _vectdata[id];
00102 }
00103
00104 void PlaneDirectionManager::WriteInformation(std::string filename, double* spc){
00105 FILE *ff;
00106 ff = fopen( filename.c_str() , "w+" );
00107 if(spc ==NULL){
00108 spc = new double[3];
00109 spc[0] = 1;
00110 spc[1] = 1;
00111 spc[2] = 1;
00112 }
00113 if (ff!=NULL)
00114 {
00115 for(int i = 0; i < _vectdata.size();i++){
00116
00117 double* p0 = _vectdata[i]->getPoint0();
00118 double* p1 = _vectdata[i]->getPoint1();
00119 double* p2 = _vectdata[i]->getPoint2();
00120 double* dir = _vectdata[i]->GetDirection();
00121
00122 double p0x = p0[0]/spc[0];
00123 double p0y = p0[1]/spc[1];
00124 double p0z = p0[2]/spc[2];
00125
00126 double p1x = p1[0]/spc[0];
00127 double p1y = p1[1]/spc[1];
00128 double p1z = p1[2]/spc[2];
00129
00130 double p2x = p2[0]/spc[0];
00131 double p2y = p2[1]/spc[1];
00132 double p2z = p2[2]/spc[2];
00133
00134 double dirx = dir[0]/spc[0];
00135 double diry = dir[1]/spc[1];
00136 double dirz = dir[2]/spc[2];
00137
00138 fprintf(ff,"Dir%d\n",i);
00139 fprintf(ff,"\tP0[%f, %f, %f]\tP1[%f, %f, %f]\tP2[%f, %f, %f]\tDir[%f, %f, %f] \n",
00140 p0x,p0y,p0z, p1x,p1y,p1z, p2x,p2y,p2z, dirx,diry,dirz);
00141 }
00142 fclose(ff);
00143 } else {
00144 printf("PlaneDirectionManager::WriteInformation ...Error... creating file");
00145 }
00146 }
00147
00148 void PlaneDirectionManager::SetArrowSize(int arrowsize){
00149 _radio = arrowsize;
00150 }