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