PlaneDirectionManagerData.cxx
Go to the documentation of this file.00001
00002 #include "PlaneDirectionManagerData.h"
00003
00004
00005
00006
00007
00008 PlaneDirectionManagerData::PlaneDirectionManagerData(int radio, double colour[3], int opacity)
00009 :PlanesOperations(){
00010 _vtkarrow = vtkArrowSource::New();
00011 _arrowMapper = vtkPolyDataMapper::New();
00012 _arrowActor = vtkActor::New();
00013
00014 _vtkarrow->SetTipResolution(30);
00015 _vtkarrow->SetShaftResolution( 30 );
00016 _arrowMapper->SetInput( _vtkarrow->GetOutput() );
00017 _arrowActor->SetMapper(_arrowMapper);
00018
00019 _radio = radio;
00020 _colour = colour;
00021 _opacity = opacity;
00022
00023 p0 = new double[3];
00024 p0[0] = 0;
00025 p0[1] = 0;
00026 p0[2] = 0;
00027 p1 = new double[3];
00028 p1[0] = 0;
00029 p1[1] = 0;
00030 p1[2] = 0;
00031 p2 = new double[3];
00032 p2[0] = 1;
00033 p2[1] = 1;
00034 p2[2] = 1;
00035 _dir = new double[3];
00036 _dir[0] = 0;
00037 _dir[1] = 0;
00038 _dir[2] = 0;
00039 }
00040
00041
00042 PlaneDirectionManagerData::~PlaneDirectionManagerData(){
00043
00044 _vtkarrow->Delete();
00045 _arrowMapper->Delete();
00046 _arrowActor->Delete();
00047 delete p0;
00048 delete p1;
00049 delete p2;
00050 delete _dir;
00051 }
00052
00053 vtkProp3D* PlaneDirectionManagerData::GetActor(){
00054 return _arrowActor;
00055 }
00056
00057 void PlaneDirectionManagerData::UpdateActor(){
00058
00059 _arrowActor->GetProperty()->SetColor( _colour[0] , _colour[1] , _colour[2] );
00060 _arrowActor->GetProperty()->SetOpacity( _opacity );
00061
00062
00063 double* vect1= getNormal(makeVector(p0, p1));
00064 double* vect2= getNormal(makeVector(p0, p2));
00065 _dir = getNormal(getCrossProduct(vect1, vect2));
00066 double *newvectnorm = getNormal(getCrossProduct(_dir, vect2));
00067 double *midp = GetMidPoint();
00068
00069 vtkMatrix4x4* _matrix = vtkMatrix4x4::New();
00070 _matrix->Identity();
00071 _matrix->SetElement(0,0,_dir[0]*_radio);
00072 _matrix->SetElement(1,0,_dir[1]*_radio);
00073 _matrix->SetElement(2,0,_dir[2]*_radio);
00074 _matrix->SetElement(0,1,vect2[0]*_radio);
00075 _matrix->SetElement(1,1,vect2[1]*_radio);
00076 _matrix->SetElement(2,1,vect2[2]*_radio);
00077 _matrix->SetElement(0,2,newvectnorm[0]*_radio);
00078 _matrix->SetElement(1,2,newvectnorm[1]*_radio);
00079 _matrix->SetElement(2,2,newvectnorm[2]*_radio);
00080 _matrix->SetElement(0,3,midp[0]);
00081 _matrix->SetElement(1,3,midp[1]);
00082 _matrix->SetElement(2,3,midp[2]);
00083 _arrowActor->SetUserMatrix(_matrix);
00084
00085 }
00086
00087 void PlaneDirectionManagerData::ChangeColour(double r,double g,double b){
00088 _colour[0] = r;
00089 _colour[1] = g;
00090 _colour[2] = b;
00091 if(_arrowActor!=NULL){
00092 _arrowActor->GetProperty()->SetColor( r,g,b );
00093 }
00094 }
00095
00096 double* PlaneDirectionManagerData::GetMidPoint(){
00097 if(p0 != NULL && p1 != NULL && p2 != NULL){
00098 double* ret = new double[3];
00099 ret[0] = (p0[0] + p1[0] +p2[0])/3;
00100 ret[1] = (p0[1] + p1[1] +p2[1])/3;
00101 ret[2] = (p0[2] + p1[2] +p2[2])/3;
00102 return ret;
00103 }
00104 return NULL;
00105 }