1 #include "manualViewBaseContour.h"
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6 // ----------------------------------------------------------------------------
8 manualViewBaseContour::manualViewBaseContour()
13 _wxvtkbaseview = NULL;
15 _posibleSelected = false;
16 _viewControlPoints = false;
19 _contourVtkActor = NULL;
22 _sizePointsContour = 100;
35 _coulorSelection_r = 0;
36 _coulorSelection_g = 1;
37 _coulorSelection_b = 0;
42 // ----------------------------------------------------------------------------
43 manualViewBaseContour::~manualViewBaseContour()
45 int i,size=_lstViewPoints.size();
46 for (i=0;i<size; i++){
47 delete _lstViewPoints[i];
49 _lstViewPoints.clear();
51 // ----------------------------------------------------------------------------
54 int manualViewBaseContour::GetType() // virtual
57 //int manualViewBaseContour::GetType() 0;
58 //int manualViewContour::GetType() 1;
59 //int manualViewRoi::GetType() 2;
60 //int manualViewCircle::GetType() 3;
61 //int manualViewStar::GetType() 4;
62 //int manualViewLine::GetType() 6;
63 //int manualViewPoints::GetType() 7;
68 // ----------------------------------------------------------------------------
70 void manualViewBaseContour::Save(FILE *pFile)
72 fprintf(pFile,"TypeView %d\n", GetType() );
75 // ----------------------------------------------------------------------------
76 void manualViewBaseContour::Open(FILE *pFile)
80 // ----------------------------------------------------------------------------
81 void manualViewBaseContour :: AddCompleteContourActor( bool ifControlPoints )
83 _viewControlPoints = ifControlPoints;
84 /*vtkRenderer * theRenderer = */ _wxvtkbaseview->GetRenderer(); // JPRx ??
89 //Adding each control point
95 // ---------------------------------------------------------------------------
97 void manualViewBaseContour :: RemoveCompleteContourActor()
99 /*vtkRenderer * theRenderer =*/ _wxvtkbaseview->GetRenderer(); // JPRx ??
100 //Removing the spline
104 //Removing each point
105 RemoveControlPoints();
109 // ---------------------------------------------------------------------------
110 manualViewBaseContour * manualViewBaseContour :: Clone( )//virtual
112 manualViewBaseContour * clone = new manualViewBaseContour();
113 CopyAttributesTo(clone);
118 // ---------------------------------------------------------------------------
120 void manualViewBaseContour::CopyAttributesTo( manualViewBaseContour * cloneObject)
123 //XXXX::CopyAttributesTo(cloneObject);
125 cloneObject-> SetWxVtkBaseView( this->_wxvtkbaseview );
126 cloneObject-> SetSelected( this->GetSelected() );
127 cloneObject-> SetPosibleSelected( this->GetPosibleSelected() );
128 cloneObject-> SetIfViewControlPoints( this->GetIfViewControlPoints() );
129 cloneObject-> SetRange( this->GetRange() );
130 cloneObject-> SetZ( this->GetZ() );
131 cloneObject-> SetSpacing( _spc );
132 cloneObject-> SetColorNormalContour( _coulorNormal_r, _coulorNormal_g, _coulorNormal_b );
133 cloneObject-> SetColorEditContour( _coulorEdit_r, _coulorEdit_g, _coulorEdit_b );
134 cloneObject-> SetColorSelectContour( _coulorSelection_r, _coulorSelection_g, _coulorSelection_b );
136 int i, size = _lstViewPoints.size();
137 for ( i=0; i<size; i++ )
139 cloneObject->AddPoint( );
143 // ----------------------------------------------------------------------------
144 void manualViewBaseContour :: AddSplineActor()
146 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
147 if (_contourVtkActor!=NULL)
148 theRenderer->AddActor( _contourVtkActor );
150 // ----------------------------------------------------------------------------
151 void manualViewBaseContour :: RemoveSplineActor() // virtual
153 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
154 if (_contourVtkActor!=NULL)
155 theRenderer->RemoveActor( _contourVtkActor );
157 // ----------------------------------------------------------------------------
158 void manualViewBaseContour :: RemoveControlPoints()
160 if (_wxvtkbaseview!=NULL){
161 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
162 int i,size=_lstViewPoints.size();
163 for (i=0;i<size; i++)
165 vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
166 theRenderer->RemoveActor( pointActor );
169 SetIfViewControlPoints( false );
171 // ----------------------------------------------------------------------------
172 void manualViewBaseContour::AddControlPoints()
174 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
175 SetIfViewControlPoints( true );
176 if( _viewControlPoints )
178 int i,size=_lstViewPoints.size();
179 for (i=0;i<size; i++)
181 vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
182 theRenderer->AddActor( pointActor );
186 // ----------------------------------------------------------------------------
187 void manualViewBaseContour::AddTextActor()
191 _wxvtkbaseview->GetRenderer()->AddActor2D( _textActor );
194 // ----------------------------------------------------------------------------
195 void manualViewBaseContour::RemoveTextActor()
199 _wxvtkbaseview->GetRenderer()->RemoveActor2D( _textActor );
202 // ----------------------------------------------------------------------------
203 void manualViewBaseContour::DeleteVtkObjects()
205 if ( _contourVtkActor != NULL ) { _contourVtkActor -> Delete(); }
206 if ( _bboxMapper != NULL ) { _bboxMapper -> Delete(); }
207 if ( _pts != NULL ) { _pts -> Delete(); }
208 if ( _pd != NULL ) { _pd -> Delete(); }
209 _contourVtkActor = NULL;
216 // ----------------------------------------------------------------------------
217 void manualViewBaseContour::SetWidthLine(double width)
220 this->UpdateColorActor();
222 // for the control points
223 int id, size = _lstViewPoints.size();
224 for( id=0; id<size; id++)
226 this->_lstViewPoints[id]->SetWidthLine(_widthline);
231 // ----------------------------------------------------------------------------
232 double manualViewBaseContour::GetWidthLine()
237 // ----------------------------------------------------------------------------
238 void manualViewBaseContour::ConstructVTKObjects()
242 //JSTG 29-02-08 -----------------------------------------------
243 //int i , nps = _sizePointsContour;
245 int nps = _manContModel->GetNumberOfPointsSpline();
246 //-------------------------------------------------------------
249 _pts = vtkPoints::New();
250 _pts->SetNumberOfPoints(nps);
251 for (i=0 ; i<nps ; i++){
252 _pts->SetPoint(i, 0 , 0 , 0 );
254 // This is for the boundaring inicialisation
257 //_pts->SetPoint(0, 0 , 0 , -1000 );
258 //_pts->SetPoint(1, 0 , 0 , 1000 );
259 _pts->SetPoint(0, -1000 , -1000 , -1000 );
260 _pts->SetPoint(1, 1000 , 1000 , 1000 );
262 vtkCellArray *lines = vtkCellArray::New();
263 lines->InsertNextCell( nps /* +1 */ );
264 for ( i=0 ; i<nps+1 ; i++ ){
265 lines->InsertCellPoint(i % nps );
267 _pd = vtkPolyData::New();
268 _pd->SetPoints( _pts );
269 _pd->SetLines( lines );
270 lines->Delete(); //do not delete lines ??
272 _contourVtkActor = vtkActor::New();
273 _bboxMapper = vtkPolyDataMapper::New();
274 _bboxMapper->ScalarVisibilityOff( );
276 _bboxMapper->SetInput(_pd);
277 _bboxMapper->ImmediateModeRenderingOn();
278 _contourVtkActor->SetMapper(_bboxMapper);
279 _contourVtkActor->GetProperty()->BackfaceCullingOff();
283 _pd->ComputeBounds();
288 void manualViewBaseContour::InitTextActor()
291 _textActor = vtkTextActor::New();
292 // _textActor->SetDisplayPosition(200, 200);
293 _textActor->SetInput("00");
294 // Set coordinates to match the old vtkScaledTextActor default value
295 // _textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
296 // _textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
297 _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
298 // _textActor->GetPositionCoordinate()->SetValue( 0.8 , 0.8 );
300 vtkTextProperty *tprop = _textActor->GetTextProperty();
301 tprop->SetFontSize(14);
302 tprop->SetFontFamilyToArial();
303 tprop->SetColor(0, 0, 1);
306 // ----------------------------------------------------------------------------
307 void manualViewBaseContour::CreateNewContour()
309 ConstructVTKObjects();
311 _wxvtkbaseview->GetRenderer()->AddActor( _contourVtkActor );
312 _wxvtkbaseview->GetRenderer()->AddActor2D(_textActor);*/
313 AddCompleteContourActor();
315 // ----------------------------------------------------------------------------
316 void manualViewBaseContour::UpdateViewPoint(int id) // virtual
318 manualPoint *mp = _manContModel->GetManualPoint(id);
321 double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
322 // wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
323 // wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
325 _lstViewPoints[id]->SetPositionXY( XX , YY ,_range, ZZ );
328 // ----------------------------------------------------------------------------
329 void manualViewBaseContour::UpdateViewPoints()
331 int id, size = _lstViewPoints.size();
332 for( id=0; id<size; id++)
334 UpdateViewPoint( id );
338 // ----------------------------------------------------------------------------
339 void manualViewBaseContour::AddPoint()
341 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
344 // ----------------------------------------------------------------------------
345 void manualViewBaseContour::AddPoint( manualViewPoint * manualViewPoint )
347 _lstViewPoints.push_back( manualViewPoint );
350 manualViewPoint->SetSpacing(_spc);
352 vtkActor *actor = manualViewPoint->CreateVtkPointActor();
353 _wxvtkbaseview->GetRenderer()->AddActor( actor );
356 // ----------------------------------------------------------------------------
357 void manualViewBaseContour::InsertPoint(int id)
359 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
362 mvp->SetSpacing(_spc);
364 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
365 _lstViewPoints.insert(itNum,mvp);
366 _wxvtkbaseview->GetRenderer()->AddActor( mvp->CreateVtkPointActor() );
368 // ----------------------------------------------------------------------------
369 void manualViewBaseContour::DeleteContour()
371 RemoveCompleteContourActor();
372 /*if (_contourVtkActor!=NULL){
373 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
376 int i,size=_lstViewPoints.size();
377 for (i=0;i<size;i++){
378 manualViewBaseContour::DeletePoint(0);
382 // ----------------------------------------------------------------------------
383 void manualViewBaseContour::DeletePoint(int id) // virtual
385 int size=_lstViewPoints.size();
386 if ( (id>=0) && (id<size) ){
387 manualViewPoint *mvp =_lstViewPoints[id];
389 // _handlePicker->DeletePickList(mvp->GetVtkActor());
390 _wxvtkbaseview->GetRenderer()->RemoveActor( mvp->GetVtkActor() );
391 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
392 _lstViewPoints.erase(itNum);
397 // ----------------------------------------------------------------------------
398 void manualViewBaseContour::DeletePoint(int x, int y, int z)
400 int id=GetIdPoint(x,y,z);
405 // ----------------------------------------------------------------------------
406 void manualViewBaseContour::SetSelected(bool selected)
410 // ----------------------------------------------------------------------------
411 void manualViewBaseContour::SetPosibleSelected(bool posibleSelected)
413 _posibleSelected=posibleSelected;
415 // ----------------------------------------------------------------------------
416 bool manualViewBaseContour::GetEditable()
420 // ----------------------------------------------------------------------------
421 void manualViewBaseContour::SetEditable( bool * condition )
423 _editable = condition;
425 // ----------------------------------------------------------------------------
426 bool manualViewBaseContour::GetSelected()
430 // ----------------------------------------------------------------------------
431 bool manualViewBaseContour::GetPosibleSelected()
433 return _posibleSelected;
435 // ----------------------------------------------------------------------------
436 void manualViewBaseContour::DeleteSelectedPoints()
438 int i,size=_lstViewPoints.size();
439 for (i=size-1;i>=0;i--){
440 if (_lstViewPoints[i]->GetSelected()==true){
446 // ----------------------------------------------------------------------------
447 void manualViewBaseContour::SelectPoint(int i, bool select)
449 _lstViewPoints[i]->SetSelected(select);
451 // ----------------------------------------------------------------------------
452 void manualViewBaseContour::SelectLstPoints()
456 // ----------------------------------------------------------------------------
457 void manualViewBaseContour::SelectAllPoints(bool select)
459 int i,size=_lstViewPoints.size();
460 for (i=0;i<size;i++){
461 SelectPoint(i,select);
464 //-----------------------------------------------------------------------------
465 void manualViewBaseContour:: SetIfViewControlPoints(bool ifShow)
467 _viewControlPoints = ifShow;
469 // ----------------------------------------------------------------------------
470 bool manualViewBaseContour:: GetIfViewControlPoints()
472 return _viewControlPoints;
475 // ----------------------------------------------------------------------------
476 void manualViewBaseContour::SetPointPosibleSelected(int id,bool select)
478 _lstViewPoints[id]->SetPosibleSelected(select);
480 // ----------------------------------------------------------------------------
481 void manualViewBaseContour::SetPointSelected(int id,bool select)
483 _lstViewPoints[id]->SetSelected(select);
485 // ----------------------------------------------------------------------------
486 void manualViewBaseContour::SelectAllPossibleSelected(bool select)
488 int i,size=_lstViewPoints.size();
489 for (i=0;i<size;i++){
490 SetPointPosibleSelected(i,select);
493 // ----------------------------------------------------------------------------
494 int manualViewBaseContour::SelectPosiblePoint(int x, int y, int z) // virtual
496 SelectAllPossibleSelected(false);
498 int id = GetIdPoint(x,y,z);
501 SetPointPosibleSelected(id,true);
505 // ----------------------------------------------------------------------------
506 bool manualViewBaseContour::SelectPosibleContour(int x, int y, int z)
509 SetPosibleSelected(result);
510 int id = GetIdPoint(x,y,z);
512 if( !GetEditable() && !_selected && id!= -1)
515 _posibleSelected=true;
519 if ( (GetEditable()==true) && (id==-1 ) && (this->_lstViewPoints.size()>=2) )
521 if (ifTouchContour(x,y,z)==true)
524 SetPosibleSelected(result);
528 if (GetEditable()==false)
530 if (ifTouchContour(x,y,z)==true)
533 SetPosibleSelected(result);
539 // ----------------------------------------------------------------------------
540 bool manualViewBaseContour::ifTouchContour(int x,int y, int z) // virtual
544 // ----------------------------------------------------------------------------
545 void manualViewBaseContour::UnSelectPoint(int i){
546 _lstViewPoints[i]->SetSelected(false);
549 // ----------------------------------------------------------------------------
550 void manualViewBaseContour::UnSelectLstPoints(){
553 // ----------------------------------------------------------------------------
554 void manualViewBaseContour::UnSelectAllPoints(){
555 int i,size=_lstViewPoints.size();
556 for (i=0;i<size;i++){
561 // ----------------------------------------------------------------------------
562 void manualViewBaseContour::SetModel(manualBaseModel *manContModel){
563 _manContModel=manContModel;
565 // ----------------------------------------------------------------------------
566 void manualViewBaseContour::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview){
567 _wxvtkbaseview = wxvtkbaseview;
569 // ----------------------------------------------------------------------------
570 void manualViewBaseContour::RefreshContour() // Virtual
573 // ----------------------------------------------------------------------------
574 double* manualViewBaseContour::GetVectorPointsXManualContour(){
576 int i,size = _sizePointsContour;
577 double *vx = (double*)malloc(sizeof(double)*size);
578 for (i=0;i<size;i++){
579 _pts->GetPoint(i,pp);
584 // ----------------------------------------------------------------------------
585 double* manualViewBaseContour::GetVectorPointsYManualContour()
588 int i,size = _sizePointsContour;
589 double *vy = (double*)malloc(sizeof(double)*size);
590 for (i=0;i<size;i++){
591 _pts->GetPoint(i,pp);
596 // ----------------------------------------------------------------------------
597 double* manualViewBaseContour::GetVectorPointsZManualContour()
600 int i,size = _sizePointsContour;
601 double *vz = (double*)malloc(sizeof(double)*size);
602 for (i=0;i<size;i++){
603 _pts->GetPoint(i,pp);
608 // ----------------------------------------------------------------------------
609 void manualViewBaseContour::Refresh() // virtual
611 if (_contourVtkActor!=NULL){
614 int i,size=_lstViewPoints.size();
615 for (i=0;i<size;i++){
617 _lstViewPoints[i]->UpdateColorActor();
621 if (_show_text==true)
626 vtkRenderWindowInteractor *vri = _wxvtkbaseview->GetWxVTKRenderWindowInteractor ();
629 _wxvtkbaseview->GetRenWin()->Render();
630 printf("EED %p How to optimize manualViewBaseContour::Refresh() \n",this);
634 // ----------------------------------------------------------------------------
635 void manualViewBaseContour::RefreshText() // virtual
637 if( _textActor!=NULL)
638 _textActor -> SetInput("00");
640 // ----------------------------------------------------------------------------
641 void manualViewBaseContour::SetColorNormalContour(double r, double g, double b)
647 // ----------------------------------------------------------------------------
648 void manualViewBaseContour::GetColorNormalContour(double &r, double &g, double &b)
654 // ----------------------------------------------------------------------------
655 void manualViewBaseContour::SetColorEditContour(double r, double g, double b)
661 // ----------------------------------------------------------------------------
662 void manualViewBaseContour::GetColorEditContour(double &r, double &g, double &b)
668 // ----------------------------------------------------------------------------
669 void manualViewBaseContour::SetColorSelectContour(double r, double g, double b)
671 _coulorSelection_r = r;
672 _coulorSelection_g = g;
673 _coulorSelection_b = b;
675 // ----------------------------------------------------------------------------
676 void manualViewBaseContour::GetColorSelectContour(double &r, double &g, double &b)
678 r = _coulorSelection_r;
679 g = _coulorSelection_g;
680 b = _coulorSelection_b;
682 // ----------------------------------------------------------------------------
683 void manualViewBaseContour::UpdateColorActor()
685 if (_contourVtkActor!=NULL)
687 _contourVtkActor->GetProperty()->SetLineWidth( _widthline );
688 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b );
689 if (_posibleSelected || (_posibleSelected && GetEditable() ) )
691 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b );
695 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b );
699 // ----------------------------------------------------------------------------
700 int manualViewBaseContour::GetIdPoint(int x, int y, int z) // virtual
703 if (_manContModel!=NULL){
707 TransfromCoordViewWorld(xx,yy,zz);
708 ii=_manContModel->GetIdPoint(xx,yy,zz,_range,-1);
713 // ----------------------------------------------------------------------------
716 int manualViewBaseContour::GetNumberOfPoints()
718 return _lstViewPoints.size();
721 // ----------------------------------------------------------------------------
723 //JSTG 25-02-08 ---------------------------------------------------------------
724 /*int manualViewBaseContour::GetNumberOfPointsSpline()
726 return _sizePointsContour;
728 //----------------------------------------------------------------------------
730 //JSTG 25-02-08 ---------------------------------------------------------------
731 /*void manualViewBaseContour::SetNumberOfPointsSpline(int size)
733 _sizePointsContour = size;
735 //----------------------------------------------------------------------------
737 void manualViewBaseContour::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // Virtual
739 _wxvtkbaseview->TransFromCoordScreenToWorld(X, Y, Z,false, type);
744 // wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*)_wxvtkbaseview;
745 // wxvtk2Dbaseview->TransformCoordinate_spacing_ModelToView(X,Y,Z);
748 // ----------------------------------------------------------------------------
749 void manualViewBaseContour::SetRange(double range)
753 // ----------------------------------------------------------------------------
754 double manualViewBaseContour::GetRange()
758 // ----------------------------------------------------------------------------
759 void manualViewBaseContour::SetZ(int z)
763 // ----------------------------------------------------------------------------
764 int manualViewBaseContour::GetZ()
769 // ----------------------------------------------------------------------------
770 void manualViewBaseContour::InitMove(int x, int y, int z) // virtual
774 // ----------------------------------------------------------------------------
775 void manualViewBaseContour::MoveContour(int x, int y, int z) // virtual
778 // ----------------------------------------------------------------------------
779 void manualViewBaseContour::MoveContour(int horizontalUnits, int verticalUnits )// virtual
783 // ----------------------------------------------------------------------------
784 void manualViewBaseContour::GetMinMax( double &minX,double &minY, double &minZ, double &maxX, double &maxY, double &maxZ )// virtual
789 int size=_manContModel->GetSizeLstPoints();
794 bool ifFindZ = minZ!=-1.0 && maxZ!=-1.0;
800 for( i = 0; i < size; i++ )
802 mp=_manContModel->GetManualPoint(i);
854 // ----------------------------------------------------------------------------
855 void manualViewBaseContour::ClearContour()
857 if (_contourVtkActor!=NULL){
858 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
861 int i,size=_lstViewPoints.size();
862 for (i=0;i<size;i++){
867 // ----------------------------------------------------------------------------
868 void manualViewBaseContour::ClearPoint(int id)
872 // ----------------------------------------------------------------------------
873 void manualViewBaseContour::SetVisible(bool ok)
883 int i,size=_lstViewPoints.size();
884 for (i=0;i<size;i++){
885 actor = _lstViewPoints[i]->GetVtkActor();
886 actor->GetProperty()->SetOpacity( opacity );
888 _contourVtkActor->GetProperty()->SetOpacity( opacity );
889 _textActor->GetProperty()->SetOpacity( opacity );
890 _textActor->SetInput("00");
893 // ----------------------------------------------------------------------------
894 void manualViewBaseContour::SetShowText(bool ok)
897 if (_show_text==false && _textActor!=NULL)
899 _textActor->SetInput("00");
902 // ----------------------------------------------------------------------------
903 wxVtkBaseView *manualViewBaseContour::GetWxVtkBaseView()
905 return this->_wxvtkbaseview;
907 // ----------------------------------------------------------------------------
908 void manualViewBaseContour::GetSpacing(double spc[3])
914 // ----------------------------------------------------------------------------
915 void manualViewBaseContour::SetSpacing(double spc[3])