manualViewPerpPlaneContour.cxx

Go to the documentation of this file.
00001 
00002 #include "manualViewPerpPlaneContour.h"
00003 
00004 #include "vtkPlane2DView.h"
00005 
00006 manualViewPerpPlaneContour::manualViewPerpPlaneContour()
00007 {
00008 }
00009 // ----------------------------------------------------------------------------
00010 manualViewPerpPlaneContour::~manualViewPerpPlaneContour()
00011 {
00012 }
00013 
00014 
00015 // ----------------------------------------------------------------------------
00016 manualViewPerpPlaneContour * manualViewPerpPlaneContour :: Clone()
00017 {
00018         manualViewPerpPlaneContour * clone = new manualViewPerpPlaneContour();
00019         CopyAttributesTo(clone);
00020         return clone;
00021 }
00022 
00023 // ---------------------------------------------------------------------------
00024 
00025 void manualViewPerpPlaneContour::CopyAttributesTo( manualViewPerpPlaneContour * cloneObject)
00026 {
00027         // Fathers object
00028         manualViewContour::CopyAttributesTo(cloneObject);
00029 }
00030 
00031 
00032 
00033 
00034 // ----------------------------------------------------------------------------
00035 void manualViewPerpPlaneContour::UpdateViewPoint(int id)
00036 {  // virtual
00037         double x,y,z;
00038         manualPoint *mp = _manContModel->GetManualPoint(id);
00039         x = mp->GetX();
00040         y = mp->GetY();
00041         z = mp->GetZ();
00042         FilterCordinateXYZ(x,y,z);
00043 
00044         _lstViewPoints[id]->SetPositionXY( x , y ,GetRange(), z );
00045         if ((z>=-1) && (z<=1))
00046         {
00047                 _lstViewPoints[id]->GetVtkActor()->VisibilityOn();
00048         } else {
00049                 _lstViewPoints[id]->GetVtkActor()->VisibilityOff();
00050         }
00051 }
00052 // ----------------------------------------------------------------------------
00053 void manualViewPerpPlaneContour::FilterCordinateXYZ (double &x, double &y, double &z)
00054 {
00055         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
00056         vtkMPRBaseData *vtkmprbasedata = vtkplane2Dview->GetVtkmprbasedata();
00057         vtkTransform *transf1 = vtkTransform::New();
00058         vtkTransform *transf2 = vtkmprbasedata->GetTransformOrientation();
00059         transf1->SetMatrix( transf2->GetMatrix() ); 
00060         transf1->Inverse();
00061 
00062         double in[4], out[4];
00063         double center = vtkplane2Dview->GetImgSize() / 2;
00064 
00065         in[0] = x - vtkmprbasedata->GetX();
00066         in[1] = y - vtkmprbasedata->GetY();
00067         in[2] = z - vtkmprbasedata->GetZ();
00068         in[3] = 0;
00069 
00070         transf1->MultiplyPoint(in,out);
00071         z = out[0];
00072         x = out[1]+center;
00073         y = out[2]+center;
00074 
00075         double spc[3];
00076         this->GetWxVtkBaseView()->GetSpacing(spc);
00077         x = x / spc[0];
00078         y = y / spc[1];
00079         z = z / spc[2];
00080 
00081         transf1->Delete();
00082 }
00083 
00084 // ----------------------------------------------------------------------------
00085 void manualViewPerpPlaneContour::TransfromCoordViewWorld( double &X,double &Y,double &Z,int type )
00086 {
00087         Z = 0;
00088         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
00089         vtkplane2Dview->TransfromCoordViewWorld2(X,Y,Z);
00090 }
00091 
00092 
00093 // ----------------------------------------------------------------------------
00094 void manualViewPerpPlaneContour::RefreshContour() // virtual
00095 {
00096 //      manualViewContour::RefreshContour();
00097 
00098         double pp1[3];
00099         double pp2[3];
00100         double u;
00101                 
00102 // JSTG 25-02-08 ----------------------------------------------------------
00103 //              tt;
00104 //--------------------------------------------------------
00105 
00106         double pp[3];
00107         double ppB[3];
00108         double ppC[3];
00109         ppB[0] = 999999;
00110         double dist,distMin = 99999999;
00111 
00112         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
00113         double center = vtkplane2Dview->GetImgSize() / 2;
00114 
00115         int i,np,nps;
00116         np              = GetNumberOfPoints( );
00117 
00118 //JSTG 25-02-08 ------------------------------------------
00119         //double t,delta;
00120     //nps               = GetNumberOfPointsSpline(); 
00121         nps = _manContModel->GetNumberOfPointsSpline();
00122         //delta = ( double ) ( np  ) / ( double ) ( nps-1  );
00123         _manContModel->UpdateSpline();
00124 //--------------------------------------------------------
00125 
00126         if ( np >= 2 )
00127         {
00128                 for( i = 0; i < nps; i++ ) 
00129                 {
00130 // JSTG 25-02-08 ----------------------------------------------------------
00131                         //t     = delta * (double)i ;
00132                         //tt    = delta * (double)(i+1) ;
00133                         //_manContModel->GetSplinePoint(t ,pp1[0],pp1[1],pp1[2]);
00134                         //_manContModel->GetSplinePoint(tt,pp2[0],pp2[1],pp2[2]);
00135                         _manContModel->GetSpline_i_Point(i ,&pp1[0],&pp1[1],&pp1[2]);
00136                         _manContModel->GetSpline_i_Point(i+1,&pp2[0],&pp2[1],&pp2[2]);
00137 //--------------------------------------------------------------------------
00138                         FilterCordinateXYZ(pp1[0],pp1[1],pp1[2]);
00139                         FilterCordinateXYZ(pp2[0],pp2[1],pp2[2]);
00140                         if (pp2[2]*pp1[2]<=0)
00141                         {
00142                                 if (pp1[2]-pp2[2]!=0) { 
00143                                         u = -pp2[2] / (pp1[2]-pp2[2]);
00144                                 } else  {
00145                                         u=9999999;
00146                                 }
00147                                 pp[0]    = ( pp1[0]-pp2[0] )*u + pp2[0];
00148                                 pp[1]    = ( pp1[1]-pp2[1] )*u + pp2[1];
00149                                 pp[2]    = ( pp1[2]-pp2[2] )*u + pp2[2];
00150                                 ppC[0] = pp[0] - center;
00151                                 ppC[1] = pp[1] - center;
00152                                 ppC[2] = pp[2] ;
00153                                 dist = sqrt( ppC[0]*ppC[0] + ppC[1]*ppC[1] + ppC[2]*ppC[2] );
00154                                 if (dist<distMin)
00155                                 {
00156                                         distMin=dist;
00157                                         ppB[0] = pp[0];
00158                                         ppB[1] = pp[1];
00159                                         ppB[2] = pp[2];
00160                                 }
00161                         }
00162 
00163                 }// for 
00164         } else {
00165                         _pts->SetPoint(0, 0 , 0 , 0);   
00166                         _pts->SetPoint(1, 0 , 0 , 0);   
00167         } // if
00168 
00169 //EED 27 sep 2006
00170         ppB[0]=ppB[0]*_spc[0];
00171         ppB[1]=ppB[1]*_spc[1];
00172 
00173         _pts->SetPoint( 0, ppB[0]   , ppB[1]+1 , 1 );   
00174         _pts->SetPoint( 1, ppB[0]   , ppB[1]-1 , 1 );   
00175         _pts->SetPoint( 2, ppB[0]   , ppB[1]   , 1 );   
00176         _pts->SetPoint( 3, ppB[0]-1 , ppB[1]   , 1 );   
00177         _pts->SetPoint( 4, ppB[0]+1 , ppB[1]   , 1 );   
00178 
00179 
00180         for( i = 5; i < nps; i++ ) 
00181         {
00182                 _pts->SetPoint( i, ppB[0] , ppB[1] , 1 );       
00183         }
00184 
00185 }
00186 
00187 //---------------------------------------------------------------------------
00188 bool manualViewPerpPlaneContour::ifTouchContour( int x, int y, int z)
00189 {
00190         bool ok=false;
00191         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
00192         double X=x;
00193         double Y=y;
00194         double Z=z;
00195         vtkplane2Dview->TransFromCoordScreenToWorld(X,Y,Z);
00196         
00197         double ppA[3];
00198         _pts->GetPoint(0, ppA);
00199         if (sqrt( (ppA[0]-X)*(ppA[0]-X) + (ppA[1]-Y)*(ppA[1]-Y) ) <=2)
00200         {
00201                 ok = true;
00202         }
00203         return ok;
00204 }
00205 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1