PlaneDirectionManager.cxx

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

Generated on 20 Oct 2010 for creaMaracasVisu_lib by  doxygen 1.6.1